BNNS
Implement and run neural networks for training and inference.
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:_:)BNNSGraph.BuilderBNNSGraph.Builder.TensorSupporting real-time ML inference on the CPU
Creating and executing graphs in Swift
Compiling a graph object
Specifying and querying compilation options
bnns_graph_compile_options_tBNNSGraphCompileOptionsMakeDefault()BNNSGraphCompileOptionsDestroy(_:)BNNSGraphCompileOptionsSetOutputPath(_:_:)BNNSGraphCompileOptionsGetOutputPath(_:)BNNSGraphCompileOptionsSetOutputFD(_:_:)BNNSGraphCompileOptionsGetOutputFD(_:)BNNSGraphCompileOptionsSetTargetSingleThread(_:_:)BNNSGraphCompileOptionsGetTargetSingleThread(_:)BNNSGraphCompileOptionsSetOptimizationPreference(_:_:)BNNSGraphCompileOptionsGetOptimizationPreference(_:)BNNSGraphOptimizationPreferenceBNNSGraphCompileOptionsSetGenerateDebugInfo(_:_:)BNNSGraphCompileOptionsGetGenerateDebugInfo(_:)BNNSTargetSystemGeneric
Specifying a graph’s compile-time message callback
BNNSGraphCompileOptionsSetMessageLogMask(_:_:)BNNSGraphContextSetMessageLogMask(_:_:)BNNSGraphMessageLevelBNNSGraphCompileOptionsSetMessageLogCallback(_:_:_:)bnns_graph_compile_message_fn_tbnns_user_message_data_t
Querying a graph’s properties
BNNSGraphGetArgumentIntents(_:_:_:_:)BNNSGraphArgumentIntentBNNSGraphGetArgumentCount(_:_:)BNNSGraphGetArgumentNames(_:_:_:_:)BNNSGraphGetFunctionCount(_:)BNNSGraphGetFunctionNames(_:_:_:)BNNSGraphGetInputCount(_:_:)BNNSGraphGetInputNames(_:_:_:_:)BNNSGraphGetOutputCount(_:_:)BNNSGraphGetOutputNames(_:_:_:_:)BNNSGraphGetArgumentPosition(_:_:_:)BNNSGraphGetArgumentInterleaveFactors(_:_:_:_:_:)
Creating and destroying a context
bnns_graph_context_tBNNSGraphContextMake(_:)BNNSGraphContextMakeStreaming(_:_:_:_:)BNNSGraphContextDestroy(_:)
Specifying and querying a context’s properties
BNNSGraphContextSetStreamingAdvanceCount(_:_:)BNNSGraphContextSetArgumentType(_:_:)BNNSGraphArgumentTypeBNNSGraphContextSetDynamicShapes(_:_:_:_:)bnns_graph_shape_tBNNSGraphContextSetBatchSize(_:_:_:)BNNSGraphContextEnableNanAndInfChecks(_:_:)BNNSGraphContextGetWorkspaceSize(_:_:)BNNSGraphContextSetStreamingAdvanceCount(_:_:)
Specifying a context’s execute-time message callback
BNNSGraphContextSetMessageLogCallback(_:_:_:)bnns_graph_execute_message_fn_tBNNSGraphMessageLevelbnns_user_message_data_t
Specifying a context’s allocation callbacks
BNNSGraphContextSetWorkspaceAllocationCallback(_:_:_:_:_:)BNNSGraphContextSetOutputAllocationCallback(_:_:_:_:_:)bnns_graph_realloc_fn_tbnns_graph_free_all_fn_t
Specifying and querying a tensor’s properties
BNNSTensorBNNSTensorGetAllocationSize(_:)BNNSGraphContextGetTensor(_:_:_:_:_:)BNNSGraphTensorFillStrides(_:_:_:_:)
Executing a graph
Enumerations
Structures
BNNSDataTypeBNNSSparsityParametersBNNSSparsityTypeBNNSTargetSystembnns_graph_argument_tBNNSImageStackDescriptorBNNSVectorDescriptor