Akida ONNX Runtime
Project description
Akida Custom Operators for Onnx Runtime
Custom ONNX Runtime operators for Akida neural network hardware acceleration.
Overview
This project provides custom ONNX operators that enable execution of neural network models on Brainchip Akida hardware through ONNX Runtime. It supports both INT8 and INT32 output types with 2 custom operators AkidaOpInt8 and AkidaOpInt32.
Requirements
Hardware
- Akida-compatible device (FPGA v2)
Software
- ONNX Runtime 1.23.0 (automatically downloaded during build)
- Akida Python package
Installation
1. Build from Source
# Clone the repository
git clone <repository-url>
cd AkidaORT
# Build the custom operator library
./build_akida_ort.sh python3.11
# The compiled library will be available at:
# build/akida_ort_lib.so
# The wheel will be available at:
# dist/akida_ort-*.whl
2. Install Package
# Install from wheel
pip install dist/akida_ort-*.whl
Usage
Basic Example with AkidaOpInt8
import numpy as np
import onnx
import onnxruntime as ort
import akida
import akida_ort
# 1. Create and compile your Akida model
model = akida.Model()
model.add(akida.InputConv2D((64, 64, 3), kernel_size=3, filters=16))
model.add(akida.Conv2D(kernel_size=3, filters=32, activation=akida.ActivationType.ReLU))
model.add(akida.Dense1D(units=10, output_bits=8)) # output_bits == 8 then use AkidaOpInt8
# 2. Map to hardware (first device found) and save program
hw_model = akida.Model(model.layers)
hw_model.map(akida.devices()[0], hw_only=True)
program = hw_model.sequences[0].program
# Save the binary program to send it to the operator
with open("program.bin", "wb") as f:
f.write(program)
# 3. Create ONNX model with AkidaOpInt8 operator
onnx_model = onnx.parser.parse_model("""
<ir_version: 8, opset_import: ["com.brainchip": 1]>
model (uint8[1, 64, 64, 3] X) => (int8[1, ?, ?, ?] Y)
{
Y = com.brainchip.AkidaOpInt8<program_path="program.bin">(X)
}
""")
# 4. Run inference with ONNX Runtime
so = ort.SessionOptions()
so.register_custom_ops_library(akida_ort.get_library_path())
sess = ort.InferenceSession(
onnx_model.SerializeToString(),
so,
providers=["CPUExecutionProvider"]
)
# 5. Execute inference
inputs = {"X": np.random.randint(0, 255, (1, 64, 64, 3), dtype=np.uint8)}
outputs = sess.run(None, inputs)
print(f"Output shape: {outputs[0].shape}, dtype: {outputs[0].dtype}")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file akida_ort-1.0.0-cp312-cp312-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: akida_ort-1.0.0-cp312-cp312-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 8.1 MB
- Tags: CPython 3.12, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0401fbe9a99fb8b33dede729cd24fd359223d55e18e9db6c1680b63ad7844dd4
|
|
| MD5 |
9c85c7548fbf304a1aa76e366821a821
|
|
| BLAKE2b-256 |
c660b8d2edb56715dae7f33b8a84a80c0d45ea4d51f01307055204e6d15a7524
|
File details
Details for the file akida_ort-1.0.0-cp311-cp311-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: akida_ort-1.0.0-cp311-cp311-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 8.1 MB
- Tags: CPython 3.11, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b2fa5d975ba993cfff6eb5acea3cfb4021e036e14dd7cf06871210b6daf0e392
|
|
| MD5 |
79b75ecdba5a3ddb3563d01c9b2971a4
|
|
| BLAKE2b-256 |
97abd6e068a0ff5f5713c7db07f495f6b5264ddf21f17ec866ae9ca99d61eb5d
|
File details
Details for the file akida_ort-1.0.0-cp310-cp310-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: akida_ort-1.0.0-cp310-cp310-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 8.1 MB
- Tags: CPython 3.10, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c73bc2a5286b1f55472758da22ab2f13fadb871218bdabb70320598dc1fdcf5a
|
|
| MD5 |
6c30bbcf43256532678b9f9ed3768b57
|
|
| BLAKE2b-256 |
bb2208a1a585d56170575c50012c2c1e035eea2af1d3f051f6cab6ddc2a4e42c
|