fuel_dispatch/lib.rs
1// SPDX-License-Identifier: MIT OR Apache-2.0
2//! # fuel-dispatch
3//!
4//! Dispatch infrastructure for fuel — extracted from fuel-storage
5//! 2026-05-31 per the picker-work phasing
6//! ([docs/session-prompts/dispatch-move-to-fuel-core.md](
7//! ../../docs/session-prompts/dispatch-move-to-fuel-core.md)).
8//!
9//! ## What lives here
10//!
11//! - **`KernelBindingTable` + registration wrappers** — backends
12//! register their per-`(op, dtypes, BackendId)` kernels into a
13//! process-wide table. The picker / optimizer queries this table
14//! to enumerate candidate alternatives at each graph decision point.
15//! - **`CompiledNode` + `compile_node`** — the dispatch-time
16//! `(KernelRef, KernelCaps, OpParams)` resolution result that the
17//! executor invokes.
18//! - **`ExecutionPlan` + `compile_plan` + `PlanOptions`** — Phase
19//! 1.5 reshape of the plan-time picker around per-decision-point
20//! `AlternativeSet`s. Replaced the pre-1.5 `NodeKernelBinding`/
21//! `TolerancePolicy`/`resolve_kernel` triple (which had zero
22//! executor consumers; the verified-empty consumer list let the
23//! rewrite ship without breakage).
24//! - **`FusedKernelRegistry`** + `PrecisionGuarantee` +
25//! `KernelRevisionHash` — fused-op dispatch substrate.
26//! - **`PipelinedExecutor`** — the production executor that walks a
27//! graph, calls `compile_node` per kernel-bearing node, and runs
28//! the resolved `KernelRef` against the input/output Storage Arcs.
29//! - **Cost functions** — Layer-1 static cost estimates per op
30//! family; the optimizer composes these along candidate routes.
31//! - **Cast fusion rule** — cast-elision graph rewrite (lives near
32//! dispatch because it inspects binding-table coverage).
33//!
34//! ## What's NOT here
35//!
36//! - `BackendStorage` enum + `Storage` wrapper — stays in `fuel-storage`
37//! until retired via Phase 0.2c (move to `fuel-core-types`).
38//! - `SystemTopology` + `Judge` + `ProbeReport` — stays in `fuel-core`
39//! today; Phase 1's optimizer ranker will decide whether to relocate.
40//! - Backend-specific kernels themselves — those live in their backend
41//! crates (fuel-cpu-backend, fuel-cuda-backend, fuel-vulkan-backend).
42//! This crate hosts the dispatch *wrappers* that bridge erased
43//! `Storage` ↔ typed backend storage.
44
45// GAP-229: `clippy::identity_op` fires 128x across fuel-core+fuel-dispatch and is a
46// defect in 0 of 128 — it measures a house idiom, not debt, so it is allowed at the
47// crate root (a MEASURED claim: "identity ops in THIS crate are intentional"; a firing
48// in a third crate is a deliberate TRIPWIRE — it reds the gate so someone looks and rules).
49// Two intentional classes:
50// * DOC-INDEX: an explicit `0 *`/`1 *` NAMES an index (`idx[i*nb + 0]`, `got[1*head_dim + j]`);
51// the `0 *` partner is separately load-bearing (CLAUDE.md: never delete it), so its `1 *`
52// sibling must survive too — auto-fixing it would strand a bare unexplained `0 *`.
53// * DOC-SHAPE: an explicit unit/batch dim in a shape product (`1 * C * H * W`) mirrors
54// `Shape::from_dims(&[1, C, H, W])`.
55// RESIDUAL, named not gated: this ALSO hides FLOAT identity ops, where `x + 0.0` normalizes
56// -0.0 -> +0.0 — a real hazard whose population is ZERO today (measured). A float identity op
57// landing later is silently admitted; re-measure at the next rust-toolchain.toml pin bump
58// (owner-tracked, docs/gaps.md GAP-229) and drop this allow if precision is no longer 0/N.
59// GAP-242. `fuel_memory::BackendStorage` gates EVERY non-CPU variant behind a
60// feature -- `Cuda` on `cuda`, `Vulkan` on `vulkan`, `Metal` on `metal` plus an
61// Apple target -- so with all backend features OFF the enum has exactly ONE
62// variant and every `if let BackendStorage::Cpu(..)` in this crate is
63// irrefutable BY CONSTRUCTION rather than by mistake.
64//
65// MEASURED at head 2026-08-27, `cargo clippy -p fuel-dispatch --all-targets`:
66// 109 sites, ALL of them `BackendStorage::Cpu`
67// 103 pipelined.rs · 2 compiled.rs · 2 kernel.rs · 1 residency.rs
68// 1 dispatch.rs -- every one in `src/`, so this crate attribute
69// reaches all of them
70// 0 sites under `--features vulkan --all-targets`
71// The class is ABSENT when any backend feature is on, not merely quieter, and
72// the site count is re-derivable from those two commands.
73//
74// NOT REWRITTEN, deliberately. There is no correctness gain, and the enum's
75// arity is `cfg`-controlled: an edit that is correct for the configuration it
76// was compiled in can break a different feature set. `--fix` on this lint
77// rewrites control flow, which is exactly that hazard.
78//
79// NOT `#[expect]`, and the reason is specific to this lint rather than
80// inherited: an expectation must be fulfilled in EVERY compilation, and this
81// class does not fire at all under any backend feature (measured: 0). A crate
82// `#[expect(irrefutable_let_patterns)]` would therefore be UNFULFILLED on every
83// build that enables `vulkan` or `cuda` -- including CI's `--workspace` job,
84// which enables `fuel-dispatch/vulkan`. It would trade 109 warnings in one
85// configuration for 1 in all the others.
86//
87// This allow is honest only because CI now runs a DEFAULT-FEATURES
88// `clippy -p fuel-dispatch --all-targets` leg. Without that leg it would
89// silence a lint no gate was running; with it, it is a documented exception
90// inside a gate that is watching. Those are different artifacts wearing the
91// same syntax.
92//
93// `unreachable_patterns` rides along for the SAME reason and is the stronger
94// case of the two. `pipelined.rs:8969` is a `match` on `BackendStorage` with a
95// `Cpu(c) => ..` arm and a `_ => panic!("expected CPU output")` catch-all; with
96// the enum single-variant the `_` is unreachable. But that arm is REQUIRED the
97// moment any backend feature is on -- "fixing" the lint means deleting it,
98// which breaks the `vulkan` build outright. Measured: 1 site at default
99// features, 0 under `--features vulkan --all-targets`.
100#![allow(irrefutable_let_patterns)]
101#![allow(unreachable_patterns)]
102#![allow(clippy::identity_op)]
103
104pub mod cast_fusion;
105pub mod compiled;
106mod conv_epilogue;
107mod conv_epilogue_pathfinder;
108pub mod cost;
109#[cfg(all(test, feature = "cuda"))]
110pub(crate) mod cuda_test_kernels;
111pub mod decode_flash;
112#[cfg(feature = "dev-tools")]
113#[doc(hidden)]
114pub mod dev_tools;
115pub mod device_budget;
116pub mod device_registry;
117pub mod dispatch;
118pub mod driver;
119pub mod fkc;
120pub mod fused;
121pub mod fused_cost;
122#[cfg(feature = "jit")]
123pub mod jit_adopt;
124#[cfg(feature = "jit")]
125pub mod jit_carrier;
126#[cfg(feature = "jit")]
127mod jit_ingest;
128#[cfg(feature = "jit")]
129pub use jit_ingest::{
130 CandidateKernel, FlagReport, IngestOutcome, IngestionConfig, IngestionService,
131 ProviderFeedback, RejectionReport,
132};
133#[cfg(all(feature = "jit", any(feature = "cuda", test)))]
134mod jit_ingest_probe;
135/// Hidden, semver-exempt re-exports of private JIT/probe items for the live CUDA tests that moved to
136/// `fuel-cuda-dispatch/tests` (GAP-418). Not part of the supported API.
137#[cfg(all(feature = "dev-tools", feature = "jit", feature = "cuda"))]
138#[doc(hidden)]
139pub mod jit_test_exports {
140 pub use crate::fkc::verify::{HostTensor, fill_deterministic};
141 pub use crate::jit_ingest::{VerifyVerdict, ingest_one, verify_candidate};
142 pub use crate::jit_ingest_probe::{reference_from_registered_recipe, reference_output};
143
144 /// `pipelined::op_to_op_kind` (crate-private): the binding-table kind of a graph op.
145 pub fn op_to_op_kind(op: &fuel_graph::Op) -> Option<fuel_ir::dispatch::OpKind> {
146 crate::pipelined::op_to_op_kind(op)
147 }
148}
149pub mod judge_cache;
150pub mod judge_report_path;
151pub mod kernel;
152#[cfg(feature = "jit")]
153#[cfg(test)]
154mod kiss_corpus;
155pub mod optimize;
156pub mod optimizer_trace;
157pub mod pipelined;
158pub mod plan;
159#[cfg(feature = "jit")]
160pub mod probe_device;
161pub mod ranker;
162pub mod region_pathfinder;
163pub mod residency;
164pub mod runtime_fused_arm;
165pub mod runtime_fused_kernels;
166pub mod runtime_fused_pathfinder;
167#[cfg(feature = "telemetry")]
168pub mod telemetry;
169pub mod topology;
170pub mod variant_bake;
171
172pub use compiled::{
173 CompiledNode, Completion, CompletionHandle, compile_node, dispatched_kernel_ident,
174 execute_compiled,
175};
176pub use driver::{
177 FrontierConvergenceOptimizer, OptimizationContext, Optimizer, PassRegistry, Pathfinder,
178 PlacementForkPathfinder,
179};
180pub use kernel::{KernelBindingTable, KernelDTypes, KernelRef, OpParams};
181pub use optimize::{OptimizedGraph, optimize_graph};
182pub use pipelined::PipelinedExecutor;
183pub use plan::{ExecutionPlan, PlanOptions, compile_plan};
184pub use ranker::{
185 AccuracyBound, AccuracyPreferenceFilter, AlternativeFilter, AlternativeSet, Candidate,
186 CapabilitiesLookup, CouplingAdjustment, DEFAULT_ACCURACY_BOUND, FilterClass, FilterContext,
187 HashMapJudge, JudgeOracle, KEEP_PER_DEVICE, PrecisionFloorFilter, PrecisionRequirement,
188 StridedInputPreferenceFilter, TransferEstimator, apply_filter_chain,
189 apply_inbound_transfer_costs, composite_ns, compute_static_costs, default_chain,
190 enumerate_candidates,
191};
192pub use residency::{
193 EvictReload, EvictionOutcome, LiveRange, ResidencyPlanner, ResidencyReport,
194 insert_residency_evictions,
195};