Expand description
ONNX inference via the pure-Rust tract engine
(onnx feature).
The model is loaded from a byte buffer, never a path, so the identical
code path runs natively (bytes from the super::download cache) and in WASM
(bytes fetched by JavaScript and handed back in). All tensors are f32
(NCDHW for the volumetric nets); callers convert to/from the crate’s f64
volumes and handle model-specific normalization and padding.
With the parallel feature, each inference spreads tract’s matrix kernels over a thread pool:
a dedicated one natively, and rayon’s global pool on WASM (the one
wasm_bindgen_rayon::init_thread_pool sets up, once the host reports it via
[onnx::set_wasm_threads_available]). Calls from
inside a rayon worker — the tiled drivers, which already run one tile per thread — stay on the
calling thread.
On wasm32 the build must enable SIMD128 (-C target-feature=+simd128): since tract
0.23, tract-linalg registers its matmul kernels on wasm only under that target feature, so a
build without it compiles fine and then fails on the first convolution at runtime with
No matmul found. The guard below turns that into a build error instead.
use qsm_core::models::onnx::{OnnxModel, Tensor};
let model = OnnxModel::load(model_bytes)?;
let out = model.run_single(&Tensor::new(vec![1, 1, d, h, w], field))?;Structs§
- Onnx
Model - A parsed ONNX model, ready to run at any spatial size.
- Onnx
Plan - A compiled execution plan for fixed input shapes, built by
OnnxModel::plan_for. Running it skips graph optimization, so reusing one plan across many equal-shaped inputs (tiled inference) amortizes the optimizer to a single up-front cost. - Tensor
- A dense
f32tensor: row-majordatainterpreted withshape.
Enums§
- Onnx
Error - Error from loading or running an ONNX model.
Functions§
- run_
threaded 🔒 - Run one inference with tract’s matrix kernels spread over a thread pool when the
parallelfeature is on (seetract_executor). Calls made from inside a rayon worker — the tiled drivers, which already run one tile per thread — stay on the calling thread. - tract_
executor 🔒 - The executor
run_threadedinstalls, orNoneto stay on the calling thread.