<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "tvOS: 27.0.0 -",
    "visionOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreAI",
  "identifier" : "/documentation/CoreAI/InferenceFunction/AsyncMutableValue/init(unsafeBuffer:byteOffset:scalarType:shape:strides:interleaveLayout:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Core AI"
    ],
    "preciseIdentifier" : "s:13CoreAIRuntime17InferenceFunctionV17AsyncMutableValueV12unsafeBuffer10byteOffset10scalarType5shape7strides16interleaveLayoutAESo9MTLBuffer_p_SiAA7NDArrayV06ScalarM0OSaySiGAqN010InterleaveQ0VSgtcfc"
  },
  "title" : "init(unsafeBuffer:byteOffset:scalarType:shape:strides:interleaveLayout:)"
}
-->

# init(unsafeBuffer:byteOffset:scalarType:shape:strides:interleaveLayout:)

Creates an async ndArray value that directly references the provided metal buffer,
interpreted as the specified scalar type and shape.

```
init(unsafeBuffer: consuming any MTLBuffer, byteOffset: Int = 0, scalarType: NDArray.ScalarType, shape: [Int], strides: [Int] = [], interleaveLayout: NDArray.InterleaveLayout? = nil)
```

## Discussion

`unsafeBuffer` must have `shared` storage mode.

Initializing an async value this way requires that you manually ensure the provided metal
buffer is not mutated while this value is being used by an inference function.

- unsafeBuffer: The metal buffer to be referenced by the resulting value.
- byteOffset: The offset into this metal buffer to be interpreted as the start of
  this value.
- scalarType: The type of scalars in the provided buffer.
- shape: The shape of the resulting value.
- strides: The strides of the resulting value. If left empty, they will be computed
  as contiguous row-major.
- interleaveLayout: Which dimension is interleaved and by what factor.
  See [`NDArray.InterleaveLayout`](/documentation/CoreAI/NDArray/InterleaveLayout-swift.struct).

---

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)