---
title: "init(unsafeBuffer:byteOffset:scalarType:shape:strides:interleaveLayout:)"
framework: coreai
role: symbol
role_heading: Initializer
path: "coreai/inferencefunction/asyncmutablevalue/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.

## Declaration

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

## Discussion

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.
