---
title: "BNNSGraphContextSetDynamicShapes(_:_:_:_:)"
framework: accelerate
role: symbol
role_heading: Function
path: "accelerate/bnnsgraphcontextsetdynamicshapes(_:_:_:_:)"
---

# BNNSGraphContextSetDynamicShapes(_:_:_:_:)

Specifies the dynamic shapes for a graph and, if possible, infers, the output shapes.

## Declaration

```swift
func BNNSGraphContextSetDynamicShapes(_ context: bnns_graph_context_t, _ function: UnsafePointer<CChar>?, _ shapes_count: Int, _ shapes: UnsafeMutablePointer<bnns_graph_shape_t>) -> Int32
```

## Parameters

- `context`: The graph context.
- `function`: The function. Specify as nil if the graph only contains one function.
- `shapes_count`: The number of elements in the shapes array.
- `shapes`: An array of input and output shapes in the same order as you pass to doc://com.apple.accelerate/documentation/Accelerate/BNNSGraphContextExecute(_:_:_:_:_:_:). On input, this function reads input shapes with a nonzero rank, and uses the constant or default value from the source model for input shapes with a zero rank. The function generates an error for shapes with a nonzero value that doesn’t match the source model. On output, the function sets output shapes with a nonzero rank to the upper bounds of the expected output shape. If the function can’t deduce the output shape because it depends on the input data values, the value of shapes[idx].size[d] is zero.

## Return Value

Return Value - 0 on success if all tensor shapes were exactly determined. That is, the workspace size is exact.

## Discussion

Discussion 1 on success if one or more tensor shapes are merely bounds, but no tensor is unbounded. That is, the workspace size is bounded. 2 on success if one or more tensor shapes are unbounded and BNNS will allocate workspace memory during execution. A negative value indicates an error. Discussion Don’t call this function while existing calls to BNNSGraphContextExecute(_:_:_:_:_:_:) are running. For example, the following code sets the dynamic shapes for an example graph context, specifies the output shape, and updates the context’s required workspace size. var inputShape: [UInt64] = [1024, 1, 1] let rank = inputShape.count var outputShape = [UInt64](repeating: 0, count: rank)

let result = outputShape.withUnsafeMutableBufferPointer { output in     inputShape.withUnsafeMutableBufferPointer { input in                  var shapes = [             bnns_graph_shape_t(rank: rank, shape: output.baseAddress!),             bnns_graph_shape_t(rank:rank, shape: input.baseAddress!)         ]                  return BNNSGraphContextSetDynamicShapes(context, nil,                                                 shapes.count, &shapes)     } }      // Prints "[1024, 1, 1]". print(outputShape) On return, the output shape contains the correct size for the input shape, and a subsequent call to BNNSGraphContextGetWorkspaceSize(_:_:) returns the correct workspace size.

## See Also

### Specifying and querying a context’s properties

- [BNNSGraphContextSetStreamingAdvanceCount(_:_:)](accelerate/bnnsgraphcontextsetstreamingadvancecount(_:_:).md)
- [BNNSGraphContextSetArgumentType(_:_:)](accelerate/bnnsgraphcontextsetargumenttype(_:_:).md)
- [BNNSGraphArgumentType](accelerate/bnnsgraphargumenttype.md)
- [bnns_graph_shape_t](accelerate/bnns_graph_shape_t.md)
- [BNNSGraphContextSetBatchSize(_:_:_:)](accelerate/bnnsgraphcontextsetbatchsize(_:_:_:).md)
- [BNNSGraphContextEnableNanAndInfChecks(_:_:)](accelerate/bnnsgraphcontextenablenanandinfchecks(_:_:).md)
- [BNNSGraphContextGetWorkspaceSize(_:_:)](accelerate/bnnsgraphcontextgetworkspacesize(_:_:).md)
- [BNNSGraphContextSetStreamingAdvanceCount(_:_:)](accelerate/bnnsgraphcontextsetstreamingadvancecount(_:_:).md)
