<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "tvOS: 27.0.0 -",
    "visionOS: 27.0.0 -",
    "watchOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreAI",
  "identifier" : "/documentation/CoreAI/InferenceFunction/AsyncMutableValue",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Core AI",
      "CoreAI"
    ],
    "preciseIdentifier" : "s:13CoreAIRuntime17InferenceFunctionV17AsyncMutableValueV"
  },
  "title" : "InferenceFunction.AsyncMutableValue"
}
-->

# InferenceFunction.AsyncMutableValue

An async value which can be provided as a mutable argument to an inference function.

```
struct AsyncMutableValue
```

## Overview

When dispatching an [`encode(inputs:states:outputViews:to:)`](/documentation/CoreAI/InferenceFunction/encode(inputs:states:outputViews:to:)), mutable values
are what is included in the states and output vaiews.

Similar to [`InferenceFunction.AsyncValue`](/documentation/CoreAI/InferenceFunction/AsyncValue), this type is a wrapper around an underlying
inference value, however this type may be mutated repeatedly after construction by
providing it as a state argument in sequence to one or more inference functions.

When encoding a sequence of inferences which each mutate the same `AsyncMutableValue`, the framework
will insert the necessary synchronization to avoid it being read or written while a previous
write is occurring.

## Topics

### Creating an async mutable value

[`init(consuming CVMutablePixelBuffer)`](/documentation/CoreAI/InferenceFunction/AsyncMutableValue/init(_:)-4aqgq)

Initialize the state from an existing pixel buffer.

[`init(consuming NDArray)`](/documentation/CoreAI/InferenceFunction/AsyncMutableValue/init(_:)-x6se)

Initialize the state from an existing ndArray.

[`init(descriptor: consuming InferenceValue.Descriptor)`](/documentation/CoreAI/InferenceFunction/AsyncMutableValue/init(descriptor:))

Initialize a new state by creating a value matching the provided descriptor.

[`init(unsafeBuffer: consuming any MTLBuffer, byteOffset: Int, scalarType: NDArray.ScalarType, shape: [Int], strides: [Int], interleaveLayout: NDArray.InterleaveLayout?)`](/documentation/CoreAI/InferenceFunction/AsyncMutableValue/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.

### Accessing an async mutable value

[`var ndArray: NDArray?`](/documentation/CoreAI/InferenceFunction/AsyncMutableValue/ndArray)

Consume this value to access the underlying NDArray once any pending write is complete.

[`var pixelBuffer: CVMutablePixelBuffer?`](/documentation/CoreAI/InferenceFunction/AsyncMutableValue/pixelBuffer)

Consume this value to access the underlying pixel buffer once any pending write is complete.



---

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)