---
title: BNNS
framework: accelerate
role: collectionGroup
role_heading: API Collection
path: accelerate/bnns-library
---

# BNNS

Implement and run neural networks for training and inference.

## Overview

Overview The Accelerate framework’s BNNS library is a collection of functions that you use to construct neural networks for training and inference. BNNS provides routines optimized for high performance and low energy consumption across all Apple platforms. The BNNSGraph API provides the means to build CPU based neural networks from the mlmodelc file that Xcode compiles from an ML package. BNNSGraph allows the BNNS library to execute entire networks rather than individual layers. By considering the full model, BNNS can apply graph-level optimizations such as omitting unnecessary copy operations, fusing computational kernels, and avoiding computing redundant information. Furthermore, BNNS can optimize data layouts for constant data — such as convolution weights — and this allows the fastest execution on specific hardware. These optimizations can represent significant performance and energy-efficiency improvements.

## Topics

### Building graphs in Swift

- [makeContext(options:_:)](accelerate/bnnsgraph/makecontext(options:_:).md)
- [BNNSGraph.Builder](accelerate/bnnsgraph/builder.md)
- [BNNSGraph.Builder.Tensor](accelerate/bnnsgraph/builder/tensor.md)
- [Supporting real-time ML inference on the CPU](accelerate/supporting-real-time-ml-inference-on-the-cpu.md)

### Creating and executing graphs in Swift

- [BNNSGraph.Context](accelerate/bnnsgraph/context.md)

### Compiling a graph object

- [bnns_graph_t](accelerate/bnns_graph_t.md)
- [BNNSGraphCompileFromFile(_:_:_:)](accelerate/bnnsgraphcompilefromfile(_:_:_:).md)

### Specifying and querying compilation options

- [bnns_graph_compile_options_t](accelerate/bnns_graph_compile_options_t.md)
- [BNNSGraphCompileOptionsMakeDefault()](accelerate/bnnsgraphcompileoptionsmakedefault().md)
- [BNNSGraphCompileOptionsDestroy(_:)](accelerate/bnnsgraphcompileoptionsdestroy(_:).md)
- [BNNSGraphCompileOptionsSetOutputPath(_:_:)](accelerate/bnnsgraphcompileoptionssetoutputpath(_:_:).md)
- [BNNSGraphCompileOptionsGetOutputPath(_:)](accelerate/bnnsgraphcompileoptionsgetoutputpath(_:).md)
- [BNNSGraphCompileOptionsSetOutputFD(_:_:)](accelerate/bnnsgraphcompileoptionssetoutputfd(_:_:).md)
- [BNNSGraphCompileOptionsGetOutputFD(_:)](accelerate/bnnsgraphcompileoptionsgetoutputfd(_:).md)
- [BNNSGraphCompileOptionsSetTargetSingleThread(_:_:)](accelerate/bnnsgraphcompileoptionssettargetsinglethread(_:_:).md)
- [BNNSGraphCompileOptionsGetTargetSingleThread(_:)](accelerate/bnnsgraphcompileoptionsgettargetsinglethread(_:).md)
- [BNNSGraphCompileOptionsSetOptimizationPreference(_:_:)](accelerate/bnnsgraphcompileoptionssetoptimizationpreference(_:_:).md)
- [BNNSGraphCompileOptionsGetOptimizationPreference(_:)](accelerate/bnnsgraphcompileoptionsgetoptimizationpreference(_:).md)
- [BNNSGraphOptimizationPreference](accelerate/bnnsgraphoptimizationpreference.md)
- [BNNSGraphCompileOptionsSetGenerateDebugInfo(_:_:)](accelerate/bnnsgraphcompileoptionssetgeneratedebuginfo(_:_:).md)
- [BNNSGraphCompileOptionsGetGenerateDebugInfo(_:)](accelerate/bnnsgraphcompileoptionsgetgeneratedebuginfo(_:).md)
- [BNNSTargetSystemGeneric](accelerate/bnnstargetsystemgeneric.md)

### Specifying a graph’s compile-time message callback

- [BNNSGraphCompileOptionsSetMessageLogMask(_:_:)](accelerate/bnnsgraphcompileoptionssetmessagelogmask(_:_:).md)
- [BNNSGraphContextSetMessageLogMask(_:_:)](accelerate/bnnsgraphcontextsetmessagelogmask(_:_:).md)
- [BNNSGraphMessageLevel](accelerate/bnnsgraphmessagelevel.md)
- [BNNSGraphCompileOptionsSetMessageLogCallback(_:_:_:)](accelerate/bnnsgraphcompileoptionssetmessagelogcallback(_:_:_:).md)
- [bnns_graph_compile_message_fn_t](accelerate/bnns_graph_compile_message_fn_t.md)
- [bnns_user_message_data_t](accelerate/bnns_user_message_data_t.md)

### Querying a graph’s properties

- [BNNSGraphGetArgumentIntents(_:_:_:_:)](accelerate/bnnsgraphgetargumentintents(_:_:_:_:).md)
- [BNNSGraphArgumentIntent](accelerate/bnnsgraphargumentintent.md)
- [BNNSGraphGetArgumentCount(_:_:)](accelerate/bnnsgraphgetargumentcount(_:_:).md)
- [BNNSGraphGetArgumentNames(_:_:_:_:)](accelerate/bnnsgraphgetargumentnames(_:_:_:_:).md)
- [BNNSGraphGetFunctionCount(_:)](accelerate/bnnsgraphgetfunctioncount(_:).md)
- [BNNSGraphGetFunctionNames(_:_:_:)](accelerate/bnnsgraphgetfunctionnames(_:_:_:).md)
- [BNNSGraphGetInputCount(_:_:)](accelerate/bnnsgraphgetinputcount(_:_:).md)
- [BNNSGraphGetInputNames(_:_:_:_:)](accelerate/bnnsgraphgetinputnames(_:_:_:_:).md)
- [BNNSGraphGetOutputCount(_:_:)](accelerate/bnnsgraphgetoutputcount(_:_:).md)
- [BNNSGraphGetOutputNames(_:_:_:_:)](accelerate/bnnsgraphgetoutputnames(_:_:_:_:).md)
- [BNNSGraphGetArgumentPosition(_:_:_:)](accelerate/bnnsgraphgetargumentposition(_:_:_:).md)
- [BNNSGraphGetArgumentInterleaveFactors(_:_:_:_:_:)](accelerate/bnnsgraphgetargumentinterleavefactors(_:_:_:_:_:).md)

### Creating and destroying a context

- [bnns_graph_context_t](accelerate/bnns_graph_context_t.md)
- [BNNSGraphContextMake(_:)](accelerate/bnnsgraphcontextmake(_:).md)
- [BNNSGraphContextMakeStreaming(_:_:_:_:)](accelerate/bnnsgraphcontextmakestreaming(_:_:_:_:).md)
- [BNNSGraphContextDestroy(_:)](accelerate/bnnsgraphcontextdestroy(_:).md)

### Specifying and querying a context’s properties

- [BNNSGraphContextSetStreamingAdvanceCount(_:_:)](accelerate/bnnsgraphcontextsetstreamingadvancecount(_:_:).md)
- [BNNSGraphContextSetArgumentType(_:_:)](accelerate/bnnsgraphcontextsetargumenttype(_:_:).md)
- [BNNSGraphArgumentType](accelerate/bnnsgraphargumenttype.md)
- [BNNSGraphContextSetDynamicShapes(_:_:_:_:)](accelerate/bnnsgraphcontextsetdynamicshapes(_:_:_:_:).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)

### Specifying a context’s execute-time message callback

- [BNNSGraphContextSetMessageLogCallback(_:_:_:)](accelerate/bnnsgraphcontextsetmessagelogcallback(_:_:_:).md)
- [bnns_graph_execute_message_fn_t](accelerate/bnns_graph_execute_message_fn_t.md)
- [BNNSGraphMessageLevel](accelerate/bnnsgraphmessagelevel.md)
- [bnns_user_message_data_t](accelerate/bnns_user_message_data_t.md)

### Specifying a context’s allocation callbacks

- [BNNSGraphContextSetWorkspaceAllocationCallback(_:_:_:_:_:)](accelerate/bnnsgraphcontextsetworkspaceallocationcallback(_:_:_:_:_:).md)
- [BNNSGraphContextSetOutputAllocationCallback(_:_:_:_:_:)](accelerate/bnnsgraphcontextsetoutputallocationcallback(_:_:_:_:_:).md)
- [bnns_graph_realloc_fn_t](accelerate/bnns_graph_realloc_fn_t.md)
- [bnns_graph_free_all_fn_t](accelerate/bnns_graph_free_all_fn_t.md)

### Specifying and querying a tensor’s properties

- [BNNSTensor](accelerate/bnnstensor.md)
- [BNNSTensorGetAllocationSize(_:)](accelerate/bnnstensorgetallocationsize(_:).md)
- [BNNSGraphContextGetTensor(_:_:_:_:_:)](accelerate/bnnsgraphcontextgettensor(_:_:_:_:_:).md)
- [BNNSGraphTensorFillStrides(_:_:_:_:)](accelerate/bnnsgraphtensorfillstrides(_:_:_:_:).md)

### Executing a graph

- [BNNSGraphContextExecute(_:_:_:_:_:_:)](accelerate/bnnsgraphcontextexecute(_:_:_:_:_:_:).md)
- [BNNSGraphArgumentType](accelerate/bnnsgraphargumenttype.md)

### Enumerations

- [BNNS](accelerate/bnns.md)
- [BNNSGraph](accelerate/bnnsgraph.md)

### Structures

- [BNNSDataType](accelerate/bnnsdatatype.md)
- [BNNSSparsityParameters](accelerate/bnnssparsityparameters.md)
- [BNNSSparsityType](accelerate/bnnssparsitytype.md)
- [BNNSTargetSystem](accelerate/bnnstargetsystem.md)
- [bnns_graph_argument_t](accelerate/bnns_graph_argument_t.md)
- [BNNSImageStackDescriptor](accelerate/bnnsimagestackdescriptor.md)
- [BNNSVectorDescriptor](accelerate/bnnsvectordescriptor.md)

### Protocols

- [BNNSScalar](accelerate/bnnsscalar.md)

### Macros

- [BNNS_MAX_TENSOR_DIMENSION](accelerate/bnns_max_tensor_dimension.md)

### Deprecated symbols

- [Classic BNNS API](accelerate/classic-bnns-api.md)

## See Also

### Neural Networks

- [Training a neural network to recognize digits](accelerate/training-a-neural-network-to-recognize-digits.md)
