edgefirst-hal
EdgeFirst Hardware Abstraction Layer — a unified Rust library for edge AI inference pipelines.
This is the umbrella crate that re-exports the core EdgeFirst HAL components:
edgefirst-tensor— Zero-copy tensor memory management (platform GPU buffer, SHM, PBO, system memory)edgefirst-codec— JPEG/PNG decode into pre-allocated tensorsedgefirst-image— Hardware-accelerated image processing and format conversionedgefirst-decoder— ML model output decoding (YOLOv5/v8/v11/v26, ModelPack)edgefirst-tracker— Multi-object tracking (ByteTrack)
codec and decoder sit at opposite ends of the pipeline: codec turns image
bytes into tensors, decoder turns model output tensors into detections.
Features
- Zero-copy memory management with DMA-BUF, IOSurface, AHardwareBuffer, POSIX shared memory, and PBO support
- Hardware-accelerated image processing via OpenGL, G2D (NXP i.MX), and optimized CPU
- Hardware JPEG decode via V4L2 mem2mem on Linux SoCs and nvJPEG on CUDA GPUs, each falling back to the built-in CPU decoder
- Efficient ML post-processing for object detection and segmentation models
- Int8 GPU shaders for direct signed int8 output without CPU post-processing
- Cross-platform — Linux, macOS/iOS, and Android with hardware acceleration; other Unix on CPU
Quick Start
Decode a JPEG into a tensor, then letterbox it into the shape a model wants. Both buffers are allocated once, outside the loop.
use ;
use ;
use ;
// Create an image processor (auto-selects the best backend).
let mut processor = new?;
// Allocate both buffers with create_image() — see the note below. The source
// holds the codec's native NV12 and is CPU-written by the decoder; the
// destination is the RGB the model consumes.
let mut src =
processor.create_image?;
let mut dst =
processor.create_image?;
let mut decoder = new;
// Hot loop: decode, then convert (colour + resize). The codec reports EXIF
// orientation in `info` but does not apply it — pass it to convert().
let bytes = read?;
let info = src.load_image?;
let rotation = from_degrees_clockwise;
let flip = if info.flip_horizontal else ;
processor.convert?;
Why
create_image()? Creating tensors directly withTensor::new()orTensorDyn::image()bypasses GPU memory negotiation. The processor cannot allocate PBO-backed buffers without knowing the GL context. Usecreate_image()for any tensor that will be passed toconvert().
Platform Support
| Platform | Memory Types | Image Acceleration |
|---|---|---|
| Linux (NXP i.MX8/i.MX95) | DMA-BUF, SHM, PBO, Mem | OpenGL, G2D, CPU |
| Linux (other) | DMA-BUF, SHM, PBO, Mem | OpenGL, CPU |
| macOS / iOS | IOSurface, SHM, Mem | OpenGL (ANGLE), CPU |
| Android | AHardwareBuffer, SHM, Mem | OpenGL, CPU |
| Other Unix | SHM, Mem | CPU |
| Windows | Mem | CPU |
DMA-BUF on Linux needs a mountable dma-heap and permission to use it; without
that the allocator falls back and everything still works, just with a copy.
TensorMemory::Dma names the platform's native GPU buffer on all three of
Linux, Apple, and Android, so portable code never branches on the mechanism.
Feature Flags
The following Cargo feature flags are available for edgefirst-hal:
-
ndarray(default) — Enable ndarray integration in the tensor crate. Allows converting tensors to/fromndarray::Array. -
opengl(default) — Enable the OpenGL backend for hardware-accelerated image processing. Compiled on Linux, macOS, iOS, and Android. -
tracing(default) — Enable theedgefirst_hal::tracemodule, which installs the process-wide subscriber that turns the sub-crates' spans into a Chrome/Perfetto trace file. Pulls intracing-subscriberandtracing-chrome. -
tracker(optional, not default) — Enable multi-object tracking support via ByteTrack. Enablesdraw_masks_tracked()in the image crate anddecode_tracked()in the decoder crate. Requires explicit opt-in:[] = { = "...", = ["tracker"] }
Python Bindings
This library is also available as a Python package:
See edgefirst-hal on PyPI for
Python-specific documentation.
Documentation
- Architecture overview: ARCHITECTURE.md
- Testing guide: TESTING.md
- Full API reference: docs.rs/edgefirst-hal
- Project README: README.md
- Python package: pypi.org/project/edgefirst-hal
- EdgeFirst AI
License
Licensed under the Apache License, Version 2.0. See LICENSE for details.