ONNX Interface for Framework Integration (ONNXIFI)
ONNXIFI is a cross-platform API for loading and executing ONNX graphs on optimized backends. High-level frameworks and applications can use this API to execute neural network and machine learning models. Hardware vendors can implement this API to expose specialized hardware accelerators and highly optimized software infrastructure to the users.
- Standardized interface for neural network inference on special-purpose accelerators (NPUs), CPUs, GPUs, DSPs, and FPGAs
- Based on widely supported technologies
- C API for function calls
- ONNX format for passing model graphs
- NCHW tensor layout for passing inputs and outputs
- Dynamic discovery of available backends for model execution
- Multiple backends from different vendors can co-exist on the same system
- Dynamic discovery of supported ONNX Operators on each backend
- Graphs with variable-shape inputs and/or outputs
- Graphs with data-dependendent output shapes
How to Use ONNX Interface for Framework Integration
- (Optional) Use
onnxifi_loadto dynamically load the ONNX Interface for Framework Integration library.
onnxGetBackendIDsto get stable identifiers of available backends. Note: it is possible there are no backends installed in the system.
onnxGetBackendInfoto check additional information about any available backend.
onnxGetBackendCompatibilityto check which operations within your model can run on the backend.
onnxInitBackendto initialize a backend, then call
onnxInitGraphto offload one or more model graphs to the backend.
onnxSetGraphIOto set locations and shapes for inputs and outputs of a graph.
- Initialize an
inputFencestructure of type
ONNXIFI_SYNCHRONIZATION_EVENT, and call
onnxInitEventto initiaze the
- Initialize an
outputFencestructure of type
onnxRunGraphwith the initialized
outputFencestructures to enable execution of the graph. The call to
eventmember of the
outputFencewith a newly created event object, asynchronously execute the graph once
eventis signalled, and then signal the
inputFenceto signal to the backend that the inputs are ready to be consumed.
onnxWaitEvent(alternatively, repeatedly call
onnxGetEventStatein a loop until the event state is
outputFenceto wait until graph outputs are ready to be consumed. Release events for inputs and outputs using
- If your model works with fixed-size inputs and outputs, and shape and location of inputs and outputs does not change, one call to
onnxSetGraphIOis sufficient for multiple
onnxRunGraphcalls. The previous call to
onnxRunGraph, however, must have finished before a user calls
onnxRunGraphagain, because concurrent execution with the same input and output locations is not allowed. For models with variable-size inputs or outputs, you'd need to call
- When done using the model, release the model graph(s) with
onnxReleaseGraph, then release the backend with
onnxReleaseBackendand backend ID with
How to Implement ONNX Interface for Framework Integration
The minimum functionality an ONNXIFI implementation must provide is the following:
- Support ONNX 1.0 model format.
- There is no minimum list of Operators a backed has to support.
- Support graph inputs / outputs in CPU memory.
- Support graph inputs / outputs with fixed shape, specified in GraphProto message.
Vendor-provided libraries should adhere to some rules to ensure discovery by ONNX-supported frameworks and applications:
- The libraries must be installed in the following directories:
- GNU/Linux: user-installed system library directory (typically /usr/lib)
- macOS: /opt/onnx/lib
- Windows: system directory (typically C:\Windows\System32)
- Filenames of vendor-specific libraries must follow the rule below:
- On Windows, library filename must match wildcard
- On macOS, library filename must match wildcard
- On Linux and other OSes, library filename must match wildcard
Hardware vendors are welcome to add their own extensions to ONNX backend interface. The backend interface offers several extension mechanisms:
- Experimental, exotic, or vendor-specific operators can be supported in a private domain using NodeProto.domain attribute.
- Vendor-provided ONNXIFI implementation can expose additional functions