Expand description
Kernel reference + op parameters + binding table. Phase 7.5 B1+B5.
KernelRef is the uniform function-pointer type that every
dispatch wrapper matches. Backend-specific typed kernels live in
their backend crates (e.g. fuel_cpu_backend::byte_kernels); the
wrapper functions here in fuel-storage bridge the dispatch-
erased Storage to those typed kernels by matching on
BackendStorage::Cpu(...) etc.
OpParams is the typed extras bag — one variant per op family
that needs auxiliary data beyond inputs and outputs. Most
elementwise ops use OpParams::None; reductions carry their
reduce dims; conv2d carries kernel/stride/padding; etc.
KernelBindingTable (B5) maps
(OpKind, SmallVec<[DType; N]>, BackendId) -> KernelRef. The dtype
list carries per-operand types — inputs in order, then outputs —
so mixed-precision ops (e.g. Cast: src→dst) and same-dtype ops
(e.g. Add: [T, T, T]) share the same key shape. Backends register
their dispatch wrappers via the dispatch::register_* functions;
op-builder methods consult the table at DAG construction time using
Graph::target_backend(id) as the BackendId key.
§Architecture (cycle-avoidance)
- Backend crates (
fuel-cpu-backend, …): typed kernels on their concrete storage types (CpuStorageBytes, …). No fuel-storage dependency. - fuel-storage (this crate): dispatch wrappers that match
BackendStorage::Cpu(...), extract the typed storage, and call the backend’s typed kernel. KernelBindingTable lives here. - Backend crates depend on fuel-storage? No — only the wrappers do. fuel-storage already depends on backend crates for variant types; this round-trip closes naturally.
Structs§
- Binding
Entry - One concrete kernel registered against a
(OpKind, dtypes, backend)decision-point key. Phase 7.6 step 9a: a single key now carriesSmallVec<[BindingEntry; 2]>— multiple alternatives compete at the same decision point (e.g. cuBLAS bf16 matmul + CUTLASS bf16 matmul at(MatMul, [BF16, BF16, BF16], Cuda)). The route picker (step 9b) selects among them at plan time; today’s single-impl callers (lookup,lookup_with_caps,lookup_precision,lookup_cost) return the first entry, preserving the pre-9a behavior for sites that haven’t migrated. - Kernel
Binding Table Cloneis load-bearing, not a convenience: the process-wide table is published as a copy-on-write snapshot (RwLock<Arc<KernelBindingTable>>indispatch.rs), so a writer clones the current table, mutates the clone, and swaps the pointer. Readers therefore never hold a lock guard. The clone is shallow-ish and cheap —BindingEntryisCopyand the keys areCopy/SmallVec, so it is aHashMapbulk copy of POD, on a write-rare path (backend init + runtime-fusion adoption).- Kernel
Caps - Per-binding capability flags. Today carries one flag —
strided_input— that signals “this kernel walks input strides explicitly and so can consume non-contiguous input layouts (including stride-0 broadcast axes) without auto-Contiguize materializing them first.” The executor’s contiguize gate consults this to skip the materialize step for capable kernels, so broadcast/transpose/slice layouts can reach the kernel as metadata-only views.
Enums§
- Binding
Key - The binding table’s op key — generalized so runtime-registered fused ops live in the SAME registry as static kernels (the 2026-07-08 decisions-log end-state; retires the transitional runtime-kernel sidecar).
- MatmulM
- How many rows a
OpParams::Matmulcomputes — the data-determined-M state for sparse-MoE / capacity-buffer matmuls.minOpParams::Matmulis always the row capacity (buffer/stride/size); this says how many of those rows to actually compute (<= m), the rest left zeroed. - OpParams
- Typed extras bag passed to kernels via
KernelRef. One variant per op family that needs auxiliary parameters;Nonefor parameter-less ops (most elementwise unary and binary). - Runtime
Fused Lookup - The outcome of
KernelBindingTable::unique_runtime_fused— three distinct facts, deliberately not collapsed into anOption.
Functions§
- unknown_
cost - Sentinel “no cost claim” function — returns
crate::fused::CostEstimate::default(all-zero). The fill pass (fill_unset_cpu_cost) recognizes this exact function pointer to decide which entries get the OpKind-family default.
Type Aliases§
- CostFn
- Maps
(OpKind, KernelDTypes, BackendId)triples to dispatch wrapper functions, whereKernelDTypeslists per-operand dtypes (inputs in order, then outputs). Built once at backend registration time (typically a process-wideOnceLockthough that’s not enforced here for testability), consulted at execute time via lookup. - Coverage
Binding - One entry of the coverage diagnostic:
(backend, op, operand dtypes). - KernelD
Types - Inline capacity for the per-operand dtype list in the binding-table key. 8 covers every op currently in flight without spilling to heap: PagedAttn (q + 2 caches + block_table + context_lens + alibi + out) at 7 entries is the worst case in inference; mixed-precision matmul is ≤ 4. Bumping later is one constant change.
- Kernel
Ref - Uniform function-pointer signature for per-backend op kernels.