Rust bindings for Huawei Ascend NPUs using the HiAI (CANN) DDK on OpenHarmony — build and run neural-network graphs.
EXPERIMENTAL — NOT FOR PRODUCTION USE. The API is unstable and will change.
| Crate | Purpose |
|---|---|
hiai-rs-sys |
Raw, unsafe FFI bindings to the HiAI DDK (bindgen-generated). Internal use only. |
hiai-rs |
Safe Rust wrapper: TensorDesc + dispatch() for running prebuilt models. |
The HiAI DDK is Huawei's libhiai runtime (part of the CANN stack) for OpenHarmony devices with Ascend NPUs. This crate binds a thin pure-C adapter (hiai-rs-sys/adapter/) that wraps the DDK's C++ API (hiai::op::*, the GE graph engine, and the model manager) so it can be called from Rust.
- Graph build (WebNN → CANN IR) lives in rustnn; this crate only binds the low-level FFI and model dispatch.
- The adapter is compiled and
libhiaiis linked only when cross-compiling for OpenHarmony (aarch64-unknown-linux-ohos).
The adapter's public headers are self-contained, so bindgen runs on any host:
cargo buildRequires the Huawei CANN-Kit DDK and the OpenHarmony SDK, plus the OHOS target:
export CANN_DDK=/path/to/CANN-Kit-next/ddk/
export OHOS_SDK_NATIVE=/path/to/OpenHarmony/sdk/native
cargo build --target aarch64-unknown-linux-ohos --releaseuse hiai_rs::{TensorDesc, dispatch};
// Prebuilt offline model bytes (produced by the rustnn CANN converter).
let model_bytes: &[u8] = todo!();
let inputs = vec![TensorDesc {
data: vec![1.0f32; 4].into_iter().flat_map(|v| v.to_le_bytes()).collect(),
shape: vec![1, 4],
dtype: 0, // CANN_DT_FLOAT
}];
let mut outputs = vec![TensorDesc {
data: vec![0u8; 16],
shape: vec![1, 4],
dtype: 0,
}];
dispatch(model_bytes, &inputs, &mut outputs)?;
# Ok::<(), hiai_rs::Error>(())CANN_DDK— path to the Huawei CANN-Kit DDK (required for OpenHarmony builds).OHOS_SDK_NATIVE— path to the OpenHarmony SDK native toolchain (for theaarch64-unknown-linux-ohostarget).
The C++ adapter under hiai-rs-sys/adapter/ is a local pure-C shim over the HiAI DDK. It is licensed under Apache-2.0 (see each file's SPDX header).
Apache-2.0. See LICENSE.