Expand description
§onnx-runtime-ep-cpu
The CPU execution provider for the ORT 2.0 runtime (see docs/ORT2.md §4.4
and §54 Phase 1). It implements onnx_runtime_ep_api::ExecutionProvider
and hosts pure-Rust reference kernels for the Phase-1 op set (MatMul,
Add, Relu, Reshape, Transpose, Gather, LayerNormalization).
§Backends: correctness baseline + optional oneDNN
The GEMM hot spot is served through backend::CpuBackend (docs/ORT2.md
§25.2). The default backend is a pure-Rust blocked, register-tiled,
rayon-parallelized f32 GEMM — the portable, offline correctness baseline that
compiles anywhere with no C++/FFI. The non-default onednn cargo feature
statically links oneDNN and routes the 2-D tile GEMM through dnnl_sgemm
([kernels::onednn]). Every backend lives behind the
onnx_runtime_ep_api::Kernel trait, so neither the EP contract nor the
session observes which one ran. See kernels::matmul for the hot spot.
§unsafe
The default (Generic) path is unsafe-minimal: the only unsafe is the raw
device-buffer access the ep-api contract forces (aligned host
alloc/dealloc, memcpy, and strided element reads/writes), each isolated
and SAFETY-documented, plus — only under the onednn feature — the
dnnl_sgemm FFI call, confined to [kernels::onednn]. The blocked rayon GEMM
itself contains no unsafe; all kernel arithmetic is safe Rust operating on
dense Vec<f32> buffers produced by the two audited accessors in kernels.
Re-exports§
pub use backend::CpuBackend;pub use backend::has_onednn;pub use provider::CpuExecutionProvider;pub use kernels::slice::SliceAxisPlan;pub use kernels::slice::slice_axes_steps;pub use kernels::slice::slice_plan;
Modules§
- backend
- CPU GEMM backend selection (
docs/ORT2.md§25.2 “CPU Backend Strategy”). - dtype
- Reusable dtype-generic machinery for the arithmetic CPU kernels
(
docs/ORT2.md§4.4; project preference “不同的dtype,是不是可以用 template”). - kernels
- CPU kernels for the Phase-1 BERT-on-CPU correctness milestone (
docs/ORT2.md§4.4). One [Kernel] per ONNX op, keyed purely by op type — there are no model-specific shapes or names anywhere in this crate; BERT is only the validation target. - provider
- The
CpuExecutionProvider: a host execution provider backed by pure-Rust reference kernels (docs/ORT2.md§4.4). - strided
- Strided-view access helpers shared by the CPU kernels (
docs/ORT2.md§5).
Macros§
- dispatch_
arith - Map a runtime
DataTypeto a monomorphized body over the matching Rust element type, across the full ONNX numeric set (floats + signed/unsigned integers). Binds$Tvia a localtypealias; unsupported dtypes yield a RULE #1 error. The body must evaluate toResult<()>. - dispatch_
float - Like [
dispatch_arith] but restricted to the floating-point dtypes ONNX defines transcendental / accumulate ops over (f32,f16,bf16,f64).