<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "macOS: 15.0.0 -",
    "tvOS: 18.0.0 -",
    "visionOS: 2.0.0 -",
    "watchOS: 11.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Accelerate",
  "identifier" : "/documentation/Accelerate/BNNSGraphContextMakeStreaming(_:_:_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "c:@F@BNNSGraphContextMakeStreaming"
  },
  "title" : "BNNSGraphContextMakeStreaming(_:_:_:_:)"
}
-->

# BNNSGraphContextMakeStreaming(_:_:_:_:)

Returns an allocated and initialized graph context with streaming support from the specified graph.

```
func BNNSGraphContextMakeStreaming(_ graph: bnns_graph_t, _ function: UnsafePointer<CChar>?, _ initial_states_count: Int, _ initial_states: UnsafePointer<BNNSTensor>?) -> bnns_graph_context_t
```

## Parameters

`graph`

The compiled graph object.

`function`

The function that the new context initializes the state for. Specify as `nil` if the graph only contains one function.

`initial_states_count`

The number of elements in the `initial_states_count` array.

`initial_states`

An array of [`BNNSTensor`](/documentation/Accelerate/BNNSTensor) structures that describe the data that the context uses to initialize each state. The context uses `initial_states[i]` to intialize the state with the name `initial_state[i]->name`.

## Return Value

A compiled graph context object. If the operation fails, the graph object’s [`data`](/documentation/Accelerate/bnns_graph_context_t/data) property is `nil`.

## Discussion

In addition to the work that [`BNNSGraphContextMake(_:)`](/documentation/Accelerate/BNNSGraphContextMake(_:)) performs, this call allocates ring-buffer backed memory for all <doc://com.apple.documentation/documentation/CoreML> state arguments of the given function.

If your model runs on a stream of data, such as processing audio data, it may benefit from working on one frame at a time. You can express this functionality through a model that uses Core ML’s concept of states. In this case, BNNS stores information that the model needs from a previous frame in the state that dilations on convolution layers may require.

If your model uses the pattern below, use this function to specify that BNNS uses an optimized mode that allocates and manages ring buffers for states. Doing so eliminates memory copies associated with the approach.

```c
output_state = concat(input_state, tensorX)
```

BNNS advances the ring buffer by the size of `tensorX` in the concatenation dimension after the function executes.

To use a context with streaming support, your function must include an attribute dictionary named `BNNSOptions` that includes the entry `{ ‘StateMode’: ‘Streaming’ }`. This specifies that the [`BNNSGraphCompileFromFile(_:_:_:)`](/documentation/Accelerate/BNNSGraphCompileFromFile(_:_:_:)) function encodes additional metadata into the graph that describes the streaming rate.

Calls to [`BNNSGraphContextExecute(_:_:_:_:_:_:)`](/documentation/Accelerate/BNNSGraphContextExecute(_:_:_:_:_:_:)) that use contexts this function creates ignore any user-provided pointers for input and output arguments. Instead, context execution uses the internal ring buffer and updates any nonnull input and output arguments to point to the same ring-buffer backed memory. On return, an analysis of the compiled program for use in the next frame determines the distance by which the operation advances the ring buffer.

To prevent memory leaks, call [`BNNSGraphContextDestroy(_:)`](/documentation/Accelerate/BNNSGraphContextDestroy(_:)) when you’re finished using the graph context.

---

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)