<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "macCatalyst: 27.0.0 -",
    "macOS: 27.0.0 -",
    "tvOS: 27.0.0 -",
    "visionOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Metal",
  "identifier" : "/documentation/Metal/MTLTensorBufferAttachments/setBuffer(_:offset:for:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal"
    ],
    "preciseIdentifier" : "c:objc(cs)MTLTensorBufferAttachments(im)setBuffer:offset:forPlane:"
  },
  "title" : "setBuffer(_:offset:for:)"
}
-->

# setBuffer(_:offset:for:)

Sets the buffer and byte offset to use as backing storage for the given
plane.

```
func setBuffer(_ buffer: any MTLBuffer, offset: Int, for plane: MTLTensorPlaneType)
```

## Parameters

`buffer`

The buffer to back the plane.

`offset`

The byte offset into the buffer.

`plane`

The plane type to associate the buffer with.

## Discussion

The offset needs to be aligned to 128 bytes if the plane uses [`MTLTensorDataType.int2`](/documentation/Metal/MTLTensorDataType/int2),
[`MTLTensorDataType.uint2`](/documentation/Metal/MTLTensorDataType/uint2), [`MTLTensorDataType.int4`](/documentation/Metal/MTLTensorDataType/int4),
[`MTLTensorDataType.uint4`](/documentation/Metal/MTLTensorDataType/uint4), [`MTLTensorDataType.metalFloat4e2m1`](/documentation/Metal/MTLTensorDataType/metalFloat4e2m1),
[`MTLTensorDataType.metalFloat8e4m3`](/documentation/Metal/MTLTensorDataType/metalFloat8e4m3), [`MTLTensorDataType.metalFloat8e5m2`](/documentation/Metal/MTLTensorDataType/metalFloat8e5m2),
or [`MTLTensorDataType.metalFloat8ue8m0`](/documentation/Metal/MTLTensorDataType/metalFloat8ue8m0), otherwise it needs to be aligned
to the size of the plane’s data type in bytes.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)