Skip to main content

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}")

Release files for akida-ort 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for akida-ort 1.0.0
File Interpreter ABI Platform
akida_ort-1.0.0-cp312-cp312-manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ x86-64 Details
akida_ort-1.0.0-cp311-cp311-manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.28+ x86-64 Details
akida_ort-1.0.0-cp310-cp310-manylinux_2_28_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.28+ x86-64 Details

Total release size: 24.3 MB

Release files / akida_ort-1.0.0-cp312-cp312-manylinux_2_28_x86_64.whl

Download URL akida_ort-1.0.0-cp312-cp312-manylinux_2_28_x86_64.whl
Size 8.1 MB
Tags CPython 3.12 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
0401fbe9a99fb8b33dede729cd24fd359223d55e18e9db6c1680b63ad7844dd4
BLAKE2b-256 checksum
How to use checksums
c660b8d2edb56715dae7f33b8a84a80c0d45ea4d51f01307055204e6d15a7524
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.11.9

Release files / akida_ort-1.0.0-cp311-cp311-manylinux_2_28_x86_64.whl

Download URL akida_ort-1.0.0-cp311-cp311-manylinux_2_28_x86_64.whl
Size 8.1 MB
Tags CPython 3.11 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
b2fa5d975ba993cfff6eb5acea3cfb4021e036e14dd7cf06871210b6daf0e392
BLAKE2b-256 checksum
How to use checksums
97abd6e068a0ff5f5713c7db07f495f6b5264ddf21f17ec866ae9ca99d61eb5d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.11.9

Release files / akida_ort-1.0.0-cp310-cp310-manylinux_2_28_x86_64.whl

Download URL akida_ort-1.0.0-cp310-cp310-manylinux_2_28_x86_64.whl
Size 8.1 MB
Tags CPython 3.10 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
c73bc2a5286b1f55472758da22ab2f13fadb871218bdabb70320598dc1fdcf5a
BLAKE2b-256 checksum
How to use checksums
bb2208a1a585d56170575c50012c2c1e035eea2af1d3f051f6cab6ddc2a4e42c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.11.9

Release history Release notifications | RSS feed

This release

1.0.0 This release

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page