Skip to main content

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 baracuda_dispatch;
105pub mod cast_fusion;
106pub mod compiled;
107pub mod cost;
108pub mod decode_flash;
109#[cfg(feature = "dev-tools")]
110#[doc(hidden)]
111pub mod dev_tools;
112pub mod dispatch;
113pub mod driver;
114pub mod fkc;
115pub mod fused;
116pub mod fused_cost;
117#[cfg(feature = "jit")]
118pub mod jit_adopt;
119#[cfg(feature = "jit")]
120pub mod jit_carrier;
121#[cfg(all(feature = "jit", feature = "cuda"))]
122pub mod jit_cuda_load;
123#[cfg(feature = "jit")]
124mod jit_ingest;
125#[cfg(feature = "jit")]
126pub use jit_ingest::{
127    CandidateKernel, FlagReport, IngestOutcome, IngestionConfig, IngestionService,
128    ProviderFeedback, RejectionReport,
129};
130#[cfg(all(feature = "jit", any(feature = "cuda", test)))]
131mod jit_ingest_probe;
132pub mod judge_cache;
133pub mod judge_report_path;
134pub mod kernel;
135#[cfg(feature = "jit")]
136#[cfg(test)]
137mod kiss_corpus;
138pub mod optimize;
139pub mod pipelined;
140pub mod plan;
141pub mod ranker;
142pub mod residency;
143pub mod runtime_fused_arm;
144pub mod runtime_fused_kernels;
145pub mod runtime_fused_pathfinder;
146#[cfg(feature = "telemetry")]
147pub mod telemetry;
148pub mod topology;
149pub mod variant_bake;
150pub mod vulkan_dispatch;
151
152pub use compiled::{
153    CompiledNode, Completion, CompletionHandle, compile_node, dispatched_kernel_ident,
154    execute_compiled,
155};
156pub use driver::{
157    FrontierConvergenceOptimizer, OptimizationContext, Optimizer, PassRegistry, Pathfinder,
158    PlacementForkPathfinder,
159};
160pub use kernel::{KernelBindingTable, KernelDTypes, KernelRef, OpParams};
161pub use optimize::{OptimizedGraph, optimize_graph};
162pub use pipelined::PipelinedExecutor;
163pub use plan::{ExecutionPlan, PlanOptions, compile_plan};
164pub use ranker::{
165    AccuracyBound, AccuracyPreferenceFilter, AlternativeFilter, AlternativeSet, Candidate,
166    CapabilitiesLookup, CouplingAdjustment, DEFAULT_ACCURACY_BOUND, FilterClass, FilterContext,
167    HashMapJudge, JudgeOracle, KEEP_PER_DEVICE, PrecisionFloorFilter, PrecisionRequirement,
168    StridedInputPreferenceFilter, TransferEstimator, apply_filter_chain,
169    apply_inbound_transfer_costs, composite_ns, compute_static_costs, default_chain,
170    enumerate_candidates,
171};
172pub use residency::{
173    EvictReload, LiveRange, ResidencyPlanner, ResidencyReport, insert_residency_evictions,
174};