diff --git a/architecture-baseline.json b/architecture-baseline.json index f336ae75..5a4511d5 100644 --- a/architecture-baseline.json +++ b/architecture-baseline.json @@ -3,77 +3,22 @@ "violations": [], "oversize": {}, "source": { - "allow-unused-imports:leleka-cpu-sys": 35, - "allow-unused-imports:leleka-cuda-driver": 410, "allow-unused-imports:leleka-engine-core": 18, "allow-unused-imports:leleka-engine-qwen35-cuda": 166, - "allow-unused-imports:leleka-experimental-ref": 1, - "allow-unused-imports:leleka-harmony": 2, - "allow-unused-imports:leleka-igpu": 2, - "allow-unused-imports:leleka-model-format": 22, - "allow-unused-imports:leleka-native-cpu-expert": 75, - "allow-unused-imports:leleka-tokenizer": 3, - "dyn-trait:leleka-cpu-worker": 4, "dyn-trait:leleka-cuda-driver": 45, - "dyn-trait:leleka-cuda-model": 3, "dyn-trait:leleka-engine-core": 18, "dyn-trait:leleka-engine-fake": 1, "dyn-trait:leleka-engine-qwen35-cuda": 53, - "dyn-trait:leleka-experimental-ref": 3, - "dyn-trait:leleka-gptoss": 10, - "dyn-trait:leleka-gptoss-igpu": 3, - "dyn-trait:leleka-gptoss-npu": 3, - "dyn-trait:leleka-gpu-npu-worker": 5, - "dyn-trait:leleka-memory": 12, - "dyn-trait:leleka-model-format": 8, - "dyn-trait:leleka-tokenizer": 1, - "env-read:leleka-cpu-kernels": 1, - "env-read:leleka-cpu-worker": 2, - "env-read:leleka-cuda-driver": 2, - "env-read:leleka-cuda-model": 2, "env-read:leleka-engine-qwen35-cuda": 1, - "env-read:leleka-gptoss": 1, - "env-read:leleka-gptoss-npu": 1, - "env-read:leleka-gpu-npu-worker": 2, - "env-read:leleka-igpu": 1, - "env-read:leleka-libc-shim": 3, - "env-read:leleka-memory": 2, - "env-read:leleka-memory-os": 1, - "env-read:leleka-model-format": 1, - "env-read:leleka-native-cpu-expert": 2, - "env-read:leleka-native-parity-bench": 1, - "env-read:leleka-npu-worker": 1, - "env-read:leleka-obs": 2, - "env-read:leleka-tokenizer": 2, - "glob-super-import:leleka-cuda-driver": 3, + "glob-super-import:leleka-cuda-driver": 2, "glob-super-import:leleka-engine-qwen35-cuda": 70, - "instant-now:leleka-cpu-worker": 9, "instant-now:leleka-cuda-driver": 25, "instant-now:leleka-engine-qwen35-cuda": 16, - "instant-now:leleka-gptoss": 4, - "instant-now:leleka-gptoss-igpu": 5, - "instant-now:leleka-gptoss-npu": 12, - "instant-now:leleka-gpu-npu-worker": 4, - "instant-now:leleka-igpu": 1, - "instant-now:leleka-memory": 1, - "instant-now:leleka-model-format": 10, "instant-now:leleka-native-cpu-expert": 27, - "instant-now:leleka-obs": 3, - "path-include:leleka-cuda-driver": 118, - "path-include:leleka-engine-qwen35-cuda": 1, - "path-include:leleka-model-format": 12, - "path-include:leleka-native-cpu-expert": 2, + "path-include:leleka-cuda-driver": 1, "process-global:leleka-cuda-driver": 96, - "process-global:leleka-cuda-model": 10, "process-global:leleka-engine-qwen35-cuda": 59, - "process-global:leleka-gptoss-npu": 2, - "process-global:leleka-libc-shim": 12, - "process-global:leleka-memory": 6, - "process-global:leleka-memory-os": 2, - "process-global:leleka-model-format": 8, - "process-global:leleka-native-cpu-expert": 27, - "process-global:leleka-obs": 6, - "process-global:leleka-tokenizer": 4 + "process-global:leleka-native-cpu-expert": 27 }, "mechanical_names": [] } diff --git a/architecture.json b/architecture.json index 3534a4fb..2f03f810 100644 --- a/architecture.json +++ b/architecture.json @@ -51,10 +51,90 @@ }, "_exceptions": "Sites that must stay, so the ratchet is zero outside this list (STRA-338 stage 10). Each entry: crate, file (relative to the crate directory), ratchet (a source_patterns id), reason. The file's hits of that ratchet are not counted; an entry that excuses nothing is an error.", "exceptions": [ + {"crate": "leleka-cuda-model", "file": "src/env_switch.rs", "ratchet": "env-read", "reason": "EnvSwitch is the one reader of the operator environment in this crate: it reads one named variable on the first get() and applies a typed rule"}, + {"crate": "leleka-cuda-model", "file": "src/env_switch.rs", "ratchet": "process-global", "reason": "the OnceLock inside EnvSwitch caches the switch position for the process life (an immutable operator setting; a hot path pays one atomic load)"}, + {"crate": "leleka-cuda-model", "file": "src/serving_context.rs", "ratchet": "process-global", "reason": "the serving context and the resident KV window are fixed once at engine start (configure_*) and read by every kernel geometry; injecting them through every owner is the settings follow-up of S13"}, + {"crate": "leleka-cpu-worker", "file": "src/settings.rs", "ratchet": "env-read", "reason": "the one reader of the process environment in this crate: it returns the operator's switches as typed values"}, + {"crate": "leleka-tokenizer", "file": "src/settings.rs", "ratchet": "env-read", "reason": "the one reader of the process environment in this crate: it returns the operator's switches as typed values"}, + {"crate": "leleka-gptoss-npu", "file": "src/settings.rs", "ratchet": "env-read", "reason": "the one reader of the process environment in this crate: it returns the operator's switches as typed values"}, + {"crate": "leleka-gpu-npu-worker", "file": "src/settings.rs", "ratchet": "env-read", "reason": "the one reader of the process environment in this crate: it returns the operator's switches as typed values"}, + {"crate": "leleka-igpu", "file": "src/settings.rs", "ratchet": "env-read", "reason": "the one reader of the process environment in this crate: it returns the operator's switches as typed values"}, + {"crate": "leleka-memory", "file": "src/settings.rs", "ratchet": "env-read", "reason": "the one reader of the process environment in this crate: it returns the operator's switches as typed values"}, + {"crate": "leleka-gptoss", "file": "src/settings.rs", "ratchet": "env-read", "reason": "the one reader of the process environment in this crate: it returns the operator's switches as typed values"}, + {"crate": "leleka-model-format", "file": "src/settings.rs", "ratchet": "env-read", "reason": "the one reader of the process environment in this crate: it returns the operator's switches as typed values"}, + {"crate": "leleka-obs", "file": "src/level.rs", "ratchet": "env-read", "reason": "the one reader of the process environment in this crate: LELEKA_LOG* parsed once into Settings, and the request-log path"}, + {"crate": "leleka-cuda-driver", "file": "src/settings.rs", "ratchet": "env-read", "reason": "the one reader of the process environment in this crate; call sites still parse the text they ask for (typed switches: EnvSwitch in leleka-cuda-model, in progress on claude/debt-hot-low)"}, + {"crate": "leleka-native-cpu-expert", "file": "src/settings.rs", "ratchet": "env-read", "reason": "the one reader of the process environment in this crate; call sites still parse the text they ask for (CPU expert pool: hot path, in progress on claude/debt-hot-low)"}, + {"crate": "leleka-cpu-kernels", "file": "src/dispatch.rs", "ratchet": "env-read", "reason": "the one reader of the process environment in this crate: ISA_ENV is parsed by Isa::from_request into the selected instruction set"}, + {"crate": "leleka-libc-shim", "file": "src/cuda_trace/trace_state.rs", "ratchet": "env-read", "reason": "Windows interposer (FFI): the CUDA call tracer reads its own LELEKA_BRINGUP_TRACE switches and must not depend on other crates"}, + {"crate": "leleka-libc-shim", "file": "src/lib.rs", "ratchet": "env-read", "reason": "Windows interposer (FFI): the DLL search directories come from the process environment before any other crate can load"}, + {"crate": "leleka-memory-os", "file": "src/heap.rs", "ratchet": "env-read", "reason": "platform adapter (glibc heap): reads its own LELEKA_MEMORY_NO_TRIM switch once"}, + {"crate": "leleka-native-parity-bench", "file": "src/lib.rs", "ratchet": "env-read", "reason": "benchmark host (L4): reads the operator's STRATA_IQ_MT_MIN override to report which value it measured"}, + {"crate": "leleka-npu-worker", "file": "src/main.rs", "ratchet": "env-read", "reason": "worker binary (composition root): reads LELEKA_OPENVINO_ROOT into its configuration"}, + {"crate": "leleka-memory", "file": "src/settings.rs", "ratchet": "process-global", "reason": "the cached LELEKA_NO_TRIM_FILE path: an immutable operator setting read once by the crate's one environment reader"}, + {"crate": "leleka-memory", "file": "src/governor.rs", "ratchet": "process-global", "reason": "Governor::global(): the process-wide memory governor installed once at engine start; its injection through the engine stack (S13/S14) belongs to the engine crate"}, + {"crate": "leleka-memory", "file": "src/inventory.rs", "ratchet": "process-global", "reason": "Inventory::global(): the process-wide census of live mappings and pinned regions, filled by the loaders; injected with the governor (S13/S14)"}, + {"crate": "leleka-memory", "file": "src/governor.rs", "ratchet": "dyn-trait", "reason": "port boundary: the Governor holds its MemoryPressure adapter as Arc, chosen at start-up (hexagonal.md, ports table)"}, + {"crate": "leleka-memory", "file": "src/governor/operations/setup.rs", "ratchet": "dyn-trait", "reason": "port boundary: Governor::new takes the host as Arc (the adapter is chosen by the composition root) and source() hands it back"}, + {"crate": "leleka-memory", "file": "src/lock/page_locking.rs", "ratchet": "dyn-trait", "reason": "port boundary: SharedPageLocking = Arc, the OS adapter of mmap/mlock chosen by the composition root"}, + {"crate": "leleka-memory", "file": "src/telemetry.rs", "ratchet": "dyn-trait", "reason": "port boundary: the GPU probe is a closure chosen at start-up (nvidia-smi or NVML) and owned by the sampler thread"}, + {"crate": "leleka-memory", "file": "src/smi.rs", "ratchet": "dyn-trait", "reason": "port boundary: the nvidia-smi probe closure handed to the telemetry sampler (see telemetry.rs)"}, + {"crate": "leleka-cpu-worker", "file": "src/engine.rs", "ratchet": "instant-now", "reason": "measurement timer, not decision logic: load and prefill wall-time measurement, reported in the worker's timing line"}, + {"crate": "leleka-cpu-worker", "file": "src/serve.rs", "ratchet": "instant-now", "reason": "measurement timer, not decision logic: per-request wall-time measurement (prefill and decode), reported in the worker's timing line"}, + {"crate": "leleka-cpu-worker", "file": "src/serve/decode_loop.rs", "ratchet": "instant-now", "reason": "measurement timer, not decision logic: per-token lap timers of the decode loop; one reading per lap, summed into the timing line"}, + {"crate": "leleka-gptoss", "file": "src/forward_pass.rs", "ratchet": "instant-now", "reason": "measurement timer, not decision logic: per-pass lap timer inside the forward pass; one reading per lap, summed into the timing report"}, + {"crate": "leleka-gptoss", "file": "src/generation.rs", "ratchet": "instant-now", "reason": "measurement timer, not decision logic: generation wall-time measurement for the timing report"}, + {"crate": "leleka-gptoss-igpu", "file": "src/prefill_pass.rs", "ratchet": "instant-now", "reason": "measurement timer, not decision logic: wall-time measurement of one prefill pass, reported with the pass"}, + {"crate": "leleka-gptoss-igpu", "file": "src/prefill_run.rs", "ratchet": "instant-now", "reason": "measurement timer, not decision logic: stage lap timers of the iGPU prefill, reported in the timing line"}, + {"crate": "leleka-gptoss-npu", "file": "src/expert_pass.rs", "ratchet": "instant-now", "reason": "measurement timer, not decision logic: stage lap timers of the NPU expert pass, reported in the timing line"}, + {"crate": "leleka-gptoss-npu", "file": "src/prefill_batch.rs", "ratchet": "instant-now", "reason": "measurement timer, not decision logic: stage lap timers of the NPU prefill batch, reported in the timing line"}, + {"crate": "leleka-gptoss-npu", "file": "src/prefill_part_pass.rs", "ratchet": "instant-now", "reason": "measurement timer, not decision logic: wall-time measurement of one NPU prefill part, reported with the pass"}, + {"crate": "leleka-gptoss-npu", "file": "src/service_transfers.rs", "ratchet": "instant-now", "reason": "measurement timer, not decision logic: transfer wall-time measurement toward the NPU service"}, + {"crate": "leleka-gpu-npu-worker", "file": "src/lib.rs", "ratchet": "instant-now", "reason": "measurement timer, not decision logic: wall-time measurement of the split prefill passes, reported in the timing line"}, + {"crate": "leleka-gpu-npu-worker", "file": "src/split_run.rs", "ratchet": "instant-now", "reason": "measurement timer, not decision logic: lap timers of the GPU and NPU legs of the split prefill"}, + {"crate": "leleka-igpu", "file": "src/matrices_and_moe_plan.rs", "ratchet": "instant-now", "reason": "measurement timer, not decision logic: wall-time measurement of the weight upload, reported at load"}, + {"crate": "leleka-npu-service", "file": "src/engine/execution.rs", "ratchet": "instant-now", "reason": "measurement timer, not decision logic: lap timers of one NPU execution, summed into the profile report"}, + {"crate": "leleka-model-format", "file": "src/bulk_read/for_each_chunk.rs", "ratchet": "instant-now", "reason": "measurement timer, not decision logic: wall-time measurement of the bulk read, reported in the load report"}, + {"crate": "leleka-model-format", "file": "src/huge_pages.rs", "ratchet": "instant-now", "reason": "measurement timer, not decision logic: wall-time measurement of the huge-page allocation probe, reported in the load report"}, + {"crate": "leleka-model-format", "file": "src/kar/independent_handles.rs", "ratchet": "instant-now", "reason": "measurement timer, not decision logic: wall-time measurement of opening the independent file handles"}, + {"crate": "leleka-model-format", "file": "src/pinned_arena_plan/expert_parallel_load.rs", "ratchet": "instant-now", "reason": "measurement timer, not decision logic: read and copy lap timers of the expert load, reported in the load report"}, + {"crate": "leleka-model-format", "file": "src/ple_reader/read_queue.rs", "ratchet": "instant-now", "reason": "measurement timer, not decision logic: readings of the per-row read queue's latency window, inside the reader loop"}, + {"crate": "leleka-model-format", "file": "src/ple_reader/row_reading.rs", "ratchet": "instant-now", "reason": "measurement timer, not decision logic: latency measurement of one PLE row read, inside the reader loop"}, + {"crate": "leleka-obs", "file": "src/time/clock.rs", "ratchet": "instant-now", "reason": "the clock adapter itself: SystemClock, AnyClock and ManualClock are the one place that reads the monotonic clock"}, + {"crate": "leleka-memory-os", "file": "src/heap.rs", "ratchet": "process-global", "reason": "platform adapter (glibc heap): the LELEKA_MEMORY_NO_TRIM switch is read once and cached"}, + {"crate": "leleka-libc-shim", "file": "src/cuda_trace/trace_state.rs", "ratchet": "process-global", "reason": "Windows interposer (FFI): the CUDA call tracer is process-wide state behind C-ABI hooks that carry no context pointer"}, + {"crate": "leleka-obs", "file": "src/lib.rs", "ratchet": "process-global", "reason": "the logger is process-wide: its Settings, rate limiter and request sink are built once from the environment"}, + {"crate": "leleka-obs", "file": "src/write_stderr.rs", "ratchet": "process-global", "reason": "the request-log sink of the process-wide logger (see lib.rs)"}, + {"crate": "leleka-tokenizer", "file": "src/lib.rs", "ratchet": "process-global", "reason": "immutable constant tables built once: the pre-tokenizer regex and the character classes"}, + {"crate": "leleka-gptoss-npu", "file": "src/half.rs", "ratchet": "process-global", "reason": "immutable constant table: the half-to-float conversion table, built once"}, + {"crate": "leleka-cuda-model", "file": "src/original_prefill_schedule.rs", "ratchet": "dyn-trait", "reason": "parameter struct SourceView borrows three residency queries (resident, pinned, transient) from the caller's tables; a generic parameter per closure would make the type unnameable in the callers' signatures"}, + {"crate": "leleka-experimental-ref", "file": "src/remote_experts.rs", "ratchet": "dyn-trait", "reason": "parameter struct Candidates borrows the primary's residency test from the caller's table; generic parameters would leak into every caller's signature"}, + {"crate": "leleka-cpu-worker", "file": "src/engine.rs", "ratchet": "dyn-trait", "reason": "port boundary: the engine holds the prefill accelerator (iGPU, NPU or split) as Box, chosen by the worker binary"}, + {"crate": "leleka-cpu-worker", "file": "src/serve.rs", "ratchet": "dyn-trait", "reason": "dyn-compatible worker trait: the progress callback of a trait method must be a trait object"}, + {"crate": "leleka-gptoss", "file": "src/state_and_cache.rs", "ratchet": "dyn-trait", "reason": "port boundary: PrefillAccelerator and LayerCache are the accelerator seams, chosen by the worker binary; their methods take the progress callback as a trait object"}, + {"crate": "leleka-gptoss", "file": "src/model.rs", "ratchet": "dyn-trait", "reason": "port boundary: the model's weights read through Arc (file, memory map or test bytes), chosen when the model is loaded"}, + {"crate": "leleka-gptoss", "file": "src/tensor_loading.rs", "ratchet": "dyn-trait", "reason": "port boundary: the model's weights read through Arc (file, memory map or test bytes), chosen when the model is loaded"}, + {"crate": "leleka-gptoss", "file": "src/weights.rs", "ratchet": "dyn-trait", "reason": "port boundary: the model's weights read through Arc (file, memory map or test bytes), chosen when the model is loaded"}, + {"crate": "leleka-gptoss", "file": "src/pool.rs", "ratchet": "dyn-trait", "reason": "the worker pool runs heterogeneous closures: Box is the type-erased job of its queue"}, + {"crate": "leleka-gptoss-igpu", "file": "src/lib.rs", "ratchet": "dyn-trait", "reason": "port boundary: the memory probe closure and the PrefillAccelerator impl (trait objects by the trait's own signature)"}, + {"crate": "leleka-gptoss-npu", "file": "src/lib.rs", "ratchet": "dyn-trait", "reason": "port boundary: the memory probe closure chosen by the worker binary"}, + {"crate": "leleka-gptoss-npu", "file": "src/accelerator.rs", "ratchet": "dyn-trait", "reason": "PrefillAccelerator impl: the progress callback is a trait object by the trait's own signature"}, + {"crate": "leleka-gpu-npu-worker", "file": "src/lib.rs", "ratchet": "dyn-trait", "reason": "port boundary: the memory probe closure, the LayerCache seam and the PrefillAccelerator impl (trait objects by the traits' own signatures)"}, + {"crate": "leleka-tokenizer", "file": "src/lib.rs", "ratchet": "dyn-trait", "reason": "Result> of the public tokenizer API: the error is the std error object at the library boundary"}, + {"crate": "leleka-model-format", "file": "src/gguf.rs", "ratchet": "dyn-trait", "reason": "Result> of the GGUF reader's public API: the std error object at the library boundary"}, + {"crate": "leleka-model-format", "file": "src/qwen4exp.rs", "ratchet": "dyn-trait", "reason": "the artifact error wraps any std error (Box) from the byte sources it reads through"}, + {"crate": "leleka-model-format", "file": "src/qwen4exp/binding_topology.rs", "ratchet": "dyn-trait", "reason": "std::error::Error::source() returns &(dyn Error + 'static) by the trait's own signature"}, + {"crate": "leleka-model-format", "file": "src/ple_reader.rs", "ratchet": "dyn-trait", "reason": "port boundary: the PLE reader holds its PageSource (file, direct-IO file or test double) as Arc"}, + {"crate": "leleka-model-format", "file": "src/ple_reader/row_reading.rs", "ratchet": "dyn-trait", "reason": "port boundary: PleReader::open takes the PageSource as Arc"}, + {"crate": "leleka-model-format", "file": "src/huge_pages.rs", "ratchet": "process-global", "reason": "the huge-page mode is an operator setting parsed once from LELEKA_HUGEPAGES and cached for the process"}, + {"crate": "leleka-model-format", "file": "src/kar/independent_handles.rs", "ratchet": "process-global", "reason": "the identity-recheck switch is an operator setting parsed once and cached for the process"}, + {"crate": "leleka-model-format", "file": "src/kar.rs", "ratchet": "process-global", "reason": "a per-instance lazily opened set of file handles (a OnceLock field of the archive), not a process global"}, + {"crate": "leleka-model-format", "file": "src/kar/verified_kar_ple_artifact.rs", "ratchet": "process-global", "reason": "constructs the per-instance lazy handle cell of kar.rs, not a process global"}, + {"crate": "leleka-model-format", "file": "src/verify_stamp.rs", "ratchet": "process-global", "reason": "the process-wide registry of verified-file stamps, written by the loaders and read by the identity re-checks; its injection belongs to the loader stack (S13)"}, {"crate": "strata-control", "file": "src/env_settings.rs", "ratchet": "env-read", "reason": "the one reader of the process environment of the crate: every variable is parsed here into a typed value (number, path, flag, mode)"}, {"crate": "leleka-deploy", "file": "src/env_settings.rs", "ratchet": "env-read", "reason": "the one reader of the process environment of the crate: every variable is parsed here into a typed value (path, flag, text)"}, {"crate": "strata-desktop-core", "file": "src/env_settings.rs", "ratchet": "env-read", "reason": "the one reader of the process environment of the crate and its binaries: credentials by name, the evaluation switches, the inherited child variables"}, - {"crate": "leleka-gateway-text", "file": "src/env_settings.rs", "ratchet": "env-read", "reason": "the one reader of the process environment of the crate: the two prompt rendering switches"}, + {"crate": "leleka-gateway-text", "file": "src/prompt/env_settings.rs", "ratchet": "env-read", "reason": "the one reader of the process environment of the crate: the two prompt rendering switches"}, {"crate": "leleka-npu-service", "file": "src/env_settings.rs", "ratchet": "env-read", "reason": "the one reader of the process environment of the crate: the profile report switch"}, {"crate": "strata-control", "file": "src/adapters/system_clock.rs", "ratchet": "instant-now", "reason": "the production Clock adapter: the one place that reads the runtime clock for the injected Clock port"}, {"crate": "strata-control", "file": "src/ports/fakes/clock.rs", "ratchet": "instant-now", "reason": "test fixture: the manual clock needs one base instant to count from and never moves by itself"}, diff --git a/control-plane/src/kar_overlay.rs b/control-plane/src/kar_overlay.rs index 416ef179..fb4b6803 100644 --- a/control-plane/src/kar_overlay.rs +++ b/control-plane/src/kar_overlay.rs @@ -180,8 +180,8 @@ pub struct Summary { pub provenance_path: PathBuf, } -mod sidecar_and_tensor_locations; -use sidecar_and_tensor_locations::*; +mod overlay_source_reading; +use overlay_source_reading::*; mod base_provenance; use base_provenance::*; mod verified_source_resolution; diff --git a/control-plane/src/kar_overlay/sidecar_and_tensor_locations.rs b/control-plane/src/kar_overlay/overlay_source_reading.rs similarity index 100% rename from control-plane/src/kar_overlay/sidecar_and_tensor_locations.rs rename to control-plane/src/kar_overlay/overlay_source_reading.rs diff --git a/control-plane/src/prepare_preview.rs b/control-plane/src/prepare_preview.rs index 462c2f58..ad07213c 100644 --- a/control-plane/src/prepare_preview.rs +++ b/control-plane/src/prepare_preview.rs @@ -100,8 +100,8 @@ pub use tensor_encoding::*; mod derived_verification; #[allow(unused_imports)] pub use derived_verification::*; -mod staging_and_raw_tensor_reads; -use staging_and_raw_tensor_reads::*; +mod preview_tensor_io; +use preview_tensor_io::*; mod sharded_encode; use sharded_encode::*; mod streamed_encode; diff --git a/control-plane/src/prepare_preview/staging_and_raw_tensor_reads.rs b/control-plane/src/prepare_preview/preview_tensor_io.rs similarity index 100% rename from control-plane/src/prepare_preview/staging_and_raw_tensor_reads.rs rename to control-plane/src/prepare_preview/preview_tensor_io.rs diff --git a/crates/context/src/context_policy/tests.rs b/crates/context/src/context_policy/tests.rs index 28234dc5..0632b334 100644 --- a/crates/context/src/context_policy/tests.rs +++ b/crates/context/src/context_policy/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests of the context policy: 2x256k needs no scaling and 1x512k needs YaRN 2, INT8 pool closing, refusal of +//! explicit none past the trained range, stray scale, bad rope knobs and request errors, and state sizing by slots. use super::*; diff --git a/crates/context/src/geometry/tests.rs b/crates/context/src/geometry/tests.rs index c5442f58..8f8c1e2a 100644 --- a/crates/context/src/geometry/tests.rs +++ b/crates/context/src/geometry/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests of the cell-count geometry: at the trained cell count every value equals its frozen literal, the resident +//! window follows kv_plan, 512k scales linear sizes by exactly two, and invalid cell counts and boundaries. use super::*; diff --git a/crates/context/src/memory_plan.rs b/crates/context/src/memory_plan.rs index 83a53a14..0f9886a5 100644 --- a/crates/context/src/memory_plan.rs +++ b/crates/context/src/memory_plan.rs @@ -127,8 +127,6 @@ pub struct EngineResidentEstimate { mod tests; mod geometry_sizes; -#[allow(unused_imports)] pub use geometry_sizes::*; mod per_token_plan; -#[allow(unused_imports)] pub use per_token_plan::*; diff --git a/crates/context/src/memory_plan/tests.rs b/crates/context/src/memory_plan/tests.rs index daf95e53..9188ddf3 100644 --- a/crates/context/src/memory_plan/tests.rs +++ b/crates/context/src/memory_plan/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests of the memory plan arithmetic: real geometry constants, per-cell bytes, INT8 generic versus literal, +//! pool derivation quirks, does-not-close messages, overflow reporting, Q4 versus INT8 closing, FP32 indexer store. use super::*; diff --git a/crates/context/src/rope_scaling.rs b/crates/context/src/rope_scaling.rs index 0a7df1d6..f0366622 100644 --- a/crates/context/src/rope_scaling.rs +++ b/crates/context/src/rope_scaling.rs @@ -166,11 +166,8 @@ pub enum SetupRopeError { mod tests; mod rope_scaling_type; -#[allow(unused_imports)] pub use rope_scaling_type::*; mod rope_table; -#[allow(unused_imports)] pub use rope_table::*; mod setup_rope_error_and_resolve; -#[allow(unused_imports)] pub use setup_rope_error_and_resolve::*; diff --git a/crates/context/src/rope_scaling/rope_scaling_type.rs b/crates/context/src/rope_scaling/rope_scaling_type.rs index 67ec1721..690a004f 100644 --- a/crates/context/src/rope_scaling/rope_scaling_type.rs +++ b/crates/context/src/rope_scaling/rope_scaling_type.rs @@ -1,5 +1,5 @@ -//! Methods of `RopeScalingType`: `name`, `parse`. Methods of `RopeScalingError`: `reason`. -//! Implements `Default for RopeKernelArgs`, `Display for RopeScalingError` and 5 more. +//! RoPE scaling types and errors: the scaling method names, default kernel arguments, the RopeScaling +//! configuration with its validation and kernel arguments, YaRN ramp and angle, and RoPE table errors and size. use super::{ DEFAULT_FREQ_BASE, PI, RopeKernelArgs, RopeScaling, RopeScalingError, RopeScalingType, RopeTableError, diff --git a/crates/context/src/rope_scaling/tests.rs b/crates/context/src/rope_scaling/tests.rs index 9bf113b5..77d9f5b6 100644 --- a/crates/context/src/rope_scaling/tests.rs +++ b/crates/context/src/rope_scaling/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests of RoPE scaling: identity default, YaRN mscale and clamped correction dims, rejection of non-finite or bad +//! configs, prefix-stable chunkable tables, table bytes at charter contexts, and setup/knob resolution. use super::*; diff --git a/crates/context/tests/rope_plan_golden/every_fixture_case_has.rs b/crates/context/tests/rope_plan_golden/every_fixture_case_has.rs index 7289bbc4..72b8a55b 100644 --- a/crates/context/tests/rope_plan_golden/every_fixture_case_has.rs +++ b/crates/context/tests/rope_plan_golden/every_fixture_case_has.rs @@ -2,7 +2,6 @@ //! yarn_is_observably_different_from_none, strata_plan_cli_output_is_reproduced_exactly, //! kv_pool_bytes_match_the_originals_layer_cpp. -#[allow(unused_imports)] use super::*; #[test] diff --git a/crates/cpu-sys/src/c_reference.rs b/crates/cpu-sys/src/c_reference.rs index 89a61669..a60830da 100644 --- a/crates/cpu-sys/src/c_reference.rs +++ b/crates/cpu-sys/src/c_reference.rs @@ -84,92 +84,55 @@ mod ffi { } mod abi_version; -#[allow(unused_imports)] pub use abi_version::abi_version; #[cfg(target_arch = "x86_64")] -#[allow(unused_imports)] pub use abi_version::avxvnni_available; -#[allow(unused_imports)] use abi_version::check_i4; -#[allow(unused_imports)] use abi_version::check_i8; -#[allow(unused_imports)] -use abi_version::check_mx; -#[allow(unused_imports)] use abi_version::check_mx_out; -#[allow(unused_imports)] use abi_version::check_q8; -#[allow(unused_imports)] -use abi_version::check_q8r; -#[allow(unused_imports)] use abi_version::check_quantize; -#[allow(unused_imports)] pub use abi_version::dot_i4i8_scalar; -#[allow(unused_imports)] pub use abi_version::dot_i8i8_scalar; #[cfg(target_arch = "x86_64")] -#[allow(unused_imports)] pub use abi_version::dot_mxfp4_q8_0_avx2; #[cfg(target_arch = "x86_64")] -#[allow(unused_imports)] pub use abi_version::dot_mxfp4_q8_0_avxvnni; -#[allow(unused_imports)] pub use abi_version::dot_mxfp4_q8_0_scalar; #[cfg(target_arch = "x86_64")] -#[allow(unused_imports)] pub use abi_version::dot_mxfp4_q8r_avx2; -#[allow(unused_imports)] pub use abi_version::dot_mxfp4_q8r_scalar; #[cfg(target_arch = "x86_64")] -#[allow(unused_imports)] pub use abi_version::dot_mxfp4_q8r4_avx2; #[cfg(target_arch = "x86_64")] -#[allow(unused_imports)] pub use abi_version::dot_mxfp4_q8r4_avxvnni; #[cfg(target_arch = "x86_64")] -#[allow(unused_imports)] pub use abi_version::mxfp4_q8_0_isums_avx2; #[cfg(target_arch = "x86_64")] -#[allow(unused_imports)] pub use abi_version::mxfp4_q8_0_isums_avxvnni; -#[allow(unused_imports)] pub use abi_version::mxfp4_q8_0_isums_scalar; mod quantize_q8_0_scalar; #[cfg(target_arch = "x86_64")] -#[allow(unused_imports)] pub use quantize_q8_0_scalar::dot_i4i8_avx2; #[cfg(target_arch = "x86_64")] -#[allow(unused_imports)] pub use quantize_q8_0_scalar::dot_i4i8_avxvnni; #[cfg(target_arch = "x86_64")] -#[allow(unused_imports)] pub use quantize_q8_0_scalar::dot_i8i8_avx2; #[cfg(target_arch = "x86_64")] -#[allow(unused_imports)] pub use quantize_q8_0_scalar::dot_i8i8_avxvnni; #[cfg(target_arch = "x86_64")] -#[allow(unused_imports)] pub use quantize_q8_0_scalar::dot_q8_0_q8_0_avx2; #[cfg(target_arch = "x86_64")] -#[allow(unused_imports)] pub use quantize_q8_0_scalar::dot_q8_0_q8_0_avxvnni; -#[allow(unused_imports)] pub use quantize_q8_0_scalar::dot_q8_0_q8_0_scalar; #[cfg(target_arch = "x86_64")] -#[allow(unused_imports)] pub use quantize_q8_0_scalar::f32_to_f16_bits_f16c; -#[allow(unused_imports)] pub use quantize_q8_0_scalar::f32_to_f16_bits_scalar; #[cfg(target_arch = "x86_64")] -#[allow(unused_imports)] pub use quantize_q8_0_scalar::q8_0_q8_0_isums_avx2; #[cfg(target_arch = "x86_64")] -#[allow(unused_imports)] pub use quantize_q8_0_scalar::q8_0_q8_0_isums_avxvnni; -#[allow(unused_imports)] pub use quantize_q8_0_scalar::q8_0_q8_0_isums_scalar; #[cfg(target_arch = "x86_64")] -#[allow(unused_imports)] pub use quantize_q8_0_scalar::quantize_q8_0_avx2; -#[allow(unused_imports)] pub use quantize_q8_0_scalar::quantize_q8_0_scalar; diff --git a/crates/cpu-sys/src/c_reference/abi_version.rs b/crates/cpu-sys/src/c_reference/abi_version.rs index c63e63c9..428180ec 100644 --- a/crates/cpu-sys/src/c_reference/abi_version.rs +++ b/crates/cpu-sys/src/c_reference/abi_version.rs @@ -1,5 +1,5 @@ -//! Functions: `abi_version`, `check_i8`, `check_i4`, `dot_i8i8_scalar` and 17 more. -//! Split out of `c_reference` to keep its files under the line limit. +//! Safe Rust wrappers over the C reference kernels: ABI version, int8/int4 dots, MXFP4 x Q8_0 dots and block sums, +//! and the q8r layout, at scalar, AVX2 and AVX-VNNI level, with the shared length checks that make the FFI calls sound. use super::{BLOCK_ELEMS, KernelError, MAX_DOT_LEN, MXFP4_BLOCK_BYTES, Q8_0_BLOCK_BYTES, avx2_available, ffi}; diff --git a/crates/cpu-sys/src/c_reference/quantize_q8_0_scalar.rs b/crates/cpu-sys/src/c_reference/quantize_q8_0_scalar.rs index 2247ae8f..5b8f41c7 100644 --- a/crates/cpu-sys/src/c_reference/quantize_q8_0_scalar.rs +++ b/crates/cpu-sys/src/c_reference/quantize_q8_0_scalar.rs @@ -1,5 +1,5 @@ -//! Functions: `quantize_q8_0_scalar`, `quantize_q8_0_avx2`, `dot_q8_0_q8_0_scalar`, `q8_0_q8_0_isums_scalar` and 10 ... -//! Split out of `c_reference` to keep its files under the line limit. +//! Safe wrappers over the C reference for Q8_0: float quantizer, Q8_0 x Q8_0 dots and block sums, float to half +//! conversion, and the AVX2/AVX-VNNI int8 and int4 dots; each SIMD level is checked against its scalar twin. use super::{KernelError, avx2_available, check_i4, check_i8, check_mx_out, check_q8, check_quantize, ffi}; #[cfg(target_arch="x86_64")] diff --git a/crates/cpu-sys/src/oracle.rs b/crates/cpu-sys/src/oracle.rs index d7c0e351..27935940 100644 --- a/crates/cpu-sys/src/oracle.rs +++ b/crates/cpu-sys/src/oracle.rs @@ -1,5 +1,5 @@ -//! Functions: `block_bytes`, `aligned`, `unaligned`, `dequantize_mxfp4` and 3 more. -//! Split out of `crate` to keep its files under the line limit. +//! Safe wrappers over the pinned ggml MXFP4 and Q8_0 quantize/dequantize routines (compiled C), used as the oracle +//! that the Rust kernels are compared against; copies buffers to 8-byte aligned storage for ggml structs. use super::{BLOCK_ELEMS, MXFP4_BLOCK_BYTES, Q8_0_BLOCK_BYTES}; diff --git a/crates/cpu-sys/src/simd/x86.rs b/crates/cpu-sys/src/simd/x86.rs index fec031f1..b5618cb2 100644 --- a/crates/cpu-sys/src/simd/x86.rs +++ b/crates/cpu-sys/src/simd/x86.rs @@ -1,5 +1,5 @@ -//! Groups the submodules `reductions_and_int_dots`, `mxfp4_q8_dots`, `q8_dots_and_mxfp4_tiles` and 4 more. -//! Split out of `simd` to keep its files under the line limit. +//! x86-64 kernel set: holds the register-tiled macros and the shared safety contract, and declares the kernel groups +//! (int dots, MXFP4 and Q8 dots, tiles, attention and f16 elementwise, Q8_0 quantizer) at AVX2 and AVX-VNNI level. //! AVX2 (+FMA +F16C) and AVX-VNNI kernels. Every function is `unsafe`: the caller must have //! verified the CPU features named in its `target_feature` attribute and that all slices have the diff --git a/crates/cpu-worker/src/engine.rs b/crates/cpu-worker/src/engine.rs index 3199bb6d..b1a27764 100644 --- a/crates/cpu-worker/src/engine.rs +++ b/crates/cpu-worker/src/engine.rs @@ -174,6 +174,7 @@ pub fn load(options: &LoadOptions) -> Result { let stop_tokens = stop_tokens_of(&tokenizer)?; let mapping = Mapping::open(options.model).map_err(|e| format!("cannot map the model: {e}"))?; if options.warm { + // Measurement timer, not decision logic (instant-now exception in architecture.json). let started = Instant::now(); let checksum = mapping.touch_pages(); eprintln!( @@ -225,7 +226,7 @@ impl GptOssEngine { max_slots: 1, active: 0, clock: 0, - log_slots: std::env::var_os("LELEKA_SLOT_LOG").is_some(), + log_slots: crate::settings::slot_log_enabled(), context, accelerator: None, accelerate_from: usize::MAX, diff --git a/crates/cpu-worker/src/lib.rs b/crates/cpu-worker/src/lib.rs index 5355152a..ddcde844 100644 --- a/crates/cpu-worker/src/lib.rs +++ b/crates/cpu-worker/src/lib.rs @@ -4,4 +4,5 @@ pub mod engine; pub mod protocol; pub mod serve; +mod settings; pub mod slots; diff --git a/crates/cpu-worker/src/serve.rs b/crates/cpu-worker/src/serve.rs index c0fe86bf..eecaba70 100644 --- a/crates/cpu-worker/src/serve.rs +++ b/crates/cpu-worker/src/serve.rs @@ -221,6 +221,7 @@ fn generate( output: &Mutex, ) -> Result<(), GenerationError> { check_budget(decoder, request)?; + // Measurement timer, not decision logic (instant-now exception in architecture.json). let started = Instant::now(); let reused = prefill_prompt(decoder, request, control, output)?; let prompt_ms = started.elapsed().as_secs_f64() * 1000.0; diff --git a/crates/cpu-worker/src/serve/decode_loop.rs b/crates/cpu-worker/src/serve/decode_loop.rs index 2c043a73..6b03a6ff 100644 --- a/crates/cpu-worker/src/serve/decode_loop.rs +++ b/crates/cpu-worker/src/serve/decode_loop.rs @@ -54,6 +54,7 @@ impl Speculation { self.abandon_pending(decoder, times); } self.logits = None; + // Measurement timer, not decision logic (instant-now exception in architecture.json). let lap = Instant::now(); let mut drafts = self.drafter.draft(&self.history); times.draft += lap.elapsed(); @@ -193,7 +194,7 @@ impl Decoding { /// The diagnostics line of `LELEKA_SPECULATION_LOG`, when set. pub(super) fn log(&self, decode_started: Instant) { - if std::env::var_os("LELEKA_SPECULATION_LOG").is_none() { + if !crate::settings::speculation_log_enabled() { return; } if let Some(s) = self.speculation.as_ref().filter(|s| s.batches > 0) { diff --git a/crates/cpu-worker/src/settings.rs b/crates/cpu-worker/src/settings.rs new file mode 100644 index 00000000..3a615a28 --- /dev/null +++ b/crates/cpu-worker/src/settings.rs @@ -0,0 +1,11 @@ +//! The only place of this crate that reads the process environment: the operator's logging switches, as typed values. + +/// `LELEKA_SLOT_LOG` is set: print the slot reuse decisions. +pub(crate) fn slot_log_enabled() -> bool { + std::env::var_os("LELEKA_SLOT_LOG").is_some() +} + +/// `LELEKA_SPECULATION_LOG` is set: print the speculation diagnostics line after each generation. +pub(crate) fn speculation_log_enabled() -> bool { + std::env::var_os("LELEKA_SPECULATION_LOG").is_some() +} diff --git a/crates/cpu-worker/tests/serve_loop/failure_shutdown_and_speculation.rs b/crates/cpu-worker/tests/serve_loop/failure_shutdown_and_speculation.rs index dd0291ad..05315ec6 100644 --- a/crates/cpu-worker/tests/serve_loop/failure_shutdown_and_speculation.rs +++ b/crates/cpu-worker/tests/serve_loop/failure_shutdown_and_speculation.rs @@ -1,6 +1,5 @@ //! Engine failure, quit, a broken output pipe, and speculative decoding with rollback. -#[allow(unused_imports)] use super::*; #[test] diff --git a/crates/cpu-worker/tests/serve_loop/generation_and_cancellation.rs b/crates/cpu-worker/tests/serve_loop/generation_and_cancellation.rs index c2c33373..df182d89 100644 --- a/crates/cpu-worker/tests/serve_loop/generation_and_cancellation.rs +++ b/crates/cpu-worker/tests/serve_loop/generation_and_cancellation.rs @@ -1,6 +1,5 @@ //! Streaming a generation to its stop token or budget, prefix reuse, cancellation by stop, and reported errors. -#[allow(unused_imports)] use super::*; #[test] diff --git a/crates/cuda-driver/src/api.rs b/crates/cuda-driver/src/api.rs index 5906f9da..4f3b107b 100644 --- a/crates/cuda-driver/src/api.rs +++ b/crates/cuda-driver/src/api.rs @@ -43,5 +43,4 @@ mod async_api; any(target_os = "linux", target_os = "windows"), target_pointer_width = "64" )))] -#[allow(unused_imports)] pub(crate) use async_api::page_size; diff --git a/crates/cuda-driver/src/api/async_api.rs b/crates/cuda-driver/src/api/async_api.rs index 861c24d6..70f510e0 100644 --- a/crates/cuda-driver/src/api/async_api.rs +++ b/crates/cuda-driver/src/api/async_api.rs @@ -1,5 +1,5 @@ -//! Methods of `AsyncApi`: `load`, `create_stream`, `create_event`, `register` and 12 more. -//! Methods of `MappedApi`: `load`, `register_bank`, `bank_alias`, `unregister_bank` and 12 more. +//! Stub implementations of AsyncApi and MappedApi for builds without a usable CUDA driver (no cuda-driver feature, +//! non-Linux/Windows or non-64-bit target): every method fails with UnsupportedPlatform, so callers compile unchanged. #[cfg(not(all( feature = "cuda-driver", diff --git a/crates/cuda-driver/src/arch_ptx.rs b/crates/cuda-driver/src/arch_ptx.rs index e90392e5..261cdd5d 100644 --- a/crates/cuda-driver/src/arch_ptx.rs +++ b/crates/cuda-driver/src/arch_ptx.rs @@ -230,32 +230,21 @@ mod tests { } mod stream_k_off; -#[allow(unused_imports)] pub(crate) use stream_k_off::cc_major_ok; -#[allow(unused_imports)] pub(crate) use stream_k_off::chunk_drain; -#[allow(unused_imports)] +#[cfg(all(test, feature = "sm86"))] pub(crate) use stream_k_off::companion_cc; -#[cfg(feature = "sm86")] -#[allow(unused_imports)] +#[cfg(all(test, feature = "sm86"))] pub(crate) use stream_k_off::companion_for; -#[allow(unused_imports)] pub(crate) use stream_k_off::forced_sms; #[cfg(not(feature = "sm86"))] -#[allow(unused_imports)] pub(crate) use stream_k_off::image; #[cfg(feature = "sm86")] -#[allow(unused_imports)] pub(crate) use stream_k_off::image; -#[allow(unused_imports)] pub(crate) use stream_k_off::latch_stream_k_policy; #[cfg(feature = "sm86")] -#[allow(unused_imports)] pub(crate) use stream_k_off::loadable; -#[allow(unused_imports)] pub(crate) use stream_k_off::mmq_cc_ok; #[cfg(feature = "sm86")] -#[allow(unused_imports)] pub(crate) use stream_k_off::native_sm120; -#[allow(unused_imports)] pub(crate) use stream_k_off::stream_k_off; diff --git a/crates/cuda-driver/src/arch_ptx/stream_k_off.rs b/crates/cuda-driver/src/arch_ptx/stream_k_off.rs index f0346c87..88b485a2 100644 --- a/crates/cuda-driver/src/arch_ptx/stream_k_off.rs +++ b/crates/cuda-driver/src/arch_ptx/stream_k_off.rs @@ -1,5 +1,5 @@ -//! Functions: `stream_k_off`, `marker_files_present`, `forced_sms`, `chunk_drain` and 10 more. -//! Split out of `arch_ptx` to keep its files under the line limit. +//! Run-time policy of the per-architecture PTX layer: the stream-K on/off switch (env vars and marker files), the +//! forced SM count and chunk-drain diagnostics, the compute-capability gates, and the sm_86 companion image lookup. use super::STREAM_K_AVOIDED; #[cfg(feature = "sm86")] diff --git a/crates/cuda-driver/src/async_owned_copy.rs b/crates/cuda-driver/src/async_owned_copy.rs index 6daaba8e..cb00da82 100644 --- a/crates/cuda-driver/src/async_owned_copy.rs +++ b/crates/cuda-driver/src/async_owned_copy.rs @@ -358,5 +358,4 @@ impl Drop for PendingOwnedCopy<'_> { } #[cfg(test)] -#[path = "async_owned_copy_gpu.rs"] mod gpu; diff --git a/crates/cuda-driver/src/async_owned_copy_gpu.rs b/crates/cuda-driver/src/async_owned_copy/gpu.rs similarity index 100% rename from crates/cuda-driver/src/async_owned_copy_gpu.rs rename to crates/cuda-driver/src/async_owned_copy/gpu.rs diff --git a/crates/cuda-driver/src/bringup_trace_enabled.rs b/crates/cuda-driver/src/bringup_trace_enabled.rs index cbd4aaac..14ed6d7d 100644 --- a/crates/cuda-driver/src/bringup_trace_enabled.rs +++ b/crates/cuda-driver/src/bringup_trace_enabled.rs @@ -1,5 +1,5 @@ -//! Methods of `PromptSyncTrace`: `enter`. Methods of `Driver`: `load`, `version`, `device`. -//! Implements `Drop for PromptSyncTrace`, `Drop for RoutedGateUpQ8`. Functions: `combine`, `valid_size`. +//! Driver bring-up core: Driver::load/device, Device::create_context and the Context constructor, the poison flag +//! (PoisonCell) with its trace, the prompt-sync trace guard, and the scratch release of RoutedGateUpQ8. use super::{ Cell, Context, Device, Driver, Error, PoisonCell, PromptSyncTrace, Rc, Result, RoutedGateUpQ8, ffi, qwen_dispatch, diff --git a/crates/cuda-driver/src/closed_kernels.rs b/crates/cuda-driver/src/closed_kernels.rs index 0a824211..4a3cb6a6 100644 --- a/crates/cuda-driver/src/closed_kernels.rs +++ b/crates/cuda-driver/src/closed_kernels.rs @@ -184,24 +184,13 @@ pub struct SBytes { mod tests; mod program; -#[allow(unused_imports)] pub use program::admit; -#[allow(unused_imports)] pub use program::admit_ptx; -#[allow(unused_imports)] pub use program::conforms; -#[allow(unused_imports)] pub use program::flash_bytes; -#[allow(unused_imports)] pub use program::flash_slots; -#[allow(unused_imports)] pub use program::poison_slots; -#[allow(unused_imports)] -use program::s_activation_bytes; -#[allow(unused_imports)] pub use program::s_gemv_entry_index; -#[allow(unused_imports)] pub use program::s_operand_bytes; mod s_gemv_slots; -#[allow(unused_imports)] pub use s_gemv_slots::s_gemv_slots; diff --git a/crates/cuda-driver/src/closed_kernels/program.rs b/crates/cuda-driver/src/closed_kernels/program.rs index d8ae7e20..944678e2 100644 --- a/crates/cuda-driver/src/closed_kernels/program.rs +++ b/crates/cuda-driver/src/closed_kernels/program.rs @@ -1,5 +1,5 @@ -//! Methods of `Program`: `name`, `ptx`, `pin`, `source` and 1 more. Methods of `Slot`: `kind`. -//! Functions: `admit_ptx`, `admit`, `s_gemv_entry_index`, `conforms` and 5 more. +//! Program catalogue of the closed kernels: name, sealed PTX, pin and CUDA source of each Program, fail-closed +//! PTX admission against its digest pin, and the slot lists and operand sizes of flash, poison and S-GEMV launches. use super::{ Arg, DEVICE_POISON_PTX, Entry, ExperimentalError, FLASH_ENTRIES, FlashBytes, Kernel, MAX_ENTRY_ARGUMENTS, diff --git a/crates/cuda-driver/src/closed_kernels/s_gemv_slots.rs b/crates/cuda-driver/src/closed_kernels/s_gemv_slots.rs index 3efdfc7f..ca42b5e8 100644 --- a/crates/cuda-driver/src/closed_kernels/s_gemv_slots.rs +++ b/crates/cuda-driver/src/closed_kernels/s_gemv_slots.rs @@ -1,5 +1,5 @@ -//! Functions: `s_gemv_slots`, `head_slots`. -//! Split out of `closed_kernels` to keep its files under the line limit. +//! Builds the ordered kernel-argument slots of a planned S-form GEMV (pointers, sizes, code bias, codebook, shift), +//! one layout per kernel variant; kept apart so program.rs holds only the catalogue and its admission. use super::{Kernel, Plan, Role, SForm, Slot}; diff --git a/crates/cuda-driver/src/closed_kernels/tests.rs b/crates/cuda-driver/src/closed_kernels/tests.rs index aca93871..d78c678d 100644 --- a/crates/cuda-driver/src/closed_kernels/tests.rs +++ b/crates/cuda-driver/src/closed_kernels/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Shared helpers of the closed-kernel tests: they read parameter kinds from the checked-in .cu sources and from the +//! Entry tables so submodules can assert that every Rust signature matches its CUDA entry and every sealed PTX its pin. use super::*; use crate::s_gemv_legacy as sg; @@ -64,7 +65,5 @@ fn arg_kinds(entry: &Entry) -> Vec<&'static str> { .collect() } -#[path = "tests/flash_and_poison_signatures_match.rs"] mod flash_and_poison_signatures_match; -#[path = "tests/sealed_assets_match_their_pins.rs"] mod sealed_assets_match_their_pins; diff --git a/crates/cuda-driver/src/closed_kernels_gpu.rs b/crates/cuda-driver/src/closed_kernels_gpu.rs index ff02fdc0..7970a2f3 100644 --- a/crates/cuda-driver/src/closed_kernels_gpu.rs +++ b/crates/cuda-driver/src/closed_kernels_gpu.rs @@ -104,6 +104,5 @@ struct Launch { } mod failure; -#[allow(unused_imports)] use failure::failure; mod closed_kernels; diff --git a/crates/cuda-driver/src/closed_kernels_gpu/closed_kernels.rs b/crates/cuda-driver/src/closed_kernels_gpu/closed_kernels.rs index 5bd08248..734ea422 100644 --- a/crates/cuda-driver/src/closed_kernels_gpu/closed_kernels.rs +++ b/crates/cuda-driver/src/closed_kernels_gpu/closed_kernels.rs @@ -1,5 +1,5 @@ -//! Groups the submodules `closed_kernels_flash_and_s_gemv`, `closed_kernels_open_admit_run`. -//! Split out of `closed_kernels_gpu` to keep its files under the line limit. +//! Module root of the ClosedKernels owner on a live context: it shares the imports of its two files, one for +//! opening, admitting and running launches and one for the concrete flash / poison / S-GEMV entry points. use super::{ Admitted, ClosedKernels, Context, DeviceBuffer, DriverResult, Error, ExperimentalError, FLASH_SHORT, diff --git a/crates/cuda-driver/src/closed_kernels_gpu/closed_kernels/closed_kernels_flash_and_s_gemv.rs b/crates/cuda-driver/src/closed_kernels_gpu/closed_kernels/closed_kernels_flash_and_s_gemv.rs index b5ef1a45..7d6fc96c 100644 --- a/crates/cuda-driver/src/closed_kernels_gpu/closed_kernels/closed_kernels_flash_and_s_gemv.rs +++ b/crates/cuda-driver/src/closed_kernels_gpu/closed_kernels/closed_kernels_flash_and_s_gemv.rs @@ -1,5 +1,5 @@ -//! Methods of `FlashBuffers`: `admit`, `operands`. -//! Methods of `ClosedKernels`: `native_flash_attn_short`, `poison_f32`, `s_gemv`, `s2_gemv`. +//! The launch entry points of ClosedKernels: short FlashAttention step, quiet-NaN poison fill and the S / S2 GEMV. +//! Each checks its operands (FlashBuffers, s_gemv_operands) and builds one Launch; opening and running are elsewhere. use super::{ ClosedKernels, DeviceBuffer, Error, ExperimentalError, FLASH_SHORT, FlashStepBuffers, Geometry, Operand, diff --git a/crates/cuda-driver/src/closed_kernels_gpu/closed_kernels/closed_kernels_open_admit_run.rs b/crates/cuda-driver/src/closed_kernels_gpu/closed_kernels/closed_kernels_open_admit_run.rs index cea0c28e..58b7154a 100644 --- a/crates/cuda-driver/src/closed_kernels_gpu/closed_kernels/closed_kernels_open_admit_run.rs +++ b/crates/cuda-driver/src/closed_kernels_gpu/closed_kernels/closed_kernels_open_admit_run.rs @@ -1,5 +1,5 @@ -//! Methods of `ClosedKernels`: `open`, `close`, `expect`, `build` and 4 more. -//! Functions: `resolve_functions`, `reject_aliasing`. +//! Lifecycle and launch plumbing of ClosedKernels: open (pin gate, module load, entry resolution), close, and the +//! per-launch checks (signature, geometry, operand admission, alias rejection) that turn slots into a Launch. use super::{ Admitted, ClosedKernels, Context, DriverResult, Error, Geometry, Launch, Operand, Program, Rc, Result, Role, Slot, diff --git a/crates/cuda-driver/src/closed_kernels_gpu/failure.rs b/crates/cuda-driver/src/closed_kernels_gpu/failure.rs index 8d846875..dc6beb5f 100644 --- a/crates/cuda-driver/src/closed_kernels_gpu/failure.rs +++ b/crates/cuda-driver/src/closed_kernels_gpu/failure.rs @@ -1,5 +1,5 @@ -//! Functions: `failure`. -//! Split out of `closed_kernels_gpu` to keep its files under the line limit. +//! Folds a primary driver failure and the outcome of the mandatory context restore into one ExperimentalError, +//! so no restore error is lost behind the first one. use super::{DriverResult, Error, ExperimentalError, combine}; diff --git a/crates/cuda-driver/src/closed_kernels_gpu_smoke.rs b/crates/cuda-driver/src/closed_kernels_gpu_smoke.rs index 07d64e9b..c2e2f126 100644 --- a/crates/cuda-driver/src/closed_kernels_gpu_smoke.rs +++ b/crates/cuda-driver/src/closed_kernels_gpu_smoke.rs @@ -94,23 +94,13 @@ fn closed_gpu_s_gemv_matches_the_shim_executed_golden() { ctx.close().unwrap(); } -#[path = "closed_kernels_gpu_smoke/cases.rs"] mod cases; -#[path = "closed_kernels_gpu_smoke/rng.rs"] mod rng; -#[allow(unused_imports)] use rng::download; -#[allow(unused_imports)] use rng::f16_bits; -#[allow(unused_imports)] use rng::f32s; -#[allow(unused_imports)] use rng::json_bytes; -#[allow(unused_imports)] use rng::json_f32; -#[allow(unused_imports)] use rng::open; -#[allow(unused_imports)] use rng::upload; -#[allow(unused_imports)] use rng::zero_kv; diff --git a/crates/cuda-driver/src/closed_kernels_gpu_smoke/rng.rs b/crates/cuda-driver/src/closed_kernels_gpu_smoke/rng.rs index 813fd76a..03c22045 100644 --- a/crates/cuda-driver/src/closed_kernels_gpu_smoke/rng.rs +++ b/crates/cuda-driver/src/closed_kernels_gpu_smoke/rng.rs @@ -1,5 +1,5 @@ -//! Methods of `Rng`: `next`, `normal`. Functions: `f16_bits`, `upload`, `download`, `f32s` and 4 more. -//! Split out of `closed_kernels_gpu_smoke` to keep its files under the line limit. +//! Helpers of the closed-kernel GPU smoke tests: a small deterministic Rng (uniform and normal-ish), f32 to f16 bits, +//! device upload / download, opening a program, zeroed KV buffers and JSON-to-vector readers for the reference cases. use super::{ClosedKernels, Context, DeviceBuffer, Program, Rng}; diff --git a/crates/cuda-driver/src/context.rs b/crates/cuda-driver/src/context.rs index dffa6c88..f73096b9 100644 --- a/crates/cuda-driver/src/context.rs +++ b/crates/cuda-driver/src/context.rs @@ -1,5 +1,5 @@ -//! Methods of `Context`: `poison`, `retain_driver`, `budget_bytes`, `device_ordinal` and 16 more. -//! Split out of `crate` to keep its files under the line limit. +//! Core of Context, the owner of one CUDA context: budget and allocation accounting, the sticky poison flag, entering +//! the context (CurrentGuard), allocate / deferred frees, synchronize, and the MoE-down pack and vector-add launches. use super::{ Context, CurrentGuard, DeviceBuffer, Error, FixedOperation, PhantomData, Rc, Result, combine, ffi, valid_size, diff --git a/crates/cuda-driver/src/context_gate_up_projection_admission.rs b/crates/cuda-driver/src/context_gate_up_projection_admission.rs index 9a3ef115..fe6174d8 100644 --- a/crates/cuda-driver/src/context_gate_up_projection_admission.rs +++ b/crates/cuda-driver/src/context_gate_up_projection_admission.rs @@ -1,5 +1,5 @@ -//! Methods of `Context`: `project_routed_gate_up_prepared_weight`, `prepared_scratch`, `gate_up_prepared_shape`, `ga... -//! Split out of `crate` to keep its files under the line limit. +//! Admission of projection launches on a Context: owner, shape, alias and temporary-budget checks for the prepared +//! routed gate/up Q8 path, the native-weight projections and the Q5_K / Q6_K matvec before any native mutation. use super::{ Context, DeviceBuffer, Error, NativeWeights, ProjectionKind, ProjectionShape, ProjectionSpec, Q5KProjectionShape, diff --git a/crates/cuda-driver/src/context_matvec_k_quant_projections.rs b/crates/cuda-driver/src/context_matvec_k_quant_projections.rs index aa3586b2..73855bae 100644 --- a/crates/cuda-driver/src/context_matvec_k_quant_projections.rs +++ b/crates/cuda-driver/src/context_matvec_k_quant_projections.rs @@ -1,5 +1,5 @@ -//! Methods of `Context`: `matvec_f32`, `q5_k_q8_1`, `q5_k_operation`, `q6_k_q8_1` and 4 more. Defines `MatvecDims`. -//! Split out of `crate` to keep its files under the line limit. +//! Context entry points for the f32 matvec and the Q5_K / Q6_K projections (MatvecDims), the shared Q8_1 activation +//! quantization with its scratch and status temporaries, and the closed-format project_q8_1 dispatch. use super::{ Context, DeviceBuffer, Error, FixedOperation, NativeWeights, ProjectionSpec, Q5KProjectionShape, Q5KShape, diff --git a/crates/cuda-driver/src/context_projection_kernel_slots.rs b/crates/cuda-driver/src/context_projection_kernel_slots.rs index 90cba01a..7b1f946c 100644 --- a/crates/cuda-driver/src/context_projection_kernel_slots.rs +++ b/crates/cuda-driver/src/context_projection_kernel_slots.rs @@ -1,5 +1,5 @@ -//! Methods of `Context`: `matvec_admission`, `kernel_slot`, `kernel_slot_rest`, `fixed_kernel` and 10 more. -//! Split out of `crate` to keep its files under the line limit. +//! Kernel cache of Context: matvec admission, the per-operation FixedKernel slots, the Q5 / Q6 pair kernels and the +//! projection kernel pairs, each loaded lazily with the context current and unloaded on failure by poisoning. use super::{ Cell, Context, DeviceBuffer, Error, FixedKernel, FixedOperation, FixedPairKernels, MatvecShape, ProjectionKernels, diff --git a/crates/cuda-driver/src/context_q8_1_and_gate_up_projection.rs b/crates/cuda-driver/src/context_q8_1_and_gate_up_projection.rs index eecabaa0..58bda301 100644 --- a/crates/cuda-driver/src/context_q8_1_and_gate_up_projection.rs +++ b/crates/cuda-driver/src/context_q8_1_and_gate_up_projection.rs @@ -1,5 +1,5 @@ -//! Methods of `Context`: `project_q8_1_weight`, `project_q8_1_operation`, `prepare_routed_gate_up_q8`, `gate_up_sour... -//! Split out of `crate` to keep its files under the line limit. +//! Q8_1 weight projection of one activation and the routed gate/up path: quantizing the activation once into a +//! RoutedGateUpQ8 (prepare), then projecting prepared scratch with each expert weight. use super::{ Context, DeviceBuffer, Error, FixedOperation, NativeWeights, ProjectionShape, ProjectionSpec, Result, RoutedFormat, diff --git a/crates/cuda-driver/src/context_unload_close_destroy.rs b/crates/cuda-driver/src/context_unload_close_destroy.rs index cd84a737..a6947538 100644 --- a/crates/cuda-driver/src/context_unload_close_destroy.rs +++ b/crates/cuda-driver/src/context_unload_close_destroy.rs @@ -1,5 +1,5 @@ -//! Methods of `Context`: `unload_projections`, `unload_projection_slot`, `unload_q5_kernels`, `unload_q6_kernels` an... -//! Methods of `CurrentGuard`: `finish`, `restore`. Implements `Drop for Context`, `Drop for CurrentGuard`. +//! Teardown of Context: unloading every cached kernel module in a fixed order, close / destroy of the CUDA context, +//! and the Drop impls of Context and CurrentGuard that restore the previously current context. use super::{Context, CurrentGuard, Error, FixedOperation, ProjectionKernels, Rc, Result, combine}; diff --git a/crates/cuda-driver/src/deferred_status.rs b/crates/cuda-driver/src/deferred_status.rs index dacfece1..77aaa998 100644 --- a/crates/cuda-driver/src/deferred_status.rs +++ b/crates/cuda-driver/src/deferred_status.rs @@ -226,8 +226,9 @@ mod device { } } #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] -#[allow(unused_imports)] -pub(crate) use device::{begin, finish, pending, resolve}; +pub(crate) use device::{begin, finish, resolve}; +#[cfg(all(test, feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] +pub(crate) use device::pending; #[cfg(not(all( feature = "cuda-driver", @@ -263,7 +264,6 @@ pub(crate) use unsupported::{begin, finish, pending, resolve}; any(target_os = "linux", target_os = "windows"), target_pointer_width = "64" ))] -#[path = "deferred_status_gpu.rs"] mod gpu_tests; #[cfg(test)] diff --git a/crates/cuda-driver/src/deferred_status_gpu.rs b/crates/cuda-driver/src/deferred_status/gpu_tests.rs similarity index 100% rename from crates/cuda-driver/src/deferred_status_gpu.rs rename to crates/cuda-driver/src/deferred_status/gpu_tests.rs diff --git a/crates/cuda-driver/src/device_buffer.rs b/crates/cuda-driver/src/device_buffer.rs index 2c488fc3..c7a173c9 100644 --- a/crates/cuda-driver/src/device_buffer.rs +++ b/crates/cuda-driver/src/device_buffer.rs @@ -1,5 +1,5 @@ -//! Methods of `DeviceBuffer`: `len`, `is_empty`, `staging`, `copy_from` and 12 more. -//! Implements `Drop for DeviceBuffer`. Functions: `chain_selects_mtp`, `chain_selects_mtp`, `set_chain_down_override`. +//! DeviceBuffer host/device copies (whole buffer and ranges, staged through a host Vec, synchronised) and its release +//! and Drop, plus the LELEKA_CHAIN 'mtp' selector chain_selects_mtp with its no-driver stubs. use super::{DeviceBuffer, Error, Result, combine, compute_drain, original_verify, vram_ledger}; #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] diff --git a/crates/cuda-driver/src/device_ref/tests.rs b/crates/cuda-driver/src/device_ref/tests.rs index 7a0db691..ae448b6b 100644 --- a/crates/cuda-driver/src/device_ref/tests.rs +++ b/crates/cuda-driver/src/device_ref/tests.rs @@ -61,21 +61,21 @@ fn a_handle_to_a_slab_range_keeps_the_slab_alive_after_the_allocator_released_it #[test] fn the_window_and_journal_modules_never_clone_a_handle() { let window_ops = [ - include_str!("../original_verify_window_ops.rs"), - include_str!("../original_verify_window_ops/gdn_stages.rs"), - include_str!("../original_verify_window_ops/window_launches.rs"), - include_str!("../original_verify_window_ops/qsa_prelude_ops.rs"), - include_str!("../original_verify_window_ops/side_qsa_branches.rs"), - include_str!("../original_verify_window_ops/side_shared_expert.rs"), - include_str!("../original_verify_window_ops/window_ops_kernels_and_pcie_plan.rs"), + include_str!("../original_verify/window_ops.rs"), + include_str!("../original_verify/window_ops/gdn_stages.rs"), + include_str!("../original_verify/window_ops/window_launches.rs"), + include_str!("../original_verify/window_ops/qsa_prelude_ops.rs"), + include_str!("../original_verify/window_ops/side_qsa_branches.rs"), + include_str!("../original_verify/window_ops/side_shared_expert.rs"), + include_str!("../original_verify/window_ops/window_ops_kernels_and_pcie_plan.rs"), ]; let journals = [ include_str!("../original_verify/original_verify_gdn_journal/verify_gdn_fused_step.rs"), include_str!("../original_verify/original_verify_gdn_journal/verify_gdn_journal_ladder_logits_scan.rs"), include_str!("../original_verify/original_verify_gdn_journal/verify_gdn_journal_stage_and_commit.rs"), include_str!("../original_verify/original_verify_gdn_journal/verify_gdn_journal_window_launches.rs"), - include_str!("../qsa_verification_commit/verify_qsa_journal_capture_commit.rs"), - include_str!("../qsa_verification_commit/verify_qsa_journal_index_image.rs"), + include_str!("../qsa_prompt_index/resident_index/verification_commit/verify_qsa_journal_capture_commit.rs"), + include_str!("../qsa_prompt_index/resident_index/verification_commit/verify_qsa_journal_index_image.rs"), ]; for source in window_ops.iter().chain(journals.iter()) { let code = source.split("#[cfg(test)]").next().unwrap_or(source); diff --git a/crates/cuda-driver/src/device_slab/tests.rs b/crates/cuda-driver/src/device_slab/tests.rs index dc14138a..ca9a6561 100644 --- a/crates/cuda-driver/src/device_slab/tests.rs +++ b/crates/cuda-driver/src/device_slab/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests of the device slab packer: policy validation, in-order aligned placement, hole reuse, direct allocations +//! above the limit, no overlapping ranges, the device memory saved for dense weights, and byte isolation of slab views. use super::*; use crate::vram_ledger::driver_bytes; diff --git a/crates/cuda-driver/src/experimental.rs b/crates/cuda-driver/src/experimental.rs index 54d15c85..ad512e83 100644 --- a/crates/cuda-driver/src/experimental.rs +++ b/crates/cuda-driver/src/experimental.rs @@ -305,48 +305,25 @@ pub(crate) struct LoadedProgram { mod tests; mod mode; -#[allow(unused_imports)] pub use mode::admit; -#[allow(unused_imports)] pub use mode::admit_ptx; -#[allow(unused_imports)] use mode::grid_x; -#[allow(unused_imports)] use mode::grid_yz; -#[allow(unused_imports)] pub(crate) use mode::invalid; -#[allow(unused_imports)] pub use mode::source_is_sealed; mod kv_shape; -#[allow(unused_imports)] pub use kv_shape::attn_chunk_grid; -#[allow(unused_imports)] pub use kv_shape::attn_merge_grid; -#[allow(unused_imports)] pub use kv_shape::attn_scratch_floats; -#[allow(unused_imports)] pub use kv_shape::check_stream_resolve; -#[allow(unused_imports)] pub use kv_shape::copy_u4_grid; -#[allow(unused_imports)] pub use kv_shape::cvec_grid; -#[allow(unused_imports)] pub use kv_shape::fwht_bytes; -#[allow(unused_imports)] pub use kv_shape::fwht_grid; -#[allow(unused_imports)] pub use kv_shape::keyless_grid; -#[allow(unused_imports)] pub use kv_shape::keyless_matrices_bytes; -#[allow(unused_imports)] pub use kv_shape::q4_batch_grid; -#[allow(unused_imports)] pub use kv_shape::q4_gather_grid; -#[allow(unused_imports)] pub use kv_shape::q4_step_grid; -#[allow(unused_imports)] pub use kv_shape::q8_gather_grid; -#[allow(unused_imports)] pub use kv_shape::q8_step_grid; -#[allow(unused_imports)] -use kv_shape::stream_error_text; diff --git a/crates/cuda-driver/src/experimental/kv_shape.rs b/crates/cuda-driver/src/experimental/kv_shape.rs index 3da6dedf..84504913 100644 --- a/crates/cuda-driver/src/experimental/kv_shape.rs +++ b/crates/cuda-driver/src/experimental/kv_shape.rs @@ -1,5 +1,5 @@ -//! Methods of `KvShape`: `real`, `as_qsa`, `base`, `check_q4` and 8 more. Methods of `Context`: `unload_experimental`. -//! Functions: `fwht_grid`, `fwht_bytes`, `q4_step_grid`, `q4_batch_grid` and 12 more. +//! KvShape of the experimental KV-cache kernels (heads, head_dim, page size) with its validity checks for Q4 / INT8 / +//! attention, the pool byte sizes, and the launch-grid planners for FWHT, Q4/Q8 step and gather, keyless and attention. use super::{ Context, ExperimentalError, Grid, KvShape, MAX_GRID_YZ, QsaShapes, Result, cvec, grid_x, grid_yz, invalid, keyless, diff --git a/crates/cuda-driver/src/experimental/mode.rs b/crates/cuda-driver/src/experimental/mode.rs index 5d686f86..bd0cd7da 100644 --- a/crates/cuda-driver/src/experimental/mode.rs +++ b/crates/cuda-driver/src/experimental/mode.rs @@ -1,5 +1,5 @@ -//! Methods of `Mode`: `name`, `bit`. Methods of `OptIn`: `with`, `is_enabled`, `is_empty`, `modes` and 2 more. -//! Implements `Display for ExperimentalError`, `Error for ExperimentalError` and 1 more. +//! The opt-in model of the experimental kernels: Mode and the OptIn set (all off by default), the Program +//! catalogue and the modes each needs, the pin / seal admission gates (fail closed), ExperimentalError, grid helpers. use super::{ CVEC_ENTRIES, CVEC_PTX, Entry, Error, ExperimentalError, KEYLESS_ENTRIES, KEYLESS_PTX, KV_Q4_ENTRIES, KV_Q4_PTX, diff --git a/crates/cuda-driver/src/experimental/tests.rs b/crates/cuda-driver/src/experimental/tests.rs index b22cb8cb..ad643770 100644 --- a/crates/cuda-driver/src/experimental/tests.rs +++ b/crates/cuda-driver/src/experimental/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests of the experimental kernel programs: entry signatures match their CUDA source, sealed PTX matches its pin, +//! modes are off by default with ordered admission, and KV grids, byte sizes and stream guards equal the Original's. use super::*; diff --git a/crates/cuda-driver/src/experimental_gpu.rs b/crates/cuda-driver/src/experimental_gpu.rs index 338956d4..7477b19a 100644 --- a/crates/cuda-driver/src/experimental_gpu.rs +++ b/crates/cuda-driver/src/experimental_gpu.rs @@ -110,12 +110,9 @@ struct Call<'g, 'c> { mod context; mod operands; -#[allow(unused_imports)] use context::i32_of; -#[allow(unused_imports)] use context::i64_of; pub use operands::*; mod facade_launches; mod stream_map; -#[allow(unused_imports)] use stream_map::failure; diff --git a/crates/cuda-driver/src/experimental_gpu/context.rs b/crates/cuda-driver/src/experimental_gpu/context.rs index 7899d9c2..3ad0a73f 100644 --- a/crates/cuda-driver/src/experimental_gpu/context.rs +++ b/crates/cuda-driver/src/experimental_gpu/context.rs @@ -1,5 +1,5 @@ -//! Methods of `Context`: `experimental_program`, `unload_failed`. Functions: `resolve_entries`, `i32_of`, `i64_of`. -//! Split out of `experimental_gpu` to keep its files under the line limit. +//! Loads an experimental Program into a Context: opt-in and pin gates, module load, entry resolution and caching +//! (nothing is published until every entry resolves), plus unload of a failed load and the i32 / i64 argument casts. use super::{ Context, DriverResult, Error, LoadedProgram, OptIn, Program, Rc, Result, admit, combine, failure, ffi, invalid, diff --git a/crates/cuda-driver/src/experimental_gpu/stream_map.rs b/crates/cuda-driver/src/experimental_gpu/stream_map.rs index 74e2b765..05624474 100644 --- a/crates/cuda-driver/src/experimental_gpu/stream_map.rs +++ b/crates/cuda-driver/src/experimental_gpu/stream_map.rs @@ -1,5 +1,5 @@ -//! Methods of `StreamMap`: `bind`. Methods of `Call`: `pointer`, `ro`, `rw`, `ro_at` and 7 more. Functions: `failure`. -//! Split out of `experimental_gpu` to keep its files under the line limit. +//! Argument binding for experimental launches: Call adds checked, context-matched pointer and scalar operands +//! (read-only / read-write, with admitted extents) and StreamMap binds the page-table and slot arrays of the KV stream. use super::{ Admitted, Arg, CTL_INTS, Call, DeviceBuffer, DriverResult, Entry, Error, ExperimentalError, Launch, Result, diff --git a/crates/cuda-driver/src/family_tests.rs b/crates/cuda-driver/src/family_tests.rs index 2905c651..55fff3e2 100644 --- a/crates/cuda-driver/src/family_tests.rs +++ b/crates/cuda-driver/src/family_tests.rs @@ -1,5 +1,5 @@ -//! Functions: `common_checked_geometry_matches_frozen_native_layouts`, `common_invalid_shapes_have_fixed_errors`, `q... -//! Defines `QuantizeBuffers`. +//! Tests of the common projection family: geometry and launch grids equal the frozen native layouts, invalid shapes +//! give fixed errors, misaligned ranges are refused, and quantizer launch / sync / restore errors keep their order. use super::*; const KINDS: [ProjectionKind; 10] = [ diff --git a/crates/cuda-driver/src/ffi.rs b/crates/cuda-driver/src/ffi.rs index 96172ec2..3659592e 100644 --- a/crates/cuda-driver/src/ffi.rs +++ b/crates/cuda-driver/src/ffi.rs @@ -8,7 +8,6 @@ //! a fixed export ABI from the newer alias. use crate::{DenseFormat, Error, FixedOperation, ProjectionKind, Result, RoutedFormat}; -#[path = "mmq_original_enqueue_ffi.rs"] pub(crate) mod original_enqueue; #[derive(Clone, Copy, PartialEq, Eq)] @@ -94,7 +93,6 @@ pub(crate) struct Q5ProjectionArguments { storage: std::ptr::NonNull, } -#[path = "mmq_ffi.rs"] mod mmq_abi; pub(crate) use mmq_abi::{ Iq3NativeIntegerArguments, MmqArguments, MmqFixupArguments, MmqGatherShape, MmqGroupBuffers, MmqGroupRouting, @@ -103,7 +101,6 @@ pub(crate) use mmq_abi::{ // Closed kernel-parameter storage of the Strata-prefill GDN / native dequant modules. #[cfg(all(any(target_os = "linux", target_os = "windows"), target_arch = "x86_64", feature = "cuda-driver"))] -#[path = "gdn_native_batch_abi.rs"] mod gdn_native_abi; #[cfg(all(any(target_os = "linux", target_os = "windows"), target_arch = "x86_64", feature = "cuda-driver"))] pub(crate) use gdn_native_abi::{GdnPrefillArguments, KernelArg}; @@ -143,29 +140,22 @@ struct HeadGreedyStorage { pub(crate) struct HeadGreedyArguments(std::ptr::NonNull); #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] -#[path = "original_expert_stager_ffi.rs"] pub(crate) mod original_stager; #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] -#[path = "original_file_expert_source_ffi.rs"] pub(crate) mod original_file_source; #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] -#[path = "deferred_status_ffi.rs"] pub(crate) mod deferred_status; mod context_handle; -#[allow(unused_imports)] pub(crate) use context_handle::projection_available; -#[allow(unused_imports)] use context_handle::projection_entry; -#[allow(unused_imports)] use context_handle::projection_ptx; #[cfg(any( test, all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64") ))] -#[allow(unused_imports)] use context_handle::validate_projection_ptx; mod api; mod function_handle; diff --git a/crates/cuda-driver/src/ffi/api.rs b/crates/cuda-driver/src/ffi/api.rs index be7e0cf6..053edf2d 100644 --- a/crates/cuda-driver/src/ffi/api.rs +++ b/crates/cuda-driver/src/ffi/api.rs @@ -1,5 +1,5 @@ -//! Methods of `Api`: `memory_info`, `mmq_capabilities`, `load_mmq`, `mmq_function` and 56 more. -//! Split out of `ffi` to keep its files under the line limit. +//! Stub of the whole ffi Api (module loads, launches, memory, contexts) for builds without a usable CUDA driver: +//! every method returns UnsupportedPlatform; the real implementation is in driver_backed. #[cfg(not(all( feature = "cuda-driver", diff --git a/crates/cuda-driver/src/ffi/context_handle.rs b/crates/cuda-driver/src/ffi/context_handle.rs index 13d66dfe..040f2bb6 100644 --- a/crates/cuda-driver/src/ffi/context_handle.rs +++ b/crates/cuda-driver/src/ffi/context_handle.rs @@ -1,9 +1,8 @@ -//! Methods of `ContextHandle`: `synthetic`. -//! Methods of `BufferHandle`: `registered_bank_alias`, `checked_subspan`, `qwen_address`, `validate_extent` and 7 more. +//! Typed handles of device memory and modules: BufferHandle checks extents, sub-spans, alignment, overlap and MoE down +//! slots before a driver call, and the selection of the PTX image and entry name for each projection kind. use super::{BufferHandle, DenseFormat, Error, ProjectionKind, Result, RoutedFormat}; // used only with some cargo features or targets of this crate -#[allow(unused_imports)] use super::ModuleHandle; #[cfg(all( diff --git a/crates/cuda-driver/src/deferred_status_ffi.rs b/crates/cuda-driver/src/ffi/deferred_status.rs similarity index 100% rename from crates/cuda-driver/src/deferred_status_ffi.rs rename to crates/cuda-driver/src/ffi/deferred_status.rs diff --git a/crates/cuda-driver/src/ffi/driver_backed.rs b/crates/cuda-driver/src/ffi/driver_backed.rs index 28c14400..42faff97 100644 --- a/crates/cuda-driver/src/ffi/driver_backed.rs +++ b/crates/cuda-driver/src/ffi/driver_backed.rs @@ -106,7 +106,6 @@ macro_rules! symbol { include!("../kar_decode_levels_ffi.rs"); mod library_drop; -#[allow(unused_imports)] use library_drop::check; mod api; mod device_context_memory_copies; diff --git a/crates/cuda-driver/src/ffi/driver_backed/api.rs b/crates/cuda-driver/src/ffi/driver_backed/api.rs index 92aaef4b..1ce881dc 100644 --- a/crates/cuda-driver/src/ffi/driver_backed/api.rs +++ b/crates/cuda-driver/src/ffi/driver_backed/api.rs @@ -1,5 +1,5 @@ -//! Methods of `Api`: `memory_info`, `mmq_capabilities`, `load_mmq`, `mmq_function` and 9 more. -//! Split out of `enabled` to keep its files under the line limit. +//! Api calls of the real driver for the fixed-function kernels of the MMQ family: memory info, MMQ capability and +//! shared-memory limit, IQ3 native integer, resident d4 and head-greedy module loads and launches. use super::{ Api, CuDevice, CuResult, Error, FunctionHandle, HeadGreedyArguments, Iq3NativeIntegerArguments, MemGetInfoV2, diff --git a/crates/cuda-driver/src/ffi/driver_backed/device_context_memory_copies.rs b/crates/cuda-driver/src/ffi/driver_backed/device_context_memory_copies.rs index a78dce8a..a4424db4 100644 --- a/crates/cuda-driver/src/ffi/driver_backed/device_context_memory_copies.rs +++ b/crates/cuda-driver/src/ffi/driver_backed/device_context_memory_copies.rs @@ -1,5 +1,5 @@ -//! Methods of `Api`: `device`, `create`, `destroy`, `push` and 11 more. -//! Split out of `enabled` to keep its files under the line limit. +//! Driver Api calls for devices, contexts and memory: cuDeviceGet, context create / destroy / push / pop, +//! synchronize, allocate / free, host-device copies, zeroing and the device-to-device weight and MoE down copies. use super::{Api, BufferHandle, ContextHandle, CuContext, Error, Result, c_void, check}; diff --git a/crates/cuda-driver/src/ffi/driver_backed/library_drop.rs b/crates/cuda-driver/src/ffi/driver_backed/library_drop.rs index 2b25d9c6..ec9cd468 100644 --- a/crates/cuda-driver/src/ffi/driver_backed/library_drop.rs +++ b/crates/cuda-driver/src/ffi/driver_backed/library_drop.rs @@ -1,5 +1,5 @@ -//! Implements `Drop for Library`. Functions: `check`. -//! Split out of `enabled` to keep its files under the line limit. +//! Ownership of the dlopen'ed driver library (dlclose on Drop) and check(), which maps a non-zero CUDA result +//! code to Error::Driver; kept apart as the two primitives every driver-backed call depends on. use super::{CuResult, Error, Library, Result}; diff --git a/crates/cuda-driver/src/ffi/driver_backed/library_load_fixed_operations.rs b/crates/cuda-driver/src/ffi/driver_backed/library_load_fixed_operations.rs index 40827deb..55d98141 100644 --- a/crates/cuda-driver/src/ffi/driver_backed/library_load_fixed_operations.rs +++ b/crates/cuda-driver/src/ffi/driver_backed/library_load_fixed_operations.rs @@ -1,5 +1,5 @@ -//! Methods of `Api`: `launch_qwen`, `load`, `resolve`, `load_q6_batch_preview` and 4 more. -//! Functions: `is_projection_family`. +//! Loads libcuda.so.1 and resolves the sixteen fixed driver symbols into the Api (dlopen, no CUDA toolkit needed), +//! plus the fixed-operation and Q6 batch module loads, function lookup and the launch_qwen entry point. use super::{ Api, COMMON_QUANTIZER_PTX, ContextCreateV2, ContextDestroyV2, ContextPopCurrentV2, ContextPushCurrentV2, diff --git a/crates/cuda-driver/src/ffi/driver_backed/matvec_projection_launches.rs b/crates/cuda-driver/src/ffi/driver_backed/matvec_projection_launches.rs index 6027f604..c701069d 100644 --- a/crates/cuda-driver/src/ffi/driver_backed/matvec_projection_launches.rs +++ b/crates/cuda-driver/src/ffi/driver_backed/matvec_projection_launches.rs @@ -1,5 +1,5 @@ -//! Methods of `Api`: `unload`, `launch`, `launch_gr_read_guard`, `launch_matvec` and 8 more. -//! Split out of `enabled` to keep its files under the line limit. +//! Real-driver kernel launches of the dense path: module unload, generic launch, matvec, Q8 quantize, Q5 / Q6 and +//! dense / grouped projections, grouped SwiGLU and the GR read guard, each with its grid and arguments checked. use super::{ Api, FunctionHandle, GrReadGuardArguments, LaunchArguments, MatvecArguments, ModuleHandle, ProjectionArguments, diff --git a/crates/cuda-driver/src/ffi/driver_backed/mmq_original_group_launches.rs b/crates/cuda-driver/src/ffi/driver_backed/mmq_original_group_launches.rs index e9bc1bc4..3298704d 100644 --- a/crates/cuda-driver/src/ffi/driver_backed/mmq_original_group_launches.rs +++ b/crates/cuda-driver/src/ffi/driver_backed/mmq_original_group_launches.rs @@ -1,5 +1,5 @@ -//! Methods of `Api`: `mmq_original_group_shared_limit`, `load_mmq_original_group`, `mmq_original_group_function`, `l... -//! Split out of `enabled` to keep its files under the line limit. +//! Real-driver loads and launches of the Original's grouped MMQ path: shared-memory limit query, group module and +//! function lookup, the gather and group-helper launches. use super::{ Api, CuDevice, CuResult, Error, FunctionHandle, MMQ_ORIGINAL_GROUP_SYMBOLS, MmqOriginalGatherArguments, diff --git a/crates/cuda-driver/src/ffi/driver_backed/mmq_resident_qsa_selected_launches.rs b/crates/cuda-driver/src/ffi/driver_backed/mmq_resident_qsa_selected_launches.rs index 8621a956..c7105343 100644 --- a/crates/cuda-driver/src/ffi/driver_backed/mmq_resident_qsa_selected_launches.rs +++ b/crates/cuda-driver/src/ffi/driver_backed/mmq_resident_qsa_selected_launches.rs @@ -1,5 +1,5 @@ -//! Methods of `Api`: `launch_mmq_original_swiglu`, `load_mmq_resident`, `mmq_resident_function`, `launch_mmq_residen... -//! Split out of `enabled` to keep its files under the line limit. +//! Real-driver loads and launches of the resident MMQ pipeline (SwiGLU, quantize, project, fixup), the QSA selected +//! gather kernels and the Qwen asset modules (load_qwen_module, qwen_function). use super::{ Api, Error, FunctionHandle, MmqArguments, MmqFixupArguments, MmqOriginalSwigluArguments, MmqQuantArguments, diff --git a/crates/cuda-driver/src/ffi/function_handle.rs b/crates/cuda-driver/src/ffi/function_handle.rs index 86fd93f6..95fde86c 100644 --- a/crates/cuda-driver/src/ffi/function_handle.rs +++ b/crates/cuda-driver/src/ffi/function_handle.rs @@ -1,5 +1,5 @@ -//! Methods of `FunctionHandle`: `qwen_success`, `synthetic`. Methods of `LaunchArguments`: `new`. -//! Implements `Drop for LaunchArguments`, `Drop for GrReadGuardArguments` and 3 more. +//! FunctionHandle constructors and the heap-pinned kernel-argument blocks (LaunchArguments, matvec, Q8 quantize, +//! Q5 / Q6 / dense projection, GR read guard): self-referential parameter arrays built once and freed by Drop. use super::{ ArgumentStorage, BufferHandle, GrReadGuardArguments, GrReadGuardStorage, LaunchArguments, MatvecArguments, @@ -7,7 +7,6 @@ use super::{ Q6ProjectionArguments, Q6ProjectionStorage, Q8QuantizeArguments, Q8QuantizeStorage, }; // used only with some cargo features or targets of this crate -#[allow(unused_imports)] use super::{Error, FunctionHandle, Result}; #[cfg(all(any(target_os = "linux", target_os = "windows"), target_arch = "x86_64", feature = "cuda-driver"))] diff --git a/crates/cuda-driver/src/gdn_native_batch_abi.rs b/crates/cuda-driver/src/ffi/gdn_native_abi.rs similarity index 100% rename from crates/cuda-driver/src/gdn_native_batch_abi.rs rename to crates/cuda-driver/src/ffi/gdn_native_abi.rs diff --git a/crates/cuda-driver/src/mmq_ffi.rs b/crates/cuda-driver/src/ffi/mmq_abi.rs similarity index 92% rename from crates/cuda-driver/src/mmq_ffi.rs rename to crates/cuda-driver/src/ffi/mmq_abi.rs index 2dbe9709..e10ca03b 100644 --- a/crates/cuda-driver/src/mmq_ffi.rs +++ b/crates/cuda-driver/src/ffi/mmq_abi.rs @@ -54,11 +54,7 @@ pub(crate) struct MmqGatherShape { pub(crate) blocks: u32, } -#[path = "mmq_ffi/owned.rs"] mod owned; -#[allow(unused_imports)] use owned::fastdiv; -#[path = "mmq_ffi/mmq_original_gather_arguments.rs"] mod mmq_original_gather_arguments; -#[path = "mmq_ffi/mmq_resident_arguments.rs"] mod mmq_resident_arguments; diff --git a/crates/cuda-driver/src/mmq_ffi/mmq_original_gather_arguments.rs b/crates/cuda-driver/src/ffi/mmq_abi/mmq_original_gather_arguments.rs similarity index 88% rename from crates/cuda-driver/src/mmq_ffi/mmq_original_gather_arguments.rs rename to crates/cuda-driver/src/ffi/mmq_abi/mmq_original_gather_arguments.rs index e292e5d8..bc5f5c01 100644 --- a/crates/cuda-driver/src/mmq_ffi/mmq_original_gather_arguments.rs +++ b/crates/cuda-driver/src/ffi/mmq_abi/mmq_original_gather_arguments.rs @@ -1,5 +1,5 @@ -//! Methods of `MmqOriginalGatherArguments`: `new`, `parameters`. -//! Split out of `mmq_abi` to keep its files under the line limit. +//! Parameter block of the Original's gather (copy16) kernel launch: the raw, gate-up and down addresses and +//! 16-byte element counts laid out in the kernel's ABI order. use super::{BufferHandle, MmqOriginalGatherArguments, Owned, c_void}; diff --git a/crates/cuda-driver/src/mmq_ffi/mmq_resident_arguments.rs b/crates/cuda-driver/src/ffi/mmq_abi/mmq_resident_arguments.rs similarity index 97% rename from crates/cuda-driver/src/mmq_ffi/mmq_resident_arguments.rs rename to crates/cuda-driver/src/ffi/mmq_abi/mmq_resident_arguments.rs index dad15f8e..3adbe962 100644 --- a/crates/cuda-driver/src/mmq_ffi/mmq_resident_arguments.rs +++ b/crates/cuda-driver/src/ffi/mmq_abi/mmq_resident_arguments.rs @@ -1,5 +1,5 @@ -//! Methods of `MmqResidentArguments`: `native_resident_d4`, `zero`, `finite`, `gather` and 1 more. -//! Methods of `Iq3NativeIntegerArguments`: `dot`, `reduce`, `new`, `parameters`. +//! Parameter blocks for the resident MMQ and native IQ3 launches: resident d4, zero, finite check, gather, IQ3 +//! dot / reduce, Original indexed quantize, grouped MMQ, fixup and SwiGLU, each laid out in its kernel's ABI order. use super::{ BufferHandle, Iq3NativeIntegerArguments, Layout, MmqArguments, MmqFixupArguments, MmqGatherShape, MmqGroupBuffers, diff --git a/crates/cuda-driver/src/mmq_ffi/owned.rs b/crates/cuda-driver/src/ffi/mmq_abi/owned.rs similarity index 96% rename from crates/cuda-driver/src/mmq_ffi/owned.rs rename to crates/cuda-driver/src/ffi/mmq_abi/owned.rs index b80469b7..5d27691c 100644 --- a/crates/cuda-driver/src/mmq_ffi/owned.rs +++ b/crates/cuda-driver/src/ffi/mmq_abi/owned.rs @@ -1,5 +1,5 @@ -//! Methods of `Owned`: `new`, `parameters`. Methods of `MmqQuantArguments`: `new`, `parameters`. -//! Implements `Drop for Owned`. Functions: `fastdiv`. +//! Owned: the heap-pinned Storage (addresses, wide, integers, fastdiv divisors, parameter pointers) behind every MMQ +//! argument block, freed once on Drop; also the fast-division constants and the quantize, MMQ and fixup block builders. use super::{BufferHandle, Layout, MmqArguments, MmqFixupArguments, MmqQuantArguments, Owned, Storage, c_void}; diff --git a/crates/cuda-driver/src/mmq_original_enqueue_ffi.rs b/crates/cuda-driver/src/ffi/original_enqueue.rs similarity index 100% rename from crates/cuda-driver/src/mmq_original_enqueue_ffi.rs rename to crates/cuda-driver/src/ffi/original_enqueue.rs diff --git a/crates/cuda-driver/src/original_file_expert_source_ffi.rs b/crates/cuda-driver/src/ffi/original_file_source.rs similarity index 82% rename from crates/cuda-driver/src/original_file_expert_source_ffi.rs rename to crates/cuda-driver/src/ffi/original_file_source.rs index c934caf3..457a0783 100644 --- a/crates/cuda-driver/src/original_file_expert_source_ffi.rs +++ b/crates/cuda-driver/src/ffi/original_file_source.rs @@ -45,22 +45,13 @@ pub(crate) struct Copy { } #[cfg(test)] -#[path = "original_file_expert_source_ffi/tests.rs"] +#[path = "../original_file_expert_source_ffi/tests.rs"] mod tests; -#[path = "original_file_expert_source_ffi/check.rs"] mod check; -#[allow(unused_imports)] -use check::check; -#[path = "original_file_expert_source_ffi/arena.rs"] mod arena; -#[allow(unused_imports)] pub(crate) use arena::copy_parts_record; -#[allow(unused_imports)] pub(crate) use arena::copy_parts_to; -#[allow(unused_imports)] pub(crate) use arena::partial_pin_cap; -#[allow(unused_imports)] pub(crate) use arena::warm; -#[allow(unused_imports)] pub(crate) use arena::worker_stack_bytes; diff --git a/crates/cuda-driver/src/original_file_expert_source_ffi/arena.rs b/crates/cuda-driver/src/ffi/original_file_source/arena.rs similarity index 96% rename from crates/cuda-driver/src/original_file_expert_source_ffi/arena.rs rename to crates/cuda-driver/src/ffi/original_file_source/arena.rs index 9fc8d5b3..98632576 100644 --- a/crates/cuda-driver/src/original_file_expert_source_ffi/arena.rs +++ b/crates/cuda-driver/src/ffi/original_file_source/arena.rs @@ -1,5 +1,5 @@ -//! Methods of `Arena`: `bytes`, `pin_limit`, `locked`, `lock_offset` and 5 more. -//! Methods of `Copy`: `into_slice`, `run`. +//! Host arena of the file expert source: a malloc / pinned block with partial mlock, checked writes, reads and +//! aliases of byte ranges, the three-part parallel Copy of expert pieces, page warm-up and worker stack sizing. use super::{Arena, Copy, Error, P, Result}; diff --git a/crates/cuda-driver/src/original_file_expert_source_ffi/check.rs b/crates/cuda-driver/src/ffi/original_file_source/check.rs similarity index 97% rename from crates/cuda-driver/src/original_file_expert_source_ffi/check.rs rename to crates/cuda-driver/src/ffi/original_file_source/check.rs index be9eecae..0a71f756 100644 --- a/crates/cuda-driver/src/original_file_expert_source_ffi/check.rs +++ b/crates/cuda-driver/src/ffi/original_file_source/check.rs @@ -1,5 +1,5 @@ -//! Methods of `Api`: `load`, `allocate`, `try_pinned`, `exchange_allocate` and 3 more. -//! Implements `Drop for Opening`, `Drop for Api`. Functions: `check`, `symbol`. Defines `Opening`. +//! The host-memory Api of the file expert source: dlopen of libcuda for page-locked alloc / register / device alias / +//! async copy, arena allocation (pinned or malloc), exchange copies and close, with the symbol and result checks. use super::{Alias, Alloc, Api, Arc, Arena, ArenaSpan, CStr, DtoH, Error, Free, P, Register, Result}; diff --git a/crates/cuda-driver/src/original_expert_stager_ffi.rs b/crates/cuda-driver/src/ffi/original_stager.rs similarity index 91% rename from crates/cuda-driver/src/original_expert_stager_ffi.rs rename to crates/cuda-driver/src/ffi/original_stager.rs index afec2221..740ad5e8 100644 --- a/crates/cuda-driver/src/original_expert_stager_ffi.rs +++ b/crates/cuda-driver/src/ffi/original_stager.rs @@ -62,14 +62,10 @@ pub(crate) struct ExpertFileMap { } #[cfg(test)] -#[path = "original_expert_stager_ffi/tests.rs"] +#[path = "../original_expert_stager_ffi/tests.rs"] mod tests; -#[path = "original_expert_stager_ffi/check.rs"] mod check; -#[allow(unused_imports)] use check::check; -#[path = "original_expert_stager_ffi/api.rs"] mod api; -#[path = "original_expert_stager_ffi/host_buffer.rs"] mod host_buffer; diff --git a/crates/cuda-driver/src/original_expert_stager_ffi/api.rs b/crates/cuda-driver/src/ffi/original_stager/api.rs similarity index 97% rename from crates/cuda-driver/src/original_expert_stager_ffi/api.rs rename to crates/cuda-driver/src/ffi/original_stager/api.rs index 201a4a30..fc167246 100644 --- a/crates/cuda-driver/src/original_expert_stager_ffi/api.rs +++ b/crates/cuda-driver/src/ffi/original_stager/api.rs @@ -1,5 +1,5 @@ -//! Methods of `Api`: `record`, `wait`, `copy_slot`, `load` and 13 more. Implements `Drop for Opening`. -//! Functions: `symbol`. Defines `Opening`. +//! Driver Api of the expert stager: dlopen of libcuda, pinned host buffers, events (record / wait / timing / +//! query), async slot copies and the worker context enter / leave that let staging threads issue DMA safely. use super::{ Api, BufferHandle, CStr, ContextHandle, Copy, Elapsed, Error, EventCreate, EventRecord, Handle, HandleCall, diff --git a/crates/cuda-driver/src/original_expert_stager_ffi/check.rs b/crates/cuda-driver/src/ffi/original_stager/check.rs similarity index 75% rename from crates/cuda-driver/src/original_expert_stager_ffi/check.rs rename to crates/cuda-driver/src/ffi/original_stager/check.rs index 3214ad0f..33a271c9 100644 --- a/crates/cuda-driver/src/original_expert_stager_ffi/check.rs +++ b/crates/cuda-driver/src/ffi/original_stager/check.rs @@ -1,5 +1,5 @@ -//! Implements `Drop for Api`. Functions: `check`. -//! Split out of `original_stager` to keep its files under the line limit. +//! Result-code check of the stager's driver calls, and the Drop of its Api that dlcloses libcuda only after the +//! last worker holding an Arc of it is gone. use super::{Api, Error, Handle, Result}; diff --git a/crates/cuda-driver/src/original_expert_stager_ffi/host_buffer.rs b/crates/cuda-driver/src/ffi/original_stager/host_buffer.rs similarity index 97% rename from crates/cuda-driver/src/original_expert_stager_ffi/host_buffer.rs rename to crates/cuda-driver/src/ffi/original_stager/host_buffer.rs index 5e91a1ab..902cb0c5 100644 --- a/crates/cuda-driver/src/original_expert_stager_ffi/host_buffer.rs +++ b/crates/cuda-driver/src/ffi/original_stager/host_buffer.rs @@ -1,5 +1,5 @@ -//! Methods of `HostBuffer`: `pinned`, `capacity`, `slot`. -//! Methods of `CopyJob`: `from_slices`, `bytes`, `copy_to`, `copy_segment` and 1 more. +//! Host side of expert staging: pinned HostBuffer slots, CopyJob (three source slices copied into a slot) and the +//! read-only mmap of the expert file (ExpertFileMap) from which expert byte ranges are read. use super::{CopyJob, Error, ExpertFileMap, HostBuffer, Result, WorkerSlot, c_void}; diff --git a/crates/cuda-driver/src/ffi/projection_tests.rs b/crates/cuda-driver/src/ffi/projection_tests.rs index 5ed16c21..55992694 100644 --- a/crates/cuda-driver/src/ffi/projection_tests.rs +++ b/crates/cuda-driver/src/ffi/projection_tests.rs @@ -1,5 +1,5 @@ -//! Functions: `new_fixed_asset_encoding_refuses_unicode_before_driver_call`, `q4_k_dense_selector_resolves_only_its_... -//! Split out of `ffi` to keep its files under the line limit. +//! Tests of the ffi projection assets: fixed PTX must be ASCII, each format selector (Q4_K, IQ3_S, IQ2_S, Q2_0, +//! IQ4_NL, IQ4_XS) resolves only its own asset and entry, plus handle alignment / overlap and exact parameter widths. use super::*; #[test] diff --git a/crates/cuda-driver/src/ffi/q5_projection_arguments_drop.rs b/crates/cuda-driver/src/ffi/q5_projection_arguments_drop.rs index 4ed5166a..24adc83d 100644 --- a/crates/cuda-driver/src/ffi/q5_projection_arguments_drop.rs +++ b/crates/cuda-driver/src/ffi/q5_projection_arguments_drop.rs @@ -1,5 +1,5 @@ -//! Implements `Drop for Q5ProjectionArguments`, `Drop for MatvecArguments`. -//! Split out of `ffi` to keep its files under the line limit. +//! Drop of the Q5 projection and matvec argument blocks: the boxed storage is freed once, and only when the +//! launch never started or completed; after an uncertain sync the owner is forgotten and the block leaks on purpose. use super::{MatvecArguments, Q5ProjectionArguments}; diff --git a/crates/cuda-driver/src/ffi/qsa_selected_arguments.rs b/crates/cuda-driver/src/ffi/qsa_selected_arguments.rs index 3c0db652..e8f3a36f 100644 --- a/crates/cuda-driver/src/ffi/qsa_selected_arguments.rs +++ b/crates/cuda-driver/src/ffi/qsa_selected_arguments.rs @@ -1,5 +1,5 @@ -//! Methods of `QsaSelectedArguments`: `new`, `parameters`. Methods of `HeadGreedyArguments`: `new`, `parameters`. -//! Implements `Drop for QsaSelectedArguments`, `Drop for HeadGreedyArguments`. +//! Parameter blocks of two small kernels, QSA selected (five buffers, layer, count) and head greedy (source, +//! output): boxed, self-referential pointer arrays freed once by Drop unless completion was uncertain. use super::{BufferHandle, HeadGreedyArguments, HeadGreedyStorage, QsaSelectedArguments, QsaSelectedStorage}; diff --git a/crates/cuda-driver/src/ffi/tests.rs b/crates/cuda-driver/src/ffi/tests.rs index 26ca663a..bea24f0e 100644 --- a/crates/cuda-driver/src/ffi/tests.rs +++ b/crates/cuda-driver/src/ffi/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of `ffi`. +//! Tests of ffi handle arithmetic: checked sub-spans refuse empty, wrapping and out-of-allocation ranges, matvec +//! address extents are validated, and the raw argument storage keeps its address when its owner moves. #[test] fn checked_subspan_refuses_empty_wrap_and_outside_allocation() { diff --git a/crates/cuda-driver/src/gdn_native_batch/tests.rs b/crates/cuda-driver/src/gdn_native_batch/tests.rs index c9022497..da2072c8 100644 --- a/crates/cuda-driver/src/gdn_native_batch/tests.rs +++ b/crates/cuda-driver/src/gdn_native_batch/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of `gdn_native_batch`. +//! Tests of the native GDN batch program: stage slots and sizes, the fixed step order, earliest-status refusal, +//! witness errors, native format geometry, closed kernel table, 256-block launches, bindings, and artifact pin checks. use super::*; diff --git a/crates/cuda-driver/src/gr_batch_read/gr_microbatch_read.rs b/crates/cuda-driver/src/gr_batch_read/gr_microbatch_read.rs deleted file mode 100644 index 759eb1a7..00000000 --- a/crates/cuda-driver/src/gr_batch_read/gr_microbatch_read.rs +++ /dev/null @@ -1,14 +0,0 @@ -//! Groups the submodules `gr_microbatch_read_inject`, `gr_microbatch_read_open`, `micro_stage_launch`. -//! Split out of `gr_batch_read` to keep its files under the line limit. - -use super::{ - Arguments, Context, DeviceBuffer, Error, FixedKernel, GrMicroValues, GrMicrobatchRead, OPS, Operation, RESERVE, - Result, SIZES, STAGES, checked_row, combine, decode, encode, ffi, qwen_ffi, ranges_layout, registered, -}; - -#[path = "gr_microbatch_read/gr_microbatch_read_inject.rs"] -mod gr_microbatch_read_inject; -#[path = "gr_microbatch_read/gr_microbatch_read_open.rs"] -mod gr_microbatch_read_open; -#[path = "gr_microbatch_read/micro_stage_launch.rs"] -mod micro_stage_launch; diff --git a/crates/cuda-driver/src/gr_read_guard.rs b/crates/cuda-driver/src/gr_read_guard.rs index 7089d0f2..ec566a29 100644 --- a/crates/cuda-driver/src/gr_read_guard.rs +++ b/crates/cuda-driver/src/gr_read_guard.rs @@ -3,7 +3,6 @@ use super::{Context, DeviceBuffer, Error, Result, combine, ffi}; #[cfg(test)] use super::Driver; // used only with some cargo features or targets of this crate -#[allow(unused_imports)] use super::{FixedOperation, Rc}; const BYTES: [usize; 5] = [40960, 1280, 1280, 40960, 40960]; fn shape(bytes: [usize; 5]) -> Result<()> { diff --git a/crates/cuda-driver/src/head_greedy.rs b/crates/cuda-driver/src/head_greedy.rs index 816abadd..7d2c1386 100644 --- a/crates/cuda-driver/src/head_greedy.rs +++ b/crates/cuda-driver/src/head_greedy.rs @@ -245,7 +245,6 @@ impl Drop for HeadGreedyWorkspace<'_> { } #[cfg(all(test, any(target_os = "linux", target_os = "windows"), target_arch = "x86_64"))] -#[path = "head_greedy_gpu.rs"] mod gpu; const ASSET_SHA: [u8; 32] = [ diff --git a/crates/cuda-driver/src/head_greedy_gpu.rs b/crates/cuda-driver/src/head_greedy/gpu.rs similarity index 100% rename from crates/cuda-driver/src/head_greedy_gpu.rs rename to crates/cuda-driver/src/head_greedy/gpu.rs diff --git a/crates/cuda-driver/src/kar_decode_levels/tests.rs b/crates/cuda-driver/src/kar_decode_levels/tests.rs index 30532a40..2c2f0b68 100644 --- a/crates/cuda-driver/src/kar_decode_levels/tests.rs +++ b/crates/cuda-driver/src/kar_decode_levels/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests of the KAR level-decode kernel contract: DecodeGeometry window layouts and bounds, multiply and expert +//! shapes, fail-closed status word, the sealed PTX against its pin, and the Rust constants against the CUDA source. use super::*; diff --git a/crates/cuda-driver/src/kar_decode_levels_gpu.rs b/crates/cuda-driver/src/kar_decode_levels_gpu.rs index cf676f28..736dbd66 100644 --- a/crates/cuda-driver/src/kar_decode_levels_gpu.rs +++ b/crates/cuda-driver/src/kar_decode_levels_gpu.rs @@ -74,13 +74,8 @@ mod context; mod expert_mlp; mod f32_bytes; mod kar_decode_levels; -#[allow(unused_imports)] use f32_bytes::download; -#[allow(unused_imports)] use f32_bytes::f32_bytes; -#[allow(unused_imports)] use f32_bytes::failure; -#[allow(unused_imports)] use f32_bytes::finite_f32; -#[allow(unused_imports)] use f32_bytes::release_all; diff --git a/crates/cuda-driver/src/kar_decode_levels_gpu/context.rs b/crates/cuda-driver/src/kar_decode_levels_gpu/context.rs index 1cb72921..6e8164f3 100644 --- a/crates/cuda-driver/src/kar_decode_levels_gpu/context.rs +++ b/crates/cuda-driver/src/kar_decode_levels_gpu/context.rs @@ -1,5 +1,5 @@ -//! Methods of `Context`: `kar_levels_kernels`, `resolve_kar_entries`, `abandon_kar_module`. -//! Split out of `kar_decode_levels_gpu` to keep its files under the line limit. +//! Loads the KAR level-decode PTX into a Context: pin admission, one cached module, resolution of the decode / +//! multiply / SwiGLU entries (nothing published until all resolve) and unloading of a half-resolved module. use super::{ Context, DriverResult, ENTRY_DECODE, ENTRY_MULTIPLY, ENTRY_SWIGLU, Error, KAR_DECODE_LEVELS_PIN, diff --git a/crates/cuda-driver/src/kar_decode_levels_gpu/expert_mlp.rs b/crates/cuda-driver/src/kar_decode_levels_gpu/expert_mlp.rs index 106e0e07..b718cefc 100644 --- a/crates/cuda-driver/src/kar_decode_levels_gpu/expert_mlp.rs +++ b/crates/cuda-driver/src/kar_decode_levels_gpu/expert_mlp.rs @@ -1,4 +1,5 @@ -//! Moved out of kar_decode_levels.rs by the STRA-338 size pass: the single-token routed expert FFN. +//! Single-token routed expert FFN on the GPU from KAR-packed matrices: buffer allocation and admission, the +//! gate / up / SwiGLU / down launch sequence and the host read-back of the checked output (expert_mlp_to_host). use super::{ Admitted, BLOCK_THREADS, Context, DeviceBuffer, ExpertShape, KarDecodeError, KarDecodeLevels, KarMatrix, Launch, diff --git a/crates/cuda-driver/src/kar_decode_levels_gpu/f32_bytes.rs b/crates/cuda-driver/src/kar_decode_levels_gpu/f32_bytes.rs index 183ba00e..2c7bf28b 100644 --- a/crates/cuda-driver/src/kar_decode_levels_gpu/f32_bytes.rs +++ b/crates/cuda-driver/src/kar_decode_levels_gpu/f32_bytes.rs @@ -1,5 +1,5 @@ -//! Functions: `f32_bytes`, `download`, `failure`, `release_all` and 1 more. -//! Split out of `kar_decode_levels_gpu` to keep its files under the line limit. +//! Small host helpers of the KAR GPU owner: f32 to little-endian bytes, device download, finite-only f32 parse, +//! joint release of buffers, and folding a primary failure with the context restore into one KarDecodeError. use super::{DeviceBuffer, DriverResult, Error, KarDecodeError, Result, combine}; diff --git a/crates/cuda-driver/src/kar_decode_levels_gpu/kar_decode_levels.rs b/crates/cuda-driver/src/kar_decode_levels_gpu/kar_decode_levels.rs index 22f4fc70..afb6bd00 100644 --- a/crates/cuda-driver/src/kar_decode_levels_gpu/kar_decode_levels.rs +++ b/crates/cuda-driver/src/kar_decode_levels_gpu/kar_decode_levels.rs @@ -1,5 +1,5 @@ -//! Methods of `KarDecodeLevels`: `open`, `close`, `admit`, `disjoint` and 15 more. Defines `MultiplyBuffers`. -//! Split out of `kar_decode_levels_gpu` to keep its files under the line limit. +//! The KarDecodeLevels owner: opens the module on a context, admits buffers and builds decode / multiply launches, +//! runs them under one drain, and offers decode_to_host / decode_multiply_to_host with status and finite checks. use super::{ Admitted, BLOCK_THREADS, Context, DecodeGeometry, DecodeMultiplyBuffers, DeviceBuffer, Error, KarDecodeError, diff --git a/crates/cuda-driver/src/kv_stream_gpu.rs b/crates/cuda-driver/src/kv_stream_gpu.rs index 687fe049..d2fbf464 100644 --- a/crates/cuda-driver/src/kv_stream_gpu.rs +++ b/crates/cuda-driver/src/kv_stream_gpu.rs @@ -45,21 +45,12 @@ fn streamed_attention_equals_fully_resident_attention_with_a_20480_cell_window() mod append_proof; mod rng; mod stream_proof; -#[allow(unused_imports)] use rng::addr; -#[allow(unused_imports)] use rng::f32s; -#[allow(unused_imports)] use rng::group; -#[allow(unused_imports)] use rng::i32s; -#[allow(unused_imports)] use rng::launch; -#[allow(unused_imports)] use rng::load; -#[allow(unused_imports)] use rng::selection; -#[allow(unused_imports)] use rng::upload; -#[allow(unused_imports)] use rng::{ImageLayout, KernelShape, expected}; diff --git a/crates/cuda-driver/src/kv_stream_gpu/rng.rs b/crates/cuda-driver/src/kv_stream_gpu/rng.rs index f9049b96..fb3dca74 100644 --- a/crates/cuda-driver/src/kv_stream_gpu/rng.rs +++ b/crates/cuda-driver/src/kv_stream_gpu/rng.rs @@ -1,5 +1,5 @@ -//! Methods of `Rng`: `next`, `unit`, `below`. Functions: `upload`, `addr`, `f32s`, `i32s` and 6 more. -//! Defines `KernelShape`, `ImageLayout`. +//! Shared fixtures of the KV-stream GPU proofs: an xorshift Rng, device upload / address / byte helpers, a kernel +//! launch and module-load wrapper, random value groups and block selections, and the expected pool image layout. use super::{ Arg, Arguments, Context, DeviceBuffer, HD, Module, NativeBatchWorkspace, PAGE, Result, Rng, combine, kv_q8, diff --git a/crates/cuda-driver/src/lib.rs b/crates/cuda-driver/src/lib.rs index 242c1989..f2f5364c 100644 --- a/crates/cuda-driver/src/lib.rs +++ b/crates/cuda-driver/src/lib.rs @@ -91,7 +91,6 @@ pub mod experimental; #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] pub mod experimental_gpu; #[cfg(all(test, feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_arch = "x86_64"))] -#[path = "experimental_gpu_smoke.rs"] mod experimental_gpu_smoke; pub mod kar_decode_levels; // Closed driver programs for native_flash_attn / s_gemv_legacy / device_poison: pins, entry signatures, argument slots @@ -100,12 +99,10 @@ pub mod closed_kernels; #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] pub mod closed_kernels_gpu; #[cfg(all(test, feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_arch = "x86_64"))] -#[path = "closed_kernels_gpu_smoke.rs"] mod closed_kernels_gpu_smoke; #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] pub mod kar_decode_levels_gpu; #[cfg(all(test, feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_arch = "x86_64"))] -#[path = "kar_decode_levels_gpu_smoke.rs"] mod kar_decode_levels_gpu_smoke; #[cfg(all( test, @@ -117,15 +114,12 @@ mod original_prefill_schedule_crosscheck; // Model-free stress of DMA out of a read-only file mapping that is page-locked in place, under working-set trimming // (Windows only). #[cfg(all(test, windows, feature = "cuda-driver", target_pointer_width = "64"))] -#[path = "mapped_file_dma_stress_gpu.rs"] mod mapped_file_dma_stress_gpu; #[cfg(all(test, any(target_os = "linux", target_os = "windows"), target_arch = "x86_64"))] -#[path = "moe_down_pack_gpu.rs"] mod moe_down_pack_gpu_tests; #[cfg(all(test, any(target_os = "linux", target_os = "windows"), target_arch = "x86_64"))] -#[path = "ple_value_full_gpu.rs"] mod ple_value_full_gpu_tests; #[cfg(test)] @@ -155,7 +149,6 @@ pub mod q6_layer_preview; any(target_os = "linux", target_os = "windows"), target_pointer_width = "64" ))] -#[path = "grouped_down_columns_gpu.rs"] mod grouped_down_columns_gpu; // Separately selected asynchronous owned-copy adapter; original APIs unchanged. @@ -166,7 +159,6 @@ mod async_owned_copy; mod refill_batch_copy; pub use refill_batch_copy::RefillBatchReport; #[cfg(all(test, feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] -#[path = "refill_batch_copy_gpu.rs"] mod refill_batch_copy_gpu; // Explicit experimental resident pipeline; original entry bodies remain unchanged. @@ -263,27 +255,18 @@ mod original_serve_assets; mod original_serve_access; mod bringup_trace_enabled; -#[allow(unused_imports)] use bringup_trace_enabled::combine; -#[allow(unused_imports)] use bringup_trace_enabled::valid_size; mod projection_grids_and_bounds; -#[allow(unused_imports)] use projection_grids_and_bounds::projection_ranges; -#[allow(unused_imports)] use projection_grids_and_bounds::projection_shape; -#[allow(unused_imports)] +#[cfg(test)] use projection_grids_and_bounds::q4_k_native_indices_fit; -#[allow(unused_imports)] use projection_grids_and_bounds::q5_k_shape; mod q6_k_shape; -#[allow(unused_imports)] use q6_k_shape::matvec_allocations; -#[allow(unused_imports)] use q6_k_shape::matvec_shape; -#[allow(unused_imports)] use q6_k_shape::q6_k_shape; -#[allow(unused_imports)] use q6_k_shape::vector_shape; mod context; mod context_gate_up_projection_admission; @@ -294,24 +277,14 @@ mod context_unload_close_destroy; mod device_buffer; mod prompt_sync_trace_types; -#[allow(unused_imports)] use prompt_sync_trace_types::FixedKernel; -#[allow(unused_imports)] use prompt_sync_trace_types::FixedOperation; -#[allow(unused_imports)] use prompt_sync_trace_types::FixedPairKernels; -#[allow(unused_imports)] pub(crate) use prompt_sync_trace_types::PoisonCell; -#[allow(unused_imports)] use prompt_sync_trace_types::ProjectionKernels; -#[allow(unused_imports)] use prompt_sync_trace_types::ProjectionShape; mod q5_kshape_types; -#[allow(unused_imports)] use q5_kshape_types::CurrentGuard; -#[allow(unused_imports)] use q5_kshape_types::MatvecShape; -#[allow(unused_imports)] use q5_kshape_types::Q5KShape; -#[allow(unused_imports)] use q5_kshape_types::Q6KShape; diff --git a/crates/cuda-driver/src/mapped_expert_bank.rs b/crates/cuda-driver/src/mapped_expert_bank.rs index 4f11f6e7..27308fd8 100644 --- a/crates/cuda-driver/src/mapped_expert_bank.rs +++ b/crates/cuda-driver/src/mapped_expert_bank.rs @@ -81,9 +81,7 @@ mod locked_tests { } mod context; -#[allow(unused_imports)] pub(crate) use context::aligned_copy_enabled; mod mapped_expert_bank_drop; mod mapped_expert_bank_operations; -#[allow(unused_imports)] use mapped_expert_bank_drop::range_covered; diff --git a/crates/cuda-driver/src/mapped_expert_bank/context.rs b/crates/cuda-driver/src/mapped_expert_bank/context.rs index dd6c6446..98d0ab8d 100644 --- a/crates/cuda-driver/src/mapped_expert_bank/context.rs +++ b/crates/cuda-driver/src/mapped_expert_bank/context.rs @@ -1,5 +1,5 @@ -//! Methods of `Context`: `mapped_expert_bank`, `check_bank_inputs`, `bank_ranges`, `bank_role` and 2 more. -//! Methods of `MappedExpertBank`: `opened`, `load_banks`. Functions: `aligned_copy_enabled`. +//! Opening a MappedExpertBank on a Context: checks the lease and member banks, plans page ranges and the budget +//! charge, loads the mapped driver ABI and registers each bank for a device alias; also the aligned-copy A/B switch. use super::{ BANKS, Context, Error, LayerRole, MappedExpertBank, RegisteredBank, ResidentExpertBankLease, diff --git a/crates/cuda-driver/src/mapped_expert_bank/mapped_expert_bank_drop.rs b/crates/cuda-driver/src/mapped_expert_bank/mapped_expert_bank_drop.rs index 9b1a3184..07ea14d2 100644 --- a/crates/cuda-driver/src/mapped_expert_bank/mapped_expert_bank_drop.rs +++ b/crates/cuda-driver/src/mapped_expert_bank/mapped_expert_bank_drop.rs @@ -1,5 +1,5 @@ -//! Methods of `PendingMappedExpertCopy`: `destination_bytes`, `new`, `observe`, `settle_observation` and 6 more. -//! Methods of `Context`: `mapped_expert_copy_scratch`. +//! Lifetime of an in-flight mapped expert copy: PendingMappedExpertCopy (event poll / wait, cleanup, leaking on +//! uncertain completion), its reusable scratch and completion owners, and the Drop of the bank that unregisters it. use super::{ Context, DeviceBuffer, Error, MappedExpertBank, MappedExpertCopyCompletion, MappedExpertCopyScratch, diff --git a/crates/cuda-driver/src/mapped_expert_bank/mapped_expert_bank_operations/mapped_expert_bank_close.rs b/crates/cuda-driver/src/mapped_expert_bank/mapped_expert_bank_operations/mapped_expert_bank_close.rs index 3f25ce40..f5de0836 100644 --- a/crates/cuda-driver/src/mapped_expert_bank/mapped_expert_bank_operations/mapped_expert_bank_close.rs +++ b/crates/cuda-driver/src/mapped_expert_bank/mapped_expert_bank_operations/mapped_expert_bank_close.rs @@ -1,5 +1,5 @@ -//! Methods of `MappedExpertBank`: `retain_uncertain`, `close`. -//! Split out of `mapped_expert_bank_methods` to keep its files under the line limit. +//! Closing a MappedExpertBank: close() and retain_uncertain(), which poisons the context and leaks the bank's +//! ABI and registrations when completion is uncertain, since the device may still read them. use super::{MappedExpertBank, Result}; diff --git a/crates/cuda-driver/src/mapped_expert_bank/mapped_expert_bank_operations/mapped_expert_bank_pcie_and_triplets.rs b/crates/cuda-driver/src/mapped_expert_bank/mapped_expert_bank_operations/mapped_expert_bank_pcie_and_triplets.rs index 5ff6418e..b202d29e 100644 --- a/crates/cuda-driver/src/mapped_expert_bank/mapped_expert_bank_operations/mapped_expert_bank_pcie_and_triplets.rs +++ b/crates/cuda-driver/src/mapped_expert_bank/mapped_expert_bank_operations/mapped_expert_bank_pcie_and_triplets.rs @@ -1,5 +1,5 @@ -//! Methods of `MappedExpertBank`: `page_locked`, `locked_experts`, `resident_bytes`, `pcie_alias` and 13 more. -//! Functions: `bank_index`, `expert_role_offset`. +//! Device-side use of a MappedExpertBank: PCIe alias lookup, eligibility checks, and copy_triplet, which launches the +//! mapped-copy kernel for one expert's three tensors into device buffers and tracks it as a pending copy. use super::{ DeviceBuffer, Error, LayerRole, MappedExpertBank, MappedExpertCopyScratch, PendingMappedExpertCopy, Rc, diff --git a/crates/cuda-driver/src/mapped_expert_bank/mapped_expert_bank_operations/mapped_expert_bank_pieces_and_pinning.rs b/crates/cuda-driver/src/mapped_expert_bank/mapped_expert_bank_operations/mapped_expert_bank_pieces_and_pinning.rs index e59d5b1b..a19579dc 100644 --- a/crates/cuda-driver/src/mapped_expert_bank/mapped_expert_bank_operations/mapped_expert_bank_pieces_and_pinning.rs +++ b/crates/cuda-driver/src/mapped_expert_bank/mapped_expert_bank_operations/mapped_expert_bank_pieces_and_pinning.rs @@ -1,5 +1,5 @@ -//! Methods of `MappedExpertBank`: `cache_context_matches`, `cache_source`, `cache_source_aligned`, `retained_span_ha... -//! Split out of `mapped_expert_bank_methods` to keep its files under the line limit. +//! Host-side views of a MappedExpertBank: cache sources and page-aligned pieces of an expert, and pin_resident, +//! which page-locks the ranked hot experts within a byte budget (round, merge, register) and unwinds on failure. use super::{ Context, Error, LayerRole, MappedExpertBank, PAGE, RegisteredBank, ResidentExpertBankSpan, Result, TensorRole, api, diff --git a/crates/cuda-driver/src/mmq.rs b/crates/cuda-driver/src/mmq.rs index d4a6adbd..cb1c063e 100644 --- a/crates/cuda-driver/src/mmq.rs +++ b/crates/cuda-driver/src/mmq.rs @@ -5,7 +5,6 @@ use super::{ }; #[cfg(test)] use super::{DenseFormat, Device, Driver, qwen_ffi}; -#[path = "mmq_original_weights.rs"] mod original_weights; use std::ffi::CStr; @@ -100,10 +99,8 @@ pub struct MmqWeights<'ctx> { } #[cfg(all(test, target_os = "linux", target_arch = "x86_64"))] -#[path = "mmq_numeric_gpu.rs"] mod mmq_numeric_gpu_tests; -#[path = "mmq_resident.rs"] pub(crate) mod resident; #[cfg(all(test, feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_arch = "x86_64"))] @@ -294,22 +291,16 @@ mod triplet_upload_installed { } #[cfg(all(test, feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_arch = "x86_64"))] -#[path = "owned_gate_up_upload_gpu.rs"] mod owned_gate_up_upload_gpu; mod asset; mod tile; -#[allow(unused_imports)] pub(crate) use asset::asset; -#[allow(unused_imports)] use asset::bytes; -#[allow(unused_imports)] use asset::finite_f32; -#[allow(unused_imports)] use asset::original_formats_asset; mod context; mod release_triplet; -#[allow(unused_imports)] use release_triplet::release_triplet; mod experiment_load; mod mmq_experiment; diff --git a/crates/cuda-driver/src/mmq/asset.rs b/crates/cuda-driver/src/mmq/asset.rs index 30763b5d..601fe449 100644 --- a/crates/cuda-driver/src/mmq/asset.rs +++ b/crates/cuda-driver/src/mmq/asset.rs @@ -1,5 +1,5 @@ -//! Methods of `Context`: `mmq_experiment`. -//! Functions: `artifacts_valid`, `asset`, `original_formats_asset`, `bytes` and 1 more. +//! Sealed PTX assets of the MMQ kernels: each artifact is checked once for pinned length, NUL-terminated ASCII and +//! SHA-256 before use (the Original-formats pair against its own pin), plus small buffer helpers and mmq_experiment(). use super::{Context, Error, MmqExperiment, ORIGINAL_FORMATS_FIXUP_PIN, ORIGINAL_FORMATS_MUL_PIN, Result}; diff --git a/crates/cuda-driver/src/mmq/context.rs b/crates/cuda-driver/src/mmq/context.rs index 5ea75417..059ff4f7 100644 --- a/crates/cuda-driver/src/mmq/context.rs +++ b/crates/cuda-driver/src/mmq/context.rs @@ -1,5 +1,5 @@ -//! Methods of `Context`: `mmq_weight_triplet`, `allocate_triplet`, `publish_triplet`, `admit_formats` and 12 more. -//! Functions: `check_weight_blocks`, `buffer_handles`, `check_padded_targets`, `owned_gate_up_layout`. +//! MMQ weight upload on a Context: format and charge admission, then repacking host or device raw weights into +//! padded MMQ layouts (single, gate/up/down triplet, owned gate-up) with checks that block counts and targets fit. use super::{ Context, DeviceBuffer, Error, Layout, MmqFormat, MmqWeights, ProjectionKind, ProjectionSpec, Result, RoutedFormat, diff --git a/crates/cuda-driver/src/mmq/mmq_experiment.rs b/crates/cuda-driver/src/mmq/mmq_experiment.rs index 92fb02f2..50be4ef4 100644 --- a/crates/cuda-driver/src/mmq/mmq_experiment.rs +++ b/crates/cuda-driver/src/mmq/mmq_experiment.rs @@ -1,5 +1,5 @@ -//! Methods of `MmqExperiment`: `new`, `enable_original_formats`, `function`, `weights` and 16 more. -//! Defines `ObservedRun`. +//! The MMQ experiment owner: loads the MMQ kernel modules and runs one observed projection (quantize, MMA, fixup) +//! with full finite readbacks, so the numeric gate tests can compare each stage with the recorded reference. use super::{ Context, DeviceBuffer, Error, Layout, MmqExperiment, MmqFormat, MmqObservation, MmqProfile, MmqRequest, MmqWeights, diff --git a/crates/cuda-driver/src/mmq/mmq_experiment_drop.rs b/crates/cuda-driver/src/mmq/mmq_experiment_drop.rs index 867908d9..7e3c31f5 100644 --- a/crates/cuda-driver/src/mmq/mmq_experiment_drop.rs +++ b/crates/cuda-driver/src/mmq/mmq_experiment_drop.rs @@ -1,5 +1,5 @@ -//! Methods of `MmqWeights`: `allocated_bytes`, `native_buffer`, `native_layout`, `native_spec` and 10 more. -//! Implements `Drop for MmqExperiment`, `Drop for MmqWeights`. +//! Native-path entry points of MmqWeights (Q8_1 quantize, gate/up and down column projections) and the close/Drop +//! implementations of MmqExperiment and MmqWeights, which release the loaded modules and device weight buffers. use super::{ DeviceBuffer, DownColumns, Error, Layout, MmqExperiment, MmqFormat, MmqWeights, NativeWeights, ProjectionKind, diff --git a/crates/cuda-driver/src/mmq_numeric_gpu.rs b/crates/cuda-driver/src/mmq/mmq_numeric_gpu_tests.rs similarity index 94% rename from crates/cuda-driver/src/mmq_numeric_gpu.rs rename to crates/cuda-driver/src/mmq/mmq_numeric_gpu_tests.rs index b6e7d8f2..3946533a 100644 --- a/crates/cuda-driver/src/mmq_numeric_gpu.rs +++ b/crates/cuda-driver/src/mmq/mmq_numeric_gpu_tests.rs @@ -169,23 +169,10 @@ fn original_first_mmq_adaptive_and_distinct_fixed_profiles_exact() { ); } -#[path = "mmq_numeric_gpu/digest.rs"] mod digest; -#[allow(unused_imports)] use digest::compare; -#[allow(unused_imports)] -use digest::digest; -#[allow(unused_imports)] use digest::field; -#[allow(unused_imports)] use digest::finite; -#[allow(unused_imports)] -use digest::hex; -#[allow(unused_imports)] use digest::integer; -#[allow(unused_imports)] -use digest::read_regular; -#[path = "mmq_numeric_gpu/format_cases.rs"] mod format_cases; -#[allow(unused_imports)] use format_cases::cases; diff --git a/crates/cuda-driver/src/mmq_numeric_gpu/digest.rs b/crates/cuda-driver/src/mmq/mmq_numeric_gpu_tests/digest.rs similarity index 96% rename from crates/cuda-driver/src/mmq_numeric_gpu/digest.rs rename to crates/cuda-driver/src/mmq/mmq_numeric_gpu_tests/digest.rs index 380736e0..a2df0bbc 100644 --- a/crates/cuda-driver/src/mmq_numeric_gpu/digest.rs +++ b/crates/cuda-driver/src/mmq/mmq_numeric_gpu_tests/digest.rs @@ -1,5 +1,5 @@ -//! Methods of `Receipt`: `load`, `read`. Functions: `digest`, `hex`, `read_regular`, `parse_manifest` and 7 more. -//! Defines `Manifest`. +//! Receipt loader of the MMQ numeric GPU tests: reads the pinned fixture manifest, checks its headers and file list +//! and sha256 pins, and offers the JSON field readers and finite/compare helpers the cases use. use super::{ BTreeMap, CASE_FILES, Component, MetadataExt, OpenOptions, OpenOptionsExt, Path, PathBuf, Pin, Read, Receipt, diff --git a/crates/cuda-driver/src/mmq_numeric_gpu/format_cases.rs b/crates/cuda-driver/src/mmq/mmq_numeric_gpu_tests/format_cases.rs similarity index 94% rename from crates/cuda-driver/src/mmq_numeric_gpu/format_cases.rs rename to crates/cuda-driver/src/mmq/mmq_numeric_gpu_tests/format_cases.rs index 483ec40f..027a88f2 100644 --- a/crates/cuda-driver/src/mmq_numeric_gpu/format_cases.rs +++ b/crates/cuda-driver/src/mmq/mmq_numeric_gpu_tests/format_cases.rs @@ -1,5 +1,5 @@ -//! Functions: `cases`, `load_case`, `check_metadata`, `check_geometry`. Defines `Shape`. -//! Split out of `mmq_numeric_gpu_tests` to keep its files under the line limit. +//! Per-format test cases of the MMQ numeric GPU tests: loads each case from the receipt and checks that its recorded +//! geometry, grid and provenance flags match what the closed fixture expects before any kernel runs. use super::{Case, Receipt, field, finite, integer}; diff --git a/crates/cuda-driver/src/mmq_original_weights.rs b/crates/cuda-driver/src/mmq/original_weights.rs similarity index 100% rename from crates/cuda-driver/src/mmq_original_weights.rs rename to crates/cuda-driver/src/mmq/original_weights.rs diff --git a/crates/cuda-driver/src/owned_gate_up_upload_gpu.rs b/crates/cuda-driver/src/mmq/owned_gate_up_upload_gpu.rs similarity index 100% rename from crates/cuda-driver/src/owned_gate_up_upload_gpu.rs rename to crates/cuda-driver/src/mmq/owned_gate_up_upload_gpu.rs diff --git a/crates/cuda-driver/src/mmq/release_triplet.rs b/crates/cuda-driver/src/mmq/release_triplet.rs index 2d873c3c..3f9bef5f 100644 --- a/crates/cuda-driver/src/mmq/release_triplet.rs +++ b/crates/cuda-driver/src/mmq/release_triplet.rs @@ -1,5 +1,5 @@ -//! Functions: `release_triplet`. -//! Split out of `mmq` to keep its files under the line limit. +//! Releases the three device buffers of an MMQ projection in reverse order, keeps the first error and +//! poisons the context when any release fails; shared by the experiment and workspace cleanup paths. use super::{Context, DeviceBuffer, Result}; diff --git a/crates/cuda-driver/src/mmq_resident.rs b/crates/cuda-driver/src/mmq/resident.rs similarity index 90% rename from crates/cuda-driver/src/mmq_resident.rs rename to crates/cuda-driver/src/mmq/resident.rs index c66b6d4f..cdf8eeb5 100644 --- a/crates/cuda-driver/src/mmq_resident.rs +++ b/crates/cuda-driver/src/mmq/resident.rs @@ -6,13 +6,9 @@ use super::{ }; #[cfg(test)] use super::{Device, DownColumns, Driver, MmqRequest, finite_f32, qwen_ffi}; -#[path = "mmq_native_activation.rs"] pub(crate) mod native_activation; -#[path = "mmq_native_down.rs"] mod native_down; -#[path = "iq3_native_integer_mma.rs"] pub(crate) mod native_integer; -#[path = "mmq_original_group.rs"] pub(crate) mod original_group; const INPUT: usize = 0; const CHUNK: usize = 1; @@ -76,20 +72,14 @@ pub struct FiniteMmqOutput<'lease, 'ctx> { } #[cfg(all(test, target_os = "linux", target_arch = "x86_64"))] -#[path = "mmq_resident_gpu.rs"] mod mmq_resident_gpu_tests; #[cfg(all(test, target_os = "linux", target_arch = "x86_64"))] -#[path = "mmq_native_resident_gpu.rs"] mod mmq_native_resident_gpu_tests; -#[path = "mmq_resident/asset.rs"] mod asset; -#[allow(unused_imports)] pub(crate) use asset::asset; -#[allow(unused_imports)] use asset::commands; -#[path = "mmq_resident/mmq_workspace_drop.rs"] mod mmq_workspace_drop; /// The workspace slots of one projection: the packed activation and the output. #[derive(Clone, Copy)] @@ -97,5 +87,4 @@ struct ProjectionSlots { packed: usize, out: usize, } -#[path = "mmq_resident/mmq_workspace.rs"] mod mmq_workspace; diff --git a/crates/cuda-driver/src/mmq_resident/asset.rs b/crates/cuda-driver/src/mmq/resident/asset.rs similarity index 94% rename from crates/cuda-driver/src/mmq_resident/asset.rs rename to crates/cuda-driver/src/mmq/resident/asset.rs index 48b2fac1..f78d5d90 100644 --- a/crates/cuda-driver/src/mmq_resident/asset.rs +++ b/crates/cuda-driver/src/mmq/resident/asset.rs @@ -1,11 +1,11 @@ -//! Methods of `QueuedCommand`: `launch`, `launch_projection`. -//! Methods of `Context`: `mmq_workspace`, `native_mmq_workspace`, `native_integer_iq3_mmq_workspace`, `native_intege... +//! The sealed PTX helper artifact of the resident MMQ path (length and sha256 checked), the queued launch commands +//! built from it, and the Context constructors of the MMQ workspace variants (native and original formats). use super::{Context, Error, MmqWorkspace, QueuedCommand, Result, combine, original_formats_asset}; // PTX is supplied only by ROOT's pinned GPU-hidden compiler. No placeholder artifact. pub(crate) fn asset() -> Result<&'static [u8]> { - let b = include_bytes!("../mmq_resident_helpers.ptx"); + let b = include_bytes!("../../mmq_resident_helpers.ptx"); if b.last() != Some(&0) || !b[..b.len() - 1].is_ascii() || b[..b.len() - 1].contains(&0) { return Err(Error::InvalidDriverValue("MMQ resident artifact")); } diff --git a/crates/cuda-driver/src/mmq_native_resident_gpu.rs b/crates/cuda-driver/src/mmq/resident/mmq_native_resident_gpu_tests.rs similarity index 96% rename from crates/cuda-driver/src/mmq_native_resident_gpu.rs rename to crates/cuda-driver/src/mmq/resident/mmq_native_resident_gpu_tests.rs index d9e4337d..0d4622b6 100644 --- a/crates/cuda-driver/src/mmq_native_resident_gpu.rs +++ b/crates/cuda-driver/src/mmq/resident/mmq_native_resident_gpu_tests.rs @@ -303,33 +303,16 @@ fn actual_expert215_native_resident_gu_and_same_source_down_diagnostic() { ); } -#[path = "mmq_native_resident_gpu/digest.rs"] mod digest; -#[allow(unused_imports)] use digest::associate; -#[allow(unused_imports)] use digest::digest; -#[allow(unused_imports)] use digest::download; -#[allow(unused_imports)] use digest::fixture; -#[allow(unused_imports)] use digest::floats; -#[allow(unused_imports)] -use digest::half_bits; -#[allow(unused_imports)] use digest::measure; -#[allow(unused_imports)] -use digest::ordered; -#[allow(unused_imports)] use digest::prefix; -#[allow(unused_imports)] use digest::read; -#[allow(unused_imports)] use digest::upload; -#[allow(unused_imports)] use digest::write_file; -#[path = "mmq_native_resident_gpu/native_hidden_q8.rs"] mod native_hidden_q8; -#[allow(unused_imports)] use native_hidden_q8::native_hidden_q8; diff --git a/crates/cuda-driver/src/mmq_native_resident_gpu/digest.rs b/crates/cuda-driver/src/mmq/resident/mmq_native_resident_gpu_tests/digest.rs similarity index 97% rename from crates/cuda-driver/src/mmq_native_resident_gpu/digest.rs rename to crates/cuda-driver/src/mmq/resident/mmq_native_resident_gpu_tests/digest.rs index 43d68c51..29f47269 100644 --- a/crates/cuda-driver/src/mmq_native_resident_gpu/digest.rs +++ b/crates/cuda-driver/src/mmq/resident/mmq_native_resident_gpu_tests/digest.rs @@ -1,5 +1,5 @@ -//! Functions: `digest`, `read`, `parse_pins`, `read_pinned` and 10 more. -//! Split out of `mmq_native_resident_gpu_tests` to keep its files under the line limit. +//! Fixture and measurement helpers of the native resident MMQ GPU tests: reads the pinned fixture files by +//! manifest size and sha256, moves buffers to and from the device, and reports error metrics between two outputs. use super::{ BTreeMap, Context, DeviceBuffer, MetadataExt, OpenOptions, OpenOptionsExt, Path, PathBuf, Read, Write, finite_f32, diff --git a/crates/cuda-driver/src/mmq_native_resident_gpu/native_hidden_q8.rs b/crates/cuda-driver/src/mmq/resident/mmq_native_resident_gpu_tests/native_hidden_q8.rs similarity index 84% rename from crates/cuda-driver/src/mmq_native_resident_gpu/native_hidden_q8.rs rename to crates/cuda-driver/src/mmq/resident/mmq_native_resident_gpu_tests/native_hidden_q8.rs index aaa08cb5..be2f2088 100644 --- a/crates/cuda-driver/src/mmq_native_resident_gpu/native_hidden_q8.rs +++ b/crates/cuda-driver/src/mmq/resident/mmq_native_resident_gpu_tests/native_hidden_q8.rs @@ -1,5 +1,5 @@ -//! Implements `Drop for Alias`. Functions: `native_hidden_q8`. -//! Split out of `mmq_native_resident_gpu_tests` to keep its files under the line limit. +//! Independent reference for the native resident tests: runs the original CommonQuantize kernel on a real native +//! hidden row and returns its Q8 bytes. Also owns the Drop of the test Alias buffer view. use super::{Alias, CHUNK, Context, DeviceBuffer, FixedOperation, download, ffi}; diff --git a/crates/cuda-driver/src/mmq_resident_gpu.rs b/crates/cuda-driver/src/mmq/resident/mmq_resident_gpu_tests.rs similarity index 83% rename from crates/cuda-driver/src/mmq_resident_gpu.rs rename to crates/cuda-driver/src/mmq/resident/mmq_resident_gpu_tests.rs index 78a86425..47413b31 100644 --- a/crates/cuda-driver/src/mmq_resident_gpu.rs +++ b/crates/cuda-driver/src/mmq/resident/mmq_resident_gpu_tests.rs @@ -95,57 +95,26 @@ fn queued_finite_chain_and_bulk_down_packets_exact() { ); } -#[path = "mmq_resident_gpu/owner_proof.rs"] mod owner_proof; -#[allow(unused_imports)] use owner_proof::*; -#[path = "mmq_resident_gpu/queued_proof.rs"] mod queued_proof; -#[allow(unused_imports)] use queued_proof::*; -#[path = "mmq_resident_gpu/digest.rs"] mod digest; -#[allow(unused_imports)] use digest::compare; -#[allow(unused_imports)] -use digest::digest; -#[allow(unused_imports)] use digest::download; -#[allow(unused_imports)] use digest::encoded; -#[allow(unused_imports)] -use digest::field; -#[allow(unused_imports)] use digest::file; -#[allow(unused_imports)] use digest::finite; -#[allow(unused_imports)] use digest::floats; -#[allow(unused_imports)] -use digest::hex; -#[allow(unused_imports)] use digest::integer; -#[allow(unused_imports)] use digest::raw_format; -#[allow(unused_imports)] -use digest::read_regular; -#[allow(unused_imports)] use digest::same; -#[allow(unused_imports)] use digest::upload; -#[path = "mmq_resident_gpu/native_owner.rs"] mod native_owner; -#[allow(unused_imports)] use native_owner::direct; -#[allow(unused_imports)] use native_owner::gather; -#[allow(unused_imports)] use native_owner::native_owner; -#[path = "mmq_resident_gpu/resident_chain.rs"] mod resident_chain; -#[allow(unused_imports)] use resident_chain::chain; -#[allow(unused_imports)] use resident_chain::witness; -#[path = "mmq_resident_gpu/live_packet_alias_drop.rs"] mod live_packet_alias_drop; diff --git a/crates/cuda-driver/src/mmq_resident_gpu/digest.rs b/crates/cuda-driver/src/mmq/resident/mmq_resident_gpu_tests/digest.rs similarity index 96% rename from crates/cuda-driver/src/mmq_resident_gpu/digest.rs rename to crates/cuda-driver/src/mmq/resident/mmq_resident_gpu_tests/digest.rs index 8d80eb19..9b1e6392 100644 --- a/crates/cuda-driver/src/mmq_resident_gpu/digest.rs +++ b/crates/cuda-driver/src/mmq/resident/mmq_resident_gpu_tests/digest.rs @@ -1,5 +1,5 @@ -//! Methods of `Receipt`: `load`, `check_pinned_contents`, `read`. -//! Functions: `digest`, `hex`, `read_regular`, `parse_manifest` and 14 more. +//! Receipt loader of the resident MMQ GPU tests: reads the pinned fixture manifest, checks its headers, file list and +//! sha256 pins (incl. pinned contents), and offers the digest, JSON field and finite/compare helpers the cases use. use super::{ BTreeMap, CASE_FILES, Component, Context, DeviceBuffer, MetadataExt, MmqFormat, OpenOptions, OpenOptionsExt, Path, diff --git a/crates/cuda-driver/src/mmq_resident_gpu/live_packet_alias_drop.rs b/crates/cuda-driver/src/mmq/resident/mmq_resident_gpu_tests/live_packet_alias_drop.rs similarity index 54% rename from crates/cuda-driver/src/mmq_resident_gpu/live_packet_alias_drop.rs rename to crates/cuda-driver/src/mmq/resident/mmq_resident_gpu_tests/live_packet_alias_drop.rs index 4c27b7a1..d675f30c 100644 --- a/crates/cuda-driver/src/mmq_resident_gpu/live_packet_alias_drop.rs +++ b/crates/cuda-driver/src/mmq/resident/mmq_resident_gpu_tests/live_packet_alias_drop.rs @@ -1,5 +1,4 @@ -//! Implements `Drop for LivePacketAlias`. -//! Split out of `mmq_resident_gpu_tests` to keep its files under the line limit. +//! Drop of LivePacketAlias: puts back the original buffer handle that the alias test view had swapped out. use super::LivePacketAlias; diff --git a/crates/cuda-driver/src/mmq_resident_gpu/native_owner.rs b/crates/cuda-driver/src/mmq/resident/mmq_resident_gpu_tests/native_owner.rs similarity index 96% rename from crates/cuda-driver/src/mmq_resident_gpu/native_owner.rs rename to crates/cuda-driver/src/mmq/resident/mmq_resident_gpu_tests/native_owner.rs index 95a392ce..062e0965 100644 --- a/crates/cuda-driver/src/mmq_resident_gpu/native_owner.rs +++ b/crates/cuda-driver/src/mmq/resident/mmq_resident_gpu_tests/native_owner.rs @@ -1,5 +1,5 @@ -//! Functions: `native_owner`, `native_gate_up_owner`, `native_down_owner`, `direct` and 2 more. -//! Split out of `mmq_resident_gpu_tests` to keep its files under the line limit. +//! Owner-equivalence checks of the resident MMQ tests: the native dual weights (gate/up prepared and grouped, +//! down columns) must produce the same bytes as the raw routed projections; plus the direct and gather checks. use super::{ CHUNK, Context, DOWN, DeviceBuffer, DownColumns, Error, GATE, GROUP, INPUT, MmqWeights, MmqWorkspace, Receipt, diff --git a/crates/cuda-driver/src/mmq_resident_gpu/owner_proof.rs b/crates/cuda-driver/src/mmq/resident/mmq_resident_gpu_tests/owner_proof.rs similarity index 100% rename from crates/cuda-driver/src/mmq_resident_gpu/owner_proof.rs rename to crates/cuda-driver/src/mmq/resident/mmq_resident_gpu_tests/owner_proof.rs diff --git a/crates/cuda-driver/src/mmq_resident_gpu/queued_proof.rs b/crates/cuda-driver/src/mmq/resident/mmq_resident_gpu_tests/queued_proof.rs similarity index 100% rename from crates/cuda-driver/src/mmq_resident_gpu/queued_proof.rs rename to crates/cuda-driver/src/mmq/resident/mmq_resident_gpu_tests/queued_proof.rs diff --git a/crates/cuda-driver/src/mmq_resident_gpu/resident_chain.rs b/crates/cuda-driver/src/mmq/resident/mmq_resident_gpu_tests/resident_chain.rs similarity index 97% rename from crates/cuda-driver/src/mmq_resident_gpu/resident_chain.rs rename to crates/cuda-driver/src/mmq/resident/mmq_resident_gpu_tests/resident_chain.rs index 0f2abf10..7a7ad4ab 100644 --- a/crates/cuda-driver/src/mmq_resident_gpu/resident_chain.rs +++ b/crates/cuda-driver/src/mmq/resident/mmq_resident_gpu_tests/resident_chain.rs @@ -1,5 +1,5 @@ -//! Methods of `LivePacketAlias`: `new`, `buffer`. -//! Functions: `chain_baseline`, `chain`, `chain_hidden_checks`, `chain_slot_checks` and 8 more. +//! The resident MMQ chain test: runs gate/up, SwiGLU and down through the workspace against the original-first +//! nonresident baseline, checks hidden rows, slot output, short and foreign packets, and the witness probes. use super::{ Context, DOWN, DeviceBuffer, Error, FiniteMmqOutput, GATE, GROUP, HIDDEN, LivePacketAlias, MmqHidden, MmqProfile, diff --git a/crates/cuda-driver/src/mmq_resident/mmq_workspace.rs b/crates/cuda-driver/src/mmq/resident/mmq_workspace.rs similarity index 54% rename from crates/cuda-driver/src/mmq_resident/mmq_workspace.rs rename to crates/cuda-driver/src/mmq/resident/mmq_workspace.rs index 5e9a2eaa..c2cd184b 100644 --- a/crates/cuda-driver/src/mmq_resident/mmq_workspace.rs +++ b/crates/cuda-driver/src/mmq/resident/mmq_workspace.rs @@ -1,5 +1,5 @@ -//! Groups the submodules `mmq_workspace_bring_up`, `mmq_workspace_gate_up_chunk_close`, `projection_plan`. -//! Split out of `resident` to keep its files under the line limit. +//! Module root of the resident MmqWorkspace: shared imports for its bring-up, gate/up chunk and projection-plan +//! files, each of which owns one phase of the workspace lifecycle. use super::{ CHUNK, Context, DOWN, DeviceBuffer, Error, GATE, GROUP, HIDDEN, INPUT, Layout, MmqChunkActivation, MmqExperiment, @@ -7,9 +7,6 @@ use super::{ bytes, combine, commands, ffi, native_activation, native_integer, }; -#[path = "mmq_workspace/mmq_workspace_bring_up.rs"] mod mmq_workspace_bring_up; -#[path = "mmq_workspace/mmq_workspace_gate_up_chunk_close.rs"] mod mmq_workspace_gate_up_chunk_close; -#[path = "mmq_workspace/projection_plan.rs"] mod projection_plan; diff --git a/crates/cuda-driver/src/mmq_resident/mmq_workspace/mmq_workspace_bring_up.rs b/crates/cuda-driver/src/mmq/resident/mmq_workspace/mmq_workspace_bring_up.rs similarity index 97% rename from crates/cuda-driver/src/mmq_resident/mmq_workspace/mmq_workspace_bring_up.rs rename to crates/cuda-driver/src/mmq/resident/mmq_workspace/mmq_workspace_bring_up.rs index 006b1bc1..aef7515d 100644 --- a/crates/cuda-driver/src/mmq_resident/mmq_workspace/mmq_workspace_bring_up.rs +++ b/crates/cuda-driver/src/mmq/resident/mmq_workspace/mmq_workspace_bring_up.rs @@ -1,5 +1,5 @@ -//! Methods of `MmqWorkspace`: `new`, `check_integer_policy`, `charge`, `bring_up` and 13 more. -//! Split out of `mmq_workspace` to keep its files under the line limit. +//! Construction and bring-up of the resident MmqWorkspace: charges its device budget up front, allocates the +//! eleven fixed buffers, loads the helper kernels and integer/native operators, and runs queued launches. use super::{ Context, DeviceBuffer, Error, MmqWorkspace, QueuedCommand, Result, bytes, combine, ffi, native_activation, diff --git a/crates/cuda-driver/src/mmq_resident/mmq_workspace/mmq_workspace_gate_up_chunk_close.rs b/crates/cuda-driver/src/mmq/resident/mmq_workspace/mmq_workspace_gate_up_chunk_close.rs similarity index 94% rename from crates/cuda-driver/src/mmq_resident/mmq_workspace/mmq_workspace_gate_up_chunk_close.rs rename to crates/cuda-driver/src/mmq/resident/mmq_workspace/mmq_workspace_gate_up_chunk_close.rs index 247f5fc8..d1e39e7e 100644 --- a/crates/cuda-driver/src/mmq_resident/mmq_workspace/mmq_workspace_gate_up_chunk_close.rs +++ b/crates/cuda-driver/src/mmq/resident/mmq_workspace/mmq_workspace_gate_up_chunk_close.rs @@ -1,5 +1,5 @@ -//! Methods of `MmqWorkspace`: `prepare_original_gate_up_chunk`, `prepare_gate_up_chunk_with_operator`, `upload_and_q... -//! Split out of `mmq_workspace` to keep its files under the line limit. +//! Original-prompt gate/up chunk activation of the resident MmqWorkspace (affine D4 quantize, independent of the +//! native integer operators), the upload-and-quantize step it uses, and the workspace close. use super::{CHUNK, Error, INPUT, Layout, MmqChunkActivation, MmqFormat, MmqWorkspace, Result, bytes, combine}; diff --git a/crates/cuda-driver/src/mmq_resident/mmq_workspace/projection_plan.rs b/crates/cuda-driver/src/mmq/resident/mmq_workspace/projection_plan.rs similarity index 98% rename from crates/cuda-driver/src/mmq_resident/mmq_workspace/projection_plan.rs rename to crates/cuda-driver/src/mmq/resident/mmq_workspace/projection_plan.rs index c28a5808..a31fb0d7 100644 --- a/crates/cuda-driver/src/mmq_resident/mmq_workspace/projection_plan.rs +++ b/crates/cuda-driver/src/mmq/resident/mmq_workspace/projection_plan.rs @@ -1,5 +1,5 @@ -//! Methods of `MmqWorkspace`: `finish_finite`, `finite`, `quantize`, `quantize_with_operator` and 15 more. -//! Functions: `finite_extent`, `finite_verdict`, `finite_output_name`. Defines `StreamKLaunch`, `ProjectPlan`. +//! Projection planning of the resident MmqWorkspace: finite-output proofs, activation quantize, plan and alias +//! validation, the native integer and stream-k projection launches, and the gate/up chunk preparation. use super::{ DOWN, Error, GATE, GROUP, HIDDEN, Layout, MmqChunkActivation, MmqExperiment, MmqFormat, MmqProfile, MmqWeights, diff --git a/crates/cuda-driver/src/mmq_resident/mmq_workspace_drop.rs b/crates/cuda-driver/src/mmq/resident/mmq_workspace_drop.rs similarity index 97% rename from crates/cuda-driver/src/mmq_resident/mmq_workspace_drop.rs rename to crates/cuda-driver/src/mmq/resident/mmq_workspace_drop.rs index 87dfdd5f..74050151 100644 --- a/crates/cuda-driver/src/mmq_resident/mmq_workspace_drop.rs +++ b/crates/cuda-driver/src/mmq/resident/mmq_workspace_drop.rs @@ -1,5 +1,5 @@ -//! Methods of `MmqChunkActivation`: `gather_gate_up`, `gather_group`, `upload_gather_ids`, `gather_handles`. -//! Methods of `MmqGroupActivation`: `admits`, `gate_up`, `project_swiglu`, `swiglu_hidden` and 1 more. +//! Grouped activation flow of the resident MmqWorkspace: gather of expert rows, gate/up with SwiGLU, down +//! projection and bounded copies of finite Down columns into ten-slot packets. Also the Drop of the workspace. use super::{ CHUNK, DOWN, DOWN_Q8, DeviceBuffer, DownCopyHandles, Error, FiniteMmqOutput, FixedOperation, GATE, GROUP, HIDDEN, diff --git a/crates/cuda-driver/src/mmq_native_activation.rs b/crates/cuda-driver/src/mmq/resident/native_activation.rs similarity index 98% rename from crates/cuda-driver/src/mmq_native_activation.rs rename to crates/cuda-driver/src/mmq/resident/native_activation.rs index 8d4fbe19..b00e6a10 100644 --- a/crates/cuda-driver/src/mmq_native_activation.rs +++ b/crates/cuda-driver/src/mmq/resident/native_activation.rs @@ -2,7 +2,7 @@ use super::{Context, DeviceBuffer, Error, FixedOperation, Layout, QueuedCommand, Result, combine, ffi}; pub(super) const CHARGE: usize = 184320; pub(crate) fn asset() -> Result<&'static [u8]> { - let b = include_bytes!("mmq_native_resident_d4.ptx"); + let b = include_bytes!("../../mmq_native_resident_d4.ptx"); if b.len() != 5200 || b.last() != Some(&0) || !b[..b.len() - 1].is_ascii() diff --git a/crates/cuda-driver/src/mmq_native_down.rs b/crates/cuda-driver/src/mmq/resident/native_down.rs similarity index 100% rename from crates/cuda-driver/src/mmq_native_down.rs rename to crates/cuda-driver/src/mmq/resident/native_down.rs diff --git a/crates/cuda-driver/src/iq3_native_integer_mma.rs b/crates/cuda-driver/src/mmq/resident/native_integer.rs similarity index 98% rename from crates/cuda-driver/src/iq3_native_integer_mma.rs rename to crates/cuda-driver/src/mmq/resident/native_integer.rs index 1469f8f2..521c6115 100644 --- a/crates/cuda-driver/src/iq3_native_integer_mma.rs +++ b/crates/cuda-driver/src/mmq/resident/native_integer.rs @@ -4,7 +4,7 @@ use super::{Context, DeviceBuffer, Error, Layout, QueuedCommand, Result, combine pub(super) const CHARGE: usize = 13_107_200; /// Actual root GPU-hidden NVCC 12.8.93 sm_120 asset; explicit experimental policy. pub(crate) fn asset() -> Result<&'static [u8]> { - let b = include_bytes!("iq3_native_integer_mma.ptx"); + let b = include_bytes!("../../iq3_native_integer_mma.ptx"); if b.len() != 17928 || b.last() != Some(&0) || !b[..b.len() - 1].is_ascii() || b[..b.len() - 1].contains(&0) { return Err(Error::InvalidDriverValue("IQ3 native integer MMA PTX encoding")); } diff --git a/crates/cuda-driver/src/mmq_original_group.rs b/crates/cuda-driver/src/mmq/resident/original_group.rs similarity index 89% rename from crates/cuda-driver/src/mmq_original_group.rs rename to crates/cuda-driver/src/mmq/resident/original_group.rs index 4925d030..aab0a65e 100644 --- a/crates/cuda-driver/src/mmq_original_group.rs +++ b/crates/cuda-driver/src/mmq/resident/original_group.rs @@ -125,44 +125,27 @@ pub struct OriginalMmqOutput<'lease, 'layer, 'ctx> { // Additive literal Original stream/event adapter. Old synchronous APIs above // remain whole-byte unchanged, including their original default finite errors. -#[path = "mmq_original_ring.rs"] mod copy_ring; use copy_ring::GatherDest; pub(crate) use copy_ring::prefetch_point; pub use copy_ring::{OriginalMmqCopySchedule, PrefetchSource, PrefetchTarget, RingExperts}; // Closed global issuer consumer. Old per-layer/synchronous producers unchanged. -#[path = "mmq_original_stream_all.rs"] mod stream_all_mmq; #[cfg(all(test, feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_arch = "x86_64"))] #[allow(unsafe_code)] -#[path = "mmq_original_group_stress_gpu.rs"] mod stress_gpu; -#[path = "mmq_original_group/asset.rs"] mod asset; -#[allow(unused_imports)] pub(crate) use asset::asset; -#[allow(unused_imports)] pub use asset::original_mmq_group_bank_bytes; -#[allow(unused_imports)] -use asset::sizes; -#[path = "mmq_original_group/kind.rs"] mod kind; -#[allow(unused_imports)] use kind::format_index; -#[allow(unused_imports)] use kind::kind; -#[allow(unused_imports)] use kind::layout; -#[allow(unused_imports)] use kind::shared; -#[path = "mmq_original_group/copy_ring_layer.rs"] mod copy_ring_layer; -#[path = "mmq_original_group/mmq_workspace.rs"] mod mmq_workspace; -#[path = "mmq_original_group/original_mmq_layer.rs"] mod original_mmq_layer; -#[path = "mmq_original_group/original_mmq_output.rs"] mod original_mmq_output; diff --git a/crates/cuda-driver/src/mmq_original_group/asset.rs b/crates/cuda-driver/src/mmq/resident/original_group/asset.rs similarity index 95% rename from crates/cuda-driver/src/mmq_original_group/asset.rs rename to crates/cuda-driver/src/mmq/resident/original_group/asset.rs index 8989b0d1..dcd0d8a4 100644 --- a/crates/cuda-driver/src/mmq_original_group/asset.rs +++ b/crates/cuda-driver/src/mmq/resident/original_group/asset.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalGroupBank`: `new`, `admit_charge`, `init`, `load_guarded` and 9 more. -//! Implements `Drop for OriginalGroupBank`. Functions: `asset`, `sizes`, `original_mmq_group_bank_bytes`. +//! The OriginalGroupBank: sealed PTX per kernel kind, the eager device-budget charge, module and kernel loading, +//! buffer allocation and bounds-checked buffer/handle access for the original prompt expert groups; Drop frees them. use super::{ Context, DeviceBuffer, Error, FORMATS, MmqFormat, OriginalGroupBank, Result, SEALED, TMP, WIDTHS, combine, ffi, @@ -8,9 +8,9 @@ use super::{ pub(crate) fn asset(kind: u32) -> Result<&'static [u8]> { let bytes: &[u8] = match kind { - 0 => include_bytes!("../mmq_original_group_swiglu.ptx"), - 1 => include_bytes!("../mmq_original_group_mul.ptx"), - 2 => include_bytes!("../mmq_original_group_fixup.ptx"), + 0 => include_bytes!("../../../mmq_original_group_swiglu.ptx"), + 1 => include_bytes!("../../../mmq_original_group_mul.ptx"), + 2 => include_bytes!("../../../mmq_original_group_fixup.ptx"), _ => return Err(Error::InvalidProjectionShape), }; let (size, sha) = SEALED[kind as usize].ok_or(Error::InvalidDriverValue("unsealed Original MMQ group"))?; diff --git a/crates/cuda-driver/src/mmq_original_ring.rs b/crates/cuda-driver/src/mmq/resident/original_group/copy_ring.rs similarity index 93% rename from crates/cuda-driver/src/mmq_original_ring.rs rename to crates/cuda-driver/src/mmq/resident/original_group/copy_ring.rs index 4e5c9baf..a581511f 100644 --- a/crates/cuda-driver/src/mmq_original_ring.rs +++ b/crates/cuda-driver/src/mmq/resident/original_group/copy_ring.rs @@ -5,11 +5,9 @@ use crate::ffi::original_enqueue::{Api, Command}; use crate::original_gpu_schedule::{OriginalEventKind, OriginalGpuEvent, OriginalGpuStream, OriginalStreamKind}; use leleka_model_format::qwen4exp::{ResidentExpertBankSpan, TensorRole}; use std::rc::Rc; -#[path = "mmq_original_host_stage.rs"] mod host_stage; use host_stage::{HostStage, Job}; #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] -#[path = "mmq_original_chunk_stream.rs"] mod chunk_stream; #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] pub(crate) use chunk_stream::prefetch_point; @@ -133,28 +131,19 @@ pub(super) struct Ring<'read, 'ctx> { closed: bool, } -#[path = "mmq_original_ring/skip_expert_dma.rs"] mod skip_expert_dma; #[cfg(not(all( feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64" )))] -#[allow(unused_imports)] pub(crate) use skip_expert_dma::prefetch_point; -#[allow(unused_imports)] use skip_expert_dma::serialize_ring; -#[allow(unused_imports)] use skip_expert_dma::skip_expert_dma; -#[path = "mmq_original_ring/original_mmq_copy_schedule.rs"] mod original_mmq_copy_schedule; -#[path = "mmq_original_ring/original_mmq_copy_schedule_drop.rs"] mod original_mmq_copy_schedule_drop; -#[path = "mmq_original_ring/ring.rs"] mod ring; -#[path = "mmq_original_ring/ring_drop.rs"] mod ring_drop; -#[path = "mmq_original_ring/ring_prefetch_issue.rs"] mod ring_prefetch_issue; use ring_prefetch_issue::RingPrefetch; pub use ring_prefetch_issue::{PrefetchSource, PrefetchTarget}; diff --git a/crates/cuda-driver/src/mmq_original_chunk_stream.rs b/crates/cuda-driver/src/mmq/resident/original_group/copy_ring/chunk_stream.rs similarity index 97% rename from crates/cuda-driver/src/mmq_original_chunk_stream.rs rename to crates/cuda-driver/src/mmq/resident/original_group/copy_ring/chunk_stream.rs index 83b8ea75..c4e35123 100644 --- a/crates/cuda-driver/src/mmq_original_chunk_stream.rs +++ b/crates/cuda-driver/src/mmq/resident/original_group/copy_ring/chunk_stream.rs @@ -86,10 +86,7 @@ pub(super) struct ChunkStream { thread: Option>, } -#[path = "mmq_original_chunk_stream/chunk_issuing.rs"] mod chunk_issuing; -#[allow(unused_imports)] pub(crate) use chunk_issuing::prefetch_point; -#[path = "mmq_original_chunk_stream/chunk_stream.rs"] mod chunk_stream; pub(crate) use chunk_stream::CoreParts; diff --git a/crates/cuda-driver/src/mmq_original_chunk_stream/chunk_issuing.rs b/crates/cuda-driver/src/mmq/resident/original_group/copy_ring/chunk_stream/chunk_issuing.rs similarity index 100% rename from crates/cuda-driver/src/mmq_original_chunk_stream/chunk_issuing.rs rename to crates/cuda-driver/src/mmq/resident/original_group/copy_ring/chunk_stream/chunk_issuing.rs diff --git a/crates/cuda-driver/src/mmq_original_chunk_stream/chunk_stream.rs b/crates/cuda-driver/src/mmq/resident/original_group/copy_ring/chunk_stream/chunk_stream.rs similarity index 98% rename from crates/cuda-driver/src/mmq_original_chunk_stream/chunk_stream.rs rename to crates/cuda-driver/src/mmq/resident/original_group/copy_ring/chunk_stream/chunk_stream.rs index 3c56f1c8..93296fd4 100644 --- a/crates/cuda-driver/src/mmq_original_chunk_stream/chunk_stream.rs +++ b/crates/cuda-driver/src/mmq/resident/original_group/copy_ring/chunk_stream/chunk_stream.rs @@ -1,5 +1,5 @@ -//! Methods of `Stats`: `new`. Methods of `Core`: `new`. Implements `Drop for ChunkStream`. Functions: `env_number`. -//! Defines `CoreParts`. +//! ChunkStream state for the prompt-chunk expert stream: an ordered list of expert copy entries (layer, expert) +//! feeding the ring slots, the shared Core and timing Stats, the issuer-thread setup and issue depth; Drop stops it. use super::{ ACTIVE, Api, Arc, AtomicBool, AtomicU64, AtomicUsize, BufferHandle, ChunkStream, Core, Entry, Error, Ordering, diff --git a/crates/cuda-driver/src/mmq_original_host_stage.rs b/crates/cuda-driver/src/mmq/resident/original_group/copy_ring/host_stage.rs similarity index 91% rename from crates/cuda-driver/src/mmq_original_host_stage.rs rename to crates/cuda-driver/src/mmq/resident/original_group/copy_ring/host_stage.rs index 3b3a0b1f..15addee9 100644 --- a/crates/cuda-driver/src/mmq_original_host_stage.rs +++ b/crates/cuda-driver/src/mmq/resident/original_group/copy_ring/host_stage.rs @@ -76,20 +76,12 @@ pub(super) struct HostStage { } #[cfg(test)] -#[path = "mmq_original_host_stage/tests.rs"] +#[path = "../../../../mmq_original_host_stage/tests.rs"] mod tests; -#[path = "mmq_original_host_stage/verify_enabled.rs"] mod verify_enabled; -#[allow(unused_imports)] -use verify_enabled::apply_priority; -#[allow(unused_imports)] -use verify_enabled::block_bytes; -#[allow(unused_imports)] pub(super) use verify_enabled::layer_priority; -#[allow(unused_imports)] +#[cfg(test)] pub(super) use verify_enabled::scales_finite; -#[allow(unused_imports)] use verify_enabled::verify_enabled; -#[path = "mmq_original_host_stage/host_stage.rs"] mod host_stage; diff --git a/crates/cuda-driver/src/mmq_original_host_stage/host_stage.rs b/crates/cuda-driver/src/mmq/resident/original_group/copy_ring/host_stage/host_stage.rs similarity index 98% rename from crates/cuda-driver/src/mmq_original_host_stage/host_stage.rs rename to crates/cuda-driver/src/mmq/resident/original_group/copy_ring/host_stage/host_stage.rs index 1bbf10c5..09a2bae1 100644 --- a/crates/cuda-driver/src/mmq_original_host_stage/host_stage.rs +++ b/crates/cuda-driver/src/mmq/resident/original_group/copy_ring/host_stage/host_stage.rs @@ -1,5 +1,5 @@ -//! Methods of `HostStage`: `new`, `stager_sizes`, `unstarted`, `allocate_ring` and 13 more. -//! Implements `Drop for HostStage`. +//! HostStage: the page-locked ring buffers and helper threads that stage pageable experts on the host ahead of their +//! DMA, plus the STAGE_VERIFY check that a released buffer still equals its source. Drop stops helpers and frees them. use super::{ Arc, AtomicU32, AtomicU64, AtomicUsize, Condvar, Error, HostStage, Job, MAX_JOBS, Mutex, NON_FINITE, Ordering, diff --git a/crates/cuda-driver/src/mmq_original_host_stage/verify_enabled.rs b/crates/cuda-driver/src/mmq/resident/original_group/copy_ring/host_stage/verify_enabled.rs similarity index 97% rename from crates/cuda-driver/src/mmq_original_host_stage/verify_enabled.rs rename to crates/cuda-driver/src/mmq/resident/original_group/copy_ring/host_stage/verify_enabled.rs index ca0dbc0a..5ccdd8b4 100644 --- a/crates/cuda-driver/src/mmq_original_host_stage/verify_enabled.rs +++ b/crates/cuda-driver/src/mmq/resident/original_group/copy_ring/host_stage/verify_enabled.rs @@ -1,10 +1,8 @@ -//! Methods of `Shared`: `claim`, `finished`, `work`, `await_jobs` and 4 more. -//! Functions: `verify_enabled`, `layer_priority`, `apply_priority`, `block_bytes` and 1 more. +//! Helper-thread side of HostStage: the shared job claim and copy loop, the finite FP16 block-scale check of copied +//! experts, the LELEKA_STAGE_VERIFY switch and the optional Windows page-cache priority for the layers read first. use super::{Arc, Job, NON_FINITE, NORMAL_PRIORITY, Ordering, Shared, thread}; // used only with some cargo features or targets of this crate -#[allow(unused_imports)] -use super::{LAYERS, LOW_PRIORITY}; /// Bring-up: `LELEKA_BRINGUP_TRACE` and `LELEKA_STAGE_VERIFY` compare every staged buffer with its source when its DMA /// is released. diff --git a/crates/cuda-driver/src/mmq_original_ring/original_mmq_copy_schedule.rs b/crates/cuda-driver/src/mmq/resident/original_group/copy_ring/original_mmq_copy_schedule.rs similarity index 97% rename from crates/cuda-driver/src/mmq_original_ring/original_mmq_copy_schedule.rs rename to crates/cuda-driver/src/mmq/resident/original_group/copy_ring/original_mmq_copy_schedule.rs index e3e86d02..244d9891 100644 --- a/crates/cuda-driver/src/mmq_original_ring/original_mmq_copy_schedule.rs +++ b/crates/cuda-driver/src/mmq/resident/original_group/copy_ring/original_mmq_copy_schedule.rs @@ -1,12 +1,11 @@ -//! Methods of `OriginalMmqCopySchedule`: `retain_host_metadata_charge`, `ring_slots`, `prompt_stream_active`, `begin... -//! Split out of `copy_ring` to keep its files under the line limit. +//! Public control of the OriginalMmqCopySchedule: begin and end the prompt-chunk expert stream, metadata byte +//! accounting, context validation, and the ordered close of host stage, events and streams after a failure. use super::{ ChunkStream, Context, Error, Events, OriginalGpuStream, OriginalMmqCopySchedule, Rc, Result, StreamEntry, chunk_stream, combine, }; // used only with some cargo features or targets of this crate -#[allow(unused_imports)] use super::ffi; #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] diff --git a/crates/cuda-driver/src/mmq_original_ring/stream_start.rs b/crates/cuda-driver/src/mmq/resident/original_group/copy_ring/original_mmq_copy_schedule/stream_start.rs similarity index 100% rename from crates/cuda-driver/src/mmq_original_ring/stream_start.rs rename to crates/cuda-driver/src/mmq/resident/original_group/copy_ring/original_mmq_copy_schedule/stream_start.rs diff --git a/crates/cuda-driver/src/mmq_original_ring/original_mmq_copy_schedule_drop.rs b/crates/cuda-driver/src/mmq/resident/original_group/copy_ring/original_mmq_copy_schedule_drop.rs similarity index 55% rename from crates/cuda-driver/src/mmq_original_ring/original_mmq_copy_schedule_drop.rs rename to crates/cuda-driver/src/mmq/resident/original_group/copy_ring/original_mmq_copy_schedule_drop.rs index ceb06900..ffa2eba5 100644 --- a/crates/cuda-driver/src/mmq_original_ring/original_mmq_copy_schedule_drop.rs +++ b/crates/cuda-driver/src/mmq/resident/original_group/copy_ring/original_mmq_copy_schedule_drop.rs @@ -1,5 +1,4 @@ -//! Implements `Drop for OriginalMmqCopySchedule`. -//! Split out of `copy_ring` to keep its files under the line limit. +//! Drop of OriginalMmqCopySchedule: closes the schedule so its streams, events and host stage are released. use super::OriginalMmqCopySchedule; diff --git a/crates/cuda-driver/src/mmq_original_ring/ring.rs b/crates/cuda-driver/src/mmq/resident/original_group/copy_ring/ring.rs similarity index 64% rename from crates/cuda-driver/src/mmq_original_ring/ring.rs rename to crates/cuda-driver/src/mmq/resident/original_group/copy_ring/ring.rs index bd6c7096..78d57b42 100644 --- a/crates/cuda-driver/src/mmq_original_ring/ring.rs +++ b/crates/cuda-driver/src/mmq/resident/original_group/copy_ring/ring.rs @@ -1,5 +1,4 @@ -//! Groups the submodules `ring_construction`, `ring_gather_and_finish`, `ring_init` and 2 more. -//! Split out of `copy_ring` to keep its files under the line limit. +//! Module root of the copy Ring: shared imports of its construction, init, prefetch, stage and gather files. use super::{ Api, COMMAND_CAP, Command, Context, DeviceBuffer, Drain, Error, FORMATS, GatherDest, GroupArena, HostStage, Job, @@ -8,14 +7,10 @@ use super::{ host_stage, kind, serialize_ring, skip_expert_dma, }; -#[path = "ring/ring_construction.rs"] mod ring_construction; -#[path = "ring/ring_gather_and_finish.rs"] mod ring_gather_and_finish; mod ring_init; -#[path = "ring/ring_prefetch.rs"] mod ring_prefetch; pub(super) use ring_prefetch::profile_prefetch; -#[path = "ring/ring_stage_expert_copies.rs"] mod ring_stage_expert_copies; pub(super) use ring_init::RingPlan; diff --git a/crates/cuda-driver/src/mmq_original_ring/ring/ring_construction.rs b/crates/cuda-driver/src/mmq/resident/original_group/copy_ring/ring/ring_construction.rs similarity index 93% rename from crates/cuda-driver/src/mmq_original_ring/ring/ring_construction.rs rename to crates/cuda-driver/src/mmq/resident/original_group/copy_ring/ring/ring_construction.rs index f5f2ecb9..45e4ce8a 100644 --- a/crates/cuda-driver/src/mmq_original_ring/ring/ring_construction.rs +++ b/crates/cuda-driver/src/mmq/resident/original_group/copy_ring/ring/ring_construction.rs @@ -1,5 +1,5 @@ -//! Methods of `Ring`: `new`, `admitted_slots`. Functions: `schedule_serves_ring`. -//! Split out of `ring` to keep its files under the line limit. +//! Construction of the copy Ring: the rule that a schedule with enough slot events serves a (smaller) arena ring, +//! with its unit tests, and the admission of the arena stage slot count. use super::{Context, Error, OriginalMmqCopySchedule, Result, Ring, RingArena, RingExperts, RingPlan, combine}; diff --git a/crates/cuda-driver/src/mmq_original_ring/ring/ring_gather_and_finish.rs b/crates/cuda-driver/src/mmq/resident/original_group/copy_ring/ring/ring_gather_and_finish.rs similarity index 97% rename from crates/cuda-driver/src/mmq_original_ring/ring/ring_gather_and_finish.rs rename to crates/cuda-driver/src/mmq/resident/original_group/copy_ring/ring/ring_gather_and_finish.rs index 5c31e8ea..c1b2ff4b 100644 --- a/crates/cuda-driver/src/mmq_original_ring/ring/ring_gather_and_finish.rs +++ b/crates/cuda-driver/src/mmq/resident/original_group/copy_ring/ring/ring_gather_and_finish.rs @@ -1,5 +1,5 @@ -//! Methods of `Ring`: `gather`, `gather_streamed`, `gather_slot`, `check_gather_destination` and 10 more. -//! Split out of `ring` to keep its files under the line limit. +//! Gather and finish side of the copy Ring: gathers a staged expert slot into the group bank on the compute stream, +//! records the slot as used, releases a layer stream entry, and copies status words after both streams drain. use super::{Command, DeviceBuffer, Error, GatherDest, MmqFormat, OriginalGpuStream, Result, Ring, combine, ffi}; use crate::ring_prefetch::RingRefusal; diff --git a/crates/cuda-driver/src/mmq_original_ring/ring_init.rs b/crates/cuda-driver/src/mmq/resident/original_group/copy_ring/ring/ring_init.rs similarity index 100% rename from crates/cuda-driver/src/mmq_original_ring/ring_init.rs rename to crates/cuda-driver/src/mmq/resident/original_group/copy_ring/ring/ring_init.rs diff --git a/crates/cuda-driver/src/mmq_original_ring/ring/ring_prefetch.rs b/crates/cuda-driver/src/mmq/resident/original_group/copy_ring/ring/ring_prefetch.rs similarity index 100% rename from crates/cuda-driver/src/mmq_original_ring/ring/ring_prefetch.rs rename to crates/cuda-driver/src/mmq/resident/original_group/copy_ring/ring/ring_prefetch.rs diff --git a/crates/cuda-driver/src/mmq_original_ring/ring/ring_stage_expert_copies.rs b/crates/cuda-driver/src/mmq/resident/original_group/copy_ring/ring/ring_stage_expert_copies.rs similarity index 98% rename from crates/cuda-driver/src/mmq_original_ring/ring/ring_stage_expert_copies.rs rename to crates/cuda-driver/src/mmq/resident/original_group/copy_ring/ring/ring_stage_expert_copies.rs index 9eab7ce1..03bd9d40 100644 --- a/crates/cuda-driver/src/mmq_original_ring/ring/ring_stage_expert_copies.rs +++ b/crates/cuda-driver/src/mmq/resident/original_group/copy_ring/ring/ring_stage_expert_copies.rs @@ -1,5 +1,5 @@ -//! Methods of `Ring`: `metadata_bytes`, `enqueue`, `flag`, `stage_one` and 10 more. Functions: `profile_copied`. -//! Split out of `ring` to keep its files under the line limit. +//! Staging side of the copy Ring: copies one expert (gate, up, down) into a ring slot from a registered bank or +//! the host stage, as page-aligned supersets or exact pieces, and records its copied event and PCIe profile. use super::{ Api, COMMAND_CAP, Command, Drain, Error, MmqFormat, OriginalGpuEvent, OriginalGpuStream, ResidentExpertBankSpan, diff --git a/crates/cuda-driver/src/mmq_original_ring/ring_drop.rs b/crates/cuda-driver/src/mmq/resident/original_group/copy_ring/ring_drop.rs similarity index 52% rename from crates/cuda-driver/src/mmq_original_ring/ring_drop.rs rename to crates/cuda-driver/src/mmq/resident/original_group/copy_ring/ring_drop.rs index fd81ee7e..a0f76ec9 100644 --- a/crates/cuda-driver/src/mmq_original_ring/ring_drop.rs +++ b/crates/cuda-driver/src/mmq/resident/original_group/copy_ring/ring_drop.rs @@ -1,5 +1,4 @@ -//! Implements `Drop for Ring`. -//! Split out of `copy_ring` to keep its files under the line limit. +//! Drop of the copy Ring: runs the ordered close so the ring slots, events and host stage are released. use super::Ring; diff --git a/crates/cuda-driver/src/mmq_original_ring/ring_prefetch_issue.rs b/crates/cuda-driver/src/mmq/resident/original_group/copy_ring/ring_prefetch_issue.rs similarity index 100% rename from crates/cuda-driver/src/mmq_original_ring/ring_prefetch_issue.rs rename to crates/cuda-driver/src/mmq/resident/original_group/copy_ring/ring_prefetch_issue.rs diff --git a/crates/cuda-driver/src/mmq_original_ring/skip_expert_dma.rs b/crates/cuda-driver/src/mmq/resident/original_group/copy_ring/skip_expert_dma.rs similarity index 96% rename from crates/cuda-driver/src/mmq_original_ring/skip_expert_dma.rs rename to crates/cuda-driver/src/mmq/resident/original_group/copy_ring/skip_expert_dma.rs index 165a0e48..999dbb31 100644 --- a/crates/cuda-driver/src/mmq_original_ring/skip_expert_dma.rs +++ b/crates/cuda-driver/src/mmq/resident/original_group/copy_ring/skip_expert_dma.rs @@ -1,5 +1,5 @@ -//! Methods of `ChunkStream`: `entry`, `next_layer_is`, `entry_matches`, `acquire` and 3 more. -//! Methods of `Drain`: `index`. Implements `RingArena for OriginalDeviceGrRead`. +//! Diagnostic switches of the copy ring (skip expert DMA, serialize ring), non-CUDA stubs of ChunkStream, the +//! RingArena view of OriginalDeviceGrRead, and Context::original_mmq_copy_schedule, which opens its streams and events. use super::{ Api, Context, Drain, Error, Events, OriginalEventKind, OriginalMmqCopySchedule, OriginalStreamKind, Rc, Result, diff --git a/crates/cuda-driver/src/mmq_original_group/copy_ring_layer.rs b/crates/cuda-driver/src/mmq/resident/original_group/copy_ring_layer.rs similarity index 99% rename from crates/cuda-driver/src/mmq_original_group/copy_ring_layer.rs rename to crates/cuda-driver/src/mmq/resident/original_group/copy_ring_layer.rs index c02c1be9..c8c2feaa 100644 --- a/crates/cuda-driver/src/mmq_original_group/copy_ring_layer.rs +++ b/crates/cuda-driver/src/mmq/resident/original_group/copy_ring_layer.rs @@ -1,6 +1,5 @@ //! Copy-ring execution of an `OriginalMmqLayer`: stage, gather, enqueue, drain (a glob import: at the line limit). -#[allow(unused_imports)] use super::*; impl<'layer, 'ctx> OriginalMmqLayer<'layer, 'ctx> { diff --git a/crates/cuda-driver/src/mmq_original_group/kind.rs b/crates/cuda-driver/src/mmq/resident/original_group/kind.rs similarity index 94% rename from crates/cuda-driver/src/mmq_original_group/kind.rs rename to crates/cuda-driver/src/mmq/resident/original_group/kind.rs index 7fc7dbdf..4658065e 100644 --- a/crates/cuda-driver/src/mmq_original_group/kind.rs +++ b/crates/cuda-driver/src/mmq/resident/original_group/kind.rs @@ -1,5 +1,5 @@ -//! Methods of `Context`: `native_integer_iq3_mmq_original_grouped_workspace`. -//! Implements `GroupArena for OriginalDeviceGrRead`. Functions: `kind`, `shared`, `format_index`, `layout` and 1 more. +//! Format tables of the original grouped MMQ path (kernel kind, shared memory, format index, layout), the Context +//! constructor of the grouped workspace, and the GroupArena span view of the prompt arena. use super::{ BOUNDS, Context, D, Error, FORMATS, GU, GroupArena, H, HQ, IDENTITY, Layout, MmqFormat, MmqWorkspace, diff --git a/crates/cuda-driver/src/mmq_original_group/mmq_workspace.rs b/crates/cuda-driver/src/mmq/resident/original_group/mmq_workspace.rs similarity index 98% rename from crates/cuda-driver/src/mmq_original_group/mmq_workspace.rs rename to crates/cuda-driver/src/mmq/resident/original_group/mmq_workspace.rs index 13d5c18c..7c246e96 100644 --- a/crates/cuda-driver/src/mmq_original_group/mmq_workspace.rs +++ b/crates/cuda-driver/src/mmq/resident/original_group/mmq_workspace.rs @@ -1,5 +1,5 @@ -//! Methods of `MmqWorkspace`: `enable_original_expert_groups`, `enable_original_expert_group_arena`, `original_exper... -//! Methods of `RoutePlan`: `new`. +//! Original expert grouping API of MmqWorkspace: enables the group bank or arena-only mode, and prepares a layer by +//! uploading routes (host or device), validating expert counts, and quantizing the Mixed rows into indexed Q8. use super::{ BOUNDS, Error, GroupArena, IDENTITY, MmqWorkspace, OriginalGroupBank, OriginalMmqLayer, QuantizeSlots, ROW_IDS, diff --git a/crates/cuda-driver/src/mmq_original_group/original_mmq_layer.rs b/crates/cuda-driver/src/mmq/resident/original_group/original_mmq_layer.rs similarity index 54% rename from crates/cuda-driver/src/mmq_original_group/original_mmq_layer.rs rename to crates/cuda-driver/src/mmq/resident/original_group/original_mmq_layer.rs index 64a9cabe..3f3c0ae1 100644 --- a/crates/cuda-driver/src/mmq_original_group/original_mmq_layer.rs +++ b/crates/cuda-driver/src/mmq/resident/original_group/original_mmq_layer.rs @@ -1,5 +1,5 @@ -//! Groups the submodules `finite_and_quantize`, `group_projection`, `original_mmq_layer_stage_experts`. -//! Split out of `original_group` to keep its files under the line limit. +//! Module root of OriginalMmqLayer, one layer of the original grouped MMQ path: its buffer checks, grouped +//! projection and expert staging live in the three files below. use super::{ BOUNDS, D, DeviceBuffer, Error, FORMATS, FiniteScan, GU, H, HQ, IDENTITY, Layout, MmqFormat, OriginalGroupBank, @@ -7,9 +7,6 @@ use super::{ STATUS, TMP, WD, WG, WIDTHS, XQ, commands, ffi, format_index, kind, layout, }; -#[path = "original_mmq_layer/finite_and_quantize.rs"] mod finite_and_quantize; -#[path = "original_mmq_layer/group_projection.rs"] mod group_projection; -#[path = "original_mmq_layer/original_mmq_layer_stage_experts.rs"] mod original_mmq_layer_stage_experts; diff --git a/crates/cuda-driver/src/mmq_original_group/original_mmq_layer/finite_and_quantize.rs b/crates/cuda-driver/src/mmq/resident/original_group/original_mmq_layer/finite_and_quantize.rs similarity index 97% rename from crates/cuda-driver/src/mmq_original_group/original_mmq_layer/finite_and_quantize.rs rename to crates/cuda-driver/src/mmq/resident/original_group/original_mmq_layer/finite_and_quantize.rs index 5197a587..93cf5920 100644 --- a/crates/cuda-driver/src/mmq_original_group/original_mmq_layer/finite_and_quantize.rs +++ b/crates/cuda-driver/src/mmq/resident/original_group/original_mmq_layer/finite_and_quantize.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalMmqLayer`: `bank`, `span`, `handle`, `reject_arena_alias` and 10 more. -//! Split out of `original_mmq_layer` to keep its files under the line limit. +//! OriginalMmqLayer buffer access and safety checks: bank spans and handles, arena alias refusal, the finite-scan +//! status decoding, the activation quantizer lookup, and staging of one expert with source overlap proofs. use super::{ D, DeviceBuffer, Error, FORMATS, FiniteScan, H, MmqFormat, OriginalGroupBank, OriginalMmqLayer, QuantizeSlots, diff --git a/crates/cuda-driver/src/mmq_original_group/original_mmq_layer/group_projection.rs b/crates/cuda-driver/src/mmq/resident/original_group/original_mmq_layer/group_projection.rs similarity index 98% rename from crates/cuda-driver/src/mmq_original_group/original_mmq_layer/group_projection.rs rename to crates/cuda-driver/src/mmq/resident/original_group/original_mmq_layer/group_projection.rs index e3b201b4..008e0c5e 100644 --- a/crates/cuda-driver/src/mmq_original_group/original_mmq_layer/group_projection.rs +++ b/crates/cuda-driver/src/mmq/resident/original_group/original_mmq_layer/group_projection.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalMmqLayer`: `project`, `project_plan`, `project_kernels`, `project_grid` and 11 more. -//! Defines `ProjectPlan`, `ProjectHandles`. +//! Grouped projection of OriginalMmqLayer: plans the gate/up and down launches (kernels, stream-k grid, fixup), +//! builds their arguments, runs the group (projection, SwiGLU, hidden quantize) and arbitrates finite status. use super::{ BOUNDS, D, Error, FiniteScan, GU, H, HQ, IDENTITY, Layout, MmqFormat, OriginalGroupBank, OriginalMmqLayer, diff --git a/crates/cuda-driver/src/mmq_original_group/original_mmq_layer/original_mmq_layer_stage_experts.rs b/crates/cuda-driver/src/mmq/resident/original_group/original_mmq_layer/original_mmq_layer_stage_experts.rs similarity index 96% rename from crates/cuda-driver/src/mmq_original_group/original_mmq_layer/original_mmq_layer_stage_experts.rs rename to crates/cuda-driver/src/mmq/resident/original_group/original_mmq_layer/original_mmq_layer_stage_experts.rs index b144167c..dac87960 100644 --- a/crates/cuda-driver/src/mmq_original_group/original_mmq_layer/original_mmq_layer_stage_experts.rs +++ b/crates/cuda-driver/src/mmq/resident/original_group/original_mmq_layer/original_mmq_layer_stage_experts.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalMmqLayer`: `stage_raw`, `stage_slots`, `raw_amount`, `check_raw_handles` and 4 more. -//! Split out of `original_mmq_layer` to keep its files under the line limit. +//! Expert staging into OriginalMmqLayer: picks the next gate/up and down slots, proves raw sources disjoint, and +//! stages an expert from retained registered slices or from a completed prompt-cache prefix. use super::{ Error, MmqFormat, OriginalGroupBank, OriginalMmqLayer, QueuedCommand, Result, WD, WG, commands, ffi, kind, diff --git a/crates/cuda-driver/src/mmq_original_group/original_mmq_output.rs b/crates/cuda-driver/src/mmq/resident/original_group/original_mmq_output.rs similarity index 96% rename from crates/cuda-driver/src/mmq_original_group/original_mmq_output.rs rename to crates/cuda-driver/src/mmq/resident/original_group/original_mmq_output.rs index 5a3d5ef0..be1e5b69 100644 --- a/crates/cuda-driver/src/mmq_original_group/original_mmq_output.rs +++ b/crates/cuda-driver/src/mmq/resident/original_group/original_mmq_output.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalMmqOutput`: `copy_group_down_to_prompt`, `check_arena_destination`, `copy_expert_down_columns... -//! Methods of `OriginalMmqLayer`: `group_down_spans`, `down_column_handles`, `check_down_destination`, `reject_down_... +//! Output side of an original grouped MMQ layer: copies the finite Down group, or single expert columns, into the +//! prompt Dm arena or Down slots, after proving shapes, owners, extents and non-overlap. use super::{ Context, D, DeviceBuffer, Error, OriginalGroupBank, OriginalMmqLayer, OriginalMmqOutput, Result, combine, ffi, diff --git a/crates/cuda-driver/src/mmq_original_stream_all.rs b/crates/cuda-driver/src/mmq/resident/original_group/stream_all_mmq.rs similarity index 83% rename from crates/cuda-driver/src/mmq_original_stream_all.rs rename to crates/cuda-driver/src/mmq/resident/original_group/stream_all_mmq.rs index 0a882aab..4a56efba 100644 --- a/crates/cuda-driver/src/mmq_original_stream_all.rs +++ b/crates/cuda-driver/src/mmq/resident/original_group/stream_all_mmq.rs @@ -29,11 +29,6 @@ struct Producer<'producer, 'layer, 'ctx> { layer_id: u8, } -#[path = "mmq_original_stream_all/group_producer_gather_project.rs"] mod group_producer_gather_project; -#[path = "mmq_original_stream_all/transport.rs"] mod transport; -#[allow(unused_imports)] -use group_producer_gather_project::rows_group_span; -#[path = "mmq_original_stream_all/original_mmq_layer.rs"] mod original_mmq_layer; diff --git a/crates/cuda-driver/src/mmq_original_stream_all/group_producer_gather_project.rs b/crates/cuda-driver/src/mmq/resident/original_group/stream_all_mmq/group_producer_gather_project.rs similarity index 97% rename from crates/cuda-driver/src/mmq_original_stream_all/group_producer_gather_project.rs rename to crates/cuda-driver/src/mmq/resident/original_group/stream_all_mmq/group_producer_gather_project.rs index 49a97474..37ebc1c6 100644 --- a/crates/cuda-driver/src/mmq_original_stream_all/group_producer_gather_project.rs +++ b/crates/cuda-driver/src/mmq/resident/original_group/stream_all_mmq/group_producer_gather_project.rs @@ -1,5 +1,5 @@ -//! Methods of `Producer`: `rejects_context`, `rejects_state`, `check_spans`, `check_formats` and 5 more. -//! Implements `OriginalStreamAllGroupProducer for Producer`. +//! Gather and project steps of the stream-all group Producer: validates the prompt rows, formats and member +//! spans, gathers one expert into the group bank and enqueues its projection, refusing aliased buffers. use super::{ BOUNDS, Command, Context, D, Error, FORMATS, GU, H, HQ, IDENTITY, OriginalGpuStream, diff --git a/crates/cuda-driver/src/mmq_original_stream_all/original_mmq_layer.rs b/crates/cuda-driver/src/mmq/resident/original_group/stream_all_mmq/original_mmq_layer.rs similarity index 97% rename from crates/cuda-driver/src/mmq_original_stream_all/original_mmq_layer.rs rename to crates/cuda-driver/src/mmq/resident/original_group/stream_all_mmq/original_mmq_layer.rs index 4bdc3c6c..5221fb7a 100644 --- a/crates/cuda-driver/src/mmq_original_stream_all/original_mmq_layer.rs +++ b/crates/cuda-driver/src/mmq/resident/original_group/stream_all_mmq/original_mmq_layer.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalMmqLayer`: `enqueue_global_group`, `enqueue_zeroes`, `enqueue_hidden_checks`, `enqueue_hidden... -//! Split out of `stream_all_mmq` to keep its files under the line limit. +//! Stream-all execution on OriginalMmqLayer: enqueues the per-group zeroing, gate/up, SwiGLU, hidden quantize and +//! down launches with finite scans, then drains the stream and arbitrates the four status words per group. use super::{ Command, D, Error, GU, H, HQ, MmqFormat, OriginalGpuStream, OriginalGroupBank, OriginalMmqLayer, diff --git a/crates/cuda-driver/src/mmq_original_stream_all/transport.rs b/crates/cuda-driver/src/mmq/resident/original_group/stream_all_mmq/transport.rs similarity index 96% rename from crates/cuda-driver/src/mmq_original_stream_all/transport.rs rename to crates/cuda-driver/src/mmq/resident/original_group/stream_all_mmq/transport.rs index bb1ec6a8..7dc5306b 100644 --- a/crates/cuda-driver/src/mmq_original_stream_all/transport.rs +++ b/crates/cuda-driver/src/mmq/resident/original_group/stream_all_mmq/transport.rs @@ -1,5 +1,5 @@ -//! Methods of `Transport`: `new`, `reserve_host`, `check_host_budget`, `check_device_budget` and 5 more. -//! Implements `Drop for Transport`, `Drop for Producer`. +//! Transport of the stream-all producer: the command list, flag and status buffers, host and device budget checks, +//! enqueue onto the GPU stream and copy-back of statuses; Drop of Transport and Producer release them. use super::{ Api, COMMAND_CAP, Command, Context, DeviceBuffer, Error, OriginalGpuStream, Producer, Result, Transport, combine, diff --git a/crates/cuda-driver/src/mmq_original_group_stress_gpu.rs b/crates/cuda-driver/src/mmq/resident/original_group/stress_gpu.rs similarity index 100% rename from crates/cuda-driver/src/mmq_original_group_stress_gpu.rs rename to crates/cuda-driver/src/mmq/resident/original_group/stress_gpu.rs diff --git a/crates/cuda-driver/src/mmq/tile.rs b/crates/cuda-driver/src/mmq/tile.rs index fe4e2c01..bdbc9d3d 100644 --- a/crates/cuda-driver/src/mmq/tile.rs +++ b/crates/cuda-driver/src/mmq/tile.rs @@ -1,5 +1,5 @@ -//! Methods of `Tile`: `width`, `index`, `original`. -//! Methods of `MmqFormat`: `index`, `entry`, `fixup_entry`, `geometry` and 2 more. +//! Tile widths (J8..J64) and MmqFormat tables of the MMQ path: the original mul_mat_q and stream-k fixup kernel +//! entry symbols per format and tile, format geometry, and the (adaptive) Layout of a projection for a token count. use super::{CStr, Error, Layout, MmqFormat, MmqProfile, Result, Tile}; diff --git a/crates/cuda-driver/src/mmq_original_host_stage/tests.rs b/crates/cuda-driver/src/mmq_original_host_stage/tests.rs index a2fd99e4..fe1c4ac9 100644 --- a/crates/cuda-driver/src/mmq_original_host_stage/tests.rs +++ b/crates/cuda-driver/src/mmq_original_host_stage/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests of the original host stage: the FP16 block-scale finite rule per routed format, and the helper-thread +//! protocol (wait refuses over-long reads, finish cancels waiters and leaves no helper copying from a released bank). use super::*; #[test] diff --git a/crates/cuda-driver/src/moe_down_pack_gpu.rs b/crates/cuda-driver/src/moe_down_pack_gpu_tests.rs similarity index 100% rename from crates/cuda-driver/src/moe_down_pack_gpu.rs rename to crates/cuda-driver/src/moe_down_pack_gpu_tests.rs diff --git a/crates/cuda-driver/src/moe_group_projection.rs b/crates/cuda-driver/src/moe_group_projection.rs index d6dce209..20f07f19 100644 --- a/crates/cuda-driver/src/moe_group_projection.rs +++ b/crates/cuda-driver/src/moe_group_projection.rs @@ -4,24 +4,12 @@ use super::{ RoutedGateUpQ8, combine, ffi, projection_shape, }; // used only by the GPU proofs of other cargo feature sets (`expert-tier-probe`) -#[allow(unused_imports)] #[cfg(test)] use super::{ - Bf16ProjectionShape, Cell, DenseFormat, Device, DownColumns, Driver, KV_RESIDENT_DEFAULT_CELLS, - KV_RESIDENT_MIN_CELLS, MAX_CONTEXT_CELLS, OriginalGraphResources, OriginalHostKv, OriginalMtpCapture, - OriginalMtpCoupledPlan, OriginalMtpKvFormat, OriginalMtpKvMode, OriginalMtpKvPlan, OriginalMtpKvStartup, - OriginalMtpLoadPlan, OriginalMtpPlanError, OriginalMtpWeightBankPlan, OriginalSessionBytes, OriginalSessionControl, - PhantomData, Q5KProjectionShape, Q6KProjectionShape, Rc, RefCell, ServingContext, TRAINED_CONTEXT_CELLS, - bringup_trace_enabled, context, + Device, DownColumns, Driver, }; // used only by the GPU proofs of other cargo feature sets (`expert-tier-probe`) -#[allow(unused_imports)] -#[cfg(all(test, any(target_os = "linux", target_os = "windows"), target_arch = "x86_64", feature = "cuda-driver"))] -use super::{GdnGemm, GrBatchModule}; // used only by the GPU proofs of other cargo feature sets (`expert-tier-probe`) -#[allow(unused_imports)] -#[cfg(all(test, feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] -use super::{OriginalNativeHeadGraphResources, OriginalVerifyGraphResources, OriginalVerifyWindowOps}; impl Context<'_> { pub fn project_routed_gate_up_columns( &self, @@ -364,7 +352,6 @@ mod installed_tests { any(target_os = "linux", target_os = "windows"), target_pointer_width = "64" ))] -#[path = "grouped_gu21_gu23_gpu.rs"] mod grouped_gu21_gu23_gpu; #[cfg(all( @@ -373,5 +360,4 @@ mod grouped_gu21_gu23_gpu; any(target_os = "linux", target_os = "windows"), target_pointer_width = "64" ))] -#[path = "grouped_gu21_gu23_nc4_gpu.rs"] mod grouped_gu21_gu23_nc4_gpu; diff --git a/crates/cuda-driver/src/grouped_gu21_gu23_gpu.rs b/crates/cuda-driver/src/moe_group_projection/grouped_gu21_gu23_gpu.rs similarity index 96% rename from crates/cuda-driver/src/grouped_gu21_gu23_gpu.rs rename to crates/cuda-driver/src/moe_group_projection/grouped_gu21_gu23_gpu.rs index 183eeb8c..8128cb16 100644 --- a/crates/cuda-driver/src/grouped_gu21_gu23_gpu.rs +++ b/crates/cuda-driver/src/moe_group_projection/grouped_gu21_gu23_gpu.rs @@ -102,11 +102,7 @@ fn original_first_gu21_gu23_full_products_refusals_reset_and_cleanup() { ); } -#[path = "grouped_gu21_gu23_gpu/grouped_numeric_run.rs"] mod grouped_numeric_run; -#[allow(unused_imports)] use grouped_numeric_run::numeric; -#[path = "grouped_gu21_gu23_gpu/guards.rs"] mod guards; -#[allow(unused_imports)] use guards::guards; diff --git a/crates/cuda-driver/src/grouped_gu21_gu23_gpu/grouped_numeric_run.rs b/crates/cuda-driver/src/moe_group_projection/grouped_gu21_gu23_gpu/grouped_numeric_run.rs similarity index 97% rename from crates/cuda-driver/src/grouped_gu21_gu23_gpu/grouped_numeric_run.rs rename to crates/cuda-driver/src/moe_group_projection/grouped_gu21_gu23_gpu/grouped_numeric_run.rs index 96f7c8e6..a87724b5 100644 --- a/crates/cuda-driver/src/grouped_gu21_gu23_gpu/grouped_numeric_run.rs +++ b/crates/cuda-driver/src/moe_group_projection/grouped_gu21_gu23_gpu/grouped_numeric_run.rs @@ -1,5 +1,5 @@ -//! Methods of `GuRig`: `new`, `finish`. Methods of `ScalarBuffers`: `new`, `release`, `column`, `down_columns`. -//! Functions: `scalar_products`, `input_unchanged`, `close_owners`, `release_inputs` and 2 more. +//! Numeric run of the grouped gate/up GPU proof: computes every original scalar product first, then the grouped +//! products from the same device owners, repeats with sentinel outputs, and compares them byte for byte. use super::{ Comparison, Context, DeviceBuffer, DownColumns, ProjectionKind, ProjectionSpec, Result, RoutedFormat, diff --git a/crates/cuda-driver/src/grouped_gu21_gu23_gpu/guards.rs b/crates/cuda-driver/src/moe_group_projection/grouped_gu21_gu23_gpu/guards.rs similarity index 97% rename from crates/cuda-driver/src/grouped_gu21_gu23_gpu/guards.rs rename to crates/cuda-driver/src/moe_group_projection/grouped_gu21_gu23_gpu/guards.rs index 87588edb..66bd767d 100644 --- a/crates/cuda-driver/src/grouped_gu21_gu23_gpu/guards.rs +++ b/crates/cuda-driver/src/moe_group_projection/grouped_gu21_gu23_gpu/guards.rs @@ -1,5 +1,5 @@ -//! Methods of `GuardRig`: `new`, `shape_refusals`, `short_refusals`, `foreign_refusal` and 5 more. -//! Functions: `is_finite_words`, `budget_refusal`, `budget_run`, `guards`. Defines `GuardRig`. +//! Refusal checks of the grouped gate/up GPU proof: wrong shape, short or foreign buffers, malformed (NaN/Inf) +//! weights, bad activations and an exhausted table budget must fail without publishing a usable product. use super::{ Context, Device, DeviceBuffer, Error, Result, RoutedFormat, RoutedGateUpQ8, gu_weights, input, read, upload, diff --git a/crates/cuda-driver/src/grouped_gu21_gu23_nc4_gpu.rs b/crates/cuda-driver/src/moe_group_projection/grouped_gu21_gu23_nc4_gpu.rs similarity index 87% rename from crates/cuda-driver/src/grouped_gu21_gu23_nc4_gpu.rs rename to crates/cuda-driver/src/moe_group_projection/grouped_gu21_gu23_nc4_gpu.rs index 7e8f6e4b..46253bea 100644 --- a/crates/cuda-driver/src/grouped_gu21_gu23_nc4_gpu.rs +++ b/crates/cuda-driver/src/moe_group_projection/grouped_gu21_gu23_nc4_gpu.rs @@ -51,21 +51,11 @@ fn original_first_gu21_gu23_nc4_full_products_tails_refusals_reset_and_cleanup() ); } -#[path = "grouped_gu21_gu23_nc4_gpu/grouped_upload_run.rs"] mod grouped_upload_run; -#[allow(unused_imports)] -use grouped_upload_run::down_weights; -#[allow(unused_imports)] use grouped_upload_run::gu_weights; -#[allow(unused_imports)] use grouped_upload_run::input; -#[allow(unused_imports)] use grouped_upload_run::numeric; -#[allow(unused_imports)] use grouped_upload_run::read; -#[allow(unused_imports)] use grouped_upload_run::upload; -#[path = "grouped_gu21_gu23_nc4_gpu/guards.rs"] mod guards; -#[allow(unused_imports)] use guards::guards; diff --git a/crates/cuda-driver/src/grouped_gu21_gu23_nc4_gpu/grouped_upload_run.rs b/crates/cuda-driver/src/moe_group_projection/grouped_gu21_gu23_nc4_gpu/grouped_upload_run.rs similarity index 98% rename from crates/cuda-driver/src/grouped_gu21_gu23_nc4_gpu/grouped_upload_run.rs rename to crates/cuda-driver/src/moe_group_projection/grouped_gu21_gu23_nc4_gpu/grouped_upload_run.rs index abf613e5..e8f808af 100644 --- a/crates/cuda-driver/src/grouped_gu21_gu23_nc4_gpu/grouped_upload_run.rs +++ b/crates/cuda-driver/src/moe_group_projection/grouped_gu21_gu23_nc4_gpu/grouped_upload_run.rs @@ -1,5 +1,5 @@ -//! Methods of `GuRig`: `new`, `finish`. Methods of `ScalarBuffers`: `new`, `release`, `column`, `down_columns`. -//! Functions: `upload`, `read`, `gu_weights`, `down_weights` and 7 more. +//! Upload helpers and numeric run of the NC4 grouped gate/up GPU proof: builds deterministic weights and inputs, +//! computes every scalar product first, then compares the four-column grouped products including the T5 tail. use super::{ Comparison, Context, DeviceBuffer, DownColumns, ProjectionKind, ProjectionSpec, Result, RoutedFormat, diff --git a/crates/cuda-driver/src/grouped_gu21_gu23_nc4_gpu/guards.rs b/crates/cuda-driver/src/moe_group_projection/grouped_gu21_gu23_nc4_gpu/guards.rs similarity index 97% rename from crates/cuda-driver/src/grouped_gu21_gu23_nc4_gpu/guards.rs rename to crates/cuda-driver/src/moe_group_projection/grouped_gu21_gu23_nc4_gpu/guards.rs index 1d9fb169..fe994db4 100644 --- a/crates/cuda-driver/src/grouped_gu21_gu23_nc4_gpu/guards.rs +++ b/crates/cuda-driver/src/moe_group_projection/grouped_gu21_gu23_nc4_gpu/guards.rs @@ -1,5 +1,5 @@ -//! Methods of `GuardRig`: `new`, `shape_refusals`, `short_refusals`, `foreign_refusal` and 7 more. -//! Functions: `is_finite_words`, `close_prepared`, `release_inputs`, `budget_refusal` and 2 more. Defines `GuardRig`. +//! Refusal checks of the NC4 grouped gate/up GPU proof: shape, short and foreign owners, malformed outputs, the +//! four-column tile plus live tail after fault and reset, and the 40-byte table budget refusal. use super::{ Context, Device, DeviceBuffer, Error, Result, RoutedFormat, RoutedGateUpQ8, gu_weights, input, read, upload, diff --git a/crates/cuda-driver/src/moe_prefill_batch/tests.rs b/crates/cuda-driver/src/moe_prefill_batch/tests.rs index fa9af278..db18998f 100644 --- a/crates/cuda-driver/src/moe_prefill_batch/tests.rs +++ b/crates/cuda-driver/src/moe_prefill_batch/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of `moe_prefill_batch`. +//! Tests of the MoE prefill batch program: stage slot order and sizes, the fixed program order with combine as the +//! only tail, status arbitration, kernel table and route/combine map checks, binding refusals and the pinned artifact. use super::*; diff --git a/crates/cuda-driver/src/mtp_dense_kv.rs b/crates/cuda-driver/src/mtp_dense_kv.rs index 4be9b0c3..1caae5d3 100644 --- a/crates/cuda-driver/src/mtp_dense_kv.rs +++ b/crates/cuda-driver/src/mtp_dense_kv.rs @@ -167,11 +167,9 @@ mod tests { } #[cfg(all(test, any(target_os = "linux", target_os = "windows"), target_arch = "x86_64"))] -#[path = "mtp_dense_kv_ring_gpu.rs"] mod gpu_tests; // Separate literal Original INT8 drafter; the historical F16 owner stays unchanged. -#[path = "mtp_original_int8.rs"] mod original_int8; pub use original_int8::MTP_ORIGINAL_WINDOW; pub(crate) use original_int8::session_assets_sealed; diff --git a/crates/cuda-driver/src/mtp_dense_kv_ring_gpu.rs b/crates/cuda-driver/src/mtp_dense_kv/gpu_tests.rs similarity index 100% rename from crates/cuda-driver/src/mtp_dense_kv_ring_gpu.rs rename to crates/cuda-driver/src/mtp_dense_kv/gpu_tests.rs diff --git a/crates/cuda-driver/src/mtp_original_int8.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8.rs similarity index 94% rename from crates/cuda-driver/src/mtp_original_int8.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8.rs index 368b3352..351a4c74 100644 --- a/crates/cuda-driver/src/mtp_original_int8.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8.rs @@ -1,10 +1,8 @@ //! Literal Original MTP INT8 ring and record_forward(full=false) attention tail. //! Input/GR and runtime causal authority are separate genuine producer obligations. //! No F16 ring, whole warm_step, prompt-attention, or host-float readiness substitute. -#[path = "mtp_original_int8_ffi.rs"] #[allow(unsafe_code)] mod abi; -#[path = "mtp_original_ring_state.rs"] mod ring_state; use crate::{Context, DeviceBuffer, Error, NativeBatchWorkspace, Result, combine}; use abi::{Arg, Arguments, LaunchDims, MappedOwner, Module}; @@ -55,13 +53,11 @@ struct Origin; #[derive(Clone)] pub struct MtpInt8OwnerId(Rc); -#[path = "mtp_original_logical_prefix.rs"] mod logical_prefix; pub use logical_prefix::{OriginalMtpSkipPrior, OriginalMtpSkippedPrefix}; // The literal prefill producer is an MTP child because it borrows this // owner's private ring/state types. Its public contracts are re-exported by // the crate integration point below. -#[path = "mtp_original_prefill.rs"] mod prefill; pub(crate) use prefill::session_assets_sealed; pub use prefill::{ @@ -207,21 +203,12 @@ mod pages_tests { } } -#[path = "mtp_original_int8/mtp_int8_owner_id.rs"] mod mtp_int8_owner_id; -#[allow(unused_imports)] use mtp_int8_owner_id::snapshot_memo; -#[path = "mtp_original_int8/physical_ring.rs"] mod physical_ring; -#[allow(unused_imports)] use physical_ring::checked; -#[allow(unused_imports)] use physical_ring::layout; -#[allow(unused_imports)] use physical_ring::rows_range; -#[allow(unused_imports)] use physical_ring::zero_bytes; -#[path = "mtp_original_int8/mtp_original_int8_operations.rs"] mod mtp_original_int8_operations; -#[path = "mtp_original_int8/mtp_original_int8_state_adoption.rs"] mod mtp_original_int8_state_adoption; diff --git a/crates/cuda-driver/src/mtp_original_int8_ffi.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/abi.rs similarity index 93% rename from crates/cuda-driver/src/mtp_original_int8_ffi.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/abi.rs index 11163e44..66fa5d0a 100644 --- a/crates/cuda-driver/src/mtp_original_int8_ffi.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/abi.rs @@ -32,7 +32,6 @@ impl LaunchShape { } #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] -#[path = "mtp_original_int8_ffi/driver_backed.rs"] mod driver_backed; #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] pub(crate) use driver_backed::Module; @@ -45,7 +44,6 @@ pub(crate) struct Module; const HOST_BYTES: usize = 276_825_088; // Original payload + four256B cursor alignment allowances. #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] -#[path = "mtp_original_int8_ffi/host_enabled.rs"] mod host_enabled; #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] pub(crate) use host_enabled::MappedOwner; @@ -56,5 +54,4 @@ pub(crate) use host_enabled::MappedOwner; )))] pub(crate) struct MappedOwner; -#[path = "mtp_original_int8_ffi/arguments.rs"] mod arguments; diff --git a/crates/cuda-driver/src/mtp_original_int8_ffi/arguments.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/abi/arguments.rs similarity index 92% rename from crates/cuda-driver/src/mtp_original_int8_ffi/arguments.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/abi/arguments.rs index 38b68978..ff7e7ca8 100644 --- a/crates/cuda-driver/src/mtp_original_int8_ffi/arguments.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/abi/arguments.rs @@ -1,5 +1,5 @@ -//! Methods of `Arguments`: `metadata_bytes`, `new`. Methods of `Module`: `load`, `launch`, `copy`, `close`. -//! Split out of `abi` to keep its files under the line limit. +//! Kernel argument list (Arguments, with its metadata byte count) of the fixed-symbol MTP ABI, plus the Module stubs +//! that refuse with UnsupportedPlatform when the CUDA driver is not built in. use super::{Arg, Arguments, Error, Result, c_void}; diff --git a/crates/cuda-driver/src/mtp_original_int8_ffi/driver_backed.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/abi/driver_backed.rs similarity index 100% rename from crates/cuda-driver/src/mtp_original_int8_ffi/driver_backed.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/abi/driver_backed.rs diff --git a/crates/cuda-driver/src/mtp_original_int8_ffi/host_enabled.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/abi/host_enabled.rs similarity index 98% rename from crates/cuda-driver/src/mtp_original_int8_ffi/host_enabled.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/abi/host_enabled.rs index 3c30b37d..32a05b41 100644 --- a/crates/cuda-driver/src/mtp_original_int8_ffi/host_enabled.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/abi/host_enabled.rs @@ -1,5 +1,5 @@ -//! Methods of `MappedOwner`: `new`, `new_sized`, `new_for_state`, `new_inner` and 9 more. -//! Implements `Drop for Library`, `Drop for MappedOwner`. Functions: `check`, `host_alloc`. +//! MappedOwner of the MTP ABI: a host-allocated block mapped to a device address, zeroed on creation, with bounded +//! write, read and state-zero access. Loads the driver library symbols; Drop frees the block and the library. use super::{Error, HOST_BYTES, Result}; use std::ffi::c_void; diff --git a/crates/cuda-driver/src/mtp_original_logical_prefix.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/logical_prefix.rs similarity index 100% rename from crates/cuda-driver/src/mtp_original_logical_prefix.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/logical_prefix.rs diff --git a/crates/cuda-driver/src/mtp_original_int8/mtp_int8_owner_id.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/mtp_int8_owner_id.rs similarity index 96% rename from crates/cuda-driver/src/mtp_original_int8/mtp_int8_owner_id.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/mtp_int8_owner_id.rs index 28becec9..ff18bc5b 100644 --- a/crates/cuda-driver/src/mtp_original_int8/mtp_int8_owner_id.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/mtp_int8_owner_id.rs @@ -1,5 +1,5 @@ -//! Methods of `MtpInt8OwnerId`: `same_owner`. Methods of `Pages`: `empty`, `from_vec`, `with_tail`, `len` and 2 more. -//! Implements `Clone for MtpOriginalRingResources`. Functions: `snapshot_memo`. +//! Snapshot bookkeeping of the original MTP int8 KV: owner identity, the copy-on-write Pages list shared by +//! snapshots, snapshot size and position accessors, the completed replay rows, and the snapshot memo switch. use super::{ CompletedMtpAttention, CompletedMtpKvReplay, Context, DeviceBuffer, Error, MtpInt8OwnerId, MtpInt8Snapshot, diff --git a/crates/cuda-driver/src/mtp_original_int8/mtp_original_int8_operations.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/mtp_original_int8_operations.rs similarity index 74% rename from crates/cuda-driver/src/mtp_original_int8/mtp_original_int8_operations.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/mtp_original_int8_operations.rs index 02b38a31..4a90c0ed 100644 --- a/crates/cuda-driver/src/mtp_original_int8/mtp_original_int8_operations.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/mtp_original_int8_operations.rs @@ -11,13 +11,8 @@ use super::{ TAIL_ENTRIES, abi, checked, combine, layout, rows_range, snapshot_memo, zero_bytes, }; -#[path = "mtp_original_int8_operations/mtp_original_int8_attend_split_k.rs"] mod mtp_original_int8_attend_split_k; -#[path = "mtp_original_int8_operations/mtp_original_int8_kv_only_replay.rs"] mod mtp_original_int8_kv_only_replay; -#[path = "mtp_original_int8_operations/mtp_original_int8_restore.rs"] mod mtp_original_int8_restore; -#[path = "mtp_original_int8_operations/mtp_original_int8_ring_bring_up.rs"] mod mtp_original_int8_ring_bring_up; -#[path = "mtp_original_int8_operations/mtp_original_int8_validate_execute.rs"] mod mtp_original_int8_validate_execute; diff --git a/crates/cuda-driver/src/mtp_original_int8/mtp_original_int8_operations/mtp_original_int8_attend_split_k.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/mtp_original_int8_operations/mtp_original_int8_attend_split_k.rs similarity index 96% rename from crates/cuda-driver/src/mtp_original_int8/mtp_original_int8_operations/mtp_original_int8_attend_split_k.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/mtp_original_int8_operations/mtp_original_int8_attend_split_k.rs index f70e3e2a..91af945b 100644 --- a/crates/cuda-driver/src/mtp_original_int8/mtp_original_int8_operations/mtp_original_int8_attend_split_k.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/mtp_original_int8_operations/mtp_original_int8_attend_split_k.rs @@ -1,5 +1,5 @@ -//! Methods of `MtpOriginalInt8`: `attend`, `check_attend`, `admit_query`, `addresses` and 6 more. -//! Split out of `mtp_original_int8_methods` to keep its files under the line limit. +//! Dense-window INT8 split-K attention of the original MTP ring: admits the query, enqueues the chunk reset, +//! split-K partials and merge launches with a finite check, and the close of the ring. use super::{ Arg, CHUNKS, Command, CompletedMtpAttention, Error, LaunchDims, MTP_ORIGINAL_WINDOW, MtpInt8Snapshot, diff --git a/crates/cuda-driver/src/mtp_original_int8/mtp_original_int8_operations/mtp_original_int8_kv_only_replay.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/mtp_original_int8_operations/mtp_original_int8_kv_only_replay.rs similarity index 98% rename from crates/cuda-driver/src/mtp_original_int8/mtp_original_int8_operations/mtp_original_int8_kv_only_replay.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/mtp_original_int8_operations/mtp_original_int8_kv_only_replay.rs index 7babde8b..e50d1836 100644 --- a/crates/cuda-driver/src/mtp_original_int8/mtp_original_int8_operations/mtp_original_int8_kv_only_replay.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/mtp_original_int8_operations/mtp_original_int8_kv_only_replay.rs @@ -1,5 +1,5 @@ -//! Methods of `MtpOriginalInt8`: `record_kv_only`, `kv_only_admit`, `kv_only_stage`, `kv_only_run` and 13 more. -//! Split out of `mtp_original_int8_methods` to keep its files under the line limit. +//! KV-only replay of the original MTP int8 ring (record_forward(false) attention tail): quantize, K/V projections, +//! K norm, rope and the per-row int8 append, with finite guards, alias checks and the resulting snapshot. use super::{ Arg, Command, CompletedMtpKvReplay, DeviceBuffer, Error, LaunchDims, MtpInt8Snapshot, MtpOriginalInt8, diff --git a/crates/cuda-driver/src/mtp_original_int8/mtp_original_int8_operations/mtp_original_int8_restore.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/mtp_original_int8_operations/mtp_original_int8_restore.rs similarity index 94% rename from crates/cuda-driver/src/mtp_original_int8/mtp_original_int8_operations/mtp_original_int8_restore.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/mtp_original_int8_operations/mtp_original_int8_restore.rs index 8e5242a3..0a1f89ed 100644 --- a/crates/cuda-driver/src/mtp_original_int8/mtp_original_int8_operations/mtp_original_int8_restore.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/mtp_original_int8_operations/mtp_original_int8_restore.rs @@ -1,5 +1,5 @@ -//! Methods of `MtpOriginalInt8`: `restore`, `begin_restore`, `restore_resident`, `write_host_pages` and 1 more. -//! Functions: `page_shared`. +//! Snapshot restore of the original MTP int8 ring: invalidates the current witness, writes the host pages the +//! previous witness lacked and rebuilds the modulo ring blocks on the device from the mapped pages. use super::{ Command, Error, HOST_OFFSETS, MtpInt8Snapshot, MtpOriginalInt8, NativeBatchWorkspace, PAGE_BYTES, Page, Rc, Result, diff --git a/crates/cuda-driver/src/mtp_original_int8/mtp_original_int8_operations/mtp_original_int8_ring_bring_up.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/mtp_original_int8_operations/mtp_original_int8_ring_bring_up.rs similarity index 92% rename from crates/cuda-driver/src/mtp_original_int8/mtp_original_int8_operations/mtp_original_int8_ring_bring_up.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/mtp_original_int8_operations/mtp_original_int8_ring_bring_up.rs index f1c76369..d6b270c5 100644 --- a/crates/cuda-driver/src/mtp_original_int8/mtp_original_int8_operations/mtp_original_int8_ring_bring_up.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/mtp_original_int8_operations/mtp_original_int8_ring_bring_up.rs @@ -1,5 +1,5 @@ -//! Methods of `MtpOriginalInt8`: `planned_device_bytes`, `pinned_host_bytes`, `max_snapshot_payload_bytes`, `max_sna... -//! Functions: `kv_assets_sealed`. +//! Bring-up of the original MTP int8 ring: byte budgets, the sealed PTX check, module loading, host mapping, +//! pool initialisation, and the retained physical resources and status queries of an open ring. use super::{ ATTN_ENTRIES, Cell, Context, DeviceBuffer, Error, KV_ENTRIES, MTP_ORIGINAL_PINNED_HOST_BYTES, @@ -11,8 +11,8 @@ use super::{ /// The ring's tail and KV PTX images must be sealed (no placeholder artifact). fn kv_assets_sealed() -> Result<()> { for ptx in [ - include_bytes!("../../mtp_original_tail.ptx").as_slice(), - include_bytes!("../../mtp_original_kv.ptx").as_slice(), + include_bytes!("../../../mtp_original_tail.ptx").as_slice(), + include_bytes!("../../../mtp_original_kv.ptx").as_slice(), ] { if ptx.windows(8).any(|w| w == b"UNSEALED") { return Err(Error::UnsupportedQwenOperation); @@ -106,10 +106,11 @@ impl<'ctx> MtpOriginalInt8<'ctx> { } fn load_modules(&mut self) -> Result<()> { self.physical_mut()?.modules[0] = - Some(Module::load(include_bytes!("../../mtp_original_tail.ptx"), TAIL_ENTRIES)?); - self.physical_mut()?.modules[1] = Some(Module::load(include_bytes!("../../mtp_original_kv.ptx"), KV_ENTRIES)?); + Some(Module::load(include_bytes!("../../../mtp_original_tail.ptx"), TAIL_ENTRIES)?); + self.physical_mut()?.modules[1] = + Some(Module::load(include_bytes!("../../../mtp_original_kv.ptx"), KV_ENTRIES)?); self.physical_mut()?.modules[2] = - Some(Module::load(include_bytes!("../../qsa_native_decode.ptx"), ATTN_ENTRIES)?); + Some(Module::load(include_bytes!("../../../qsa_native_decode.ptx"), ATTN_ENTRIES)?); self.map_host() } fn map_host(&mut self) -> Result<()> { diff --git a/crates/cuda-driver/src/mtp_original_int8/mtp_original_int8_operations/mtp_original_int8_validate_execute.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/mtp_original_int8_operations/mtp_original_int8_validate_execute.rs similarity index 97% rename from crates/cuda-driver/src/mtp_original_int8/mtp_original_int8_operations/mtp_original_int8_validate_execute.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/mtp_original_int8_operations/mtp_original_int8_validate_execute.rs index 36e9571f..de134a6b 100644 --- a/crates/cuda-driver/src/mtp_original_int8/mtp_original_int8_operations/mtp_original_int8_validate_execute.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/mtp_original_int8_operations/mtp_original_int8_validate_execute.rs @@ -1,5 +1,5 @@ -//! Methods of `MtpOriginalInt8`: `validate`, `provided`, `validate_pool`, `reject_earlier_overlap` and 12 more. -//! Split out of `mtp_original_int8_methods` to keep its files under the line limit. +//! Admission and execution of the original MTP int8 ring: pool and snapshot validation (overlap and mapped-alias +//! checks), launching command lists on the model stream, and settling their completion or poisoning. use super::{ Arg, Arguments, Command, DeviceBuffer, Error, LaunchDims, MTP_ORIGINAL_MAX_CELLS, MTP_ORIGINAL_PINNED_HOST_BYTES, diff --git a/crates/cuda-driver/src/mtp_original_int8/mtp_original_int8_state_adoption.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/mtp_original_int8_state_adoption.rs similarity index 90% rename from crates/cuda-driver/src/mtp_original_int8/mtp_original_int8_state_adoption.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/mtp_original_int8_state_adoption.rs index e2deffab..602f0cde 100644 --- a/crates/cuda-driver/src/mtp_original_int8/mtp_original_int8_state_adoption.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/mtp_original_int8_state_adoption.rs @@ -1,5 +1,5 @@ -//! Methods of `MtpOriginalInt8`: `new_original_state`, `bring_up_state`, `load_state_modules`, `adopt_selected` and ... -//! Implements `Drop for MtpOriginalInt8`. Functions: `original_state_sealed`. +//! State adoption of MtpOriginalInt8: seals and loads the state modules, binds the selected ring state or allocates +//! the extra pools, and exposes host addresses and encoded pages; Drop of MtpOriginalInt8 lives here too. use super::{ ATTN_ENTRIES, Context, DeviceBuffer, Error, HOST_OFFSETS, HOST_RUNS, KV_ENTRIES, MappedOwner, Module, @@ -15,9 +15,9 @@ impl Drop for MtpOriginalInt8<'_> { /// The tail, KV and QSA PTX images must be sealed (no placeholder artifact). fn original_state_sealed() -> Result<()> { for ptx in [ - include_bytes!("../mtp_original_tail.ptx").as_slice(), - include_bytes!("../mtp_original_kv.ptx").as_slice(), - include_bytes!("../qsa_native_decode.ptx").as_slice(), + include_bytes!("../../mtp_original_tail.ptx").as_slice(), + include_bytes!("../../mtp_original_kv.ptx").as_slice(), + include_bytes!("../../qsa_native_decode.ptx").as_slice(), ] { if ptx.windows(8).any(|w| w == b"UNSEALED") { return Err(Error::UnsupportedQwenOperation); @@ -72,9 +72,9 @@ impl<'ctx> MtpOriginalInt8<'ctx> { } fn load_state_modules(&mut self) -> Result<()> { for (i, (ptx, entries)) in [ - (include_bytes!("../mtp_original_tail.ptx").as_slice(), TAIL_ENTRIES), - (include_bytes!("../mtp_original_kv.ptx").as_slice(), KV_ENTRIES), - (include_bytes!("../qsa_native_decode.ptx").as_slice(), ATTN_ENTRIES), + (include_bytes!("../../mtp_original_tail.ptx").as_slice(), TAIL_ENTRIES), + (include_bytes!("../../mtp_original_kv.ptx").as_slice(), KV_ENTRIES), + (include_bytes!("../../qsa_native_decode.ptx").as_slice(), ATTN_ENTRIES), ] .into_iter() .enumerate() diff --git a/crates/cuda-driver/src/mtp_original_int8/physical_ring.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/physical_ring.rs similarity index 96% rename from crates/cuda-driver/src/mtp_original_int8/physical_ring.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/physical_ring.rs index 573a484a..0ac34ee7 100644 --- a/crates/cuda-driver/src/mtp_original_int8/physical_ring.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/physical_ring.rs @@ -1,5 +1,5 @@ -//! Methods of `PhysicalRing`: `validate_context`, `unavailable`, `close_inner`, `close_modules` and 1 more. -//! Methods of `Context`: `mtp_original_int8`. Implements `Drop for PhysicalRing`. +//! Physical storage of the original MTP int8 ring: context validation, ordered close of modules and host mapping, +//! the pool layout and row-range checks, and the Context::mtp_original_int8 entry point; Drop of PhysicalRing. use super::{ Context, DeviceBuffer, Error, MTP_ORIGINAL_MAX_CELLS, MTP_ORIGINAL_WINDOW, MtpOriginalInt8, PhysicalRing, Result, diff --git a/crates/cuda-driver/src/mtp_original_prefill.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill.rs similarity index 93% rename from crates/cuda-driver/src/mtp_original_prefill.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill.rs index cd01fd50..e6840bc7 100644 --- a/crates/cuda-driver/src/mtp_original_prefill.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill.rs @@ -11,7 +11,6 @@ use crate::ffi::BufferHandle; use crate::original_prefill_arena::OriginalPromptSpan; use crate::{OriginalDeviceResidual, OriginalPromptRows}; #[allow(unsafe_code)] -#[path = "mtp_original_prefill_ffi.rs"] mod prefill_abi; use prefill_abi::{Arg as A, Arguments as Args, Geometry as PrefillGeometry, Module as Mod}; use std::ffi::CStr; @@ -37,7 +36,6 @@ const ENTRIES: &[&CStr] = &[ c"mtp_prefill_gr_product_scan", c"mtp_prefill_q8_scan", ]; -#[path = "mtp_original_prefill_symbols.rs"] mod symbols; #[derive(Clone, Copy, Debug, PartialEq, Eq)] @@ -160,7 +158,6 @@ pub struct OriginalMtpPrefill<'ctx> { failed: bool, } -#[path = "mtp_original_scalar_prefill.rs"] mod scalar; pub(crate) use scalar::session_assets_sealed; pub use scalar::{ @@ -170,17 +167,10 @@ pub use scalar::{ OriginalMtpStepOutput, ScalarDraftKvSources, }; -#[path = "mtp_original_prefill/completed_draft_kv.rs"] mod completed_draft_kv; -#[allow(unused_imports)] use completed_draft_kv::aligned; -#[allow(unused_imports)] use completed_draft_kv::fastdiv; -#[allow(unused_imports)] use completed_draft_kv::q8_bytes; -#[path = "mtp_original_prefill/original_mtp_prefill.rs"] mod original_mtp_prefill; -#[path = "mtp_original_prefill/original_mtp_prefill_drop.rs"] mod original_mtp_prefill_drop; -#[path = "mtp_original_prefill/region.rs"] mod region; diff --git a/crates/cuda-driver/src/mtp_original_prefill/completed_draft_kv.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/completed_draft_kv.rs similarity index 96% rename from crates/cuda-driver/src/mtp_original_prefill/completed_draft_kv.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/completed_draft_kv.rs index 445c70ac..48e31e41 100644 --- a/crates/cuda-driver/src/mtp_original_prefill/completed_draft_kv.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/completed_draft_kv.rs @@ -1,5 +1,5 @@ -//! Methods of `CompletedDraftKv`: `validate_current`, `first_materialized`, `next_position`, `owner_id` and 3 more. -//! Methods of `OriginalMtpEmbedding`: `native`, `compressed`, `vocab`. +//! Accessors of CompletedDraftKv (the finished draft KV of a prefill: snapshots at a position or window, validity +//! against the ring), the native and compressed MTP embedding table layouts, and the original int8 DraftKvPolicy. use super::{ CompletedDraftKv, CompressedEmbedding, DeviceBuffer, DraftKvPolicy, EmbeddingKind, Error, MtpInt8OwnerId, diff --git a/crates/cuda-driver/src/mtp_original_prefill/original_mtp_prefill.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/original_mtp_prefill.rs similarity index 62% rename from crates/cuda-driver/src/mtp_original_prefill/original_mtp_prefill.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/original_mtp_prefill.rs index ac1b2c41..b4a3866b 100644 --- a/crates/cuda-driver/src/mtp_original_prefill/original_mtp_prefill.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/original_mtp_prefill.rs @@ -1,5 +1,5 @@ -//! Groups the submodules `block_commands`, `kernel_commands`, `original_mtp_prefill_close` and 4 more. -//! Split out of `prefill` to keep its files under the line limit. +//! Root of the MTP prefill recorder: declares the submodules that record block, kernel and projection commands, +//! walk the operands, run and settle the command list, and close the prefill. use super::{ A, Args, BufferHandle, Cmd, CompletedDraftKv, Context, DeviceBuffer, DraftKvFallback, DraftKvOutcome, @@ -10,21 +10,13 @@ use super::{ WIDTHS, combine, fastdiv, q8_bytes, symbols, zero_bytes, }; -#[path = "original_mtp_prefill/block_commands.rs"] mod block_commands; -#[path = "original_mtp_prefill/kernel_commands.rs"] mod kernel_commands; -#[path = "original_mtp_prefill/original_mtp_prefill_close.rs"] mod original_mtp_prefill_close; -#[path = "original_mtp_prefill/projection_commands.rs"] mod projection_commands; -#[path = "original_mtp_prefill/record_operands.rs"] mod record_operands; -#[path = "original_mtp_prefill/record_walk.rs"] mod record_walk; -#[path = "original_mtp_prefill/run_and_settle.rs"] mod run_and_settle; -#[allow(unused_imports)] use record_operands::{ Admit, AppendBlock, Block, Call, GrBufs, KernelAt, KernelShape, PageRuns, ProjectionAddresses, ProjectionDims, Stage, Staged, WEIGHT_EXTENTS, diff --git a/crates/cuda-driver/src/mtp_original_prefill/original_mtp_prefill/block_commands.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/original_mtp_prefill/block_commands.rs similarity index 100% rename from crates/cuda-driver/src/mtp_original_prefill/original_mtp_prefill/block_commands.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/original_mtp_prefill/block_commands.rs diff --git a/crates/cuda-driver/src/mtp_original_prefill/original_mtp_prefill/kernel_commands.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/original_mtp_prefill/kernel_commands.rs similarity index 90% rename from crates/cuda-driver/src/mtp_original_prefill/original_mtp_prefill/kernel_commands.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/original_mtp_prefill/kernel_commands.rs index ab9e16ef..f9a11034 100644 --- a/crates/cuda-driver/src/mtp_original_prefill/original_mtp_prefill/kernel_commands.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/original_mtp_prefill/kernel_commands.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalMtpPrefill`: `new`, `sealed_assets`, `open`, `load_modules` and 10 more. -//! Split out of `original_mtp_prefill` to keep its files under the line limit. +//! Bring-up and kernel-command plumbing of OriginalMtpPrefill: loads the five sealed PTX assets, allocates scratch and +//! status words, and offers the kernel/finite command builders plus the weight and scratch alias checks. use super::{ A, Args, BufferHandle, Cmd, Context, DeviceBuffer, ENTRIES, Error, FLAG_WORDS, KernelAt, KernelShape, Mod, @@ -26,11 +26,11 @@ impl<'ctx> OriginalMtpPrefill<'ctx> { } fn sealed_assets() -> Result<[&'static [u8]; 5]> { let assets = [ - include_bytes!("../../mtp_original_prefill.ptx").as_slice(), - include_bytes!("../../mtp_original_prefill_embedding.ptx").as_slice(), - include_bytes!("../../mtp_original_prefill_quant.ptx").as_slice(), - include_bytes!("../../mtp_original_prefill_mmq.ptx").as_slice(), - include_bytes!("../../mtp_original_prefill_fixup.ptx").as_slice(), + include_bytes!("../../../../mtp_original_prefill.ptx").as_slice(), + include_bytes!("../../../../mtp_original_prefill_embedding.ptx").as_slice(), + include_bytes!("../../../../mtp_original_prefill_quant.ptx").as_slice(), + include_bytes!("../../../../mtp_original_prefill_mmq.ptx").as_slice(), + include_bytes!("../../../../mtp_original_prefill_fixup.ptx").as_slice(), ]; if assets.iter().any(|a| a.windows(8).any(|w| w == b"UNSEALED")) { return Err(Error::UnsupportedQwenOperation); diff --git a/crates/cuda-driver/src/mtp_original_prefill/original_mtp_prefill/original_mtp_prefill_close.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/original_mtp_prefill/original_mtp_prefill_close.rs similarity index 90% rename from crates/cuda-driver/src/mtp_original_prefill/original_mtp_prefill/original_mtp_prefill_close.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/original_mtp_prefill/original_mtp_prefill_close.rs index 0c5ad030..97bdbc10 100644 --- a/crates/cuda-driver/src/mtp_original_prefill/original_mtp_prefill/original_mtp_prefill_close.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/original_mtp_prefill/original_mtp_prefill_close.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalMtpPrefill`: `close`, `close_inner`, `close_module`, `release_buffer`. -//! Split out of `original_mtp_prefill` to keep its files under the line limit. +//! Close of OriginalMtpPrefill: unloads the kernel modules and releases the status and scratch buffers, keeping the +//! first error. use super::{Context, DeviceBuffer, Error, Mod, OriginalMtpPrefill, Result, combine}; diff --git a/crates/cuda-driver/src/mtp_original_prefill/original_mtp_prefill/projection_commands.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/original_mtp_prefill/projection_commands.rs similarity index 97% rename from crates/cuda-driver/src/mtp_original_prefill/original_mtp_prefill/projection_commands.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/original_mtp_prefill/projection_commands.rs index 8ef557dd..7c88bd82 100644 --- a/crates/cuda-driver/src/mtp_original_prefill/original_mtp_prefill/projection_commands.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/original_mtp_prefill/projection_commands.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalMtpPrefill`: `project`, `project_launch`, `project_tile`, `project_grid` and 6 more. -//! Split out of `original_mtp_prefill` to keep its files under the line limit. +//! Projection command builder of OriginalMtpPrefill: picks the tile width and stream-k grid, quantizes and scans the +//! activations, and enqueues the projection kernel and, when needed, the fixup kernel. use super::{ A, Cmd, Error, KernelAt, KernelShape, OriginalMtpPrefill, ProjectionAddresses, ProjectionDims, Region, Result, diff --git a/crates/cuda-driver/src/mtp_original_prefill/original_mtp_prefill/record_operands.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/original_mtp_prefill/record_operands.rs similarity index 100% rename from crates/cuda-driver/src/mtp_original_prefill/original_mtp_prefill/record_operands.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/original_mtp_prefill/record_operands.rs diff --git a/crates/cuda-driver/src/mtp_original_prefill/original_mtp_prefill/record_walk.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/original_mtp_prefill/record_walk.rs similarity index 98% rename from crates/cuda-driver/src/mtp_original_prefill/original_mtp_prefill/record_walk.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/original_mtp_prefill/record_walk.rs index eb941c7d..f57d94bd 100644 --- a/crates/cuda-driver/src/mtp_original_prefill/original_mtp_prefill/record_walk.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/original_mtp_prefill/record_walk.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalMtpPrefill`: `record`, `record_call`, `admit`, `fallback_for` and 16 more. -//! Functions: `weight_refs`. +//! Entry point of the original MTP prefill: records the draft KV of a row range into the draft ring, admitting the +//! call, staging weights with disjointness proofs, walking the blocks, and reading back the changed pages. use super::{ Admit, AppendBlock, Block, BufferHandle, Call, CompletedDraftKv, DeviceBuffer, DraftKvFallback, DraftKvOutcome, diff --git a/crates/cuda-driver/src/mtp_original_prefill/original_mtp_prefill/run_and_settle.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/original_mtp_prefill/run_and_settle.rs similarity index 96% rename from crates/cuda-driver/src/mtp_original_prefill/original_mtp_prefill/run_and_settle.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/original_mtp_prefill/run_and_settle.rs index 006662cb..eeb6b2ac 100644 --- a/crates/cuda-driver/src/mtp_original_prefill/original_mtp_prefill/run_and_settle.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/original_mtp_prefill/run_and_settle.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalMtpPrefill`: `run`, `checked_status`, `mark_run_failed`, `run_error` and 4 more. -//! Methods of `RunJob`: `new`. Functions: `status_word`. Defines `StatusRead`, `RunJob`, `Settled`. +//! Executes one recorded MTP prefill command list on the device and settles it: uploads staging data, launches every +//! kernel/copy/GEMM, waits on stream and device, reads back the status words and poisons the prefill on failure. use super::{ BufferHandle, Cmd, Error, FLAG_WORDS, NativeBatchWorkspace, OriginalMtpPrefill, OriginalPromptRows, diff --git a/crates/cuda-driver/src/mtp_original_prefill/original_mtp_prefill_drop.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/original_mtp_prefill_drop.rs similarity index 54% rename from crates/cuda-driver/src/mtp_original_prefill/original_mtp_prefill_drop.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/original_mtp_prefill_drop.rs index c68af9d7..79eb84cc 100644 --- a/crates/cuda-driver/src/mtp_original_prefill/original_mtp_prefill_drop.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/original_mtp_prefill_drop.rs @@ -1,5 +1,4 @@ -//! Implements `Drop for OriginalMtpPrefill`. -//! Split out of `prefill` to keep its files under the line limit. +//! Drop of OriginalMtpPrefill: closes the prefill (releasing its device buffers and modules) on a best-effort basis. use super::OriginalMtpPrefill; diff --git a/crates/cuda-driver/src/mtp_original_prefill_ffi.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/prefill_abi.rs similarity index 100% rename from crates/cuda-driver/src/mtp_original_prefill_ffi.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/prefill_abi.rs diff --git a/crates/cuda-driver/src/mtp_original_prefill/region.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/region.rs similarity index 91% rename from crates/cuda-driver/src/mtp_original_prefill/region.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/region.rs index 6d43ef26..b8b9297c 100644 --- a/crates/cuda-driver/src/mtp_original_prefill/region.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/region.rs @@ -1,5 +1,5 @@ -//! Methods of `Region`: `new`, `per_row`, `widths`, `handle` and 1 more. Methods of `Context`: `original_mtp_prefill`. -//! Split out of `prefill` to keep its files under the line limit. +//! The scratch Region of the MTP prefill: carves one device buffer into 20 aligned per-row roles for a row batch +//! and hands out bounds-checked sub-handles; also the Context entry point original_mtp_prefill. use super::{BufferHandle, Context, Error, OriginalMtpPrefill, Region, Result, aligned, q8_bytes}; diff --git a/crates/cuda-driver/src/mtp_original_scalar_prefill.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar.rs similarity index 90% rename from crates/cuda-driver/src/mtp_original_scalar_prefill.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar.rs index d49b6210..87a199e5 100644 --- a/crates/cuda-driver/src/mtp_original_scalar_prefill.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar.rs @@ -10,20 +10,16 @@ use super::{ TAIL_ENTRIES, abi, aligned, checked, combine, ring_state, zero_bytes, }; #[allow(unsafe_code)] -#[path = "mtp_original_scalar_ffi.rs"] mod scalar_abi; use crate::{OriginalGpuStream, OriginalGraphKey, OriginalGraphRegistry, OriginalGraphResources, OriginalStreamKind}; use abi::LaunchShape; use scalar_abi::{Arg, Arguments, Module}; -#[path = "mtp_original_scalar_weights.rs"] mod retained_weights; pub use retained_weights::OriginalMtpRetainedScalarWeights; #[allow(unsafe_code)] -#[path = "mtp_original_scalar_mapped.rs"] mod mapped_records; use std::cell::RefCell; #[allow(unsafe_code)] -#[path = "mtp_original_physical_layout.rs"] mod physical_layout; struct OriginalLayoutSetup<'ctx> { layout: physical_layout::Layout, @@ -77,7 +73,6 @@ struct Scratch { bytes: usize, } -#[path = "mtp_original_full_forward.rs"] mod full_forward; pub(crate) use full_forward::session_assets_sealed; pub use full_forward::{ @@ -129,16 +124,11 @@ pub struct OriginalMtpScalarPrefill<'ctx> { has_pending: bool, } -#[path = "mtp_original_scalar_graph.rs"] mod graph; #[cfg(test)] -#[path = "mtp_original_scalar_short_gpu.rs"] mod short_prompt_gpu; -#[path = "mtp_original_scalar_prefill/graph_resources_original_graph_resources.rs"] mod graph_resources_original_graph_resources; -#[path = "mtp_original_scalar_prefill/original_mtp_scalar_prefill.rs"] mod original_mtp_scalar_prefill; -#[path = "mtp_original_scalar_prefill/original_mtp_scalar_prefill_drop.rs"] mod original_mtp_scalar_prefill_drop; diff --git a/crates/cuda-driver/src/mtp_original_full_forward.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward.rs similarity index 91% rename from crates/cuda-driver/src/mtp_original_full_forward.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward.rs index b931bff9..66dc0382 100644 --- a/crates/cuda-driver/src/mtp_original_full_forward.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward.rs @@ -13,15 +13,11 @@ use super::{ #[cfg(test)] use super::TAIL_ENTRIES; #[allow(unsafe_code)] -#[path = "mtp_original_full_ffi.rs"] mod full_abi; use full_abi::{Arg as F, Arguments as FA, Module as FM}; #[allow(unsafe_code)] -#[path = "mtp_original_full_mapped.rs"] mod full_mapped; -#[path = "mtp_original_full_head_dispatch.rs"] mod head_dispatch; -#[path = "mtp_original_full_symbols.rs"] mod symbols; use crate::mtp_dense_kv::original_int8::abi::LaunchShape; use crate::native_head::OriginalMtpNativeEmbedding; @@ -200,17 +196,13 @@ pub struct OriginalMtpStepOutput { pub probability: f32, } -#[path = "mtp_original_full_drafter.rs"] mod full_drafter; -#[path = "mtp_original_full_round.rs"] pub(crate) mod full_round; pub use full_drafter::{CompletedOriginalMtpDraft, OriginalMtpDrafter}; pub use full_round::OriginalMtpDraftProgram; -#[path = "mtp_original_session.rs"] mod session_coupling; pub(crate) use session_coupling::session_assets_sealed; -pub use session_coupling::{OriginalMtpRopeForm, OriginalMtpSessionPlan, OriginalMtpSessionResources}; #[cfg(test)] mod role_map_tests { @@ -324,37 +316,21 @@ mod role_map_tests { } } -#[path = "mtp_original_full_forward/context.rs"] mod context; -#[path = "mtp_original_full_forward/full_owned.rs"] mod full_owned; mod mtp_original_check_batch_program; mod mtp_original_full_init; -#[path = "mtp_original_full_forward/original_mtp_full_forward.rs"] mod original_mtp_full_forward; -#[path = "mtp_original_full_forward/original_mtp_retained_prefix.rs"] mod original_mtp_retained_prefix; -#[path = "mtp_original_full_forward/validate_scalar_prefix.rs"] mod validate_scalar_prefix; -#[allow(unused_imports)] use validate_scalar_prefix::chain_mtp_assets; -#[allow(unused_imports)] use validate_scalar_prefix::daily_mtp; -#[allow(unused_imports)] use validate_scalar_prefix::fixed_entry; -#[allow(unused_imports)] use validate_scalar_prefix::mmvf_block; -#[allow(unused_imports)] use validate_scalar_prefix::push; -#[allow(unused_imports)] use validate_scalar_prefix::validate_scalar_prefix; -#[path = "mtp_original_full_forward/context_original_mtp_shared_layout.rs"] mod context_original_mtp_shared_layout; -#[path = "mtp_original_full_forward/full_forward_prefix_program.rs"] mod full_forward_prefix_program; -#[path = "mtp_original_full_forward/matrix_vector_buffers_and_shape.rs"] mod matrix_vector_buffers_and_shape; -#[path = "mtp_original_full_forward/original_mtp_forward_program.rs"] mod original_mtp_forward_program; -#[path = "mtp_original_full_forward/original_mtp_forward_program_original_graph.rs"] mod original_mtp_forward_program_original_graph; diff --git a/crates/cuda-driver/src/mtp_original_full_forward/context.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/context.rs similarity index 76% rename from crates/cuda-driver/src/mtp_original_full_forward/context.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/context.rs index 0cd399b1..b0006624 100644 --- a/crates/cuda-driver/src/mtp_original_full_forward/context.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/context.rs @@ -1,5 +1,4 @@ -//! Methods of `Context`: `original_mtp_full_forward`. -//! Split out of `full_forward` to keep its files under the line limit. +//! Context entry point original_mtp_full_forward: builds the full-forward MTP drafter program from retained weights. use super::{Context, OriginalMtpFullForward, OriginalMtpRetainedFullWeights, Rc, Result}; diff --git a/crates/cuda-driver/src/mtp_original_full_forward/context_original_mtp_shared_layout.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/context_original_mtp_shared_layout.rs similarity index 93% rename from crates/cuda-driver/src/mtp_original_full_forward/context_original_mtp_shared_layout.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/context_original_mtp_shared_layout.rs index 7c451e18..7a724d1c 100644 --- a/crates/cuda-driver/src/mtp_original_full_forward/context_original_mtp_shared_layout.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/context_original_mtp_shared_layout.rs @@ -1,5 +1,5 @@ -//! Methods of `Context`: `original_mtp_shared_layout`, `admit_layout_charge`, `original_mtp_shared_layout_device_byt... -//! Functions: `shared_layout_charge`, `layout_setup`, `ring_assets_sealed`. +//! Context constructors for the shared Original MTP layout: one device arena used by the scalar prefill and the +//! full forward, with its budget charge, admission and sealed-PTX checks; _with_ring also builds the ring state. use super::{ Context, Error, MtpOriginalInt8, OriginalLayoutSetup, OriginalMtpFullForward, OriginalMtpRetainedFullWeights, @@ -47,9 +47,9 @@ fn layout_setup<'ctx>( fn ring_assets_sealed() -> Result<()> { OriginalMtpScalarPrefill::assets_ready()?; for ptx in [ - include_bytes!("../mtp_original_tail.ptx").as_slice(), - include_bytes!("../mtp_original_kv.ptx").as_slice(), - include_bytes!("../qsa_native_decode.ptx").as_slice(), + include_bytes!("../../../../../mtp_original_tail.ptx").as_slice(), + include_bytes!("../../../../../mtp_original_kv.ptx").as_slice(), + include_bytes!("../../../../../qsa_native_decode.ptx").as_slice(), ] { if ptx.windows(8).any(|w| w == b"UNSEALED") { return Err(Error::UnsupportedQwenOperation); diff --git a/crates/cuda-driver/src/mtp_original_full_ffi.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_abi.rs similarity index 98% rename from crates/cuda-driver/src/mtp_original_full_ffi.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_abi.rs index 0fed49e3..7a6ec352 100644 --- a/crates/cuda-driver/src/mtp_original_full_ffi.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_abi.rs @@ -98,7 +98,6 @@ impl Copy2D { } } #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] -#[path = "mtp_original_full_ffi/driver_backed.rs"] mod driver_backed; #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] pub(crate) use driver_backed::Module; @@ -149,5 +148,5 @@ impl Module { } } #[cfg(test)] -#[path = "mtp_original_full_ffi/tests.rs"] +#[path = "../../../../../mtp_original_full_ffi/tests.rs"] mod tests; diff --git a/crates/cuda-driver/src/mtp_original_full_ffi/driver_backed.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_abi/driver_backed.rs similarity index 100% rename from crates/cuda-driver/src/mtp_original_full_ffi/driver_backed.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_abi/driver_backed.rs diff --git a/crates/cuda-driver/src/mtp_original_full_drafter.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_drafter.rs similarity index 94% rename from crates/cuda-driver/src/mtp_original_full_drafter.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_drafter.rs index ab40269d..404d903e 100644 --- a/crates/cuda-driver/src/mtp_original_full_drafter.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_drafter.rs @@ -67,7 +67,6 @@ struct AdmittedRound { policy_key: [u32; 23], } -#[path = "original_mtp_round_lifecycle.rs"] mod round_lifecycle; pub struct CompletedOriginalMtpDraft<'ctx> { @@ -97,9 +96,6 @@ pub struct OriginalMtpDrafter<'ctx> { in_flight: Option>, } -#[path = "mtp_original_full_drafter/completed_original_mtp_draft.rs"] mod completed_original_mtp_draft; -#[path = "mtp_original_full_drafter/original_mtp_drafter.rs"] mod original_mtp_drafter; -#[path = "mtp_original_full_drafter/original_mtp_drafter_from_verifier.rs"] mod original_mtp_drafter_from_verifier; diff --git a/crates/cuda-driver/src/mtp_original_full_drafter/completed_original_mtp_draft.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_drafter/completed_original_mtp_draft.rs similarity index 85% rename from crates/cuda-driver/src/mtp_original_full_drafter/completed_original_mtp_draft.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_drafter/completed_original_mtp_draft.rs index 0943b1f4..f6ff6031 100644 --- a/crates/cuda-driver/src/mtp_original_full_drafter/completed_original_mtp_draft.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_drafter/completed_original_mtp_draft.rs @@ -1,5 +1,5 @@ -//! Methods of `CompletedOriginalMtpDraft`: `ids`, `probabilities`, `count`, `final_snapshot` and 4 more. -//! Split out of `full_drafter` to keep its files under the line limit. +//! Read accessors of a finished MTP draft (ids, probabilities, count, positions, snapshot) and the check that it is +//! still the current snapshot of the ring it was drafted on. use super::{CompletedOriginalMtpDraft, Error, MtpInt8Snapshot, MtpOriginalInt8, Rc, Result}; diff --git a/crates/cuda-driver/src/mtp_original_full_drafter/original_mtp_drafter.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_drafter/original_mtp_drafter.rs similarity index 59% rename from crates/cuda-driver/src/mtp_original_full_drafter/original_mtp_drafter.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_drafter/original_mtp_drafter.rs index ee82c682..beb8adf7 100644 --- a/crates/cuda-driver/src/mtp_original_full_drafter/original_mtp_drafter.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_drafter/original_mtp_drafter.rs @@ -1,5 +1,5 @@ -//! Groups the submodules `original_mtp_drafter_chain_gate`, `original_mtp_drafter_finish_chain`, `original_mtp_draft... -//! Split out of `full_drafter` to keep its files under the line limit. +//! Root of OriginalMtpDrafter: declares its submodules (construction, round launch, chain finishing, pipelined chain, +//! chain gate, keep-bank) and holds their shared imports. use super::{ AcceptedWindow, AdmittedRound, CompletedOriginalMtpDraft, Context, DirectVerifierRows, DraftKvOutcome, @@ -10,15 +10,9 @@ use super::{ Result, RoundMode, SamplerParams, ScalarDraftKvSources, combine, validate_scalar_prefix, }; -#[path = "original_mtp_drafter/original_mtp_drafter_chain_gate.rs"] mod original_mtp_drafter_chain_gate; -#[path = "original_mtp_drafter/original_mtp_drafter_finish_chain.rs"] mod original_mtp_drafter_finish_chain; -#[path = "original_mtp_drafter/original_mtp_drafter_pipelined_chain.rs"] mod original_mtp_drafter_pipelined_chain; -#[path = "original_mtp_drafter/original_mtp_drafter_keep_bank.rs"] mod original_mtp_drafter_keep_bank; -#[path = "original_mtp_drafter/original_mtp_drafter_launch_rounds.rs"] mod original_mtp_drafter_launch_rounds; -#[path = "original_mtp_drafter/original_mtp_drafter_new_draft.rs"] mod original_mtp_drafter_new_draft; diff --git a/crates/cuda-driver/src/mtp_original_full_drafter/original_mtp_drafter/original_mtp_drafter_chain_gate.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_drafter/original_mtp_drafter/original_mtp_drafter_chain_gate.rs similarity index 100% rename from crates/cuda-driver/src/mtp_original_full_drafter/original_mtp_drafter/original_mtp_drafter_chain_gate.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_drafter/original_mtp_drafter/original_mtp_drafter_chain_gate.rs diff --git a/crates/cuda-driver/src/mtp_original_full_drafter/original_mtp_drafter/original_mtp_drafter_finish_chain.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_drafter/original_mtp_drafter/original_mtp_drafter_finish_chain.rs similarity index 98% rename from crates/cuda-driver/src/mtp_original_full_drafter/original_mtp_drafter/original_mtp_drafter_finish_chain.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_drafter/original_mtp_drafter/original_mtp_drafter_finish_chain.rs index 2f82f982..fa8502cb 100644 --- a/crates/cuda-driver/src/mtp_original_full_drafter/original_mtp_drafter/original_mtp_drafter_finish_chain.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_drafter/original_mtp_drafter/original_mtp_drafter_finish_chain.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalMtpDrafter`: `finish_inner`, `finish_chain`, `fail_if_poisoned`, `finish_first_step` and 10 m... -//! Functions: `chain_key`. Defines `ChainPlan`, `ChainStepAt`, `ChainGraphs`. +//! Finishing half of an MTP draft: reads back the first round graph, runs the chain steps that follow while the host +//! works, closes the ring mutation, and releases verifier bindings, records the scalar prefill and closes the drafter. use super::{ CompletedOriginalMtpDraft, Context, DraftKvOutcome, Error, InFlightDraft, MTP_ORIGINAL_MAX_CELLS, MtpInt8Snapshot, diff --git a/crates/cuda-driver/src/mtp_original_full_drafter/original_mtp_drafter/original_mtp_drafter_keep_bank.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_drafter/original_mtp_drafter/original_mtp_drafter_keep_bank.rs similarity index 100% rename from crates/cuda-driver/src/mtp_original_full_drafter/original_mtp_drafter/original_mtp_drafter_keep_bank.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_drafter/original_mtp_drafter/original_mtp_drafter_keep_bank.rs diff --git a/crates/cuda-driver/src/mtp_original_full_drafter/original_mtp_drafter/original_mtp_drafter_launch_rounds.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_drafter/original_mtp_drafter/original_mtp_drafter_launch_rounds.rs similarity index 98% rename from crates/cuda-driver/src/mtp_original_full_drafter/original_mtp_drafter/original_mtp_drafter_launch_rounds.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_drafter/original_mtp_drafter/original_mtp_drafter_launch_rounds.rs index 55f8fbd0..23017647 100644 --- a/crates/cuda-driver/src/mtp_original_full_drafter/original_mtp_drafter/original_mtp_drafter_launch_rounds.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_drafter/original_mtp_drafter/original_mtp_drafter_launch_rounds.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalMtpDrafter`: `launch_inner`, `launch_prepare`, `launch_record`, `launch_enqueue` and 9 more. -//! Split out of `original_mtp_drafter` to keep its files under the line limit. +//! Launching half of an MTP draft: admits the request against the ring and prior state, stages the first residual, +//! records the round graph once and enqueues it on the draft stream; launch_inner leaves the draft in flight. use super::{ AcceptedWindow, AdmittedRound, Context, DirectVerifierRows, DraftRoundRequest, DraftSampling, DraftTarget, Error, diff --git a/crates/cuda-driver/src/mtp_original_full_drafter/original_mtp_drafter/original_mtp_drafter_new_draft.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_drafter/original_mtp_drafter/original_mtp_drafter_new_draft.rs similarity index 94% rename from crates/cuda-driver/src/mtp_original_full_drafter/original_mtp_drafter/original_mtp_drafter_new_draft.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_drafter/original_mtp_drafter/original_mtp_drafter_new_draft.rs index 184dd67c..98d9540f 100644 --- a/crates/cuda-driver/src/mtp_original_full_drafter/original_mtp_drafter/original_mtp_drafter_new_draft.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_drafter/original_mtp_drafter/original_mtp_drafter_new_draft.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalMtpDrafter`: `new`, `unregistered`, `validate_context`, `metadata_bytes` and 3 more. -//! Split out of `original_mtp_drafter` to keep its files under the line limit. +//! Construction and validation of OriginalMtpDrafter from a full forward plus a scalar prefill, and the blocking +//! draft and draft_first entry points that launch and finish a draft in one call. use super::{ AcceptedWindow, CompletedOriginalMtpDraft, Context, DraftRoundRequest, DraftSampling, DraftTarget, Error, diff --git a/crates/cuda-driver/src/mtp_original_full_drafter/original_mtp_drafter/original_mtp_drafter_pipelined_chain.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_drafter/original_mtp_drafter/original_mtp_drafter_pipelined_chain.rs similarity index 100% rename from crates/cuda-driver/src/mtp_original_full_drafter/original_mtp_drafter/original_mtp_drafter_pipelined_chain.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_drafter/original_mtp_drafter/original_mtp_drafter_pipelined_chain.rs diff --git a/crates/cuda-driver/src/mtp_original_full_drafter/original_mtp_drafter_from_verifier.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_drafter/original_mtp_drafter_from_verifier.rs similarity index 96% rename from crates/cuda-driver/src/mtp_original_full_drafter/original_mtp_drafter_from_verifier.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_drafter/original_mtp_drafter_from_verifier.rs index 02690c5b..798aa020 100644 --- a/crates/cuda-driver/src/mtp_original_full_drafter/original_mtp_drafter_from_verifier.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_drafter/original_mtp_drafter_from_verifier.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalMtpFullPolicy`: `for_capture`, `capture_key`, `validate_selected`. -//! Methods of `OriginalMtpDrafter`: `draft_inner`, `launch_from_verifier`, `finish_from_verifier`, `draft_in_flight`... +//! The verifier-coupled drafting API: launch, finish and draft_from_verifier over the verifier window, with Drop +//! of the drafter and the capture-key and validation rules of OriginalMtpFullPolicy that key the cached round graphs. use super::{ AcceptedWindow, CompletedOriginalMtpDraft, DraftKvPolicy, DraftRoundRequest, DraftSampling, DraftTarget, Error, diff --git a/crates/cuda-driver/src/original_mtp_round_lifecycle.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_drafter/round_lifecycle.rs similarity index 94% rename from crates/cuda-driver/src/original_mtp_round_lifecycle.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_drafter/round_lifecycle.rs index da815c17..f2cd2830 100644 --- a/crates/cuda-driver/src/original_mtp_round_lifecycle.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_drafter/round_lifecycle.rs @@ -82,11 +82,7 @@ struct OriginalMtpResumePlan { slots: usize, } -#[path = "original_mtp_round_lifecycle/original_mtp_prefill_plan.rs"] mod original_mtp_prefill_plan; -#[allow(unused_imports)] use original_mtp_prefill_plan::public_step; -#[path = "original_mtp_round_lifecycle/original_mtp_drafter.rs"] mod original_mtp_drafter; -#[path = "original_mtp_round_lifecycle/public_draft_output_copy.rs"] mod public_draft_output_copy; diff --git a/crates/cuda-driver/src/original_mtp_round_lifecycle/original_mtp_drafter.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_drafter/round_lifecycle/original_mtp_drafter.rs similarity index 98% rename from crates/cuda-driver/src/original_mtp_round_lifecycle/original_mtp_drafter.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_drafter/round_lifecycle/original_mtp_drafter.rs index b5e5214d..539e403e 100644 --- a/crates/cuda-driver/src/original_mtp_round_lifecycle/original_mtp_drafter.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_drafter/round_lifecycle/original_mtp_drafter.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalMtpDrafter`: `loaded_max_t`, `loaded_coupled`, `idle_public`, `plan_public_prefill` and 12 more. -//! Functions: `resume_copies`, `fill_public_records`. +//! Public (crate-level) lifecycle of a loaded OriginalMtpDrafter: idle, public prefill planning, KV resume copies +//! from the host pools, and the array-based draft_public / draft_first_public adapters over the graph executor. use super::{ CompletedOriginalMtpDraft, DraftSettings, Error, FM, HOST_OFFSETS, MTP_ORIGINAL_MAX_CELLS, MTP_ORIGINAL_WINDOW, diff --git a/crates/cuda-driver/src/original_mtp_round_lifecycle/original_mtp_prefill_plan.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_drafter/round_lifecycle/original_mtp_prefill_plan.rs similarity index 96% rename from crates/cuda-driver/src/original_mtp_round_lifecycle/original_mtp_prefill_plan.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_drafter/round_lifecycle/original_mtp_prefill_plan.rs index c80d797b..0896da56 100644 --- a/crates/cuda-driver/src/original_mtp_round_lifecycle/original_mtp_prefill_plan.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_drafter/round_lifecycle/original_mtp_prefill_plan.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalMtpPrefillPlan`: `residual`, `tokens`, `bulk_records`, `metadata_bytes` and 3 more. -//! Methods of `OriginalMtpPrefillActions`: `group_action`, `bulk_action`, `mapped_action`. +//! The public prefill plan of the MTP drafter: read access to its residual, tokens and bulk records, the per-row +//! step words, and OriginalMtpPrefillActions, the iterator that yields the device actions in order. use super::{ Error, MTP_ORIGINAL_MAX_CELLS, MtpOriginalInt8, OriginalDeviceResidual, OriginalMtpPrefillAction, diff --git a/crates/cuda-driver/src/original_mtp_round_lifecycle/public_draft_output_copy.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_drafter/round_lifecycle/public_draft_output_copy.rs similarity index 87% rename from crates/cuda-driver/src/original_mtp_round_lifecycle/public_draft_output_copy.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_drafter/round_lifecycle/public_draft_output_copy.rs index b610acc8..0d9f0ccc 100644 --- a/crates/cuda-driver/src/original_mtp_round_lifecycle/public_draft_output_copy.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_drafter/round_lifecycle/public_draft_output_copy.rs @@ -1,5 +1,4 @@ -//! Methods of `OriginalMtpDrafter`: `copy_public_draft_output`. -//! Split out of `round_lifecycle` to keep its files under the line limit. +//! Copies a completed draft into the caller public arrays (ids and optional probabilities), zeroing the unused tail. use super::{CompletedOriginalMtpDraft, Error, OriginalMtpDrafter, Result}; diff --git a/crates/cuda-driver/src/mtp_original_full_forward/full_forward_prefix_program.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_forward_prefix_program.rs similarity index 69% rename from crates/cuda-driver/src/mtp_original_full_forward/full_forward_prefix_program.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_forward_prefix_program.rs index 674d951c..564de4d5 100644 --- a/crates/cuda-driver/src/mtp_original_full_forward/full_forward_prefix_program.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_forward_prefix_program.rs @@ -1,5 +1,5 @@ -//! Groups the submodules `full_forward_program_alias_checks`, `original_mtp_full_forward`. -//! Split out of `full_forward` to keep its files under the line limit. +//! Root of the full-forward program builder: separates the alias-checking program assembly from the prefix command +//! recording, and holds their shared imports. use super::{ Arg, Arguments, BufferHandle, Context, DeviceBuffer, DraftKvPolicy, EmbeddingKind, Error, F, FA, ForwardPrefix, @@ -10,7 +10,5 @@ use super::{ ScalarPrefixPlan, TAIL_FLAGS, TailArgs, abi, checked, full_abi, validate_scalar_prefix, }; -#[path = "full_forward_prefix_program/full_forward_program_alias_checks.rs"] mod full_forward_program_alias_checks; -#[path = "full_forward_prefix_program/original_mtp_full_forward.rs"] mod original_mtp_full_forward; diff --git a/crates/cuda-driver/src/mtp_original_full_forward/full_forward_prefix_program/full_forward_program_alias_checks.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_forward_prefix_program/full_forward_program_alias_checks.rs similarity index 97% rename from crates/cuda-driver/src/mtp_original_full_forward/full_forward_prefix_program/full_forward_program_alias_checks.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_forward_prefix_program/full_forward_program_alias_checks.rs index 5c7f5e27..b5fc131b 100644 --- a/crates/cuda-driver/src/mtp_original_full_forward/full_forward_prefix_program/full_forward_program_alias_checks.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_forward_prefix_program/full_forward_program_alias_checks.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalMtpFullForward`: `program`, `program_commands`, `program_addrs`, `program_prefix` and 10 more. -//! Split out of `full_forward_prefix_program` to keep its files under the line limit. +//! Builds the OriginalMtpForwardProgram of one draft step (prefix, tail commands, addresses, owners) and refuses any +//! device buffer of the full-forward scratch that aliases a weight, scalar or ring buffer it must not overlap. use super::super::mtp_original_check_batch_program::{CheckBatchModules, merge_prefix, merge_tail}; use super::{ diff --git a/crates/cuda-driver/src/mtp_original_full_forward/full_forward_prefix_program/original_mtp_full_forward.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_forward_prefix_program/original_mtp_full_forward.rs similarity index 89% rename from crates/cuda-driver/src/mtp_original_full_forward/full_forward_prefix_program/original_mtp_full_forward.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_forward_prefix_program/original_mtp_full_forward.rs index 97e12e07..5cfc4199 100644 --- a/crates/cuda-driver/src/mtp_original_full_forward/full_forward_prefix_program/original_mtp_full_forward.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_forward_prefix_program/original_mtp_full_forward.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalMtpFullForward`: `prefix_commands`. -//! Split out of `full_forward_prefix_program` to keep its files under the line limit. +//! Builds the full=true T1 prefix command list of the draft step from the retained model roles; it only records +//! commands and launches nothing. Its row, part and embedding helpers are the prefix_parts and prefix_rows submodules. use super::{ Arg, BufferHandle, DeviceBuffer, DraftKvPolicy, EmbeddingKind, Error, LaunchShape, MTP_ORIGINAL_MAX_CELLS, diff --git a/crates/cuda-driver/src/mtp_original_full_forward/full_forward_prefix_program/prefix_parts.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_forward_prefix_program/original_mtp_full_forward/prefix_parts.rs similarity index 100% rename from crates/cuda-driver/src/mtp_original_full_forward/full_forward_prefix_program/prefix_parts.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_forward_prefix_program/original_mtp_full_forward/prefix_parts.rs diff --git a/crates/cuda-driver/src/mtp_original_full_forward/full_forward_prefix_program/prefix_rows.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_forward_prefix_program/original_mtp_full_forward/prefix_rows.rs similarity index 100% rename from crates/cuda-driver/src/mtp_original_full_forward/full_forward_prefix_program/prefix_rows.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_forward_prefix_program/original_mtp_full_forward/prefix_rows.rs diff --git a/crates/cuda-driver/src/mtp_original_full_mapped.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_mapped.rs similarity index 100% rename from crates/cuda-driver/src/mtp_original_full_mapped.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_mapped.rs diff --git a/crates/cuda-driver/src/mtp_original_full_forward/full_owned.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_owned.rs similarity index 97% rename from crates/cuda-driver/src/mtp_original_full_forward/full_owned.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_owned.rs index 7ab839ac..f4594285 100644 --- a/crates/cuda-driver/src/mtp_original_full_forward/full_owned.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_owned.rs @@ -1,5 +1,5 @@ -//! Methods of `FullOwned`: `validate`, `validate_original`, `handle`, `original_handle` and 12 more. -//! Implements `Drop for FullOwned`. Functions: `extra_slot`. +//! Resource ownership of FullOwned, the scratch bank of the full forward: validation, role handles and addresses +//! inside the shared or private arena, ordered close of modules, mapped memory, scratch and extra banks, and Drop. use super::{ BufferHandle, CHUNKS, Context, DeviceBuffer, Error, FM, FullOwned, MtpOriginalInt8, OriginalMtpScalarPrefill, Rc, diff --git a/crates/cuda-driver/src/mtp_original_full_round.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_round.rs similarity index 91% rename from crates/cuda-driver/src/mtp_original_full_round.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_round.rs index ba6a3a62..6bef70b6 100644 --- a/crates/cuda-driver/src/mtp_original_full_round.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_round.rs @@ -112,23 +112,13 @@ mod stage_fence_tests { } } -#[path = "mtp_original_full_round/staged_source.rs"] mod staged_source; -#[allow(unused_imports)] -use staged_source::mapped_i32; -#[allow(unused_imports)] use staged_source::mtp_select; -#[path = "mtp_original_full_round/post_select.rs"] mod post_select; -#[allow(unused_imports)] use post_select::post_select; -#[path = "mtp_original_full_round/original_mtp_draft_program.rs"] mod original_mtp_draft_program; -#[path = "mtp_original_full_round/put.rs"] mod put; -#[allow(unused_imports)] +#[cfg(test)] use put::copy_rows_then_fence; -#[allow(unused_imports)] use put::overlap; -#[allow(unused_imports)] use put::put; diff --git a/crates/cuda-driver/src/mtp_original_full_round/original_mtp_draft_program.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_round/original_mtp_draft_program.rs similarity index 98% rename from crates/cuda-driver/src/mtp_original_full_round/original_mtp_draft_program.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_round/original_mtp_draft_program.rs index abe3729d..d52a37e3 100644 --- a/crates/cuda-driver/src/mtp_original_full_round/original_mtp_draft_program.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_round/original_mtp_draft_program.rs @@ -1,7 +1,6 @@ -//! Methods of `OriginalMtpDraftProgram`: `enqueue_commands`, `capture`, `capture_all`, `capture_catchup` and 17 more. -//! Split out of `full_round` to keep its files under the line limit. +//! Capture and per-round staging of OriginalMtpDraftProgram: replays the coupled stage, catch-up, forward program and +//! post commands into a graph, stages each round or chain step into the mapped records, and reads the step output back. -#[allow(unused_imports)] use super::super::mtp_original_check_batch_program::launch_prefix_command; use super::{ Error, FA, FullCommand, LaunchShape, MTP_ORIGINAL_MAX_CELLS, NativeHeadSelection, OriginalCapture, diff --git a/crates/cuda-driver/src/mtp_original_full_round/post_select.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_round/post_select.rs similarity index 83% rename from crates/cuda-driver/src/mtp_original_full_round/post_select.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_round/post_select.rs index aadb7817..7b449ad6 100644 --- a/crates/cuda-driver/src/mtp_original_full_round/post_select.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_round/post_select.rs @@ -1,5 +1,5 @@ -//! Functions: `post_select`. -//! Split out of `full_round` to keep its files under the line limit. +//! Builds the post-step selection command: wires the residual rows, token ids, row index and mapped readback +//! addresses of a draft step into the selection kernel launch that records the draft token and probability. use super::{ Error, FullCommand, OriginalMtpForwardProgram, Result, SelectionReadback, SelectionSource, SelectionTarget, diff --git a/crates/cuda-driver/src/mtp_original_full_round/put.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_round/put.rs similarity index 97% rename from crates/cuda-driver/src/mtp_original_full_round/put.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_round/put.rs index 293ca488..fc568fb8 100644 --- a/crates/cuda-driver/src/mtp_original_full_round/put.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_round/put.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalMtpFullForward`: `stage_first_residual`, `check_staging_window`, `check_first_repeat`, `insta... -//! Methods of `OriginalMtpDraftProgram`: `uses_direct_verifier_window`. +//! Staging of the first-round residual and verifier window for the MTP draft program: writes the mapped cell records, +//! repeats or direct-copies the completed residual rows (cross-stream fence) and rebinds a round to the verifier bank. use super::{ DirectVerifierRows, Error, F, LaunchShape, MTP_ORIGINAL_MAX_CELLS, MtpOriginalInt8, NativeHeadSelection, diff --git a/crates/cuda-driver/src/mtp_original_full_round/staged_source.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_round/staged_source.rs similarity index 98% rename from crates/cuda-driver/src/mtp_original_full_round/staged_source.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_round/staged_source.rs index ad7abda5..e60b6b83 100644 --- a/crates/cuda-driver/src/mtp_original_full_round/staged_source.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/full_round/staged_source.rs @@ -1,5 +1,5 @@ -//! Methods of `StagedSource`: `validate`. -//! Methods of `FullOwned`: `mapped_window_offset`, `validate_staged`, `validate_staged_ahead`. +//! Round and chain-step preparation of the MTP draft program (prepare_round, prepare_step, prepare_chain_step): the +//! before/after command lists, the selection kernel launch, staged-source validation and the graph-resource impl. use super::super::mtp_original_check_batch_program::merge_prefix; use super::{ diff --git a/crates/cuda-driver/src/mtp_original_full_head_dispatch.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/head_dispatch.rs similarity index 100% rename from crates/cuda-driver/src/mtp_original_full_head_dispatch.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/head_dispatch.rs diff --git a/crates/cuda-driver/src/mtp_original_full_forward/matrix_vector_buffers_and_shape.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/matrix_vector_buffers_and_shape.rs similarity index 67% rename from crates/cuda-driver/src/mtp_original_full_forward/matrix_vector_buffers_and_shape.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/matrix_vector_buffers_and_shape.rs index 69831664..dbe51f17 100644 --- a/crates/cuda-driver/src/mtp_original_full_forward/matrix_vector_buffers_and_shape.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/matrix_vector_buffers_and_shape.rs @@ -1,5 +1,5 @@ -//! Defines `MatVecBuffers`, `MatVecShape`. -//! Split out of `full_forward` to keep its files under the line limit. +//! Root of the matrix-vector planning helpers of the full forward: the MatVecBuffers and MatVecShape descriptors +//! shared by the final-GR, finite-tail and MoE block planners in its submodules. use super::{ CHUNKS, DeviceBuffer, DraftKvPolicy, Error, F, ForwardPrefix, FullCommand, LaunchShape, NativeHeadDispatch, @@ -22,11 +22,7 @@ pub(super) struct MatVecShape { rows: usize, } -#[path = "matrix_vector_buffers_and_shape/full_forward_final_gr_stages.rs"] mod full_forward_final_gr_stages; -#[path = "matrix_vector_buffers_and_shape/full_forward_finite_tail_mlp_gr.rs"] mod full_forward_finite_tail_mlp_gr; -#[path = "matrix_vector_buffers_and_shape/full_forward_moe_block_plan.rs"] mod full_forward_moe_block_plan; -#[path = "matrix_vector_buffers_and_shape/original_mtp_full_forward.rs"] mod original_mtp_full_forward; diff --git a/crates/cuda-driver/src/mtp_original_full_forward/matrix_vector_buffers_and_shape/full_forward_final_gr_stages.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/matrix_vector_buffers_and_shape/full_forward_final_gr_stages.rs similarity index 95% rename from crates/cuda-driver/src/mtp_original_full_forward/matrix_vector_buffers_and_shape/full_forward_final_gr_stages.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/matrix_vector_buffers_and_shape/full_forward_final_gr_stages.rs index bdd5e3b7..2f7d2168 100644 --- a/crates/cuda-driver/src/mtp_original_full_forward/matrix_vector_buffers_and_shape/full_forward_final_gr_stages.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/matrix_vector_buffers_and_shape/full_forward_final_gr_stages.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalMtpFullForward`: `gr_weight`, `final_gr`, `final_gr_native`, `final_gr_native_tail` and 4 more. -//! Split out of `matrix_vector_buffers_and_shape` to keep its files under the line limit. +//! Command recording for the final GR block of the MTP draft step: the native fused path, or the staged path of +//! norm, 320-column projection, 1280-column projection and 4-way reduction kernels. use super::{ Error, F, ForwardPrefix, FullCommand, LaunchShape, MatVecBuffers, MatVecShape, OriginalMtpFullForward, diff --git a/crates/cuda-driver/src/mtp_original_full_forward/matrix_vector_buffers_and_shape/full_forward_finite_tail_mlp_gr.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/matrix_vector_buffers_and_shape/full_forward_finite_tail_mlp_gr.rs similarity index 96% rename from crates/cuda-driver/src/mtp_original_full_forward/matrix_vector_buffers_and_shape/full_forward_finite_tail_mlp_gr.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/matrix_vector_buffers_and_shape/full_forward_finite_tail_mlp_gr.rs index e63ab63a..8b90b795 100644 --- a/crates/cuda-driver/src/mtp_original_full_forward/matrix_vector_buffers_and_shape/full_forward_finite_tail_mlp_gr.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/matrix_vector_buffers_and_shape/full_forward_finite_tail_mlp_gr.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalMtpFullForward`: `finite_tail`, `q8_tail`, `quant`, `mmvq` and 3 more. -//! Functions: `second_mlp_entry`. +//! Small command builders of the draft step tail: finiteness and Q8 flag checks, input quantization, the +//! quantized and float matrix-vector launches, and the fused MLP GR kernel launch with its 114 by-value words. use super::{ Error, F, ForwardPrefix, FullCommand, LaunchShape, MatVecBuffers, MatVecShape, NativeHeadDispatch, diff --git a/crates/cuda-driver/src/mtp_original_full_forward/matrix_vector_buffers_and_shape/full_forward_moe_block_plan.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/matrix_vector_buffers_and_shape/full_forward_moe_block_plan.rs similarity index 100% rename from crates/cuda-driver/src/mtp_original_full_forward/matrix_vector_buffers_and_shape/full_forward_moe_block_plan.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/matrix_vector_buffers_and_shape/full_forward_moe_block_plan.rs diff --git a/crates/cuda-driver/src/mtp_original_full_forward/matrix_vector_buffers_and_shape/original_mtp_full_forward.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/matrix_vector_buffers_and_shape/original_mtp_full_forward.rs similarity index 97% rename from crates/cuda-driver/src/mtp_original_full_forward/matrix_vector_buffers_and_shape/original_mtp_full_forward.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/matrix_vector_buffers_and_shape/original_mtp_full_forward.rs index 76af732b..45596309 100644 --- a/crates/cuda-driver/src/mtp_original_full_forward/matrix_vector_buffers_and_shape/original_mtp_full_forward.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/matrix_vector_buffers_and_shape/original_mtp_full_forward.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalMtpFullForward`: `plan`, `validate_plan`, `slot`, `slots` and 11 more. Defines `PlanBufs`. -//! `plan` records the commands of one draft step in the order of the former single function; the attention block is ... +//! Plans the commands of one draft step of OriginalMtpFullForward in the order of the former single function: +//! validation, then the attention block (Q, RoPE, windowed attention, gate, residual); MoE and tail are a sibling. use super::{ CHUNKS, DraftKvPolicy, Error, F, ForwardPrefix, FullCommand, LaunchShape, MatVecBuffers, MatVecShape, diff --git a/crates/cuda-driver/src/mtp_original_check_batch_program.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/mtp_original_check_batch_program.rs similarity index 100% rename from crates/cuda-driver/src/mtp_original_check_batch_program.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/mtp_original_check_batch_program.rs diff --git a/crates/cuda-driver/src/mtp_original_check_batch_program/gpu_tests.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/mtp_original_check_batch_program/gpu_tests.rs similarity index 100% rename from crates/cuda-driver/src/mtp_original_check_batch_program/gpu_tests.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/mtp_original_check_batch_program/gpu_tests.rs diff --git a/crates/cuda-driver/src/mtp_original_check_batch_program/tests.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/mtp_original_check_batch_program/tests.rs similarity index 100% rename from crates/cuda-driver/src/mtp_original_check_batch_program/tests.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/mtp_original_check_batch_program/tests.rs diff --git a/crates/cuda-driver/src/mtp_original_full_init.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/mtp_original_full_init.rs similarity index 100% rename from crates/cuda-driver/src/mtp_original_full_init.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/mtp_original_full_init.rs diff --git a/crates/cuda-driver/src/mtp_original_full_forward/original_mtp_forward_program.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/original_mtp_forward_program.rs similarity index 97% rename from crates/cuda-driver/src/mtp_original_full_forward/original_mtp_forward_program.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/original_mtp_forward_program.rs index fee41622..87186b95 100644 --- a/crates/cuda-driver/src/mtp_original_full_forward/original_mtp_forward_program.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/original_mtp_forward_program.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalMtpForwardProgram`: `capture`, `capture_prefix`, `capture_coupled_stage`, `capture_flag_reset... -//! Functions: `history_bytes`. +//! Capture and post-drain checks of OriginalMtpForwardProgram: replays the prefix, coupled stage, flag reset and tail +//! commands into a graph, then validates the status flags, reads the step output and stages coupled sampler state. use super::mtp_original_check_batch_program::{ CheckBatchModules, is_tail_batch, launch_prefix_command, launch_tail_batch, diff --git a/crates/cuda-driver/src/mtp_original_full_forward/original_mtp_forward_program_original_graph.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/original_mtp_forward_program_original_graph.rs similarity index 81% rename from crates/cuda-driver/src/mtp_original_full_forward/original_mtp_forward_program_original_graph.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/original_mtp_forward_program_original_graph.rs index 810646c2..92c2f637 100644 --- a/crates/cuda-driver/src/mtp_original_full_forward/original_mtp_forward_program_original_graph.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/original_mtp_forward_program_original_graph.rs @@ -1,5 +1,4 @@ -//! Implements `Sealed for OriginalMtpForwardProgram`, `OriginalGraphResources for OriginalMtpForwardProgram`. -//! Split out of `full_forward` to keep its files under the line limit. +//! Marks OriginalMtpForwardProgram as a graph resource: validates its context, tail, ring, buffers and mapped owner. use super::{Context, Error, OriginalGraphResources, OriginalMtpForwardProgram, Result, checked}; diff --git a/crates/cuda-driver/src/mtp_original_full_forward/original_mtp_full_forward.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/original_mtp_full_forward.rs similarity index 92% rename from crates/cuda-driver/src/mtp_original_full_forward/original_mtp_full_forward.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/original_mtp_full_forward.rs index bfa3cf2c..a41a8a78 100644 --- a/crates/cuda-driver/src/mtp_original_full_forward/original_mtp_full_forward.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/original_mtp_full_forward.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalMtpFullForward`: `planned_device_bytes`, `new`, `new_internal`, `allocated_bytes` and 4 more. -//! Split out of `full_forward` to keep its files under the line limit. +//! Construction and lifecycle of OriginalMtpFullForward, the tail (head, sampler) half of the MTP draft: device-byte +//! planning, new (private or shared Original layout), size accounting, context validation and close. use super::mtp_original_full_init::FullGeometry; use super::{ diff --git a/crates/cuda-driver/src/mtp_original_full_forward/original_mtp_retained_prefix.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/original_mtp_retained_prefix.rs similarity index 97% rename from crates/cuda-driver/src/mtp_original_full_forward/original_mtp_retained_prefix.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/original_mtp_retained_prefix.rs index 31f2dc11..fd6ce05f 100644 --- a/crates/cuda-driver/src/mtp_original_full_forward/original_mtp_retained_prefix.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/original_mtp_retained_prefix.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalMtpRetainedPrefix`: `from_scalar`, `native`, `validate_context`, `check_roles` and 1 more. -//! Methods of `OriginalMtpRetainedFullWeights`: `retain`, `validate_context`, `metadata_bytes`, `head_rows` and 2 more. +//! Retained model weights of the MTP draft: the prefix roles and embedding (OriginalMtpRetainedPrefix) and the full +//! set with draft head and optional vocab subset (OriginalMtpRetainedFullWeights), with extent and disjointness checks. use super::{ BufferHandle, Context, DeviceBuffer, Error, FULL_EXTENTS, FullForwardHead, OriginalMtpNativeEmbedding, diff --git a/crates/cuda-driver/src/mtp_original_session.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/session_coupling.rs similarity index 91% rename from crates/cuda-driver/src/mtp_original_session.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/session_coupling.rs index 2a91ea6a..ce4d05b2 100644 --- a/crates/cuda-driver/src/mtp_original_session.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/session_coupling.rs @@ -67,15 +67,9 @@ pub(crate) struct OriginalMtpSessionRopePlan<'ctx> { heads: usize, } -#[path = "mtp_original_session/original_mtp_session_plan.rs"] mod original_mtp_session_plan; -#[path = "mtp_original_session/original_mtp_session_resources.rs"] mod original_mtp_session_resources; -#[allow(unused_imports)] use original_mtp_session_resources::session_legacy_asset; -#[allow(unused_imports)] use original_mtp_session_resources::session_native_asset; -#[path = "mtp_original_session/session_owned_drop.rs"] mod session_owned_drop; -#[allow(unused_imports)] pub(crate) use session_owned_drop::session_assets_sealed; diff --git a/crates/cuda-driver/src/mtp_original_session/original_mtp_session_plan.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/session_coupling/original_mtp_session_plan.rs similarity index 93% rename from crates/cuda-driver/src/mtp_original_session/original_mtp_session_plan.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/session_coupling/original_mtp_session_plan.rs index c9451841..4197eb45 100644 --- a/crates/cuda-driver/src/mtp_original_session/original_mtp_session_plan.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/session_coupling/original_mtp_session_plan.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalMtpSessionPlan`: `from_primary`, `sized`, `max_cells`, `experts_per_token` and 11 more. -//! Split out of `session_coupling` to keep its files under the line limit. +//! OriginalMtpSessionPlan: the pure geometry of the MTP session (ring cells, attention capacity, page counts, rope and +//! canonical host bytes) computed from the primary shape, plus its read accessors; allocates nothing. use super::{Error, MTP_ORIGINAL_MAX_CELLS, MTP_ORIGINAL_WINDOW, OriginalMtpSessionPlan, Result}; diff --git a/crates/cuda-driver/src/mtp_original_session/original_mtp_session_resources.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/session_coupling/original_mtp_session_resources.rs similarity index 96% rename from crates/cuda-driver/src/mtp_original_session/original_mtp_session_resources.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/session_coupling/original_mtp_session_resources.rs index 8f5aa733..87a8acb5 100644 --- a/crates/cuda-driver/src/mtp_original_session/original_mtp_session_resources.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/session_coupling/original_mtp_session_resources.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalMtpSessionResources`: `retain_primary`, `check_primary`, `check_plan`, `check_tables` and 14 ... -//! Methods of `SessionOwned`: `check_live`, `validate`. Functions: `session_native_asset`, `session_legacy_asset`. +//! Session resources of the MTP drafter shared with SessionState: retains and validates the rope tables and module, +//! builds the rope plan (addresses, aliasing checks, kernel arguments), and loads the sealed session assets. use super::{ BufferHandle, Cell, Context, DeviceBuffer, Error, F, FA, FM, OriginalMtpRopeForm, OriginalMtpSessionPlan, @@ -264,13 +264,13 @@ impl<'ctx> OriginalMtpSessionResources<'ctx> { } pub(super) fn session_native_asset() -> Option<&'static [u8]> { crate::sealed_ptx::pinned( - concat!(include_str!("../mtp_original_session_native_rope.ptx"), "\0").as_bytes(), + concat!(include_str!("../../../../../../mtp_original_session_native_rope.ptx"), "\0").as_bytes(), SESSION_NATIVE_ASSET_PIN, ) } pub(super) fn session_legacy_asset() -> Option<&'static [u8]> { crate::sealed_ptx::pinned( - concat!(include_str!("../mtp_original_session_legacy_rope.ptx"), "\0").as_bytes(), + concat!(include_str!("../../../../../../mtp_original_session_legacy_rope.ptx"), "\0").as_bytes(), SESSION_LEGACY_ASSET_PIN, ) } diff --git a/crates/cuda-driver/src/mtp_original_session/session_owned_drop.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/session_coupling/session_owned_drop.rs similarity index 93% rename from crates/cuda-driver/src/mtp_original_session/session_owned_drop.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/session_coupling/session_owned_drop.rs index 298fc04f..bd93496b 100644 --- a/crates/cuda-driver/src/mtp_original_session/session_owned_drop.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/session_coupling/session_owned_drop.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalMtpSessionRopePlan`: `capture`. -//! Implements `Drop for SessionOwned`, `Sealed for OriginalMtpSessionRopePlan` and 1 more. +//! Teardown and graph capture of the session rope: Drop of SessionOwned (module close, leak on poison), and the capture +//! of OriginalMtpSessionRopePlan into a graph, with the sealed-asset probe. use super::{ Context, Error, LaunchShape, OriginalCapture, OriginalGraphResources, OriginalMtpRopeForm, diff --git a/crates/cuda-driver/src/mtp_original_full_symbols.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/symbols.rs similarity index 71% rename from crates/cuda-driver/src/mtp_original_full_symbols.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/symbols.rs index 365339e6..cedc2c48 100644 --- a/crates/cuda-driver/src/mtp_original_full_symbols.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/symbols.rs @@ -1,33 +1,20 @@ use super::CStr; -#[path = "mtp_original_full_symbols/assets_types.rs"] mod assets_types; -#[allow(unused_imports)] pub(super) use assets_types::ASSETS; -#[path = "mtp_original_full_symbols/chain_asset_types.rs"] mod chain_asset_types; -#[allow(unused_imports)] pub(super) use chain_asset_types::CHAIN_ASSET; -#[allow(unused_imports)] -pub(super) use chain_asset_types::CHAIN_QSA_CHUNK; -#[allow(unused_imports)] pub(super) use chain_asset_types::CHAIN_QSA_MERGE_N; -#[allow(unused_imports)] pub(super) use chain_asset_types::CHAIN_ROW_TOP_PROB; -#[allow(unused_imports)] pub(super) use chain_asset_types::CHAIN_SAMPLER_GREEDY; -#[allow(unused_imports)] pub(super) use chain_asset_types::DAILY_ASSET; -#[allow(unused_imports)] pub(super) use chain_asset_types::DAILY_CHUNK; -#[allow(unused_imports)] pub(super) use chain_asset_types::DAILY_MERGE_V2; /// The sealed batched numerical guard (`LELEKA_DRAFT_CHECK_MERGE`); loaded only when the switch is on, so it is not a /// slot of `ASSETS` and moves no index. -#[allow(unused_imports)] pub(super) static CHECK_BATCH: (&[u8], &[&std::ffi::CStr]) = - (include_bytes!("mtp_original_check_batch.ptx"), &[c"mtp_original_check_batch"]); + (include_bytes!("../../../../../mtp_original_check_batch.ptx"), &[c"mtp_original_check_batch"]); /// Length (with the terminal NUL) and sha256 of the body of `mtp_original_check_batch.ptx`, compiled from /// `mtp_original_check_batch.cu` by `scripts/gpu-bringup/compile_assets.py` (nvcc 13.2.86, the plan entry of diff --git a/crates/cuda-driver/src/mtp_original_full_symbols/assets_types.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/symbols/assets_types.rs similarity index 85% rename from crates/cuda-driver/src/mtp_original_full_symbols/assets_types.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/symbols/assets_types.rs index 7171ae6a..affd9eb9 100644 --- a/crates/cuda-driver/src/mtp_original_full_symbols/assets_types.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/symbols/assets_types.rs @@ -1,11 +1,15 @@ -//! Items of the parent module. -//! Split out of `symbols` to keep its files under the line limit. +//! The ASSETS table of the MTP full forward: each sealed PTX image of the crate with the kernel entry names it exports, +//! indexed by the asset constants (the chain and sm120 daily modules sit last, loaded only when selected). use super::CStr; +/// The sealed PTX of the crate's `src/` directory, six levels above this file: `ptx!("name.ptx")` is its bytes. +#[rustfmt::skip] +macro_rules! ptx { ($name:literal) => { include_bytes!(concat!("../../../../../../", $name)) }; } + pub(in super::super) const ASSETS: &[(&[u8], &[&CStr])] = &[ ( - include_bytes!("../mtp_original_full_s2.ptx"), + ptx!("mtp_original_full_s2.ptx"), &[ c"mtp_full_group_resident_kernel", c"mtp_full_gu_grouped_kernel", @@ -15,9 +19,9 @@ pub(in super::super) const ASSETS: &[(&[u8], &[&CStr])] = &[ c"mtp_full_down_grouped_t_kernel", ], ), - (include_bytes!("../mtp_original_full_quant80.ptx"), &[c"mtp_full_quantize_q8_0_scaled_kernel"]), + (ptx!("mtp_original_full_quant80.ptx"), &[c"mtp_full_quantize_q8_0_scaled_kernel"]), ( - include_bytes!("../mtp_original_full_shared.ptx"), + ptx!("mtp_original_full_shared.ptx"), &[ c"mtp_full_native_swiglu_kernel", c"mtp_full_scalar_gate_kernel", @@ -26,18 +30,18 @@ pub(in super::super) const ASSETS: &[(&[u8], &[&CStr])] = &[ c"mtp_full_moe_combine_kernel", ], ), - (include_bytes!("../mtp_original_full_router.ptx"), &[c"mtp_full_route"]), + (ptx!("mtp_original_full_router.ptx"), &[c"mtp_full_route"]), ( - include_bytes!("../mtp_original_full_router_legacy.ptx"), + ptx!("mtp_original_full_router_legacy.ptx"), &[ c"mtp_full_router_top10_kernel", c"mtp_full_router_top10_fast_kernel", c"mtp_full_router_top10_serial_kernel", ], ), - (include_bytes!("../mtp_original_full_combine.ptx"), &[c"mtp_full_combine"]), + (ptx!("mtp_original_full_combine.ptx"), &[c"mtp_full_combine"]), ( - include_bytes!("../mtp_original_full_bf16.ptx"), + ptx!("mtp_original_full_bf16.ptx"), &[ c"mtp_full_mmvf32", c"mtp_full_mmvf64", @@ -49,13 +53,10 @@ pub(in super::super) const ASSETS: &[(&[u8], &[&CStr])] = &[ c"mtp_full_mmvf256", ], ), - (include_bytes!("../mtp_original_full_gr_norm.ptx"), &[c"mtp_full_gr_norm"]), + (ptx!("mtp_original_full_gr_norm.ptx"), &[c"mtp_full_gr_norm"]), + (ptx!("mtp_original_full_gr_post.ptx"), &[c"mtp_full_down_silu", c"mtp_full_pre_final", c"mtp_full_native_write"]), ( - include_bytes!("../mtp_original_full_gr_post.ptx"), - &[c"mtp_full_down_silu", c"mtp_full_pre_final", c"mtp_full_native_write"], - ), - ( - include_bytes!("../mtp_original_full_gr_write.ptx"), + ptx!("mtp_original_full_gr_write.ptx"), &[ c"mtp_full_gr_write", c"mtp_full_legacy_norm_true", @@ -68,16 +69,16 @@ pub(in super::super) const ASSETS: &[(&[u8], &[&CStr])] = &[ ], ), ( - include_bytes!("../mtp_original_full_element.ptx"), + ptx!("mtp_original_full_element.ptx"), &[c"mtp_full_to_bf16", c"mtp_full_copy_from_mapped", c"mtp_full_copy_i32_from_mapped"], ), - (include_bytes!("../mtp_original_full_qsa_gate.ptx"), &[c"mtp_full_gate"]), + (ptx!("mtp_original_full_qsa_gate.ptx"), &[c"mtp_full_gate"]), ( - include_bytes!("../mtp_original_full_verify.ptx"), + ptx!("mtp_original_full_verify.ptx"), &[c"mtp_full_row_top_prob_kernel", c"mtp_full_map_ids_kernel", c"mtp_full_mtp_select_kernel"], ), ( - include_bytes!("../mtp_original_full_head_native.ptx"), + ptx!("mtp_original_full_head_native.ptx"), &[ c"head_quant", c"head_n2_s0", @@ -313,7 +314,7 @@ pub(in super::super) const ASSETS: &[(&[u8], &[&CStr])] = &[ ], ), ( - include_bytes!("../mtp_original_full_head_iq.ptx"), + ptx!("mtp_original_full_head_iq.ptx"), &[ c"head_i7_old", c"head_i16_old", @@ -351,7 +352,7 @@ pub(in super::super) const ASSETS: &[(&[u8], &[&CStr])] = &[ ], ), ( - include_bytes!("../mtp_original_full_head_sampler.ptx"), + ptx!("mtp_original_full_head_sampler.ptx"), &[ c"sampler_greedy_kernel", c"sampler_kernel", @@ -360,9 +361,9 @@ pub(in super::super) const ASSETS: &[(&[u8], &[&CStr])] = &[ c"sampler_split_merge_kernel", ], ), - (include_bytes!("../mtp_original_full_qnorm.ptx"), &[c"mtp_full_qnorm", c"mtp_scalar_rope"]), + (ptx!("mtp_original_full_qnorm.ptx"), &[c"mtp_full_qnorm", c"mtp_scalar_rope"]), ( - include_bytes!("../mtp_original_full_fused_gr.ptx"), + ptx!("mtp_original_full_fused_gr.ptx"), &[ c"mtp_scalar_gr_norm", c"mtp_scalar_gr_split", @@ -372,16 +373,16 @@ pub(in super::super) const ASSETS: &[(&[u8], &[&CStr])] = &[ c"mtp_scalar_gr_down2560", ], ), - (include_bytes!("../mtp_original_full_checks.ptx"), &[c"mtp_original_finite", c"mtp_original_q8_guard"]), - (include_bytes!("../mtp_original_full_attention.ptx"), &[c"leleka_qsa_decode_chunk", c"leleka_qsa_decode_merge"]), + (ptx!("mtp_original_full_checks.ptx"), &[c"mtp_original_finite", c"mtp_original_q8_guard"]), + (ptx!("mtp_original_full_attention.ptx"), &[c"leleka_qsa_decode_chunk", c"leleka_qsa_decode_merge"]), ( - include_bytes!("../mtp_original_full_coupled.ptx"), + ptx!("mtp_original_full_coupled.ptx"), &[c"sampler_split_part_kernel", c"coupled_stage_kernel", c"coupled_penalize_kernel", c"coupled_merge_kernel"], ), // 21: chain_window.ptx (claude/chain-kernels), loaded only when LELEKA_CHAIN selects a group that launches from it // (`CHAIN_ASSET`); checked against its pin (`original_verify::chain::CHAIN`) before it is handed to the driver. ( - concat!(include_str!("../chain_window.ptx"), "\0").as_bytes(), + concat!(include_str!("../../../../../../chain_window.ptx"), "\0").as_bytes(), &[ c"chain_qsa_decode_chunk", c"chain_qsa_decode_merge_n", @@ -393,7 +394,7 @@ pub(in super::super) const ASSETS: &[(&[u8], &[&CStr])] = &[ // `LELEKA_SM120_ATTN_DAILY_MTP=1` (`DAILY_ASSET`); checked against its pin (`original_verify::sm120::ATTN_DAILY`) // before it is handed to the driver. ( - concat!(include_str!("../sm120_attn_daily.ptx"), "").as_bytes(), + concat!(include_str!("../../../../../../sm120_attn_daily.ptx"), "").as_bytes(), &[c"leleka_qsa_decode_chunk_daily", c"leleka_qsa_decode_merge_v2"], ), ]; diff --git a/crates/cuda-driver/src/mtp_original_full_symbols/chain_asset_types.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/symbols/chain_asset_types.rs similarity index 84% rename from crates/cuda-driver/src/mtp_original_full_symbols/chain_asset_types.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/symbols/chain_asset_types.rs index 9c9d9896..42a5c788 100644 --- a/crates/cuda-driver/src/mtp_original_full_symbols/chain_asset_types.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/symbols/chain_asset_types.rs @@ -1,5 +1,4 @@ -//! Items of the parent module. -//! CHAIN_ASSET, DAILY_ASSET, DAILY_CHUNK, DAILY_MERGE_V2, CHAIN_QSA_CHUNK, CHAIN_QSA_MERGE_N .... +//! Indices of the chain and sm120 daily modules in ASSETS and of their kernel entries (chunk, merge, sampler). /// Index of the chain module in `ASSETS` (absent from the loaded modules unless `LELEKA_CHAIN` selects `mtp` or /// `head`). diff --git a/crates/cuda-driver/src/mtp_original_full_forward/validate_scalar_prefix.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/validate_scalar_prefix.rs similarity index 92% rename from crates/cuda-driver/src/mtp_original_full_forward/validate_scalar_prefix.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/validate_scalar_prefix.rs index 523ca586..f7ef4a66 100644 --- a/crates/cuda-driver/src/mtp_original_full_forward/validate_scalar_prefix.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/validate_scalar_prefix.rs @@ -1,5 +1,5 @@ -//! Functions: `validate_scalar_prefix`, `push`, `daily_mtp`, `chain_mtp_assets` and 2 more. -//! Split out of `full_forward` to keep its files under the line limit. +//! Shared helpers of the draft step builders: validation of the scalar prefix owner, the command-push helper, and the +//! switches that select the sm120 daily or chain attention assets and the fixed kernel entries. use super::{ Error, F, FA, FullCommand, LaunchShape, OriginalGpuStream, OriginalMtpScalarPrefill, Result, SCALAR_FLAGS, checked, diff --git a/crates/cuda-driver/src/mtp_original_scalar_graph.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/graph.rs similarity index 100% rename from crates/cuda-driver/src/mtp_original_scalar_graph.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/graph.rs diff --git a/crates/cuda-driver/src/mtp_original_scalar_prefill/graph_resources_original_graph_resources.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/graph_resources_original_graph_resources.rs similarity index 88% rename from crates/cuda-driver/src/mtp_original_scalar_prefill/graph_resources_original_graph_resources.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/graph_resources_original_graph_resources.rs index 69b48cb1..37e3db2b 100644 --- a/crates/cuda-driver/src/mtp_original_scalar_prefill/graph_resources_original_graph_resources.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/graph_resources_original_graph_resources.rs @@ -1,5 +1,5 @@ -//! Methods of `Scratch`: `new`. Methods of `Context`: `original_mtp_scalar_prefill`. -//! Implements `Sealed for GraphResources`, `OriginalGraphResources for GraphResources`. +//! GraphResources of the scalar prefill as a graph resource (context, ring, weights, buffer and mapped checks), plus +//! the Scratch layout of per-token buffer sizes and offsets, and the Context entry point original_mtp_scalar_prefill. use super::{ Context, Error, GraphResources, OriginalGraphResources, OriginalMtpScalarPrefill, Result, Scratch, aligned, checked, diff --git a/crates/cuda-driver/src/mtp_original_scalar_mapped.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/mapped_records.rs similarity index 100% rename from crates/cuda-driver/src/mtp_original_scalar_mapped.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/mapped_records.rs diff --git a/crates/cuda-driver/src/mtp_original_scalar_prefill/original_mtp_scalar_prefill.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/original_mtp_scalar_prefill.rs similarity index 57% rename from crates/cuda-driver/src/mtp_original_scalar_prefill/original_mtp_scalar_prefill.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/original_mtp_scalar_prefill.rs index ea1666a8..9eb3106c 100644 --- a/crates/cuda-driver/src/mtp_original_scalar_prefill/original_mtp_scalar_prefill.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/original_mtp_scalar_prefill.rs @@ -1,5 +1,5 @@ -//! Groups the submodules `call_admission`, `group_capture`, `group_loop` and 5 more. -//! Split out of `scalar` to keep its files under the line limit. +//! Root of the scalar MTP prefill: declares the submodules for call admission, group capture and loop, kernel commands, +//! operands, GR recording, construction and close, and holds their shared imports. use super::{ Arg, Arguments, BufferHandle, Context, DeviceBuffer, DraftKvOutcome, ENTRIES, EmbeddingKind, Error, GR_ENTRIES, @@ -12,24 +12,15 @@ use super::{ ScalarDraftKvSources, Scratch, TAIL_ENTRIES, checked, combine, mapped_records, zero_bytes, }; -#[path = "original_mtp_scalar_prefill/call_admission.rs"] mod call_admission; -#[path = "original_mtp_scalar_prefill/group_capture.rs"] mod group_capture; -#[path = "original_mtp_scalar_prefill/group_loop.rs"] mod group_loop; -#[path = "original_mtp_scalar_prefill/kernel_commands.rs"] mod kernel_commands; -#[path = "original_mtp_scalar_prefill/original_mtp_scalar_prefill_admit_new.rs"] mod original_mtp_scalar_prefill_admit_new; -#[path = "original_mtp_scalar_prefill/original_mtp_scalar_prefill_close.rs"] mod original_mtp_scalar_prefill_close; -#[path = "original_mtp_scalar_prefill/original_mtp_scalar_prefill_record_gr.rs"] mod original_mtp_scalar_prefill_record_gr; -#[path = "original_mtp_scalar_prefill/record_operands.rs"] mod record_operands; -#[allow(unused_imports)] use record_operands::{ - Cap, ExternalOwners, GrRows, GroupIo, GroupSpan, PagePublication, ScalarCall, ScalarGroupSources, ScalarOperands, + Cap, ExternalOwners, GrRows, GroupSpan, PagePublication, ScalarCall, ScalarGroupSources, ScalarOperands, ScalarStaged, }; diff --git a/crates/cuda-driver/src/mtp_original_scalar_prefill/original_mtp_scalar_prefill/call_admission.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/original_mtp_scalar_prefill/call_admission.rs similarity index 100% rename from crates/cuda-driver/src/mtp_original_scalar_prefill/original_mtp_scalar_prefill/call_admission.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/original_mtp_scalar_prefill/call_admission.rs diff --git a/crates/cuda-driver/src/mtp_original_scalar_prefill/original_mtp_scalar_prefill/group_capture.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/original_mtp_scalar_prefill/group_capture.rs similarity index 100% rename from crates/cuda-driver/src/mtp_original_scalar_prefill/original_mtp_scalar_prefill/group_capture.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/original_mtp_scalar_prefill/group_capture.rs diff --git a/crates/cuda-driver/src/mtp_original_scalar_prefill/original_mtp_scalar_prefill/group_loop.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/original_mtp_scalar_prefill/group_loop.rs similarity index 100% rename from crates/cuda-driver/src/mtp_original_scalar_prefill/original_mtp_scalar_prefill/group_loop.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/original_mtp_scalar_prefill/group_loop.rs diff --git a/crates/cuda-driver/src/mtp_original_scalar_prefill/original_mtp_scalar_prefill/kernel_commands.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/original_mtp_scalar_prefill/kernel_commands.rs similarity index 100% rename from crates/cuda-driver/src/mtp_original_scalar_prefill/original_mtp_scalar_prefill/kernel_commands.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/original_mtp_scalar_prefill/kernel_commands.rs diff --git a/crates/cuda-driver/src/mtp_original_scalar_prefill/original_mtp_scalar_prefill/original_mtp_scalar_prefill_admit_new.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/original_mtp_scalar_prefill/original_mtp_scalar_prefill_admit_new.rs similarity index 89% rename from crates/cuda-driver/src/mtp_original_scalar_prefill/original_mtp_scalar_prefill/original_mtp_scalar_prefill_admit_new.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/original_mtp_scalar_prefill/original_mtp_scalar_prefill_admit_new.rs index 2263d6e5..6c75e862 100644 --- a/crates/cuda-driver/src/mtp_original_scalar_prefill/original_mtp_scalar_prefill/original_mtp_scalar_prefill_admit_new.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/original_mtp_scalar_prefill/original_mtp_scalar_prefill_admit_new.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalMtpScalarPrefill`: `assets_ready`, `planned_device_bytes`, `planned_host_bytes`, `host_metada... -//! Split out of `original_mtp_scalar_prefill` to keep its files under the line limit. +//! Construction of OriginalMtpScalarPrefill: byte planning, shape and sealed-asset admission against the budget, then +//! allocation of scratch, records, status, stream, modules and mapped memory (private or shared layout). use super::{ Context, ENTRIES, Error, GR_ENTRIES, KV_ENTRIES, MAX_PROMPT, MTP_ORIGINAL_MAX_CELLS, Module, OriginalGraphRegistry, @@ -10,12 +10,12 @@ use super::{ impl<'ctx> OriginalMtpScalarPrefill<'ctx> { pub(in super::super) fn assets_ready() -> Result<()> { let assets = [ - include_bytes!("../../mtp_original_prefill.ptx").as_slice(), - include_bytes!("../../mtp_original_prefill_embedding.ptx").as_slice(), - include_bytes!("../../mtp_original_tail.ptx").as_slice(), - include_bytes!("../../mtp_original_scalar_norm.ptx").as_slice(), - include_bytes!("../../mtp_original_scalar_gr.ptx").as_slice(), - include_bytes!("../../mtp_original_kv.ptx").as_slice(), + include_bytes!("../../../../../mtp_original_prefill.ptx").as_slice(), + include_bytes!("../../../../../mtp_original_prefill_embedding.ptx").as_slice(), + include_bytes!("../../../../../mtp_original_tail.ptx").as_slice(), + include_bytes!("../../../../../mtp_original_scalar_norm.ptx").as_slice(), + include_bytes!("../../../../../mtp_original_scalar_gr.ptx").as_slice(), + include_bytes!("../../../../../mtp_original_kv.ptx").as_slice(), ]; if assets.iter().any(|p| p.windows(8).any(|w| w == b"UNSEALED")) { Err(Error::UnsupportedQwenOperation) @@ -75,12 +75,12 @@ impl<'ctx> OriginalMtpScalarPrefill<'ctx> { /// The six sealed prefill assets, in module-slot order. fn scalar_assets() -> [&'static [u8]; 6] { [ - include_bytes!("../../mtp_original_prefill.ptx").as_slice(), - include_bytes!("../../mtp_original_prefill_embedding.ptx").as_slice(), - include_bytes!("../../mtp_original_tail.ptx").as_slice(), - include_bytes!("../../mtp_original_scalar_norm.ptx").as_slice(), - include_bytes!("../../mtp_original_scalar_gr.ptx").as_slice(), - include_bytes!("../../mtp_original_kv.ptx").as_slice(), + include_bytes!("../../../../../mtp_original_prefill.ptx").as_slice(), + include_bytes!("../../../../../mtp_original_prefill_embedding.ptx").as_slice(), + include_bytes!("../../../../../mtp_original_tail.ptx").as_slice(), + include_bytes!("../../../../../mtp_original_scalar_norm.ptx").as_slice(), + include_bytes!("../../../../../mtp_original_scalar_gr.ptx").as_slice(), + include_bytes!("../../../../../mtp_original_kv.ptx").as_slice(), ] } diff --git a/crates/cuda-driver/src/mtp_original_scalar_prefill/original_mtp_scalar_prefill/original_mtp_scalar_prefill_close.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/original_mtp_scalar_prefill/original_mtp_scalar_prefill_close.rs similarity index 94% rename from crates/cuda-driver/src/mtp_original_scalar_prefill/original_mtp_scalar_prefill/original_mtp_scalar_prefill_close.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/original_mtp_scalar_prefill/original_mtp_scalar_prefill_close.rs index 3216a2e3..54bf87ce 100644 --- a/crates/cuda-driver/src/mtp_original_scalar_prefill/original_mtp_scalar_prefill/original_mtp_scalar_prefill_close.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/original_mtp_scalar_prefill/original_mtp_scalar_prefill_close.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalMtpScalarPrefill`: `close`, `close_inner`, `finish_host`, `close_stream` and 3 more. -//! Split out of `original_mtp_scalar_prefill` to keep its files under the line limit. +//! Ordered teardown of OriginalMtpScalarPrefill: closes graphs, stream, modules, device buffers and mapped memory, +//! poisoning the context and leaking resources the device may still touch when a step fails. use super::{Context, DeviceBuffer, Error, Module, OriginalGpuStream, OriginalMtpScalarPrefill, Rc, Result, combine}; diff --git a/crates/cuda-driver/src/mtp_original_scalar_prefill/original_mtp_scalar_prefill/original_mtp_scalar_prefill_record_gr.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/original_mtp_scalar_prefill/original_mtp_scalar_prefill_record_gr.rs similarity index 93% rename from crates/cuda-driver/src/mtp_original_scalar_prefill/original_mtp_scalar_prefill/original_mtp_scalar_prefill_record_gr.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/original_mtp_scalar_prefill/original_mtp_scalar_prefill_record_gr.rs index 912b0361..cf20cab6 100644 --- a/crates/cuda-driver/src/mtp_original_scalar_prefill/original_mtp_scalar_prefill/original_mtp_scalar_prefill_record_gr.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/original_mtp_scalar_prefill/original_mtp_scalar_prefill_record_gr.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalMtpScalarPrefill`: `gr`, `gr_chunks`, `gr_chunk_kernel`, `record` and 1 more. -//! Split out of `original_mtp_scalar_prefill` to keep its files under the line limit. +//! Records the GR kernels of the scalar prefill (norm, chunked projection, reduction) per prompt rows, and the public +//! record entry that adds the draft K/V of the rows and drains any pending graphs. use super::{ BufferHandle, DraftKvOutcome, GrRows, LaunchShape, NativeBatchWorkspace, OriginalDeviceResidual, diff --git a/crates/cuda-driver/src/mtp_original_scalar_prefill/original_mtp_scalar_prefill/record_operands.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/original_mtp_scalar_prefill/record_operands.rs similarity index 100% rename from crates/cuda-driver/src/mtp_original_scalar_prefill/original_mtp_scalar_prefill/record_operands.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/original_mtp_scalar_prefill/record_operands.rs diff --git a/crates/cuda-driver/src/mtp_original_scalar_prefill/original_mtp_scalar_prefill_drop.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/original_mtp_scalar_prefill_drop.rs similarity index 56% rename from crates/cuda-driver/src/mtp_original_scalar_prefill/original_mtp_scalar_prefill_drop.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/original_mtp_scalar_prefill_drop.rs index 4559d79b..96f79a41 100644 --- a/crates/cuda-driver/src/mtp_original_scalar_prefill/original_mtp_scalar_prefill_drop.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/original_mtp_scalar_prefill_drop.rs @@ -1,5 +1,4 @@ -//! Implements `Drop for OriginalMtpScalarPrefill`. -//! Split out of `scalar` to keep its files under the line limit. +//! Drop of OriginalMtpScalarPrefill: closes the prefill (releasing device buffers, modules and stream) best-effort. use super::OriginalMtpScalarPrefill; diff --git a/crates/cuda-driver/src/mtp_original_physical_layout.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/physical_layout.rs similarity index 100% rename from crates/cuda-driver/src/mtp_original_physical_layout.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/physical_layout.rs diff --git a/crates/cuda-driver/src/mtp_original_scalar_weights.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/retained_weights.rs similarity index 100% rename from crates/cuda-driver/src/mtp_original_scalar_weights.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/retained_weights.rs diff --git a/crates/cuda-driver/src/mtp_original_scalar_ffi.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/scalar_abi.rs similarity index 100% rename from crates/cuda-driver/src/mtp_original_scalar_ffi.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/scalar_abi.rs diff --git a/crates/cuda-driver/src/mtp_original_scalar_short_gpu.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/short_prompt_gpu.rs similarity index 100% rename from crates/cuda-driver/src/mtp_original_scalar_short_gpu.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/short_prompt_gpu.rs diff --git a/crates/cuda-driver/src/mtp_original_prefill_symbols.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/symbols.rs similarity index 100% rename from crates/cuda-driver/src/mtp_original_prefill_symbols.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/symbols.rs diff --git a/crates/cuda-driver/src/mtp_original_ring_state.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/ring_state.rs similarity index 81% rename from crates/cuda-driver/src/mtp_original_ring_state.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/ring_state.rs index a079a4c4..f0a15386 100644 --- a/crates/cuda-driver/src/mtp_original_ring_state.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/ring_state.rs @@ -35,15 +35,7 @@ pub(super) struct PreparedState<'ctx> { mapped: Option, } -#[path = "mtp_original_ring_state/a16.rs"] mod a16; -#[allow(unused_imports)] -use a16::a16; -#[path = "mtp_original_ring_state/cleanup_fns.rs"] mod cleanup_fns; -#[path = "mtp_original_ring_state/pin_failure.rs"] mod pin_failure; -#[path = "mtp_original_ring_state/selected.rs"] mod selected; -#[allow(unused_imports)] -pub(super) use pin_failure::pin_failure; diff --git a/crates/cuda-driver/src/mtp_original_ring_state/a16.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/ring_state/a16.rs similarity index 89% rename from crates/cuda-driver/src/mtp_original_ring_state/a16.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/ring_state/a16.rs index 59395bad..9e03ea5f 100644 --- a/crates/cuda-driver/src/mtp_original_ring_state/a16.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/ring_state/a16.rs @@ -1,5 +1,5 @@ -//! Methods of `StateLayout`: `new`, `region_sizes`. Functions: `a16`. -//! Split out of `ring_state` to keep its files under the line limit. +//! Layout of the Original ring state buffer: StateLayout sizes and offsets the 12 regions (resident or windowed) +//! for a draft width, with the 16-byte alignment helper a16 and the total byte size. use super::{Error, MTP_ORIGINAL_MAX_CELLS, MTP_ORIGINAL_WINDOW, Result, StateLayout}; diff --git a/crates/cuda-driver/src/mtp_original_ring_state/cleanup_fns.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/ring_state/cleanup_fns.rs similarity index 100% rename from crates/cuda-driver/src/mtp_original_ring_state/cleanup_fns.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/ring_state/cleanup_fns.rs diff --git a/crates/cuda-driver/src/mtp_original_ring_state/pin_failure.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/ring_state/pin_failure.rs similarity index 95% rename from crates/cuda-driver/src/mtp_original_ring_state/pin_failure.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/ring_state/pin_failure.rs index 1e2580f7..b2cb78ce 100644 --- a/crates/cuda-driver/src/mtp_original_ring_state/pin_failure.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/ring_state/pin_failure.rs @@ -1,5 +1,5 @@ -//! Methods of `PreparedState`: `attempt`, `budgeted_layout`, `build`, `pin_hosts` and 6 more. -//! Implements `Drop for PreparedState`. Functions: `pin_failure`, `enter_poisoning`. +//! Preparation of the ring state (PreparedState): budgeted layout, device and pinned host allocation, identity table, +//! zeroing and rollback on failure; pin_failure tells pinned-allocation failures (which allow fallback) from others. use super::cleanup_fns::{close_mapped, release_state}; use super::{ diff --git a/crates/cuda-driver/src/mtp_original_ring_state/selected.rs b/crates/cuda-driver/src/mtp_dense_kv/original_int8/ring_state/selected.rs similarity index 97% rename from crates/cuda-driver/src/mtp_original_ring_state/selected.rs rename to crates/cuda-driver/src/mtp_dense_kv/original_int8/ring_state/selected.rs index 0b9ab227..cdceb6a3 100644 --- a/crates/cuda-driver/src/mtp_original_ring_state/selected.rs +++ b/crates/cuda-driver/src/mtp_dense_kv/original_int8/ring_state/selected.rs @@ -1,5 +1,5 @@ -//! Methods of `Selected`: `from_prepared`, `provides`, `span`, `locate` and 10 more. Implements `Drop for Selected`. -//! Functions: `main_span_index`. +//! Selected, the chosen state of the ring: the prepared state paired with the shared main-bank spans, with span lookup, +//! alias and overlap checks, page reads, transfer and close. use super::cleanup_fns::{close_mapped, release_state}; use super::{ diff --git a/crates/cuda-driver/src/mtp_original_full_ffi/tests.rs b/crates/cuda-driver/src/mtp_original_full_ffi/tests.rs index 7df6ca7a..1d0847b7 100644 --- a/crates/cuda-driver/src/mtp_original_full_ffi/tests.rs +++ b/crates/cuda-driver/src/mtp_original_full_ffi/tests.rs @@ -1,4 +1,4 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests that pin the q-split copy2d descriptor: it stays inside both tail owners for every T, device-to-device only. use super::*; /// `copy2d` hands the driver a raw descriptor of fixed extents; the two owners it names (`TailLayout` roles diff --git a/crates/cuda-driver/src/native_head.rs b/crates/cuda-driver/src/native_head.rs index 206401a9..3e7fb2b5 100644 --- a/crates/cuda-driver/src/native_head.rs +++ b/crates/cuda-driver/src/native_head.rs @@ -1,9 +1,7 @@ //! Literal Original compressed NativeHead/NativeEmbed and verification head banks. //! These are actual numerical owners, never session or accepted-prefix certificates. -#[path = "native_head_ffi.rs"] #[allow(unsafe_code)] mod abi; -#[path = "native_head_mapped.rs"] #[allow(unsafe_code)] mod mapped; use crate::original_gpu_schedule::{OriginalCapture, OriginalGpuStream, OriginalGraphResources, resources}; @@ -15,7 +13,6 @@ use std::{ rc::Rc, }; -#[path = "mtp_original_native_embedding.rs"] pub(crate) mod mtp_embedding; pub use mtp_embedding::OriginalMtpNativeEmbedding; @@ -23,97 +20,56 @@ pub use mtp_embedding::OriginalMtpNativeEmbedding; mod alias_tests; mod native_asset; -#[allow(unused_imports)] use native_asset::address; -#[allow(unused_imports)] use native_asset::admission; -#[allow(unused_imports)] use native_asset::admit; -#[allow(unused_imports)] use native_asset::admit_history_prefix; -#[allow(unused_imports)] use native_asset::cmd; -#[allow(unused_imports)] use native_asset::disjoint; -#[allow(unused_imports)] use native_asset::geometry; -#[allow(unused_imports)] use native_asset::greedy_entry; -#[allow(unused_imports)] use native_asset::iq_asset; -#[allow(unused_imports)] use native_asset::native_asset; -#[allow(unused_imports)] pub use native_asset::native_embed_supported; -#[allow(unused_imports)] pub use native_asset::native_head_row_bytes; -#[allow(unused_imports)] pub use native_asset::native_head_supported; -#[allow(unused_imports)] use native_asset::sampler_asset; -#[allow(unused_imports)] use native_asset::transport; mod head_owned; mod projection_commands; -#[allow(unused_imports)] use projection_commands::projection_commands; mod dispatch; mod original_native_embed; mod original_native_embed_rows_original_graph; mod original_native_head_rows; mod original_native_head_rows_drop_original_graph; -#[allow(unused_imports)] use dispatch::dispatch; mod original_native_head_rows_original_native; -#[allow(unused_imports)] pub(crate) use original_native_head_rows_original_native::head_assets_sealed; mod native_asset_pin_types; -#[allow(unused_imports)] use native_asset_pin_types::EmbedOwned; -#[allow(unused_imports)] use native_asset_pin_types::HeadOwned; -#[allow(unused_imports)] use native_asset_pin_types::IQ_ASSET_PIN; -#[allow(unused_imports)] use native_asset_pin_types::Kernels; -#[allow(unused_imports)] use native_asset_pin_types::NATIVE_ASSET_PIN; -#[allow(unused_imports)] pub use native_asset_pin_types::NativeEmbedFlight; -#[allow(unused_imports)] pub use native_asset_pin_types::NativeHeadDispatch; -#[allow(unused_imports)] pub use native_asset_pin_types::NativeHeadFlight; -#[allow(unused_imports)] pub use native_asset_pin_types::NativeHeadPayload; -#[allow(unused_imports)] pub use native_asset_pin_types::NativeHeadSampling; -#[allow(unused_imports)] pub use native_asset_pin_types::NativeHeadSelection; -#[allow(unused_imports)] pub use native_asset_pin_types::OriginalNativeEmbed; -#[allow(unused_imports)] pub use native_asset_pin_types::OriginalNativeEmbedRows; -#[allow(unused_imports)] pub use native_asset_pin_types::OriginalNativeHead; -#[allow(unused_imports)] pub use native_asset_pin_types::OriginalNativeHeadRows; -#[allow(unused_imports)] use native_asset_pin_types::RESERVE; -#[allow(unused_imports)] use native_asset_pin_types::SAMPLER_ASSET_PIN; -#[allow(unused_imports)] use native_asset_pin_types::SamplingScratch; mod native_entries_types; -#[allow(unused_imports)] use native_entries_types::NATIVE_ENTRIES; mod iq_entries_types; -#[allow(unused_imports)] use iq_entries_types::IQ_ENTRIES; -#[allow(unused_imports)] pub use iq_entries_types::NativeHeadProjectionFlight; -#[allow(unused_imports)] pub use iq_entries_types::OriginalNativeHeadGraphResources; -#[allow(unused_imports)] use iq_entries_types::SAMPLER_ENTRIES; diff --git a/crates/cuda-driver/src/native_head_ffi.rs b/crates/cuda-driver/src/native_head/abi.rs similarity index 100% rename from crates/cuda-driver/src/native_head_ffi.rs rename to crates/cuda-driver/src/native_head/abi.rs diff --git a/crates/cuda-driver/src/native_head/alias_tests.rs b/crates/cuda-driver/src/native_head/alias_tests.rs index 8e543328..98f9e10e 100644 --- a/crates/cuda-driver/src/native_head/alias_tests.rs +++ b/crates/cuda-driver/src/native_head/alias_tests.rs @@ -1,5 +1,5 @@ -//! Functions: `payload`, `map_payload`, `alias_over`, `read_through_the_first_alias` and 3 more. -//! Split out of `native_head` to keep its files under the line limit. +//! Tests that a device alias of a mapped host table reads the host bytes, costs no device memory, is not freed when +//! dropped, and works for both the mapped table and the native embed table. use super::*; diff --git a/crates/cuda-driver/src/native_head/dispatch.rs b/crates/cuda-driver/src/native_head/dispatch.rs index 54f498dd..16ef3a87 100644 --- a/crates/cuda-driver/src/native_head/dispatch.rs +++ b/crates/cuda-driver/src/native_head/dispatch.rs @@ -1,5 +1,5 @@ -//! Functions: `dispatch`, `head_launch_shape`, `iq_columns`, `kind_geometry` and 3 more. -//! Split out of `native_head` to keep its files under the line limit. +//! Kernel dispatch of the native head projection: from the weight kind, token count and dispatch options picks the +//! kernel name, grid and block shape of the plain or IQ head kernels (column counts, rows divisor, mode). use super::{Error, NativeHeadDispatch, Result}; pub(super) fn dispatch( diff --git a/crates/cuda-driver/src/native_head/head_owned.rs b/crates/cuda-driver/src/native_head/head_owned.rs index f141902c..f466fc6d 100644 --- a/crates/cuda-driver/src/native_head/head_owned.rs +++ b/crates/cuda-driver/src/native_head/head_owned.rs @@ -1,5 +1,5 @@ -//! Methods of `HeadOwned`: `validate`, `close`, `is_released`, `leak_all` and 4 more. -//! Methods of `Context`: `original_native_head`. Implements `Drop for HeadOwned`. +//! HeadOwned, the owner of the native head weights, scalar Q8 scratch and kernels: validation, upload, ordered release +//! or leak on an uncertain context, plus the Context entry point original_native_head and the OriginalNativeHead API. use super::{ Cell, Command, Context, DeviceBuffer, Error, HeadOwned, Kernels, NativeHeadDispatch, NativeHeadPayload, diff --git a/crates/cuda-driver/src/native_head/iq_entries_types.rs b/crates/cuda-driver/src/native_head/iq_entries_types.rs index 82758dcb..96bb69e5 100644 --- a/crates/cuda-driver/src/native_head/iq_entries_types.rs +++ b/crates/cuda-driver/src/native_head/iq_entries_types.rs @@ -1,5 +1,5 @@ -//! Defines `OriginalNativeHeadGraphResources`, `NativeHeadProjectionFlight`. -//! IQ_ENTRIES, SAMPLER_ENTRIES, OriginalNativeHeadGraphResources, NativeHeadProjectionFlight. +//! Kernel entry-name tables of the IQ head kernels and the samplers, the OriginalNativeHeadGraphResources trait that +//! exposes a verifier resource head bank, and the NativeHeadProjectionFlight state of an in-flight projection. use super::{ Command, DeviceBuffer, OriginalGpuStream, OriginalGraphResources, OriginalNativeHead, OriginalNativeHeadRows, diff --git a/crates/cuda-driver/src/native_head_mapped.rs b/crates/cuda-driver/src/native_head/mapped.rs similarity index 100% rename from crates/cuda-driver/src/native_head_mapped.rs rename to crates/cuda-driver/src/native_head/mapped.rs diff --git a/crates/cuda-driver/src/mtp_original_native_embedding.rs b/crates/cuda-driver/src/native_head/mtp_embedding.rs similarity index 100% rename from crates/cuda-driver/src/mtp_original_native_embedding.rs rename to crates/cuda-driver/src/native_head/mtp_embedding.rs diff --git a/crates/cuda-driver/src/native_head/native_asset.rs b/crates/cuda-driver/src/native_head/native_asset.rs index 5b99f1e2..890d0656 100644 --- a/crates/cuda-driver/src/native_head/native_asset.rs +++ b/crates/cuda-driver/src/native_head/native_asset.rs @@ -1,5 +1,5 @@ -//! Methods of `NativeHeadDispatch`: `from_original_environment`. -//! Methods of `Kernels`: `load`, `load_modules`, `module`, `close`. Implements `Default for NativeHeadDispatch`. +//! Sealed PTX loading of the native head (pinned native, IQ and sampler images), the Kernels loader, supported kinds, +//! row sizes, geometry and admission checks, and the NativeHeadDispatch defaults with its environment switch. use super::{ Arg, Command, Context, DeviceBuffer, Error, IQ_ASSET_PIN, IQ_ENTRIES, Kernels, Module, NATIVE_ASSET_PIN, diff --git a/crates/cuda-driver/src/native_head/native_asset_pin_types.rs b/crates/cuda-driver/src/native_head/native_asset_pin_types.rs index fc73d156..0786a36e 100644 --- a/crates/cuda-driver/src/native_head/native_asset_pin_types.rs +++ b/crates/cuda-driver/src/native_head/native_asset_pin_types.rs @@ -1,5 +1,5 @@ -//! Defines `NativeHeadSampling`, `NativeHeadPayload`, `NativeHeadDispatch` and 11 more. -//! NATIVE_ASSET_PIN, IQ_ASSET_PIN, SAMPLER_ASSET_PIN, RESERVE, NativeHeadSampling, NativeHeadDispatch .... +//! Data types of the native head (sampling inputs, payload, dispatch options, kernels, owners, rows, flights, +//! selection) with the size and digest pins of the three sealed PTX assets and the device reserve. use super::{ Cell, Command, Context, DeviceBuffer, MappedAllocation, Module, OriginalGpuStream, Rc, RefCell, SamplerParams, diff --git a/crates/cuda-driver/src/native_head/native_entries_types.rs b/crates/cuda-driver/src/native_head/native_entries_types.rs index ecc08cbe..d8a4e4df 100644 --- a/crates/cuda-driver/src/native_head/native_entries_types.rs +++ b/crates/cuda-driver/src/native_head/native_entries_types.rs @@ -1,5 +1,4 @@ -//! Items of the parent module. -//! NATIVE_ENTRIES. +//! NATIVE_ENTRIES: kernel entry names of the native head PTX module, in module index order. pub(super) const NATIVE_ENTRIES: &[&str] = &[ "head_quant", diff --git a/crates/cuda-driver/src/native_head/original_native_embed.rs b/crates/cuda-driver/src/native_head/original_native_embed.rs index 2a3cce94..a4c59676 100644 --- a/crates/cuda-driver/src/native_head/original_native_embed.rs +++ b/crates/cuda-driver/src/native_head/original_native_embed.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalNativeEmbed`: `validate_context`, `kind`, `bytes`, `is_mapped` and 6 more. -//! Methods of `NativeEmbedFlight`: `wait`. +//! OriginalNativeEmbed, the native token embedding table: single-token gather, per-T row gathers for graphs +//! (OriginalNativeEmbedRows), a non-owning table alias, and the in-flight NativeEmbedFlight with close and drop. use super::{ Arg, Command, Context, DeviceBuffer, Error, NativeEmbedFlight, OriginalCapture, OriginalGpuStream, diff --git a/crates/cuda-driver/src/native_head/original_native_embed_rows_original_graph.rs b/crates/cuda-driver/src/native_head/original_native_embed_rows_original_graph.rs index ad400d94..e3eb5f0d 100644 --- a/crates/cuda-driver/src/native_head/original_native_embed_rows_original_graph.rs +++ b/crates/cuda-driver/src/native_head/original_native_embed_rows_original_graph.rs @@ -1,5 +1,4 @@ -//! Implements `OriginalGraphResources for OriginalNativeEmbedRows`. -//! Split out of `native_head` to keep its files under the line limit. +//! Marks OriginalNativeEmbedRows as a graph resource by delegating context validation to it. use super::{Context, OriginalGraphResources, OriginalNativeEmbedRows, Result}; diff --git a/crates/cuda-driver/src/native_head/original_native_head_rows.rs b/crates/cuda-driver/src/native_head/original_native_head_rows.rs index 3fd3d754..72b6e5cb 100644 --- a/crates/cuda-driver/src/native_head/original_native_head_rows.rs +++ b/crates/cuda-driver/src/native_head/original_native_head_rows.rs @@ -1,5 +1,4 @@ -//! Groups the submodules `original_native_head_rows_greedy_submit`, `original_native_head_rows_sampling`. -//! Split out of `native_head` to keep its files under the line limit. +//! Root of OriginalNativeHeadRows: declares the greedy/submit and sampling submodules and holds their shared imports. use super::{ Arg, Cell, Command, Context, DeviceBuffer, Error, HeadOwned, MappedAllocation, NativeHeadFlight, diff --git a/crates/cuda-driver/src/native_head/original_native_head_rows/original_native_head_rows_greedy_submit.rs b/crates/cuda-driver/src/native_head/original_native_head_rows/original_native_head_rows_greedy_submit.rs index b752b2df..5e8a44b1 100644 --- a/crates/cuda-driver/src/native_head/original_native_head_rows/original_native_head_rows_greedy_submit.rs +++ b/crates/cuda-driver/src/native_head/original_native_head_rows/original_native_head_rows_greedy_submit.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalNativeHeadRows`: `new`, `allocate_buffers`, `set_finite_verdict_in_graph`, `finite_verdict_in... -//! Functions: `sampling_needed`. +//! Construction and execution of OriginalNativeHeadRows (the per-T head of the verifier): buffer allocation, finite- +//! logit verdict word, projection and greedy command build, graph capture, stream submit and selection read-back. use super::{ Arg, Cell, Command, Context, DeviceBuffer, Error, HeadOwned, MappedAllocation, NativeHeadFlight, diff --git a/crates/cuda-driver/src/native_head/original_native_head_rows/original_native_head_rows_sampling.rs b/crates/cuda-driver/src/native_head/original_native_head_rows/original_native_head_rows_sampling.rs index 302ef68b..344fb49e 100644 --- a/crates/cuda-driver/src/native_head/original_native_head_rows/original_native_head_rows_sampling.rs +++ b/crates/cuda-driver/src/native_head/original_native_head_rows/original_native_head_rows_sampling.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalNativeHeadRows`: `sample_commands`, `sample_args`, `history_shared_bytes`, `greedy_sample` an... -//! Defines `SampleArgs`. +//! Sampler launches of OriginalNativeHeadRows (greedy, one-block, split and merge kernels) with per-stream scratch +//! and penalty-history shared memory, plus completed-logits access and the ordered close or leak of the rows. use super::{ Arg, Command, DeviceBuffer, Error, NativeHeadSampling, OriginalNativeHeadRows, Result, SamplerParams, SamplerPath, diff --git a/crates/cuda-driver/src/native_head/original_native_head_rows_drop_original_graph.rs b/crates/cuda-driver/src/native_head/original_native_head_rows_drop_original_graph.rs index 05449365..bd17b488 100644 --- a/crates/cuda-driver/src/native_head/original_native_head_rows_drop_original_graph.rs +++ b/crates/cuda-driver/src/native_head/original_native_head_rows_drop_original_graph.rs @@ -1,5 +1,5 @@ -//! Methods of `NativeHeadFlight`: `finish`. -//! Methods of `NativeHeadSelection`: `ids`, `position`, `vocabulary`, `into_ids`. +//! Lifecycle of the head results: Drop and graph-resource impls of OriginalNativeHeadRows, NativeHeadFlight finish and +//! drop, NativeHeadSelection accessors, and EmbedOwned (the embedding table owner) with original_native_embed. use super::{ Cell, Context, DeviceBuffer, EmbedOwned, Error, IQ_ENTRIES, MappedAllocation, Module, NativeHeadFlight, diff --git a/crates/cuda-driver/src/native_head/original_native_head_rows_original_native.rs b/crates/cuda-driver/src/native_head/original_native_head_rows_original_native.rs index 8647add7..4fb26902 100644 --- a/crates/cuda-driver/src/native_head/original_native_head_rows_original_native.rs +++ b/crates/cuda-driver/src/native_head/original_native_head_rows_original_native.rs @@ -1,5 +1,5 @@ -//! Methods of `NativeHeadProjectionFlight`: `wait`. -//! Implements `OriginalNativeHeadGraphResources for OriginalNativeHeadRows`, `Drop for NativeHeadProjectionFlight`. +//! Graph-resource access to the head rows (OriginalNativeHeadGraphResources), NativeHeadProjectionFlight wait/drop +//! that poison the head on a failed drain, and a probe of whether the three native head PTX assets are sealed. use super::{ NativeHeadProjectionFlight, OriginalNativeHeadGraphResources, OriginalNativeHeadRows, Result, iq_asset, diff --git a/crates/cuda-driver/src/native_head/projection_commands.rs b/crates/cuda-driver/src/native_head/projection_commands.rs index 5254da6d..af1a7f25 100644 --- a/crates/cuda-driver/src/native_head/projection_commands.rs +++ b/crates/cuda-driver/src/native_head/projection_commands.rs @@ -1,5 +1,5 @@ -//! Functions: `projection_commands`, `admit_projection`, `quant_command`, `head_command`. Defines `ProjectionBuffers`. -//! Split out of `native_head` to keep its files under the line limit. +//! Command list of one output-head projection: Q8 quantisation of the mixed hidden state, then the head matmul +//! to logits. Checks buffer sizes and pairwise disjointness first, so the dispatcher only sees admitted launches. use super::{ Arg, Command, DeviceBuffer, Error, HeadOwned, Result, address, admit, cmd, disjoint, dispatch, diff --git a/crates/cuda-driver/src/native_parity.rs b/crates/cuda-driver/src/native_parity.rs index 82d48797..d3679cc3 100644 --- a/crates/cuda-driver/src/native_parity.rs +++ b/crates/cuda-driver/src/native_parity.rs @@ -78,38 +78,22 @@ const ENTRIES: &[&str] = &[ ]; mod sealed_ptx; -#[allow(unused_imports)] use sealed_ptx::address; -#[allow(unused_imports)] use sealed_ptx::bytes_f32; -#[allow(unused_imports)] use sealed_ptx::bytes_i32; -#[allow(unused_imports)] use sealed_ptx::command; -#[allow(unused_imports)] use sealed_ptx::first; -#[allow(unused_imports)] use sealed_ptx::floats; -#[allow(unused_imports)] use sealed_ptx::layout; -#[allow(unused_imports)] use sealed_ptx::message; -#[allow(unused_imports)] pub use sealed_ptx::native_parity_embed_supported; -#[allow(unused_imports)] pub use sealed_ptx::native_parity_iq_supported; -#[allow(unused_imports)] pub use sealed_ptx::native_parity_row_bytes; -#[allow(unused_imports)] use sealed_ptx::sealed_ptx; -#[allow(unused_imports)] use sealed_ptx::split; mod native_parity_expert; mod native_parity_operations; mod parity_session; -#[allow(unused_imports)] use native_parity_expert::down_entry; -#[allow(unused_imports)] use native_parity_expert::gu_entry; -#[allow(unused_imports)] use native_parity_expert::read; diff --git a/crates/cuda-driver/src/native_parity/native_parity_expert.rs b/crates/cuda-driver/src/native_parity/native_parity_expert.rs index 979cd24a..f674b0f0 100644 --- a/crates/cuda-driver/src/native_parity/native_parity_expert.rs +++ b/crates/cuda-driver/src/native_parity/native_parity_expert.rs @@ -1,5 +1,5 @@ -//! Methods of `NativeParityExpert`: `diagnostics`, `release`, `release_inner`. -//! Methods of `Temporary`: `new`, `release`, `release_inner`. +//! Lifetime of one parity-harness expert: lazily allocated diagnostic buffers (dequant targets, reversed rows), +//! release/Drop that drain the stream and free every buffer, the blocking readback, and the gate/up/down kernel tables. use super::{ BenchResult, DeviceBuffer, Error, FF, H, NativeParityExpert, Rc, State, Temporary, bytes_i32, first, message, diff --git a/crates/cuda-driver/src/native_parity/native_parity_operations/native_parity_dequantize_diagnostics.rs b/crates/cuda-driver/src/native_parity/native_parity_operations/native_parity_dequantize_diagnostics.rs index 4ee5c541..88392b44 100644 --- a/crates/cuda-driver/src/native_parity/native_parity_operations/native_parity_dequantize_diagnostics.rs +++ b/crates/cuda-driver/src/native_parity/native_parity_operations/native_parity_dequantize_diagnostics.rs @@ -1,5 +1,5 @@ -//! Methods of `NativeParity`: `dequantize_expert_role`, `read_dequantized`, `embed_expert_gate`, `release_expert` an... -//! Functions: `check_gate_rows`, `gate_embed_command`, `dequant_commands`, `q5_commands` and 1 more. +//! Diagnostic operations of the native parity harness: per-role expert dequantisation, gate embedding, the Q5_1 and +//! BF16 embedding checks, and expert release. They exist to compare device output with the Original, not to serve. use super::{ Arg, BenchResult, Command, DeviceBuffer, FF, H, NativeParity, NativeParityExpert, Rc, Temporary, address, diff --git a/crates/cuda-driver/src/native_parity/native_parity_operations/native_parity_expert_enqueue.rs b/crates/cuda-driver/src/native_parity/native_parity_operations/native_parity_expert_enqueue.rs index e8105ad5..b7ba0220 100644 --- a/crates/cuda-driver/src/native_parity/native_parity_operations/native_parity_expert_enqueue.rs +++ b/crates/cuda-driver/src/native_parity/native_parity_operations/native_parity_expert_enqueue.rs @@ -1,5 +1,5 @@ -//! Methods of `NativeParity`: `new`, `idle`, `expert`, `old_kernels` and 9 more. -//! Functions: `expert_head_args`, `old_iq_mmvq`, `scratch_slots`, `gate_up_args` and 1 more. +//! Setup and run of one parity expert: harness construction (sealed PTX, stream, module), staging weights and routing, +//! launching the gate/up and down kernels (old or split IQ MMVQ variant) and reading the f32 result back. use super::{ Api, Arg, BenchResult, Cell, Command, Context, DeviceBuffer, H, Layout, NT, NativeParity, NativeParityExpert, Rc, diff --git a/crates/cuda-driver/src/native_parity/sealed_ptx.rs b/crates/cuda-driver/src/native_parity/sealed_ptx.rs index aece3cb8..3fe371b3 100644 --- a/crates/cuda-driver/src/native_parity/sealed_ptx.rs +++ b/crates/cuda-driver/src/native_parity/sealed_ptx.rs @@ -1,5 +1,5 @@ -//! Functions: `sealed_ptx`, `message`, `first`, `native_parity_iq_supported` and 9 more. -//! Split out of `native_parity` to keep its files under the line limit. +//! Shared plumbing of the native parity harness: the pinned sealed PTX, error-to-message adapters, and the tables of +//! block-quantised formats the harness supports with their elements and bytes per block (row byte sizes). use super::{Arg, BenchResult, Command, DeviceBuffer, FF, H, Layout, Result, SEALED_PTX_PIN}; diff --git a/crates/cuda-driver/src/native_prompt_device.rs b/crates/cuda-driver/src/native_prompt_device.rs index ec6361ce..b770bd07 100644 --- a/crates/cuda-driver/src/native_prompt_device.rs +++ b/crates/cuda-driver/src/native_prompt_device.rs @@ -9,7 +9,6 @@ use crate::{ }; use std::ffi::CStr; const RESERVE: usize = 128 << 20; -#[path = "native_prompt_device_stage.rs"] mod stage_impl; mod stage_phases; pub use stage_impl::PromptInputStage; @@ -102,25 +101,15 @@ use crate::prefill_stage::fused_scans; mod original_device_block; mod original_ple_history; -#[allow(unused_imports)] use original_ple_history::GrNormRequest; -#[allow(unused_imports)] use original_ple_history::LaunchGeometry; -#[allow(unused_imports)] use original_ple_history::PhaseGuards; -#[allow(unused_imports)] use original_ple_history::ScanExtent; -#[allow(unused_imports)] use original_ple_history::WeightExtent; -#[allow(unused_imports)] use original_ple_history::bytes; -#[allow(unused_imports)] use original_ple_history::encode; -#[allow(unused_imports)] use original_ple_history::kernel; -#[allow(unused_imports)] use original_ple_history::scan_gr; -#[allow(unused_imports)] use original_ple_history::scan_ple; mod original_prompt_device; mod original_prompt_device_drop; diff --git a/crates/cuda-driver/src/native_prompt_device/original_device_block.rs b/crates/cuda-driver/src/native_prompt_device/original_device_block.rs index dbeb7f9d..7e1bcbcd 100644 --- a/crates/cuda-driver/src/native_prompt_device/original_device_block.rs +++ b/crates/cuda-driver/src/native_prompt_device/original_device_block.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalDeviceBlock`: `lease_identity`. -//! Methods of `Context`: `original_prompt_device`, `original_ple_history`, `check_history_budget`. +//! Handles that carry prompt rows on the device between stages: the residual, the GR-read lease and the finished +//! block, with final-row readback and finite checks; plus Context entry points for the prompt device and PLE history. use super::{ Context, Error, GrNativeProfile, OriginalDeviceBlock, OriginalDeviceGrRead, OriginalDeviceResidual, diff --git a/crates/cuda-driver/src/native_prompt_device/original_ple_history.rs b/crates/cuda-driver/src/native_prompt_device/original_ple_history.rs index 39b9d909..1c216eee 100644 --- a/crates/cuda-driver/src/native_prompt_device/original_ple_history.rs +++ b/crates/cuda-driver/src/native_prompt_device/original_ple_history.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalPleHistory`: `device`, `final_values`, `allocated_bytes`, `close` and 1 more. -//! Methods of `LaunchGeometry`: `new`. Implements `Drop for OriginalPleHistory`. +//! Device-resident PLE history buffer (read-back at commit, close/Drop) plus the small launch and guard value types +//! (LaunchGeometry, ScanExtent, PhaseGuards, WeightExtent) and kernel/scan helpers shared by the prompt-device phases. use super::{A, BufferHandle, C, DeviceBuffer, Error, KernelArguments, OriginalPleHistory, Result}; diff --git a/crates/cuda-driver/src/native_prompt_device/original_prompt_device.rs b/crates/cuda-driver/src/native_prompt_device/original_prompt_device.rs index 4241598c..4e47de4b 100644 --- a/crates/cuda-driver/src/native_prompt_device/original_prompt_device.rs +++ b/crates/cuda-driver/src/native_prompt_device/original_prompt_device.rs @@ -1,5 +1,5 @@ -//! Groups the submodules `gr_read_phases`, `inject_phases`, `original_prompt_device_apply_ple` and 8 more. -//! Split out of `native_prompt_device` to keep its files under the line limit. +//! Parent module of the prompt device's phases: one child per phase (bring-up, initialize, GR read, inject, PLE, +//! close), each adding methods to OriginalPromptDevice, plus the phase command builders; shares their imports. use super::{ A, BufferHandle, C, Context, DeviceBuffer, Error, GR_ENTRIES, GR_PTX, GR_SHA, GrNativeProfile, GrNormRequest, diff --git a/crates/cuda-driver/src/native_prompt_device/original_prompt_device/original_prompt_device_apply_ple.rs b/crates/cuda-driver/src/native_prompt_device/original_prompt_device/original_prompt_device_apply_ple.rs index 4db41df7..594bd7a6 100644 --- a/crates/cuda-driver/src/native_prompt_device/original_prompt_device/original_prompt_device_apply_ple.rs +++ b/crates/cuda-driver/src/native_prompt_device/original_prompt_device/original_prompt_device_apply_ple.rs @@ -1,7 +1,6 @@ -//! Methods of `OriginalPromptDevice`: `apply_ple`. -//! Split out of `original_prompt_device` to keep its files under the line limit. +//! Applies PLE (per-layer embedding) to the prompt residual in sub-batches: builds each chunk's commands, runs them, +//! and marks the history failed if a chunk errors. The command lists themselves live in ple_apply_phases. -#[allow(unused_imports)] use super::ple_apply_phases::ple_commands; use super::{ NativeBatchWorkspace, OriginalDeviceResidual, OriginalPleHistory, OriginalPromptDevice, PleClosedWeights, Result, diff --git a/crates/cuda-driver/src/native_prompt_device/original_prompt_device/original_prompt_device_bring_up.rs b/crates/cuda-driver/src/native_prompt_device/original_prompt_device/original_prompt_device_bring_up.rs index 5dd99b92..36c1dd94 100644 --- a/crates/cuda-driver/src/native_prompt_device/original_prompt_device/original_prompt_device_bring_up.rs +++ b/crates/cuda-driver/src/native_prompt_device/original_prompt_device/original_prompt_device_bring_up.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalPromptDevice`: `device_bytes`, `new`, `blank`, `init_resources` and 12 more. -//! Functions: `check_sealed_assets`. +//! Construction and validation of the prompt device: checks the pinned PLE/GR PTX, allocates status words, loads the +//! four kernel modules, and checks that leases, spans and weights are live, disjoint and sized before any phase runs. use super::{ BufferHandle, Context, DeviceBuffer, Error, GR_ENTRIES, GR_PTX, GR_SHA, GrNativeProfile, KernelModule, diff --git a/crates/cuda-driver/src/native_prompt_device/original_prompt_device/original_prompt_device_close_modules.rs b/crates/cuda-driver/src/native_prompt_device/original_prompt_device/original_prompt_device_close_modules.rs index 43660c39..9b29339a 100644 --- a/crates/cuda-driver/src/native_prompt_device/original_prompt_device/original_prompt_device_close_modules.rs +++ b/crates/cuda-driver/src/native_prompt_device/original_prompt_device/original_prompt_device_close_modules.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalPromptDevice`: `close_inner`. Functions: `poison_on_error`, `close_module`, `release_owner`. -//! Split out of `original_prompt_device` to keep its files under the line limit. +//! Teardown of the prompt device: closes kernel modules and releases buffers under the context guard, leaking them +//! (and poisoning the context) when the context is already unusable, so a failed close cannot free live GPU memory. use super::{Context, DeviceBuffer, Error, KernelModule, OriginalPromptDevice, Result, combine}; diff --git a/crates/cuda-driver/src/native_prompt_device/original_prompt_device/original_prompt_device_gr_read_plan.rs b/crates/cuda-driver/src/native_prompt_device/original_prompt_device/original_prompt_device_gr_read_plan.rs index a55af5cb..07874b52 100644 --- a/crates/cuda-driver/src/native_prompt_device/original_prompt_device/original_prompt_device_gr_read_plan.rs +++ b/crates/cuda-driver/src/native_prompt_device/original_prompt_device/original_prompt_device_gr_read_plan.rs @@ -1,7 +1,6 @@ -//! Methods of `OriginalPromptDevice`: `read_gr_impl`, `gr_read_plan`, `gr_read_spans`. -//! Split out of `original_prompt_device` to keep its files under the line limit. +//! GR read phase of the prompt device: validates the epsilon and weights, builds the plan of spans and weight extents, +//! and runs it under the finite guards, turning a residual into a GR-read lease. -#[allow(unused_imports)] use super::gr_read_phases::{GR_READ_NAMES, GR_READ_ORDER, GrReadPlan}; use super::{ BufferHandle, DeviceBuffer, Error, GrNativeProfile, GrNormRequest, NativeBatchWorkspace, OriginalDeviceGrRead, diff --git a/crates/cuda-driver/src/native_prompt_device/original_prompt_device/original_prompt_device_initialize_rows.rs b/crates/cuda-driver/src/native_prompt_device/original_prompt_device/original_prompt_device_initialize_rows.rs index 7bc4957e..42d2dd77 100644 --- a/crates/cuda-driver/src/native_prompt_device/original_prompt_device/original_prompt_device_initialize_rows.rs +++ b/crates/cuda-driver/src/native_prompt_device/original_prompt_device/original_prompt_device_initialize_rows.rs @@ -1,7 +1,6 @@ -//! Methods of `OriginalPromptDevice`: `initialize_rows`, `upload_initial`, `settle_upload`, `run`. -//! Functions: `stage_rows`. +//! Uploads the initial prompt rows (residual-stream and PLE embedding values) to the device in one staged pass, +//! and the shared run helper that executes a phase command list under finite guards and settles the result. -#[allow(unused_imports)] use super::run_phases::RunBuffers; use super::{ C, Error, NativeBatchWorkspace, OriginalDeviceResidual, OriginalPromptDevice, OriginalPromptRows, PhaseGuards, diff --git a/crates/cuda-driver/src/native_prompt_device/original_prompt_device/original_prompt_device_inject_gr.rs b/crates/cuda-driver/src/native_prompt_device/original_prompt_device/original_prompt_device_inject_gr.rs index 8b49f5b7..448e8590 100644 --- a/crates/cuda-driver/src/native_prompt_device/original_prompt_device/original_prompt_device_inject_gr.rs +++ b/crates/cuda-driver/src/native_prompt_device/original_prompt_device/original_prompt_device_inject_gr.rs @@ -1,7 +1,6 @@ -//! Methods of `OriginalPromptDevice`: `inject_gr`, `inject_gr_fused`, `close`. -//! Split out of `original_prompt_device` to keep its files under the line limit. +//! GR injection phase: rechecks the finished block, then writes the GR output back into the residual rows, plain or +//! fused with the following RMS norm (inject_gr_fused), under the finite guards; also the explicit close. -#[allow(unused_imports)] use super::inject_phases::{inject_commands, inject_fused_commands}; use super::{ DeviceBuffer, Error, NativeBatchWorkspace, OriginalDeviceBlock, OriginalDeviceNormedResidual, diff --git a/crates/cuda-driver/src/native_prompt_device/original_prompt_device/original_prompt_device_read_gr.rs b/crates/cuda-driver/src/native_prompt_device/original_prompt_device/original_prompt_device_read_gr.rs index 7fd1d414..6dca67ff 100644 --- a/crates/cuda-driver/src/native_prompt_device/original_prompt_device/original_prompt_device_read_gr.rs +++ b/crates/cuda-driver/src/native_prompt_device/original_prompt_device/original_prompt_device_read_gr.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalPromptDevice`: `read_gr`, `read_gr_normed`. -//! Split out of `original_prompt_device` to keep its files under the line limit. +//! Public entry points of the GR read phase for a plain residual and for an already normed one; they check the +//! gamma/epsilon pairing and delegate to read_gr_impl, which owns the plan and launch. use super::{ DeviceBuffer, Error, GrNormRequest, NativeBatchWorkspace, OriginalDeviceGrRead, OriginalDeviceNormedResidual, diff --git a/crates/cuda-driver/src/native_prompt_device/original_prompt_device_drop.rs b/crates/cuda-driver/src/native_prompt_device/original_prompt_device_drop.rs index 04a3245c..bb09555f 100644 --- a/crates/cuda-driver/src/native_prompt_device/original_prompt_device_drop.rs +++ b/crates/cuda-driver/src/native_prompt_device/original_prompt_device_drop.rs @@ -1,5 +1,4 @@ -//! Implements `Drop for OriginalPromptDevice`. -//! Split out of `native_prompt_device` to keep its files under the line limit. +//! Drop for OriginalPromptDevice: closes the device's modules and buffers if the owner did not call close. use super::OriginalPromptDevice; diff --git a/crates/cuda-driver/src/native_prompt_device_stage.rs b/crates/cuda-driver/src/native_prompt_device/stage_impl.rs similarity index 97% rename from crates/cuda-driver/src/native_prompt_device_stage.rs rename to crates/cuda-driver/src/native_prompt_device/stage_impl.rs index ecdd0910..ea1298f0 100644 --- a/crates/cuda-driver/src/native_prompt_device_stage.rs +++ b/crates/cuda-driver/src/native_prompt_device/stage_impl.rs @@ -48,8 +48,6 @@ impl<'ctx> OriginalPromptDevice<'ctx> { } #[cfg(test)] -#[path = "prefill_stage_gpu.rs"] mod gpu_tests; #[cfg(test)] -#[path = "prefill_stage_gr_gpu.rs"] mod gr_gpu_tests; diff --git a/crates/cuda-driver/src/prefill_stage_gpu.rs b/crates/cuda-driver/src/native_prompt_device/stage_impl/gpu_tests.rs similarity index 100% rename from crates/cuda-driver/src/prefill_stage_gpu.rs rename to crates/cuda-driver/src/native_prompt_device/stage_impl/gpu_tests.rs diff --git a/crates/cuda-driver/src/prefill_stage_gr_gpu.rs b/crates/cuda-driver/src/native_prompt_device/stage_impl/gr_gpu_tests.rs similarity index 62% rename from crates/cuda-driver/src/prefill_stage_gr_gpu.rs rename to crates/cuda-driver/src/native_prompt_device/stage_impl/gr_gpu_tests.rs index 8a2edaec..0e017e52 100644 --- a/crates/cuda-driver/src/prefill_stage_gr_gpu.rs +++ b/crates/cuda-driver/src/native_prompt_device/stage_impl/gr_gpu_tests.rs @@ -4,29 +4,17 @@ use super::*; use crate::ple_batch_ffi::{BatchArg as A, KernelArguments, KernelModule}; -#[path = "prefill_stage_gr_gpu/rng.rs"] mod rng; -#[allow(unused_imports)] use rng::download; -#[allow(unused_imports)] use rng::f32_bytes; -#[allow(unused_imports)] use rng::h; -#[allow(unused_imports)] use rng::run_all; -#[allow(unused_imports)] use rng::upload; -#[path = "prefill_stage_gr_gpu/enable_types.rs"] mod enable_types; -#[allow(unused_imports)] use enable_types::ENABLE; -#[allow(unused_imports)] use enable_types::Launch; -#[allow(unused_imports)] use enable_types::Rng; -#[path = "prefill_stage_gr_gpu/gr_fused_guards_equal.rs"] mod gr_fused_guards_equal; -#[path = "prefill_stage_gr_gpu/gr_kernels_run_near_their.rs"] mod gr_kernels_run_near_their; diff --git a/crates/cuda-driver/src/native_prompt_device/stage_impl/gr_gpu_tests/enable_types.rs b/crates/cuda-driver/src/native_prompt_device/stage_impl/gr_gpu_tests/enable_types.rs new file mode 100644 index 00000000..fbce4362 --- /dev/null +++ b/crates/cuda-driver/src/native_prompt_device/stage_impl/gr_gpu_tests/enable_types.rs @@ -0,0 +1,10 @@ +//! Shared test types of the GR GPU proofs: the LELEKA_PREFILL_STAGE_GPU switch that enables them, the xorshift +//! random generator (Rng) that makes their inputs reproducible, and the Launch tuple describing one kernel launch. + +use super::{A, KernelModule}; + +pub(super) const ENABLE: &str = "LELEKA_PREFILL_STAGE_GPU"; + +pub(super) struct Rng(pub(super) u64); + +pub(super) type Launch<'m> = (&'m KernelModule, usize, usize, u32, Vec); diff --git a/crates/cuda-driver/src/prefill_stage_gr_gpu/gr_fused_guards_equal.rs b/crates/cuda-driver/src/native_prompt_device/stage_impl/gr_gpu_tests/gr_fused_guards_equal.rs similarity index 100% rename from crates/cuda-driver/src/prefill_stage_gr_gpu/gr_fused_guards_equal.rs rename to crates/cuda-driver/src/native_prompt_device/stage_impl/gr_gpu_tests/gr_fused_guards_equal.rs diff --git a/crates/cuda-driver/src/prefill_stage_gr_gpu/gr_kernels_run_near_their.rs b/crates/cuda-driver/src/native_prompt_device/stage_impl/gr_gpu_tests/gr_kernels_run_near_their.rs similarity index 100% rename from crates/cuda-driver/src/prefill_stage_gr_gpu/gr_kernels_run_near_their.rs rename to crates/cuda-driver/src/native_prompt_device/stage_impl/gr_gpu_tests/gr_kernels_run_near_their.rs diff --git a/crates/cuda-driver/src/prefill_stage_gr_gpu/rng.rs b/crates/cuda-driver/src/native_prompt_device/stage_impl/gr_gpu_tests/rng.rs similarity index 88% rename from crates/cuda-driver/src/prefill_stage_gr_gpu/rng.rs rename to crates/cuda-driver/src/native_prompt_device/stage_impl/gr_gpu_tests/rng.rs index 14ee023f..60e95f96 100644 --- a/crates/cuda-driver/src/prefill_stage_gr_gpu/rng.rs +++ b/crates/cuda-driver/src/native_prompt_device/stage_impl/gr_gpu_tests/rng.rs @@ -1,5 +1,5 @@ -//! Methods of `Rng`: `next`. Functions: `f32_bytes`, `upload`, `h`, `download` and 1 more. -//! Split out of `gr_gpu_tests` to keep its files under the line limit. +//! Test helpers of the GR GPU proofs: the xorshift step of Rng, f32 byte encoding, buffer upload/download wrappers, +//! and run_all, which launches kernels in order on the workspace stream and drains it. use super::{BufferHandle, Context, DeviceBuffer, KernelArguments, Launch, NativeBatchWorkspace, Rng}; use crate::ple_batch_ffi::LinearLaunch; diff --git a/crates/cuda-driver/src/original_conversation_state/tests.rs b/crates/cuda-driver/src/original_conversation_state/tests.rs index 772a91fe..809bd486 100644 --- a/crates/cuda-driver/src/original_conversation_state/tests.rs +++ b/crates/cuda-driver/src/original_conversation_state/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests that pin the conversation-state layout against the Original: running-state region sizes (golden C++ values), +//! the KV pool spans per state format and streaming mode, the draft KV staying outside the arena, and span bounds. use super::super::{OriginalLayerBounds, OriginalSessionGeometry, OriginalSessionKvPolicy, OriginalSessionLayout}; use super::*; diff --git a/crates/cuda-driver/src/original_expert_cache/original_cache_prefix.rs b/crates/cuda-driver/src/original_expert_cache/original_cache_prefix.rs index fb1f213b..96ba205e 100644 --- a/crates/cuda-driver/src/original_expert_cache/original_cache_prefix.rs +++ b/crates/cuda-driver/src/original_expert_cache/original_cache_prefix.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalCachePrefix`: `completed_slot_span`. -//! Methods of `Context`: `original_expert_cache_uniform`, `original_expert_cache_sized`. +//! Cache prefix view: finding the completed (Filled) slot span of one layer/expert, and the Context constructors that +//! open an expert cache with uniform slots or with per-slot sizes. use super::{Context, OriginalCachePrefix, OriginalExpertCache, OriginalExpertSlots, Result, State}; diff --git a/crates/cuda-driver/src/original_expert_cache/original_expert_cache_drop.rs b/crates/cuda-driver/src/original_expert_cache/original_expert_cache_drop.rs index 63f2d2c2..4754d88b 100644 --- a/crates/cuda-driver/src/original_expert_cache/original_expert_cache_drop.rs +++ b/crates/cuda-driver/src/original_expert_cache/original_expert_cache_drop.rs @@ -1,5 +1,4 @@ -//! Implements `Drop for OriginalExpertCache`. -//! Split out of `original_expert_cache` to keep its files under the line limit. +//! Drop for OriginalExpertCache: closes the cache (drains copies, releases the arena) if the owner did not close it. use super::OriginalExpertCache; diff --git a/crates/cuda-driver/src/original_expert_cache/original_expert_cache_operations/original_expert_cache_adaptive_swaps.rs b/crates/cuda-driver/src/original_expert_cache/original_expert_cache_operations/original_expert_cache_adaptive_swaps.rs index 81fe90a8..7864529b 100644 --- a/crates/cuda-driver/src/original_expert_cache/original_expert_cache_operations/original_expert_cache_adaptive_swaps.rs +++ b/crates/cuda-driver/src/original_expert_cache/original_expert_cache_operations/original_expert_cache_adaptive_swaps.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalExpertCache`: `arm_swaps`, `record_swap_event`, `swaps_pending`, `swap_copies_running` and 15... -//! Split out of `original_expert_cache_methods` to keep its files under the line limit. +//! Expert cache: the adaptive swap batch (arm event, poll/wait, publish swapped slots) and the queued fills from a +//! mapped bank or probe bytes, with admission checks, the copy stream choice and the liveness guard. use super::original_expert_cache_open_and_slots::{check_total, span_layer}; use super::{ diff --git a/crates/cuda-driver/src/original_expert_cache/original_expert_cache_operations/original_expert_cache_file_slot_fill.rs b/crates/cuda-driver/src/original_expert_cache/original_expert_cache_operations/original_expert_cache_file_slot_fill.rs index 5e9dc6a8..b34dbf84 100644 --- a/crates/cuda-driver/src/original_expert_cache/original_expert_cache_operations/original_expert_cache_file_slot_fill.rs +++ b/crates/cuda-driver/src/original_expert_cache/original_expert_cache_operations/original_expert_cache_file_slot_fill.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalExpertCache`: `fill_file_slot_queued`, `check_file_queue`, `digest_conflict`, `owner_mismatch... -//! Split out of `original_expert_cache_methods` to keep its files under the line limit. +//! Expert cache: fills of a slot from a file-backed expert blob, queued or blocking, with the source-digest and +//! owner checks, host-byte accounting of pending fills, read-back verification of a slot and the queue sync. use super::{ Error, MappedExpertBank, OriginalExpertCache, Rc, ResidentExpertBankSpan, Result, RetainedFill, State, api, diff --git a/crates/cuda-driver/src/original_expert_cache/original_expert_cache_operations/original_expert_cache_open_and_slots.rs b/crates/cuda-driver/src/original_expert_cache/original_expert_cache_operations/original_expert_cache_open_and_slots.rs index c812c7bb..5167ea63 100644 --- a/crates/cuda-driver/src/original_expert_cache/original_expert_cache_operations/original_expert_cache_open_and_slots.rs +++ b/crates/cuda-driver/src/original_expert_cache/original_expert_cache_operations/original_expert_cache_open_and_slots.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalExpertCache`: `validate_file_source_context`, `completed_file_source_member`, `open`, `unopen... -//! Functions: `span_layer`, `check_total`, `queue_span_copies`. Defines `SwapPlan`, `SlotRegion`. +//! Expert cache opening and slot bookkeeping: the free-VRAM and budget check before the single arena allocation, +//! zeroing, slot/owner/layer-range queries and counters, and the planning and copy of queued slot swaps. use super::{ Context, Error, MappedExpertBank, OriginalExpertCache, OriginalExpertSlots, Rc, ResidentExpertBankSpan, Result, diff --git a/crates/cuda-driver/src/original_expert_cache/original_expert_cache_operations/original_expert_cache_verify_and_lend.rs b/crates/cuda-driver/src/original_expert_cache/original_expert_cache_operations/original_expert_cache_verify_and_lend.rs index b776f767..eb62a26b 100644 --- a/crates/cuda-driver/src/original_expert_cache/original_expert_cache_operations/original_expert_cache_verify_and_lend.rs +++ b/crates/cuda-driver/src/original_expert_cache/original_expert_cache_operations/original_expert_cache_verify_and_lend.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalExpertCache`: `verify_slot`, `check_verify`, `compare_spans`, `completed_slot` and 9 more. -//! Split out of `original_expert_cache_methods` to keep its files under the line limit. +//! Expert cache audits and loans: read-back byte verification of a filled slot against its source, lending the cache +//! tail slots to a prefill (choose_loan, lend_prefill_tail, needs_refill), plus poison, close and leak-all teardown. use super::original_expert_cache_open_and_slots::span_layer; use super::{ diff --git a/crates/cuda-driver/src/original_expert_stager.rs b/crates/cuda-driver/src/original_expert_stager.rs index 2394a8af..ef7853b0 100644 --- a/crates/cuda-driver/src/original_expert_stager.rs +++ b/crates/cuda-driver/src/original_expert_stager.rs @@ -100,7 +100,6 @@ pub struct OriginalStagerCompleted<'ctx> { stream: OriginalGpuStream<'ctx>, } -#[path = "original_stream_all.rs"] mod stream_all; pub use stream_all::{ OriginalStreamAll, OriginalStreamAllCompleted, OriginalStreamAllForward, OriginalStreamAllOptions, @@ -124,14 +123,10 @@ mod tests; mod original_stager_options; mod stager_workers; #[cfg(windows)] -#[allow(unused_imports)] use stager_workers::available_memory; #[cfg(unix)] -#[allow(unused_imports)] use stager_workers::available_memory; -#[allow(unused_imports)] use stager_workers::metadata; -#[allow(unused_imports)] use stager_workers::worker; mod context; mod original_expert_stager_lifecycle; diff --git a/crates/cuda-driver/src/original_expert_stager/context.rs b/crates/cuda-driver/src/original_expert_stager/context.rs index abb40859..1c5b431c 100644 --- a/crates/cuda-driver/src/original_expert_stager/context.rs +++ b/crates/cuda-driver/src/original_expert_stager/context.rs @@ -1,5 +1,5 @@ -//! Methods of `Context`: `original_expert_stager`, `original_file_expert_stager`, `open_original_stager`, `abandon_s... -//! Methods of `OriginalExpertStager`: `spawn_workers`. Functions: `shared_state`. Defines `StagerPlan`, `StagerTables`. +//! Opening of the expert stager: the Context entry points for a bank-backed or file-backed source, the ring and thread +//! plan with its host-byte admission, the pinned slot buffers and events, the shared worker state and the worker spawn. use super::{ Arc, AtomicBool, AtomicU8, AtomicU64, AtomicUsize, Condvar, Context, Error, FileExpertSourceLease, FileSource, diff --git a/crates/cuda-driver/src/original_expert_stager/original_stager_batch.rs b/crates/cuda-driver/src/original_expert_stager/original_stager_batch.rs index 483855f8..27ab6f8c 100644 --- a/crates/cuda-driver/src/original_expert_stager/original_stager_batch.rs +++ b/crates/cuda-driver/src/original_expert_stager/original_stager_batch.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalStagerBatch`: `len`, `is_empty`, `issue`, `issue_target` and 3 more. -//! Methods of `OriginalStagerCompleted`: `into_parts`. Implements `Drop for OriginalStagerBatch`. +//! One in-flight batch of the expert stager: ordered issue of staged jobs to device destinations, finish and Drop of +//! the batch, the assembled file blob accessors, and the stager's file-source blob and job construction. use super::{ Context, DeviceBuffer, Error, FileExpertSourceLease, HEADROOM, LayerRole, Ordering, OriginalExpertStager, diff --git a/crates/cuda-driver/src/original_expert_stager/original_stager_options.rs b/crates/cuda-driver/src/original_expert_stager/original_stager_options.rs index 9c527e8a..fb90629a 100644 --- a/crates/cuda-driver/src/original_expert_stager/original_stager_options.rs +++ b/crates/cuda-driver/src/original_expert_stager/original_stager_options.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalStagerOptions`: `from_environment`, `dimensions`. -//! Methods of `OriginalStagerJob`: `new`, `layer`, `expert`. +//! Stager configuration and its source: ring/thread sizing from STRATA_STAGER_* settings, the job type naming one +//! layer and expert, and how a bank or file source validates itself and turns a job into a raw copy job. use super::{ Error, FileSource, LayerRole, OriginalStagerJob, OriginalStagerOptions, ResidentExpertBankLease, diff --git a/crates/cuda-driver/src/original_stream_all.rs b/crates/cuda-driver/src/original_expert_stager/stream_all.rs similarity index 96% rename from crates/cuda-driver/src/original_stream_all.rs rename to crates/cuda-driver/src/original_expert_stager/stream_all.rs index 01321e09..dacea8ea 100644 --- a/crates/cuda-driver/src/original_stream_all.rs +++ b/crates/cuda-driver/src/original_expert_stager/stream_all.rs @@ -128,9 +128,5 @@ pub(crate) trait OriginalStreamAllGroupProducer<'ctx> { ) -> Result<()>; } -#[path = "original_stream_all/original_stream_all_options.rs"] mod original_stream_all_options; -#[allow(unused_imports)] -use original_stream_all_options::issuer_thread; -#[path = "original_stream_all/original_expert_stager.rs"] mod original_expert_stager; diff --git a/crates/cuda-driver/src/original_stream_all/original_expert_stager.rs b/crates/cuda-driver/src/original_expert_stager/stream_all/original_expert_stager.rs similarity index 98% rename from crates/cuda-driver/src/original_stream_all/original_expert_stager.rs rename to crates/cuda-driver/src/original_expert_stager/stream_all/original_expert_stager.rs index a2903ebc..f387f772 100644 --- a/crates/cuda-driver/src/original_stream_all/original_expert_stager.rs +++ b/crates/cuda-driver/src/original_expert_stager/stream_all/original_expert_stager.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalExpertStager`: `run_stream_all_forward`, `admit_forward`, `check_forward_caps`. -//! Methods of `OriginalStreamAllForward`: `settle`, `validate_rows`, `with_compute`, `consume_layer` and 1 more. +//! Forward variant of the stream-all transport: run_stream_all_forward admits host and cache costs for layers +//! first..end, gives a consumer the forward scope and settles its rows; also consume_layer and its grouped form. use super::{ BufferHandle, Entry, Error, GPU_RING_MAX, HEADROOM, Issuer, JoinHandle, MAX_JOBS, META_CAP, OriginalExpertStager, diff --git a/crates/cuda-driver/src/original_stream_all/original_stream_all_options.rs b/crates/cuda-driver/src/original_expert_stager/stream_all/original_stream_all_options.rs similarity index 60% rename from crates/cuda-driver/src/original_stream_all/original_stream_all_options.rs rename to crates/cuda-driver/src/original_expert_stager/stream_all/original_stream_all_options.rs index 3f534071..3de99efc 100644 --- a/crates/cuda-driver/src/original_stream_all/original_stream_all_options.rs +++ b/crates/cuda-driver/src/original_expert_stager/stream_all/original_stream_all_options.rs @@ -1,5 +1,5 @@ -//! Groups the submodules `original_stream_all_options_issuer`, `original_expert_stager`, `original_stream_all` and 1... -//! Split out of `stream_all` to keep its files under the line limit. +//! Parent module of the stream-all scope: its issuer, run_stream_all, the live scope and the scope phases; +//! shares their imports and re-exports issuer_thread for the stager's worker setup. use super::{ Arc, AtomicBool, AtomicUsize, BufferHandle, Entry, Error, EventBank, GPU_RING_MAX, HEADROOM, Issuer, JoinHandle, @@ -9,13 +9,8 @@ use super::{ OriginalStreamPair, Result, SOURCE_CAP, Shared, WORKER_STACK, abi, available_memory, combine, size_of, thread, }; -#[path = "original_stream_all_options/original_stream_all_options_issuer.rs"] mod original_stream_all_options_issuer; -#[allow(unused_imports)] pub(super) use original_stream_all_options_issuer::issuer_thread; -#[path = "original_stream_all_options/original_expert_stager.rs"] mod original_expert_stager; -#[path = "original_stream_all_options/original_stream_all.rs"] mod original_stream_all; -#[path = "original_stream_all_options/stream_phases.rs"] mod stream_phases; diff --git a/crates/cuda-driver/src/original_stream_all/original_stream_all_options/original_expert_stager.rs b/crates/cuda-driver/src/original_expert_stager/stream_all/original_stream_all_options/original_expert_stager.rs similarity index 88% rename from crates/cuda-driver/src/original_stream_all/original_stream_all_options/original_expert_stager.rs rename to crates/cuda-driver/src/original_expert_stager/stream_all/original_stream_all_options/original_expert_stager.rs index 950f7a9b..955953ad 100644 --- a/crates/cuda-driver/src/original_stream_all/original_stream_all_options/original_expert_stager.rs +++ b/crates/cuda-driver/src/original_expert_stager/stream_all/original_stream_all_options/original_expert_stager.rs @@ -1,7 +1,6 @@ -//! Methods of `OriginalExpertStager`: `run_stream_all`. -//! Split out of `original_stream_all_options` to keep its files under the line limit. +//! run_stream_all: opens one all-expert stream scope over the prompt rows (preflight, budget, targets, queued jobs, +//! issuer), runs the consumer inside it and finishes the scope, which guarantees join and drain even on panic. -#[allow(unused_imports)] use super::stream_phases::{arm_scope, finish_scope, open_scope, start_or_cleanup}; use super::{ Error, OriginalExpertStager, OriginalPromptRows, OriginalStreamAll, OriginalStreamAllCompleted, diff --git a/crates/cuda-driver/src/original_stream_all/original_stream_all_options/original_stream_all.rs b/crates/cuda-driver/src/original_expert_stager/stream_all/original_stream_all_options/original_stream_all.rs similarity index 95% rename from crates/cuda-driver/src/original_stream_all/original_stream_all_options/original_stream_all.rs rename to crates/cuda-driver/src/original_expert_stager/stream_all/original_stream_all_options/original_stream_all.rs index dd71ca58..032005b4 100644 --- a/crates/cuda-driver/src/original_stream_all/original_stream_all_options/original_stream_all.rs +++ b/crates/cuda-driver/src/original_expert_stager/stream_all/original_stream_all_options/original_stream_all.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalStreamAll`: `issue_inline`, `healthy`, `give_back`, `release_unused` and 5 more. -//! Implements `Drop for OriginalStreamAll`. +//! The live stream-all scope: inline or threaded issue of copy jobs, health checks, releasing unused experts to the +//! copy/used event ring, consume_layer for producers, issuer join, cleanup, and a Drop that retains owners on failure. use super::{ BufferHandle, Entry, Error, ORIGINAL_MMQ_GROUP, Ordering, OriginalGpuStream, OriginalStreamAll, @@ -7,7 +7,6 @@ use super::{ thread, }; -#[path = "original_stream_all/walk.rs"] mod walk; impl OriginalStreamAll<'_, '_, '_, '_> { diff --git a/crates/cuda-driver/src/original_stream_all/original_stream_all_options/original_stream_all/walk.rs b/crates/cuda-driver/src/original_expert_stager/stream_all/original_stream_all_options/original_stream_all/walk.rs similarity index 100% rename from crates/cuda-driver/src/original_stream_all/original_stream_all_options/original_stream_all/walk.rs rename to crates/cuda-driver/src/original_expert_stager/stream_all/original_stream_all_options/original_stream_all/walk.rs diff --git a/crates/cuda-driver/src/original_stream_all/original_stream_all_options/original_stream_all_options_issuer.rs b/crates/cuda-driver/src/original_expert_stager/stream_all/original_stream_all_options/original_stream_all_options_issuer.rs similarity index 96% rename from crates/cuda-driver/src/original_stream_all/original_stream_all_options/original_stream_all_options_issuer.rs rename to crates/cuda-driver/src/original_expert_stager/stream_all/original_stream_all_options/original_stream_all_options_issuer.rs index bdb9d094..e8109530 100644 --- a/crates/cuda-driver/src/original_stream_all/original_stream_all_options/original_stream_all_options_issuer.rs +++ b/crates/cuda-driver/src/original_expert_stager/stream_all/original_stream_all_options/original_stream_all_options_issuer.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalStreamAllOptions`: `from_environment`, `eligible`. Methods of `EventBank`: `retire`. -//! Functions: `issuer_thread`, `issue_all`. +//! Issuer side of stream-all: options read from STRATA_PREFILL_* settings (minimum rows, issuer thread on/off), +//! event bank retirement, and the issuer thread that issues every copy job in ascending order. use super::{ Arc, Error, EventBank, Issuer, Ordering, OriginalGpuStream, OriginalPromptRows, OriginalStreamAllCompleted, diff --git a/crates/cuda-driver/src/original_stream_all/original_stream_all_options/stream_phases.rs b/crates/cuda-driver/src/original_expert_stager/stream_all/original_stream_all_options/stream_phases.rs similarity index 100% rename from crates/cuda-driver/src/original_stream_all/original_stream_all_options/stream_phases.rs rename to crates/cuda-driver/src/original_expert_stager/stream_all/original_stream_all_options/stream_phases.rs diff --git a/crates/cuda-driver/src/original_expert_stager/tests.rs b/crates/cuda-driver/src/original_expert_stager/tests.rs index cf258b03..5070efe9 100644 --- a/crates/cuda-driver/src/original_expert_stager/tests.rs +++ b/crates/cuda-driver/src/original_expert_stager/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests that pin the expert stager's stop fence: after stop returns, no worker may still be claiming a job that +//! would copy from a released source (helpers run the real claim prologue against a shared state and flag late claims). use super::*; diff --git a/crates/cuda-driver/src/original_expert_stager_ffi/tests.rs b/crates/cuda-driver/src/original_expert_stager_ffi/tests.rs index c8366693..d917ad28 100644 --- a/crates/cuda-driver/src/original_expert_stager_ffi/tests.rs +++ b/crates/cuda-driver/src/original_expert_stager_ffi/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests of the stager's raw copy boundary: a CopyJob refuses empty, oversized or overlapping parts and writes nothing +//! on refusal, and an expert file map hands out only parts inside the mapping (Windows and Unix test mappings). use super::*; diff --git a/crates/cuda-driver/src/original_file_expert_source.rs b/crates/cuda-driver/src/original_file_expert_source.rs index f6d78040..810a99d2 100644 --- a/crates/cuda-driver/src/original_file_expert_source.rs +++ b/crates/cuda-driver/src/original_file_expert_source.rs @@ -117,18 +117,12 @@ pub(crate) enum OriginalFileStreamSource<'source, 'ctx> { } mod original_resident_options_and_blob; -#[allow(unused_imports)] -use original_resident_options_and_blob::atoi; -#[allow(unused_imports)] use original_resident_options_and_blob::key; -#[allow(unused_imports)] use original_resident_options_and_blob::vec_filled; mod file_expert_source_swap_exchanges; mod original_file_expert_source_operations; #[cfg(windows)] -#[allow(unused_imports)] use file_expert_source_swap_exchanges::available_memory; mod available_memory; #[cfg(unix)] -#[allow(unused_imports)] use available_memory::available_memory; diff --git a/crates/cuda-driver/src/original_file_expert_source/available_memory.rs b/crates/cuda-driver/src/original_file_expert_source/available_memory.rs index 6c1de3fd..b85f4e19 100644 --- a/crates/cuda-driver/src/original_file_expert_source/available_memory.rs +++ b/crates/cuda-driver/src/original_file_expert_source/available_memory.rs @@ -1,5 +1,5 @@ -//! Functions: `available_memory`, `text`, `value`, `meminfo_available` and 6 more. -//! Split out of `original_file_expert_source` to keep its files under the line limit. +//! Host memory available to the file expert source on Unix: MemAvailable from /proc/meminfo, lowered by the cgroup +//! memory limits of the process and its ancestors, so budget checks respect containers; any parse failure is an error. use super::{Error, Result}; diff --git a/crates/cuda-driver/src/original_file_expert_source/file_expert_source_swap_exchanges.rs b/crates/cuda-driver/src/original_file_expert_source/file_expert_source_swap_exchanges.rs index ad134c52..b5d68d5c 100644 --- a/crates/cuda-driver/src/original_file_expert_source/file_expert_source_swap_exchanges.rs +++ b/crates/cuda-driver/src/original_file_expert_source/file_expert_source_swap_exchanges.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalFileExpertSource`: `reserve_exchanges`, `admit_exchanges`, `replace_exchange`, `stage_swaps` ... -//! Implements `Drop for OriginalFileExpertSource`. Functions: `available_memory`. Defines `Candidate`. +//! File expert source exchange arena: reserving it, staging swaps by copying outgoing cache slots into exchange +//! entries, and committing them once the cache fills are complete; also Drop and the Windows available_memory. use super::{ EXPERTS, Error, Exchange, N, NONE, OriginalExpertCache, OriginalFileExpertSource, OriginalSourceSwap, Result, abi, diff --git a/crates/cuda-driver/src/original_file_expert_source/original_file_expert_source_operations/build_phases.rs b/crates/cuda-driver/src/original_file_expert_source/original_file_expert_source_operations/build_phases.rs index 43544c1b..173e4f61 100644 --- a/crates/cuda-driver/src/original_file_expert_source/original_file_expert_source_operations/build_phases.rs +++ b/crates/cuda-driver/src/original_file_expert_source/original_file_expert_source_operations/build_phases.rs @@ -1,6 +1,5 @@ //! STRA-338 size: the phases of `OriginalFileExpertSource::build_cache_complement`, extracted in call order. -#[allow(unused_imports)] use super::fill_workers::{run_fill_workers, straddling_cut}; use super::{ Context, EXPERTS, Error, GIB, LAYERS, META_CAP, N, NONE, OriginalExpertCache, OriginalFileExpertSource, diff --git a/crates/cuda-driver/src/original_file_expert_source/original_file_expert_source_operations/file_expert_source_cache_complement.rs b/crates/cuda-driver/src/original_file_expert_source/original_file_expert_source_operations/file_expert_source_cache_complement.rs index a5ae47f1..672cf64a 100644 --- a/crates/cuda-driver/src/original_file_expert_source/original_file_expert_source_operations/file_expert_source_cache_complement.rs +++ b/crates/cuda-driver/src/original_file_expert_source/original_file_expert_source_operations/file_expert_source_cache_complement.rs @@ -1,7 +1,6 @@ -//! Methods of `OriginalFileExpertSource`: `build_cache_complement`. -//! Split out of `original_file_expert_source_methods` to keep its files under the line limit. +//! Builds the cache complement: after the primary cache is complete and fenced, plans and fills one host arena +//! (pinned if asked) with every expert the cache does not hold, cleaning up or leaking the arena by failure kind. -#[allow(unused_imports)] use super::build_phases::{ArenaFillPlan, alloc_failed, discard_arena, leak_arena, poison_parts}; use super::{Error, OriginalExpertCache, OriginalFileExpertSource, OriginalResidentOptions, Result, combine}; diff --git a/crates/cuda-driver/src/original_file_expert_source/original_file_expert_source_operations/file_expert_source_prefetch.rs b/crates/cuda-driver/src/original_file_expert_source/original_file_expert_source_operations/file_expert_source_prefetch.rs index 525f61db..5d41ea00 100644 --- a/crates/cuda-driver/src/original_file_expert_source/original_file_expert_source_operations/file_expert_source_prefetch.rs +++ b/crates/cuda-driver/src/original_file_expert_source/original_file_expert_source_operations/file_expert_source_prefetch.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalFileExpertSource`: `prefetch_impl`, `prefetch_jobs`, `claim_prefetch`, `note_warm_hit` and 7 ... -//! Functions: `fetch_worker`, `scoped_fetch`. Defines `FetchOutcomes`. +//! File expert source prefetch and teardown: claims stages for wanted experts, copies them in parallel worker +//! threads, accounts hits and fetches, and closes or retains the source's arenas and stages. use super::{ AtomicUsize, EXPERTS, Error, Instant, LAYERS, Mutex, N, NONE, Ordering, OriginalFileExpertSource, Result, abi, diff --git a/crates/cuda-driver/src/original_file_expert_source/original_file_expert_source_operations/file_expert_source_stages_and_blobs.rs b/crates/cuda-driver/src/original_file_expert_source/original_file_expert_source_operations/file_expert_source_stages_and_blobs.rs index d35bb7a1..1003f5d8 100644 --- a/crates/cuda-driver/src/original_file_expert_source/original_file_expert_source_operations/file_expert_source_stages_and_blobs.rs +++ b/crates/cuda-driver/src/original_file_expert_source/original_file_expert_source_operations/file_expert_source_stages_and_blobs.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalFileExpertSource`: `plan`, `claim_stage`, `stage_victim`, `grow_stage` and 13 more. -//! Functions: `omit_table`. +//! File expert source stages and blobs: the layout plan, an LRU of staged experts, and blob reads from arena, +//! exchange, stage or the file itself (blob, copy_blob, warm, prefetch), with read counters. use super::{ EXPERTS, Error, Instant, LAYERS, N, NONE, OriginalFileExpertSource, OriginalFileSourceBlob, Result, Stage, abi, diff --git a/crates/cuda-driver/src/original_file_expert_source/original_file_expert_source_operations/file_expert_source_status_counters.rs b/crates/cuda-driver/src/original_file_expert_source/original_file_expert_source_operations/file_expert_source_status_counters.rs index f9503201..57cdc19e 100644 --- a/crates/cuda-driver/src/original_file_expert_source/original_file_expert_source_operations/file_expert_source_status_counters.rs +++ b/crates/cuda-driver/src/original_file_expert_source/original_file_expert_source_operations/file_expert_source_status_counters.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalFileExpertSource`: `live`, `validate_context`, `parts`, `source_digest` and 15 more. -//! Split out of `original_file_expert_source_methods` to keep its files under the line limit. +//! File expert source status and accounting: liveness and context checks, expert part views from the mapped file, +//! residency and pinned-byte counters, per-layer begin, and the host metadata charge and admission of extra bytes. use super::{ Context, Error, Exchange, GIB, LAYERS, LayerRole, META_CAP, NONE, OriginalFileExpertSource, diff --git a/crates/cuda-driver/src/original_file_expert_source/original_resident_options_and_blob.rs b/crates/cuda-driver/src/original_file_expert_source/original_resident_options_and_blob.rs index 0241d9e2..5da701fc 100644 --- a/crates/cuda-driver/src/original_file_expert_source/original_resident_options_and_blob.rs +++ b/crates/cuda-driver/src/original_file_expert_source/original_resident_options_and_blob.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalResidentOptions`: `from_environment`. -//! Methods of `OriginalFileSourceBlob`: `bytes`, `layer`, `expert`, `source_digest` and 6 more. +//! Resident-source options (defaults, STRATA_PARTIAL_PIN settings), accessors of a file source blob (bytes, parts, +//! role sizes, pinned state, device alias), and the Context constructor that assembles a file expert source. use super::{ Cell, Context, EXPERTS, Error, ExpertFileMap, FileExpertSourceLease, GIB, HashMap, LAYERS, LayerRole, N, diff --git a/crates/cuda-driver/src/original_file_expert_source_ffi/tests.rs b/crates/cuda-driver/src/original_file_expert_source_ffi/tests.rs index ea4bc9dd..2b2c875c 100644 --- a/crates/cuda-driver/src/original_file_expert_source_ffi/tests.rs +++ b/crates/cuda-driver/src/original_file_expert_source_ffi/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests of the pinned/host arena boundary: write, part and overwrite stay inside the block, copy records refuse +//! overlap, empty, null or oversize pieces, and the partial-pin cap parses a positive prefix or falls back to 24 GiB. use super::*; diff --git a/crates/cuda-driver/src/original_gpu_schedule.rs b/crates/cuda-driver/src/original_gpu_schedule.rs index b931580a..59eb4e86 100644 --- a/crates/cuda-driver/src/original_gpu_schedule.rs +++ b/crates/cuda-driver/src/original_gpu_schedule.rs @@ -1,7 +1,6 @@ //! Original CUDA scheduling owners. Capture resources are real owned/borrowed //! producers, retained through every replay and through uncertain retirement. //! No public raw stream, graph, event, kernel address or readiness constructor. -#[path = "original_gpu_schedule_ffi.rs"] mod abi; use crate::{Context, Error, Result, combine}; use std::{ @@ -47,7 +46,6 @@ pub trait OriginalGraphResources: resources::Sealed { } } -#[path = "mtp_original_full_graph.rs"] mod mtp_full_graph; /// `CUDA_ERROR_OUT_OF_MEMORY` of the driver API. Not sticky: the context is intact after it. const CUDA_ERROR_OUT_OF_MEMORY: i32 = 2; @@ -148,11 +146,9 @@ pub struct OriginalGraphRegistry<'ctx, R: OriginalGraphResources> { } #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] -#[path = "original_gpu_head_bridge.rs"] mod native_head_bridge; #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] -#[path = "original_gpu_verify_bridge.rs"] mod verifier_bridge; /// Operator timing of `capture_owned` (host ms spent capturing, then instantiating + uploading), summed per thread @@ -212,29 +208,19 @@ mod oom_tests { } mod transport; -#[allow(unused_imports)] use transport::call; -#[allow(unused_imports)] use transport::call_unless; -#[allow(unused_imports)] use transport::healthy; -#[allow(unused_imports)] use transport::injected_window_oom; -#[allow(unused_imports)] pub(crate) use transport::is_graph_out_of_memory; -#[allow(unused_imports)] use transport::poison; -#[allow(unused_imports)] +#[cfg(test)] use transport::poisons; -#[allow(unused_imports)] use transport::transport; mod original_gpu_stream; mod set_side_streams_wanted; -#[allow(unused_imports)] use set_side_streams_wanted::drop_side; -#[allow(unused_imports)] use set_side_streams_wanted::make_side; -#[allow(unused_imports)] pub(crate) use set_side_streams_wanted::set_side_streams_wanted; mod original_gpu_graph; mod original_graph_key; diff --git a/crates/cuda-driver/src/original_gpu_schedule_ffi.rs b/crates/cuda-driver/src/original_gpu_schedule/abi.rs similarity index 85% rename from crates/cuda-driver/src/original_gpu_schedule_ffi.rs rename to crates/cuda-driver/src/original_gpu_schedule/abi.rs index 58653c56..854dfbd9 100644 --- a/crates/cuda-driver/src/original_gpu_schedule_ffi.rs +++ b/crates/cuda-driver/src/original_gpu_schedule/abi.rs @@ -1,7 +1,6 @@ //! Private CUDA Driver ABI, matching Original runtime stream/event/graph calls. use crate::{Error, Result}; #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] -#[path = "original_gpu_schedule_ffi/platform.rs"] mod platform; #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] pub(crate) use platform::Api; @@ -12,5 +11,4 @@ pub(crate) use platform::Api; )))] pub(crate) struct Api; -#[path = "original_gpu_schedule_ffi/api.rs"] mod api; diff --git a/crates/cuda-driver/src/original_gpu_schedule_ffi/api.rs b/crates/cuda-driver/src/original_gpu_schedule/abi/api.rs similarity index 93% rename from crates/cuda-driver/src/original_gpu_schedule_ffi/api.rs rename to crates/cuda-driver/src/original_gpu_schedule/abi/api.rs index 53e9707b..1f368af0 100644 --- a/crates/cuda-driver/src/original_gpu_schedule_ffi/api.rs +++ b/crates/cuda-driver/src/original_gpu_schedule/abi/api.rs @@ -1,5 +1,5 @@ -//! Methods of `Api`: `load`, `stream_create`, `stream_destroy`, `stream_sync` and 23 more. -//! Split out of `abi` to keep its files under the line limit. +//! Api stand-in for platforms without the CUDA driver (feature off, or not 64-bit Linux/Windows): every +//! call returns UnsupportedPlatform, so the GPU schedule compiles everywhere and fails cleanly at load. #[cfg(not(all( feature = "cuda-driver", diff --git a/crates/cuda-driver/src/original_gpu_schedule_ffi/platform.rs b/crates/cuda-driver/src/original_gpu_schedule/abi/platform.rs similarity index 90% rename from crates/cuda-driver/src/original_gpu_schedule_ffi/platform.rs rename to crates/cuda-driver/src/original_gpu_schedule/abi/platform.rs index 2bf1ff75..0763ddac 100644 --- a/crates/cuda-driver/src/original_gpu_schedule_ffi/platform.rs +++ b/crates/cuda-driver/src/original_gpu_schedule/abi/platform.rs @@ -1,5 +1,5 @@ -//! Defines `Handle`, `Library`, `StreamCreate` and 21 more. -//! Split out of `abi` to keep its files under the line limit. +//! Declarations of the GPU schedule's driver table: the C signatures of the CUDA driver calls it binds, the Api +//! struct holding them with the refused-call latches, and the children that load and call them. use super::{Error, Result}; use std::ffi::{CStr, c_void}; @@ -72,19 +72,12 @@ pub(crate) struct Api { write_refused: std::sync::atomic::AtomicBool, } -#[path = "platform/library_drop.rs"] mod library_drop; #[cfg(target_os = "linux")] -#[allow(unused_imports)] use library_drop::callback_warmup_enabled; -#[allow(unused_imports)] use library_drop::check; #[cfg(target_os = "linux")] -#[allow(unused_imports)] use library_drop::noop_host_fn; -#[allow(unused_imports)] use library_drop::raise_after_copies; -#[path = "platform/api.rs"] mod api; -#[path = "platform/async_copies_and_flag_writes.rs"] mod async_copies_and_flag_writes; diff --git a/crates/cuda-driver/src/original_gpu_schedule_ffi/platform/api.rs b/crates/cuda-driver/src/original_gpu_schedule/abi/platform/api.rs similarity index 98% rename from crates/cuda-driver/src/original_gpu_schedule_ffi/platform/api.rs rename to crates/cuda-driver/src/original_gpu_schedule/abi/platform/api.rs index d579ee40..92d28fa8 100644 --- a/crates/cuda-driver/src/original_gpu_schedule_ffi/platform/api.rs +++ b/crates/cuda-driver/src/original_gpu_schedule/abi/platform/api.rs @@ -1,5 +1,5 @@ -//! Methods of `Api`: `load`, `stream_create`, `warm_callback_thread`, `warm_callback_thread` and 19 more. -//! Functions: `symbol`. +//! Driver table of the GPU schedule: dlopen of the CUDA driver and binding of every symbol (plus the optional batch +//! copy and stream-write ones), then the stream, event, graph capture and launch calls and callback-thread warm-up. use super::{ Api, Begin, CStr, CopyBatch, CopyH2d, End, Error, EventCall, EventCreate, EventElapsed, EventRecord, GraphCall, diff --git a/crates/cuda-driver/src/original_gpu_schedule_ffi/platform/async_copies_and_flag_writes.rs b/crates/cuda-driver/src/original_gpu_schedule/abi/platform/async_copies_and_flag_writes.rs similarity index 96% rename from crates/cuda-driver/src/original_gpu_schedule_ffi/platform/async_copies_and_flag_writes.rs rename to crates/cuda-driver/src/original_gpu_schedule/abi/platform/async_copies_and_flag_writes.rs index 0b9954fb..0a54018a 100644 --- a/crates/cuda-driver/src/original_gpu_schedule_ffi/platform/async_copies_and_flag_writes.rs +++ b/crates/cuda-driver/src/original_gpu_schedule/abi/platform/async_copies_and_flag_writes.rs @@ -1,5 +1,5 @@ -//! Methods of `Api`: `copy_h2d`, `copy_h2d_many`, `copy_h2d_batched`, `can_write_u32` and 3 more. -//! Split out of `platform` to keep its files under the line limit. +//! Asynchronous host-to-device copies of the GPU schedule (single, grouped or one cuMemcpyBatchAsync) and the stream +//! writes or host callbacks that raise a ring flag after the copies, with fallback once the driver refuses a call. use super::{Api, BatchAttributes, CopyBatch, Error, Handle, Raise, Result, check, raise_after_copies}; diff --git a/crates/cuda-driver/src/original_gpu_schedule_ffi/platform/library_drop.rs b/crates/cuda-driver/src/original_gpu_schedule/abi/platform/library_drop.rs similarity index 88% rename from crates/cuda-driver/src/original_gpu_schedule_ffi/platform/library_drop.rs rename to crates/cuda-driver/src/original_gpu_schedule/abi/platform/library_drop.rs index 70ce463e..659a95c7 100644 --- a/crates/cuda-driver/src/original_gpu_schedule_ffi/platform/library_drop.rs +++ b/crates/cuda-driver/src/original_gpu_schedule/abi/platform/library_drop.rs @@ -1,5 +1,5 @@ -//! Implements `Drop for Library`. Functions: `check`, `raise_after_copies`, `noop_host_fn`, `callback_warmup_enabled`. -//! Split out of `platform` to keep its files under the line limit. +//! Small helpers of the driver table: dlclose on Drop, mapping a driver return code to an error, the host function +//! that raises a flag word, and the no-op callback and LELEKA_CB_WARMUP switch used to warm the callback thread. use super::{Error, Library, Raise, Result, c_void}; diff --git a/crates/cuda-driver/src/mtp_original_full_graph.rs b/crates/cuda-driver/src/original_gpu_schedule/mtp_full_graph.rs similarity index 100% rename from crates/cuda-driver/src/mtp_original_full_graph.rs rename to crates/cuda-driver/src/original_gpu_schedule/mtp_full_graph.rs diff --git a/crates/cuda-driver/src/original_gpu_head_bridge.rs b/crates/cuda-driver/src/original_gpu_schedule/native_head_bridge.rs similarity index 100% rename from crates/cuda-driver/src/original_gpu_head_bridge.rs rename to crates/cuda-driver/src/original_gpu_schedule/native_head_bridge.rs diff --git a/crates/cuda-driver/src/original_gpu_schedule/original_gpu_graph.rs b/crates/cuda-driver/src/original_gpu_schedule/original_gpu_graph.rs index 68e200fb..f647e168 100644 --- a/crates/cuda-driver/src/original_gpu_schedule/original_gpu_graph.rs +++ b/crates/cuda-driver/src/original_gpu_schedule/original_gpu_graph.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalGpuGraph`: `validate`, `nodes`, `policy`, `validate_context` and 14 more. -//! Methods of `OriginalGraphFlight`: `query`, `wait`, `wait_ms`. +//! A captured CUDA graph executable of the GPU schedule: enqueue or launch on a stream, the in-flight handle with +//! query/wait/timeout, the receipts (stream drain, event, wait) that allow its resources to be reused, and close/Drop. use super::{ Context, Duration, Error, Instant, OriginalCapturePolicy, OriginalGpuEvent, OriginalGpuGraph, OriginalGpuStream, diff --git a/crates/cuda-driver/src/original_gpu_schedule/original_gpu_stream.rs b/crates/cuda-driver/src/original_gpu_schedule/original_gpu_stream.rs index 5ef95ac0..75638180 100644 --- a/crates/cuda-driver/src/original_gpu_schedule/original_gpu_stream.rs +++ b/crates/cuda-driver/src/original_gpu_schedule/original_gpu_stream.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalGpuStream`: `validate_context`, `is_failed`, `priority`, `query` and 9 more. -//! Split out of `original_gpu_schedule` to keep its files under the line limit. +//! The GPU schedule's stream handle: context and failure checks, observational priority, query and synchronize, +//! enqueue of host-to-device copies and flag raises, graph capture on the stream, and the drain receipt. use super::{ CUDA_ERROR_OUT_OF_MEMORY, Cell, Context, Error, Instant, OriginalCapture, OriginalCapturePolicy, OriginalGpuGraph, diff --git a/crates/cuda-driver/src/original_gpu_schedule/original_graph_key.rs b/crates/cuda-driver/src/original_gpu_schedule/original_graph_key.rs index abe3260f..fd8b616f 100644 --- a/crates/cuda-driver/src/original_gpu_schedule/original_graph_key.rs +++ b/crates/cuda-driver/src/original_gpu_schedule/original_graph_key.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalGraphKey`: `validate`, `policy`. -//! Methods of `OriginalGraphRegistry`: `new`, `planned_metadata_bytes`, `metadata_bytes`, `captures` and 7 more. +//! Graph identity and cache: OriginalGraphKey names a capturable graph (layer pre/post, token, verify window, MTP +//! steps) with range check and capture policy; OriginalGraphRegistry records, looks up and clears cached graphs. use super::{ Context, Error, OriginalCapture, OriginalCapturePolicy, OriginalGpuGraph, OriginalGpuStream, OriginalGraphKey, diff --git a/crates/cuda-driver/src/original_gpu_schedule/set_side_streams_wanted.rs b/crates/cuda-driver/src/original_gpu_schedule/set_side_streams_wanted.rs index 108a45f8..61265544 100644 --- a/crates/cuda-driver/src/original_gpu_schedule/set_side_streams_wanted.rs +++ b/crates/cuda-driver/src/original_gpu_schedule/set_side_streams_wanted.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalCapture`: `has_side`, `side_fork`, `side_end`, `side_join` and 2 more. -//! Methods of `OriginalGpuEvent`: `handle`, `validate_context`, `record`, `wait_on` and 6 more. +//! Side streams and events of the GPU schedule: the switch for a verifier-window capture to fork two side streams, +//! their creation/teardown, fork/end/join in a capture, and the OriginalGpuEvent record, wait, query, timing and close. use super::{ Context, Error, OriginalCapture, OriginalEventKind, OriginalGpuEvent, OriginalGpuStream, Rc, Result, diff --git a/crates/cuda-driver/src/original_gpu_schedule/transport.rs b/crates/cuda-driver/src/original_gpu_schedule/transport.rs index a674eadc..a6366a24 100644 --- a/crates/cuda-driver/src/original_gpu_schedule/transport.rs +++ b/crates/cuda-driver/src/original_gpu_schedule/transport.rs @@ -1,5 +1,5 @@ -//! Methods of `Stream`: `bump`, `validate`, `run`, `close` and 1 more. -//! Methods of `Context`: `original_default_gpu_stream`, `original_gpu_stream`, `original_gpu_event`. +//! Driver-call plumbing of the GPU schedule: error classification (transport, recoverable out-of-memory), poisoning of +//! the context on failure, the per-stream run/close guard, and the Context constructors for streams and events. use super::{ CUDA_ERROR_OUT_OF_MEMORY, Cell, Context, Error, OriginalCapturePolicy, OriginalEventKind, OriginalGpuEvent, diff --git a/crates/cuda-driver/src/original_gpu_verify_bridge.rs b/crates/cuda-driver/src/original_gpu_schedule/verifier_bridge.rs similarity index 100% rename from crates/cuda-driver/src/original_gpu_verify_bridge.rs rename to crates/cuda-driver/src/original_gpu_schedule/verifier_bridge.rs diff --git a/crates/cuda-driver/src/original_moe_prompt_device.rs b/crates/cuda-driver/src/original_moe_prompt_device.rs index 09a5c02e..710f87c2 100644 --- a/crates/cuda-driver/src/original_moe_prompt_device.rs +++ b/crates/cuda-driver/src/original_moe_prompt_device.rs @@ -128,17 +128,11 @@ struct GemmSize { } mod blank; -#[allow(unused_imports)] use blank::blank; -#[allow(unused_imports)] use blank::common; -#[allow(unused_imports)] use blank::dequant_index; -#[allow(unused_imports)] use blank::gemm; -#[allow(unused_imports)] use blank::kernel; -#[allow(unused_imports)] use blank::phase; mod original_moe_prompt_device_drop; mod original_moe_prompt_device_operations; diff --git a/crates/cuda-driver/src/original_moe_prompt_device/blank.rs b/crates/cuda-driver/src/original_moe_prompt_device/blank.rs index c94da085..5d06526d 100644 --- a/crates/cuda-driver/src/original_moe_prompt_device/blank.rs +++ b/crates/cuda-driver/src/original_moe_prompt_device/blank.rs @@ -1,5 +1,5 @@ -//! Methods of `Context`: `original_moe_prompt_device`. Functions: `blank`, `kernel`, `gemm`, `phase` and 2 more. -//! Split out of `original_moe_prompt_device` to keep its files under the line limit. +//! Shared builders of the MoE prompt device: zeroed host buffers, kernel and GEMM command constructors, span +//! lookups for phase and common prompt-row roles, the dequant kernel index per GDN format, and the Context entry point. use super::{ A, BufferHandle, Command, Context, Error, GdnNativeFormat, GemmOperands, GemmSize, KernelArguments, diff --git a/crates/cuda-driver/src/original_moe_prompt_device/original_moe_prompt_device_drop.rs b/crates/cuda-driver/src/original_moe_prompt_device/original_moe_prompt_device_drop.rs index 295a5020..44563657 100644 --- a/crates/cuda-driver/src/original_moe_prompt_device/original_moe_prompt_device_drop.rs +++ b/crates/cuda-driver/src/original_moe_prompt_device/original_moe_prompt_device_drop.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalMoePromptLayer`: `experts`, `counts`, `metadata_bytes`, `execute_original_copy_ring` and 8 more. -//! Implements `Drop for OriginalMoePromptDevice`. Functions: `source_in_layer`. +//! Per-layer MoE prompt execution (OriginalMoePromptLayer): route order and counts, the copy-ring, MMQ and stream-all +//! expert executions, the slot-table upload and weighted combine finish; also Drop for OriginalMoePromptDevice. use super::{ A, BufferHandle, Command, Error, ExpertStreamLayer, MappedExpertBank, MmqWorkspace, NativeBatchWorkspace, diff --git a/crates/cuda-driver/src/original_moe_prompt_device/original_moe_prompt_device_operations/original_moe_prompt_device_new_run.rs b/crates/cuda-driver/src/original_moe_prompt_device/original_moe_prompt_device_operations/original_moe_prompt_device_new_run.rs index 87c6dfee..4d9fb06b 100644 --- a/crates/cuda-driver/src/original_moe_prompt_device/original_moe_prompt_device_operations/original_moe_prompt_device_new_run.rs +++ b/crates/cuda-driver/src/original_moe_prompt_device/original_moe_prompt_device_operations/original_moe_prompt_device_new_run.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalMoePromptDevice`: `new`, `allocate_and_load`, `allocated_bytes`, `handle` and 9 more. -//! Split out of `original_moe_prompt_device_methods` to keep its files under the line limit. +//! Construction and command runner of the MoE prompt device: budget check, status and scratch allocation, kernel +//! module loading, weight and span admission, and run, which issues commands and checks the finite-status words. use super::{ A, BufferHandle, Command, Context, DQ_ENTRIES, DeviceBuffer, Error, KernelModule, MOE_ENTRIES, diff --git a/crates/cuda-driver/src/original_moe_prompt_device/original_moe_prompt_device_operations/original_moe_prompt_device_prepare.rs b/crates/cuda-driver/src/original_moe_prompt_device/original_moe_prompt_device_operations/original_moe_prompt_device_prepare.rs index a76deaae..c324864d 100644 --- a/crates/cuda-driver/src/original_moe_prompt_device/original_moe_prompt_device_operations/original_moe_prompt_device_prepare.rs +++ b/crates/cuda-driver/src/original_moe_prompt_device/original_moe_prompt_device_operations/original_moe_prompt_device_prepare.rs @@ -1,7 +1,6 @@ -//! Methods of `OriginalMoePromptDevice`: `prepare`, `close`. -//! Split out of `original_moe_prompt_device_methods` to keep its files under the line limit. +//! MoE prepare phase: validates the GR-read rows against the device, runs the router and grouping commands and builds +//! the per-layer route plan (expert order and counts) that the layer then executes; also the explicit close. -#[allow(unused_imports)] use super::prepare_phases::{MOE_NAMES, route_plan}; use super::{ DeviceBuffer, Error, NativeBatchWorkspace, OriginalDeviceGrRead, OriginalMoePromptDevice, OriginalMoePromptLayer, diff --git a/crates/cuda-driver/src/original_moe_prompt_device/original_moe_prompt_device_operations/original_moe_prompt_device_release.rs b/crates/cuda-driver/src/original_moe_prompt_device/original_moe_prompt_device_operations/original_moe_prompt_device_release.rs index 9f29ad81..0fb26b0a 100644 --- a/crates/cuda-driver/src/original_moe_prompt_device/original_moe_prompt_device_operations/original_moe_prompt_device_release.rs +++ b/crates/cuda-driver/src/original_moe_prompt_device/original_moe_prompt_device_operations/original_moe_prompt_device_release.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalMoePromptDevice`: `close_inner`, `is_released`, `retain_poisoned`. -//! Split out of `original_moe_prompt_device_methods` to keep its files under the line limit. +//! Teardown of the MoE prompt device: closes kernel modules and releases buffers under the context guard, or leaks +//! them when the context is poisoned so a failed close never frees GPU memory a stuck stream may still touch. use super::{Error, OriginalMoePromptDevice, Result, combine}; diff --git a/crates/cuda-driver/src/original_mtp_actor.rs b/crates/cuda-driver/src/original_mtp_actor.rs index 28f5c61e..46d2e892 100644 --- a/crates/cuda-driver/src/original_mtp_actor.rs +++ b/crates/cuda-driver/src/original_mtp_actor.rs @@ -22,7 +22,6 @@ //! state. This is not a numerical, serving or device-completion certificate. #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] -#[path = "original_mtp_actor_loaded.rs"] mod loaded; #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] pub use loaded::{OriginalMtpActor, OriginalMtpLoadEvidence, OriginalMtpLoadMeter, OriginalMtpLoadedParts}; diff --git a/crates/cuda-driver/src/original_mtp_actor_loaded.rs b/crates/cuda-driver/src/original_mtp_actor/loaded.rs similarity index 93% rename from crates/cuda-driver/src/original_mtp_actor_loaded.rs rename to crates/cuda-driver/src/original_mtp_actor/loaded.rs index 8c071127..193eb754 100644 --- a/crates/cuda-driver/src/original_mtp_actor_loaded.rs +++ b/crates/cuda-driver/src/original_mtp_actor/loaded.rs @@ -75,13 +75,8 @@ pub struct OriginalMtpActor<'ctx> { draft_vocabulary: Option, } -#[path = "original_mtp_actor_loaded/inconsistent.rs"] mod inconsistent; -#[allow(unused_imports)] use inconsistent::inconsistent; -#[allow(unused_imports)] use inconsistent::mismatch; -#[path = "original_mtp_actor_loaded/original_mtp_actor.rs"] mod original_mtp_actor; -#[path = "original_mtp_actor_loaded/original_mtp_actor_drop.rs"] mod original_mtp_actor_drop; diff --git a/crates/cuda-driver/src/original_mtp_actor_loaded/inconsistent.rs b/crates/cuda-driver/src/original_mtp_actor/loaded/inconsistent.rs similarity index 87% rename from crates/cuda-driver/src/original_mtp_actor_loaded/inconsistent.rs rename to crates/cuda-driver/src/original_mtp_actor/loaded/inconsistent.rs index e2688a35..abcc659f 100644 --- a/crates/cuda-driver/src/original_mtp_actor_loaded/inconsistent.rs +++ b/crates/cuda-driver/src/original_mtp_actor/loaded/inconsistent.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalMtpLoadMeter`: `start`, `finish`. Functions: `inconsistent`, `mismatch`. -//! Split out of `loaded` to keep its files under the line limit. +//! Load accounting of the MTP draft actor: OriginalMtpLoadMeter measures the VRAM a load added (monotonic, same +//! device) and the helpers that build the load-failure errors for inconsistent owners or mismatched facts. use super::{ Context, Error, OriginalMtpDraftHead, OriginalMtpLoadEvidence, OriginalMtpLoadFailure, OriginalMtpLoadMeter, diff --git a/crates/cuda-driver/src/original_mtp_actor_loaded/original_mtp_actor.rs b/crates/cuda-driver/src/original_mtp_actor/loaded/original_mtp_actor.rs similarity index 71% rename from crates/cuda-driver/src/original_mtp_actor_loaded/original_mtp_actor.rs rename to crates/cuda-driver/src/original_mtp_actor/loaded/original_mtp_actor.rs index 9e19983b..23620f29 100644 --- a/crates/cuda-driver/src/original_mtp_actor_loaded/original_mtp_actor.rs +++ b/crates/cuda-driver/src/original_mtp_actor/loaded/original_mtp_actor.rs @@ -1,5 +1,5 @@ -//! Groups the submodules `draft_rounds`, `original_mtp_actor_adopt_loaded`. -//! Split out of `loaded` to keep its files under the line limit. +//! Parent module of the MTP draft actor: one child for adopting loaded owners and one for draft rounds, +//! both adding methods to OriginalMtpActor; shares their imports. use super::{ AcceptedWindow, ActorRefusal, CompletedOriginalMtpDraft, Context, CoupledDraftHost, CoupledPlan, CoupledPreference, @@ -10,7 +10,5 @@ use super::{ setup_disposition, }; -#[path = "original_mtp_actor/draft_rounds.rs"] mod draft_rounds; -#[path = "original_mtp_actor/original_mtp_actor_adopt_loaded.rs"] mod original_mtp_actor_adopt_loaded; diff --git a/crates/cuda-driver/src/original_mtp_actor_loaded/original_mtp_actor/draft_rounds.rs b/crates/cuda-driver/src/original_mtp_actor/loaded/original_mtp_actor/draft_rounds.rs similarity index 100% rename from crates/cuda-driver/src/original_mtp_actor_loaded/original_mtp_actor/draft_rounds.rs rename to crates/cuda-driver/src/original_mtp_actor/loaded/original_mtp_actor/draft_rounds.rs diff --git a/crates/cuda-driver/src/original_mtp_actor_loaded/original_mtp_actor/original_mtp_actor_adopt_loaded.rs b/crates/cuda-driver/src/original_mtp_actor/loaded/original_mtp_actor/original_mtp_actor_adopt_loaded.rs similarity index 97% rename from crates/cuda-driver/src/original_mtp_actor_loaded/original_mtp_actor/original_mtp_actor_adopt_loaded.rs rename to crates/cuda-driver/src/original_mtp_actor/loaded/original_mtp_actor/original_mtp_actor_adopt_loaded.rs index aa3f2858..ed5c3d0d 100644 --- a/crates/cuda-driver/src/original_mtp_actor_loaded/original_mtp_actor/original_mtp_actor_adopt_loaded.rs +++ b/crates/cuda-driver/src/original_mtp_actor/loaded/original_mtp_actor/original_mtp_actor_adopt_loaded.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalMtpActor`: `adopt`, `admit`, `check_loaded`, `coupled_setup` and 22 more. -//! Split out of `original_mtp_actor` to keep its files under the line limit. +//! Adoption and accessors of the MTP draft actor: takes the loaded drafter, ring and weights, verifies them against the +//! plan and load evidence, sets up coupled drafting, and exposes the settings, restore and end-of-request calls. use super::{ ActorRefusal, Context, CoupledDraftHost, CoupledPlan, CoupledPreference, CoupledSetupReceipt, DraftSettings, Error, diff --git a/crates/cuda-driver/src/original_mtp_actor_loaded/original_mtp_actor_drop.rs b/crates/cuda-driver/src/original_mtp_actor/loaded/original_mtp_actor_drop.rs similarity index 53% rename from crates/cuda-driver/src/original_mtp_actor_loaded/original_mtp_actor_drop.rs rename to crates/cuda-driver/src/original_mtp_actor/loaded/original_mtp_actor_drop.rs index 15c47de1..97faa2ec 100644 --- a/crates/cuda-driver/src/original_mtp_actor_loaded/original_mtp_actor_drop.rs +++ b/crates/cuda-driver/src/original_mtp_actor/loaded/original_mtp_actor_drop.rs @@ -1,5 +1,4 @@ -//! Implements `Drop for OriginalMtpActor`. -//! Split out of `loaded` to keep its files under the line limit. +//! Drop glue of the loaded MTP actor: dropping it closes the device resources it still holds, ignoring close errors. use super::OriginalMtpActor; diff --git a/crates/cuda-driver/src/original_mtp_bank.rs b/crates/cuda-driver/src/original_mtp_bank.rs index 68178e74..aea028e7 100644 --- a/crates/cuda-driver/src/original_mtp_bank.rs +++ b/crates/cuda-driver/src/original_mtp_bank.rs @@ -305,5 +305,4 @@ pub fn original_mtp_draft_vocab_bytes(directory: &Path) -> Option { } #[cfg(all(test, any(target_os = "linux", target_os = "windows"), target_arch = "x86_64"))] -#[path = "original_mtp_bank_gpu.rs"] mod gpu_tests; diff --git a/crates/cuda-driver/src/original_mtp_bank_gpu.rs b/crates/cuda-driver/src/original_mtp_bank/gpu_tests.rs similarity index 99% rename from crates/cuda-driver/src/original_mtp_bank_gpu.rs rename to crates/cuda-driver/src/original_mtp_bank/gpu_tests.rs index 14708338..8bd7840e 100644 --- a/crates/cuda-driver/src/original_mtp_bank_gpu.rs +++ b/crates/cuda-driver/src/original_mtp_bank/gpu_tests.rs @@ -117,7 +117,7 @@ fn bank_budget_refusal(tight: &Context<'_>, dir: &TempDir, experts: &[u8]) { #[test] #[ignore = "Root-only: needs a CUDA device"] fn draft_head_gather_matches_a_host_gather_for_each_kernel_width() { - use crate::original_mtp_coupled::subset_inverse; + assert_eq!(std::env::var(ENABLE).ok().as_deref(), Some("yes")); let driver = Driver::load().expect("driver"); let device = driver.device(0).expect("device"); diff --git a/crates/cuda-driver/src/original_mtp_draft_vocab/tests.rs b/crates/cuda-driver/src/original_mtp_draft_vocab/tests.rs index 0f877da1..d322d04a 100644 --- a/crates/cuda-driver/src/original_mtp_draft_vocab/tests.rs +++ b/crates/cuda-driver/src/original_mtp_draft_vocab/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests of the draft-vocabulary selection: setting spellings, the recorded digest table, refusal of wrong digests, +//! malformed files and symlinks, and the round trip from draft tokens to full vocabulary ids. use super::*; use crate::original_mtp_coupled::subset_inverse; diff --git a/crates/cuda-driver/src/original_mtp_rt.rs b/crates/cuda-driver/src/original_mtp_rt.rs index 32918425..d0ac9d04 100644 --- a/crates/cuda-driver/src/original_mtp_rt.rs +++ b/crates/cuda-driver/src/original_mtp_rt.rs @@ -201,39 +201,21 @@ pub(crate) mod fixtures { mod tests; mod rt_error; -#[allow(unused_imports)] -use rt_error::digits; -#[allow(unused_imports)] use rt_error::open_regular; -#[allow(unused_imports)] use rt_error::zeroed; mod read_index; -#[allow(unused_imports)] pub(crate) use read_index::draft_vocab_path; -#[allow(unused_imports)] pub(crate) use read_index::expert_bank_bytes; -#[allow(unused_imports)] pub(crate) use read_index::expert_scales_finite; -#[allow(unused_imports)] -use read_index::observed_default_bytes; -#[allow(unused_imports)] pub(crate) use read_index::observed_draft_vocab_bytes; -#[allow(unused_imports)] +#[cfg(test)] pub(crate) use read_index::observed_draft_vocab_bytes_with; -#[allow(unused_imports)] -use read_index::read_default_draft_vocab; -#[allow(unused_imports)] pub(crate) use read_index::read_dense; -#[allow(unused_imports)] pub(crate) use read_index::read_draft_vocab; #[cfg(test)] -#[allow(unused_imports)] pub(crate) use read_index::read_draft_vocab_with; -#[allow(unused_imports)] pub(crate) use read_index::read_index; -#[allow(unused_imports)] +#[cfg(test)] pub(crate) use read_index::read_selected_draft_vocab; -#[allow(unused_imports)] pub(crate) use read_index::stream_experts; -#[allow(unused_imports)] pub(crate) use read_index::validate_subset; diff --git a/crates/cuda-driver/src/original_mtp_rt/read_index.rs b/crates/cuda-driver/src/original_mtp_rt/read_index.rs index ae975026..c02e58d6 100644 --- a/crates/cuda-driver/src/original_mtp_rt/read_index.rs +++ b/crates/cuda-driver/src/original_mtp_rt/read_index.rs @@ -1,5 +1,5 @@ -//! Functions: `read_index`, `read_dense`, `expert_bank_bytes`, `expert_scales_finite` and 10 more. -//! Split out of `original_mtp_rt` to keep its files under the line limit. +//! File readers of the MTP runtime pack: dense.txt index, dense blob, experts.bin chunk streaming with the Inf/NaN +//! scale scan, and the draft vocabulary selection. Each mirrors the Original mtp.cpp read semantics and size limits. use super::{ DENSE_LIMIT, DRAFT_VOCAB_MAX_IDS, DenseIndex, DraftVocab, EXPERT_SCALE_OFFSET, INDEX_LIMIT, Path, PathBuf, Read, diff --git a/crates/cuda-driver/src/original_mtp_rt/rt_error.rs b/crates/cuda-driver/src/original_mtp_rt/rt_error.rs index d4e0a955..a655fbf9 100644 --- a/crates/cuda-driver/src/original_mtp_rt/rt_error.rs +++ b/crates/cuda-driver/src/original_mtp_rt/rt_error.rs @@ -1,5 +1,5 @@ -//! Methods of `RtError`: `message`, `index_message`, `pack_message`, `limit_message`. -//! Methods of `OriginalMtpTensorKind`: `parse`, `index_name`, `row_bytes`. +//! Parsing and error text of the MTP runtime pack index: RtError messages in the Original mtp.cpp wording, tensor kind +//! parsing and row sizes, the dense.txt parser with extent, required-name and finiteness checks, regular-file opening. use super::{DenseIndex, File, MAX_TENSORS, OriginalMtpTensorKind, Path, RtError, RtResult, TensorEntry, fs}; diff --git a/crates/cuda-driver/src/original_mtp_rt/tests.rs b/crates/cuda-driver/src/original_mtp_rt/tests.rs index c4eba4d3..2bd09591 100644 --- a/crates/cuda-driver/src/original_mtp_rt/tests.rs +++ b/crates/cuda-driver/src/original_mtp_rt/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests of the MTP runtime pack readers: index parsing, extent and finiteness checks, expert streaming error order, +//! and refusal of symlinked files; submodules hold the cases. use super::fixtures::*; use super::*; @@ -15,7 +16,5 @@ const REQUIRED: &[&str] = &[ "mlp.shared_expert.down_proj.weight", ]; -#[path = "tests/expert_stream_error_paths_use.rs"] mod expert_stream_error_paths_use; -#[path = "tests/parses_getline_loop_and_skips.rs"] mod parses_getline_loop_and_skips; diff --git a/crates/cuda-driver/src/original_mtp_rt/tests/expert_stream_error_paths_use.rs b/crates/cuda-driver/src/original_mtp_rt/tests/expert_stream_error_paths_use.rs index b1d86f97..54ceaa66 100644 --- a/crates/cuda-driver/src/original_mtp_rt/tests/expert_stream_error_paths_use.rs +++ b/crates/cuda-driver/src/original_mtp_rt/tests/expert_stream_error_paths_use.rs @@ -2,7 +2,6 @@ //! expert_stream_error_paths_use_original_order_and_text, expert_scale_scan_handles_chunk_boundaries_inside_blobs, //! draft_vocab_follows_the_original_size_filter. -#[allow(unused_imports)] use super::*; #[test] diff --git a/crates/cuda-driver/src/original_mtp_rt/tests/parses_getline_loop_and_skips.rs b/crates/cuda-driver/src/original_mtp_rt/tests/parses_getline_loop_and_skips.rs index e5c824ff..ab8cbdac 100644 --- a/crates/cuda-driver/src/original_mtp_rt/tests/parses_getline_loop_and_skips.rs +++ b/crates/cuda-driver/src/original_mtp_rt/tests/parses_getline_loop_and_skips.rs @@ -2,7 +2,6 @@ //! malformed_index_lines_carry_the_original_message, extent_validation_is_exact_and_bounded, //! required_names_are_checked_in_source_order_by_kind .... -#[allow(unused_imports)] use super::*; #[test] diff --git a/crates/cuda-driver/src/original_sampler.rs b/crates/cuda-driver/src/original_sampler.rs index c5c862bf..a7ac4b0f 100644 --- a/crates/cuda-driver/src/original_sampler.rs +++ b/crates/cuda-driver/src/original_sampler.rs @@ -74,9 +74,7 @@ pub struct OriginalSampler<'ctx> { } mod asset; -#[allow(unused_imports)] use asset::asset; mod original_sampler_drop; mod original_sampler_operations; -#[allow(unused_imports)] pub(crate) use original_sampler_drop::sampler_asset_sealed; diff --git a/crates/cuda-driver/src/original_sampler/asset.rs b/crates/cuda-driver/src/original_sampler/asset.rs index a4039aa8..9e525396 100644 --- a/crates/cuda-driver/src/original_sampler/asset.rs +++ b/crates/cuda-driver/src/original_sampler/asset.rs @@ -1,5 +1,5 @@ -//! Methods of `Launch`: `new`. Methods of `Context`: `original_sampler`. Functions: `asset`. -//! Split out of `original_sampler` to keep its files under the line limit. +//! Loads the sealed PTX asset of the Original sampler, builds a kernel Launch description, and opens the sampler +//! from a Context. use super::{ASSET_PIN, Arg, Command, Context, Launch, OriginalSampler, Result}; diff --git a/crates/cuda-driver/src/original_sampler/original_sampler_drop.rs b/crates/cuda-driver/src/original_sampler/original_sampler_drop.rs index 7601d557..80df25e4 100644 --- a/crates/cuda-driver/src/original_sampler/original_sampler_drop.rs +++ b/crates/cuda-driver/src/original_sampler/original_sampler_drop.rs @@ -1,5 +1,4 @@ -//! Implements `Drop for OriginalSampler`. Functions: `sampler_asset_sealed`. -//! Split out of `original_sampler` to keep its files under the line limit. +//! Drop glue of the Original sampler (closes its device resources) and the probe for a sealed PTX asset. use super::{OriginalSampler, asset}; diff --git a/crates/cuda-driver/src/original_sampler/original_sampler_operations/original_sampler_bring_up.rs b/crates/cuda-driver/src/original_sampler/original_sampler_operations/original_sampler_bring_up.rs index 87d9881c..f137ecb2 100644 --- a/crates/cuda-driver/src/original_sampler/original_sampler_operations/original_sampler_bring_up.rs +++ b/crates/cuda-driver/src/original_sampler/original_sampler_operations/original_sampler_bring_up.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalSampler`: `new`, `unloaded`, `check_budget`, `allocate_and_load` and 11 more. -//! Split out of `original_sampler_methods` to keep its files under the line limit. +//! Bring-up of the Original sampler: budget check, device buffer and kernel module allocation, buffer admission checks, +//! scratch growth for the split path, and uploads. Everything done before the first launch. use super::{ Context, DRAFTS, DeviceBuffer, ENTRIES, Error, HIST, KernelModule, MappedAllocation, OriginalSampler, RESERVE, diff --git a/crates/cuda-driver/src/original_sampler/original_sampler_operations/original_sampler_close_resources.rs b/crates/cuda-driver/src/original_sampler/original_sampler_operations/original_sampler_close_resources.rs index e165ef6b..652587c7 100644 --- a/crates/cuda-driver/src/original_sampler/original_sampler_operations/original_sampler_close_resources.rs +++ b/crates/cuda-driver/src/original_sampler/original_sampler_operations/original_sampler_close_resources.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalSampler`: `close_inner`, `is_released`, `close_module_and_mapped`, `retain_module_and_mapped`. -//! Functions: `release_buffer`. +//! Teardown of the Original sampler: releases buffers, kernel module and mapped staging inside an entered context, +//! or retains them when the context is poisoned. use super::{Context, DeviceBuffer, Error, KernelModule, OriginalSampler, Result, combine}; diff --git a/crates/cuda-driver/src/original_sampler/original_sampler_operations/original_sampler_coupled_draft.rs b/crates/cuda-driver/src/original_sampler/original_sampler_operations/original_sampler_coupled_draft.rs index 1a0418a9..f6e25e1d 100644 --- a/crates/cuda-driver/src/original_sampler/original_sampler_operations/original_sampler_coupled_draft.rs +++ b/crates/cuda-driver/src/original_sampler/original_sampler_operations/original_sampler_coupled_draft.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalSampler`: `set_subset`, `stage_coupled_round`, `write_round_staging`, `launch_stage` and 11 m... -//! Split out of `original_sampler_methods` to keep its files under the line limit. +//! Coupled draft sampling of the Original sampler: installs the draft-head vocabulary subset, stages a round's +//! parameters and history, and runs penalties, widest split and coupled merge for one draft logits row. use super::{Arg, DRAFTS, DeviceBuffer, Error, HIST, Launch, OriginalSampler, Result, SamplerParams, combine}; diff --git a/crates/cuda-driver/src/original_sampler/original_sampler_operations/original_sampler_run_verify_window.rs b/crates/cuda-driver/src/original_sampler/original_sampler_operations/original_sampler_run_verify_window.rs index 07fa1fcf..07a6a955 100644 --- a/crates/cuda-driver/src/original_sampler/original_sampler_operations/original_sampler_run_verify_window.rs +++ b/crates/cuda-driver/src/original_sampler/original_sampler_operations/original_sampler_run_verify_window.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalSampler`: `run`, `issue_guarded`, `launch_all`, `read_outputs` and 10 more. -//! Methods of `SampleArgs`: `split_partial`, `greedy`, `old`, `fused`. Functions: `zeroed`, `split_merge`. +//! Verify-window sampling of the Original sampler: uploads row histories, launches the greedy, fused or split-merge +//! kernels, reads the sampled ids back and settles the drain. Launch arguments are built here. use super::{ Arg, Error, Launch, OriginalSampler, Result, SampleRequest, SampleWindow, SamplerLaunchShape, SamplerParams, diff --git a/crates/cuda-driver/src/original_session_state.rs b/crates/cuda-driver/src/original_session_state.rs index ca919f25..5847168a 100644 --- a/crates/cuda-driver/src/original_session_state.rs +++ b/crates/cuda-driver/src/original_session_state.rs @@ -2,18 +2,12 @@ //! Carved spans are offsets in one retained ACTUAL whole arena, never device //! allocations, initialized QSA products, current-row or session certificates. //! Root must supply the actual QSA mapped-staging/table-builder/registry adapters. -#[path = "original_session_rope.rs"] mod rope; -pub(crate) use rope::{OriginalRopeScaling, OriginalRopeScalingType, OriginalRopeTable, OriginalRopeUpload}; +pub(crate) use rope::{OriginalRopeScaling, OriginalRopeTable}; #[allow(dead_code)] -#[path = "original_conversation_state.rs"] mod conversation; -#[path = "original_session_qsa_init.rs"] mod qsa_init; use crate::{Context, DeviceBuffer, Error, Result, combine}; -#[allow(unused_imports)] -pub(crate) use conversation::OriginalConversationAccess; -#[allow(unused_imports)] pub use conversation::{ OriginalGeometryFacts, OriginalHostKv, OriginalIdxKind, OriginalKvLayer, OriginalKvPool, OriginalQsaFacts, OriginalRegion, OriginalSessionBytes, OriginalSessionControl, OriginalSessionFacts, @@ -160,27 +154,15 @@ pub(crate) struct OriginalSessionState<'ctx> { } mod add; -#[allow(unused_imports)] use add::add; -#[allow(unused_imports)] use add::align; -#[allow(unused_imports)] use add::mul; -#[allow(unused_imports)] use add::parts; -#[allow(unused_imports)] use add::product; -#[allow(unused_imports)] -use add::q8k; -#[allow(unused_imports)] use add::sum; -#[allow(unused_imports)] use add::sum16; mod qsa_price; -#[allow(unused_imports)] use qsa_price::qsa_carve; -#[allow(unused_imports)] use qsa_price::qsa_price; -#[allow(unused_imports)] pub(crate) use qsa_price::session_bytes; mod original_session_layout; diff --git a/crates/cuda-driver/src/original_session_state/add.rs b/crates/cuda-driver/src/original_session_state/add.rs index 4f889d7b..0aadfb63 100644 --- a/crates/cuda-driver/src/original_session_state/add.rs +++ b/crates/cuda-driver/src/original_session_state/add.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalSessionGeometry`: `original`, `dimensions`, `validate`, `recurrence_bytes` and 14 more. -//! Methods of `OriginalSessionSpan`: `end`, `at`. Functions: `add`, `mul`, `product`, `align` and 6 more. +//! Byte-size model of an Original session: checked arithmetic helpers, the OriginalSessionGeometry dimensions and +//! the sizes of the GDN, GR, MoE, block and QSA scratch regions, plus the span and cursor helpers that carve an arena. use super::{Cursor, Error, OriginalSessionGeometry, OriginalSessionQsaLayout, OriginalSessionSpan, Result}; diff --git a/crates/cuda-driver/src/original_conversation_state.rs b/crates/cuda-driver/src/original_session_state/conversation.rs similarity index 99% rename from crates/cuda-driver/src/original_conversation_state.rs rename to crates/cuda-driver/src/original_session_state/conversation.rs index a8a74a08..4cd952f5 100644 --- a/crates/cuda-driver/src/original_conversation_state.rs +++ b/crates/cuda-driver/src/original_session_state/conversation.rs @@ -392,5 +392,5 @@ impl<'ctx> OriginalSessionState<'ctx> { } #[cfg(test)] -#[path = "original_conversation_state/tests.rs"] +#[path = "../original_conversation_state/tests.rs"] mod tests; diff --git a/crates/cuda-driver/src/original_session_state/original_session_layout.rs b/crates/cuda-driver/src/original_session_state/original_session_layout.rs index aa72834b..c30295db 100644 --- a/crates/cuda-driver/src/original_session_state/original_session_layout.rs +++ b/crates/cuda-driver/src/original_session_state/original_session_layout.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalSessionLayout`: `new`, `gdn_point_at`, `gdn_local_index`, `gdn_point_spans` and 1 more. -//! Methods of `OriginalSessionState`: `session_init_carve`, `validate_context`, `layout`, `with_carved_arena` and 3 ... +//! Layout and lifecycle of a session state: finds the GDN point spans and the primary QSA layout, carves the arena, +//! registers and releases the primary RoPE tables, and closes the state. use super::{ ALIGN, Context, Cursor, DeviceBuffer, Error, OriginalLayerBounds, OriginalSessionGeometry, OriginalSessionKvPolicy, diff --git a/crates/cuda-driver/src/original_session_qsa_init.rs b/crates/cuda-driver/src/original_session_state/qsa_init.rs similarity index 100% rename from crates/cuda-driver/src/original_session_qsa_init.rs rename to crates/cuda-driver/src/original_session_state/qsa_init.rs diff --git a/crates/cuda-driver/src/original_session_state/qsa_price.rs b/crates/cuda-driver/src/original_session_state/qsa_price.rs index d5868ad1..861b2b6a 100644 --- a/crates/cuda-driver/src/original_session_state/qsa_price.rs +++ b/crates/cuda-driver/src/original_session_state/qsa_price.rs @@ -1,5 +1,5 @@ -//! Methods of `PoolSizes`: `new`, `select`, `without_key`, `hybrid`. Methods of `KvSizes`: `new`. -//! Functions: `qsa_price`, `kv_placement`, `tier_off`, `smaller_tier` and 11 more. +//! Pricing and carving of QSA session state: K/V placement tier (drafter ring, clock-resident, full), pool and table +//! sizes, the region-by-region carve of one state, and the pure total session_bytes of the Original sequence. use super::{ ALIGN, Cursor, Error, OriginalSessionGeometry, OriginalSessionKvPolicy, OriginalSessionQsaLayout, diff --git a/crates/cuda-driver/src/original_session_rope.rs b/crates/cuda-driver/src/original_session_state/rope.rs similarity index 100% rename from crates/cuda-driver/src/original_session_rope.rs rename to crates/cuda-driver/src/original_session_state/rope.rs diff --git a/crates/cuda-driver/src/original_verify.rs b/crates/cuda-driver/src/original_verify.rs index 90baea3b..11dcbe6b 100644 --- a/crates/cuda-driver/src/original_verify.rs +++ b/crates/cuda-driver/src/original_verify.rs @@ -1,54 +1,32 @@ //! Original Verifier physical arena, retained GDN operands and accepted-prefix //! commit. Numerical owners only: the runtime must bind genuine current session //! lineage before each window and publication. No prompt-GEMM fallback. -#[path = "original_verify_ffi.rs"] #[allow(unsafe_code)] pub(crate) mod abi; -#[path = "original_verify_window_chain.rs"] pub(crate) mod chain; -#[path = "original_verify_diag.rs"] #[allow(unsafe_code)] mod diag; -#[path = "original_verify/original_verify_window_combine_head.rs"] pub(crate) mod combine_head; -#[path = "original_verify/original_verify_window_down.rs"] pub(crate) mod down; -#[path = "original_verify_window_draft.rs"] pub(crate) mod draft; -#[path = "original_verify/original_verify_window_ffn.rs"] pub(crate) mod ffn; pub(crate) mod finite_verdict; -#[path = "original_verify/original_verify_window_gdn_fused.rs"] pub(crate) mod gdn_fused; -#[path = "original_verify_window_gr.rs"] pub(crate) mod gr; -#[path = "original_verify_window_kernels.rs"] pub(crate) mod kernels; -#[path = "original_verify_layout.rs"] mod layout; -#[path = "original_verify_logits.rs"] mod logits; -#[path = "original_verify_mapped.rs"] #[allow(unsafe_code)] mod mapped; -#[path = "original_verify_window_moe.rs"] pub(crate) mod moe; -#[path = "original_verify_window_planner.rs"] pub(crate) mod planner; -#[path = "original_verify_profile.rs"] mod profile; -#[path = "original_verify_window_proj.rs"] pub(crate) mod proj; -#[path = "original_verify_window_qsa.rs"] pub(crate) mod qsa; -#[path = "original_verify_window_sm120.rs"] pub(crate) mod sm120; #[cfg(test)] -#[path = "original_verify_window_gpu.rs"] mod window_gpu; -#[path = "original_verify_window_plan.rs"] pub(crate) mod window_plan; -#[path = "original_verify_window_record.rs"] pub(crate) mod window_record; use crate::original_gpu_schedule::{OriginalCapture, OriginalGraphResources, resources}; use crate::{Context, DeviceBuffer, DeviceRef, Error, Result, combine}; @@ -219,15 +197,12 @@ pub struct OriginalVerifyResources<'ctx> { qsa: Rc>, head: crate::OriginalNativeHeadRows<'ctx>, } -#[path = "original_verify_gpu_plan.rs"] mod gpu_plan; -#[path = "original_verify_schedule.rs"] mod schedule; pub use gpu_plan::{MAX_PCIE_FETCHES, OriginalVerifyGpuPlan, OriginalVerifyPcieSource}; #[cfg(any(test, feature = "expert-tier-probe"))] -#[path = "original_verify_expert_probe.rs"] mod expert_probe; -#[cfg(any(test, feature = "expert-tier-probe"))] +#[cfg(feature = "expert-tier-probe")] pub use expert_probe::{OriginalExpertTierProbe, expert_probe_geometry}; pub use schedule::{ OriginalVerifier, OriginalVerifyCpuRows, OriginalVerifyCpuSink, OriginalVerifyWindowResult, @@ -236,7 +211,6 @@ pub use schedule::{ mod original_verify_rearm; pub use original_verify_rearm::OriginalVerifyRearm; use original_verify_rearm::StagedWindow; -#[path = "original_verify_window_ops.rs"] mod window_ops; pub use gr::{ HcHalfBuffers, HcLayerBuffers, HcOutputBuffers, OriginalVerifyGrBinding, PLE_SCRATCH_BYTES, PleBuffers, @@ -257,30 +231,15 @@ pub use window_plan::{PlanLayout, WINDOW_LAYERS}; pub use window_record::{ExpertTier, HcHalf, Projection, QuantSource, Rows, WindowOps, WindowPolicy, record_window}; mod share_window_modules; -#[allow(unused_imports)] -use share_window_modules::admission; -#[allow(unused_imports)] use share_window_modules::admit; -#[allow(unused_imports)] use share_window_modules::check_canonical_lengths; -#[allow(unused_imports)] use share_window_modules::check_commands; -#[allow(unused_imports)] use share_window_modules::command; -#[allow(unused_imports)] pub(crate) use share_window_modules::gather_rows_module; -#[allow(unused_imports)] use share_window_modules::handle; -#[allow(unused_imports)] use share_window_modules::poison; -#[allow(unused_imports)] use share_window_modules::sealed_asset; -#[allow(unused_imports)] -use share_window_modules::share_window_modules; -#[allow(unused_imports)] use share_window_modules::transport; -#[allow(unused_imports)] use share_window_modules::zero; mod original_verify_gdn_journal; -#[allow(unused_imports)] pub(crate) use original_verify_gdn_journal::verify_assets_sealed; diff --git a/crates/cuda-driver/src/original_verify_ffi.rs b/crates/cuda-driver/src/original_verify/abi.rs similarity index 100% rename from crates/cuda-driver/src/original_verify_ffi.rs rename to crates/cuda-driver/src/original_verify/abi.rs diff --git a/crates/cuda-driver/src/original_verify_window_chain.rs b/crates/cuda-driver/src/original_verify/chain.rs similarity index 96% rename from crates/cuda-driver/src/original_verify_window_chain.rs rename to crates/cuda-driver/src/original_verify/chain.rs index f7dc86ff..761dca95 100644 --- a/crates/cuda-driver/src/original_verify_window_chain.rs +++ b/crates/cuda-driver/src/original_verify/chain.rs @@ -39,7 +39,7 @@ pub(crate) const E_QSA_MERGE_N: &str = "chain_qsa_decode_merge_n"; /// Sealed by `scripts/gpu-bringup/seal_pins.py` (extra-seal-plan.json, group chain-window). pub(crate) static CHAIN: AssetSpec = AssetSpec { name: "chain_window.ptx", - ptx: concat!(include_str!("chain_window.ptx"), "\0").as_bytes(), + ptx: concat!(include_str!("../chain_window.ptx"), "\0").as_bytes(), sha: [ 163, 171, 220, 65, 134, 182, 109, 81, 168, 12, 142, 245, 47, 99, 111, 24, 147, 162, 19, 107, 136, 124, 214, 84, 135, 134, 254, 162, 121, 239, 113, 186, @@ -283,16 +283,16 @@ mod tests { #[test] fn the_swiglu_quant_fusion_divides_like_the_pair_it_replaces() { parity_of( - include_str!("chain_window.ptx"), - &String::from_utf8_lossy(include_bytes!("mtp_original_full_head_iq.ptx")), + include_str!("../chain_window.ptx"), + &String::from_utf8_lossy(include_bytes!("../mtp_original_full_head_iq.ptx")), ); } #[test] fn the_swiglu_quant_fusion_divides_like_the_pair_it_replaces_on_the_sm86_seal() { parity_of( - include_str!("../ptx-sm86/chain_window.ptx"), - &String::from_utf8_lossy(include_bytes!("../ptx-sm86/mtp_original_full_head_iq.ptx")), + include_str!("../../ptx-sm86/chain_window.ptx"), + &String::from_utf8_lossy(include_bytes!("../../ptx-sm86/mtp_original_full_head_iq.ptx")), ); } @@ -301,12 +301,12 @@ mod tests { // the fast-math quantizer copy (native_head_iq, `--use_fast_math`) is a different flavour: this check must // tell them apart let fast = numeric_ops(entry_body( - &String::from_utf8_lossy(include_bytes!("native_head_iq.ptx")), + &String::from_utf8_lossy(include_bytes!("../native_head_iq.ptx")), "quantize_q8_1_kernel", )); assert!(fast.contains_key("div.approx.ftz.f32"), "{fast:?}"); let precise = numeric_ops(entry_body( - &String::from_utf8_lossy(include_bytes!("mtp_original_full_head_iq.ptx")), + &String::from_utf8_lossy(include_bytes!("../mtp_original_full_head_iq.ptx")), "quantize_q8_1_kernel", )); assert!(precise.contains_key("div.rn.f32") && !precise.contains_key("div.approx.ftz.f32")); diff --git a/crates/cuda-driver/src/original_verify/original_verify_window_combine_head.rs b/crates/cuda-driver/src/original_verify/combine_head.rs similarity index 100% rename from crates/cuda-driver/src/original_verify/original_verify_window_combine_head.rs rename to crates/cuda-driver/src/original_verify/combine_head.rs diff --git a/crates/cuda-driver/src/original_verify_diag.rs b/crates/cuda-driver/src/original_verify/diag.rs similarity index 100% rename from crates/cuda-driver/src/original_verify_diag.rs rename to crates/cuda-driver/src/original_verify/diag.rs diff --git a/crates/cuda-driver/src/original_verify/original_verify_window_down.rs b/crates/cuda-driver/src/original_verify/down.rs similarity index 100% rename from crates/cuda-driver/src/original_verify/original_verify_window_down.rs rename to crates/cuda-driver/src/original_verify/down.rs diff --git a/crates/cuda-driver/src/original_verify_window_draft.rs b/crates/cuda-driver/src/original_verify/draft.rs similarity index 95% rename from crates/cuda-driver/src/original_verify_window_draft.rs rename to crates/cuda-driver/src/original_verify/draft.rs index 33f3477f..d4cb66f8 100644 --- a/crates/cuda-driver/src/original_verify_window_draft.rs +++ b/crates/cuda-driver/src/original_verify/draft.rs @@ -15,7 +15,7 @@ pub(crate) const E_QSA: &str = "draft_commit_qsa_layers"; /// group draft-round). pub(crate) static DRAFT_COMMIT: AssetSpec = AssetSpec { name: "draft_commit.ptx", - ptx: concat!(include_str!("draft_commit.ptx"), "\0").as_bytes(), + ptx: concat!(include_str!("../draft_commit.ptx"), "\0").as_bytes(), sha: [ 42, 84, 134, 220, 68, 111, 65, 245, 130, 212, 5, 3, 242, 10, 36, 211, 62, 194, 218, 187, 182, 163, 8, 18, 113, 83, 194, 204, 47, 192, 99, 150, @@ -27,7 +27,7 @@ pub(crate) static DRAFT_COMMIT: AssetSpec = AssetSpec { /// `draft_commit_qsa.cu` (QSA layers, fast math like the Original's `original_verify_qsa.ptx`), sealed the same way. pub(crate) static DRAFT_COMMIT_QSA: AssetSpec = AssetSpec { name: "draft_commit_qsa.ptx", - ptx: concat!(include_str!("draft_commit_qsa.ptx"), "\0").as_bytes(), + ptx: concat!(include_str!("../draft_commit_qsa.ptx"), "\0").as_bytes(), sha: [ 223, 201, 194, 216, 75, 207, 191, 33, 97, 151, 192, 218, 191, 162, 203, 165, 182, 75, 182, 169, 170, 199, 204, 83, 70, 33, 188, 104, 184, 119, 48, 157, diff --git a/crates/cuda-driver/src/original_verify_expert_probe.rs b/crates/cuda-driver/src/original_verify/expert_probe.rs similarity index 100% rename from crates/cuda-driver/src/original_verify_expert_probe.rs rename to crates/cuda-driver/src/original_verify/expert_probe.rs diff --git a/crates/cuda-driver/src/original_verify/original_verify_window_ffn.rs b/crates/cuda-driver/src/original_verify/ffn.rs similarity index 100% rename from crates/cuda-driver/src/original_verify/original_verify_window_ffn.rs rename to crates/cuda-driver/src/original_verify/ffn.rs diff --git a/crates/cuda-driver/src/original_verify/original_verify_window_gdn_fused.rs b/crates/cuda-driver/src/original_verify/gdn_fused.rs similarity index 100% rename from crates/cuda-driver/src/original_verify/original_verify_window_gdn_fused.rs rename to crates/cuda-driver/src/original_verify/gdn_fused.rs diff --git a/crates/cuda-driver/src/original_verify_gpu_plan.rs b/crates/cuda-driver/src/original_verify/gpu_plan.rs similarity index 86% rename from crates/cuda-driver/src/original_verify_gpu_plan.rs rename to crates/cuda-driver/src/original_verify/gpu_plan.rs index c2877be5..62a44d32 100644 --- a/crates/cuda-driver/src/original_verify_gpu_plan.rs +++ b/crates/cuda-driver/src/original_verify/gpu_plan.rs @@ -45,28 +45,19 @@ pub struct OriginalVerifyPcieSource<'s, 'ctx> { any(target_os = "linux", target_os = "windows"), target_pointer_width = "64" ))] -#[path = "original_pcie_copy_gpu_smoke.rs"] mod pcie_copy_smoke; #[cfg(test)] -#[path = "original_verify_gpu_plan/tests.rs"] +#[path = "../original_verify_gpu_plan/tests.rs"] mod tests; -#[path = "original_verify_gpu_plan/original_verify_gpu_plan_encoding.rs"] mod original_verify_gpu_plan_encoding; -#[allow(unused_imports)] use original_verify_gpu_plan_encoding::span_layer; -#[allow(unused_imports)] pub(crate) use original_verify_gpu_plan_encoding::{PlanEntryShape, encode_plan_block}; -#[path = "original_verify_gpu_plan/cpu_sink_publish_gpu_plan.rs"] mod cpu_sink_publish_gpu_plan; -#[path = "original_verify_gpu_plan/plan_phases.rs"] mod plan_phases; -#[path = "original_verify_gpu_plan/plan_tier_tally.rs"] mod plan_tier_tally; -#[allow(unused_imports)] +#[cfg(test)] pub(crate) use cpu_sink_publish_gpu_plan::dma_options; -#[path = "original_verify_gpu_plan/dma_options_for.rs"] mod dma_options_for; -#[allow(unused_imports)] use dma_options_for::dma_options_for; diff --git a/crates/cuda-driver/src/original_verify_gpu_plan/cpu_sink_publish_gpu_plan.rs b/crates/cuda-driver/src/original_verify/gpu_plan/cpu_sink_publish_gpu_plan.rs similarity index 95% rename from crates/cuda-driver/src/original_verify_gpu_plan/cpu_sink_publish_gpu_plan.rs rename to crates/cuda-driver/src/original_verify/gpu_plan/cpu_sink_publish_gpu_plan.rs index 181354a5..cec52903 100644 --- a/crates/cuda-driver/src/original_verify_gpu_plan/cpu_sink_publish_gpu_plan.rs +++ b/crates/cuda-driver/src/original_verify/gpu_plan/cpu_sink_publish_gpu_plan.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalVerifyCpuSink`: `plan_capacity`, `staging_capacity`, `copies_landed`, `group_ids` and 1 more. -//! Functions: `dma_options`. +//! Publishing of a group's GPU plan from the CPU sink: capacity and group-id accessors, publish_gpu_plan (flag A, PCIe +//! share staged by DMA, flag B), and the DMA option switches with their platform defaults. use super::{ Error, OriginalExpertCache, OriginalGpuStream, OriginalVerifyGpuPlan, OriginalVerifyPcieSource, Result, diff --git a/crates/cuda-driver/src/original_verify_gpu_plan/dma_options_for.rs b/crates/cuda-driver/src/original_verify/gpu_plan/dma_options_for.rs similarity index 75% rename from crates/cuda-driver/src/original_verify_gpu_plan/dma_options_for.rs rename to crates/cuda-driver/src/original_verify/gpu_plan/dma_options_for.rs index 6479ae08..d1e21fba 100644 --- a/crates/cuda-driver/src/original_verify_gpu_plan/dma_options_for.rs +++ b/crates/cuda-driver/src/original_verify/gpu_plan/dma_options_for.rs @@ -1,5 +1,5 @@ -//! Functions: `dma_options_for`. -//! Split out of `gpu_plan` to keep its files under the line limit. +//! Pure platform and environment rule behind the DMA staging options: WSL2 and native Windows make the batch copy +//! and the stream write opt-in. Separate from dma_options so it can be tested with a fake environment. /// `dma_options` for a platform and an environment: `wsl` (WSL2 passthrough) makes the batch copy and the stream /// write opt-in, `windows` (native) the batch copy only. diff --git a/crates/cuda-driver/src/original_verify_gpu_plan/original_verify_gpu_plan_encoding.rs b/crates/cuda-driver/src/original_verify/gpu_plan/original_verify_gpu_plan_encoding.rs similarity index 100% rename from crates/cuda-driver/src/original_verify_gpu_plan/original_verify_gpu_plan_encoding.rs rename to crates/cuda-driver/src/original_verify/gpu_plan/original_verify_gpu_plan_encoding.rs diff --git a/crates/cuda-driver/src/original_pcie_copy_gpu_smoke.rs b/crates/cuda-driver/src/original_verify/gpu_plan/pcie_copy_smoke.rs similarity index 100% rename from crates/cuda-driver/src/original_pcie_copy_gpu_smoke.rs rename to crates/cuda-driver/src/original_verify/gpu_plan/pcie_copy_smoke.rs diff --git a/crates/cuda-driver/src/original_verify_gpu_plan/plan_phases.rs b/crates/cuda-driver/src/original_verify/gpu_plan/plan_phases.rs similarity index 100% rename from crates/cuda-driver/src/original_verify_gpu_plan/plan_phases.rs rename to crates/cuda-driver/src/original_verify/gpu_plan/plan_phases.rs diff --git a/crates/cuda-driver/src/original_verify_gpu_plan/plan_tier_tally.rs b/crates/cuda-driver/src/original_verify/gpu_plan/plan_tier_tally.rs similarity index 100% rename from crates/cuda-driver/src/original_verify_gpu_plan/plan_tier_tally.rs rename to crates/cuda-driver/src/original_verify/gpu_plan/plan_tier_tally.rs diff --git a/crates/cuda-driver/src/original_verify_window_gr.rs b/crates/cuda-driver/src/original_verify/gr.rs similarity index 93% rename from crates/cuda-driver/src/original_verify_window_gr.rs rename to crates/cuda-driver/src/original_verify/gr.rs index a4d11499..8c4baddd 100644 --- a/crates/cuda-driver/src/original_verify_window_gr.rs +++ b/crates/cuda-driver/src/original_verify/gr.rs @@ -74,7 +74,7 @@ const E_DOWN2560: &str = "mtp_scalar_gr_down2560"; pub(crate) static GR_FUSED: AssetSpec = AssetSpec { name: "mtp_original_full_fused_gr.ptx", - ptx: include_bytes!("mtp_original_full_fused_gr.ptx"), + ptx: include_bytes!("../mtp_original_full_fused_gr.ptx"), sha: [ 172, 84, 0, 167, 151, 43, 63, 36, 38, 72, 194, 222, 113, 239, 79, 23, 132, 102, 211, 139, 19, 146, 168, 58, 149, 145, 179, 178, 78, 146, 197, 155, @@ -84,7 +84,7 @@ pub(crate) static GR_FUSED: AssetSpec = AssetSpec { }; pub(crate) static GR_NORM: AssetSpec = AssetSpec { name: "mtp_original_full_gr_norm.ptx", - ptx: include_bytes!("mtp_original_full_gr_norm.ptx"), + ptx: include_bytes!("../mtp_original_full_gr_norm.ptx"), sha: [ 6, 214, 23, 123, 72, 44, 182, 116, 19, 198, 89, 106, 2, 145, 180, 218, 177, 133, 3, 50, 22, 74, 146, 18, 175, 246, 123, 158, 253, 242, 17, 32, @@ -94,7 +94,7 @@ pub(crate) static GR_NORM: AssetSpec = AssetSpec { }; pub(crate) static GR_POST: AssetSpec = AssetSpec { name: "mtp_original_full_gr_post.ptx", - ptx: include_bytes!("mtp_original_full_gr_post.ptx"), + ptx: include_bytes!("../mtp_original_full_gr_post.ptx"), sha: [ 155, 71, 156, 15, 65, 42, 224, 7, 115, 129, 92, 154, 109, 137, 215, 244, 195, 247, 169, 240, 246, 145, 135, 109, 232, 5, 235, 56, 23, 141, 151, 144, @@ -104,7 +104,7 @@ pub(crate) static GR_POST: AssetSpec = AssetSpec { }; pub(crate) static PLE_BATCH: AssetSpec = AssetSpec { name: "ple_native_batch.ptx", - ptx: concat!(include_str!("ple_native_batch.ptx"), "\0").as_bytes(), + ptx: concat!(include_str!("../ple_native_batch.ptx"), "\0").as_bytes(), sha: [ 95, 165, 201, 48, 244, 12, 180, 157, 158, 121, 163, 94, 25, 17, 198, 133, 129, 249, 44, 9, 119, 80, 239, 242, 140, 36, 94, 40, 112, 150, 74, 64, @@ -327,51 +327,30 @@ pub struct OriginalVerifyGrBinding<'ctx> { } #[cfg(test)] -#[path = "original_verify_window_gr/tests.rs"] +#[path = "../original_verify_window_gr/tests.rs"] mod tests; -#[path = "original_verify_window_gr/assets.rs"] mod assets; -#[allow(unused_imports)] pub(crate) use assets::assets; -#[allow(unused_imports)] use assets::check_geometry; -#[allow(unused_imports)] use assets::check_rows; -#[allow(unused_imports)] use assets::chunk_words; -#[allow(unused_imports)] use assets::multi_words; -#[allow(unused_imports)] use assets::refuse; -#[allow(unused_imports)] use assets::row_span; -#[allow(unused_imports)] pub(crate) use assets::shared_attributes; -#[allow(unused_imports)] pub(crate) use assets::tiled_down_geometry; -#[path = "original_verify_window_gr/fused_down.rs"] pub(crate) mod fused_down; -#[path = "original_verify_window_gr/head_chain.rs"] pub(crate) mod head_chain; -#[path = "original_verify_window_gr/plan_hc_read.rs"] mod plan_hc_read; pub(crate) use fused_down::plan_hc_read_launches; -#[allow(unused_imports)] pub(crate) use plan_hc_read::plan_final_write; -#[allow(unused_imports)] pub(crate) use plan_hc_read::plan_hc_read; -#[allow(unused_imports)] pub(crate) use plan_hc_read::plan_head_mix; -#[allow(unused_imports)] use plan_hc_read::write_row; -#[path = "original_verify_window_gr/plan_head_mix_multi.rs"] mod plan_head_mix_multi; -#[allow(unused_imports)] pub(crate) use plan_head_mix_multi::plan_head_mix_multi; -#[path = "original_verify_window_gr/plan_ple_row.rs"] mod plan_ple_row; -#[allow(unused_imports)] pub(crate) use plan_ple_row::plan_ple_layer1; -#[allow(unused_imports)] +#[cfg(test)] pub(crate) use plan_ple_row::plan_ple_row; diff --git a/crates/cuda-driver/src/original_verify_window_gr/assets.rs b/crates/cuda-driver/src/original_verify/gr/assets.rs similarity index 97% rename from crates/cuda-driver/src/original_verify_window_gr/assets.rs rename to crates/cuda-driver/src/original_verify/gr/assets.rs index 06205ba2..236d45ef 100644 --- a/crates/cuda-driver/src/original_verify_window_gr/assets.rs +++ b/crates/cuda-driver/src/original_verify/gr/assets.rs @@ -1,5 +1,5 @@ -//! Methods of `GrVariant`: `from_env_value`. Methods of `GrConfig`: `from_device`, `query`, `down_entry`. -//! Functions: `assets`, `cap_to_optin`, `shared_attributes`, `tiled_down_geometry` and 6 more. +//! Assets and per-device configuration of the GR (hyper-connection read/write) kernel family: variant choice from the +//! environment, shared-memory attributes, tiled down geometry, row checks and the argument-word helpers. use super::{ ARGS_WORDS, ATTR_COMPUTE_CAPABILITY_MAJOR, ATTR_COMPUTE_CAPABILITY_MINOR, ATTR_MAX_SHARED_PER_BLOCK, diff --git a/crates/cuda-driver/src/original_verify_window_gr/fused_down.rs b/crates/cuda-driver/src/original_verify/gr/fused_down.rs similarity index 98% rename from crates/cuda-driver/src/original_verify_window_gr/fused_down.rs rename to crates/cuda-driver/src/original_verify/gr/fused_down.rs index ec2192b5..2bf5d0f9 100644 --- a/crates/cuda-driver/src/original_verify_window_gr/fused_down.rs +++ b/crates/cuda-driver/src/original_verify/gr/fused_down.rs @@ -29,7 +29,7 @@ pub(crate) const E_GR_DOWN_FUSED: &str = "leleka_gr_down_fused_t2w8"; /// (extra-seal-plan.json, group sm120-decode). pub(crate) static GR_DOWN_FUSED: AssetSpec = AssetSpec { name: "sm120_gr_down_fused.ptx", - ptx: concat!(include_str!("../sm120_gr_down_fused.ptx"), "\0").as_bytes(), + ptx: concat!(include_str!("../../sm120_gr_down_fused.ptx"), "\0").as_bytes(), sha: [ 199, 142, 148, 149, 154, 181, 122, 105, 95, 156, 68, 210, 189, 80, 52, 231, 101, 198, 246, 184, 110, 221, 185, 78, 195, 163, 231, 255, 127, 207, 23, 127, diff --git a/crates/cuda-driver/src/original_verify_window_gr/head_chain.rs b/crates/cuda-driver/src/original_verify/gr/head_chain.rs similarity index 99% rename from crates/cuda-driver/src/original_verify_window_gr/head_chain.rs rename to crates/cuda-driver/src/original_verify/gr/head_chain.rs index 98520b93..4bbaf39f 100644 --- a/crates/cuda-driver/src/original_verify_window_gr/head_chain.rs +++ b/crates/cuda-driver/src/original_verify/gr/head_chain.rs @@ -36,7 +36,7 @@ const NORM_THREADS: u32 = 1024; /// `sm120-decode`). pub(crate) static HEAD_CHAIN: AssetSpec = AssetSpec { name: "sm120_head_chain.ptx", - ptx: concat!(include_str!("../sm120_head_chain.ptx"), "\0").as_bytes(), + ptx: concat!(include_str!("../../sm120_head_chain.ptx"), "\0").as_bytes(), sha: [ 108, 159, 128, 249, 97, 125, 144, 237, 99, 113, 100, 98, 16, 147, 170, 163, 30, 214, 120, 146, 251, 203, 3, 73, 31, 110, 176, 118, 251, 64, 94, 168, diff --git a/crates/cuda-driver/src/original_verify_window_gr/plan_hc_read.rs b/crates/cuda-driver/src/original_verify/gr/plan_hc_read.rs similarity index 98% rename from crates/cuda-driver/src/original_verify_window_gr/plan_hc_read.rs rename to crates/cuda-driver/src/original_verify/gr/plan_hc_read.rs index 93c88527..49fe47f5 100644 --- a/crates/cuda-driver/src/original_verify_window_gr/plan_hc_read.rs +++ b/crates/cuda-driver/src/original_verify/gr/plan_hc_read.rs @@ -1,5 +1,5 @@ -//! Functions: `plan_hc_read`, `hc_read_of_rows`, `hc_read_rows`, `hc_read_norm` and 9 more. -//! Split out of `gr` to keep its files under the line limit. +//! Planner of the GR read launches (norm, down, up) per window half, the final residual write of the last layer +//! and the per-token head mix. Picks tiled, buffered or fused down kernels by card limits. use super::{ A, ArenaMap, Bf16GemvExtents, D, DOWN_BLOCKS, E_NORM, E_SPLIT, E_UP, EPS, Error, GR_FUSED, GR_NORM, GR_POST, diff --git a/crates/cuda-driver/src/original_verify_window_gr/plan_head_mix_multi.rs b/crates/cuda-driver/src/original_verify/gr/plan_head_mix_multi.rs similarity index 100% rename from crates/cuda-driver/src/original_verify_window_gr/plan_head_mix_multi.rs rename to crates/cuda-driver/src/original_verify/gr/plan_head_mix_multi.rs diff --git a/crates/cuda-driver/src/original_verify_window_gr/plan_ple_row.rs b/crates/cuda-driver/src/original_verify/gr/plan_ple_row.rs similarity index 97% rename from crates/cuda-driver/src/original_verify_window_gr/plan_ple_row.rs rename to crates/cuda-driver/src/original_verify/gr/plan_ple_row.rs index 08a7707e..1069c8aa 100644 --- a/crates/cuda-driver/src/original_verify_window_gr/plan_ple_row.rs +++ b/crates/cuda-driver/src/original_verify/gr/plan_ple_row.rs @@ -1,5 +1,5 @@ -//! Methods of `PleScratch`: `at`. -//! Methods of `OriginalVerifyGrBinding`: `new`, `half`, `half_addrs`, `head_addrs` and 4 more. +//! Planner of the layer-1 PLE (per-layer embedding) block, one launch list per window row, and the GR binding that +//! validates and hands out the device addresses of the hyper-connection halves, the head and the PLE buffers. use super::{ A, ArenaMap, Bf16GemvExtents, Context, D, DeviceBuffer, Error, GrWindow, HC, HC_DOWN_BYTES, HC_INJECT_BYTES, diff --git a/crates/cuda-driver/src/original_verify_window_kernels.rs b/crates/cuda-driver/src/original_verify/kernels.rs similarity index 100% rename from crates/cuda-driver/src/original_verify_window_kernels.rs rename to crates/cuda-driver/src/original_verify/kernels.rs diff --git a/crates/cuda-driver/src/original_verify_layout.rs b/crates/cuda-driver/src/original_verify/layout.rs similarity index 100% rename from crates/cuda-driver/src/original_verify_layout.rs rename to crates/cuda-driver/src/original_verify/layout.rs diff --git a/crates/cuda-driver/src/original_verify_logits.rs b/crates/cuda-driver/src/original_verify/logits.rs similarity index 100% rename from crates/cuda-driver/src/original_verify_logits.rs rename to crates/cuda-driver/src/original_verify/logits.rs diff --git a/crates/cuda-driver/src/original_verify_mapped.rs b/crates/cuda-driver/src/original_verify/mapped.rs similarity index 100% rename from crates/cuda-driver/src/original_verify_mapped.rs rename to crates/cuda-driver/src/original_verify/mapped.rs diff --git a/crates/cuda-driver/src/original_verify_window_moe.rs b/crates/cuda-driver/src/original_verify/moe.rs similarity index 92% rename from crates/cuda-driver/src/original_verify_window_moe.rs rename to crates/cuda-driver/src/original_verify/moe.rs index 38bd890e..09afae70 100644 --- a/crates/cuda-driver/src/original_verify_window_moe.rs +++ b/crates/cuda-driver/src/original_verify/moe.rs @@ -55,7 +55,7 @@ const E_TO_BF16: &str = /// `elementwise.cu` (`f32_to_bf16_bulk`). pub(crate) static ELEMENT: AssetSpec = AssetSpec { name: "mtp_original_full_element.ptx", - ptx: include_bytes!("mtp_original_full_element.ptx"), + ptx: include_bytes!("../mtp_original_full_element.ptx"), sha: [ 143, 223, 223, 142, 246, 22, 105, 140, 18, 48, 31, 125, 244, 113, 111, 192, 34, 191, 52, 180, 25, 9, 158, 76, 151, 39, 41, 146, 11, 213, 244, 167, @@ -68,7 +68,7 @@ const E_ROUTE: &str = "mtp_full_route"; /// `native_router.cu` (`native_router_top10(_multi)`). pub(crate) static ROUTER: AssetSpec = AssetSpec { name: "mtp_original_full_router.ptx", - ptx: include_bytes!("mtp_original_full_router.ptx"), + ptx: include_bytes!("../mtp_original_full_router.ptx"), sha: [ 190, 110, 60, 145, 228, 246, 131, 20, 100, 245, 153, 55, 135, 240, 191, 249, 105, 188, 93, 40, 57, 95, 36, 34, 107, 136, 103, 107, 48, 105, 168, 203, @@ -84,7 +84,7 @@ const E_ROUTER_TOP10: &str = concat!( /// `router_top10.cu` (`router_top10`, the generic router when the native one is off). pub(crate) static ROUTER_LEGACY: AssetSpec = AssetSpec { name: "mtp_original_full_router_legacy.ptx", - ptx: include_bytes!("mtp_original_full_router_legacy.ptx"), + ptx: include_bytes!("../mtp_original_full_router_legacy.ptx"), sha: [ 165, 132, 18, 36, 151, 87, 204, 53, 30, 184, 51, 46, 128, 126, 121, 241, 179, 218, 88, 101, 87, 77, 15, 183, 23, 158, 245, 88, 223, 112, 175, 36, @@ -112,7 +112,7 @@ const E_MOE_COMBINE: &str = concat!( /// `shared_expert.cu` (the Original TU: `shared_expert_multi`'s kernels and `moe_combine`). pub(crate) static SHARED: AssetSpec = AssetSpec { name: "mtp_original_full_shared.ptx", - ptx: include_bytes!("mtp_original_full_shared.ptx"), + ptx: include_bytes!("../mtp_original_full_shared.ptx"), sha: [ 179, 111, 67, 38, 146, 228, 63, 121, 72, 162, 83, 140, 34, 202, 181, 94, 246, 124, 98, 91, 141, 68, 97, 198, 124, 162, 162, 117, 25, 185, 224, 240, @@ -135,7 +135,7 @@ const E_QUANTIZE_Q8_1: &str = concat!( /// this name or union the entry lists of both specs). pub(crate) static HEAD_IQ_EXPERT: AssetSpec = AssetSpec { name: "mtp_original_full_head_iq.ptx#window-moe", - ptx: include_bytes!("mtp_original_full_head_iq.ptx"), + ptx: include_bytes!("../mtp_original_full_head_iq.ptx"), sha: [ 229, 116, 82, 204, 172, 119, 42, 138, 138, 119, 37, 59, 198, 201, 100, 235, 183, 188, 97, 253, 178, 233, 117, 39, 169, 119, 95, 140, 207, 60, 59, 159, @@ -149,7 +149,7 @@ const E_ADD_HITS: &str = /// `s2_expert_grouped.cu` (`moe_hit_add`). pub(crate) static S2_HITS: AssetSpec = AssetSpec { name: "mtp_original_full_s2.ptx", - ptx: include_bytes!("mtp_original_full_s2.ptx"), + ptx: include_bytes!("../mtp_original_full_s2.ptx"), sha: [ 251, 185, 23, 213, 144, 234, 128, 51, 138, 123, 223, 7, 178, 202, 109, 69, 143, 167, 39, 99, 186, 39, 158, 87, 107, 204, 30, 236, 136, 54, 253, 85, @@ -162,7 +162,7 @@ const E_COMBINE: &str = "mtp_full_combine"; /// `native_moe.cu` (`native_moe_combine(_multi)`). pub(crate) static COMBINE: AssetSpec = AssetSpec { name: "mtp_original_full_combine.ptx", - ptx: include_bytes!("mtp_original_full_combine.ptx"), + ptx: include_bytes!("../mtp_original_full_combine.ptx"), sha: [ 34, 83, 254, 45, 100, 19, 80, 244, 68, 90, 10, 105, 196, 160, 252, 34, 184, 92, 47, 255, 202, 124, 189, 83, 111, 254, 93, 41, 18, 248, 31, 183, @@ -216,7 +216,7 @@ const EXPERT_ENTRIES: &[&str] = &[ /// PTX compiled with nvcc 13.2.86 and sealed on 2026-10-15). pub(crate) static EXPERTS: AssetSpec = AssetSpec { name: "original_verify_window_moe_experts.ptx", - ptx: include_bytes!("original_verify_window_moe_experts.ptx"), + ptx: include_bytes!("../original_verify_window_moe_experts.ptx"), sha: [ 36, 210, 140, 205, 156, 58, 91, 190, 219, 235, 147, 59, 79, 235, 55, 111, 132, 10, 116, 226, 26, 68, 130, 23, 72, 140, 6, 238, 35, 130, 17, 87, @@ -233,7 +233,7 @@ pub(crate) static EXPERTS: AssetSpec = AssetSpec { /// sm_120, sm_86 companion in `sm86_table`), launched only by windows recorded with `pcie_mode` 2. pub(crate) static PCIE: AssetSpec = AssetSpec { name: "original_verify_window_pcie.ptx", - ptx: include_bytes!("original_verify_window_pcie.ptx"), + ptx: include_bytes!("../original_verify_window_pcie.ptx"), sha: [ 203, 235, 50, 63, 118, 71, 104, 47, 238, 158, 211, 241, 47, 183, 183, 165, 179, 235, 25, 47, 33, 102, 198, 236, 150, 184, 29, 85, 195, 186, 185, 209, @@ -246,7 +246,7 @@ pub(crate) static PCIE: AssetSpec = AssetSpec { /// loads in flight per thread. Loaded and launched only when `LELEKA_PCIE_KERNEL` names one (no sm_86 companion yet). pub(crate) static PCIE_FAST: AssetSpec = AssetSpec { name: "original_verify_window_pcie_fast.ptx", - ptx: include_bytes!("original_verify_window_pcie_fast.ptx"), + ptx: include_bytes!("../original_verify_window_pcie_fast.ptx"), sha: [ 116, 7, 133, 159, 141, 136, 129, 102, 63, 58, 100, 110, 190, 40, 140, 49, 19, 140, 206, 50, 39, 193, 197, 217, 226, 229, 146, 100, 142, 215, 122, 234, @@ -345,56 +345,32 @@ pub struct OriginalVerifyMoeBinding<'ctx> { } #[cfg(test)] -#[path = "original_verify_window_moe/tests.rs"] +#[path = "../original_verify_window_moe/tests.rs"] mod tests; -#[path = "original_verify_window_moe/pcie_fast_kernel.rs"] mod pcie_fast_kernel; -#[allow(unused_imports)] use pcie_fast_kernel::align256; -#[allow(unused_imports)] pub(crate) use pcie_fast_kernel::assets; -#[allow(unused_imports)] use pcie_fast_kernel::check_rows; -#[allow(unused_imports)] +#[cfg(test)] use pcie_fast_kernel::d_qk; -#[allow(unused_imports)] +#[cfg(test)] use pcie_fast_kernel::expert_blob; -#[allow(unused_imports)] use pcie_fast_kernel::f32s; -#[allow(unused_imports)] +#[cfg(test)] use pcie_fast_kernel::gu_qk; -#[allow(unused_imports)] use pcie_fast_kernel::items; -#[allow(unused_imports)] pub(crate) use pcie_fast_kernel::pcie_fast_kernel; -#[allow(unused_imports)] use pcie_fast_kernel::plan_word; -#[allow(unused_imports)] pub(crate) use pcie_fast_kernel::shared_attributes; -#[path = "original_verify_window_moe/plan_f32_to_bf16.rs"] mod plan_f32_to_bf16; -#[allow(unused_imports)] pub(crate) use plan_f32_to_bf16::BatchedRows; -#[allow(unused_imports)] pub(crate) use plan_f32_to_bf16::expert_scratch; -#[allow(unused_imports)] -use plan_f32_to_bf16::plan_f32_to_bf16; -#[allow(unused_imports)] pub(crate) use plan_f32_to_bf16::plan_quantize_expert_input; -#[allow(unused_imports)] -use plan_f32_to_bf16::plan_route; -#[allow(unused_imports)] pub(crate) use plan_f32_to_bf16::plan_router; -#[allow(unused_imports)] pub(crate) use plan_f32_to_bf16::plan_shared_expert; -#[path = "original_verify_window_moe/plan_expert_groups.rs"] mod plan_expert_groups; -#[allow(unused_imports)] pub(crate) use plan_expert_groups::ExpertGroupSite; -#[allow(unused_imports)] pub(crate) use plan_expert_groups::plan_combine; -#[allow(unused_imports)] pub(crate) use plan_expert_groups::plan_expert_groups; -#[allow(unused_imports)] pub(crate) use plan_expert_groups::plan_hit_add; diff --git a/crates/cuda-driver/src/original_verify_window_moe/pcie_fast_kernel.rs b/crates/cuda-driver/src/original_verify/moe/pcie_fast_kernel.rs similarity index 97% rename from crates/cuda-driver/src/original_verify_window_moe/pcie_fast_kernel.rs rename to crates/cuda-driver/src/original_verify/moe/pcie_fast_kernel.rs index 92dc69cf..aea2b2fa 100644 --- a/crates/cuda-driver/src/original_verify_window_moe/pcie_fast_kernel.rs +++ b/crates/cuda-driver/src/original_verify/moe/pcie_fast_kernel.rs @@ -1,5 +1,5 @@ -//! Methods of `MoeKnobs`: `mode17`. Methods of `ExpertBlob`: `words`. -//! Functions: `pcie_fast_kernel`, `pcie_kernel_name`, `pcie_grid`, `assets` and 13 more. +//! MoE family setup: assets, knobs and PCIe staging copy kernel choice, the expert blob formats a window supports, +//! the MoE buffer binding with its address checks, and the small arena helpers shared by the MoE planners. use super::{ ArenaMap, AssetSpec, COMBINE, Context, DeviceBuffer, ELEMENT, EXPERTS, Error, ExpertBlob, HEAD_IQ_EXPERT, MoeKnobs, diff --git a/crates/cuda-driver/src/original_verify_window_moe/plan_expert_groups.rs b/crates/cuda-driver/src/original_verify/moe/plan_expert_groups.rs similarity index 98% rename from crates/cuda-driver/src/original_verify_window_moe/plan_expert_groups.rs rename to crates/cuda-driver/src/original_verify/moe/plan_expert_groups.rs index 6170e2a7..2ed7aa16 100644 --- a/crates/cuda-driver/src/original_verify_window_moe/plan_expert_groups.rs +++ b/crates/cuda-driver/src/original_verify/moe/plan_expert_groups.rs @@ -1,5 +1,5 @@ -//! Methods of `GroupPlan`: `new`, `launches`, `upstream_layout`, `swiglu_quant` and 4 more. -//! Functions: `plan_expert_groups`, `group_kernels`, `fused_gate_up_entry`, `plan_hit_add` and 5 more. +//! Planner of the routed-expert launches of a window group: gate/up, SwiGLU with q8_1 quantization and down projection +//! per tier, then the hit add and the MoE combine (batched, native per row, or legacy). use super::super::down; use super::{ diff --git a/crates/cuda-driver/src/original_verify_window_moe/plan_f32_to_bf16.rs b/crates/cuda-driver/src/original_verify/moe/plan_f32_to_bf16.rs similarity index 98% rename from crates/cuda-driver/src/original_verify_window_moe/plan_f32_to_bf16.rs rename to crates/cuda-driver/src/original_verify/moe/plan_f32_to_bf16.rs index d5f2a149..e2c64495 100644 --- a/crates/cuda-driver/src/original_verify_window_moe/plan_f32_to_bf16.rs +++ b/crates/cuda-driver/src/original_verify/moe/plan_f32_to_bf16.rs @@ -1,5 +1,5 @@ -//! Methods of `BatchedRows`: `new`. Methods of `RouterSpans`: `mixed`, `logits`, `ids`, `weights`. -//! Functions: `plan_f32_to_bf16`, `plan_route`, `plan_router`, `router_batched` and 5 more. +//! Planner of the MoE front end: f32 to bf16 conversion, router logits with top-10 selection (batched or per row), +//! and the shared expert (conversion, projections, SwiGLU, gate scalar). use super::{ A, ArenaMap, Bf16GemvExtents, E_NATIVE_SWIGLU, E_QUANTIZE_Q8_1, E_ROUTE, E_ROUTER_TOP10, E_SCALAR_GATE, diff --git a/crates/cuda-driver/src/original_verify/original_verify_gdn_journal.rs b/crates/cuda-driver/src/original_verify/original_verify_gdn_journal.rs index 32e83ce6..ceb53f7e 100644 --- a/crates/cuda-driver/src/original_verify/original_verify_gdn_journal.rs +++ b/crates/cuda-driver/src/original_verify/original_verify_gdn_journal.rs @@ -1,5 +1,5 @@ -//! Groups the submodules `original_verify_window`, `verify_gdn_fused_step`, `verify_gdn_journal_ladder_logits_scan` ... -//! Split out of `original_verify` to keep its files under the line limit. +//! Parent of the GDN journal of the verify window: shares the imports of its submodules (window geometry, fused step, +//! logits scan, stage and commit, launch plumbing) so each one stays a single responsibility. use super::{ ASSET, ASSET_SHA, Arg, Command, Context, DeviceBuffer, EPS, Error, LAYER_BYTES, Module, OriginalCapture, @@ -14,5 +14,4 @@ mod verify_gdn_fused_step; mod verify_gdn_journal_ladder_logits_scan; mod verify_gdn_journal_stage_and_commit; mod verify_gdn_journal_window_launches; -#[allow(unused_imports)] pub(crate) use original_verify_window::verify_assets_sealed; diff --git a/crates/cuda-driver/src/original_verify/original_verify_gdn_journal/original_verify_window.rs b/crates/cuda-driver/src/original_verify/original_verify_gdn_journal/original_verify_window.rs index 282c94d4..5a75b907 100644 --- a/crates/cuda-driver/src/original_verify/original_verify_gdn_journal/original_verify_window.rs +++ b/crates/cuda-driver/src/original_verify/original_verify_gdn_journal/original_verify_window.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalVerifyWindow`: `validate_mtp_geometry`, `retained_residual_address_for_mtp`, `actual_mtp_resi... -//! Functions: `verify_assets_sealed`. +//! Geometry admission and residual-bank access of OriginalVerifyWindow for the MTP drafter, plus the probe that tells +//! whether the two verifier PTX assets are sealed. use super::{ASSET, ASSET_SHA, Error, OriginalVerifyWindow, QSA_ASSET, QSA_ASSET_SHA, Result, handle, sealed_asset}; diff --git a/crates/cuda-driver/src/original_verify/original_verify_gdn_journal/verify_gdn_journal_ladder_logits_scan.rs b/crates/cuda-driver/src/original_verify/original_verify_gdn_journal/verify_gdn_journal_ladder_logits_scan.rs index f38438f3..de6a6b3d 100644 --- a/crates/cuda-driver/src/original_verify/original_verify_gdn_journal/verify_gdn_journal_ladder_logits_scan.rs +++ b/crates/cuda-driver/src/original_verify/original_verify_gdn_journal/verify_gdn_journal_ladder_logits_scan.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalVerifyGdnJournal`: `capture_ladder`, `capture_ple_snapshot`, `validate_completed_logits`, `lo... -//! Methods of `OriginalVerifyResources`: `new`. +//! Journal captures of the verify window: the ladder diagnostic, PLE history snapshots, and the finite scan over the +//! head logits (post-drain or as graph nodes); also the verify resource bundle and the journal accessors. use super::{ Arg, Command, Context, DeviceBuffer, Error, OriginalCapture, OriginalGraphResources, OriginalVerifyBank, diff --git a/crates/cuda-driver/src/original_verify/original_verify_gdn_journal/verify_gdn_journal_stage_and_commit.rs b/crates/cuda-driver/src/original_verify/original_verify_gdn_journal/verify_gdn_journal_stage_and_commit.rs index 812d175d..deccfa88 100644 --- a/crates/cuda-driver/src/original_verify/original_verify_gdn_journal/verify_gdn_journal_stage_and_commit.rs +++ b/crates/cuda-driver/src/original_verify/original_verify_gdn_journal/verify_gdn_journal_stage_and_commit.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalVerifyGdnJournal`: `capture_layer_stage`, `stage_operands`, `stage_commands`, `stage_conv_com... -//! Methods of `FusedSpans`: `launch`. Functions: `single_command`. Defines `StageOperands`, `FusedSpans`. +//! GDN layer stage (convolution, alpha/beta, recurrence) and the commit graph of the journal: per-layer commit and +//! the fused 36-layer commit launch, with the affine-span checks the fused form relies on. use super::{ Arg, Command, EPS, Error, LAYER_BYTES, OriginalCapture, OriginalGraphResources, OriginalVerifyGdnJournal, diff --git a/crates/cuda-driver/src/original_verify/original_verify_gdn_journal/verify_gdn_journal_window_launches.rs b/crates/cuda-driver/src/original_verify/original_verify_gdn_journal/verify_gdn_journal_window_launches.rs index ce3c4645..22e14570 100644 --- a/crates/cuda-driver/src/original_verify/original_verify_gdn_journal/verify_gdn_journal_window_launches.rs +++ b/crates/cuda-driver/src/original_verify/original_verify_gdn_journal/verify_gdn_journal_window_launches.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalVerifyGdnJournal`: `ple_buffer`, `submit`, `submit_qsa`, `submit_with` and 16 more. -//! Functions: `launch_commands`, `admit_window_launches`, `window_module`. +//! Launch plumbing of the GDN journal: admits and submits window commands and launches on the capture stream, loads +//! window assets, and records the graph inputs, profile stamps and the group doorbell. use super::{ Arg, Command, Context, DeviceBuffer, Error, Module, OriginalCapture, OriginalVerifyGdnJournal, Rc, Result, chain, diff --git a/crates/cuda-driver/src/original_verify_window_planner.rs b/crates/cuda-driver/src/original_verify/planner.rs similarity index 99% rename from crates/cuda-driver/src/original_verify_window_planner.rs rename to crates/cuda-driver/src/original_verify/planner.rs index 8ac5572c..6d907d38 100644 --- a/crates/cuda-driver/src/original_verify_window_planner.rs +++ b/crates/cuda-driver/src/original_verify/planner.rs @@ -205,5 +205,5 @@ impl<'p> Planner<'p> { } #[cfg(test)] -#[path = "original_verify_window_planner/tests.rs"] +#[path = "../original_verify_window_planner/tests.rs"] mod tests; diff --git a/crates/cuda-driver/src/original_verify_profile.rs b/crates/cuda-driver/src/original_verify/profile.rs similarity index 100% rename from crates/cuda-driver/src/original_verify_profile.rs rename to crates/cuda-driver/src/original_verify/profile.rs diff --git a/crates/cuda-driver/src/original_verify_window_proj.rs b/crates/cuda-driver/src/original_verify/proj.rs similarity index 64% rename from crates/cuda-driver/src/original_verify_window_proj.rs rename to crates/cuda-driver/src/original_verify/proj.rs index 51d4ef43..3708732c 100644 --- a/crates/cuda-driver/src/original_verify_window_proj.rs +++ b/crates/cuda-driver/src/original_verify/proj.rs @@ -18,83 +18,39 @@ use crate::native_head::native_head_row_bytes; use crate::{Context, DeviceRef}; use crate::{Error, NativeHeadDispatch, Result}; -#[path = "mtp_original_full_head_dispatch.rs"] +#[path = "../mtp_dense_kv/original_int8/prefill/scalar/full_forward/head_dispatch.rs"] mod head_dispatch; #[cfg(test)] -#[path = "original_verify_window_proj/tests.rs"] +#[path = "../original_verify_window_proj/tests.rs"] mod tests; -#[path = "original_verify_window_proj/q8_1_row_bytes.rs"] mod q8_1_row_bytes; -#[allow(unused_imports)] pub(crate) use q8_1_row_bytes::is_iq_kind; -#[allow(unused_imports)] +#[cfg(test)] pub(crate) use q8_1_row_bytes::mmvf_block_size; -#[allow(unused_imports)] -pub(crate) use q8_1_row_bytes::mmvq_asset; -#[allow(unused_imports)] pub(crate) use q8_1_row_bytes::mmvq_assets; -#[allow(unused_imports)] -use q8_1_row_bytes::multi_entry; -#[allow(unused_imports)] pub(crate) use q8_1_row_bytes::native_matrix_bytes; -#[allow(unused_imports)] pub(crate) use q8_1_row_bytes::plan_bf16_gemv; -#[allow(unused_imports)] pub(crate) use q8_1_row_bytes::plan_mmvq; -#[allow(unused_imports)] pub(crate) use q8_1_row_bytes::plan_quantize_q8_1; -#[allow(unused_imports)] pub(crate) use q8_1_row_bytes::plan_window_mmvq; -#[allow(unused_imports)] pub(crate) use q8_1_row_bytes::plan_window_quantize; -#[allow(unused_imports)] -use q8_1_row_bytes::projection_first_row; -#[allow(unused_imports)] -use q8_1_row_bytes::projection_shape; -#[allow(unused_imports)] pub(crate) use q8_1_row_bytes::q8_1_row_bytes; -#[allow(unused_imports)] -use q8_1_row_bytes::quant_source_span; -#[allow(unused_imports)] -pub(crate) use q8_1_row_bytes::quant_source_width; -#[allow(unused_imports)] -use q8_1_row_bytes::single_entry; -#[allow(unused_imports)] pub(crate) use q8_1_row_bytes::{Bf16GemvExtents, MmvqExtents, StridedRows, WindowProjectionSite}; -#[path = "original_verify_window_proj/admit_matrix.rs"] mod admit_matrix; -#[allow(unused_imports)] -use admit_matrix::admit_matrix; -#[path = "original_verify_window_proj/head_native_entries_types.rs"] mod head_native_entries_types; -#[allow(unused_imports)] use head_native_entries_types::HEAD_NATIVE_ENTRIES; -#[path = "original_verify_window_proj/head_iq_entries_types.rs"] mod head_iq_entries_types; -#[allow(unused_imports)] pub(crate) use head_iq_entries_types::BF16; -#[allow(unused_imports)] use head_iq_entries_types::BF16_ENTRIES; -#[allow(unused_imports)] pub(crate) use head_iq_entries_types::GdnProjectionAddrs; -#[allow(unused_imports)] pub(crate) use head_iq_entries_types::HEAD_IQ; -#[allow(unused_imports)] -use head_iq_entries_types::HEAD_IQ_ENTRIES; -#[allow(unused_imports)] pub(crate) use head_iq_entries_types::HEAD_NATIVE; -#[allow(unused_imports)] pub(crate) use head_iq_entries_types::NativeWeight; -#[allow(unused_imports)] pub use head_iq_entries_types::OriginalVerifyGdnProjections; -#[allow(unused_imports)] pub use head_iq_entries_types::OriginalVerifyNativeMatrix; -#[allow(unused_imports)] pub use head_iq_entries_types::OriginalVerifyProjBinding; -#[allow(unused_imports)] pub use head_iq_entries_types::OriginalVerifyQsaProjections; -#[allow(unused_imports)] pub(crate) use head_iq_entries_types::QsaProjectionAddrs; diff --git a/crates/cuda-driver/src/original_verify_window_proj/admit_matrix.rs b/crates/cuda-driver/src/original_verify/proj/admit_matrix.rs similarity index 93% rename from crates/cuda-driver/src/original_verify_window_proj/admit_matrix.rs rename to crates/cuda-driver/src/original_verify/proj/admit_matrix.rs index b3ee4320..547d2866 100644 --- a/crates/cuda-driver/src/original_verify_window_proj/admit_matrix.rs +++ b/crates/cuda-driver/src/original_verify/proj/admit_matrix.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalVerifyProjBinding`: `new`, `gdn_addrs`, `qsa_addrs`, `assets`. Functions: `admit_matrix`. -//! Split out of `proj` to keep its files under the line limit. +//! Binding of the native projection matrices of the verifier window: admits each GDN and QSA matrix by exact byte size +//! and hands out per-layer device addresses and the sealed assets those weight types need. use super::{ AssetSpec, Context, Error, GdnProjectionAddrs, HEAD_IQ, HEAD_NATIVE, NativeWeight, OriginalVerifyGdnProjections, diff --git a/crates/cuda-driver/src/original_verify_window_proj/head_iq_entries_types.rs b/crates/cuda-driver/src/original_verify/proj/head_iq_entries_types.rs similarity index 94% rename from crates/cuda-driver/src/original_verify_window_proj/head_iq_entries_types.rs rename to crates/cuda-driver/src/original_verify/proj/head_iq_entries_types.rs index 8b78b3a3..03f7cc54 100644 --- a/crates/cuda-driver/src/original_verify_window_proj/head_iq_entries_types.rs +++ b/crates/cuda-driver/src/original_verify/proj/head_iq_entries_types.rs @@ -1,5 +1,5 @@ -//! Defines `NativeWeight`, `OriginalVerifyNativeMatrix`, `OriginalVerifyGdnProjections` and 4 more. -//! HEAD_IQ_ENTRIES, BF16_ENTRIES, HEAD_NATIVE, HEAD_IQ, BF16, NativeWeight .... +//! Sealed PTX asset specs of the projection family (native MMVQ, IQ-type MMVQ, BF16 GEMV) with their entry-name tables, +//! and the native weight, projection matrix and address types shared by the projection planners. use super::{AssetSpec, DeviceRef, HEAD_NATIVE_ENTRIES}; @@ -113,7 +113,7 @@ pub(super) const BF16_ENTRIES: &[&str] = &[ pub(crate) static HEAD_NATIVE: AssetSpec = AssetSpec { name: "mtp_original_full_head_native.ptx", - ptx: include_bytes!("../mtp_original_full_head_native.ptx"), + ptx: include_bytes!("../../mtp_original_full_head_native.ptx"), sha: [ 248, 32, 158, 28, 159, 191, 151, 139, 197, 123, 96, 176, 181, 246, 237, 202, 177, 144, 94, 73, 164, 171, 58, 169, 130, 96, 78, 62, 104, 15, 164, 55, @@ -123,7 +123,7 @@ pub(crate) static HEAD_NATIVE: AssetSpec = AssetSpec { }; pub(crate) static HEAD_IQ: AssetSpec = AssetSpec { name: "mtp_original_full_head_iq.ptx", - ptx: include_bytes!("../mtp_original_full_head_iq.ptx"), + ptx: include_bytes!("../../mtp_original_full_head_iq.ptx"), sha: [ 229, 116, 82, 204, 172, 119, 42, 138, 138, 119, 37, 59, 198, 201, 100, 235, 183, 188, 97, 253, 178, 233, 117, 39, 169, 119, 95, 140, 207, 60, 59, 159, @@ -133,7 +133,7 @@ pub(crate) static HEAD_IQ: AssetSpec = AssetSpec { }; pub(crate) static BF16: AssetSpec = AssetSpec { name: "mtp_original_full_bf16.ptx", - ptx: include_bytes!("../mtp_original_full_bf16.ptx"), + ptx: include_bytes!("../../mtp_original_full_bf16.ptx"), sha: [ 161, 109, 252, 252, 154, 73, 204, 171, 37, 216, 3, 2, 147, 213, 130, 111, 143, 117, 226, 134, 143, 174, 27, 108, 76, 239, 112, 107, 109, 252, 61, 8, diff --git a/crates/cuda-driver/src/original_verify_window_proj/head_native_entries_types.rs b/crates/cuda-driver/src/original_verify/proj/head_native_entries_types.rs similarity index 96% rename from crates/cuda-driver/src/original_verify_window_proj/head_native_entries_types.rs rename to crates/cuda-driver/src/original_verify/proj/head_native_entries_types.rs index 99bd4c56..d786d79c 100644 --- a/crates/cuda-driver/src/original_verify_window_proj/head_native_entries_types.rs +++ b/crates/cuda-driver/src/original_verify/proj/head_native_entries_types.rs @@ -1,5 +1,5 @@ -//! Items of the parent module. -//! HEAD_NATIVE_ENTRIES. +//! Entry-point name table of the sealed native head PTX asset (q8_1 quantize and the MMVQ kernel variants), +//! kept apart because it is a long literal list checked against the PTX. pub(super) const HEAD_NATIVE_ENTRIES: &[&str] = &[ "head_quant", diff --git a/crates/cuda-driver/src/original_verify_window_proj/q8_1_row_bytes.rs b/crates/cuda-driver/src/original_verify/proj/q8_1_row_bytes.rs similarity index 98% rename from crates/cuda-driver/src/original_verify_window_proj/q8_1_row_bytes.rs rename to crates/cuda-driver/src/original_verify/proj/q8_1_row_bytes.rs index 54f53021..89803530 100644 --- a/crates/cuda-driver/src/original_verify_window_proj/q8_1_row_bytes.rs +++ b/crates/cuda-driver/src/original_verify/proj/q8_1_row_bytes.rs @@ -1,5 +1,5 @@ -//! Methods of `StridedRows`: `new`. Methods of `Bf16GemvExtents`: `new`. -//! Functions: `q8_1_row_bytes`, `is_iq_kind`, `mmvq_assets`, `mmvq_asset` and 17 more. +//! Launch planners of the projection family: q8_1 quantization, native MMVQ and BF16 GEMV (extents, strides, kernel +//! entry choice), and the window projection producers. Pure addresses in, Launch out. use super::{ A, ArenaMap, AssetSpec, BF16, BF16_ENTRIES, Error, GdnProjectionAddrs, HEAD_IQ, HEAD_NATIVE, Launch, LaunchExtent, diff --git a/crates/cuda-driver/src/original_verify_window_qsa.rs b/crates/cuda-driver/src/original_verify/qsa.rs similarity index 94% rename from crates/cuda-driver/src/original_verify_window_qsa.rs rename to crates/cuda-driver/src/original_verify/qsa.rs index e4ad99fd..59e52c26 100644 --- a/crates/cuda-driver/src/original_verify_window_qsa.rs +++ b/crates/cuda-driver/src/original_verify/qsa.rs @@ -51,7 +51,7 @@ const GATE_ENTRIES: &[&str] = &["verify_window_qsa_gate"]; /// Literal Original `native_qsa::norm<256>` and `native_rope::apply`, `--use_fast_math`. pub(crate) static DECODE_POSTOPS: AssetSpec = AssetSpec { name: "qsa_decode_postops.ptx", - ptx: include_bytes!("qsa_decode_postops.ptx"), + ptx: include_bytes!("../qsa_decode_postops.ptx"), sha: [ 253, 118, 230, 248, 69, 87, 215, 242, 166, 42, 197, 110, 22, 213, 228, 247, 136, 98, 231, 86, 239, 152, 82, 176, 77, 89, 25, 153, 33, 58, 81, 25, @@ -62,7 +62,7 @@ pub(crate) static DECODE_POSTOPS: AssetSpec = AssetSpec { /// `qsa_split_q`: the q half of `qfull` (the q/gate split copy). pub(crate) static SPLIT: AssetSpec = AssetSpec { name: "qsa_prompt_postops.ptx", - ptx: include_bytes!("qsa_prompt_postops.ptx"), + ptx: include_bytes!("../qsa_prompt_postops.ptx"), sha: [ 72, 106, 115, 176, 107, 58, 52, 242, 152, 245, 126, 146, 194, 12, 200, 57, 77, 197, 157, 123, 216, 75, 92, 204, 248, 218, 83, 170, 80, 129, 172, 159, @@ -73,7 +73,7 @@ pub(crate) static SPLIT: AssetSpec = AssetSpec { /// Original `kv_append_q8_kernel` (precise flags). pub(crate) static KV_APPEND: AssetSpec = AssetSpec { name: "mtp_original_kv.ptx", - ptx: include_bytes!("mtp_original_kv.ptx"), + ptx: include_bytes!("../mtp_original_kv.ptx"), sha: [ 224, 193, 255, 16, 211, 212, 188, 248, 253, 51, 105, 113, 48, 121, 178, 50, 230, 44, 219, 44, 58, 52, 95, 174, 196, 157, 30, 102, 118, 63, 145, 31, @@ -84,7 +84,7 @@ pub(crate) static KV_APPEND: AssetSpec = AssetSpec { /// Original `block_scores_multi_kernel` / `block_scores_kernel` / `block_topk_kernel`. pub(crate) static SELECT: AssetSpec = AssetSpec { name: "qsa_prompt_select.ptx", - ptx: include_bytes!("qsa_prompt_select.ptx"), + ptx: include_bytes!("../qsa_prompt_select.ptx"), sha: [ 30, 53, 81, 71, 68, 33, 98, 41, 176, 207, 251, 79, 69, 210, 241, 63, 37, 203, 149, 243, 119, 163, 12, 28, 1, 37, 67, 219, 245, 58, 28, 45, @@ -95,7 +95,7 @@ pub(crate) static SELECT: AssetSpec = AssetSpec { /// Original `kv_stream.cu` `resolve_kernel` + `copy_kernel`. pub(crate) static RESOLVER: AssetSpec = AssetSpec { name: "qsa_prompt_resolver.ptx", - ptx: include_bytes!("qsa_prompt_resolver.ptx"), + ptx: include_bytes!("../qsa_prompt_resolver.ptx"), sha: [ 141, 62, 203, 174, 203, 242, 132, 69, 186, 100, 72, 91, 223, 243, 217, 26, 33, 216, 123, 133, 213, 147, 154, 1, 82, 239, 47, 36, 20, 72, 14, 34, @@ -106,7 +106,7 @@ pub(crate) static RESOLVER: AssetSpec = AssetSpec { /// Original `attn_chunk_kernel<1>` + `attn_merge_kernel` (batched form). pub(crate) static ATTENTION: AssetSpec = AssetSpec { name: "mtp_original_full_attention.ptx", - ptx: include_bytes!("mtp_original_full_attention.ptx"), + ptx: include_bytes!("../mtp_original_full_attention.ptx"), sha: [ 63, 178, 53, 202, 64, 93, 36, 195, 184, 208, 236, 70, 97, 29, 157, 100, 1, 3, 183, 26, 101, 133, 153, 35, 25, 79, 2, 240, 107, 72, 47, 108, @@ -118,7 +118,7 @@ pub(crate) static ATTENTION: AssetSpec = AssetSpec { /// 2026-10-15. pub(crate) static GATE: AssetSpec = AssetSpec { name: "original_verify_window_qsa_gate.ptx", - ptx: include_bytes!("original_verify_window_qsa_gate.ptx"), + ptx: include_bytes!("../original_verify_window_qsa_gate.ptx"), sha: [ 16, 128, 124, 76, 98, 216, 191, 75, 231, 92, 251, 26, 80, 119, 252, 62, 0, 220, 143, 64, 234, 102, 155, 34, 220, 255, 123, 120, 83, 171, 121, 73, @@ -285,28 +285,17 @@ struct Span { } #[cfg(test)] -#[path = "original_verify_window_qsa/tests.rs"] +#[path = "../original_verify_window_qsa/tests.rs"] mod tests; -#[path = "original_verify_window_qsa/assets.rs"] mod assets; -#[allow(unused_imports)] pub(crate) use assets::assets; -#[allow(unused_imports)] pub(crate) use assets::cluster_assets; -#[allow(unused_imports)] pub(crate) use assets::daily_assets; -#[allow(unused_imports)] use assets::declared_i32; -#[allow(unused_imports)] use assets::grid_u32; -#[allow(unused_imports)] use assets::max_blocks; -#[allow(unused_imports)] use assets::scratch_floats; -#[allow(unused_imports)] pub(crate) use assets::shared_attributes; -#[path = "original_verify_window_qsa/fused_prelude.rs"] pub(crate) mod fused_prelude; -#[path = "original_verify_window_qsa/qsa_window.rs"] mod qsa_window; diff --git a/crates/cuda-driver/src/original_verify_window_qsa/assets.rs b/crates/cuda-driver/src/original_verify/qsa/assets.rs similarity index 97% rename from crates/cuda-driver/src/original_verify_window_qsa/assets.rs rename to crates/cuda-driver/src/original_verify/qsa/assets.rs index 82c85dd3..d5321190 100644 --- a/crates/cuda-driver/src/original_verify_window_qsa/assets.rs +++ b/crates/cuda-driver/src/original_verify/qsa/assets.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalVerifyQsaPolicy`: `mode17`, `validate`. Methods of `QsaRope`: `new`, `from_rope`, `is_identity`. -//! Functions: `assets`, `cluster_assets`, `daily_assets`, `shared_attributes` and 4 more. +//! QSA (quantized sparse attention) setup of the verifier window: sealed assets and shared-memory attributes, the +//! mode17 policy and its validation, RoPE constants, and the KV and weight bindings with their admission checks. use super::{ ATTENTION, ATTN_CHUNK, AssetSpec, CLUSTER, CLUSTER_ENTRIES, Context, DECODE_POSTOPS, Error, GATE, KV_APPEND, diff --git a/crates/cuda-driver/src/original_verify_window_qsa/fused_prelude.rs b/crates/cuda-driver/src/original_verify/qsa/fused_prelude.rs similarity index 96% rename from crates/cuda-driver/src/original_verify_window_qsa/fused_prelude.rs rename to crates/cuda-driver/src/original_verify/qsa/fused_prelude.rs index fd7b79c9..b644467d 100644 --- a/crates/cuda-driver/src/original_verify_window_qsa/fused_prelude.rs +++ b/crates/cuda-driver/src/original_verify/qsa/fused_prelude.rs @@ -27,7 +27,7 @@ pub(crate) const E_INDEX_ROWS: &str = "leleka_verify_qsa_index_rows"; /// a pin does not match its bytes. pub(crate) static KV_ROWS: AssetSpec = AssetSpec { name: "original_verify_window_qsa_kv_rows.ptx", - ptx: concat!(include_str!("../original_verify_window_qsa_kv_rows.ptx"), "\0").as_bytes(), + ptx: concat!(include_str!("../../original_verify_window_qsa_kv_rows.ptx"), "\0").as_bytes(), sha: [ 217, 24, 52, 136, 189, 9, 207, 86, 34, 6, 137, 55, 116, 152, 82, 81, 123, 82, 109, 46, 201, 207, 91, 113, 81, 42, 29, 254, 208, 161, 219, 133, @@ -40,7 +40,7 @@ pub(crate) static KV_ROWS: AssetSpec = AssetSpec { /// `KV_ROWS`. pub(crate) static INDEX_ROWS: AssetSpec = AssetSpec { name: "original_verify_window_qsa_index_rows.ptx", - ptx: concat!(include_str!("../original_verify_window_qsa_index_rows.ptx"), "\0").as_bytes(), + ptx: concat!(include_str!("../../original_verify_window_qsa_index_rows.ptx"), "\0").as_bytes(), sha: [ 113, 219, 156, 79, 31, 64, 14, 200, 110, 124, 241, 140, 177, 124, 53, 4, 138, 238, 50, 70, 215, 152, 40, 219, 112, 252, 43, 86, 45, 44, 213, 125, @@ -202,5 +202,5 @@ pub(crate) fn index_dim_supported(index_dim: usize) -> bool { } #[cfg(test)] -#[path = "fused_prelude/tests.rs"] +#[path = "../../original_verify_window_qsa/fused_prelude/tests.rs"] mod tests; diff --git a/crates/cuda-driver/src/original_verify_window_qsa/qsa_window.rs b/crates/cuda-driver/src/original_verify/qsa/qsa_window.rs similarity index 64% rename from crates/cuda-driver/src/original_verify_window_qsa/qsa_window.rs rename to crates/cuda-driver/src/original_verify/qsa/qsa_window.rs index d8073764..ae08106f 100644 --- a/crates/cuda-driver/src/original_verify_window_qsa/qsa_window.rs +++ b/crates/cuda-driver/src/original_verify/qsa/qsa_window.rs @@ -1,5 +1,5 @@ -//! Groups the submodules `qsa_window_prelude_rows`, `qsa_window_query_key_paths`, `qsa_window_select_and_attend`. -//! Split out of `qsa` to keep its files under the line limit. +//! Parent of QsaWindow, the launch planner of one QSA layer in the verifier window; its submodules split the prelude +//! rows, the query/key paths and the select-and-attend steps while sharing these imports. use super::{ A, ATTENTION, ATTN_CHUNK, ArenaMap, Bf16GemvExtents, CLUSTER, CLUSTER_ENTRIES, CLUSTER_MAX_QUERIES, DECODE_POSTOPS, @@ -9,9 +9,6 @@ use super::{ plan_bf16_gemv, rope_abi, scratch_floats, }; -#[path = "qsa_window/qsa_window_prelude_rows.rs"] mod qsa_window_prelude_rows; -#[path = "qsa_window/qsa_window_query_key_paths.rs"] mod qsa_window_query_key_paths; -#[path = "qsa_window/qsa_window_select_and_attend.rs"] mod qsa_window_select_and_attend; diff --git a/crates/cuda-driver/src/original_verify_window_qsa/qsa_window/qsa_window_prelude_rows.rs b/crates/cuda-driver/src/original_verify/qsa/qsa_window/qsa_window_prelude_rows.rs similarity index 100% rename from crates/cuda-driver/src/original_verify_window_qsa/qsa_window/qsa_window_prelude_rows.rs rename to crates/cuda-driver/src/original_verify/qsa/qsa_window/qsa_window_prelude_rows.rs diff --git a/crates/cuda-driver/src/original_verify_window_qsa/qsa_window/qsa_window_query_key_paths.rs b/crates/cuda-driver/src/original_verify/qsa/qsa_window/qsa_window_query_key_paths.rs similarity index 98% rename from crates/cuda-driver/src/original_verify_window_qsa/qsa_window/qsa_window_query_key_paths.rs rename to crates/cuda-driver/src/original_verify/qsa/qsa_window/qsa_window_query_key_paths.rs index 0459ec45..85d5d571 100644 --- a/crates/cuda-driver/src/original_verify_window_qsa/qsa_window/qsa_window_query_key_paths.rs +++ b/crates/cuda-driver/src/original_verify/qsa/qsa_window/qsa_window_query_key_paths.rs @@ -1,5 +1,5 @@ -//! Methods of `QsaWindow`: `new`, `span`, `rows`, `rms` and 12 more. Functions: `append_launch`. -//! Split out of `qsa_window` to keep its files under the line limit. +//! QsaWindow launch planners for the query, key and index paths: RMS norm and RoPE, indexer k and q projections, +//! k norm with RoPE, q/gate split, and the KV append into the resident pool and host copy. use super::{ A, ArenaMap, Bf16GemvExtents, DECODE_POSTOPS, EPS, Error, KV_APPEND, Launch, LaunchExtent, OriginalVerifyGeometry, diff --git a/crates/cuda-driver/src/original_verify_window_qsa/qsa_window/qsa_window_select_and_attend.rs b/crates/cuda-driver/src/original_verify/qsa/qsa_window/qsa_window_select_and_attend.rs similarity index 98% rename from crates/cuda-driver/src/original_verify_window_qsa/qsa_window/qsa_window_select_and_attend.rs rename to crates/cuda-driver/src/original_verify/qsa/qsa_window/qsa_window_select_and_attend.rs index 7013d241..f2f8030e 100644 --- a/crates/cuda-driver/src/original_verify_window_qsa/qsa_window/qsa_window_select_and_attend.rs +++ b/crates/cuda-driver/src/original_verify/qsa/qsa_window/qsa_window_select_and_attend.rs @@ -1,5 +1,5 @@ -//! Methods of `QsaWindow`: `block_scores_topk`, `scores_launch`, `topk_launch`, `kv_resolve` and 5 more. -//! Defines `AttnDims`, `AttnSpans`. +//! QsaWindow launch planners for block selection and attention: block scores and top-k, KV streaming resolve, +//! split decode attention (chunk and merge) and the output gate. use super::{ A, ATTENTION, ATTN_CHUNK, CLUSTER, CLUSTER_ENTRIES, CLUSTER_MAX_QUERIES, Error, GATE, Launch, LaunchExtent, diff --git a/crates/cuda-driver/src/original_verify_schedule.rs b/crates/cuda-driver/src/original_verify/schedule.rs similarity index 89% rename from crates/cuda-driver/src/original_verify_schedule.rs rename to crates/cuda-driver/src/original_verify/schedule.rs index 8e1471b4..f0790d37 100644 --- a/crates/cuda-driver/src/original_verify_schedule.rs +++ b/crates/cuda-driver/src/original_verify/schedule.rs @@ -77,17 +77,10 @@ pub struct OriginalVerifier<'ctx, R: OriginalVerifyGraphResources<'ctx> + Origin test_stall: u64, } -#[path = "original_verify_schedule/commit_sync_forced.rs"] mod commit_sync_forced; -#[allow(unused_imports)] use commit_sync_forced::commit_sync_forced; -#[path = "original_verify_schedule/original_verifier.rs"] mod original_verifier; -#[path = "original_verify_schedule/verifier_commit_window_lifecycle.rs"] mod verifier_commit_window_lifecycle; -#[path = "original_verify_schedule/verifier_logits_diagnostics_close.rs"] mod verifier_logits_diagnostics_close; -#[path = "original_verify_schedule/verifier_park_rearm.rs"] mod verifier_park_rearm; -#[path = "original_verify_schedule/window_phases.rs"] mod window_phases; diff --git a/crates/cuda-driver/src/original_verify_schedule/commit_sync_forced.rs b/crates/cuda-driver/src/original_verify/schedule/commit_sync_forced.rs similarity index 98% rename from crates/cuda-driver/src/original_verify_schedule/commit_sync_forced.rs rename to crates/cuda-driver/src/original_verify/schedule/commit_sync_forced.rs index cf50a6f0..df488b80 100644 --- a/crates/cuda-driver/src/original_verify_schedule/commit_sync_forced.rs +++ b/crates/cuda-driver/src/original_verify/schedule/commit_sync_forced.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalVerifyCpuSink`: `with_output`. -//! Methods of `OriginalVerifier`: `new`, `open`, `unopened`, `bank` and 9 more. +//! Construction and window recording of OriginalVerifier: opens the bank, records the window and commit graphs (fused +//! or per-layer commit), sets the PCIe mode and split, plus the CPU sink output accessor. use super::{ Context, Error, OriginalCapture, OriginalCapturePolicy, OriginalEventKind, OriginalNativeHeadGraphResources, diff --git a/crates/cuda-driver/src/original_verify_schedule/original_verifier.rs b/crates/cuda-driver/src/original_verify/schedule/original_verifier.rs similarity index 94% rename from crates/cuda-driver/src/original_verify_schedule/original_verifier.rs rename to crates/cuda-driver/src/original_verify/schedule/original_verifier.rs index 7fc00a37..ae8a90ba 100644 --- a/crates/cuda-driver/src/original_verify_schedule/original_verifier.rs +++ b/crates/cuda-driver/src/original_verify/schedule/original_verifier.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalVerifier`: `run`, `commit`, `commit_after_stage`, `complete_commit_sync`. -//! Split out of `schedule` to keep its files under the line limit. +//! Run and commit entry points of OriginalVerifier: run executes the cached window graph with the CPU/GPU split, +//! commit stages the accepted rows and launches the commit graph, asynchronously or drained. use super::{ Error, NativeHeadSampling, OriginalGpuStream, OriginalNativeHeadGraphResources, OriginalVerifier, diff --git a/crates/cuda-driver/src/original_verify_schedule/verifier_commit_window_lifecycle.rs b/crates/cuda-driver/src/original_verify/schedule/verifier_commit_window_lifecycle.rs similarity index 97% rename from crates/cuda-driver/src/original_verify_schedule/verifier_commit_window_lifecycle.rs rename to crates/cuda-driver/src/original_verify/schedule/verifier_commit_window_lifecycle.rs index 21d63c85..dd04915f 100644 --- a/crates/cuda-driver/src/original_verify_schedule/verifier_commit_window_lifecycle.rs +++ b/crates/cuda-driver/src/original_verify/schedule/verifier_commit_window_lifecycle.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalVerifier`: `pending_commit_event`, `wait_commit`, `complete_pending_commit`, `discard_window`... -//! Split out of `schedule` to keep its files under the line limit. +//! Post-run lifecycle of OriginalVerifier: pending commit wait, discarding a window for a retry, access to the +//! completed window, committed GDN and QSA state, diagnostics, and the watchdog release of the GPU waits. use super::{ DeviceBuffer, Duration, Error, Instant, OriginalGpuEvent, OriginalNativeHeadGraphResources, OriginalVerifier, diff --git a/crates/cuda-driver/src/original_verify_schedule/verifier_logits_diagnostics_close.rs b/crates/cuda-driver/src/original_verify/schedule/verifier_logits_diagnostics_close.rs similarity index 98% rename from crates/cuda-driver/src/original_verify_schedule/verifier_logits_diagnostics_close.rs rename to crates/cuda-driver/src/original_verify/schedule/verifier_logits_diagnostics_close.rs index f443dc7d..f09ebd14 100644 --- a/crates/cuda-driver/src/original_verify_schedule/verifier_logits_diagnostics_close.rs +++ b/crates/cuda-driver/src/original_verify/schedule/verifier_logits_diagnostics_close.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalVerifier`: `read_logit_rows`, `copy_logits`, `window_logprobs`, `window_logprobs_topk` and 7 ... -//! Implements `Drop for OriginalVerifier`. +//! Read-back side of OriginalVerifier: logits and logprob rows, bring-up residual and ladder dumps, the bounded +//! stream drain that aborts GPU waits, and the close and Drop teardown. use super::{ Context, DeviceBuffer, Duration, Error, Instant, LogitRows, LogprobReadout, OriginalGpuStream, diff --git a/crates/cuda-driver/src/original_verify_schedule/verifier_park_rearm.rs b/crates/cuda-driver/src/original_verify/schedule/verifier_park_rearm.rs similarity index 98% rename from crates/cuda-driver/src/original_verify_schedule/verifier_park_rearm.rs rename to crates/cuda-driver/src/original_verify/schedule/verifier_park_rearm.rs index 633d517e..d1926552 100644 --- a/crates/cuda-driver/src/original_verify_schedule/verifier_park_rearm.rs +++ b/crates/cuda-driver/src/original_verify/schedule/verifier_park_rearm.rs @@ -112,5 +112,5 @@ impl<'ctx, R: OriginalVerifyGraphResources<'ctx> + OriginalNativeHeadGraphResour } #[cfg(test)] -#[path = "park_rearm_tests.rs"] +#[path = "../../original_verify_schedule/park_rearm_tests.rs"] mod tests; diff --git a/crates/cuda-driver/src/original_verify_schedule/window_phases.rs b/crates/cuda-driver/src/original_verify/schedule/window_phases.rs similarity index 100% rename from crates/cuda-driver/src/original_verify_schedule/window_phases.rs rename to crates/cuda-driver/src/original_verify/schedule/window_phases.rs diff --git a/crates/cuda-driver/src/original_verify/share_window_modules.rs b/crates/cuda-driver/src/original_verify/share_window_modules.rs index 632527de..82e1b5b3 100644 --- a/crates/cuda-driver/src/original_verify/share_window_modules.rs +++ b/crates/cuda-driver/src/original_verify/share_window_modules.rs @@ -1,5 +1,5 @@ -//! Groups the submodules `verify_bank_and_canonical_gdn_open`, `original_verify_bank`, `physical` and 1 more. -//! Split out of `original_verify` to keep its files under the line limit. +//! Parent of the verify bank files: opening the bank and canonical GDN, the bank staging, its physical resources and +//! the plan and window row accessors, with the imports they share. use super::{ ASSET, ASSET_SHA, Arg, CANONICAL_BYTES, Canonical, Cell, Command, Context, DeviceBuffer, DeviceRef, ENTRIES, Error, @@ -10,29 +10,17 @@ use super::{ }; mod verify_bank_and_canonical_gdn_open; -#[allow(unused_imports)] pub(super) use verify_bank_and_canonical_gdn_open::admission; -#[allow(unused_imports)] pub(super) use verify_bank_and_canonical_gdn_open::admit; -#[allow(unused_imports)] pub(super) use verify_bank_and_canonical_gdn_open::check_canonical_lengths; -#[allow(unused_imports)] pub(super) use verify_bank_and_canonical_gdn_open::check_commands; -#[allow(unused_imports)] pub(super) use verify_bank_and_canonical_gdn_open::command; -#[allow(unused_imports)] pub(crate) use verify_bank_and_canonical_gdn_open::gather_rows_module; -#[allow(unused_imports)] pub(super) use verify_bank_and_canonical_gdn_open::handle; -#[allow(unused_imports)] pub(super) use verify_bank_and_canonical_gdn_open::poison; -#[allow(unused_imports)] pub(super) use verify_bank_and_canonical_gdn_open::sealed_asset; -#[allow(unused_imports)] pub(super) use verify_bank_and_canonical_gdn_open::share_window_modules; -#[allow(unused_imports)] pub(super) use verify_bank_and_canonical_gdn_open::transport; -#[allow(unused_imports)] pub(super) use verify_bank_and_canonical_gdn_open::zero; mod original_verify_bank; mod physical; diff --git a/crates/cuda-driver/src/original_verify/share_window_modules/original_verify_bank.rs b/crates/cuda-driver/src/original_verify/share_window_modules/original_verify_bank.rs index da0a506e..fabcc860 100644 --- a/crates/cuda-driver/src/original_verify/share_window_modules/original_verify_bank.rs +++ b/crates/cuda-driver/src/original_verify/share_window_modules/original_verify_bank.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalVerifyBank`: `new`, `staged_window`, `staged_keep`, `completed_row` and 14 more. -//! Split out of `share_window_modules` to keep its files under the line limit. +//! Host-side staging of OriginalVerifyBank: creation, staging of tokens, positions, PLE values and the commit keep +//! count into the mapped words, completed-row access, and the release of the GPU waits. use super::{ ASSET, ASSET_SHA, Context, Error, OriginalVerifyBank, OriginalVerifyGeometry, OriginalVerifyLayout, diff --git a/crates/cuda-driver/src/original_verify/share_window_modules/physical.rs b/crates/cuda-driver/src/original_verify/share_window_modules/physical.rs index 844716f7..ff32cce0 100644 --- a/crates/cuda-driver/src/original_verify/share_window_modules/physical.rs +++ b/crates/cuda-driver/src/original_verify/share_window_modules/physical.rs @@ -1,5 +1,5 @@ -//! Methods of `Physical`: `validate`, `span`, `ensure_window_assets`, `select_ready` and 15 more. -//! Implements `Drop for Physical`. Functions: `group_specs`, `reuse_loaded`. Defines `WindowGroup`, `ReadyModule`. +//! Physical: the device resources behind a verify bank (kernel modules, mapped staging, arena, profile stamps), its +//! window-module loading with sharing across banks of a context, shared-memory configuration, and teardown. use super::{ Cell, Context, DeviceBuffer, ENTRIES, Error, MappedAllocation, Module, OriginalVerifyLayout, Physical, QSA_ENTRIES, diff --git a/crates/cuda-driver/src/original_verify/share_window_modules/verify_bank_and_canonical_gdn_open.rs b/crates/cuda-driver/src/original_verify/share_window_modules/verify_bank_and_canonical_gdn_open.rs index e9c57ef3..7b4bff6a 100644 --- a/crates/cuda-driver/src/original_verify/share_window_modules/verify_bank_and_canonical_gdn_open.rs +++ b/crates/cuda-driver/src/original_verify/share_window_modules/verify_bank_and_canonical_gdn_open.rs @@ -1,5 +1,5 @@ -//! Methods of `Context`: `original_verify_canonical_gdn`, `original_verify_bank`. -//! Methods of `Canonical`: `upload_layers`, `reseed`, `allocated_bytes`, `validate_context` and 4 more. +//! Entry points that open a verify bank and the canonical GDN image on a Context, the checked helpers shared by the +//! bank files (admit, poison, sealed asset), and the canonical state upload, reseed, read and close. use super::{ ASSET, ASSET_SHA, Arg, CANONICAL_BYTES, Canonical, Cell, Command, Context, DeviceBuffer, ENTRIES, Error, diff --git a/crates/cuda-driver/src/original_verify/share_window_modules/verify_bank_plan_and_window_rows.rs b/crates/cuda-driver/src/original_verify/share_window_modules/verify_bank_plan_and_window_rows.rs index 7c1b10b5..e3337dc4 100644 --- a/crates/cuda-driver/src/original_verify/share_window_modules/verify_bank_plan_and_window_rows.rs +++ b/crates/cuda-driver/src/original_verify/share_window_modules/verify_bank_plan_and_window_rows.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalVerifyBank`: `read_profile`, `doorbell_sequence`, `publish_empty_plan`, `zero_plan_header` an... -//! Methods of `OriginalVerifyRow`: `position`, `validate_context`, `residual`. +//! Bank-side plan and journal access: profile read, doorbell sequence, empty plan publication, PCIe source retention, +//! GDN journal construction with operand checks, and the accessors of completed rows and windows. use super::{ Context, DeviceBuffer, DeviceRef, Error, MappedAllocation, OriginalGraphResources, OriginalVerifyBank, diff --git a/crates/cuda-driver/src/original_verify_window_sm120.rs b/crates/cuda-driver/src/original_verify/sm120.rs similarity index 99% rename from crates/cuda-driver/src/original_verify_window_sm120.rs rename to crates/cuda-driver/src/original_verify/sm120.rs index 37421f05..816d371d 100644 --- a/crates/cuda-driver/src/original_verify_window_sm120.rs +++ b/crates/cuda-driver/src/original_verify/sm120.rs @@ -32,7 +32,7 @@ pub(crate) const E_ATTN_MERGE_V2: &str = "leleka_qsa_decode_merge_v2"; /// `sm120_attn_daily.cu`, sealed by `scripts/gpu-bringup/seal_pins.py` (extra-seal-plan.json, group sm120-decode). pub(crate) static ATTN_DAILY: AssetSpec = AssetSpec { name: "sm120_attn_daily.ptx", - ptx: concat!(include_str!("sm120_attn_daily.ptx"), "\0").as_bytes(), + ptx: concat!(include_str!("../sm120_attn_daily.ptx"), "\0").as_bytes(), sha: [ 73, 254, 226, 193, 238, 114, 44, 253, 105, 185, 137, 63, 194, 92, 42, 62, 145, 177, 230, 181, 184, 134, 234, 111, 57, 33, 127, 124, 167, 213, 98, 213, @@ -55,7 +55,7 @@ pub(crate) const GU_SWIGLU_TYPES: [u32; 6] = [16, 17, 18, 21, 22, 23]; /// `sm120_gu_swiglu.cu`, sealed by `scripts/gpu-bringup/seal_pins.py` (extra-seal-plan.json, group sm120-decode). pub(crate) static GU_SWIGLU: AssetSpec = AssetSpec { name: "sm120_gu_swiglu.ptx", - ptx: concat!(include_str!("sm120_gu_swiglu.ptx"), "\0").as_bytes(), + ptx: concat!(include_str!("../sm120_gu_swiglu.ptx"), "\0").as_bytes(), sha: [ 107, 0, 213, 80, 35, 131, 13, 91, 78, 112, 245, 194, 119, 44, 69, 22, 61, 118, 18, 91, 59, 9, 185, 31, 8, 119, 145, 191, 64, 140, 101, 123, diff --git a/crates/cuda-driver/src/original_verify_window_gpu.rs b/crates/cuda-driver/src/original_verify/window_gpu.rs similarity index 100% rename from crates/cuda-driver/src/original_verify_window_gpu.rs rename to crates/cuda-driver/src/original_verify/window_gpu.rs diff --git a/crates/cuda-driver/src/original_verify_window_ops.rs b/crates/cuda-driver/src/original_verify/window_ops.rs similarity index 89% rename from crates/cuda-driver/src/original_verify_window_ops.rs rename to crates/cuda-driver/src/original_verify/window_ops.rs index 0d056b03..7b57ba95 100644 --- a/crates/cuda-driver/src/original_verify_window_ops.rs +++ b/crates/cuda-driver/src/original_verify/window_ops.rs @@ -99,34 +99,23 @@ pub(crate) struct OriginalVerifyWindowOps<'c, 's, 'ctx> { } #[cfg(test)] -#[path = "original_verify_window_ops/tests.rs"] +#[path = "../original_verify_window_ops/tests.rs"] mod tests; -#[path = "original_verify_window_ops/all_window_assets.rs"] mod all_window_assets; -#[allow(unused_imports)] +#[cfg(test)] pub(super) use all_window_assets::all_window_assets; -#[allow(unused_imports)] +#[cfg(test)] use all_window_assets::unsealed_keys; -#[allow(unused_imports)] pub use all_window_assets::unsealed_window_assets; -#[path = "original_verify_window_ops/gdn_stages.rs"] mod gdn_stages; -#[path = "original_verify_window_ops/hits_combine.rs"] mod hits_combine; -#[path = "original_verify_window_ops/original_verifier.rs"] mod original_verifier; -#[path = "original_verify_window_ops/window_launches.rs"] mod window_launches; -#[path = "original_verify_window_ops/qsa_prelude_ops.rs"] mod qsa_prelude_ops; -#[path = "original_verify_window_ops/side_qsa_branches.rs"] mod side_qsa_branches; -#[path = "original_verify_window_ops/side_shared_expert.rs"] mod side_shared_expert; -#[path = "original_verify_window_ops/window_ops_kernels_and_pcie_plan.rs"] mod window_ops_kernels_and_pcie_plan; -#[path = "original_verify_window_ops/wait_rows.rs"] mod wait_rows; -#[allow(unused_imports)] +#[cfg(test)] pub(crate) use original_verifier::graph_oom_at; diff --git a/crates/cuda-driver/src/original_verify_window_ops/all_window_assets.rs b/crates/cuda-driver/src/original_verify/window_ops/all_window_assets.rs similarity index 98% rename from crates/cuda-driver/src/original_verify_window_ops/all_window_assets.rs rename to crates/cuda-driver/src/original_verify/window_ops/all_window_assets.rs index 7d9be575..b1c95a89 100644 --- a/crates/cuda-driver/src/original_verify_window_ops/all_window_assets.rs +++ b/crates/cuda-driver/src/original_verify/window_ops/all_window_assets.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalVerifyExpertLayout`: `new`, `with_role_bytes`, `blob_bytes`, `role_bytes`. -//! Methods of `OriginalVerifyWindowResources`: `new`, `rows`, `with_projections`, `with_gr` and 4 more. +//! Resources of a recorded verify window: the list of every sealed kernel asset, the expert layout, and the window +//! resource bundle that attaches projections, GR, QSA and MoE bindings, loads assets before capture and serves weights. use super::{ AssetSpec, Context, Error, GdnProjectionAddrs, GrConfig, HcHalf, MoeLayerAddrs, OriginalGraphResources, diff --git a/crates/cuda-driver/src/original_verify_window_ops/gdn_stages.rs b/crates/cuda-driver/src/original_verify/window_ops/gdn_stages.rs similarity index 100% rename from crates/cuda-driver/src/original_verify_window_ops/gdn_stages.rs rename to crates/cuda-driver/src/original_verify/window_ops/gdn_stages.rs diff --git a/crates/cuda-driver/src/original_verify_window_ops/hits_combine.rs b/crates/cuda-driver/src/original_verify/window_ops/hits_combine.rs similarity index 94% rename from crates/cuda-driver/src/original_verify_window_ops/hits_combine.rs rename to crates/cuda-driver/src/original_verify/window_ops/hits_combine.rs index 6a73d72a..1a621029 100644 --- a/crates/cuda-driver/src/original_verify_window_ops/hits_combine.rs +++ b/crates/cuda-driver/src/original_verify/window_ops/hits_combine.rs @@ -9,13 +9,14 @@ //! it needs no other switch. When the shape does not fit the vector kernel (k != 10, `n_embd % 4 != 0`, an unaligned //! row, the legacy double-precision combine) the method records the two launches it replaces, `add_hits` then the //! combine the planner would have chosen, so the hit rows are added in every case. -#[path = "hits_combine/plan_hits_combine.rs"] mod plan_hits_combine; use super::{AssetSpec, Launch, OriginalVerifyWindowOps, Planner, Result, Rows, ffn}; #[cfg(test)] use super::{A, Error}; -pub(crate) use plan_hits_combine::{E_COMBINE_HITS, HITS_COMBINE}; +pub(crate) use plan_hits_combine::HITS_COMBINE; +#[cfg(test)] +use plan_hits_combine::E_COMBINE_HITS; use plan_hits_combine::{HitsCombineSite, plan_hits_combine}; /// The assets the window preloads before capture for the FFN switches: the folded combine when it is on. @@ -49,5 +50,5 @@ impl OriginalVerifyWindowOps<'_, '_, '_> { } #[cfg(test)] -#[path = "hits_combine/tests.rs"] +#[path = "../../original_verify_window_ops/hits_combine/tests.rs"] mod tests; diff --git a/crates/cuda-driver/src/original_verify_window_ops/hits_combine/plan_hits_combine.rs b/crates/cuda-driver/src/original_verify/window_ops/hits_combine/plan_hits_combine.rs similarity index 98% rename from crates/cuda-driver/src/original_verify_window_ops/hits_combine/plan_hits_combine.rs rename to crates/cuda-driver/src/original_verify/window_ops/hits_combine/plan_hits_combine.rs index 36c886cd..6a245483 100644 --- a/crates/cuda-driver/src/original_verify_window_ops/hits_combine/plan_hits_combine.rs +++ b/crates/cuda-driver/src/original_verify/window_ops/hits_combine/plan_hits_combine.rs @@ -21,7 +21,7 @@ const VECTOR_ALIGN: u64 = 16; /// `scripts/gpu-bringup/extra-seal-plan.json` (group `sm120-decode`). pub(crate) static HITS_COMBINE: AssetSpec = AssetSpec { name: "sm120_combine_hits.ptx", - ptx: concat!(include_str!("../../sm120_combine_hits.ptx"), "\0").as_bytes(), + ptx: concat!(include_str!("../../../sm120_combine_hits.ptx"), "\0").as_bytes(), sha: [ 167, 221, 5, 153, 20, 187, 51, 255, 103, 227, 166, 6, 169, 179, 141, 180, 228, 225, 133, 121, 209, 86, 86, 50, 6, 143, 132, 170, 183, 52, 112, 247, diff --git a/crates/cuda-driver/src/original_verify_window_ops/original_verifier.rs b/crates/cuda-driver/src/original_verify/window_ops/original_verifier.rs similarity index 96% rename from crates/cuda-driver/src/original_verify_window_ops/original_verifier.rs rename to crates/cuda-driver/src/original_verify/window_ops/original_verifier.rs index f9fdc60c..b787c3c8 100644 --- a/crates/cuda-driver/src/original_verify_window_ops/original_verifier.rs +++ b/crates/cuda-driver/src/original_verify/window_ops/original_verifier.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalVerifier`: `record_literal_window`, `record_all`. -//! Functions: `resolve_cluster_topk`, `resolve_sm120_switches`, `pcie_role_bytes`, `graph_oom_at`. +//! Recording of all verify window graphs (T = 1..max_t) and the commit graph by OriginalVerifier, with the +//! per-recording resolution of cluster top-k and sm_120 switches, PCIe role bytes, and graph out-of-memory naming. use super::{ Error, OriginalVerifier, OriginalVerifyGraphResources, OriginalVerifyWindowOps, OriginalVerifyWindowResources, diff --git a/crates/cuda-driver/src/original_verify_window_ops/qsa_prelude_ops.rs b/crates/cuda-driver/src/original_verify/window_ops/qsa_prelude_ops.rs similarity index 100% rename from crates/cuda-driver/src/original_verify_window_ops/qsa_prelude_ops.rs rename to crates/cuda-driver/src/original_verify/window_ops/qsa_prelude_ops.rs diff --git a/crates/cuda-driver/src/original_verify_window_ops/side_qsa_branches.rs b/crates/cuda-driver/src/original_verify/window_ops/side_qsa_branches.rs similarity index 100% rename from crates/cuda-driver/src/original_verify_window_ops/side_qsa_branches.rs rename to crates/cuda-driver/src/original_verify/window_ops/side_qsa_branches.rs diff --git a/crates/cuda-driver/src/original_verify_window_ops/side_shared_expert.rs b/crates/cuda-driver/src/original_verify/window_ops/side_shared_expert.rs similarity index 100% rename from crates/cuda-driver/src/original_verify_window_ops/side_shared_expert.rs rename to crates/cuda-driver/src/original_verify/window_ops/side_shared_expert.rs diff --git a/crates/cuda-driver/src/original_verify_window_ops/wait_rows.rs b/crates/cuda-driver/src/original_verify/window_ops/wait_rows.rs similarity index 97% rename from crates/cuda-driver/src/original_verify_window_ops/wait_rows.rs rename to crates/cuda-driver/src/original_verify/window_ops/wait_rows.rs index 58467ef7..8cf898e1 100644 --- a/crates/cuda-driver/src/original_verify_window_ops/wait_rows.rs +++ b/crates/cuda-driver/src/original_verify/window_ops/wait_rows.rs @@ -30,7 +30,7 @@ const NEEDS_ROWS_KERNEL: &str = /// `scripts/gpu-bringup/extra-seal-plan.json` (group `sm120-decode`). pub(crate) static WAIT_COPY_ROWS: AssetSpec = AssetSpec { name: "sm120_wait_copy_rows.ptx", - ptx: concat!(include_str!("../sm120_wait_copy_rows.ptx"), "\0").as_bytes(), + ptx: concat!(include_str!("../../sm120_wait_copy_rows.ptx"), "\0").as_bytes(), sha: [ 248, 179, 63, 32, 217, 130, 188, 199, 138, 72, 18, 113, 46, 109, 236, 252, 206, 222, 204, 192, 196, 252, 209, 143, 153, 7, 79, 143, 182, 106, 7, 0, @@ -124,5 +124,5 @@ impl OriginalVerifyWindowOps<'_, '_, '_> { } #[cfg(test)] -#[path = "wait_rows/tests.rs"] +#[path = "../../original_verify_window_ops/wait_rows/tests.rs"] mod tests; diff --git a/crates/cuda-driver/src/original_verify_window_ops/window_launches.rs b/crates/cuda-driver/src/original_verify/window_ops/window_launches.rs similarity index 100% rename from crates/cuda-driver/src/original_verify_window_ops/window_launches.rs rename to crates/cuda-driver/src/original_verify/window_ops/window_launches.rs diff --git a/crates/cuda-driver/src/original_verify_window_ops/window_ops_kernels_and_pcie_plan.rs b/crates/cuda-driver/src/original_verify/window_ops/window_ops_kernels_and_pcie_plan.rs similarity index 98% rename from crates/cuda-driver/src/original_verify_window_ops/window_ops_kernels_and_pcie_plan.rs rename to crates/cuda-driver/src/original_verify/window_ops/window_ops_kernels_and_pcie_plan.rs index 97eca746..eeab0dc1 100644 --- a/crates/cuda-driver/src/original_verify_window_ops/window_ops_kernels_and_pcie_plan.rs +++ b/crates/cuda-driver/src/original_verify/window_ops/window_ops_kernels_and_pcie_plan.rs @@ -1,7 +1,6 @@ -//! Methods of `OriginalVerifyWindowOps`: `capture_finite_verdict`, `plan_copy_addresses`, `wait_plan_glue`, `copy_hi... -//! Implements `WindowOps for OriginalVerifyWindowOps`. Functions: `pcie_fetch_launch`, `pcie_rebase_command`. +//! The WindowOps implementation that turns each window step (embed, GR, projections, GDN, QSA, router, experts, PCIe +//! staging, combine, head) into recorded launches, plus the finite-verdict capture and PCIe fetch helpers. -#[allow(unused_imports)] use super::side_qsa_branches::QsaSideLayer; use super::{ A, Arg, Command, Error, ExpertTier, HcHalf, Launch, LaunchExtent, OriginalVerifyGraphResources, diff --git a/crates/cuda-driver/src/original_verify_window_plan.rs b/crates/cuda-driver/src/original_verify/window_plan.rs similarity index 100% rename from crates/cuda-driver/src/original_verify_window_plan.rs rename to crates/cuda-driver/src/original_verify/window_plan.rs diff --git a/crates/cuda-driver/src/original_verify_window_record.rs b/crates/cuda-driver/src/original_verify/window_record.rs similarity index 99% rename from crates/cuda-driver/src/original_verify_window_record.rs rename to crates/cuda-driver/src/original_verify/window_record.rs index c2c5b0fa..9e0267e3 100644 --- a/crates/cuda-driver/src/original_verify_window_record.rs +++ b/crates/cuda-driver/src/original_verify/window_record.rs @@ -396,5 +396,5 @@ fn post_combine(ops: &mut O, policy: &WindowPolicy, l: usize, rows } #[cfg(test)] -#[path = "original_verify_window_record/tests.rs"] +#[path = "../original_verify_window_record/tests.rs"] mod tests; diff --git a/crates/cuda-driver/src/original_verify_gpu_plan/tests.rs b/crates/cuda-driver/src/original_verify_gpu_plan/tests.rs index 6af32b33..7fed2165 100644 --- a/crates/cuda-driver/src/original_verify_gpu_plan/tests.rs +++ b/crates/cuda-driver/src/original_verify_gpu_plan/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests of the GPU plan sink: DMA option defaults per platform, the plan block carve, empty and corrupt plans, +//! and when flag B waits for the PCIe staging copies. use super::*; diff --git a/crates/cuda-driver/src/original_verify_window_gr/tests/fused_down_launches.rs b/crates/cuda-driver/src/original_verify_window_gr/fused_down_launches.rs similarity index 100% rename from crates/cuda-driver/src/original_verify_window_gr/tests/fused_down_launches.rs rename to crates/cuda-driver/src/original_verify_window_gr/fused_down_launches.rs diff --git a/crates/cuda-driver/src/original_verify_window_gr/tests/head_chain_launches.rs b/crates/cuda-driver/src/original_verify_window_gr/head_chain_launches.rs similarity index 100% rename from crates/cuda-driver/src/original_verify_window_gr/tests/head_chain_launches.rs rename to crates/cuda-driver/src/original_verify_window_gr/head_chain_launches.rs diff --git a/crates/cuda-driver/src/original_verify_window_gr/tests/head_mix_is_the_native.rs b/crates/cuda-driver/src/original_verify_window_gr/head_mix_is_the_native.rs similarity index 100% rename from crates/cuda-driver/src/original_verify_window_gr/tests/head_mix_is_the_native.rs rename to crates/cuda-driver/src/original_verify_window_gr/head_mix_is_the_native.rs diff --git a/crates/cuda-driver/src/original_verify_window_gr/tests/head_mix_multi.rs b/crates/cuda-driver/src/original_verify_window_gr/head_mix_multi.rs similarity index 100% rename from crates/cuda-driver/src/original_verify_window_gr/tests/head_mix_multi.rs rename to crates/cuda-driver/src/original_verify_window_gr/head_mix_multi.rs diff --git a/crates/cuda-driver/src/original_verify_window_gr/tests.rs b/crates/cuda-driver/src/original_verify_window_gr/tests.rs index 1cd127e0..24ac948e 100644 --- a/crates/cuda-driver/src/original_verify_window_gr/tests.rs +++ b/crates/cuda-driver/src/original_verify_window_gr/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests of the GR window planner: launch words, variant choice from card limits, fused and tiled down kernels, +//! head chain and head mix, against a fake arena layout; submodules hold the per-kernel cases. use super::super::kernels::{LayoutMap, test_geometry}; use super::*; @@ -58,13 +59,8 @@ fn ple_addrs(key: PleKey) -> PleAddrs { } } -#[path = "tests/fused_down_launches.rs"] mod fused_down_launches; -#[path = "tests/head_chain_launches.rs"] mod head_chain_launches; -#[path = "tests/head_mix_is_the_native.rs"] mod head_mix_is_the_native; -#[path = "tests/head_mix_multi.rs"] mod head_mix_multi; -#[path = "tests/tiled_down_projection_covers.rs"] mod tiled_down_projection_covers; diff --git a/crates/cuda-driver/src/original_verify_window_gr/tests/tiled_down_projection_covers.rs b/crates/cuda-driver/src/original_verify_window_gr/tiled_down_projection_covers.rs similarity index 100% rename from crates/cuda-driver/src/original_verify_window_gr/tests/tiled_down_projection_covers.rs rename to crates/cuda-driver/src/original_verify_window_gr/tiled_down_projection_covers.rs diff --git a/crates/cuda-driver/src/original_verify_window_moe/tests/alternative_pcie_staging_copy.rs b/crates/cuda-driver/src/original_verify_window_moe/alternative_pcie_staging_copy.rs similarity index 99% rename from crates/cuda-driver/src/original_verify_window_moe/tests/alternative_pcie_staging_copy.rs rename to crates/cuda-driver/src/original_verify_window_moe/alternative_pcie_staging_copy.rs index f0eb7a80..09fc81d4 100644 --- a/crates/cuda-driver/src/original_verify_window_moe/tests/alternative_pcie_staging_copy.rs +++ b/crates/cuda-driver/src/original_verify_window_moe/alternative_pcie_staging_copy.rs @@ -74,10 +74,10 @@ fn assert_expert_format_qk(iq: &str) { #[test] fn expert_entries_match_the_cu_source_and_the_original_format_lists() { - let cu = include_str!("../../original_verify_window_moe_experts.cu"); + let cu = include_str!("../original_verify_window_moe_experts.cu"); assert!(cu.contains("window_moe_gu_##T") && cu.contains("window_moe_down_##T")); assert!(cu.contains("STRATA_GU_FMTS(STRATA_WINDOW_GU)") && cu.contains("STRATA_D_FMTS(STRATA_WINDOW_DOWN)")); - let iq = include_str!("../../mtp_original_full_head_iq.cu"); + let iq = include_str!("../mtp_original_full_head_iq.cu"); assert_expert_entry_tables(iq); // the Original's per-type values-per-block (Fmt::qk) used by native_expert_supported assert_expert_format_qk(iq); diff --git a/crates/cuda-driver/src/original_verify_window_moe/tests/down_sub16_plan.rs b/crates/cuda-driver/src/original_verify_window_moe/down_sub16_plan.rs similarity index 100% rename from crates/cuda-driver/src/original_verify_window_moe/tests/down_sub16_plan.rs rename to crates/cuda-driver/src/original_verify_window_moe/down_sub16_plan.rs diff --git a/crates/cuda-driver/src/original_verify_window_moe/tests/hit_add_scans_the_cpu.rs b/crates/cuda-driver/src/original_verify_window_moe/hit_add_scans_the_cpu.rs similarity index 100% rename from crates/cuda-driver/src/original_verify_window_moe/tests/hit_add_scans_the_cpu.rs rename to crates/cuda-driver/src/original_verify_window_moe/hit_add_scans_the_cpu.rs diff --git a/crates/cuda-driver/src/original_verify_window_moe/tests/shared_gate_without_native_bf16.rs b/crates/cuda-driver/src/original_verify_window_moe/shared_gate_without_native_bf16.rs similarity index 100% rename from crates/cuda-driver/src/original_verify_window_moe/tests/shared_gate_without_native_bf16.rs rename to crates/cuda-driver/src/original_verify_window_moe/shared_gate_without_native_bf16.rs diff --git a/crates/cuda-driver/src/original_verify_window_moe/tests.rs b/crates/cuda-driver/src/original_verify_window_moe/tests.rs index 88f4cf07..48a3dd22 100644 --- a/crates/cuda-driver/src/original_verify_window_moe/tests.rs +++ b/crates/cuda-driver/src/original_verify_window_moe/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests of the MoE window planner against a fake arena: launch ABI against the PTX entries, plus the PCIe staging copy +//! kernel, down sub16 plan, hit add and shared gate cases in the submodules. use super::super::kernels::{LayoutMap, test_geometry}; use super::*; @@ -68,11 +69,7 @@ fn assert_abi(launches: &[Launch]) { } } -#[path = "tests/alternative_pcie_staging_copy.rs"] mod alternative_pcie_staging_copy; -#[path = "tests/down_sub16_plan.rs"] mod down_sub16_plan; -#[path = "tests/hit_add_scans_the_cpu.rs"] mod hit_add_scans_the_cpu; -#[path = "tests/shared_gate_without_native_bf16.rs"] mod shared_gate_without_native_bf16; diff --git a/crates/cuda-driver/src/original_verify_window_ops/tests.rs b/crates/cuda-driver/src/original_verify_window_ops/tests.rs index fa2d0633..317c9682 100644 --- a/crates/cuda-driver/src/original_verify_window_ops/tests.rs +++ b/crates/cuda-driver/src/original_verify_window_ops/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests of the window asset and layout bookkeeping: graph out-of-memory naming, sealed and unique window assets, +//! and the expert layout bounds. use super::*; diff --git a/crates/cuda-driver/src/original_verify_window_planner/tests/combine_head_switches.rs b/crates/cuda-driver/src/original_verify_window_planner/combine_head_switches.rs similarity index 100% rename from crates/cuda-driver/src/original_verify_window_planner/tests/combine_head_switches.rs rename to crates/cuda-driver/src/original_verify_window_planner/combine_head_switches.rs diff --git a/crates/cuda-driver/src/original_verify_window_planner/tests/every_window_size_and_group.rs b/crates/cuda-driver/src/original_verify_window_planner/every_window_size_and_group.rs similarity index 100% rename from crates/cuda-driver/src/original_verify_window_planner/tests/every_window_size_and_group.rs rename to crates/cuda-driver/src/original_verify_window_planner/every_window_size_and_group.rs diff --git a/crates/cuda-driver/src/original_verify_window_planner/tests/fused_gr_down.rs b/crates/cuda-driver/src/original_verify_window_planner/fused_gr_down.rs similarity index 100% rename from crates/cuda-driver/src/original_verify_window_planner/tests/fused_gr_down.rs rename to crates/cuda-driver/src/original_verify_window_planner/fused_gr_down.rs diff --git a/crates/cuda-driver/src/original_verify_window_planner/tests/fused_qsa_prelude.rs b/crates/cuda-driver/src/original_verify_window_planner/fused_qsa_prelude.rs similarity index 100% rename from crates/cuda-driver/src/original_verify_window_planner/tests/fused_qsa_prelude.rs rename to crates/cuda-driver/src/original_verify_window_planner/fused_qsa_prelude.rs diff --git a/crates/cuda-driver/src/original_verify_window_planner/tests/head_chain_batch.rs b/crates/cuda-driver/src/original_verify_window_planner/head_chain_batch.rs similarity index 100% rename from crates/cuda-driver/src/original_verify_window_planner/tests/head_chain_batch.rs rename to crates/cuda-driver/src/original_verify_window_planner/head_chain_batch.rs diff --git a/crates/cuda-driver/src/original_verify_window_planner/tests.rs b/crates/cuda-driver/src/original_verify_window_planner/tests.rs index 22070b12..bd115e29 100644 --- a/crates/cuda-driver/src/original_verify_window_planner/tests.rs +++ b/crates/cuda-driver/src/original_verify_window_planner/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests of the whole window recorder with a fake WindowOps and weights: the planned launch order for every window +//! size and group, with submodules for the fused GR down, QSA prelude, head chain and combine switches. use super::super::kernels::{LayoutMap, test_geometry}; use super::super::moe::MoeLayerAddrs; @@ -339,13 +340,8 @@ fn names(log: &[String]) -> Vec<&str> { log.iter().map(String::as_str).collect() } -#[path = "tests/combine_head_switches.rs"] mod combine_head_switches; -#[path = "tests/every_window_size_and_group.rs"] mod every_window_size_and_group; -#[path = "tests/fused_gr_down.rs"] mod fused_gr_down; -#[path = "tests/fused_qsa_prelude.rs"] mod fused_qsa_prelude; -#[path = "tests/head_chain_batch.rs"] mod head_chain_batch; diff --git a/crates/cuda-driver/src/original_verify_window_proj/tests.rs b/crates/cuda-driver/src/original_verify_window_proj/tests.rs index a1523298..5376dd99 100644 --- a/crates/cuda-driver/src/original_verify_window_proj/tests.rs +++ b/crates/cuda-driver/src/original_verify_window_proj/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests of the projection planners: pinned assets and entries, q8_1 quantize and MMVQ dispatch, BF16 GEMV single or +//! multi choice, IQ kinds, and the window projection addresses and matrix sizes. use super::*; diff --git a/crates/cuda-driver/src/original_verify_window_qsa/tests/q_path_per_token_splits.rs b/crates/cuda-driver/src/original_verify_window_qsa/q_path_per_token_splits.rs similarity index 100% rename from crates/cuda-driver/src/original_verify_window_qsa/tests/q_path_per_token_splits.rs rename to crates/cuda-driver/src/original_verify_window_qsa/q_path_per_token_splits.rs diff --git a/crates/cuda-driver/src/original_verify_window_qsa/tests/sealed_assets_are_pinned.rs b/crates/cuda-driver/src/original_verify_window_qsa/sealed_assets_are_pinned.rs similarity index 98% rename from crates/cuda-driver/src/original_verify_window_qsa/tests/sealed_assets_are_pinned.rs rename to crates/cuda-driver/src/original_verify_window_qsa/sealed_assets_are_pinned.rs index c0e8909d..5de32c38 100644 --- a/crates/cuda-driver/src/original_verify_window_qsa/tests/sealed_assets_are_pinned.rs +++ b/crates/cuda-driver/src/original_verify_window_qsa/sealed_assets_are_pinned.rs @@ -25,14 +25,14 @@ fn the_new_gate_asset_is_sealed_with_a_matching_source() { // Sealed with nvcc 13.2.86 on 2026-10-15; structure and pin only (no numerical claim). GATE.assert_sealed_and_fail_closed(); assert_eq!(GATE.ptx.iter().filter(|&&b| b == 0).count(), 1); - let source = include_str!("../../original_verify_window_qsa_gate.cu"); + let source = include_str!("../original_verify_window_qsa_gate.cu"); for e in GATE.entries { assert!(source.contains(&format!("extern \"C\" __global__ void {e}(")), "{e}"); } // the body is the Original `gate`: second half of each [head][2][head_dim] row assert!(source.contains("q_full[head * 2 * head_dim + head_dim + channel]")); assert!(source.contains("1.0f / (1.0f + expf(-raw))")); - assert!(include_str!("../../../../../docs/cuda-seal-plan-additions-window.json").contains("--use_fast_math")); + assert!(include_str!("../../../../docs/cuda-seal-plan-additions-window.json").contains("--use_fast_math")); } #[test] diff --git a/crates/cuda-driver/src/original_verify_window_qsa/tests.rs b/crates/cuda-driver/src/original_verify_window_qsa/tests.rs index c5d18da4..156683d0 100644 --- a/crates/cuda-driver/src/original_verify_window_qsa/tests.rs +++ b/crates/cuda-driver/src/original_verify_window_qsa/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests of the QsaWindow planners against a fake arena: launch ABI against the PTX entries; submodules cover the +//! q path splits, sealed asset pins and the Original weight sizes. use super::super::kernels::{LayoutMap, test_geometry}; use super::*; @@ -62,9 +63,6 @@ fn rope_param_count() -> usize { } } -#[path = "tests/q_path_per_token_splits.rs"] mod q_path_per_token_splits; -#[path = "tests/sealed_assets_are_pinned.rs"] mod sealed_assets_are_pinned; -#[path = "tests/weight_sizes_are_the_original.rs"] mod weight_sizes_are_the_original; diff --git a/crates/cuda-driver/src/original_verify_window_qsa/tests/weight_sizes_are_the_original.rs b/crates/cuda-driver/src/original_verify_window_qsa/weight_sizes_are_the_original.rs similarity index 100% rename from crates/cuda-driver/src/original_verify_window_qsa/tests/weight_sizes_are_the_original.rs rename to crates/cuda-driver/src/original_verify_window_qsa/weight_sizes_are_the_original.rs diff --git a/crates/cuda-driver/src/original_verify_window_record/tests.rs b/crates/cuda-driver/src/original_verify_window_record/tests.rs index 5bb69f12..78723db4 100644 --- a/crates/cuda-driver/src/original_verify_window_record/tests.rs +++ b/crates/cuda-driver/src/original_verify_window_record/tests.rs @@ -1,4 +1,4 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests of the window recorder call order with a logging WindowOps: layer sequences, rings, flags and split windows. use super::*; diff --git a/crates/cuda-driver/src/ple_batch_ffi/driver_backed.rs b/crates/cuda-driver/src/ple_batch_ffi/driver_backed.rs index a3f05f75..3351a5ff 100644 --- a/crates/cuda-driver/src/ple_batch_ffi/driver_backed.rs +++ b/crates/cuda-driver/src/ple_batch_ffi/driver_backed.rs @@ -81,11 +81,7 @@ pub(crate) struct KernelModule { unload: Destroy, } -#[path = "driver_backed/library.rs"] mod library; -#[allow(unused_imports)] use library::check; -#[path = "driver_backed/blas.rs"] mod blas; -#[path = "driver_backed/kernel_module_launch_and_close.rs"] mod kernel_module_launch_and_close; diff --git a/crates/cuda-driver/src/ple_batch_ffi/driver_backed/blas.rs b/crates/cuda-driver/src/ple_batch_ffi/driver_backed/blas.rs index ae7371a4..280e261f 100644 --- a/crates/cuda-driver/src/ple_batch_ffi/driver_backed/blas.rs +++ b/crates/cuda-driver/src/ple_batch_ffi/driver_backed/blas.rs @@ -1,5 +1,5 @@ -//! Methods of `Blas`: `load`, `init_handle`, `stream`, `gemm` and 7 more. -//! Functions: `gemm_shape_admitted`, `gdn_shape_admitted`, `gdn_bf16_shape_admitted`, `gdn_f16_shape_admitted`. +//! cuBLAS wrapper of the batch FFI: loads the library with a private stream and workspace, the single GemmEx call and +//! its BF16 and F16 entry points, and the admission of the closed Original GEMM and GDN shapes. use super::{ Blas, BufferHandle, Create, Destroy, Error, GdnGemmLayout, Gemm, GemmDims, GemmOperands, GemmScalars, InputType, diff --git a/crates/cuda-driver/src/ple_batch_ffi/driver_backed/kernel_module_launch_and_close.rs b/crates/cuda-driver/src/ple_batch_ffi/driver_backed/kernel_module_launch_and_close.rs index b00bce01..cc1176a4 100644 --- a/crates/cuda-driver/src/ple_batch_ffi/driver_backed/kernel_module_launch_and_close.rs +++ b/crates/cuda-driver/src/ple_batch_ffi/driver_backed/kernel_module_launch_and_close.rs @@ -1,5 +1,5 @@ -//! Methods of `Blas`: `close_inner`. -//! Methods of `KernelModule`: `load`, `init_functions`, `launch`, `launch_dynamic` and 5 more. +//! Closing of the cuBLAS wrapper, and the KernelModule that loads a PTX image and launches its entries (plain, dynamic +//! shared memory, cluster), reports the device geometry, and closes. use super::{ BatchArg, Blas, CStr, ClusterShape, Destroy, Error, FuncSetAttribute, KernelArguments, KernelModule, Launch, diff --git a/crates/cuda-driver/src/ple_batch_ffi/driver_backed/library.rs b/crates/cuda-driver/src/ple_batch_ffi/driver_backed/library.rs index 2dbc80b2..b48f9d0c 100644 --- a/crates/cuda-driver/src/ple_batch_ffi/driver_backed/library.rs +++ b/crates/cuda-driver/src/ple_batch_ffi/driver_backed/library.rs @@ -1,5 +1,5 @@ -//! Methods of `Library`: `open`. Implements `Drop for Library`. Functions: `check`. -//! Split out of `enabled` to keep its files under the line limit. +//! Owned dlopen handle of the private driver library used by the PLE batch FFI (open, dlclose on drop) and the +//! check helper that turns a nonzero driver return code into Error::Driver. use super::{CStr, Error, Library, Result, c_int}; diff --git a/crates/cuda-driver/src/ple_batch_ffi/kernel_arguments.rs b/crates/cuda-driver/src/ple_batch_ffi/kernel_arguments.rs index 49a96990..7f8d816a 100644 --- a/crates/cuda-driver/src/ple_batch_ffi/kernel_arguments.rs +++ b/crates/cuda-driver/src/ple_batch_ffi/kernel_arguments.rs @@ -1,5 +1,5 @@ -//! Methods of `KernelArguments`: `new`. Methods of `Blas`: `load`, `stream`, `gemm_bf16`, `gemm_f16` and 4 more. -//! Split out of `ple_batch_ffi` to keep its files under the line limit. +//! Argument pack for PLE batch kernel launches, plus the stub Blas and KernelModule used on builds without a 64-bit +//! Linux/Windows CUDA driver: every operation there answers Error::UnsupportedPlatform. use super::{BatchArg, KernelArguments}; diff --git a/crates/cuda-driver/src/ple_batch_queue.rs b/crates/cuda-driver/src/ple_batch_queue.rs index 6449ccdd..5c872422 100644 --- a/crates/cuda-driver/src/ple_batch_queue.rs +++ b/crates/cuda-driver/src/ple_batch_queue.rs @@ -81,21 +81,13 @@ enum Command { } mod assets; -#[allow(unused_imports)] use assets::assets; mod ple_batch_queue_drop; mod ple_batch_queue_operations; -#[allow(unused_imports)] use ple_batch_queue_drop::ScanExtent; -#[allow(unused_imports)] use ple_batch_queue_drop::decode; -#[allow(unused_imports)] use ple_batch_queue_drop::float_owner; -#[allow(unused_imports)] use ple_batch_queue_drop::float_staging; -#[allow(unused_imports)] use ple_batch_queue_drop::push; -#[allow(unused_imports)] use ple_batch_queue_drop::scan; -#[allow(unused_imports)] use ple_batch_queue_drop::staging; diff --git a/crates/cuda-driver/src/ple_batch_queue/assets.rs b/crates/cuda-driver/src/ple_batch_queue/assets.rs index 5df09b44..a447fa5d 100644 --- a/crates/cuda-driver/src/ple_batch_queue/assets.rs +++ b/crates/cuda-driver/src/ple_batch_queue/assets.rs @@ -1,5 +1,6 @@ -//! Methods of `PleBatchCompletion`: `rows`, `numerical_refusal`, `take_row`. -//! Methods of `PleBatchQueue`: `read_row`, `settle_row`. Functions: `assets`, `check_ptx`. +//! Sealed PTX assets and row read-back of the PLE batch queue: verifies pinned PTX digest and length, and reads +//! one completed row (streams and history) to the host, poisoning the context if the drain is uncertain. +//! Also holds the Context constructors of the queue and the completion that reports numerical refusals. use super::{ BufferHandle, Context, Error, PACK_PTX, PACK_PTX_BYTES, PACK_PTX_SHA256, PTX, PTX_BYTES, PTX_SHA256, diff --git a/crates/cuda-driver/src/ple_batch_queue/ple_batch_queue_drop.rs b/crates/cuda-driver/src/ple_batch_queue/ple_batch_queue_drop.rs index bfc3a540..e31d8223 100644 --- a/crates/cuda-driver/src/ple_batch_queue/ple_batch_queue_drop.rs +++ b/crates/cuda-driver/src/ple_batch_queue/ple_batch_queue_drop.rs @@ -1,5 +1,5 @@ -//! Methods of `Command`: `launch`. Methods of `ScanExtent`: `new`. Implements `Drop for PleBatchQueue`. -//! Functions: `push`, `scan`, `staging`, `float_staging` and 2 more. Defines `ScanExtent`. +//! Command list primitives of the PLE batch queue: how a recorded Kernel or Gemm command is launched, helpers that +//! append kernel and finite-scan commands, host staging/decode of f32 buffers, and the queue Drop (best-effort close). use super::{A, Blas, BufferHandle, Command, Error, KernelArguments, KernelModule, PleBatchQueue, Result}; use crate::ple_batch_ffi::{GemmDims, GemmOperands, GemmScalars, LinearLaunch}; diff --git a/crates/cuda-driver/src/ple_batch_queue/ple_batch_queue_operations/ple_batch_queue_bring_up.rs b/crates/cuda-driver/src/ple_batch_queue/ple_batch_queue_operations/ple_batch_queue_bring_up.rs index 7ca3ab91..89e5c30a 100644 --- a/crates/cuda-driver/src/ple_batch_queue/ple_batch_queue_operations/ple_batch_queue_bring_up.rs +++ b/crates/cuda-driver/src/ple_batch_queue/ple_batch_queue_operations/ple_batch_queue_bring_up.rs @@ -1,5 +1,6 @@ -//! Methods of `PleBatchQueue`: `new`, `new_capacity`, `init_resources`, `load_modules` and 9 more. -//! Functions: `batch_sizes`, `check_required`. +//! Bring-up and invariants of the PLE batch queue: sizes its 15 device buffers for a row capacity, checks the memory +//! budget, loads the pack and batch kernel modules, and validates that buffers and weights belong to the context, have +//! the right size and do not overlap. use super::{ BufferHandle, Context, DeviceBuffer, ENTRIES, Error, KernelModule, PACK_ENTRIES, PLE_BATCH_QUEUE_BYTES, diff --git a/crates/cuda-driver/src/ple_batch_queue/ple_batch_queue_operations/ple_batch_queue_close.rs b/crates/cuda-driver/src/ple_batch_queue/ple_batch_queue_operations/ple_batch_queue_close.rs index 095c1c2f..837b4bec 100644 --- a/crates/cuda-driver/src/ple_batch_queue/ple_batch_queue_operations/ple_batch_queue_close.rs +++ b/crates/cuda-driver/src/ple_batch_queue/ple_batch_queue_operations/ple_batch_queue_close.rs @@ -1,5 +1,5 @@ -//! Methods of `PleBatchQueue`: `close`, `close_inner`, `close_guard`. Functions: `close_or_leak`, `poison_on_error`. -//! Split out of `ple_batch_queue_methods` to keep its files under the line limit. +//! Teardown of the PLE batch queue: closes kernel modules and releases device buffers under the context guard, and +//! leaks them instead of freeing when the context is poisoned, so a failed close never double-frees. use super::{Context, Error, PleBatchQueue, Result, combine}; use crate::CurrentGuard; diff --git a/crates/cuda-driver/src/ple_batch_queue/ple_batch_queue_operations/ple_batch_queue_compose.rs b/crates/cuda-driver/src/ple_batch_queue/ple_batch_queue_operations/ple_batch_queue_compose.rs index f7008397..4c5f9ce3 100644 --- a/crates/cuda-driver/src/ple_batch_queue/ple_batch_queue_operations/ple_batch_queue_compose.rs +++ b/crates/cuda-driver/src/ple_batch_queue/ple_batch_queue_operations/ple_batch_queue_compose.rs @@ -1,8 +1,6 @@ -//! Methods of `PleBatchQueue`: `compose`. -//! Split out of `ple_batch_queue_methods` to keep its files under the line limit. +//! The public compose entry of the PLE batch queue: stages a batch, uploads, launches the kernels and GEMMs, reads +//! the numerical statuses back and settles the result; the phase helpers it calls live in compose_phases. -#[allow(unused_imports)] -use super::compose_phases::BatchHost; use super::{NativeBatchWorkspace, PleBatchCompletion, PleBatchQueue, PleBatchSources, PleClosedWeights, Result}; impl<'ctx> PleBatchQueue<'ctx> { diff --git a/crates/cuda-driver/src/ple_value_full_gpu.rs b/crates/cuda-driver/src/ple_value_full_gpu_tests.rs similarity index 100% rename from crates/cuda-driver/src/ple_value_full_gpu.rs rename to crates/cuda-driver/src/ple_value_full_gpu_tests.rs diff --git a/crates/cuda-driver/src/prefill_stage_gr_gpu/enable_types.rs b/crates/cuda-driver/src/prefill_stage_gr_gpu/enable_types.rs deleted file mode 100644 index eb0280d7..00000000 --- a/crates/cuda-driver/src/prefill_stage_gr_gpu/enable_types.rs +++ /dev/null @@ -1,10 +0,0 @@ -//! Defines `Rng`, `Launch`. -//! ENABLE, Rng, Launch. - -use super::{A, KernelModule}; - -pub(super) const ENABLE: &str = "LELEKA_PREFILL_STAGE_GPU"; - -pub(super) struct Rng(pub(super) u64); - -pub(super) type Launch<'m> = (&'m KernelModule, usize, usize, u32, Vec); diff --git a/crates/cuda-driver/src/projection_grids_and_bounds.rs b/crates/cuda-driver/src/projection_grids_and_bounds.rs index efab9b9a..f280237a 100644 --- a/crates/cuda-driver/src/projection_grids_and_bounds.rs +++ b/crates/cuda-driver/src/projection_grids_and_bounds.rs @@ -1,5 +1,5 @@ -//! Functions: `q4_k_native_indices_fit`, `q4_k_last_signed_byte_offset`, `bounded_projection_size`, `check_projectio... -//! Split out of `crate` to keep its files under the line limit. +//! Host-side shape admission of dense Q4_K and generic projections and of Q5_K: byte sizes, quantizer and projection +//! grids, the signed 32-bit offset limit of the Q4_K PTX, and the alias/extent checks of the three buffers. use super::{DenseFormat, Error, ProjectionKind, ProjectionShape, ProjectionSpec, Q5KShape, Result, ffi, valid_size}; diff --git a/crates/cuda-driver/src/prompt_sync_trace_types.rs b/crates/cuda-driver/src/prompt_sync_trace_types.rs index ab682ac9..11d42a23 100644 --- a/crates/cuda-driver/src/prompt_sync_trace_types.rs +++ b/crates/cuda-driver/src/prompt_sync_trace_types.rs @@ -1,5 +1,5 @@ -//! Defines `PromptSyncTrace`, `Driver`, `Device` and 8 more. -//! PromptSyncTrace, Error, Result, Bf16ProjectionShape, Driver, Device .... +//! Core handle types of the CUDA driver crate: Driver, Device, Context (budget, poison flag, per-context kernel slots), +//! the fixed-kernel selectors, the projection shape record and the PromptSyncTrace bring-up guard. use super::{Cell, DeviceBuffer, Rc, RefCell, experimental, ffi, kar_decode_levels, original_verify, qwen_dispatch}; #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] diff --git a/crates/cuda-driver/src/q5_kshape_types.rs b/crates/cuda-driver/src/q5_kshape_types.rs index 638b5f60..5da4b6f1 100644 --- a/crates/cuda-driver/src/q5_kshape_types.rs +++ b/crates/cuda-driver/src/q5_kshape_types.rs @@ -1,5 +1,5 @@ -//! Defines `Q5KShape`, `Q6KShape`, `MatvecShape` and 2 more. -//! Q5KShape, Q6KShape, MatvecShape, CurrentGuard, DeviceBuffer. +//! Plain records shared by the projection code: Q5_K, Q6_K and matvec shapes (byte sizes and launch grids), the +//! CurrentGuard push/pop context guard and DeviceBuffer, the exact byte allocation borrowed from a Context. use super::{Context, PhantomData, Rc, ffi}; diff --git a/crates/cuda-driver/src/q6_k_shape.rs b/crates/cuda-driver/src/q6_k_shape.rs index dfd983e3..55234643 100644 --- a/crates/cuda-driver/src/q6_k_shape.rs +++ b/crates/cuda-driver/src/q6_k_shape.rs @@ -1,5 +1,5 @@ -//! Functions: `q6_k_shape`, `q6_abi_extents`, `q6_checked_bytes`, `q6_grids` and 4 more. -//! Split out of `crate` to keep its files under the line limit. +//! Shape admission for Q6_K projections, the f32 matvec and the vector add: checked byte sizes, ABI extents and launch +//! grids, plus the allocation checks that keep the matvec output from aliasing its inputs. use super::{Error, MatvecShape, Q6KShape, Result, ffi, valid_size}; diff --git a/crates/cuda-driver/src/qsa_late.rs b/crates/cuda-driver/src/qsa_late.rs index df4b2313..c060a944 100644 --- a/crates/cuda-driver/src/qsa_late.rs +++ b/crates/cuda-driver/src/qsa_late.rs @@ -141,5 +141,4 @@ mod tests { } #[cfg(test)] -#[path = "qsa_late_gpu.rs"] mod gpu_tests; diff --git a/crates/cuda-driver/src/qsa_late_gpu.rs b/crates/cuda-driver/src/qsa_late/gpu_tests.rs similarity index 79% rename from crates/cuda-driver/src/qsa_late_gpu.rs rename to crates/cuda-driver/src/qsa_late/gpu_tests.rs index 6e1f2985..8ace773d 100644 --- a/crates/cuda-driver/src/qsa_late_gpu.rs +++ b/crates/cuda-driver/src/qsa_late/gpu_tests.rs @@ -29,9 +29,10 @@ fn selection_kernels_equal_the_originals_at_long_positions() { with_gpu(|context, stream, max_blocks| { let guard = context.enter().expect("enter"); let select = - KernelModule::load(include_bytes!("qsa_prompt_select.ptx"), &[c"qsa_topk_ref"]).expect("select module"); + KernelModule::load(include_bytes!("../qsa_prompt_select.ptx"), &[c"qsa_topk_ref"]).expect("select module"); let index = - KernelModule::load(include_bytes!("qsa_prompt_indexer.ptx"), &[c"qsa_score_scan"]).expect("index module"); + KernelModule::load(include_bytes!("../qsa_prompt_indexer.ptx"), &[c"qsa_score_scan"]) + .expect("index module"); let late = KernelModule::load(PTX, ENTRIES).expect("late module"); guard.finish().expect("finish"); let mut rng = Rng(0x243f6a8885a308d3); @@ -79,7 +80,7 @@ fn topk_variants_equal_the_original_and_are_timed() { with_gpu(|context, stream, max_blocks| { let guard = context.enter().expect("enter"); let select = - KernelModule::load(include_bytes!("qsa_prompt_select.ptx"), &[c"qsa_topk_ref"]).expect("select module"); + KernelModule::load(include_bytes!("../qsa_prompt_select.ptx"), &[c"qsa_topk_ref"]).expect("select module"); let late = KernelModule::load(PTX, ENTRIES).expect("late module"); let cluster = KernelModule::load(crate::qsa_cluster::PTX, crate::qsa_cluster::ENTRIES).expect("cluster module"); guard.finish().expect("finish"); @@ -103,7 +104,7 @@ fn decode_scores_are_timed_next_to_the_topk() { with_gpu(|context, stream, max_blocks| { let guard = context.enter().expect("enter"); let select = - KernelModule::load(include_bytes!("qsa_prompt_select.ptx"), &[c"qsa_decode_scores", c"qsa_topk_ref"]) + KernelModule::load(include_bytes!("../qsa_prompt_select.ptx"), &[c"qsa_decode_scores", c"qsa_topk_ref"]) .expect("select module"); guard.finish().expect("finish"); let mut rng = Rng(0x1234_5678_9abc_def1); @@ -113,51 +114,19 @@ fn decode_scores_are_timed_next_to_the_topk() { }); } -#[path = "qsa_late_gpu/rng.rs"] mod rng; -#[allow(unused_imports)] use rng::download; -#[allow(unused_imports)] use rng::f32_raw; -#[allow(unused_imports)] use rng::handle; -#[allow(unused_imports)] -use rng::scan_flags_match_original; -#[allow(unused_imports)] -use rng::scores_with_variant; -#[allow(unused_imports)] use rng::selection_case; -#[allow(unused_imports)] -use rng::selection_scores; -#[allow(unused_imports)] use rng::step_bytes; -#[allow(unused_imports)] use rng::topk_args; -#[allow(unused_imports)] -use rng::topk_matches_original; -#[allow(unused_imports)] use rng::upload; -#[allow(unused_imports)] use rng::with_gpu; -#[path = "qsa_late_gpu/scan_both.rs"] mod scan_both; -#[allow(unused_imports)] use scan_both::bench_case; -#[allow(unused_imports)] use scan_both::bench_cases; -#[allow(unused_imports)] -use scan_both::bench_scores; -#[allow(unused_imports)] use scan_both::decode_inputs; -#[allow(unused_imports)] use scan_both::scan_both; -#[allow(unused_imports)] -use scan_both::time_variant; -#[allow(unused_imports)] -use scan_both::topk_variants; -#[path = "qsa_late_gpu/time_scores_and_topk.rs"] mod time_scores_and_topk; -#[allow(unused_imports)] use time_scores_and_topk::time_scores_and_topk; -#[allow(unused_imports)] -use time_scores_and_topk::time_warm; diff --git a/crates/cuda-driver/src/qsa_late_gpu/rng.rs b/crates/cuda-driver/src/qsa_late/gpu_tests/rng.rs similarity index 96% rename from crates/cuda-driver/src/qsa_late_gpu/rng.rs rename to crates/cuda-driver/src/qsa_late/gpu_tests/rng.rs index 3941d94a..f6e73761 100644 --- a/crates/cuda-driver/src/qsa_late_gpu/rng.rs +++ b/crates/cuda-driver/src/qsa_late/gpu_tests/rng.rs @@ -1,5 +1,5 @@ -//! Methods of `Rng`: `next`. Functions: `upload`, `download`, `with_gpu`, `handle` and 8 more. -//! Split out of `gpu_tests` to keep its files under the line limit. +//! Shared fixtures of the QSA late-kernel GPU tests: a xorshift Rng, device upload/download, with_gpu setup, +//! synthetic block scores and step words, and the checks of the fast top-k and score scan against the Original kernels. use super::{A, CAP, Context, DeviceBuffer, Driver, ENABLE, KernelArguments, Rng, SelectionRig, TOPK_FAST, scan_both}; use crate::ple_batch_ffi::LinearLaunch; diff --git a/crates/cuda-driver/src/qsa_late_gpu/scan_both.rs b/crates/cuda-driver/src/qsa_late/gpu_tests/scan_both.rs similarity index 97% rename from crates/cuda-driver/src/qsa_late_gpu/scan_both.rs rename to crates/cuda-driver/src/qsa_late/gpu_tests/scan_both.rs index 306771e3..2dacf89b 100644 --- a/crates/cuda-driver/src/qsa_late_gpu/scan_both.rs +++ b/crates/cuda-driver/src/qsa_late/gpu_tests/scan_both.rs @@ -1,5 +1,5 @@ -//! Functions: `scan_both`, `bench_cases`, `bench_scores`, `topk_variants` and 4 more. -//! Split out of `gpu_tests` to keep its files under the line limit. +//! GPU test helpers that run the Original score scan and the late fast scan on the same scores, the benchmark case +//! table with its synthetic score generator, and the top-k variants (ref, fast, wide, sample, cluster) that are timed. use super::{ A, BenchRig, CAP, Context, DeviceBuffer, KernelArguments, Rng, Run, SCORE_SCAN_FAST, SelectionRig, TOPK_FAST, diff --git a/crates/cuda-driver/src/qsa_late_gpu/time_scores_and_topk.rs b/crates/cuda-driver/src/qsa_late/gpu_tests/time_scores_and_topk.rs similarity index 91% rename from crates/cuda-driver/src/qsa_late_gpu/time_scores_and_topk.rs rename to crates/cuda-driver/src/qsa_late/gpu_tests/time_scores_and_topk.rs index d2ad47ab..ab55c2fc 100644 --- a/crates/cuda-driver/src/qsa_late_gpu/time_scores_and_topk.rs +++ b/crates/cuda-driver/src/qsa_late/gpu_tests/time_scores_and_topk.rs @@ -1,5 +1,5 @@ -//! Functions: `time_scores_and_topk`, `time_warm`. -//! Split out of `gpu_tests` to keep its files under the line limit. +//! GPU timing helper of the QSA late tests: launches the decode scores kernel and the reference top-k at one +//! (position, query count) shape and reports warm microseconds per launch. use super::{ A, CAP, Context, DeviceBuffer, KernelArguments, KernelModule, Rng, decode_inputs, handle, topk_args, upload, diff --git a/crates/cuda-driver/src/qsa_native_batch.rs b/crates/cuda-driver/src/qsa_native_batch.rs index df368b03..d4a7df4a 100644 --- a/crates/cuda-driver/src/qsa_native_batch.rs +++ b/crates/cuda-driver/src/qsa_native_batch.rs @@ -58,6 +58,4 @@ pub struct QsaNativeBatchWorkspace<'ctx> { } mod qsa_native_kind; -#[allow(unused_imports)] -use qsa_native_kind::encoded; mod native_projections; diff --git a/crates/cuda-driver/src/qsa_native_batch/native_projections.rs b/crates/cuda-driver/src/qsa_native_batch/native_projections.rs index 75aec2f5..ea836fd1 100644 --- a/crates/cuda-driver/src/qsa_native_batch/native_projections.rs +++ b/crates/cuda-driver/src/qsa_native_batch/native_projections.rs @@ -1,5 +1,6 @@ -//! Methods of `QsaNativeBatchWorkspace`: `project`, `project_io`, `launch_project`, `reset_status` and 10 more. -//! Methods of `ProjectionShape`: `new`, `inputs`. Implements `Drop for QsaNativeBatchWorkspace`. +//! The projection stage of the QSA native batch workspace: packs activations, scans inputs and weights for non-finite +//! values, dequantizes quantized weights to F16 and runs the vendor GEMMs for the five input projections and the gated +//! Out projection, then settles the status words, with its close and Drop. use super::{ A, DeviceBuffer, Error, KernelArguments, KernelModule, NativeBatchWorkspace, QsaGatedAttention, QsaInputWeights, diff --git a/crates/cuda-driver/src/qsa_native_batch/qsa_native_kind.rs b/crates/cuda-driver/src/qsa_native_batch/qsa_native_kind.rs index 5ef24352..31fbad64 100644 --- a/crates/cuda-driver/src/qsa_native_batch/qsa_native_kind.rs +++ b/crates/cuda-driver/src/qsa_native_batch/qsa_native_kind.rs @@ -1,5 +1,5 @@ -//! Methods of `QsaNativeKind`: `entry`, `block`. -//! Methods of `Context`: `qsa_native_batch_workspace`, `qsa_native_batch_workspace_for_prompt`. +//! Construction and buffer handling of the QSA native batch workspace: weight format table (Q4_K, Q5_K, Q6_K, +//! IQ4_XS), capacity and budget admission, module loading, span checks, host upload and readback, Context hooks. use super::{ Context, DEQUANT_PTX, DeviceBuffer, Error, KernelModule, NativeBatchWorkspace, PTX, QsaNativeBatchWorkspace, diff --git a/crates/cuda-driver/src/qsa_native_decode.rs b/crates/cuda-driver/src/qsa_native_decode.rs index 1019fb71..bf35964c 100644 --- a/crates/cuda-driver/src/qsa_native_decode.rs +++ b/crates/cuda-driver/src/qsa_native_decode.rs @@ -365,6 +365,5 @@ fn load_decode_module(c: &Context<'_>) -> Result { } } -#[path = "qsa_resident_decode.rs"] mod resident_decode; pub use resident_decode::OriginalQsaResidentDecodeCompletion; diff --git a/crates/cuda-driver/src/qsa_resident_decode.rs b/crates/cuda-driver/src/qsa_native_decode/resident_decode.rs similarity index 100% rename from crates/cuda-driver/src/qsa_resident_decode.rs rename to crates/cuda-driver/src/qsa_native_decode/resident_decode.rs diff --git a/crates/cuda-driver/src/qsa_prompt_attention.rs b/crates/cuda-driver/src/qsa_prompt_attention.rs index 71802e12..c6c5a977 100644 --- a/crates/cuda-driver/src/qsa_prompt_attention.rs +++ b/crates/cuda-driver/src/qsa_prompt_attention.rs @@ -42,10 +42,8 @@ pub struct QsaPromptAttentionCompletion<'loan, 'ctx> { t: usize, } -#[path = "qsa_prompt_device_attention.rs"] mod device_attention; -#[path = "qsa_resident_attention.rs"] mod resident_attention; pub(crate) use resident_attention::OriginalQsaAttendedKv; @@ -54,5 +52,4 @@ pub use resident_attention::OriginalQsaResidentAttention; mod attention_kernel_plan_and_passes; mod qsa_attention_inputs; mod qsa_prompt_attention_drop; -#[allow(unused_imports)] pub(crate) use qsa_prompt_attention_drop::guard_grid; diff --git a/crates/cuda-driver/src/qsa_prompt_attention/attention_kernel_plan_and_passes.rs b/crates/cuda-driver/src/qsa_prompt_attention/attention_kernel_plan_and_passes.rs index 26f178be..565f926b 100644 --- a/crates/cuda-driver/src/qsa_prompt_attention/attention_kernel_plan_and_passes.rs +++ b/crates/cuda-driver/src/qsa_prompt_attention/attention_kernel_plan_and_passes.rs @@ -1,5 +1,5 @@ -//! Methods of `KernelPlan`: `entry`. Defines `KernelPlan`, `KernelEntry`, `AttnPasses` and 1 more. -//! Split out of `qsa_prompt_attention` to keep its files under the line limit. +//! Plain types that describe one QSA prompt attention launch: the kernel plan (module, entries, shared bytes), the +//! launch target, the device addresses the three passes use, and the Runner signature; the logic lives in submodules. use super::{ Arg, Arguments, Context, DeviceBuffer, DeviceCaps, Error, LaunchGeometry, Module, NativeBatchWorkspace, @@ -52,7 +52,5 @@ pub(super) type Runner<'ctx> = fn( mod attention_passes; mod prompt_attention_owner; mod reject_mutual_alias; -#[allow(unused_imports)] pub(super) use reject_mutual_alias::admit_budget; -#[allow(unused_imports)] use reject_mutual_alias::reject_mutual_alias; diff --git a/crates/cuda-driver/src/qsa_prompt_attention/attention_kernel_plan_and_passes/attention_passes.rs b/crates/cuda-driver/src/qsa_prompt_attention/attention_kernel_plan_and_passes/attention_passes.rs index ce58130e..ef144870 100644 --- a/crates/cuda-driver/src/qsa_prompt_attention/attention_kernel_plan_and_passes/attention_passes.rs +++ b/crates/cuda-driver/src/qsa_prompt_attention/attention_kernel_plan_and_passes/attention_passes.rs @@ -1,5 +1,5 @@ -//! Methods of `QsaPromptAttention`: `attend_kernel`, `ensure_plan`, `validate_stage`, `output_address` and 10 more. -//! Methods of `KernelPlan`: `of`. +//! The launch sequence of QSA prompt attention: chooses the kernel plan, admits the Q/IDs/steps inputs (exact sizes, no +//! aliasing with the stage, workspace or own buffers), then runs guard scan, attention and output scan; also closes it. use super::{ Arg, Arguments, AttnPasses, DeviceBuffer, Error, KernelPlan, LaunchGeometry, Module, NativeBatchWorkspace, diff --git a/crates/cuda-driver/src/qsa_prompt_attention/attention_kernel_plan_and_passes/prompt_attention_owner.rs b/crates/cuda-driver/src/qsa_prompt_attention/attention_kernel_plan_and_passes/prompt_attention_owner.rs index 689506f3..92e8a927 100644 --- a/crates/cuda-driver/src/qsa_prompt_attention/attention_kernel_plan_and_passes/prompt_attention_owner.rs +++ b/crates/cuda-driver/src/qsa_prompt_attention/attention_kernel_plan_and_passes/prompt_attention_owner.rs @@ -1,5 +1,5 @@ -//! Methods of `QsaPromptAttention`: `new`, `new_capacity`, `with_module`, `allocate_buffers` and 13 more. -//! Split out of `attention_kernel_plan_and_passes` to keep its files under the line limit. +//! The QsaPromptAttention owner: allocation of its output bank and status word under the memory budget, module loading, +//! state accessors and the public attend entries that select the attention kernel for the device. use super::{ Arguments, Context, DeviceBuffer, DeviceCaps, Error, KernelEntry, LaunchGeometry, Module, NativeBatchWorkspace, diff --git a/crates/cuda-driver/src/qsa_prompt_attention/attention_kernel_plan_and_passes/reject_mutual_alias.rs b/crates/cuda-driver/src/qsa_prompt_attention/attention_kernel_plan_and_passes/reject_mutual_alias.rs index ab6e1b71..1ea6e113 100644 --- a/crates/cuda-driver/src/qsa_prompt_attention/attention_kernel_plan_and_passes/reject_mutual_alias.rs +++ b/crates/cuda-driver/src/qsa_prompt_attention/attention_kernel_plan_and_passes/reject_mutual_alias.rs @@ -1,5 +1,5 @@ -//! Functions: `reject_mutual_alias`, `admit_budget`. -//! Split out of `attention_kernel_plan_and_passes` to keep its files under the line limit. +//! Admission checks of QSA prompt attention: no two input buffers may overlap, and the output bank plus status word +//! and a 128 MiB reserve must fit the context budget and the free device memory. use super::{Context, DeviceBuffer, Error, Result}; diff --git a/crates/cuda-driver/src/qsa_prompt_device_attention.rs b/crates/cuda-driver/src/qsa_prompt_attention/device_attention.rs similarity index 100% rename from crates/cuda-driver/src/qsa_prompt_device_attention.rs rename to crates/cuda-driver/src/qsa_prompt_attention/device_attention.rs diff --git a/crates/cuda-driver/src/qsa_prompt_attention/qsa_attention_inputs.rs b/crates/cuda-driver/src/qsa_prompt_attention/qsa_attention_inputs.rs index 7d7c60f4..a6eedcfd 100644 --- a/crates/cuda-driver/src/qsa_prompt_attention/qsa_attention_inputs.rs +++ b/crates/cuda-driver/src/qsa_prompt_attention/qsa_attention_inputs.rs @@ -1,5 +1,5 @@ -//! Methods of `QsaAttentionInputs`: `new`. -//! Methods of `Context`: `qsa_prompt_attention`, `qsa_prompt_attention_for_capacity`. +//! Validated inputs of QSA prompt attention (Q, selected IDs and steps buffers with exact sizes for t rows) and the +//! Context constructors of QsaPromptAttention. use super::{Context, DeviceBuffer, Error, QsaAttentionInputs, QsaPromptAttention, Result, checked}; diff --git a/crates/cuda-driver/src/qsa_prompt_attention/qsa_prompt_attention_drop.rs b/crates/cuda-driver/src/qsa_prompt_attention/qsa_prompt_attention_drop.rs index 15db6b8a..755436a0 100644 --- a/crates/cuda-driver/src/qsa_prompt_attention/qsa_prompt_attention_drop.rs +++ b/crates/cuda-driver/src/qsa_prompt_attention/qsa_prompt_attention_drop.rs @@ -1,5 +1,5 @@ -//! Methods of `QsaPromptAttentionCompletion`: `rows`, `with_output`, `into_values`. -//! Implements `Drop for QsaPromptAttention`. Functions: `guard_grid`. +//! Result side of QSA prompt attention: the completion view of the output bank (rows, borrowed output, host copy +//! of the values), the Drop of the owner and the launch grid of the guard kernels. use super::{DeviceBuffer, Error, QsaPromptAttention, QsaPromptAttentionCompletion, Result}; diff --git a/crates/cuda-driver/src/qsa_resident_attention.rs b/crates/cuda-driver/src/qsa_prompt_attention/resident_attention.rs similarity index 99% rename from crates/cuda-driver/src/qsa_resident_attention.rs rename to crates/cuda-driver/src/qsa_prompt_attention/resident_attention.rs index e8313eb4..58907c12 100644 --- a/crates/cuda-driver/src/qsa_resident_attention.rs +++ b/crates/cuda-driver/src/qsa_prompt_attention/resident_attention.rs @@ -208,7 +208,7 @@ fn load_resident_module(c: &Context<'_>) -> Result { e })?; let load = Module::load( - include_bytes!("qsa_prompt_attention.ptx"), + include_bytes!("../qsa_prompt_attention.ptx"), &[c"leleka_qsa_prompt_guard", c"leleka_qsa_prompt_attn", c"leleka_qsa_prompt_output_guard"], ); let pop = g.finish(); diff --git a/crates/cuda-driver/src/qsa_prompt_index.rs b/crates/cuda-driver/src/qsa_prompt_index.rs index 47b1838b..b1ade19e 100644 --- a/crates/cuda-driver/src/qsa_prompt_index.rs +++ b/crates/cuda-driver/src/qsa_prompt_index.rs @@ -50,37 +50,30 @@ pub struct QsaPromptSelection<'lease, 'ctx> { } mod index_rows; -#[allow(unused_imports)] use index_rows::SelectRequest; pub(crate) use index_rows::{ArenaRows, IndexProgramSpans}; pub use index_rows::{QsaChunkRows, QsaIndexPrior}; -#[path = "qsa_prompt_device_index.rs"] mod device_index; -#[path = "qsa_prompt_device.rs"] mod prompt_device; pub(crate) use prompt_device::kv_stage_spans_of; pub use prompt_device::{ OriginalQsaDeviceSelection, OriginalQsaPromptDevice, OriginalQsaPromptWeights, QsaChunkPrior, QsaKvAppendTarget, }; -#[path = "qsa_resident_index.rs"] mod resident_index; pub use resident_index::{ OriginalQsaIndexBatch, OriginalQsaIndexCheckpoint, OriginalQsaResidentIndex, ResidentContinuation, }; -#[path = "qsa_resident_index_program.rs"] mod resident_program; -#[path = "qsa_resident_transfer.rs"] #[allow(unsafe_code)] pub(crate) mod resident_transfer; pub use prompt_device::{ OriginalQsaResidentAppendTarget, OriginalQsaResidentPromptDevice, OriginalQsaResidentSelection, }; -#[path = "qsa_resident_scalar_index.rs"] mod resident_scalar_index; pub use resident_scalar_index::{OriginalQsaResidentScalarIndex, OriginalQsaResidentScalarSelection, ScalarStepRows}; @@ -88,11 +81,8 @@ pub use resident_scalar_index::{OriginalQsaResidentScalarIndex, OriginalQsaResid pub use resident_index::verification_commit::{OriginalQsaOwners, OriginalVerifyQsaJournal, OriginalVerifyRope}; mod max_blocks; -#[allow(unused_imports)] use max_blocks::encode; -#[allow(unused_imports)] use max_blocks::max_blocks; -#[allow(unused_imports)] use max_blocks::sizes; mod append_select; mod index_run; diff --git a/crates/cuda-driver/src/qsa_prompt_index/append_select.rs b/crates/cuda-driver/src/qsa_prompt_index/append_select.rs index 458eefc5..596e9360 100644 --- a/crates/cuda-driver/src/qsa_prompt_index/append_select.rs +++ b/crates/cuda-driver/src/qsa_prompt_index/append_select.rs @@ -1,5 +1,5 @@ -//! Methods of `QsaPromptIndexWorkspace`: `append_select_inner`, `check_select_inputs`, `select_bounds_ok`, `admit_ou... -//! Functions: `release_outputs`, `select_lengths_ok`. Defines `Outputs`. +//! Append-and-select entry of the QSA prompt index workspace: validates the prior image and row inputs, allocates and +//! alias-checks the five per-call output buffers, runs the index program and reads back the selection state. use super::{ CAP, DeviceBuffer, Error, IndexProgramSpans, NativeBatchWorkspace, QsaPromptIndexWorkspace, QsaPromptSelection, diff --git a/crates/cuda-driver/src/qsa_prompt_device_index.rs b/crates/cuda-driver/src/qsa_prompt_index/device_index.rs similarity index 100% rename from crates/cuda-driver/src/qsa_prompt_device_index.rs rename to crates/cuda-driver/src/qsa_prompt_index/device_index.rs diff --git a/crates/cuda-driver/src/qsa_prompt_index/index_run.rs b/crates/cuda-driver/src/qsa_prompt_index/index_run.rs index 75b21c95..22163aa3 100644 --- a/crates/cuda-driver/src/qsa_prompt_index/index_run.rs +++ b/crates/cuda-driver/src/qsa_prompt_index/index_run.rs @@ -1,5 +1,5 @@ -//! Methods of `QsaPromptIndexWorkspace`: `run`, `execute_run`. -//! Split out of `qsa_prompt_index` to keep its files under the line limit. +//! Non-resident run of the QSA prompt index program: uploads the prior image and rows, stages the commands and +//! executes them under the context guard, then checks the status words and the selected IDs. use super::run_phases::{HostStaging, RunPlan}; use super::{ diff --git a/crates/cuda-driver/src/qsa_prompt_index/max_blocks.rs b/crates/cuda-driver/src/qsa_prompt_index/max_blocks.rs index b009dce6..52a69af9 100644 --- a/crates/cuda-driver/src/qsa_prompt_index/max_blocks.rs +++ b/crates/cuda-driver/src/qsa_prompt_index/max_blocks.rs @@ -1,5 +1,5 @@ -//! Methods of `Context`: `qsa_prompt_index_workspace`, `qsa_prompt_index_workspace_for_capacity`. -//! Functions: `max_blocks`, `sizes`, `encode`. +//! Size constants of the QSA prompt index workspace derived from the serving context (score row stride, the eleven +//! buffer sizes), the f32 little-endian encoder for uploads and the Context constructors. use super::{Context, Error, QsaPromptIndexWorkspace, Result}; diff --git a/crates/cuda-driver/src/qsa_prompt_device.rs b/crates/cuda-driver/src/qsa_prompt_index/prompt_device.rs similarity index 86% rename from crates/cuda-driver/src/qsa_prompt_device.rs rename to crates/cuda-driver/src/qsa_prompt_index/prompt_device.rs index 1c8e3df6..53473e7f 100644 --- a/crates/cuda-driver/src/qsa_prompt_device.rs +++ b/crates/cuda-driver/src/qsa_prompt_index/prompt_device.rs @@ -13,7 +13,7 @@ use crate::{ QsaNativePacking, QsaNativeWeight, QsaPromptAttention, QsaPromptKv, QsaPromptStage, }; const SCRATCH: usize = 64 << 20; -const GATE_PTX: &[u8] = concat!(include_str!("qsa_prompt_device_gate.ptx"), "\0").as_bytes(); +const GATE_PTX: &[u8] = concat!(include_str!("../qsa_prompt_device_gate.ptx"), "\0").as_bytes(); const GATE_SHA: [u8; 32] = [ 0x69, 0xf0, 0x3b, 0xe1, 0x7d, 0xb1, 0x7a, 0xba, 0x2f, 0x82, 0x8c, 0xf4, 0x37, 0x91, 0x0a, 0x4d, 0xb6, 0x63, 0x23, 0x97, 0x3d, 0xaa, 0x8b, 0x1a, 0x45, 0x9c, 0x24, 0x18, 0xf9, 0x11, 0x45, 0xd4, @@ -68,30 +68,19 @@ pub struct OriginalQsaDeviceSelection<'lease, 'arena, 'loan, 'ctx> { state: QsaPromptIndexState, } -#[path = "qsa_resident_device.rs"] mod resident_device; pub(crate) use resident_device::kv_stage_spans_of; pub use resident_device::{ OriginalQsaResidentAppendTarget, OriginalQsaResidentPromptDevice, OriginalQsaResidentSelection, }; -#[path = "qsa_prompt_device/context.rs"] mod context; -#[allow(unused_imports)] use context::arena_span; -#[allow(unused_imports)] use context::common; -#[allow(unused_imports)] use context::native_block; -#[allow(unused_imports)] use context::native_entry; -#[path = "qsa_prompt_device/device_phases.rs"] mod device_phases; -#[path = "qsa_prompt_device/device_prepare.rs"] mod device_prepare; -#[path = "qsa_prompt_device/original_qsa_prompt_device.rs"] mod original_qsa_prompt_device; -#[path = "qsa_prompt_device/project_phases.rs"] mod project_phases; -#[path = "qsa_prompt_device/selection_completion.rs"] mod selection_completion; diff --git a/crates/cuda-driver/src/qsa_prompt_device/context.rs b/crates/cuda-driver/src/qsa_prompt_index/prompt_device/context.rs similarity index 88% rename from crates/cuda-driver/src/qsa_prompt_device/context.rs rename to crates/cuda-driver/src/qsa_prompt_index/prompt_device/context.rs index 2232faf6..c4bc5cbf 100644 --- a/crates/cuda-driver/src/qsa_prompt_device/context.rs +++ b/crates/cuda-driver/src/qsa_prompt_index/prompt_device/context.rs @@ -1,5 +1,5 @@ -//! Methods of `Context`: `original_qsa_prompt_device`. -//! Functions: `native_block`, `native_entry`, `arena_span`, `common`. +//! Context entry point of the Original QSA prompt device, plus lookup of native weight block sizes and entries per +//! quantization kind and of the arena and common spans a chunk read exposes. use super::{ Context, OriginalDeviceGrRead, OriginalQsaPromptDevice, PrefillPhase, QsaNativeKind, QsaNativePacking, Result, S, diff --git a/crates/cuda-driver/src/qsa_prompt_device/device_phases.rs b/crates/cuda-driver/src/qsa_prompt_index/prompt_device/device_phases.rs similarity index 98% rename from crates/cuda-driver/src/qsa_prompt_device/device_phases.rs rename to crates/cuda-driver/src/qsa_prompt_index/prompt_device/device_phases.rs index 35a2c440..e7bdd0be 100644 --- a/crates/cuda-driver/src/qsa_prompt_device/device_phases.rs +++ b/crates/cuda-driver/src/qsa_prompt_index/prompt_device/device_phases.rs @@ -52,7 +52,7 @@ fn load_dequant() -> Result { return KernelModule::load(crate::prefill_stage::PTX, crate::prefill_stage::ENTRIES); } KernelModule::load( - concat!(include_str!("../offline_native_dequant_f16.ptx"), "\0").as_bytes(), + concat!(include_str!("../../offline_native_dequant_f16.ptx"), "\0").as_bytes(), &[ c"leleka_native_dequant_f16_q4_k", c"leleka_native_dequant_f16_q5_k", @@ -134,7 +134,7 @@ impl<'ctx> OriginalQsaPromptDevice<'ctx> { Some(Module::load(INDEX, SELECT, POSTOPS, DECODE_POSTOPS)?); self.dequant = Some(load_dequant()?); self.pack = Some(KernelModule::load( - concat!(include_str!("../qsa_native_batch.ptx"), "\0").as_bytes(), + concat!(include_str!("../../qsa_native_batch.ptx"), "\0").as_bytes(), &[c"qsa_pack", c"qsa_gate_pack", c"qsa_scan_half"], )?); self.gate = Some(KernelModule::load(GATE_PTX, &[c"qsa_prompt_device_gate"])?); diff --git a/crates/cuda-driver/src/qsa_prompt_device/device_prepare.rs b/crates/cuda-driver/src/qsa_prompt_index/prompt_device/device_prepare.rs similarity index 92% rename from crates/cuda-driver/src/qsa_prompt_device/device_prepare.rs rename to crates/cuda-driver/src/qsa_prompt_index/prompt_device/device_prepare.rs index 9f1531a0..f19a6140 100644 --- a/crates/cuda-driver/src/qsa_prompt_device/device_prepare.rs +++ b/crates/cuda-driver/src/qsa_prompt_index/prompt_device/device_prepare.rs @@ -1,7 +1,6 @@ -//! Methods of `OriginalQsaPromptDevice`: `project`, `prepare`, `close`. -//! Split out of `prompt_device` to keep its files under the line limit. +//! Prepare step of the Original QSA prompt device: projects the chunk rows with native weights, runs the prompt index +//! program after the prior image, and returns the pending selection that complete() later finishes. -#[allow(unused_imports)] use super::project_phases::{ProjectArgs, Projection}; use super::{ ArenaRows, Error, IndexProgramSpans, NativeBatchWorkspace, OriginalDeviceGrRead, OriginalQsaDeviceSelection, diff --git a/crates/cuda-driver/src/qsa_prompt_device/original_qsa_prompt_device.rs b/crates/cuda-driver/src/qsa_prompt_index/prompt_device/original_qsa_prompt_device.rs similarity index 94% rename from crates/cuda-driver/src/qsa_prompt_device/original_qsa_prompt_device.rs rename to crates/cuda-driver/src/qsa_prompt_index/prompt_device/original_qsa_prompt_device.rs index a5f8ce8c..1eb1120c 100644 --- a/crates/cuda-driver/src/qsa_prompt_device/original_qsa_prompt_device.rs +++ b/crates/cuda-driver/src/qsa_prompt_index/prompt_device/original_qsa_prompt_device.rs @@ -1,7 +1,6 @@ -//! Methods of `OriginalQsaPromptDevice`: `device_bytes`, `new`, `is_failed`, `allocated_bytes` and 2 more. -//! Split out of `prompt_device` to keep its files under the line limit. +//! Construction and admission of the Original QSA prompt device: device byte budget for a capacity, resource +//! allocation, ownership checks of weight buffers, and the admission that all spans are disjoint. -#[allow(unused_imports)] use super::device_phases::{check_assets, index_for}; use super::{ Context, DeviceBuffer, Error, NativeBatchWorkspace, OriginalDeviceGrRead, OriginalQsaPromptDevice, diff --git a/crates/cuda-driver/src/qsa_prompt_device/project_phases.rs b/crates/cuda-driver/src/qsa_prompt_index/prompt_device/project_phases.rs similarity index 100% rename from crates/cuda-driver/src/qsa_prompt_device/project_phases.rs rename to crates/cuda-driver/src/qsa_prompt_index/prompt_device/project_phases.rs diff --git a/crates/cuda-driver/src/qsa_resident_device.rs b/crates/cuda-driver/src/qsa_prompt_index/prompt_device/resident_device.rs similarity index 89% rename from crates/cuda-driver/src/qsa_resident_device.rs rename to crates/cuda-driver/src/qsa_prompt_index/prompt_device/resident_device.rs index 44ee17ea..ff6e66a1 100644 --- a/crates/cuda-driver/src/qsa_resident_device.rs +++ b/crates/cuda-driver/src/qsa_prompt_index/prompt_device/resident_device.rs @@ -31,11 +31,7 @@ pub struct OriginalQsaResidentPromptDevice<'ctx> { inner: OriginalQsaPromptDevice<'ctx>, } -#[path = "qsa_resident_device/original_qsa_prompt_device.rs"] mod original_qsa_prompt_device; -#[allow(unused_imports)] pub(crate) use original_qsa_prompt_device::kv_stage_spans_of; -#[path = "qsa_resident_device/qsa_prompt_device_resident_bring_up.rs"] mod qsa_prompt_device_resident_bring_up; -#[path = "qsa_resident_device/qsa_resident_prompt_device_prepare.rs"] mod qsa_resident_prompt_device_prepare; diff --git a/crates/cuda-driver/src/qsa_resident_device/original_qsa_prompt_device.rs b/crates/cuda-driver/src/qsa_prompt_index/prompt_device/resident_device/original_qsa_prompt_device.rs similarity index 98% rename from crates/cuda-driver/src/qsa_resident_device/original_qsa_prompt_device.rs rename to crates/cuda-driver/src/qsa_prompt_index/prompt_device/resident_device/original_qsa_prompt_device.rs index 1bb8e191..922f3179 100644 --- a/crates/cuda-driver/src/qsa_resident_device/original_qsa_prompt_device.rs +++ b/crates/cuda-driver/src/qsa_prompt_index/prompt_device/resident_device/original_qsa_prompt_device.rs @@ -1,5 +1,5 @@ -//! Methods of `ResidentJob`: `run_index`. -//! Methods of `OriginalQsaPromptDevice`: `prepare_resident`, `resident_bounds`, `check_resident_idle`, `admit_budget... +//! Resident-mode prepare of the Original QSA prompt device: admits a chunk, projects it, runs the index program in the +//! private resident image and rolls it back to the checkpoint on failure; also the resident selection accessors. use super::{ ArenaRows, CAP, Context, DeviceBuffer, Error, IndexProgramSpans, NativeBatchWorkspace, OriginalDeviceGrRead, diff --git a/crates/cuda-driver/src/qsa_resident_device/qsa_prompt_device_resident_bring_up.rs b/crates/cuda-driver/src/qsa_prompt_index/prompt_device/resident_device/qsa_prompt_device_resident_bring_up.rs similarity index 92% rename from crates/cuda-driver/src/qsa_resident_device/qsa_prompt_device_resident_bring_up.rs rename to crates/cuda-driver/src/qsa_prompt_index/prompt_device/resident_device/qsa_prompt_device_resident_bring_up.rs index 4e7c19c0..75fdebe0 100644 --- a/crates/cuda-driver/src/qsa_resident_device/qsa_prompt_device_resident_bring_up.rs +++ b/crates/cuda-driver/src/qsa_prompt_index/prompt_device/resident_device/qsa_prompt_device_resident_bring_up.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalQsaPromptDevice`: `new_resident`, `unloaded`, `init_resident`, `allocate_resident` and 2 more. -//! Functions: `check_sealed`, `resident_sizes`. +//! Bring-up of the resident Original QSA prompt device: checks the sealed kernels, sizes the placeholder index image, +//! checks the budget, allocates the buffers and loads the kernel modules. use super::{ Context, DECODE_POSTOPS, Error, GATE_PTX, GATE_SHA, INDEX, KernelModule, Module, OriginalQsaPromptDevice, @@ -116,7 +116,7 @@ impl<'ctx> OriginalQsaPromptDevice<'ctx> { Some(Module::load(INDEX, SELECT, POSTOPS, DECODE_POSTOPS)?); self.dequant = Some(Self::load_dequant()?); self.pack = Some(KernelModule::load( - concat!(include_str!("../qsa_native_batch.ptx"), "\0").as_bytes(), + concat!(include_str!("../../../qsa_native_batch.ptx"), "\0").as_bytes(), &[c"qsa_pack", c"qsa_gate_pack", c"qsa_scan_half"], )?); self.gate = Some(KernelModule::load(GATE_PTX, &[c"qsa_prompt_device_gate"])?); @@ -127,7 +127,7 @@ impl<'ctx> OriginalQsaPromptDevice<'ctx> { return KernelModule::load(crate::prefill_stage::PTX, crate::prefill_stage::ENTRIES); } KernelModule::load( - concat!(include_str!("../offline_native_dequant_f16.ptx"), "\0").as_bytes(), + concat!(include_str!("../../../offline_native_dequant_f16.ptx"), "\0").as_bytes(), &[ c"leleka_native_dequant_f16_q4_k", c"leleka_native_dequant_f16_q5_k", diff --git a/crates/cuda-driver/src/qsa_resident_device/qsa_resident_prompt_device_prepare.rs b/crates/cuda-driver/src/qsa_prompt_index/prompt_device/resident_device/qsa_resident_prompt_device_prepare.rs similarity index 97% rename from crates/cuda-driver/src/qsa_resident_device/qsa_resident_prompt_device_prepare.rs rename to crates/cuda-driver/src/qsa_prompt_index/prompt_device/resident_device/qsa_resident_prompt_device_prepare.rs index 8280411d..b41e243b 100644 --- a/crates/cuda-driver/src/qsa_resident_device/qsa_resident_prompt_device_prepare.rs +++ b/crates/cuda-driver/src/qsa_prompt_index/prompt_device/resident_device/qsa_resident_prompt_device_prepare.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalQsaResidentSelection`: `abort`, `complete`, `complete_inner`, `reject_weight_overlap` and 3 m... -//! Methods of `Context`: `original_qsa_resident_prompt_device`. +//! Public face of the resident Original QSA prompt device: the pending resident selection (abort, complete with KV +//! append, attention, Qf gate and native Out projection), the Out weight overlap check, and device byte accounting. use super::original_qsa_prompt_device::lap; use super::{ diff --git a/crates/cuda-driver/src/qsa_prompt_device/selection_completion.rs b/crates/cuda-driver/src/qsa_prompt_index/prompt_device/selection_completion.rs similarity index 95% rename from crates/cuda-driver/src/qsa_prompt_device/selection_completion.rs rename to crates/cuda-driver/src/qsa_prompt_index/prompt_device/selection_completion.rs index 5a44c48f..bbe78064 100644 --- a/crates/cuda-driver/src/qsa_prompt_device/selection_completion.rs +++ b/crates/cuda-driver/src/qsa_prompt_index/prompt_device/selection_completion.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalQsaPromptDevice`: `close_inner`. -//! Methods of `OriginalQsaDeviceSelection`: `rows`, `first_position`, `final_index`, `validate` and 3 more. +//! The pending selection of the Original QSA prompt device and its completion (INT8 KV append, attention, gate and +//! native Out projection), plus the Drop of the device. use super::{ CAP, CompletedQsaKvAppend, Context, Error, NativeBatchWorkspace, OriginalDeviceBlock, OriginalQsaDeviceSelection, diff --git a/crates/cuda-driver/src/qsa_prompt_index/qsa_prompt_index_read_and_close.rs b/crates/cuda-driver/src/qsa_prompt_index/qsa_prompt_index_read_and_close.rs index 5d1c6d7f..cbb9bedf 100644 --- a/crates/cuda-driver/src/qsa_prompt_index/qsa_prompt_index_read_and_close.rs +++ b/crates/cuda-driver/src/qsa_prompt_index/qsa_prompt_index_read_and_close.rs @@ -1,5 +1,5 @@ -//! Methods of `QsaPromptIndexWorkspace`: `read`, `final_state`, `final_state_with`, `read_finite` and 3 more. -//! Methods of `QsaPromptIndexPrefix`: `end_position`, `pooled`, `tail`, `dead`. +//! Result side of the QSA prompt index workspace: device-to-host readback of the final index state (pooled, tail, +//! dead rows, finite-checked), the accessors of states, prefixes and selections, and the close/Drop paths. use super::{ Context, DeviceBuffer, Error, QsaPromptIndexPrefix, QsaPromptIndexState, QsaPromptIndexWorkspace, diff --git a/crates/cuda-driver/src/qsa_prompt_index/qsa_prompt_index_workspace.rs b/crates/cuda-driver/src/qsa_prompt_index/qsa_prompt_index_workspace.rs index 63954029..5ad47d57 100644 --- a/crates/cuda-driver/src/qsa_prompt_index/qsa_prompt_index_workspace.rs +++ b/crates/cuda-driver/src/qsa_prompt_index/qsa_prompt_index_workspace.rs @@ -1,5 +1,5 @@ -//! Methods of `QsaPromptIndexWorkspace`: `new`, `new_capacity`, `init_resources`, `prompt_device_bytes` and 11 more. -//! Functions: `capacity_sizes`, `check_assets_sealed`, `check_peak_budget`. +//! The QSA prompt index workspace owner: sizes, budget and sealed-asset admission, buffer allocation, weight and +//! overlap checks, input upload, and the public append_select entries for prompt rows and a single decode row. use super::{ CAP, Context, DECODE_POSTOPS, DeviceBuffer, Error, INDEX, Module, NativeBatchWorkspace, POSTOPS, QsaChunkRows, diff --git a/crates/cuda-driver/src/qsa_resident_index.rs b/crates/cuda-driver/src/qsa_prompt_index/resident_index.rs similarity index 88% rename from crates/cuda-driver/src/qsa_resident_index.rs rename to crates/cuda-driver/src/qsa_prompt_index/resident_index.rs index a6a4fad4..6b61cd18 100644 --- a/crates/cuda-driver/src/qsa_resident_index.rs +++ b/crates/cuda-driver/src/qsa_prompt_index/resident_index.rs @@ -5,7 +5,6 @@ use super::{ Context, DeviceBuffer, Error, NativeBatchWorkspace, QsaPromptIndexWorkspace, RESERVE, Result, combine, ffi, sizes, }; // used only with some cargo features or targets of this crate -#[allow(unused_imports)] use super::{DeviceRef, OriginalQsaMappedAppend, OriginalQsaMappedJournal}; use std::{ cell::{Cell, RefCell}, @@ -58,16 +57,10 @@ pub struct OriginalQsaIndexBatch<'index, 'weights, 'ctx> { } #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] -#[path = "qsa_verification_commit.rs"] pub(crate) mod verification_commit; -#[path = "qsa_resident_index/image_bytes.rs"] mod image_bytes; -#[allow(unused_imports)] use image_bytes::image_bytes; -#[path = "qsa_resident_index/original_qsa_index_batch.rs"] mod original_qsa_index_batch; -#[path = "qsa_resident_index/original_qsa_resident_index.rs"] mod original_qsa_resident_index; -#[path = "qsa_resident_index/qsa_resident_index_checkpoint_restore.rs"] mod qsa_resident_index_checkpoint_restore; diff --git a/crates/cuda-driver/src/qsa_resident_index/image_bytes.rs b/crates/cuda-driver/src/qsa_prompt_index/resident_index/image_bytes.rs similarity index 90% rename from crates/cuda-driver/src/qsa_resident_index/image_bytes.rs rename to crates/cuda-driver/src/qsa_prompt_index/resident_index/image_bytes.rs index f41b5adc..288a94e0 100644 --- a/crates/cuda-driver/src/qsa_resident_index/image_bytes.rs +++ b/crates/cuda-driver/src/qsa_prompt_index/resident_index/image_bytes.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalQsaIndexCheckpoint`: `next_position`, `device_bytes`, `validate_retained`. -//! Methods of `Context`: `original_qsa_resident_index`. Implements `Drop for Saved`. Functions: `image_bytes`. +//! Checkpoint side of the resident QSA index: the byte size of an index image, the pooled checkpoint buffer that +//! returns to its pool on drop, checkpoint accessors and validation, and the Context constructor of the index. use super::{ CHECKPOINT_BYTES, Context, DeviceBuffer, Error, OriginalQsaIndexCheckpoint, OriginalQsaResidentIndex, POOLED, diff --git a/crates/cuda-driver/src/qsa_resident_index/original_qsa_index_batch.rs b/crates/cuda-driver/src/qsa_prompt_index/resident_index/original_qsa_index_batch.rs similarity index 93% rename from crates/cuda-driver/src/qsa_resident_index/original_qsa_index_batch.rs rename to crates/cuda-driver/src/qsa_prompt_index/resident_index/original_qsa_index_batch.rs index afb3d7a5..bf117029 100644 --- a/crates/cuda-driver/src/qsa_resident_index/original_qsa_index_batch.rs +++ b/crates/cuda-driver/src/qsa_prompt_index/resident_index/original_qsa_index_batch.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalQsaIndexBatch`: `first_position`, `rows`, `commit_prefix`, `publish` and 2 more. -//! Implements `Drop for OriginalQsaIndexBatch`. +//! One in-flight batch of the resident QSA index: after a verification run, commit_prefix publishes the accepted rows +//! (restoring the start checkpoint and replaying the prefix when only some are accepted) or aborts the batch. use super::{ Error, NativeBatchWorkspace, OriginalQsaIndexBatch, OriginalQsaIndexCheckpoint, QsaPromptIndexWorkspace, Result, diff --git a/crates/cuda-driver/src/qsa_resident_index/original_qsa_resident_index.rs b/crates/cuda-driver/src/qsa_prompt_index/resident_index/original_qsa_resident_index.rs similarity index 98% rename from crates/cuda-driver/src/qsa_resident_index/original_qsa_resident_index.rs rename to crates/cuda-driver/src/qsa_prompt_index/resident_index/original_qsa_resident_index.rs index 5276a421..5b60cb1e 100644 --- a/crates/cuda-driver/src/qsa_resident_index/original_qsa_resident_index.rs +++ b/crates/cuda-driver/src/qsa_prompt_index/resident_index/original_qsa_resident_index.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalQsaResidentIndex`: `device_bytes`, `new`, `empty`, `init_image` and 19 more. -//! Functions: `poison_unless_host_allocation`. +//! The OriginalQsaResidentIndex owner: allocates and zero-fills its device image, validates context and checkpoints, +//! takes checkpoints (also several fenced at once) from a pooled buffer, and restores one. use super::{ CHECKPOINT_BYTES, Cell, Context, Coverage, DeviceBuffer, Error, NativeBatchWorkspace, Origin, diff --git a/crates/cuda-driver/src/qsa_resident_index/qsa_resident_index_checkpoint_restore.rs b/crates/cuda-driver/src/qsa_prompt_index/resident_index/qsa_resident_index_checkpoint_restore.rs similarity index 98% rename from crates/cuda-driver/src/qsa_resident_index/qsa_resident_index_checkpoint_restore.rs rename to crates/cuda-driver/src/qsa_prompt_index/resident_index/qsa_resident_index_checkpoint_restore.rs index 9377a905..53039661 100644 --- a/crates/cuda-driver/src/qsa_resident_index/qsa_resident_index_checkpoint_restore.rs +++ b/crates/cuda-driver/src/qsa_prompt_index/resident_index/qsa_resident_index_checkpoint_restore.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalQsaResidentIndex`: `restore_private`, `checkpoint_ranges`, `placed`, `reset` and 16 more. -//! Implements `Drop for Placement`, `Drop for OriginalQsaResidentIndex`. Defines `Placement`. +//! Restore, reset and close of the resident QSA index, the window-state read/write used to undo a verifier window, +//! and the prefix-cache export/import of pooled key rows plus a checkpoint tail (Placement swaps in the image). use super::original_qsa_resident_index::poison_unless_host_allocation; use super::{ diff --git a/crates/cuda-driver/src/qsa_verification_commit.rs b/crates/cuda-driver/src/qsa_prompt_index/resident_index/verification_commit.rs similarity index 85% rename from crates/cuda-driver/src/qsa_verification_commit.rs rename to crates/cuda-driver/src/qsa_prompt_index/resident_index/verification_commit.rs index 84790efd..267b9adf 100644 --- a/crates/cuda-driver/src/qsa_verification_commit.rs +++ b/crates/cuda-driver/src/qsa_prompt_index/resident_index/verification_commit.rs @@ -64,22 +64,13 @@ pub struct OriginalVerifyQsaJournal<'ctx> { ple_snapshot: RefCell>, } -#[path = "qsa_verification_commit/original_verify_rope.rs"] mod original_verify_rope; -#[allow(unused_imports)] use original_verify_rope::overlaps; -#[allow(unused_imports)] use original_verify_rope::whole; -#[path = "qsa_verification_commit/original_verify_qsa_journal.rs"] mod original_verify_qsa_journal; -#[path = "qsa_verification_commit/verify_qsa_journal_loan.rs"] mod verify_qsa_journal_loan; pub use verify_qsa_journal_loan::OriginalQsaOwners; -#[path = "qsa_verification_commit/verify_qsa_journal_capture_commit.rs"] mod verify_qsa_journal_capture_commit; -#[path = "qsa_verification_commit/verify_qsa_journal_index_image.rs"] mod verify_qsa_journal_index_image; -#[path = "qsa_verification_commit/verify_qsa_journal_publish_discard.rs"] mod verify_qsa_journal_publish_discard; -#[path = "qsa_verification_commit/verify_qsa_journal_rearm.rs"] mod verify_qsa_journal_rearm; diff --git a/crates/cuda-driver/src/qsa_verification_commit/original_verify_qsa_journal.rs b/crates/cuda-driver/src/qsa_prompt_index/resident_index/verification_commit/original_verify_qsa_journal.rs similarity index 98% rename from crates/cuda-driver/src/qsa_verification_commit/original_verify_qsa_journal.rs rename to crates/cuda-driver/src/qsa_prompt_index/resident_index/verification_commit/original_verify_qsa_journal.rs index 9b4e0867..6d8de783 100644 --- a/crates/cuda-driver/src/qsa_verification_commit/original_verify_qsa_journal.rs +++ b/crates/cuda-driver/src/qsa_prompt_index/resident_index/verification_commit/original_verify_qsa_journal.rs @@ -1,7 +1,6 @@ -//! Methods of `OriginalVerifyQsaJournal`: `new`, `validate_context`, `identity`, `with_image` and 10 more. -//! Functions: `check_armed_window`, `image_addresses`, `image_clear`, `check_gamma` and 2 more. Defines `Indices`. +//! The OriginalVerifyQsaJournal owner: twelve per-layer resident QSA indices plus their mapped K/V journals for the +//! verifier window; validates that images, norm weights and RoPE tables are disjoint and idle, and begins a window. -#[allow(unused_imports)] use super::verify_qsa_journal_loan::print_of; use super::{ Arg, Cell, Command, Context, DeviceBuffer, DeviceRef, Error, Live, NativeBatchWorkspace, OriginalCapture, diff --git a/crates/cuda-driver/src/qsa_verification_commit/original_verify_rope.rs b/crates/cuda-driver/src/qsa_prompt_index/resident_index/verification_commit/original_verify_rope.rs similarity index 91% rename from crates/cuda-driver/src/qsa_verification_commit/original_verify_rope.rs rename to crates/cuda-driver/src/qsa_prompt_index/resident_index/verification_commit/original_verify_rope.rs index cfbf4ed1..1106b3a9 100644 --- a/crates/cuda-driver/src/qsa_verification_commit/original_verify_rope.rs +++ b/crates/cuda-driver/src/qsa_prompt_index/resident_index/verification_commit/original_verify_rope.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalVerifyRope`: `validate`, `validate_scalars`. Functions: `validate_angles`, `whole`, `overlaps`. -//! Split out of `verification_commit` to keep its files under the line limit. +//! Validation of the retained RoPE constants and tables of the verifier: scalars finite and in range, the angle +//! tables and position buffer whole and sized for the capacity, and the buffer overlap tests. use super::{Context, DeviceBuffer, DeviceRef, Error, OriginalVerifyRope, Result}; diff --git a/crates/cuda-driver/src/qsa_verification_commit/verify_qsa_journal_capture_commit.rs b/crates/cuda-driver/src/qsa_prompt_index/resident_index/verification_commit/verify_qsa_journal_capture_commit.rs similarity index 98% rename from crates/cuda-driver/src/qsa_verification_commit/verify_qsa_journal_capture_commit.rs rename to crates/cuda-driver/src/qsa_prompt_index/resident_index/verification_commit/verify_qsa_journal_capture_commit.rs index 58fe22fe..0acfb90d 100644 --- a/crates/cuda-driver/src/qsa_verification_commit/verify_qsa_journal_capture_commit.rs +++ b/crates/cuda-driver/src/qsa_prompt_index/resident_index/verification_commit/verify_qsa_journal_capture_commit.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalVerifyQsaJournal`: `capture_commit_layer`, `capture_commit_fused`, `fused_layers`, `fused_wor... -//! Functions: `fused_io`. Defines `AppendPlan`, `LayerRows`, `AppendAddresses`. +//! Capture of the QSA index appends of a verifier window (row by row, or fused over the twelve layers for the commit) +//! and the host-side publish of mapped K/V prefixes from the append receipts. use super::original_verify_qsa_journal::{check_armed_window, image_addresses}; use super::{ diff --git a/crates/cuda-driver/src/qsa_verification_commit/verify_qsa_journal_index_image.rs b/crates/cuda-driver/src/qsa_prompt_index/resident_index/verification_commit/verify_qsa_journal_index_image.rs similarity index 100% rename from crates/cuda-driver/src/qsa_verification_commit/verify_qsa_journal_index_image.rs rename to crates/cuda-driver/src/qsa_prompt_index/resident_index/verification_commit/verify_qsa_journal_index_image.rs diff --git a/crates/cuda-driver/src/qsa_verification_commit/verify_qsa_journal_loan.rs b/crates/cuda-driver/src/qsa_prompt_index/resident_index/verification_commit/verify_qsa_journal_loan.rs similarity index 100% rename from crates/cuda-driver/src/qsa_verification_commit/verify_qsa_journal_loan.rs rename to crates/cuda-driver/src/qsa_prompt_index/resident_index/verification_commit/verify_qsa_journal_loan.rs diff --git a/crates/cuda-driver/src/qsa_verification_commit/verify_qsa_journal_publish_discard.rs b/crates/cuda-driver/src/qsa_prompt_index/resident_index/verification_commit/verify_qsa_journal_publish_discard.rs similarity index 97% rename from crates/cuda-driver/src/qsa_verification_commit/verify_qsa_journal_publish_discard.rs rename to crates/cuda-driver/src/qsa_prompt_index/resident_index/verification_commit/verify_qsa_journal_publish_discard.rs index 1f85ed17..9f3723fc 100644 --- a/crates/cuda-driver/src/qsa_verification_commit/verify_qsa_journal_publish_discard.rs +++ b/crates/cuda-driver/src/qsa_prompt_index/resident_index/verification_commit/verify_qsa_journal_publish_discard.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalVerifyQsaJournal`: `complete_commit`, `check_all_in_flight`, `publish_window_indices`, `publi... -//! Split out of `verification_commit` to keep its files under the line limit. +//! End of a verifier window for the QSA journal: complete_commit publishes the K/V and index halves together, +//! discard_window undoes a refused window from the begin snapshots (index images, PLE history), and ownership return. use super::original_verify_qsa_journal::check_armed_window; use super::{ diff --git a/crates/cuda-driver/src/qsa_verification_commit/verify_qsa_journal_rearm.rs b/crates/cuda-driver/src/qsa_prompt_index/resident_index/verification_commit/verify_qsa_journal_rearm.rs similarity index 100% rename from crates/cuda-driver/src/qsa_verification_commit/verify_qsa_journal_rearm.rs rename to crates/cuda-driver/src/qsa_prompt_index/resident_index/verification_commit/verify_qsa_journal_rearm.rs diff --git a/crates/cuda-driver/src/qsa_resident_index_program.rs b/crates/cuda-driver/src/qsa_prompt_index/resident_program.rs similarity index 61% rename from crates/cuda-driver/src/qsa_resident_index_program.rs rename to crates/cuda-driver/src/qsa_prompt_index/resident_program.rs index 81e725d7..5c15cad7 100644 --- a/crates/cuda-driver/src/qsa_resident_index_program.rs +++ b/crates/cuda-driver/src/qsa_prompt_index/resident_program.rs @@ -5,14 +5,9 @@ use super::{ QsaPromptIndexWorkspace, Result, combine, ffi, max_blocks, }; -#[path = "qsa_resident_index_program/arena_plan.rs"] mod arena_plan; -#[path = "qsa_resident_index_program/prefix_replay.rs"] mod prefix_replay; -#[path = "qsa_resident_index_program/qsa_prompt_index_workspace.rs"] mod qsa_prompt_index_workspace; -#[allow(unused_imports)] -use arena_plan::{ArenaCall, ArenaIo, ArenaPlan, LateLaunch, LateQueue}; +use arena_plan::{ArenaCall, ArenaIo, ArenaPlan, LateQueue}; pub(super) use prefix_replay::ReplayKeySpans; -#[allow(unused_imports)] use prefix_replay::launch_label; diff --git a/crates/cuda-driver/src/qsa_resident_index_program/arena_plan.rs b/crates/cuda-driver/src/qsa_prompt_index/resident_program/arena_plan.rs similarity index 100% rename from crates/cuda-driver/src/qsa_resident_index_program/arena_plan.rs rename to crates/cuda-driver/src/qsa_prompt_index/resident_program/arena_plan.rs diff --git a/crates/cuda-driver/src/qsa_resident_index_program/prefix_replay.rs b/crates/cuda-driver/src/qsa_prompt_index/resident_program/prefix_replay.rs similarity index 97% rename from crates/cuda-driver/src/qsa_resident_index_program/prefix_replay.rs rename to crates/cuda-driver/src/qsa_prompt_index/resident_program/prefix_replay.rs index 301ef25b..d91ed4c2 100644 --- a/crates/cuda-driver/src/qsa_resident_index_program/prefix_replay.rs +++ b/crates/cuda-driver/src/qsa_prompt_index/resident_program/prefix_replay.rs @@ -1,5 +1,5 @@ -//! Methods of `QsaPromptIndexWorkspace`: `replay_resident_prefix`, `replay_handles`, `upload_steps`, `check_replay` ... -//! Functions: `replay_steps`, `replay_commands`, `replay_append`, `launch_label` and 1 more. +//! Accepted-prefix replay of the resident QSA index: after a verifier window keeps only some rows, re-appends them +//! from the raw keys to the resident image with the decode-append kernel and finite scans, and labels the launches. use super::{ A, Arguments, CAP, DeviceBuffer, Error, Launch, NativeBatchWorkspace, QsaPromptIndexWorkspace, Result, combine, ffi, diff --git a/crates/cuda-driver/src/qsa_resident_index_program/qsa_prompt_index_workspace.rs b/crates/cuda-driver/src/qsa_prompt_index/resident_program/qsa_prompt_index_workspace.rs similarity index 97% rename from crates/cuda-driver/src/qsa_resident_index_program/qsa_prompt_index_workspace.rs rename to crates/cuda-driver/src/qsa_prompt_index/resident_program/qsa_prompt_index_workspace.rs index 46a62e85..ed7b87c2 100644 --- a/crates/cuda-driver/src/qsa_resident_index_program/qsa_prompt_index_workspace.rs +++ b/crates/cuda-driver/src/qsa_prompt_index/resident_program/qsa_prompt_index_workspace.rs @@ -1,5 +1,5 @@ -//! Methods of `QsaPromptIndexWorkspace`: `run_resident_arena`, `run_arena`, `submit_arena`, `arena_steps` and 7 more. -//! Functions: `late_label`. +//! Resident-arena run of the QSA prompt index program: uploads step words and positions, submits the recorded plan +//! (with the late kernels when due) on the batch stream, and checks the status words. use super::{ ArenaCall, ArenaIo, ArenaPlan, ArenaRows, CAP, CurrentGuard, Error, IndexProgramSpans, LateQueue, diff --git a/crates/cuda-driver/src/qsa_resident_scalar_index.rs b/crates/cuda-driver/src/qsa_prompt_index/resident_scalar_index.rs similarity index 100% rename from crates/cuda-driver/src/qsa_resident_scalar_index.rs rename to crates/cuda-driver/src/qsa_prompt_index/resident_scalar_index.rs diff --git a/crates/cuda-driver/src/qsa_resident_transfer.rs b/crates/cuda-driver/src/qsa_prompt_index/resident_transfer.rs similarity index 97% rename from crates/cuda-driver/src/qsa_resident_transfer.rs rename to crates/cuda-driver/src/qsa_prompt_index/resident_transfer.rs index c14c483f..dc421a67 100644 --- a/crates/cuda-driver/src/qsa_resident_transfer.rs +++ b/crates/cuda-driver/src/qsa_prompt_index/resident_transfer.rs @@ -2,7 +2,6 @@ //! No public address/range API. All source owners remain borrowed until drain. use crate::{Context, Error, NativeBatchWorkspace, Result, combine}; #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] -#[path = "qsa_resident_transfer/enabled.rs"] mod enabled; #[cfg(not(all( feature = "cuda-driver", diff --git a/crates/cuda-driver/src/qsa_resident_transfer/enabled.rs b/crates/cuda-driver/src/qsa_prompt_index/resident_transfer/enabled.rs similarity index 98% rename from crates/cuda-driver/src/qsa_resident_transfer/enabled.rs rename to crates/cuda-driver/src/qsa_prompt_index/resident_transfer/enabled.rs index bf474157..507c860d 100644 --- a/crates/cuda-driver/src/qsa_resident_transfer/enabled.rs +++ b/crates/cuda-driver/src/qsa_prompt_index/resident_transfer/enabled.rs @@ -1,5 +1,5 @@ -//! Methods of `Transfer`: `new`, `can_overlap`, `is_pending`, `begin` and 8 more. Implements `Drop for Transfer`. -//! Functions: `driver_code`, `poison_failed`, `check_ranges`, `load_side`. +//! Device-to-device copy engine of the resident QSA index (libcuda via dlopen): synchronous and fenced copies of +//! checkpoint ranges, and an optional side stream that overlaps the prior-KV prefix copy with the layer compute. use super::{Context, Error, NativeBatchWorkspace, Result, combine}; use std::ffi::c_void; diff --git a/crates/cuda-driver/src/qsa_prompt_kv.rs b/crates/cuda-driver/src/qsa_prompt_kv.rs index f858d1f7..2b559c0b 100644 --- a/crates/cuda-driver/src/qsa_prompt_kv.rs +++ b/crates/cuda-driver/src/qsa_prompt_kv.rs @@ -79,31 +79,21 @@ pub struct QsaPromptStage<'ctx> { failed: bool, } -#[path = "qsa_prompt_device_kv.rs"] mod device_kv; -#[path = "qsa_mapped_journal.rs"] mod mapped_journal; pub use mapped_journal::{OriginalQsaMappedAppend, OriginalQsaMappedJournal, OriginalQsaMappedPrefix}; -#[path = "qsa_resident_transport.rs"] mod resident_transport; pub use resident_transport::{OriginalQsaResidentTransport, set_qsa_prefetch_override}; mod offsets; -#[allow(unused_imports)] use offsets::admit; -#[allow(unused_imports)] use offsets::bytes_i32; -#[allow(unused_imports)] pub(crate) use offsets::checked; -#[allow(unused_imports)] use offsets::offsets; -#[allow(unused_imports)] use offsets::resident_runs; -#[allow(unused_imports)] use offsets::stage_runs; mod qsa_prompt_kv_drop; mod staged_append; -#[allow(unused_imports)] pub(crate) use qsa_prompt_kv_drop::read_range; diff --git a/crates/cuda-driver/src/qsa_prompt_device_kv.rs b/crates/cuda-driver/src/qsa_prompt_kv/device_kv.rs similarity index 100% rename from crates/cuda-driver/src/qsa_prompt_device_kv.rs rename to crates/cuda-driver/src/qsa_prompt_kv/device_kv.rs diff --git a/crates/cuda-driver/src/qsa_mapped_journal.rs b/crates/cuda-driver/src/qsa_prompt_kv/mapped_journal.rs similarity index 98% rename from crates/cuda-driver/src/qsa_mapped_journal.rs rename to crates/cuda-driver/src/qsa_prompt_kv/mapped_journal.rs index c1416bea..08bbdb5d 100644 --- a/crates/cuda-driver/src/qsa_mapped_journal.rs +++ b/crates/cuda-driver/src/qsa_prompt_kv/mapped_journal.rs @@ -245,7 +245,5 @@ mod parked_tests { } } -#[path = "qsa_mapped_journal/original_qsa_mapped_journal.rs"] mod original_qsa_mapped_journal; -#[path = "qsa_mapped_journal/original_qsa_mapped_prefix.rs"] mod original_qsa_mapped_prefix; diff --git a/crates/cuda-driver/src/qsa_mapped_journal/original_qsa_mapped_journal.rs b/crates/cuda-driver/src/qsa_prompt_kv/mapped_journal/original_qsa_mapped_journal.rs similarity index 98% rename from crates/cuda-driver/src/qsa_mapped_journal/original_qsa_mapped_journal.rs rename to crates/cuda-driver/src/qsa_prompt_kv/mapped_journal/original_qsa_mapped_journal.rs index 79d9a4db..d1c14349 100644 --- a/crates/cuda-driver/src/qsa_mapped_journal/original_qsa_mapped_journal.rs +++ b/crates/cuda-driver/src/qsa_prompt_kv/mapped_journal/original_qsa_mapped_journal.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalQsaMappedJournal`: `append_resident_decode`, `completed_kv_handles`, `admit_append`, `reject_... -//! Defines `AppendPlan`. +//! Resident append of the Original QSA mapped K/V journal for decode: admits new cells, guards, quantizes and writes +//! them to the resident pools and host copy; also the prefix-cache export/import of whole host pages. use super::{ Arg, Arguments, Cell, Context, Coverage, Error, LaunchGeometry, NativeBatchWorkspace, OriginalQsaMappedAppend, diff --git a/crates/cuda-driver/src/qsa_mapped_journal/original_qsa_mapped_prefix.rs b/crates/cuda-driver/src/qsa_prompt_kv/mapped_journal/original_qsa_mapped_prefix.rs similarity index 53% rename from crates/cuda-driver/src/qsa_mapped_journal/original_qsa_mapped_prefix.rs rename to crates/cuda-driver/src/qsa_prompt_kv/mapped_journal/original_qsa_mapped_prefix.rs index b5f19edb..69c31d14 100644 --- a/crates/cuda-driver/src/qsa_mapped_journal/original_qsa_mapped_prefix.rs +++ b/crates/cuda-driver/src/qsa_prompt_kv/mapped_journal/original_qsa_mapped_prefix.rs @@ -1,5 +1,5 @@ -//! Groups the submodules `qsa_mapped_journal_append_and_resolve`, `qsa_mapped_journal_prefix_and_prefetch`. -//! Split out of `mapped_journal` to keep its files under the line limit. +//! Module root of the mapped K/V journal pieces that deal with arena appends and with prefix tracking; it only +//! imports the shared names and declares the two submodules. use super::{ Cell, Context, Coverage, DeviceBuffer, Error, NativeBatchWorkspace, OriginalDeviceGrRead, OriginalQsaMappedAppend, @@ -7,7 +7,5 @@ use super::{ QsaPromptKv, Rc, Result, SelectedRows, checked, stage_runs, }; -#[path = "original_qsa_mapped_prefix/qsa_mapped_journal_append_and_resolve.rs"] mod qsa_mapped_journal_append_and_resolve; -#[path = "original_qsa_mapped_prefix/qsa_mapped_journal_prefix_and_prefetch.rs"] mod qsa_mapped_journal_prefix_and_prefetch; diff --git a/crates/cuda-driver/src/qsa_mapped_journal/original_qsa_mapped_prefix/qsa_mapped_journal_append_and_resolve.rs b/crates/cuda-driver/src/qsa_prompt_kv/mapped_journal/original_qsa_mapped_prefix/qsa_mapped_journal_append_and_resolve.rs similarity index 97% rename from crates/cuda-driver/src/qsa_mapped_journal/original_qsa_mapped_prefix/qsa_mapped_journal_append_and_resolve.rs rename to crates/cuda-driver/src/qsa_prompt_kv/mapped_journal/original_qsa_mapped_prefix/qsa_mapped_journal_append_and_resolve.rs index f69a3e6d..89f85f54 100644 --- a/crates/cuda-driver/src/qsa_mapped_journal/original_qsa_mapped_prefix/qsa_mapped_journal_append_and_resolve.rs +++ b/crates/cuda-driver/src/qsa_prompt_kv/mapped_journal/original_qsa_mapped_prefix/qsa_mapped_journal_append_and_resolve.rs @@ -1,7 +1,6 @@ -//! Methods of `OriginalQsaMappedJournal`: `append_resident_arena`, `arena_plan`, `stage_arena`, `stage_prefix_from_h... -//! Split out of `original_qsa_mapped_prefix` to keep its files under the line limit. +//! Arena-chunk side of the mapped K/V journal: prompt append with the host-to-stage prefix copy, the streamed-KV +//! resolver (reset, resolve, window addresses) and alias checks. -#[allow(unused_imports)] use super::super::original_qsa_mapped_journal::AppendPlan; use super::{ DeviceBuffer, Error, NativeBatchWorkspace, OriginalQsaMappedAppend, OriginalQsaMappedJournal, diff --git a/crates/cuda-driver/src/qsa_mapped_journal/original_qsa_mapped_prefix/qsa_mapped_journal_prefix_and_prefetch.rs b/crates/cuda-driver/src/qsa_prompt_kv/mapped_journal/original_qsa_mapped_prefix/qsa_mapped_journal_prefix_and_prefetch.rs similarity index 97% rename from crates/cuda-driver/src/qsa_mapped_journal/original_qsa_mapped_prefix/qsa_mapped_journal_prefix_and_prefetch.rs rename to crates/cuda-driver/src/qsa_prompt_kv/mapped_journal/original_qsa_mapped_prefix/qsa_mapped_journal_prefix_and_prefetch.rs index 75d572a0..9041c681 100644 --- a/crates/cuda-driver/src/qsa_mapped_journal/original_qsa_mapped_prefix/qsa_mapped_journal_prefix_and_prefetch.rs +++ b/crates/cuda-driver/src/qsa_prompt_kv/mapped_journal/original_qsa_mapped_prefix/qsa_mapped_journal_prefix_and_prefetch.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalQsaMappedPrefix`: `next_position`, `owner_id`, `validate_retained`. -//! Methods of `OriginalQsaMappedAppend`: `rows`, `first_position`, `prefix_after`, `final_prefix`. +//! Prefix lineage of the mapped K/V journal: prefix and append receipts, rollback, accept, reset, window publication, +//! conversion from QsaPromptKv, close, and the side-stream prefetch of the layer prefix copy. use super::{ Cell, Context, Coverage, Error, NativeBatchWorkspace, OriginalDeviceGrRead, OriginalQsaMappedAppend, diff --git a/crates/cuda-driver/src/qsa_prompt_kv/offsets.rs b/crates/cuda-driver/src/qsa_prompt_kv/offsets.rs index 22c0b2f4..3f594c39 100644 --- a/crates/cuda-driver/src/qsa_prompt_kv/offsets.rs +++ b/crates/cuda-driver/src/qsa_prompt_kv/offsets.rs @@ -1,5 +1,5 @@ -//! Methods of `QsaKvInputs`: `new`. Methods of `QsaKvOwnerId`: `same_owner`. -//! Functions: `offsets`, `stage_runs`, `resident_runs`, `page_payload_eq` and 3 more. +//! Layout and identity helpers of QSA prompt K/V: run offsets and sizes of the mapped pools, the validated K/V inputs, +//! snapshot and owner-id accessors, the device Pools owner, size admission and the Context constructors. use super::{ CompletedQsaKvAppend, Context, DeviceBuffer, Error, Origin, Page, Pools, QSA_PROMPT_HOST_PAGE_BYTES, QsaKvInputs, diff --git a/crates/cuda-driver/src/qsa_prompt_kv/qsa_prompt_kv_drop.rs b/crates/cuda-driver/src/qsa_prompt_kv/qsa_prompt_kv_drop.rs index e9bd652b..1b78aa19 100644 --- a/crates/cuda-driver/src/qsa_prompt_kv/qsa_prompt_kv_drop.rs +++ b/crates/cuda-driver/src/qsa_prompt_kv/qsa_prompt_kv_drop.rs @@ -1,5 +1,5 @@ -//! Methods of `QsaPromptStage`: `new`, `allocate_all`, `allocated_bytes`, `is_failed` and 11 more. -//! Implements `Drop for QsaPromptKv`, `Drop for QsaPromptStage`. Functions: `read_range`. +//! The QsaPromptStage owner: pools, status word and page table of the staging area, snapshot restore, kernel runs on +//! the workspace stream and close; also the Drop of the QSA K/V owner and its range readback. use super::{ Arguments, Context, DeviceBuffer, Error, LaunchGeometry, NativeBatchWorkspace, PAGE, Pools, QsaKvSnapshot, diff --git a/crates/cuda-driver/src/qsa_resident_transport.rs b/crates/cuda-driver/src/qsa_prompt_kv/resident_transport.rs similarity index 99% rename from crates/cuda-driver/src/qsa_resident_transport.rs rename to crates/cuda-driver/src/qsa_prompt_kv/resident_transport.rs index 7e0f39be..643b9d4b 100644 --- a/crates/cuda-driver/src/qsa_resident_transport.rs +++ b/crates/cuda-driver/src/qsa_prompt_kv/resident_transport.rs @@ -40,7 +40,7 @@ impl<'ctx> OriginalQsaResidentTransport<'ctx> { e })?; let load = Module::load( - include_bytes!("qsa_prompt_kv.ptx"), + include_bytes!("../qsa_prompt_kv.ptx"), &[c"leleka_qsa_kv_guard", c"leleka_qsa_kv_append", c"leleka_qsa_kv_scale_guard"], ); let pop = g.finish(); diff --git a/crates/cuda-driver/src/qsa_prompt_kv/staged_append.rs b/crates/cuda-driver/src/qsa_prompt_kv/staged_append.rs index a9e7b739..b592f85f 100644 --- a/crates/cuda-driver/src/qsa_prompt_kv/staged_append.rs +++ b/crates/cuda-driver/src/qsa_prompt_kv/staged_append.rs @@ -1,5 +1,5 @@ -//! Defines `StagedAppend`. -//! Split out of `qsa_prompt_kv` to keep its files under the line limit. +//! Small carrier type of an append: the stage one bounded K/V append runs on and the prior snapshot it extends; +//! the append logic is in the submodules. use super::{ Arg, Arguments, CompletedQsaKvAppend, Context, DeviceBuffer, Error, LaunchGeometry, MappedAllocation, diff --git a/crates/cuda-driver/src/qsa_prompt_kv/staged_append/qsa_prompt_kv_append_bounded_close.rs b/crates/cuda-driver/src/qsa_prompt_kv/staged_append/qsa_prompt_kv_append_bounded_close.rs index 6e500c56..0e72c0da 100644 --- a/crates/cuda-driver/src/qsa_prompt_kv/staged_append/qsa_prompt_kv_append_bounded_close.rs +++ b/crates/cuda-driver/src/qsa_prompt_kv/staged_append/qsa_prompt_kv_append_bounded_close.rs @@ -1,5 +1,5 @@ -//! Methods of `QsaPromptKv`: `append_bounded`, `close`, `close_inner`, `close_mapped` and 1 more. -//! Split out of `staged_append` to keep its files under the line limit. +//! Bounded append of QSA K/V through a stage, and the close of the owner including the pinned host mapping, which is +//! retained instead of freed when a poisoned context cannot prove DMA completion. use super::{ CompletedQsaKvAppend, Error, MappedAllocation, NativeBatchWorkspace, QsaKvInputs, QsaPromptKv, Result, diff --git a/crates/cuda-driver/src/qsa_prompt_kv/staged_append/qsa_prompt_kv_bring_up.rs b/crates/cuda-driver/src/qsa_prompt_kv/staged_append/qsa_prompt_kv_bring_up.rs index 2f84694f..dfb3cece 100644 --- a/crates/cuda-driver/src/qsa_prompt_kv/staged_append/qsa_prompt_kv_bring_up.rs +++ b/crates/cuda-driver/src/qsa_prompt_kv/staged_append/qsa_prompt_kv_bring_up.rs @@ -1,5 +1,5 @@ -//! Methods of `QsaPromptKv`: `new`, `init_resources`, `map_host`, `empty_snapshot` and 16 more. -//! Functions: `check_host_memory`. +//! Bring-up of the QsaPromptKv owner: host memory check, pinned mapped host area, snapshot validation and restore, +//! selection admission and the append entries. use super::{ CompletedQsaKvAppend, Context, DeviceBuffer, Error, MappedAllocation, NativeBatchWorkspace, Origin, PAGE, diff --git a/crates/cuda-driver/src/qsa_selected_kv.rs b/crates/cuda-driver/src/qsa_selected_kv.rs index 9740adcb..98af2538 100644 --- a/crates/cuda-driver/src/qsa_selected_kv.rs +++ b/crates/cuda-driver/src/qsa_selected_kv.rs @@ -49,11 +49,8 @@ pub struct QsaSelectedKvProducts<'lease, 'ctx> { mod selected_kv_installed; mod asset; -#[allow(unused_imports)] pub(crate) use asset::asset; mod qsa_selected_kv_attend_io; mod qsa_selected_kv_workspace; -#[allow(unused_imports)] use qsa_selected_kv_attend_io::owned_bytes; -#[allow(unused_imports)] use qsa_selected_kv_attend_io::slot_bytes; diff --git a/crates/cuda-driver/src/qsa_selected_kv/asset.rs b/crates/cuda-driver/src/qsa_selected_kv/asset.rs index 70ad36a6..fdd94dd6 100644 --- a/crates/cuda-driver/src/qsa_selected_kv/asset.rs +++ b/crates/cuda-driver/src/qsa_selected_kv/asset.rs @@ -1,5 +1,5 @@ -//! Methods of `Context`: `qsa_selected_kv_workspace`. Functions: `asset`. -//! Split out of `qsa_selected_kv` to keep its files under the line limit. +//! Sealed PTX asset check of the QSA selected-K/V workspace (pinned length, digest, NUL-terminated ASCII) and the +//! Context constructor of the workspace. use super::{Context, Error, PTX, PTX_BYTES, PTX_SHA, QsaSelectedKvWorkspace, Result, qwen_ffi}; diff --git a/crates/cuda-driver/src/qsa_selected_kv/qsa_selected_kv_attend_io.rs b/crates/cuda-driver/src/qsa_selected_kv/qsa_selected_kv_attend_io.rs index b3223efd..df496f9d 100644 --- a/crates/cuda-driver/src/qsa_selected_kv/qsa_selected_kv_attend_io.rs +++ b/crates/cuda-driver/src/qsa_selected_kv/qsa_selected_kv_attend_io.rs @@ -1,5 +1,5 @@ -//! Methods of `QsaSelectedKvProducts`: `width`, `generation`, `attend`. -//! Methods of `QsaSelectedKvWorkspace`: `attend_io`, `check_attend_buffers`, `launch_attend`. +//! Attend side of the QSA selected-K/V workspace: the products handle that attends one query over the gathered +//! selected cells, the alias and size checks of its query/output buffers, the launch, and the workspace Drop. use super::{ CELL, DeviceBuffer, Error, Operation, PACKED, QsaSelectedKvProducts, QsaSelectedKvWorkspace, Result, SIZES, diff --git a/crates/cuda-driver/src/qsa_selected_kv/qsa_selected_kv_workspace.rs b/crates/cuda-driver/src/qsa_selected_kv/qsa_selected_kv_workspace.rs index b70987e8..5fbdac48 100644 --- a/crates/cuda-driver/src/qsa_selected_kv/qsa_selected_kv_workspace.rs +++ b/crates/cuda-driver/src/qsa_selected_kv/qsa_selected_kv_workspace.rs @@ -1,5 +1,5 @@ -//! Methods of `QsaSelectedKvWorkspace`: `new`, `admit_new`, `load`, `load_modules` and 12 more. -//! Functions: `check_shapes`, `check_finite`, `release_buffer`, `unload_module`. Defines `SelectedLaunch`. +//! The QsaSelectedKvWorkspace owner: sealed asset admission, buffers and modules, validation of miss and selection +//! slots, the prepare step that scatters missed rows into cells and gathers the selection, and close. use super::{ CELL, CELLS, Cell, Context, DeviceBuffer, Error, LAYERS, MAP, Operation, PACKED, QsaKvMisses, diff --git a/crates/cuda-driver/src/qwen_dispatch.rs b/crates/cuda-driver/src/qwen_dispatch.rs index 80ebc0dc..578112d1 100644 --- a/crates/cuda-driver/src/qwen_dispatch.rs +++ b/crates/cuda-driver/src/qwen_dispatch.rs @@ -6,7 +6,6 @@ use crate::{ }; use std::{cell::Cell, rc::Rc}; pub(crate) mod fixed_operands; -#[path = "gr_batch_read.rs"] pub(crate) mod gr_batch_read; pub(super) struct Cache { @@ -36,7 +35,6 @@ struct Admission<'asset> { #[cfg(test)] mod tests; -#[path = "batch_gr_preview.rs"] pub(crate) mod batch_gr_preview; #[cfg(all(test, any(target_os = "linux", target_os = "windows"), target_arch = "x86_64", feature = "cuda-driver"))] @@ -45,71 +43,52 @@ mod queued_gr_installed; #[cfg(all(test, any(target_os = "linux", target_os = "windows"), target_arch = "x86_64", feature = "cuda-driver"))] mod gdn_products_installed; -#[path = "qwen_shared_tail.rs"] pub(crate) mod qwen_shared_tail; // Additive closed MTP input prefix; original dispatch stays byte-exact. -#[path = "mtp_input_workspace.rs"] pub(crate) mod mtp_input_workspace; // Additive closed GDN row stage queue; original GDN dispatch stays byte-exact. -#[path = "gdn_closed_queue.rs"] pub(crate) mod gdn_closed_queue; // Closed batched GDN program of the Strata PREFILL path (option B); needs the // Root-built PTX images and pins, so it is wired in last (see gdn_native_batch.rs). #[cfg(all(any(target_os = "linux", target_os = "windows"), target_arch = "x86_64", feature = "cuda-driver"))] -#[path = "gdn_native_batch.rs"] pub(crate) mod gdn_native_batch; // Closed batched MoE router + shared-expert program of the Strata PREFILL path; needs the Root-built PTX image and // pin, so it is wired in last (see moe_prefill_batch.rs). #[cfg(all(any(target_os = "linux", target_os = "windows"), target_arch = "x86_64", feature = "cuda-driver"))] -#[path = "moe_prefill_batch.rs"] pub(crate) mod moe_prefill_batch; // Closed single-token fused GDN program of the Original Strata engine (default `no_fused_gdn = false`); needs the // Root-built PTX image and pin, so it is wired in last (see gdn_fused_t1.rs). #[cfg(all(any(target_os = "linux", target_os = "windows"), target_arch = "x86_64", feature = "cuda-driver"))] -#[path = "gdn_fused_t1.rs"] pub(crate) mod gdn_fused_t1; #[cfg(all(any(target_os = "linux", target_os = "windows"), target_arch = "x86_64", feature = "cuda-driver"))] -#[path = "gr_batch_inject_workspace.rs"] pub(crate) mod gr_batch_inject_workspace; // Closed original PLE whole-role queue; old entry bodies remain unchanged. -#[path = "ple_closed_queue.rs"] pub(crate) mod ple_closed_queue; -#[path = "gr_native_batch.rs"] pub(crate) mod gr_native_batch; mod cache; -#[allow(unused_imports)] use cache::execute; -#[allow(unused_imports)] use cache::prepare_pair; -#[allow(unused_imports)] use cache::registered; -#[allow(unused_imports)] use cache::restore; mod prepare_gr_read_set; -#[allow(unused_imports)] +#[cfg(test)] use prepare_gr_read_set::native_span; #[cfg(all(any(target_os = "linux", target_os = "windows"), target_arch = "x86_64", feature = "cuda-driver"))] -#[allow(unused_imports)] use prepare_gr_read_set::prepare_gr_read_set; #[cfg(test)] -#[allow(unused_imports)] use prepare_gr_read_set::ranges; -#[allow(unused_imports)] use prepare_gr_read_set::ranges_layout; -#[allow(unused_imports)] use prepare_gr_read_set::unload; mod admission; -#[allow(unused_imports)] use admission::admission; -#[allow(unused_imports)] use admission::owned_mtp_scratch; mod context; diff --git a/crates/cuda-driver/src/qwen_dispatch/admission.rs b/crates/cuda-driver/src/qwen_dispatch/admission.rs index 8b99b939..76e8f432 100644 --- a/crates/cuda-driver/src/qwen_dispatch/admission.rs +++ b/crates/cuda-driver/src/qwen_dispatch/admission.rs @@ -1,5 +1,5 @@ -//! Functions: `admission`, `check_owned`, `admitted_layout`, `buffer_handles` and 1 more. -//! Split out of `qwen_dispatch` to keep its files under the line limit. +//! Request admission of the Qwen closed-kernel dispatch: checks that every operand belongs to the context and is live, +//! validates operand count, epsilon and layout against the sealed asset, and allocates the owned MTP scratch buffers. use super::{ Admission, Asset, Backend, Context, DeviceBuffer, Error, Operation, Result, combine, ffi, qwen_ffi, ranges_layout, diff --git a/crates/cuda-driver/src/batch_gr_preview.rs b/crates/cuda-driver/src/qwen_dispatch/batch_gr_preview.rs similarity index 99% rename from crates/cuda-driver/src/batch_gr_preview.rs rename to crates/cuda-driver/src/qwen_dispatch/batch_gr_preview.rs index 13cebb44..982bcfab 100644 --- a/crates/cuda-driver/src/batch_gr_preview.rs +++ b/crates/cuda-driver/src/qwen_dispatch/batch_gr_preview.rs @@ -2,7 +2,6 @@ //! Numerical experiment only; no production asset admission or session commit. use super::{Context, DeviceBuffer, Error, Operation, Result, qwen_ffi}; // used only with some cargo features or targets of this crate -#[allow(unused_imports)] use super::{Arguments, Backend, combine, ffi, ranges_layout}; /// The four device buffers of one batched residual-inject launch. pub struct GrInjectBuffers<'a, 'b> { diff --git a/crates/cuda-driver/src/qwen_dispatch/cache.rs b/crates/cuda-driver/src/qwen_dispatch/cache.rs index a1efdfc5..74c26727 100644 --- a/crates/cuda-driver/src/qwen_dispatch/cache.rs +++ b/crates/cuda-driver/src/qwen_dispatch/cache.rs @@ -1,5 +1,5 @@ -//! Methods of `Cache`: `new`. Implements `Backend for Context`. -//! Functions: `restore`, `registered`, `execute`, `prepare_pair` and 3 more. +//! The kernel cache of the Qwen dispatch and its Backend implementation for Context: lazy load and resolve of fixed +//! kernels, single and paired registration with unload on failure, and execution under the context guard. use super::{Arguments, Asset, Backend, Cache, Cell, Context, Error, FixedKernel, Operation, Rc, Result, combine, ffi}; diff --git a/crates/cuda-driver/src/qwen_dispatch/context.rs b/crates/cuda-driver/src/qwen_dispatch/context.rs index f40fb0a2..1c56787b 100644 --- a/crates/cuda-driver/src/qwen_dispatch/context.rs +++ b/crates/cuda-driver/src/qwen_dispatch/context.rs @@ -1,5 +1,5 @@ -//! Groups the submodules `context_gr_gate_mean_inject`, `gdn_ple_fixed_kernels`, `gdn_step_kernels` and 4 more. -//! Split out of `qwen_dispatch` to keep its files under the line limit. +//! The Context side of qwen_dispatch: groups the fixed-kernel call families (GDN/PLE, GDN step, GR read chain, +//! MTP dense attention, MTP fixed kernels, QSA kernels) and re-uses the dispatch types of the parent. use super::{ Admission, Arguments, Asset, Backend, Context, DeviceBuffer, Error, FixedKernel, Operation, Result, admission, @@ -8,17 +8,10 @@ use super::{ }; #[cfg(all(any(target_os = "linux", target_os = "windows"), target_arch = "x86_64", feature = "cuda-driver"))] -#[path = "context/context_gr_gate_mean_inject.rs"] mod context_gr_gate_mean_inject; -#[path = "context/gdn_ple_fixed_kernels.rs"] mod gdn_ple_fixed_kernels; -#[path = "context/gdn_step_kernels.rs"] mod gdn_step_kernels; -#[path = "context/gr_read_chain.rs"] mod gr_read_chain; -#[path = "context/mtp_dense_attention.rs"] mod mtp_dense_attention; -#[path = "context/mtp_fixed_kernels.rs"] mod mtp_fixed_kernels; -#[path = "context/qsa_fixed_kernels.rs"] mod qsa_fixed_kernels; diff --git a/crates/cuda-driver/src/qwen_dispatch/context/context_gr_gate_mean_inject.rs b/crates/cuda-driver/src/qwen_dispatch/context/context_gr_gate_mean_inject.rs index 96568806..9f8ddc6c 100644 --- a/crates/cuda-driver/src/qwen_dispatch/context/context_gr_gate_mean_inject.rs +++ b/crates/cuda-driver/src/qwen_dispatch/context/context_gr_gate_mean_inject.rs @@ -1,5 +1,5 @@ -//! Methods of `Context`: `gr_gate_mean_layer_fused_f32`, `gr_gate_mean_final_unfused_f32`, `gr_inject_residual_f32`,... -//! Split out of `context` to keep its files under the line limit. +//! Context entry points for the GR gate-mean (layer fused, final unfused) and residual-inject Qwen kernels; each +//! validates its F32 operands and dispatches through qwen_call. use super::{Context, DeviceBuffer, Operation, Result}; diff --git a/crates/cuda-driver/src/qwen_dispatch/context/gdn_ple_fixed_kernels.rs b/crates/cuda-driver/src/qwen_dispatch/context/gdn_ple_fixed_kernels.rs index 92381e23..382b8ace 100644 --- a/crates/cuda-driver/src/qwen_dispatch/context/gdn_ple_fixed_kernels.rs +++ b/crates/cuda-driver/src/qwen_dispatch/context/gdn_ple_fixed_kernels.rs @@ -1,5 +1,5 @@ -//! Methods of `Context`: `qsa_block_topk`, `qsa_attend`, `qsa_gate_f32`, `moe_swiglu_f32` and 15 more. -//! Split out of `context` to keep its files under the line limit. +//! Context entry points for the fixed Qwen kernels of QSA (block top-k, attend, gate), MoE (SwiGLU, shared scalar, +//! combine), PLE and GDN steps; thin typed wrappers that hand their buffers to qwen_call. use super::fixed_operands::{GdnConvResult, GdnGates, GdnQkv, GdnStepResult, PleConvResult, QsaPackedKv}; use super::{Context, DeviceBuffer, Operation, Result}; diff --git a/crates/cuda-driver/src/qwen_dispatch/context/gdn_step_kernels.rs b/crates/cuda-driver/src/qwen_dispatch/context/gdn_step_kernels.rs index cf11276b..fd716833 100644 --- a/crates/cuda-driver/src/qwen_dispatch/context/gdn_step_kernels.rs +++ b/crates/cuda-driver/src/qwen_dispatch/context/gdn_step_kernels.rs @@ -1,5 +1,5 @@ -//! Methods of `Context`: `gdn_step_from_products_f32`, `admit_gdn_step`, `gdn_out_norm_f32`, `qwen_route_top10` and ... -//! Split out of `context` to keep its files under the line limit. +//! Context entry points for the fixed GDN step, GDN output norm, top-10 expert router and BF16 projection kernels. +//! Also holds the shared qwen_call admission-and-launch helper and the unload of the Qwen kernel set. use super::fixed_operands::{GdnGates, GdnOutNormInput, GdnStepProducts, GdnStepResult}; use super::{ diff --git a/crates/cuda-driver/src/qwen_dispatch/context/gr_read_chain.rs b/crates/cuda-driver/src/qwen_dispatch/context/gr_read_chain.rs index 9809f139..ebc85799 100644 --- a/crates/cuda-driver/src/qwen_dispatch/context/gr_read_chain.rs +++ b/crates/cuda-driver/src/qwen_dispatch/context/gr_read_chain.rs @@ -1,12 +1,11 @@ -//! Methods of `GrChain`: `new`. -//! Methods of `Context`: `gr_read_chain_queued`, `admit_gr_read`, `gr_stage`, `gr_run_chain` and 8 more. +//! The GR read chain: five fixed stages (norm, down, down-silu, up, layer gate) plus a finite guard, run on one stream +//! with a single completion fence; cross-stage alias checks live here. Also the single-stage GR projection/norm calls. use super::fixed_operands::{GrReadInputs, GrReadOutputs}; use super::{ Admission, Asset, Context, DeviceBuffer, Error, Operation, Result, admission, ffi, prepare_gr_read_set, qwen_ffi, }; // used only with some cargo features or targets of this crate -#[allow(unused_imports)] use super::{Arguments, FixedKernel, combine}; #[cfg(all(any(target_os = "linux", target_os = "windows"), target_arch = "x86_64", feature = "cuda-driver"))] diff --git a/crates/cuda-driver/src/qwen_dispatch/context/mtp_dense_attention.rs b/crates/cuda-driver/src/qwen_dispatch/context/mtp_dense_attention.rs index 9dd77502..c670e124 100644 --- a/crates/cuda-driver/src/qwen_dispatch/context/mtp_dense_attention.rs +++ b/crates/cuda-driver/src/qwen_dispatch/context/mtp_dense_attention.rs @@ -1,5 +1,5 @@ -//! Methods of `Context`: `mtp_dense_attend_f16`, `mtp_dense_attend_ring_f16`, `dense_plan`, `check_dense_buffer` and... -//! Functions: `dense_admission`, `dense_clear`, `ring_active`. Defines `DensePlan`. +//! Closed causal dense attention of the MTP head over FP16 K/V (plain or ring window): input sizing and alias checks, +//! accumulator/max/sum scratch, and the chunk-then-merge launch pair. use super::fixed_operands::{MtpDenseKv, MtpRingWindow}; use super::{ diff --git a/crates/cuda-driver/src/qwen_dispatch/context/mtp_fixed_kernels.rs b/crates/cuda-driver/src/qwen_dispatch/context/mtp_fixed_kernels.rs index 2f41c504..3618fa22 100644 --- a/crates/cuda-driver/src/qwen_dispatch/context/mtp_fixed_kernels.rs +++ b/crates/cuda-driver/src/qwen_dispatch/context/mtp_fixed_kernels.rs @@ -1,7 +1,6 @@ -//! Methods of `Context`: `mtp_gr_attention_down`, `mtp_gr_attention_up`, `mtp_gr_mlp_down`, `mtp_gr_mlp_up` and 11 m... -//! Split out of `context` to keep its files under the line limit. +//! Context entry points for the fixed MTP kernels: GR attention/MLP down and up passes, scaled quantization, +//! S2 expert tiles and full banks, SwiGLU, embedding and hidden norms, broadcast. No caller geometry is exposed. -#[allow(unused_imports)] use super::fixed_operands::{ MtpGrMlpOutputs, MtpGrMlpResidual, MtpGrProducts, MtpGrWeights, MtpQuantizedInput, MtpS2SelectedExpert, MtpS2TileWeights, diff --git a/crates/cuda-driver/src/qwen_dispatch/context/qsa_fixed_kernels.rs b/crates/cuda-driver/src/qwen_dispatch/context/qsa_fixed_kernels.rs index c6eee457..64b2eb65 100644 --- a/crates/cuda-driver/src/qwen_dispatch/context/qsa_fixed_kernels.rs +++ b/crates/cuda-driver/src/qwen_dispatch/context/qsa_fixed_kernels.rs @@ -1,5 +1,5 @@ -//! Methods of `Context`: `kar_ple_call`, `kar_ple_scatter`, `kar_ple_decode`, `qsa_call` and 11 more. -//! Split out of `context` to keep its files under the line limit. +//! Context entry points for the closed QSA attention kernels (q gate split, norms, ropes, index append, kv pack, +//! block scores) and the experimental PLE row-cache scatter and decode; unqualified assets refuse before mutation. use super::fixed_operands::{QsaIndexAppendSource, QsaPooledImage}; use super::{Admission, Arguments, Context, DeviceBuffer, Error, Operation, Result, admission, execute, qwen_ffi}; diff --git a/crates/cuda-driver/src/gdn_closed_queue.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_closed_queue.rs similarity index 97% rename from crates/cuda-driver/src/gdn_closed_queue.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_closed_queue.rs index 66c0d76b..4421fed3 100644 --- a/crates/cuda-driver/src/gdn_closed_queue.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gdn_closed_queue.rs @@ -254,18 +254,11 @@ mod tests { } #[cfg(all(test, feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_arch = "x86_64"))] -#[path = "gdn_closed_queue_gpu.rs"] mod gpu; -#[path = "gdn_closed_queue/gdn_queue_stage.rs"] mod gdn_queue_stage; -#[allow(unused_imports)] use gdn_queue_stage::column_row_offset; -#[allow(unused_imports)] use gdn_queue_stage::decode_statuses; -#[path = "gdn_closed_queue/gdn_row_prefix.rs"] mod gdn_row_prefix; -#[path = "gdn_closed_queue/gdn_row_queue.rs"] mod gdn_row_queue; -#[allow(unused_imports)] use gdn_row_queue::staging; diff --git a/crates/cuda-driver/src/gdn_closed_queue/gdn_queue_stage.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_closed_queue/gdn_queue_stage.rs similarity index 97% rename from crates/cuda-driver/src/gdn_closed_queue/gdn_queue_stage.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_closed_queue/gdn_queue_stage.rs index 98d5d939..39547bc1 100644 --- a/crates/cuda-driver/src/gdn_closed_queue/gdn_queue_stage.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gdn_closed_queue/gdn_queue_stage.rs @@ -1,5 +1,5 @@ -//! Methods of `GdnQueueStage`: `words`, `slot`. Methods of `Step`: `next`. -//! Functions: `decode_statuses`, `column_row_offset`. +//! Vocabulary and lifecycle of the GDN row queue: finite-scan stage sizes, program step order, status-word decoding, +//! batched QKV row offsets, the completion result, and opening the queue (status buffer, six kernels). use super::{ Context, Error, GdnQueueStage, GdnRowCompletion, GdnRowPrefix, GdnRowQueue, Kernels, MAX_COLUMN_ROWS, OPS, diff --git a/crates/cuda-driver/src/gdn_closed_queue/gdn_row_prefix.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_closed_queue/gdn_row_prefix.rs similarity index 60% rename from crates/cuda-driver/src/gdn_closed_queue/gdn_row_prefix.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_closed_queue/gdn_row_prefix.rs index e3237a7b..b3a4669f 100644 --- a/crates/cuda-driver/src/gdn_closed_queue/gdn_row_prefix.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gdn_closed_queue/gdn_row_prefix.rs @@ -1,5 +1,5 @@ -//! Groups the submodules `convolution_stages`, `gdn_row_prefix_fenced_drain`, `recurrence_stages`. -//! Split out of `gdn_closed_queue` to keep its files under the line limit. +//! The GDN row prefix: an owned, ordered program of kernel launches and finite scans for one GDN row, built from +//! convolution/recurrence stages and executed by the fenced drain; the submodules split it by program phase. use super::{ Admission, Arguments, BETA, CONV, Command, DeviceBuffer, Drained, Error, GATE, GdnConvBuffers, GdnOutNormBuffers, @@ -8,9 +8,6 @@ use super::{ decode_statuses, ffi, qwen_ffi, ranges_layout, staging, }; -#[path = "gdn_row_prefix/convolution_stages.rs"] mod convolution_stages; -#[path = "gdn_row_prefix/gdn_row_prefix_fenced_drain.rs"] mod gdn_row_prefix_fenced_drain; -#[path = "gdn_row_prefix/recurrence_stages.rs"] mod recurrence_stages; diff --git a/crates/cuda-driver/src/gdn_closed_queue/gdn_row_prefix/convolution_stages.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_closed_queue/gdn_row_prefix/convolution_stages.rs similarity index 97% rename from crates/cuda-driver/src/gdn_closed_queue/gdn_row_prefix/convolution_stages.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_closed_queue/gdn_row_prefix/convolution_stages.rs index 23604733..378bcf15 100644 --- a/crates/cuda-driver/src/gdn_closed_queue/gdn_row_prefix/convolution_stages.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gdn_closed_queue/gdn_row_prefix/convolution_stages.rs @@ -1,5 +1,5 @@ -//! Methods of `GdnRowPrefix`: `ready`, `latch`, `handle_of`, `same` and 11 more. -//! Split out of `gdn_row_prefix` to keep its files under the line limit. +//! First stages of the GDN row program: step-order and operand-identity checks, the push_stage/push_scan helpers, +//! the QKV, alpha and raw-beta scans, and the convolution plus SiLU (own QKV row or a row of a retained columns owner). use super::{ Admission, Arguments, CONV, Command, DeviceBuffer, Error, GdnConvBuffers, GdnQueueStage, GdnRowPrefix, OPS, diff --git a/crates/cuda-driver/src/gdn_closed_queue/gdn_row_prefix/gdn_row_prefix_fenced_drain.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_closed_queue/gdn_row_prefix/gdn_row_prefix_fenced_drain.rs similarity index 96% rename from crates/cuda-driver/src/gdn_closed_queue/gdn_row_prefix/gdn_row_prefix_fenced_drain.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_closed_queue/gdn_row_prefix/gdn_row_prefix_fenced_drain.rs index fae50168..aaded3f8 100644 --- a/crates/cuda-driver/src/gdn_closed_queue/gdn_row_prefix/gdn_row_prefix_fenced_drain.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gdn_closed_queue/gdn_row_prefix/gdn_row_prefix_fenced_drain.rs @@ -1,5 +1,5 @@ -//! Methods of `GdnRowPrefix`: `drain`, `drain_buffers`, `decoded_refusal`, `fenced` and 2 more. -//! Functions: `fetched_history`, `history_words`. Defines `Fenced`. +//! Final drain of a GDN row program: reset the status words, launch every queued command, read statuses and optional +//! next history back and synchronize in one fence; failures latch the queue and poison the context. use super::{ Drained, Error, GdnQueueStage, GdnRowPrefix, HISTORY_BYTES, Result, SLOTS, STATUS_BYTES, combine, decode_statuses, diff --git a/crates/cuda-driver/src/gdn_closed_queue/gdn_row_prefix/recurrence_stages.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_closed_queue/gdn_row_prefix/recurrence_stages.rs similarity index 97% rename from crates/cuda-driver/src/gdn_closed_queue/gdn_row_prefix/recurrence_stages.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_closed_queue/gdn_row_prefix/recurrence_stages.rs index f14deb43..0f91ff6a 100644 --- a/crates/cuda-driver/src/gdn_closed_queue/gdn_row_prefix/recurrence_stages.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gdn_closed_queue/gdn_row_prefix/recurrence_stages.rs @@ -1,5 +1,5 @@ -//! Methods of `GdnRowPrefix`: `qk_l2`, `beta_sigmoid`, `gate_softplus`, `recurrence` and 7 more. -//! Split out of `gdn_row_prefix` to keep its files under the line limit. +//! Later stages of the GDN row program: Q/K L2, beta sigmoid, gate softplus, the recurrence over fixed Q/K/V ranges, +//! the Z scan, output norm, selecting the history to fetch, and finish, which drains the whole prefix once. use super::{ Admission, Arguments, BETA, Command, DeviceBuffer, Error, GATE, GdnOutNormBuffers, GdnQueueStage, diff --git a/crates/cuda-driver/src/gdn_closed_queue/gdn_row_queue.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_closed_queue/gdn_row_queue.rs similarity index 90% rename from crates/cuda-driver/src/gdn_closed_queue/gdn_row_queue.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_closed_queue/gdn_row_queue.rs index 39c2249f..32deaef8 100644 --- a/crates/cuda-driver/src/gdn_closed_queue/gdn_row_queue.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gdn_closed_queue/gdn_row_queue.rs @@ -1,5 +1,5 @@ -//! Methods of `GdnRowQueue`: `close_inner`, `release_status`, `release_module`. Methods of `Command`: `launch`. -//! Implements `Drop for GdnRowQueue`. Functions: `staging`. +//! Teardown and plumbing of the GDN row queue: closing it releases the status buffer and helper module (poisoning the +//! context on failure), Drop closes it, plus host staging allocation and the launch of one queued command. use super::{Command, Context, DeviceBuffer, Error, GdnRowQueue, Result, combine, ffi}; diff --git a/crates/cuda-driver/src/gdn_closed_queue_gpu.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_closed_queue/gpu.rs similarity index 84% rename from crates/cuda-driver/src/gdn_closed_queue_gpu.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_closed_queue/gpu.rs index 82983e0a..82353aa5 100644 --- a/crates/cuda-driver/src/gdn_closed_queue_gpu.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gdn_closed_queue/gpu.rs @@ -74,37 +74,17 @@ fn queued_gdn_row_matches_scalar_calls_orders_refusals_and_cleans_up() { ); } -#[path = "gdn_closed_queue_gpu/bytes.rs"] mod bytes; -#[path = "gdn_closed_queue_gpu/scenarios.rs"] mod scenarios; -#[allow(unused_imports)] use bytes::blank; -#[allow(unused_imports)] use bytes::bytes; -#[allow(unused_imports)] use bytes::column_image; -#[allow(unused_imports)] -use bytes::pattern; -#[allow(unused_imports)] use bytes::queued; -#[allow(unused_imports)] use bytes::queued_columns; -#[allow(unused_imports)] -use bytes::read; -#[allow(unused_imports)] use bytes::scalar; -#[allow(unused_imports)] use bytes::upload; -#[path = "gdn_closed_queue_gpu/columns_pair_cases.rs"] mod columns_pair_cases; -#[allow(unused_imports)] use columns_pair_cases::clean_pair; -#[allow(unused_imports)] -use columns_pair_cases::compare; -#[allow(unused_imports)] use columns_pair_cases::refusal_case; -#[allow(unused_imports)] use columns_pair_cases::refuse; -#[allow(unused_imports)] use columns_pair_cases::{ColumnsCase, ColumnsPoison, columns_pair}; diff --git a/crates/cuda-driver/src/gdn_closed_queue_gpu/bytes.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_closed_queue/gpu/bytes.rs similarity index 97% rename from crates/cuda-driver/src/gdn_closed_queue_gpu/bytes.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_closed_queue/gpu/bytes.rs index 0f1bace4..a7b0241c 100644 --- a/crates/cuda-driver/src/gdn_closed_queue_gpu/bytes.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gdn_closed_queue/gpu/bytes.rs @@ -1,5 +1,5 @@ -//! Methods of `Row`: `conv_buffers`, `recurrence_buffers`, `out_norm_buffers`, `new` and 7 more. -//! Functions: `bytes`, `upload`, `blank`, `read` and 6 more. +//! GPU test fixtures of the GDN row queue: a Row of whole device owners with deterministic (optionally NaN-tailed) +//! inputs, the scalar reference sequence, the queued programs (own or retained QKV row) and upload/readback helpers. use super::{ CHANNELS, Context, DeviceBuffer, EPSILON, GdnConvBuffers, GdnOutNormBuffers, GdnRecurrenceBuffers, diff --git a/crates/cuda-driver/src/gdn_closed_queue_gpu/columns_pair_cases.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_closed_queue/gpu/columns_pair_cases.rs similarity index 96% rename from crates/cuda-driver/src/gdn_closed_queue_gpu/columns_pair_cases.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_closed_queue/gpu/columns_pair_cases.rs index 482c1fb9..e45d1f41 100644 --- a/crates/cuda-driver/src/gdn_closed_queue_gpu/columns_pair_cases.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gdn_closed_queue/gpu/columns_pair_cases.rs @@ -1,5 +1,5 @@ -//! Functions: `columns_pair`, `poisoned_image`, `compare_columns`, `note_qkv_refusal` and 4 more. -//! Defines `ColumnsCase`, `ColumnsPoison`, `RetainedColumns`. +//! GPU test cases of the GDN row queue: queued results must match the scalar sequence bit for bit, including retained +//! batched QKV rows (non-finite words in other rows are ignored, in the used row they refuse at the first stage). use super::{ CHANNELS, Context, DeviceBuffer, Error, GdnQueueStage, GdnRowCompletion, GdnRowQueue, Poison, Report, Result, Row, diff --git a/crates/cuda-driver/src/gdn_closed_queue_gpu/scenarios.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_closed_queue/gpu/scenarios.rs similarity index 100% rename from crates/cuda-driver/src/gdn_closed_queue_gpu/scenarios.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_closed_queue/gpu/scenarios.rs diff --git a/crates/cuda-driver/src/gdn_fused_t1.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_fused_t1.rs similarity index 97% rename from crates/cuda-driver/src/gdn_fused_t1.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_fused_t1.rs index 6917697f..d2d39573 100644 --- a/crates/cuda-driver/src/gdn_fused_t1.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gdn_fused_t1.rs @@ -311,26 +311,16 @@ mod tests { } #[cfg(all(test, feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_arch = "x86_64"))] -#[path = "gdn_fused_t1_gpu.rs"] mod gpu; -#[path = "gdn_fused_t1/pinned.rs"] mod pinned; -#[allow(unused_imports)] use pinned::decode_statuses; -#[allow(unused_imports)] pub(crate) use pinned::fused_asset; -#[allow(unused_imports)] use pinned::linear; -#[allow(unused_imports)] +#[cfg(test)] use pinned::pinned; -#[path = "gdn_fused_t1/gdn_fused_prefix.rs"] mod gdn_fused_prefix; -#[path = "gdn_fused_t1/gdn_fused_t1_lifecycle.rs"] mod gdn_fused_t1_lifecycle; -#[path = "gdn_fused_t1/words.rs"] mod words; -#[allow(unused_imports)] use words::staging; -#[allow(unused_imports)] use words::words; diff --git a/crates/cuda-driver/src/gdn_fused_t1/gdn_fused_prefix.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_fused_t1/gdn_fused_prefix.rs similarity index 58% rename from crates/cuda-driver/src/gdn_fused_t1/gdn_fused_prefix.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_fused_t1/gdn_fused_prefix.rs index 9c188aa5..0ca867b6 100644 --- a/crates/cuda-driver/src/gdn_fused_t1/gdn_fused_prefix.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gdn_fused_t1/gdn_fused_prefix.rs @@ -1,5 +1,5 @@ -//! Groups the submodules `fused_stage_binding`, `gdn_fused_prefix_step_norm_drain`. -//! Split out of `gdn_fused_t1` to keep its files under the line limit. +//! The fused GDN T1 prefix: one owned program of fused kernels and finite scans for a single token step; the +//! submodules split it into the binding/early stages and the step-norm stage with its fenced drain. use super::{ C, Command, DeviceBuffer, Drained, Error, F16, F32, FusedKernel, GDN_FUSED_T1_STATE_BYTES, GdnAbBuffers, @@ -7,7 +7,5 @@ use super::{ STATE_WORDS, STATUS_BYTES, Step, combine, decode_statuses, ffi, linear, staging, words, }; -#[path = "gdn_fused_prefix/fused_stage_binding.rs"] mod fused_stage_binding; -#[path = "gdn_fused_prefix/gdn_fused_prefix_step_norm_drain.rs"] mod gdn_fused_prefix_step_norm_drain; diff --git a/crates/cuda-driver/src/gdn_fused_t1/gdn_fused_prefix/fused_stage_binding.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_fused_t1/gdn_fused_prefix/fused_stage_binding.rs similarity index 97% rename from crates/cuda-driver/src/gdn_fused_t1/gdn_fused_prefix/fused_stage_binding.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_fused_t1/gdn_fused_prefix/fused_stage_binding.rs index a4160750..d6ada148 100644 --- a/crates/cuda-driver/src/gdn_fused_t1/gdn_fused_prefix/fused_stage_binding.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gdn_fused_t1/gdn_fused_prefix/fused_stage_binding.rs @@ -1,5 +1,5 @@ -//! Methods of `GdnFusedPrefix`: `ready`, `latch`, `bind`, `push` and 10 more. -//! Split out of `gdn_fused_prefix` to keep its files under the line limit. +//! First half of the fused GDN T1 program: step order, role-bound buffer admission, ordered finite scans, and the +//! input scan, state seeding, conv+L2 and gate/beta (ab) kernels. The step norm and the drain are in the sibling file. use super::{ C, Command, DeviceBuffer, Error, F16, F32, FusedKernel, GDN_FUSED_T1_STATE_BYTES, GdnAbBuffers, GdnFusedPrefix, diff --git a/crates/cuda-driver/src/gdn_fused_t1/gdn_fused_prefix/gdn_fused_prefix_step_norm_drain.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_fused_t1/gdn_fused_prefix/gdn_fused_prefix_step_norm_drain.rs similarity index 97% rename from crates/cuda-driver/src/gdn_fused_t1/gdn_fused_prefix/gdn_fused_prefix_step_norm_drain.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_fused_t1/gdn_fused_prefix/gdn_fused_prefix_step_norm_drain.rs index f21921aa..69e10d1c 100644 --- a/crates/cuda-driver/src/gdn_fused_t1/gdn_fused_prefix/gdn_fused_prefix_step_norm_drain.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gdn_fused_t1/gdn_fused_prefix/gdn_fused_prefix_step_norm_drain.rs @@ -1,5 +1,5 @@ -//! Methods of `GdnFusedPrefix`: `step_norm`, `step_norm_handles`, `push_step_norm`, `fetch_candidate` and 8 more. -//! Functions: `fetched_candidate`, `candidate_words`. Defines `DrainBuffers`, `Fenced`. +//! Second half of the fused GDN T1 program: the step-norm kernel, the request for the candidate state/history, and +//! finish, which drains the whole prefix in one fence (statuses and candidate read back, failures poison the context). use super::{ DeviceBuffer, Drained, Error, F32, FusedKernel, GDN_FUSED_T1_STATE_BYTES, GdnFusedCompletion, GdnFusedPrefix, diff --git a/crates/cuda-driver/src/gdn_fused_t1/gdn_fused_t1_lifecycle.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_fused_t1/gdn_fused_t1_lifecycle.rs similarity index 100% rename from crates/cuda-driver/src/gdn_fused_t1/gdn_fused_t1_lifecycle.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_fused_t1/gdn_fused_t1_lifecycle.rs diff --git a/crates/cuda-driver/src/gdn_fused_t1_gpu.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_fused_t1/gpu.rs similarity index 100% rename from crates/cuda-driver/src/gdn_fused_t1_gpu.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_fused_t1/gpu.rs diff --git a/crates/cuda-driver/src/gdn_fused_t1/pinned.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_fused_t1/pinned.rs similarity index 93% rename from crates/cuda-driver/src/gdn_fused_t1/pinned.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_fused_t1/pinned.rs index 78aabcc0..51fa1f86 100644 --- a/crates/cuda-driver/src/gdn_fused_t1/pinned.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gdn_fused_t1/pinned.rs @@ -1,5 +1,5 @@ -//! Methods of `FusedKernel`: `entry`, `index`. Methods of `GdnFusedStage`: `slot`, `elements`, `bytes`. -//! Functions: `pinned`, `fused_asset`, `linear`, `decode_statuses`. +//! Pinned sealed PTX of the fused GDN T1 kernels (digest-checked), kernel entry names and indices, the finite-scan +//! stage table (slot, element count, bytes), status decoding in source order, launch geometry and the role bindings. use super::{ Bindings, C, Context, Error, F32, FUSED_PTX_LEN, FUSED_PTX_SHA256, FusedKernel, GdnFusedStage, GdnFusedT1, @@ -20,7 +20,7 @@ pub(super) fn pinned(ptx: &'static [u8], len: usize, digest: [u8; 32]) -> Result Ok(ptx) } pub(crate) fn fused_asset() -> Result<&'static [u8]> { - pinned(concat!(include_str!("../offline_gdn_fused_t1.ptx"), "\0").as_bytes(), FUSED_PTX_LEN, FUSED_PTX_SHA256) + pinned(concat!(include_str!("../../offline_gdn_fused_t1.ptx"), "\0").as_bytes(), FUSED_PTX_LEN, FUSED_PTX_SHA256) } impl FusedKernel { pub(crate) fn entry(self) -> &'static std::ffi::CStr { diff --git a/crates/cuda-driver/src/gdn_fused_t1/words.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_fused_t1/words.rs similarity index 95% rename from crates/cuda-driver/src/gdn_fused_t1/words.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_fused_t1/words.rs index a9bf6b17..04fb5340 100644 --- a/crates/cuda-driver/src/gdn_fused_t1/words.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gdn_fused_t1/words.rs @@ -1,5 +1,5 @@ -//! Methods of `GdnFusedT1`: `close_inner`, `release_status`, `release_module`, `replay_state_from_products`. -//! Methods of `GdnFusedPrefix`: `bind_replay`, `finish_device`. Implements `Drop for GdnFusedT1`. +//! Teardown of the fused GDN T1 owner (status buffer and module release, Drop), host word/staging conversion, and the +//! device-only replay of the state update from completed journal products. use super::{ C, DeviceBuffer, Error, F32, FusedKernel, GdnFusedPrefix, GdnFusedStage, GdnFusedT1, GdnReplayBuffers, HV, Result, diff --git a/crates/cuda-driver/src/gdn_native_batch.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch.rs similarity index 96% rename from crates/cuda-driver/src/gdn_native_batch.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_native_batch.rs index 8623e5dd..a10555c2 100644 --- a/crates/cuda-driver/src/gdn_native_batch.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch.rs @@ -332,35 +332,24 @@ struct Drained { } #[cfg(test)] -#[path = "gdn_native_batch/tests.rs"] +#[path = "../gdn_native_batch/tests.rs"] mod tests; #[cfg(all(test, feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_arch = "x86_64"))] -#[path = "gdn_native_batch_gpu.rs"] mod gpu; // Original physical prompt arena producer: old whole-owner API remains exact. -#[path = "gdn_prompt_device.rs"] mod prompt_device; pub use prompt_device::{GdnPromptOptions, OriginalGdnPromptDevice, OriginalGdnPromptState, OriginalGdnPromptWeights}; -#[path = "gdn_native_batch/pinned.rs"] mod pinned; -#[allow(unused_imports)] use pinned::decode_statuses; -#[allow(unused_imports)] pub(crate) use pinned::dequant_asset; -#[allow(unused_imports)] use pinned::linear; -#[allow(unused_imports)] +#[cfg(test)] use pinned::pinned; -#[allow(unused_imports)] pub(crate) use pinned::prefill_asset; -#[path = "gdn_native_batch/context.rs"] mod context; -#[path = "gdn_native_batch/gdn_batch_prefix.rs"] mod gdn_batch_prefix; -#[path = "gdn_native_batch/staging.rs"] mod staging; -#[allow(unused_imports)] use staging::staging; diff --git a/crates/cuda-driver/src/gdn_native_batch/context.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/context.rs similarity index 96% rename from crates/cuda-driver/src/gdn_native_batch/context.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/context.rs index 608901b1..8039008a 100644 --- a/crates/cuda-driver/src/gdn_native_batch/context.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/context.rs @@ -1,5 +1,5 @@ -//! Methods of `Context`: `gdn_prefill_batch`, `gdn_prefill_batch_for_prompt`. -//! Methods of `GdnPrefillBatch`: `new`, `new_capacity`, `open`, `load_functions` and 6 more. Functions: `reserved`. +//! Opening and running the batched native GDN prefill: Context constructors, the GdnPrefillBatch owner (status buffer, +//! prefill and dequantization kernels), starting a prefix on a GEMM adapter, launching commands, the completion result. use super::{ Bindings, Command, Context, Error, Functions, GDN_BATCH_MAX_TOKENS, GdnBatchCompletion, GdnBatchPrefix, diff --git a/crates/cuda-driver/src/gdn_native_batch/gdn_batch_prefix.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/gdn_batch_prefix.rs similarity index 54% rename from crates/cuda-driver/src/gdn_native_batch/gdn_batch_prefix.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/gdn_batch_prefix.rs index 8bacfcb5..a629a0fa 100644 --- a/crates/cuda-driver/src/gdn_native_batch/gdn_batch_prefix.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/gdn_batch_prefix.rs @@ -1,5 +1,5 @@ -//! Groups the submodules `native_projection`, `qkv_and_z_projections`, `recurrence_and_output`. -//! Split out of `gdn_native_batch` to keep its files under the line limit. +//! The batched GDN prefill prefix: an owned program of kernels, GEMMs and finite scans over a token chunk; the +//! submodules split it into the shared base/projection, the early stages, and the recurrence with its drain. use super::{ C, CONV_TILE, Command, DeviceBuffer, Drained, Error, F16, F32, GDN_BATCH_EPSILON, GdnBatchCompletion, @@ -7,9 +7,6 @@ use super::{ STATE_WORDS, STATUS_BYTES, Step, ZV, combine, decode_statuses, ffi, linear, staging, }; -#[path = "gdn_batch_prefix/native_projection.rs"] mod native_projection; -#[path = "gdn_batch_prefix/qkv_and_z_projections.rs"] mod qkv_and_z_projections; -#[path = "gdn_batch_prefix/recurrence_and_output.rs"] mod recurrence_and_output; diff --git a/crates/cuda-driver/src/gdn_native_batch/gdn_batch_prefix/native_projection.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/gdn_batch_prefix/native_projection.rs similarity index 97% rename from crates/cuda-driver/src/gdn_native_batch/gdn_batch_prefix/native_projection.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/gdn_batch_prefix/native_projection.rs index 518f6484..9a26d70b 100644 --- a/crates/cuda-driver/src/gdn_native_batch/gdn_batch_prefix/native_projection.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/gdn_batch_prefix/native_projection.rs @@ -1,5 +1,5 @@ -//! Methods of `GdnBatchPrefix`: `tokens`, `ready`, `latch`, `function` and 12 more. Functions: `size_admitted`. -//! Defines `NativeProjection`, `ProjectionOperands`. +//! Shared base of the batched GDN prefill program: step order, role-bound buffer admission, ordered finite scans, +//! the mixed-activation image packing, and the native quantized projection (dequantize to FP16, then GEMM). use super::{ Command, DeviceBuffer, Error, F16, F32, GdnBatchPrefix, GdnBatchStage, GdnNativeFormat, GemmShape, Kernel, N, diff --git a/crates/cuda-driver/src/gdn_native_batch/gdn_batch_prefix/qkv_and_z_projections.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/gdn_batch_prefix/qkv_and_z_projections.rs similarity index 98% rename from crates/cuda-driver/src/gdn_native_batch/gdn_batch_prefix/qkv_and_z_projections.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/gdn_batch_prefix/qkv_and_z_projections.rs index 16f37947..7ea97ee6 100644 --- a/crates/cuda-driver/src/gdn_native_batch/gdn_batch_prefix/qkv_and_z_projections.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/gdn_batch_prefix/qkv_and_z_projections.rs @@ -1,5 +1,5 @@ -//! Methods of `GdnBatchPrefix`: `project_qkv`, `project_z`, `project_alpha_beta`, `push_ab_gemm` and 7 more. -//! Split out of `gdn_batch_prefix` to keep its files under the line limit. +//! Early stages of the batched GDN prefill program: the QKV, Z and alpha/beta projections, the gates kernel, +//! the causal convolution plus SiLU (serial or tiled by chunk length) and the Q/K L2 normalization. use super::native_projection::{NativeProjection, ProjectionOperands}; use super::{ diff --git a/crates/cuda-driver/src/gdn_native_batch/gdn_batch_prefix/recurrence_and_output.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/gdn_batch_prefix/recurrence_and_output.rs similarity index 97% rename from crates/cuda-driver/src/gdn_native_batch/gdn_batch_prefix/recurrence_and_output.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/gdn_batch_prefix/recurrence_and_output.rs index d9e48a8c..82632db8 100644 --- a/crates/cuda-driver/src/gdn_native_batch/gdn_batch_prefix/recurrence_and_output.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/gdn_batch_prefix/recurrence_and_output.rs @@ -1,5 +1,5 @@ -//! Methods of `GdnBatchPrefix`: `recurrence`, `recurrence_arguments`, `out_norm`, `project_out` and 7 more. -//! Functions: `fetched_history`, `history_words`. Defines `Fenced`. +//! Late stages of the batched GDN prefill program: the whole-chunk recurrence, output norm and output projection, +//! then finish, which drains the program in one fence (status words and history read back; failures poison it). use super::native_projection::{NativeProjection, ProjectionOperands}; use super::{ diff --git a/crates/cuda-driver/src/gdn_native_batch_gpu.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/gpu.rs similarity index 89% rename from crates/cuda-driver/src/gdn_native_batch_gpu.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/gpu.rs index a03069fc..7da3984a 100644 --- a/crates/cuda-driver/src/gdn_native_batch_gpu.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/gpu.rs @@ -132,43 +132,20 @@ fn run_cases(context: &Context<'_>, batch: &mut GdnPrefillBatch<'_>) -> Result<( run_case(context, batch, 3, Poison::default(), None) } -#[path = "gdn_native_batch_gpu/bytes_of.rs"] mod bytes_of; -#[allow(unused_imports)] use bytes_of::bf_bits; -#[allow(unused_imports)] use bytes_of::bf_value; -#[allow(unused_imports)] use bytes_of::bytes_of; -#[allow(unused_imports)] use bytes_of::close; -#[allow(unused_imports)] use bytes_of::f16_bits; -#[allow(unused_imports)] use bytes_of::f16_value; -#[allow(unused_imports)] use bytes_of::halves_of; -#[allow(unused_imports)] use bytes_of::pattern; -#[allow(unused_imports)] use bytes_of::q8_0; -#[allow(unused_imports)] -use bytes_of::sigm; -#[allow(unused_imports)] use bytes_of::words_of; -#[allow(unused_imports)] use bytes_of::{Projections, reference}; -#[path = "gdn_native_batch_gpu/host_gemm_adapter.rs"] mod host_gemm_adapter; -#[allow(unused_imports)] use host_gemm_adapter::mismatch; -#[allow(unused_imports)] use host_gemm_adapter::read; -#[allow(unused_imports)] -use host_gemm_adapter::upload; -#[path = "gdn_native_batch_gpu/run_case.rs"] mod run_case; -#[allow(unused_imports)] -use run_case::check_clean; -#[allow(unused_imports)] use run_case::run_case; diff --git a/crates/cuda-driver/src/gdn_native_batch_gpu/bytes_of.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/gpu/bytes_of.rs similarity index 97% rename from crates/cuda-driver/src/gdn_native_batch_gpu/bytes_of.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/gpu/bytes_of.rs index 30368f75..cb766c6c 100644 --- a/crates/cuda-driver/src/gdn_native_batch_gpu/bytes_of.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/gpu/bytes_of.rs @@ -1,5 +1,5 @@ -//! Functions: `bytes_of`, `words_of`, `halves_of`, `f16_bits` and 15 more. Defines `Projections`. -//! Split out of `gpu` to keep its files under the line limit. +//! Host-side numerics of the GDN prefill GPU smoke test: byte/word/half conversions, FP16/BF16 rounding, Q8_0 blocks, +//! deterministic input patterns, and the host reference of every original kernel (gates, conv, L2, recurrence, norm). use super::{C, EPS, HISTORY_WORDS, HV, HostInputs, Q8_0_BLOCK, Reference, S, ZV}; diff --git a/crates/cuda-driver/src/gdn_native_batch_gpu/host_gemm_adapter.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/gpu/host_gemm_adapter.rs similarity index 97% rename from crates/cuda-driver/src/gdn_native_batch_gpu/host_gemm_adapter.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/gpu/host_gemm_adapter.rs index 95d6d0ba..8b9942c4 100644 --- a/crates/cuda-driver/src/gdn_native_batch_gpu/host_gemm_adapter.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/gpu/host_gemm_adapter.rs @@ -1,5 +1,5 @@ -//! Methods of `HostGemm`: `run`, `poison_output`, `capture`. Methods of `Fixture`: `new`, `release`. -//! Implements `GdnGemm for HostGemm`. Functions: `host_gemm`, `upload`, `read`, `mismatch`. +//! Host stand-in for the closed cuBLAS GEMM adapter in the GDN prefill GPU smoke test (it records every call and can +//! poison an output word), plus the Fixture of uploaded inputs and blank outputs and the buffer upload/read helpers. use super::{ C, Context, DeviceBuffer, Error, Fixture, FixtureInputs, FixtureOutputs, GdnGemm, GdnStream, GemmShape, diff --git a/crates/cuda-driver/src/gdn_native_batch_gpu/run_case.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/gpu/run_case.rs similarity index 97% rename from crates/cuda-driver/src/gdn_native_batch_gpu/run_case.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/gpu/run_case.rs index 8b765471..6432fafe 100644 --- a/crates/cuda-driver/src/gdn_native_batch_gpu/run_case.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/gpu/run_case.rs @@ -1,5 +1,5 @@ -//! Functions: `run_case`, `check_case`, `push_program`, `inputs_untouched` and 8 more. -//! Split out of `gpu` to keep its files under the line limit. +//! Runs one complete GDN prefill program over the fixture and checks the completion, untouched inputs, the GEMM call +//! sequence, exact dequantization, image packing and every device output against the host reference. use super::{ C, Captured, Cell, Context, Error, Fixture, GdnBatchPrefix, GdnBatchStage, GdnNativeFormat, GdnPrefillBatch, HV, diff --git a/crates/cuda-driver/src/gdn_native_batch/pinned.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/pinned.rs similarity index 95% rename from crates/cuda-driver/src/gdn_native_batch/pinned.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/pinned.rs index 5241e86f..b384cad3 100644 --- a/crates/cuda-driver/src/gdn_native_batch/pinned.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/pinned.rs @@ -1,5 +1,5 @@ -//! Methods of `Kernel`: `entry`, `is_dequant`, `index`. -//! Methods of `GdnNativeFormat`: `ggml_type`, `block`, `kernel`, `matrix_bytes`. +//! Pinned sealed PTX of the batched GDN prefill and dequantization kernels (digest-checked), kernel entry names, the +//! GGUF weight formats, the stage table (slot, elements, bytes), status decoding, step order and role bindings. use super::{ Bindings, C, DEQUANT_PTX_LEN, DEQUANT_PTX_SHA256, Error, F16, F32, Functions, GdnBatchStage, GdnNativeFormat, @@ -22,7 +22,7 @@ pub(super) fn pinned(ptx: &'static [u8], len: usize, digest: [u8; 32], what: &'s } pub(crate) fn prefill_asset() -> Result<&'static [u8]> { pinned( - concat!(include_str!("../offline_gdn_prefill.ptx"), "\0").as_bytes(), + concat!(include_str!("../../offline_gdn_prefill.ptx"), "\0").as_bytes(), PREFILL_PTX_LEN, PREFILL_PTX_SHA256, "GDN prefill artifact digest", @@ -30,7 +30,7 @@ pub(crate) fn prefill_asset() -> Result<&'static [u8]> { } pub(crate) fn dequant_asset() -> Result<&'static [u8]> { pinned( - concat!(include_str!("../offline_native_dequant_f16.ptx"), "\0").as_bytes(), + concat!(include_str!("../../offline_native_dequant_f16.ptx"), "\0").as_bytes(), DEQUANT_PTX_LEN, DEQUANT_PTX_SHA256, "native dequant artifact digest", diff --git a/crates/cuda-driver/src/gdn_prompt_device.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device.rs similarity index 94% rename from crates/cuda-driver/src/gdn_prompt_device.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device.rs index c3e0909f..9540264a 100644 --- a/crates/cuda-driver/src/gdn_prompt_device.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device.rs @@ -85,13 +85,9 @@ enum DeviceCommand { } #[cfg(test)] -#[path = "prefill_stage_gdn_gpu.rs"] mod stage_gpu_tests; -#[path = "gdn_prompt_device/context.rs"] mod context; -#[path = "gdn_prompt_device/original_gdn_prompt_device.rs"] mod original_gdn_prompt_device; use original_gdn_prompt_device::TensorCoreState; -#[path = "gdn_prompt_device/original_gdn_prompt_device_drop.rs"] mod original_gdn_prompt_device_drop; diff --git a/crates/cuda-driver/src/gdn_prompt_device/context.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device/context.rs similarity index 82% rename from crates/cuda-driver/src/gdn_prompt_device/context.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device/context.rs index 7bc47b29..424937a0 100644 --- a/crates/cuda-driver/src/gdn_prompt_device/context.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device/context.rs @@ -1,5 +1,4 @@ -//! Methods of `Context`: `original_gdn_prompt_device`, `original_gdn_prompt_device_with`. -//! Split out of `prompt_device` to keep its files under the line limit. +//! Context constructors of the original GDN prompt device: default options or operator-supplied GdnPromptOptions. use super::{Context, GdnPromptOptions, OriginalGdnPromptDevice, Result}; diff --git a/crates/cuda-driver/src/gdn_prompt_device/original_gdn_prompt_device.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device/original_gdn_prompt_device.rs similarity index 56% rename from crates/cuda-driver/src/gdn_prompt_device/original_gdn_prompt_device.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device/original_gdn_prompt_device.rs index 046d752e..f6d9e415 100644 --- a/crates/cuda-driver/src/gdn_prompt_device/original_gdn_prompt_device.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device/original_gdn_prompt_device.rs @@ -1,5 +1,5 @@ -//! Groups the submodules `gdn_prompt_run_buffer_binder`, `original_gdn_prompt_device_admit_open`, `original_gdn_prom... -//! Split out of `prompt_device` to keep its files under the line limit. +//! The original GDN prompt device: a device-resident program of the GDN layer over a prompt block, split into +//! construction, close, buffer binding, command-list building, tensor-core scan, drain and the produce entry point. use super::{ A, Bindings, C, Context, DeviceBuffer, DeviceCommand, Error, Functions, GDN_BATCH_EPSILON, GdnBatchStage, @@ -9,20 +9,12 @@ use super::{ SCRATCH, SLOTS, STATE_WORDS, STATUS_BYTES, ZV, combine, decode_statuses, ffi, linear, staging, }; -#[path = "original_gdn_prompt_device/gdn_prompt_run_buffer_binder.rs"] mod gdn_prompt_run_buffer_binder; -#[path = "original_gdn_prompt_device/original_gdn_prompt_device_admit_open.rs"] mod original_gdn_prompt_device_admit_open; -#[path = "original_gdn_prompt_device/original_gdn_prompt_device_close.rs"] mod original_gdn_prompt_device_close; -#[path = "original_gdn_prompt_device/original_gdn_prompt_device_drain.rs"] mod original_gdn_prompt_device_drain; -#[path = "original_gdn_prompt_device/prompt_block_produce.rs"] mod prompt_block_produce; -#[path = "original_gdn_prompt_device/prompt_command_list.rs"] mod prompt_command_list; -#[path = "original_gdn_prompt_device/prompt_tensor_core_scan.rs"] mod prompt_tensor_core_scan; -#[allow(unused_imports)] use gdn_prompt_run_buffer_binder::{Binder, Carve, Carved, Handles, Phase}; pub(super) use prompt_tensor_core_scan::TensorCoreState; diff --git a/crates/cuda-driver/src/gdn_prompt_device/original_gdn_prompt_device/gdn_prompt_run_buffer_binder.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device/original_gdn_prompt_device/gdn_prompt_run_buffer_binder.rs similarity index 100% rename from crates/cuda-driver/src/gdn_prompt_device/original_gdn_prompt_device/gdn_prompt_run_buffer_binder.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device/original_gdn_prompt_device/gdn_prompt_run_buffer_binder.rs diff --git a/crates/cuda-driver/src/gdn_prompt_device/original_gdn_prompt_device/original_gdn_prompt_device_admit_open.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device/original_gdn_prompt_device/original_gdn_prompt_device_admit_open.rs similarity index 93% rename from crates/cuda-driver/src/gdn_prompt_device/original_gdn_prompt_device/original_gdn_prompt_device_admit_open.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device/original_gdn_prompt_device/original_gdn_prompt_device_admit_open.rs index 3407b25b..e46cc840 100644 --- a/crates/cuda-driver/src/gdn_prompt_device/original_gdn_prompt_device/original_gdn_prompt_device_admit_open.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device/original_gdn_prompt_device/original_gdn_prompt_device_admit_open.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalGdnPromptDevice`: `device_bytes`, `new`, `admit_budget`, `open` and 2 more. -//! Split out of `original_gdn_prompt_device` to keep its files under the line limit. +//! Construction of the original GDN prompt device: device-byte sizing, budget and free-memory admission, and opening +//! the batch owner, scratch and the two history buffers. use super::{ Context, DeviceBuffer, Error, GdnPrefillBatch, GdnPromptOptions, HISTORY, OriginalGdnPromptDevice, RESERVE, Result, diff --git a/crates/cuda-driver/src/gdn_prompt_device/original_gdn_prompt_device/original_gdn_prompt_device_close.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device/original_gdn_prompt_device/original_gdn_prompt_device_close.rs similarity index 89% rename from crates/cuda-driver/src/gdn_prompt_device/original_gdn_prompt_device/original_gdn_prompt_device_close.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device/original_gdn_prompt_device/original_gdn_prompt_device_close.rs index 1c943728..c09733d8 100644 --- a/crates/cuda-driver/src/gdn_prompt_device/original_gdn_prompt_device/original_gdn_prompt_device_close.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device/original_gdn_prompt_device/original_gdn_prompt_device_close.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalGdnPromptDevice`: `close`, `close_inner`, `release_stage`, `release_batch`. -//! Functions: `release_buffer`. +//! Teardown of the original GDN prompt device: releases history, scratch, stage module, tensor-core state and batch +//! owner; on a poisoned context buffers are leaked instead of freed, and a failed close poisons the context. use super::{Context, DeviceBuffer, Error, GdnPrefillBatch, KernelModule, OriginalGdnPromptDevice, Result, combine}; diff --git a/crates/cuda-driver/src/gdn_prompt_device/original_gdn_prompt_device/original_gdn_prompt_device_drain.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device/original_gdn_prompt_device/original_gdn_prompt_device_drain.rs similarity index 100% rename from crates/cuda-driver/src/gdn_prompt_device/original_gdn_prompt_device/original_gdn_prompt_device_drain.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device/original_gdn_prompt_device/original_gdn_prompt_device_drain.rs diff --git a/crates/cuda-driver/src/gdn_prompt_device/original_gdn_prompt_device/prompt_block_produce.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device/original_gdn_prompt_device/prompt_block_produce.rs similarity index 96% rename from crates/cuda-driver/src/gdn_prompt_device/original_gdn_prompt_device/prompt_block_produce.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device/original_gdn_prompt_device/prompt_block_produce.rs index f766b5a3..ce161678 100644 --- a/crates/cuda-driver/src/gdn_prompt_device/original_gdn_prompt_device/prompt_block_produce.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device/original_gdn_prompt_device/prompt_block_produce.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalGdnPromptDevice`: `produce`, `admit`, `admit_handles`, `admit_state` and 4 more. -//! `produce` admits the buffers, records the command list (`prompt_command_list.rs`) and drains it (`original_gdn_pr... +//! Entry point of the prompt GDN block: produce admits the GR read, workspace, weights and prior state (owners, +//! aliases, shapes, finite history), builds the command list and drains it, returning the completed block and history. use super::{ Binder, Bindings, C, Carve, Carved, DeviceBuffer, Error, HISTORY, HISTORY_WORDS, HV, Handles, N, diff --git a/crates/cuda-driver/src/gdn_prompt_device/original_gdn_prompt_device/prompt_command_list.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device/original_gdn_prompt_device/prompt_command_list.rs similarity index 100% rename from crates/cuda-driver/src/gdn_prompt_device/original_gdn_prompt_device/prompt_command_list.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device/original_gdn_prompt_device/prompt_command_list.rs diff --git a/crates/cuda-driver/src/gdn_prompt_device/original_gdn_prompt_device/prompt_tensor_core_scan.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device/original_gdn_prompt_device/prompt_tensor_core_scan.rs similarity index 100% rename from crates/cuda-driver/src/gdn_prompt_device/original_gdn_prompt_device/prompt_tensor_core_scan.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device/original_gdn_prompt_device/prompt_tensor_core_scan.rs diff --git a/crates/cuda-driver/src/gdn_prompt_device/original_gdn_prompt_device_drop.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device/original_gdn_prompt_device_drop.rs similarity index 54% rename from crates/cuda-driver/src/gdn_prompt_device/original_gdn_prompt_device_drop.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device/original_gdn_prompt_device_drop.rs index 58acda75..3f6d8415 100644 --- a/crates/cuda-driver/src/gdn_prompt_device/original_gdn_prompt_device_drop.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device/original_gdn_prompt_device_drop.rs @@ -1,5 +1,4 @@ -//! Implements `Drop for OriginalGdnPromptDevice`. -//! Split out of `prompt_device` to keep its files under the line limit. +//! Drop of the original GDN prompt device: closes it and ignores the result. use super::OriginalGdnPromptDevice; diff --git a/crates/cuda-driver/src/prefill_stage_gdn_gpu.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device/stage_gpu_tests.rs similarity index 58% rename from crates/cuda-driver/src/prefill_stage_gdn_gpu.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device/stage_gpu_tests.rs index 43381329..a4f10c9c 100644 --- a/crates/cuda-driver/src/prefill_stage_gdn_gpu.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device/stage_gpu_tests.rs @@ -4,33 +4,19 @@ use super::*; use crate::ple_batch_ffi::{BatchArg as A, KernelArguments, KernelModule}; -#[path = "prefill_stage_gdn_gpu/rng.rs"] mod rng; -#[allow(unused_imports)] use rng::download; -#[allow(unused_imports)] use rng::f32_bytes; -#[allow(unused_imports)] use rng::hd; -#[allow(unused_imports)] use rng::run_stage; -#[allow(unused_imports)] use rng::upload; -#[allow(unused_imports)] use rng::words; -#[path = "prefill_stage_gdn_gpu/enable_types.rs"] mod enable_types; -#[allow(unused_imports)] use enable_types::ENABLE; -#[allow(unused_imports)] use enable_types::Old; -#[allow(unused_imports)] use enable_types::Rng; -#[path = "prefill_stage_gdn_gpu/gdn_recurrence_equals_the_original.rs"] mod gdn_recurrence_equals_the_original; -#[path = "prefill_stage_gdn_gpu/gdn_stage_kernels_equal.rs"] mod gdn_stage_kernels_equal; -#[path = "prefill_stage_gdn_gpu/gdn_tensor_core_scan_parity.rs"] mod gdn_tensor_core_scan_parity; diff --git a/crates/cuda-driver/src/prefill_stage_gdn_gpu/enable_types.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device/stage_gpu_tests/enable_types.rs similarity index 70% rename from crates/cuda-driver/src/prefill_stage_gdn_gpu/enable_types.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device/stage_gpu_tests/enable_types.rs index c1943853..4eb78d95 100644 --- a/crates/cuda-driver/src/prefill_stage_gdn_gpu/enable_types.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device/stage_gpu_tests/enable_types.rs @@ -1,5 +1,4 @@ -//! Defines `Rng`, `Old`. -//! ENABLE, Rng, Old. +//! Shared test types of the stage GPU proofs: the environment switch, a xorshift Rng and the Old launcher context. use super::{Context, Functions}; diff --git a/crates/cuda-driver/src/prefill_stage_gdn_gpu/gdn_recurrence_equals_the_original.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device/stage_gpu_tests/gdn_recurrence_equals_the_original.rs similarity index 100% rename from crates/cuda-driver/src/prefill_stage_gdn_gpu/gdn_recurrence_equals_the_original.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device/stage_gpu_tests/gdn_recurrence_equals_the_original.rs diff --git a/crates/cuda-driver/src/prefill_stage_gdn_gpu/gdn_stage_kernels_equal.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device/stage_gpu_tests/gdn_stage_kernels_equal.rs similarity index 99% rename from crates/cuda-driver/src/prefill_stage_gdn_gpu/gdn_stage_kernels_equal.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device/stage_gpu_tests/gdn_stage_kernels_equal.rs index 34f11c76..751a96e1 100644 --- a/crates/cuda-driver/src/prefill_stage_gdn_gpu/gdn_stage_kernels_equal.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device/stage_gpu_tests/gdn_stage_kernels_equal.rs @@ -1,7 +1,6 @@ //! Tests of prefill_stage_gdn_gpu by topic (moved out of the test file by STRA-338): //! gdn_stage_kernels_equal_the_originals_bit_for_bit. -#[allow(unused_imports)] use super::gdn_recurrence_equals_the_original::{Rig, with_rig}; use super::*; diff --git a/crates/cuda-driver/src/prefill_stage_gdn_gpu/gdn_tensor_core_scan_parity.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device/stage_gpu_tests/gdn_tensor_core_scan_parity.rs similarity index 100% rename from crates/cuda-driver/src/prefill_stage_gdn_gpu/gdn_tensor_core_scan_parity.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device/stage_gpu_tests/gdn_tensor_core_scan_parity.rs diff --git a/crates/cuda-driver/src/prefill_stage_gdn_gpu/rng.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device/stage_gpu_tests/rng.rs similarity index 92% rename from crates/cuda-driver/src/prefill_stage_gdn_gpu/rng.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device/stage_gpu_tests/rng.rs index 81c9bcab..05bc467c 100644 --- a/crates/cuda-driver/src/prefill_stage_gdn_gpu/rng.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/prompt_device/stage_gpu_tests/rng.rs @@ -1,5 +1,5 @@ -//! Methods of `Rng`: `next`, `f`, `f16`. Methods of `Old`: `run`. -//! Functions: `f32_bytes`, `upload`, `hd`, `download` and 2 more. +//! Helpers of the stage GPU proofs: a deterministic xorshift generator (finite f32/f16 values), buffer upload/download +//! helpers, and Old, which launches the existing GDN kernels on a stream as the reference side. use super::{A, Context, DeviceBuffer, GdnStream, Kernel, KernelArguments, KernelModule, Old, Rng, ffi}; use crate::ple_batch_ffi::LinearLaunch; diff --git a/crates/cuda-driver/src/gdn_native_batch/staging.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/staging.rs similarity index 91% rename from crates/cuda-driver/src/gdn_native_batch/staging.rs rename to crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/staging.rs index 95eb88a9..8252cad5 100644 --- a/crates/cuda-driver/src/gdn_native_batch/staging.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gdn_native_batch/staging.rs @@ -1,5 +1,5 @@ -//! Methods of `GdnPrefillBatch`: `close_inner`, `release_status`, `release_module`. -//! Implements `Drop for GdnPrefillBatch`. Functions: `staging`. +//! Teardown of the batched GDN prefill owner: releasing the status buffer and kernel modules (poisoning the context +//! on failure), Drop, and the host staging buffer allocation. use super::{DeviceBuffer, Error, GdnPrefillBatch, Result, combine, ffi}; diff --git a/crates/cuda-driver/src/qwen_dispatch/gdn_products_installed.rs b/crates/cuda-driver/src/qwen_dispatch/gdn_products_installed.rs index a83147b6..4b5e867f 100644 --- a/crates/cuda-driver/src/qwen_dispatch/gdn_products_installed.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gdn_products_installed.rs @@ -1,5 +1,5 @@ -//! Methods of `Host`: `pattern`. Methods of `Rig`: `allocate`, `old_expected`, `products_step`, `candidate` and 8 more. -//! Functions: `encode`, `read_pair`, `count_difference`, `allocate_all` and 4 more. Defines `Host`, `Rig`. +//! Root-only GPU test of the whole-product GDN step boundary: the candidate step over whole Q/K/H/gate/beta +//! owners must equal the old marshalled step bit for bit, keep unused tails intact and refuse bad shapes and aliases. use super::*; use crate::{Device, Driver, GdnGates, GdnQkv, GdnStepProducts, GdnStepResult}; diff --git a/crates/cuda-driver/src/gr_batch_inject_workspace.rs b/crates/cuda-driver/src/qwen_dispatch/gr_batch_inject_workspace.rs similarity index 99% rename from crates/cuda-driver/src/gr_batch_inject_workspace.rs rename to crates/cuda-driver/src/qwen_dispatch/gr_batch_inject_workspace.rs index 09ee9812..829242ea 100644 --- a/crates/cuda-driver/src/gr_batch_inject_workspace.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gr_batch_inject_workspace.rs @@ -342,5 +342,4 @@ fn encode(values: &[f32]) -> Result> { } #[cfg(test)] -#[path = "gr_batch_inject_workspace_gpu.rs"] mod gpu; diff --git a/crates/cuda-driver/src/gr_batch_inject_workspace_gpu.rs b/crates/cuda-driver/src/qwen_dispatch/gr_batch_inject_workspace/gpu.rs similarity index 100% rename from crates/cuda-driver/src/gr_batch_inject_workspace_gpu.rs rename to crates/cuda-driver/src/qwen_dispatch/gr_batch_inject_workspace/gpu.rs diff --git a/crates/cuda-driver/src/gr_batch_read.rs b/crates/cuda-driver/src/qwen_dispatch/gr_batch_read.rs similarity index 98% rename from crates/cuda-driver/src/gr_batch_read.rs rename to crates/cuda-driver/src/qwen_dispatch/gr_batch_read.rs index b41903df..f205f439 100644 --- a/crates/cuda-driver/src/gr_batch_read.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gr_batch_read.rs @@ -377,15 +377,9 @@ mod installed { eprintln!("GR microbank original-FIRST words={words} bit_exact=true allocated0=true context_closed=true"); } } -#[path = "gr_batch_read/context.rs"] mod context; -#[allow(unused_imports)] use context::checked_row; -#[allow(unused_imports)] use context::encode; -#[path = "gr_batch_read/gr_microbatch_read.rs"] mod gr_microbatch_read; -#[path = "gr_batch_read/gr_microbatch_read_drop.rs"] mod gr_microbatch_read_drop; -#[allow(unused_imports)] use gr_microbatch_read_drop::decode; diff --git a/crates/cuda-driver/src/gr_batch_read/context.rs b/crates/cuda-driver/src/qwen_dispatch/gr_batch_read/context.rs similarity index 85% rename from crates/cuda-driver/src/gr_batch_read/context.rs rename to crates/cuda-driver/src/qwen_dispatch/gr_batch_read/context.rs index eccf3342..6ee11b92 100644 --- a/crates/cuda-driver/src/gr_batch_read/context.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gr_batch_read/context.rs @@ -1,5 +1,4 @@ -//! Methods of `Context`: `gr_microbatch_read`. Functions: `checked_row`, `encode`. -//! Split out of `gr_batch_read` to keep its files under the line limit. +//! Context constructor of the GR micro-batch read, with the row-range check and the f32 byte encoding it uses. use super::{Context, Error, GrMicrobatchRead, Result}; diff --git a/crates/cuda-driver/src/qwen_dispatch/gr_batch_read/gr_microbatch_read.rs b/crates/cuda-driver/src/qwen_dispatch/gr_batch_read/gr_microbatch_read.rs new file mode 100644 index 00000000..c169c2b6 --- /dev/null +++ b/crates/cuda-driver/src/qwen_dispatch/gr_batch_read/gr_microbatch_read.rs @@ -0,0 +1,11 @@ +//! The GR micro-batch read: retained row banks and a program of GR kernels with finite scans; the submodules split +//! it into opening, the per-row read launch and the residual inject. + +use super::{ + Arguments, Context, DeviceBuffer, Error, FixedKernel, GrMicroValues, GrMicrobatchRead, OPS, Operation, RESERVE, + Result, SIZES, STAGES, checked_row, combine, decode, encode, ffi, qwen_ffi, ranges_layout, registered, +}; + +mod gr_microbatch_read_inject; +mod gr_microbatch_read_open; +mod micro_stage_launch; diff --git a/crates/cuda-driver/src/gr_batch_read/gr_microbatch_read/gr_microbatch_read_inject.rs b/crates/cuda-driver/src/qwen_dispatch/gr_batch_read/gr_microbatch_read/gr_microbatch_read_inject.rs similarity index 97% rename from crates/cuda-driver/src/gr_batch_read/gr_microbatch_read/gr_microbatch_read_inject.rs rename to crates/cuda-driver/src/qwen_dispatch/gr_batch_read/gr_microbatch_read/gr_microbatch_read_inject.rs index ad94c917..c1885db9 100644 --- a/crates/cuda-driver/src/gr_batch_read/gr_microbatch_read/gr_microbatch_read_inject.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gr_batch_read/gr_microbatch_read/gr_microbatch_read_inject.rs @@ -1,5 +1,5 @@ -//! Methods of `GrMicrobatchRead`: `inject`, `inject_handles`, `inject_admit`, `inject_arguments` and 11 more. -//! Split out of `gr_microbatch_read` to keep its files under the line limit. +//! Residual inject of the GR micro-batch read: uploads the blocks, runs the inject kernel and finite scan per row, +//! publishes the candidate as the next input bank, and closes the owner (buffers and helper module). use super::{ Arguments, Error, FixedKernel, GrMicrobatchRead, Operation, Result, combine, decode, encode, ffi, qwen_ffi, diff --git a/crates/cuda-driver/src/gr_batch_read/gr_microbatch_read/gr_microbatch_read_open.rs b/crates/cuda-driver/src/qwen_dispatch/gr_batch_read/gr_microbatch_read/gr_microbatch_read_open.rs similarity index 97% rename from crates/cuda-driver/src/gr_batch_read/gr_microbatch_read/gr_microbatch_read_open.rs rename to crates/cuda-driver/src/qwen_dispatch/gr_batch_read/gr_microbatch_read/gr_microbatch_read_open.rs index b00dce61..faa6aa82 100644 --- a/crates/cuda-driver/src/gr_batch_read/gr_microbatch_read/gr_microbatch_read_open.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gr_batch_read/gr_microbatch_read/gr_microbatch_read_open.rs @@ -1,5 +1,5 @@ -//! Methods of `GrMicrobatchRead`: `new`, `admit_inputs`, `open`, `load_finite` and 10 more. -//! Split out of `gr_microbatch_read` to keep its files under the line limit. +//! Opening the GR micro-batch read: input and budget admission, bank allocation, finite-scan helper loading, +//! accessors, alias checks against the weights, and the per-row kernel argument assembly. use super::{ Arguments, Context, DeviceBuffer, Error, GrMicrobatchRead, OPS, Operation, RESERVE, Result, SIZES, checked_row, diff --git a/crates/cuda-driver/src/gr_batch_read/gr_microbatch_read/micro_stage_launch.rs b/crates/cuda-driver/src/qwen_dispatch/gr_batch_read/gr_microbatch_read/micro_stage_launch.rs similarity index 97% rename from crates/cuda-driver/src/gr_batch_read/gr_microbatch_read/micro_stage_launch.rs rename to crates/cuda-driver/src/qwen_dispatch/gr_batch_read/gr_microbatch_read/micro_stage_launch.rs index 80b09420..9aeff621 100644 --- a/crates/cuda-driver/src/gr_batch_read/gr_microbatch_read/micro_stage_launch.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gr_batch_read/gr_microbatch_read/micro_stage_launch.rs @@ -1,5 +1,5 @@ -//! Methods of `GrMicrobatchRead`: `read`, `micro_kernels_guarded`, `micro_enqueue`, `micro_complete` and 6 more. -//! Defines `MicroKernels`. +//! The read of the GR micro-batch: per row the six GR kernels each followed by a finite scan, enqueued, fenced and +//! settled so an earlier numerical refusal wins over a later enqueue failure; products are decoded on success. use super::{ Arguments, DeviceBuffer, Error, FixedKernel, GrMicroValues, GrMicrobatchRead, OPS, Result, SIZES, STAGES, combine, diff --git a/crates/cuda-driver/src/gr_batch_read/gr_microbatch_read_drop.rs b/crates/cuda-driver/src/qwen_dispatch/gr_batch_read/gr_microbatch_read_drop.rs similarity index 82% rename from crates/cuda-driver/src/gr_batch_read/gr_microbatch_read_drop.rs rename to crates/cuda-driver/src/qwen_dispatch/gr_batch_read/gr_microbatch_read_drop.rs index 6ee6d183..c1050240 100644 --- a/crates/cuda-driver/src/gr_batch_read/gr_microbatch_read_drop.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gr_batch_read/gr_microbatch_read_drop.rs @@ -1,5 +1,4 @@ -//! Implements `Drop for GrMicrobatchRead`. Functions: `decode`. -//! Split out of `gr_batch_read` to keep its files under the line limit. +//! Drop of the GR micro-batch read (closes it) and the decoding of a device buffer to finite canonical f32 values. use super::{DeviceBuffer, Error, GrMicrobatchRead, Result}; diff --git a/crates/cuda-driver/src/gr_native_batch.rs b/crates/cuda-driver/src/qwen_dispatch/gr_native_batch.rs similarity index 84% rename from crates/cuda-driver/src/gr_native_batch.rs rename to crates/cuda-driver/src/qwen_dispatch/gr_native_batch.rs index 46930a93..933d41ed 100644 --- a/crates/cuda-driver/src/gr_native_batch.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gr_native_batch.rs @@ -5,7 +5,7 @@ use crate::ple_batch_ffi::{BatchArg as A, Blas, KernelArguments, KernelModule}; use crate::{CurrentGuard, NativeBatchWorkspace}; use std::ffi::CStr; -const PTX: &[u8] = concat!(include_str!("gr_native_batch.ptx"), "\0").as_bytes(); +const PTX: &[u8] = concat!(include_str!("../gr_native_batch.ptx"), "\0").as_bytes(); const ENTRIES: &[&CStr] = &[ c"gr_norm_rs_kernel", c"gr_silu_kernel", @@ -46,13 +46,8 @@ pub struct GrNativeBatch<'ctx> { failed: bool, } -#[path = "gr_native_batch/context.rs"] mod context; -#[allow(unused_imports)] use context::decode; -#[allow(unused_imports)] use context::encode; -#[path = "gr_native_batch/gr_native_batch_drop.rs"] mod gr_native_batch_drop; -#[path = "gr_native_batch/gr_native_batch_operations.rs"] mod gr_native_batch_operations; diff --git a/crates/cuda-driver/src/gr_native_batch/context.rs b/crates/cuda-driver/src/qwen_dispatch/gr_native_batch/context.rs similarity index 88% rename from crates/cuda-driver/src/gr_native_batch/context.rs rename to crates/cuda-driver/src/qwen_dispatch/gr_native_batch/context.rs index a4245dcd..daa5ae8b 100644 --- a/crates/cuda-driver/src/gr_native_batch/context.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gr_native_batch/context.rs @@ -1,5 +1,5 @@ -//! Methods of `Context`: `gr_native_batch`, `gr_native_prompt_batch`. Functions: `encode`, `decode`. -//! Split out of `gr_native_batch` to keep its files under the line limit. +//! Context constructors of the native GR batch (decode and prompt-sized variants) and the f32 byte encode and +//! finite-checked decode helpers. use super::{Context, DeviceBuffer, Error, GrNativeBatch, GrNativeProfile, Result}; diff --git a/crates/cuda-driver/src/gr_native_batch/gr_native_batch_drop.rs b/crates/cuda-driver/src/qwen_dispatch/gr_native_batch/gr_native_batch_drop.rs similarity index 53% rename from crates/cuda-driver/src/gr_native_batch/gr_native_batch_drop.rs rename to crates/cuda-driver/src/qwen_dispatch/gr_native_batch/gr_native_batch_drop.rs index f76b3277..c5920c72 100644 --- a/crates/cuda-driver/src/gr_native_batch/gr_native_batch_drop.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gr_native_batch/gr_native_batch_drop.rs @@ -1,5 +1,4 @@ -//! Implements `Drop for GrNativeBatch`. -//! Split out of `gr_native_batch` to keep its files under the line limit. +//! Drop of the native GR batch: closes it and ignores the result. use super::GrNativeBatch; diff --git a/crates/cuda-driver/src/gr_native_batch/gr_native_batch_operations.rs b/crates/cuda-driver/src/qwen_dispatch/gr_native_batch/gr_native_batch_operations.rs similarity index 74% rename from crates/cuda-driver/src/gr_native_batch/gr_native_batch_operations.rs rename to crates/cuda-driver/src/qwen_dispatch/gr_native_batch/gr_native_batch_operations.rs index 94278a0a..f248644f 100644 --- a/crates/cuda-driver/src/gr_native_batch/gr_native_batch_operations.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gr_native_batch/gr_native_batch_operations.rs @@ -7,9 +7,6 @@ use super::{ KernelArguments, KernelModule, NativeBatchWorkspace, PTX, RESERVE, Result, STAGES, combine, decode, encode, ffi, }; -#[path = "gr_native_batch_operations/native_command_drain.rs"] mod native_command_drain; -#[path = "gr_native_batch_operations/native_gemm_launch.rs"] mod native_gemm_launch; -#[path = "gr_native_batch_operations/native_inject.rs"] mod native_inject; diff --git a/crates/cuda-driver/src/gr_native_batch/gr_native_batch_operations/native_command_drain.rs b/crates/cuda-driver/src/qwen_dispatch/gr_native_batch/gr_native_batch_operations/native_command_drain.rs similarity index 98% rename from crates/cuda-driver/src/gr_native_batch/gr_native_batch_operations/native_command_drain.rs rename to crates/cuda-driver/src/qwen_dispatch/gr_native_batch/gr_native_batch_operations/native_command_drain.rs index c0993ded..f3035ab6 100644 --- a/crates/cuda-driver/src/gr_native_batch/gr_native_batch_operations/native_command_drain.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gr_native_batch/gr_native_batch_operations/native_command_drain.rs @@ -1,5 +1,5 @@ -//! Methods of `GrNativeBatch`: `finish`, `native_status`, `native_settle`, `native_fail` and 13 more. -//! Defines `NativeDrain`. +//! Native GR read: builds the kernel arguments and command list in the literal Original order, drains the vendor +//! stream, reads the finite status words back and settles them (a failed drain or pop poisons the context). use super::native_gemm_launch::GemmRoles; use super::{ diff --git a/crates/cuda-driver/src/gr_native_batch/gr_native_batch_operations/native_gemm_launch.rs b/crates/cuda-driver/src/qwen_dispatch/gr_native_batch/gr_native_batch_operations/native_gemm_launch.rs similarity index 97% rename from crates/cuda-driver/src/gr_native_batch/gr_native_batch_operations/native_gemm_launch.rs rename to crates/cuda-driver/src/qwen_dispatch/gr_native_batch/gr_native_batch_operations/native_gemm_launch.rs index 4b4d1274..9f42f75b 100644 --- a/crates/cuda-driver/src/gr_native_batch/gr_native_batch_operations/native_gemm_launch.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gr_native_batch/gr_native_batch_operations/native_gemm_launch.rs @@ -1,5 +1,5 @@ -//! Methods of `GrNativeBatch`: `prompt_device_bytes`, `new`, `new_bounded`, `check_new_inputs` and 15 more. -//! Defines `GemmRoles`. +//! Construction and plumbing of the native GR batch: sizing, admission, buffer and module setup, alias checks, +//! kernel argument helpers, and the Original GEMM over the high (and low) image. use super::{ A, BYTES, Blas, Context, DeviceBuffer, ENTRIES, Error, GrNativeBatch, GrNativeProfile, KernelArguments, diff --git a/crates/cuda-driver/src/gr_native_batch/gr_native_batch_operations/native_inject.rs b/crates/cuda-driver/src/qwen_dispatch/gr_native_batch/gr_native_batch_operations/native_inject.rs similarity index 96% rename from crates/cuda-driver/src/gr_native_batch/gr_native_batch_operations/native_inject.rs rename to crates/cuda-driver/src/qwen_dispatch/gr_native_batch/gr_native_batch_operations/native_inject.rs index 908906e8..6c551e67 100644 --- a/crates/cuda-driver/src/gr_native_batch/gr_native_batch_operations/native_inject.rs +++ b/crates/cuda-driver/src/qwen_dispatch/gr_native_batch/gr_native_batch_operations/native_inject.rs @@ -1,5 +1,5 @@ -//! Methods of `GrNativeBatch`: `inject`, `check_inject`, `stage_blocks`, `inject_args` and 6 more. -//! Defines `StatusReset`. +//! Residual inject of the native GR batch: stages the blocks, enqueues the inject kernel and scans, and takes the +//! injected result; also closing the batch (module and buffer retirement). use super::native_command_drain::NativeDrain; use super::{ diff --git a/crates/cuda-driver/src/moe_prefill_batch.rs b/crates/cuda-driver/src/qwen_dispatch/moe_prefill_batch.rs similarity index 94% rename from crates/cuda-driver/src/moe_prefill_batch.rs rename to crates/cuda-driver/src/qwen_dispatch/moe_prefill_batch.rs index 9bf0eee8..aab1ce61 100644 --- a/crates/cuda-driver/src/moe_prefill_batch.rs +++ b/crates/cuda-driver/src/qwen_dispatch/moe_prefill_batch.rs @@ -230,24 +230,18 @@ struct Drained { } #[cfg(test)] -#[path = "moe_prefill_batch/tests.rs"] +#[path = "../moe_prefill_batch/tests.rs"] mod tests; #[cfg(all(test, feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_arch = "x86_64"))] -#[path = "moe_prefill_batch_gpu.rs"] mod gpu; -#[path = "moe_prefill_batch/pinned.rs"] mod pinned; -#[allow(unused_imports)] use pinned::decode_statuses; -#[allow(unused_imports)] use pinned::format_index; -#[allow(unused_imports)] use pinned::linear; -#[allow(unused_imports)] +#[cfg(test)] use pinned::pinned; -#[allow(unused_imports)] pub(crate) use pinned::prefill_asset; /// The three caller-lent combine inputs: the route weights `[t][10]`, the shared output `[t][2560]` and the scalar /// gate logits `[t]`, all f32. @@ -258,15 +252,9 @@ pub struct MoeCombineInputs<'lease> { pub sg: &'lease DeviceBuffer<'lease>, } -#[path = "moe_prefill_batch/moe_batch_prefix.rs"] mod moe_batch_prefix; -#[path = "moe_prefill_batch/moe_prefill_batch_lifecycle.rs"] mod moe_prefill_batch_lifecycle; -#[path = "moe_prefill_batch/words.rs"] mod words; -#[allow(unused_imports)] use words::check_slot_map; -#[allow(unused_imports)] use words::staging; -#[allow(unused_imports)] use words::words; diff --git a/crates/cuda-driver/src/moe_prefill_batch_gpu.rs b/crates/cuda-driver/src/qwen_dispatch/moe_prefill_batch/gpu.rs similarity index 83% rename from crates/cuda-driver/src/moe_prefill_batch_gpu.rs rename to crates/cuda-driver/src/qwen_dispatch/moe_prefill_batch/gpu.rs index f77aba6c..8aa1a36b 100644 --- a/crates/cuda-driver/src/moe_prefill_batch_gpu.rs +++ b/crates/cuda-driver/src/qwen_dispatch/moe_prefill_batch/gpu.rs @@ -78,45 +78,24 @@ fn strata_prefill_moe_program_runs_in_order_refuses_earliest_and_cleans_up() { assert_eq!(leaked, 0, "bytes still allocated after close"); } -#[path = "moe_prefill_batch_gpu/bytes_of.rs"] mod bytes_of; -#[allow(unused_imports)] use bytes_of::bf_bits; -#[allow(unused_imports)] use bytes_of::bf_value; -#[allow(unused_imports)] use bytes_of::bytes_of; -#[allow(unused_imports)] use bytes_of::close; -#[allow(unused_imports)] use bytes_of::f16_bits; -#[allow(unused_imports)] use bytes_of::f16_value; -#[allow(unused_imports)] use bytes_of::halves_of; -#[allow(unused_imports)] use bytes_of::mismatch; -#[allow(unused_imports)] use bytes_of::pattern; -#[allow(unused_imports)] use bytes_of::q8_0; -#[allow(unused_imports)] use bytes_of::read; -#[allow(unused_imports)] use bytes_of::sigm; -#[allow(unused_imports)] use bytes_of::upload; -#[allow(unused_imports)] use bytes_of::words_of; -#[path = "moe_prefill_batch_gpu/fixture.rs"] mod fixture; -#[allow(unused_imports)] use fixture::{Window, run_case}; -#[path = "moe_prefill_batch_gpu/program_cases.rs"] mod program_cases; -#[allow(unused_imports)] use program_cases::run_program_cases; -#[path = "moe_prefill_batch_gpu/clean_window_check.rs"] mod clean_window_check; -#[allow(unused_imports)] use clean_window_check::check_clean; diff --git a/crates/cuda-driver/src/moe_prefill_batch_gpu/bytes_of.rs b/crates/cuda-driver/src/qwen_dispatch/moe_prefill_batch/gpu/bytes_of.rs similarity index 96% rename from crates/cuda-driver/src/moe_prefill_batch_gpu/bytes_of.rs rename to crates/cuda-driver/src/qwen_dispatch/moe_prefill_batch/gpu/bytes_of.rs index d232f7d4..5f5ff615 100644 --- a/crates/cuda-driver/src/moe_prefill_batch_gpu/bytes_of.rs +++ b/crates/cuda-driver/src/qwen_dispatch/moe_prefill_batch/gpu/bytes_of.rs @@ -1,5 +1,5 @@ -//! Methods of `HostGemm`: `run`, `poison_output`. Implements `GdnGemm for HostGemm`. -//! Functions: `bytes_of`, `words_of`, `halves_of`, `f16_bits` and 13 more. +//! Host-side helpers of the MoE prefill GPU smoke test: FP16/BF16 conversions, Q8_0 blocks, deterministic patterns, +//! and HostGemm, the host stand-in for the closed cuBLAS GEMM adapter (it records calls and can poison an output word). use super::{ Context, DeviceBuffer, EXPERTS, Error, GdnGemm, GdnStream, GemmShape, HostGemm, Q8_0_BLOCK, Result, combine, diff --git a/crates/cuda-driver/src/moe_prefill_batch_gpu/clean_window_check.rs b/crates/cuda-driver/src/qwen_dispatch/moe_prefill_batch/gpu/clean_window_check.rs similarity index 96% rename from crates/cuda-driver/src/moe_prefill_batch_gpu/clean_window_check.rs rename to crates/cuda-driver/src/qwen_dispatch/moe_prefill_batch/gpu/clean_window_check.rs index d17a28ee..491e3885 100644 --- a/crates/cuda-driver/src/moe_prefill_batch_gpu/clean_window_check.rs +++ b/crates/cuda-driver/src/qwen_dispatch/moe_prefill_batch/gpu/clean_window_check.rs @@ -1,5 +1,5 @@ -//! Functions: `check_clean`, `check_down_reads_h`, `check_dequantized_scratch`, `check_mixed_images` and 5 more. -//! Split out of `gpu` to keep its files under the line limit. +//! Checks of a clean MoE prefill window in the GPU smoke test: GEMM call sequence, dequantization, image packing, +//! route against a host softmax/top-10, shared SwiGLU and the combine, all against host references. use super::{ Captured, EXPERTS, Error, FF, Fixture, HostGemm, MoeRouteBatch, N, Result, SELECTED, Window, bf_bits, bf_value, diff --git a/crates/cuda-driver/src/moe_prefill_batch_gpu/fixture.rs b/crates/cuda-driver/src/qwen_dispatch/moe_prefill_batch/gpu/fixture.rs similarity index 97% rename from crates/cuda-driver/src/moe_prefill_batch_gpu/fixture.rs rename to crates/cuda-driver/src/qwen_dispatch/moe_prefill_batch/gpu/fixture.rs index 09a00613..e67d0424 100644 --- a/crates/cuda-driver/src/moe_prefill_batch_gpu/fixture.rs +++ b/crates/cuda-driver/src/qwen_dispatch/moe_prefill_batch/gpu/fixture.rs @@ -1,5 +1,5 @@ -//! Methods of `Fixture`: `new`, `release`. Methods of `Images`: `new`. -//! Functions: `blank`, `bf16_matrix`, `run_case`, `run_window` and 1 more. Defines `Window`. +//! Fixture of the MoE prefill GPU smoke test: uploaded inputs and blank outputs (images, routing, experts, +//! products), the Window describing one program run, and run_case/run_window which enqueue the full program. use super::{ Captured, Cell, Context, DeviceBuffer, EXPERTS, Error, Experts, FF, Fixture, GdnNativeFormat, HostGemm, Images, diff --git a/crates/cuda-driver/src/moe_prefill_batch_gpu/program_cases.rs b/crates/cuda-driver/src/qwen_dispatch/moe_prefill_batch/gpu/program_cases.rs similarity index 100% rename from crates/cuda-driver/src/moe_prefill_batch_gpu/program_cases.rs rename to crates/cuda-driver/src/qwen_dispatch/moe_prefill_batch/gpu/program_cases.rs diff --git a/crates/cuda-driver/src/moe_prefill_batch/moe_batch_prefix.rs b/crates/cuda-driver/src/qwen_dispatch/moe_prefill_batch/moe_batch_prefix.rs similarity index 56% rename from crates/cuda-driver/src/moe_prefill_batch/moe_batch_prefix.rs rename to crates/cuda-driver/src/qwen_dispatch/moe_prefill_batch/moe_batch_prefix.rs index f8d3fa6a..4daf2a9a 100644 --- a/crates/cuda-driver/src/moe_prefill_batch/moe_batch_prefix.rs +++ b/crates/cuda-driver/src/qwen_dispatch/moe_prefill_batch/moe_batch_prefix.rs @@ -1,5 +1,5 @@ -//! Groups the submodules `combine_stage`, `moe_batch_prefix_router_pack`, `shared_expert_projections`. -//! Split out of `moe_prefill_batch` to keep its files under the line limit. +//! The MoE batch prefix: an owned program of router, shared-expert and optional combine stages over a token window; +//! the submodules split it into router/binding base, shared-expert projections, and the combine plus drain. use super::{ Command, Context, DeviceBuffer, Drained, EXPERTS, Error, F16, F32, FF, GdnNativeFormat, GemmShape, @@ -8,9 +8,6 @@ use super::{ staging, words, }; -#[path = "moe_batch_prefix/combine_stage.rs"] mod combine_stage; -#[path = "moe_batch_prefix/moe_batch_prefix_router_pack.rs"] mod moe_batch_prefix_router_pack; -#[path = "moe_batch_prefix/shared_expert_projections.rs"] mod shared_expert_projections; diff --git a/crates/cuda-driver/src/moe_prefill_batch/moe_batch_prefix/combine_stage.rs b/crates/cuda-driver/src/qwen_dispatch/moe_prefill_batch/moe_batch_prefix/combine_stage.rs similarity index 97% rename from crates/cuda-driver/src/moe_prefill_batch/moe_batch_prefix/combine_stage.rs rename to crates/cuda-driver/src/qwen_dispatch/moe_prefill_batch/moe_batch_prefix/combine_stage.rs index e27f5118..d425a928 100644 --- a/crates/cuda-driver/src/moe_prefill_batch/moe_batch_prefix/combine_stage.rs +++ b/crates/cuda-driver/src/qwen_dispatch/moe_prefill_batch/moe_batch_prefix/combine_stage.rs @@ -1,5 +1,5 @@ -//! Methods of `MoeBatchPrefix`: `combine_from`, `combine_body`, `combine_inputs`, `upload_slot_map` and 8 more. -//! Methods of `DrainStaging`: `new`. Defines `DrainStaging`. +//! Tail of the MoE batch prefix: the combine-only program and combine body (row-map upload), finish, and the fenced +//! drain that reads the status words and optional route back after one completion fence (failures poison the context). use super::{ Context, DeviceBuffer, Drained, EXPERTS, Error, F32, MoeBatchCompletion, MoeBatchPrefix, MoeBatchStage, diff --git a/crates/cuda-driver/src/moe_prefill_batch/moe_batch_prefix/moe_batch_prefix_router_pack.rs b/crates/cuda-driver/src/qwen_dispatch/moe_prefill_batch/moe_batch_prefix/moe_batch_prefix_router_pack.rs similarity index 97% rename from crates/cuda-driver/src/moe_prefill_batch/moe_batch_prefix/moe_batch_prefix_router_pack.rs rename to crates/cuda-driver/src/qwen_dispatch/moe_prefill_batch/moe_batch_prefix/moe_batch_prefix_router_pack.rs index f5927882..bac7ceb5 100644 --- a/crates/cuda-driver/src/moe_prefill_batch/moe_batch_prefix/moe_batch_prefix_router_pack.rs +++ b/crates/cuda-driver/src/qwen_dispatch/moe_prefill_batch/moe_batch_prefix/moe_batch_prefix_router_pack.rs @@ -1,5 +1,5 @@ -//! Methods of `MoeBatchPrefix`: `tokens`, `ready`, `latch`, `moe_function` and 13 more. -//! Functions: `bind_size_admitted`. +//! Base and router head of the MoE batch prefix: step order, role-bound buffer admission, kernel pushes, ordered finite +//! scans, packing of the mixed activation images, and the BF16 router with its top-10 route kernel. use super::{ Command, DeviceBuffer, EXPERTS, Error, F16, F32, GemmShape, MoeBatchPrefix, MoeBatchStage, MoeKernel, N, Result, diff --git a/crates/cuda-driver/src/moe_prefill_batch/moe_batch_prefix/shared_expert_projections.rs b/crates/cuda-driver/src/qwen_dispatch/moe_prefill_batch/moe_batch_prefix/shared_expert_projections.rs similarity index 97% rename from crates/cuda-driver/src/moe_prefill_batch/moe_batch_prefix/shared_expert_projections.rs rename to crates/cuda-driver/src/qwen_dispatch/moe_prefill_batch/moe_batch_prefix/shared_expert_projections.rs index 4926988d..3b75ff50 100644 --- a/crates/cuda-driver/src/moe_prefill_batch/moe_batch_prefix/shared_expert_projections.rs +++ b/crates/cuda-driver/src/qwen_dispatch/moe_prefill_batch/moe_batch_prefix/shared_expert_projections.rs @@ -1,5 +1,5 @@ -//! Methods of `MoeBatchPrefix`: `project_native`, `push_dequant`, `shared_gate`, `shared_up` and 4 more. -//! Defines `NativeProjection`, `ProjectionOperands`. +//! Shared-expert stages of the MoE batch prefix: native dequantize-then-GEMM projections (gate, up, down), the SwiGLU +//! pair, the shared scalar gate, and the optional combine kernel, each followed by its finite scan. use super::{ Command, DeviceBuffer, Error, F16, F32, FF, GdnNativeFormat, GemmShape, MoeBatchPrefix, MoeBatchStage, MoeKernel, diff --git a/crates/cuda-driver/src/moe_prefill_batch/moe_prefill_batch_lifecycle.rs b/crates/cuda-driver/src/qwen_dispatch/moe_prefill_batch/moe_prefill_batch_lifecycle.rs similarity index 100% rename from crates/cuda-driver/src/moe_prefill_batch/moe_prefill_batch_lifecycle.rs rename to crates/cuda-driver/src/qwen_dispatch/moe_prefill_batch/moe_prefill_batch_lifecycle.rs diff --git a/crates/cuda-driver/src/moe_prefill_batch/pinned.rs b/crates/cuda-driver/src/qwen_dispatch/moe_prefill_batch/pinned.rs similarity index 93% rename from crates/cuda-driver/src/moe_prefill_batch/pinned.rs rename to crates/cuda-driver/src/qwen_dispatch/moe_prefill_batch/pinned.rs index ba66e9e5..b0c73640 100644 --- a/crates/cuda-driver/src/moe_prefill_batch/pinned.rs +++ b/crates/cuda-driver/src/qwen_dispatch/moe_prefill_batch/pinned.rs @@ -1,5 +1,5 @@ -//! Methods of `MoeKernel`: `entry`, `index`. Methods of `MoeBatchStage`: `slot`, `elements`, `is_half`, `bytes`. -//! Functions: `pinned`, `prefill_asset`, `format_index`, `linear` and 1 more. +//! Pinned sealed PTX of the MoE prefill kernels (digest-checked), kernel entry names, weight format indices, the stage +//! table (slot, elements, bytes), status decoding, step order, role bindings and the Context constructor. use super::{ Bindings, Context, EXPERTS, Error, F16, F32, FF, GdnNativeFormat, MOE_PTX_LEN, MOE_PTX_SHA256, MoeBatchStage, @@ -20,7 +20,7 @@ pub(super) fn pinned(ptx: &'static [u8], len: usize, digest: [u8; 32]) -> Result Ok(ptx) } pub(crate) fn prefill_asset() -> Result<&'static [u8]> { - pinned(concat!(include_str!("../offline_moe_prefill.ptx"), "\0").as_bytes(), MOE_PTX_LEN, MOE_PTX_SHA256) + pinned(concat!(include_str!("../../offline_moe_prefill.ptx"), "\0").as_bytes(), MOE_PTX_LEN, MOE_PTX_SHA256) } impl MoeKernel { pub(crate) fn entry(self) -> &'static std::ffi::CStr { diff --git a/crates/cuda-driver/src/moe_prefill_batch/words.rs b/crates/cuda-driver/src/qwen_dispatch/moe_prefill_batch/words.rs similarity index 94% rename from crates/cuda-driver/src/moe_prefill_batch/words.rs rename to crates/cuda-driver/src/qwen_dispatch/moe_prefill_batch/words.rs index ebeb807d..bb324af2 100644 --- a/crates/cuda-driver/src/moe_prefill_batch/words.rs +++ b/crates/cuda-driver/src/qwen_dispatch/moe_prefill_batch/words.rs @@ -1,5 +1,5 @@ -//! Methods of `MoePrefillBatch`: `close_inner`, `retire_buffer`, `retire_module`. -//! Implements `Drop for MoePrefillBatch`. Functions: `words`, `check_slot_map`, `staging`. +//! Teardown of the MoE prefill batch owner (buffer and module retirement, Drop), host word and staging helpers, +//! and the check that the routed-row map is a permutation of all routed rows. use super::{DeviceBuffer, Error, MOE_BATCH_MAX_TOKENS, MoePrefillBatch, Result, SELECTED, combine, ffi}; diff --git a/crates/cuda-driver/src/mtp_input_workspace.rs b/crates/cuda-driver/src/qwen_dispatch/mtp_input_workspace.rs similarity index 93% rename from crates/cuda-driver/src/mtp_input_workspace.rs rename to crates/cuda-driver/src/qwen_dispatch/mtp_input_workspace.rs index 61df5298..c08980fd 100644 --- a/crates/cuda-driver/src/mtp_input_workspace.rs +++ b/crates/cuda-driver/src/qwen_dispatch/mtp_input_workspace.rs @@ -88,14 +88,9 @@ enum Command { } #[cfg(all(test, feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_arch = "x86_64"))] -#[path = "mtp_input_workspace_gpu.rs"] mod gpu; -#[path = "mtp_input_workspace/mtp_input_completion.rs"] mod mtp_input_completion; -#[path = "mtp_input_workspace/mtp_input_prefix.rs"] mod mtp_input_prefix; -#[path = "mtp_input_workspace/mtp_input_workspace_lifecycle.rs"] mod mtp_input_workspace_lifecycle; -#[allow(unused_imports)] use mtp_input_workspace_lifecycle::staging; diff --git a/crates/cuda-driver/src/mtp_input_workspace_gpu.rs b/crates/cuda-driver/src/qwen_dispatch/mtp_input_workspace/gpu.rs similarity index 85% rename from crates/cuda-driver/src/mtp_input_workspace_gpu.rs rename to crates/cuda-driver/src/qwen_dispatch/mtp_input_workspace/gpu.rs index 2c3bd045..5d424567 100644 --- a/crates/cuda-driver/src/mtp_input_workspace_gpu.rs +++ b/crates/cuda-driver/src/qwen_dispatch/mtp_input_workspace/gpu.rs @@ -67,33 +67,14 @@ fn check_report(report: &Report, allocated: [usize; 3], poisoned: bool) { assert_eq!(report.numeric, 6); assert_eq!(report.guards, report.refusals); } -#[path = "mtp_input_workspace_gpu/bytes.rs"] mod bytes; -#[allow(unused_imports)] use bytes::bytes; -#[allow(unused_imports)] -use bytes::compare; -#[allow(unused_imports)] use bytes::finite_case; -#[allow(unused_imports)] -use bytes::full_finite; -#[allow(unused_imports)] use bytes::inputs; -#[allow(unused_imports)] use bytes::original; -#[allow(unused_imports)] use bytes::queue; -#[allow(unused_imports)] use bytes::raw; -#[allow(unused_imports)] -use bytes::read; -#[allow(unused_imports)] use bytes::refuse; -#[allow(unused_imports)] use bytes::upload; -#[path = "mtp_input_workspace_gpu/numeric_case.rs"] mod numeric_case; -#[allow(unused_imports)] -use numeric_case::numeric_case; -#[allow(unused_imports)] use numeric_case::run; diff --git a/crates/cuda-driver/src/mtp_input_workspace_gpu/bytes.rs b/crates/cuda-driver/src/qwen_dispatch/mtp_input_workspace/gpu/bytes.rs similarity index 97% rename from crates/cuda-driver/src/mtp_input_workspace_gpu/bytes.rs rename to crates/cuda-driver/src/qwen_dispatch/mtp_input_workspace/gpu/bytes.rs index f89112d9..ab453fbf 100644 --- a/crates/cuda-driver/src/mtp_input_workspace_gpu/bytes.rs +++ b/crates/cuda-driver/src/qwen_dispatch/mtp_input_workspace/gpu/bytes.rs @@ -1,5 +1,5 @@ -//! Functions: `bytes`, `upload`, `read`, `full_finite` and 13 more. Defines `Step`. -//! Split out of `gpu` to keep its files under the line limit. +//! Fixtures and the original reference of the MTP input GPU test: byte helpers, inputs, comparison and refusal +//! checks, the independent scalar sequence of norms, projections and broadcast, and the queued candidate readback. use super::{ Context, DenseFormat, DeviceBuffer, Error, MtpInputCompletion, MtpInputRefusal, MtpInputWorkspace, Numeric, diff --git a/crates/cuda-driver/src/mtp_input_workspace_gpu/numeric_case.rs b/crates/cuda-driver/src/qwen_dispatch/mtp_input_workspace/gpu/numeric_case.rs similarity index 97% rename from crates/cuda-driver/src/mtp_input_workspace_gpu/numeric_case.rs rename to crates/cuda-driver/src/qwen_dispatch/mtp_input_workspace/gpu/numeric_case.rs index fc6fdb12..066345a9 100644 --- a/crates/cuda-driver/src/mtp_input_workspace_gpu/numeric_case.rs +++ b/crates/cuda-driver/src/qwen_dispatch/mtp_input_workspace/gpu/numeric_case.rs @@ -1,5 +1,5 @@ -//! Functions: `numeric_case`, `run`, `run_cases`, `upload_corpus` and 5 more. -//! Split out of `gpu` to keep its files under the line limit. +//! Numeric and refusal cases of the MTP input GPU test: non-finite inputs must refuse at the same stage as the +//! original sequence, malformed sources and weights are refused, and the prefix stays drainable. use super::{ Context, DeviceBuffer, Error, MtpInputRefusal, MtpInputWorkspace, Numeric, Report, Result, STAGES, TOTAL, bytes, diff --git a/crates/cuda-driver/src/mtp_input_workspace/mtp_input_completion.rs b/crates/cuda-driver/src/qwen_dispatch/mtp_input_workspace/mtp_input_completion.rs similarity index 96% rename from crates/cuda-driver/src/mtp_input_workspace/mtp_input_completion.rs rename to crates/cuda-driver/src/qwen_dispatch/mtp_input_workspace/mtp_input_completion.rs index d688b093..e910b685 100644 --- a/crates/cuda-driver/src/mtp_input_workspace/mtp_input_completion.rs +++ b/crates/cuda-driver/src/qwen_dispatch/mtp_input_workspace/mtp_input_completion.rs @@ -1,5 +1,5 @@ -//! Methods of `MtpInputCompletion`: `numerical_refusal`, `refusal_stage`, `into_streams`. -//! Methods of `Context`: `mtp_input_workspace`. Functions: `qwen_functions`, `stage_inputs`. +//! The MTP input workspace owner and its completion: Context constructor, admission, bring-up (kernels and nine +//! private owners), begin, close, and the completion that reports a numerical refusal or hands out the streams. use super::{ Context, DenseFormat, DeviceBuffer, Error, Kernels, MtpInputCompletion, MtpInputPrefix, MtpInputRefusal, diff --git a/crates/cuda-driver/src/mtp_input_workspace/mtp_input_prefix.rs b/crates/cuda-driver/src/qwen_dispatch/mtp_input_workspace/mtp_input_prefix.rs similarity index 98% rename from crates/cuda-driver/src/mtp_input_workspace/mtp_input_prefix.rs rename to crates/cuda-driver/src/qwen_dispatch/mtp_input_workspace/mtp_input_prefix.rs index de912931..19e2b9c3 100644 --- a/crates/cuda-driver/src/mtp_input_workspace/mtp_input_prefix.rs +++ b/crates/cuda-driver/src/qwen_dispatch/mtp_input_workspace/mtp_input_prefix.rs @@ -1,5 +1,5 @@ -//! Methods of `MtpInputPrefix`: `weight`, `ready`, `latch`, `status` and 14 more. Methods of `DrainStaging`: `new`. -//! Functions: `first_refusal`, `queue_qwen`, `square_shape`. Defines `DrainStaging`. +//! Builder of the MTP input prefix: queues the embedding norm, projections and broadcast one admitted phase at a time. +//! Its drain uploads inputs, runs the queue, reads the status words and turns the first nonzero one into a refusal. use super::{ Admission, Arguments, Command, Context, DenseFormat, DeviceBuffer, Drained, Error, MtpInputCompletion, diff --git a/crates/cuda-driver/src/mtp_input_workspace/mtp_input_workspace_lifecycle.rs b/crates/cuda-driver/src/qwen_dispatch/mtp_input_workspace/mtp_input_workspace_lifecycle.rs similarity index 100% rename from crates/cuda-driver/src/mtp_input_workspace/mtp_input_workspace_lifecycle.rs rename to crates/cuda-driver/src/qwen_dispatch/mtp_input_workspace/mtp_input_workspace_lifecycle.rs diff --git a/crates/cuda-driver/src/ple_closed_queue.rs b/crates/cuda-driver/src/qwen_dispatch/ple_closed_queue.rs similarity index 88% rename from crates/cuda-driver/src/ple_closed_queue.rs rename to crates/cuda-driver/src/qwen_dispatch/ple_closed_queue.rs index 7e5e115e..b9c1bad2 100644 --- a/crates/cuda-driver/src/ple_closed_queue.rs +++ b/crates/cuda-driver/src/qwen_dispatch/ple_closed_queue.rs @@ -73,20 +73,12 @@ enum Command { } #[cfg(all(test, feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_arch = "x86_64"))] -#[path = "ple_closed_queue_gpu.rs"] mod gpu; -#[path = "ple_closed_queue/compose_phases.rs"] mod compose_phases; -#[path = "ple_closed_queue/ple_closed_completion.rs"] mod ple_closed_completion; -#[path = "ple_closed_queue/ple_closed_queue_compose_close.rs"] mod ple_closed_queue_compose_close; -#[allow(unused_imports)] use ple_closed_queue_compose_close::float_staging; -#[allow(unused_imports)] use ple_closed_queue_compose_close::staging; -#[path = "ple_closed_queue/float_owner.rs"] mod float_owner; -#[allow(unused_imports)] use float_owner::float_owner; diff --git a/crates/cuda-driver/src/ple_closed_queue/compose_phases.rs b/crates/cuda-driver/src/qwen_dispatch/ple_closed_queue/compose_phases.rs similarity index 100% rename from crates/cuda-driver/src/ple_closed_queue/compose_phases.rs rename to crates/cuda-driver/src/qwen_dispatch/ple_closed_queue/compose_phases.rs diff --git a/crates/cuda-driver/src/ple_closed_queue/float_owner.rs b/crates/cuda-driver/src/qwen_dispatch/ple_closed_queue/float_owner.rs similarity index 77% rename from crates/cuda-driver/src/ple_closed_queue/float_owner.rs rename to crates/cuda-driver/src/qwen_dispatch/ple_closed_queue/float_owner.rs index c3cbd70b..6bf5f1f6 100644 --- a/crates/cuda-driver/src/ple_closed_queue/float_owner.rs +++ b/crates/cuda-driver/src/qwen_dispatch/ple_closed_queue/float_owner.rs @@ -1,5 +1,5 @@ -//! Methods of `Command`: `launch`. Functions: `float_owner`. -//! Split out of `ple_closed_queue` to keep its files under the line limit. +//! Host f32 allocation helper and the launch of one queued PLE command (a Qwen operator or a finite-guard kernel). +//! Kept apart so the queue files share one place that turns a command into a driver launch. use super::{Command, Context, Error, Result}; diff --git a/crates/cuda-driver/src/ple_closed_queue_gpu.rs b/crates/cuda-driver/src/qwen_dispatch/ple_closed_queue/gpu.rs similarity index 99% rename from crates/cuda-driver/src/ple_closed_queue_gpu.rs rename to crates/cuda-driver/src/qwen_dispatch/ple_closed_queue/gpu.rs index aaa3a6de..e3bdad46 100644 --- a/crates/cuda-driver/src/ple_closed_queue_gpu.rs +++ b/crates/cuda-driver/src/qwen_dispatch/ple_closed_queue/gpu.rs @@ -365,6 +365,5 @@ fn causal_history_cases<'c>( } Ok(history) } -#[path = "ple_closed_queue_gpu/refusal.rs"] mod refusal; use refusal::{corrupted_weight_cases, foreign_weight_case, invalid_input_cases}; diff --git a/crates/cuda-driver/src/ple_closed_queue_gpu/refusal.rs b/crates/cuda-driver/src/qwen_dispatch/ple_closed_queue/gpu/refusal.rs similarity index 100% rename from crates/cuda-driver/src/ple_closed_queue_gpu/refusal.rs rename to crates/cuda-driver/src/qwen_dispatch/ple_closed_queue/gpu/refusal.rs diff --git a/crates/cuda-driver/src/ple_closed_queue/ple_closed_completion.rs b/crates/cuda-driver/src/qwen_dispatch/ple_closed_queue/ple_closed_completion.rs similarity index 97% rename from crates/cuda-driver/src/ple_closed_queue/ple_closed_completion.rs rename to crates/cuda-driver/src/qwen_dispatch/ple_closed_queue/ple_closed_completion.rs index bc830ba6..16ff6b06 100644 --- a/crates/cuda-driver/src/ple_closed_queue/ple_closed_completion.rs +++ b/crates/cuda-driver/src/qwen_dispatch/ple_closed_queue/ple_closed_completion.rs @@ -1,5 +1,5 @@ -//! Methods of `PleClosedCompletion`: `numerical_refusal`, `into_parts`. Methods of `Context`: `ple_closed_queue`. -//! Functions: `check_charge`. +//! Result of a completed closed PLE queue (numeric refusal or the final streams) and construction of the queue. +//! Construction validates the operator assets and checks the charge plus reserve against budget and free memory. use super::{ Admission, Arguments, CHARGE, Command, Context, DeviceBuffer, Error, OPS, OUTPUTS, Operation, PleClosedCompletion, diff --git a/crates/cuda-driver/src/ple_closed_queue/ple_closed_queue_compose_close.rs b/crates/cuda-driver/src/qwen_dispatch/ple_closed_queue/ple_closed_queue_compose_close.rs similarity index 92% rename from crates/cuda-driver/src/ple_closed_queue/ple_closed_queue_compose_close.rs rename to crates/cuda-driver/src/qwen_dispatch/ple_closed_queue/ple_closed_queue_compose_close.rs index 55cbd9a7..419a2d37 100644 --- a/crates/cuda-driver/src/ple_closed_queue/ple_closed_queue_compose_close.rs +++ b/crates/cuda-driver/src/qwen_dispatch/ple_closed_queue/ple_closed_queue_compose_close.rs @@ -1,7 +1,6 @@ -//! Methods of `PleClosedQueue`: `compose`, `close`, `close_inner`. Implements `Drop for PleClosedQueue`. -//! Functions: `staging`, `float_staging`, `release_buffer`. +//! Runs one closed PLE composition: checks inputs, drains the queued kernels, reads results back under the guard. +//! Also owns closing the queue: frees the buffers and unloads the kernel module, or leaks them on a poisoned context. -#[allow(unused_imports)] use super::compose_phases::ComposeHost; use super::{ Context, DeviceBuffer, Error, PleClosedCompletion, PleClosedQueue, PleClosedWeights, Result, combine, ffi, diff --git a/crates/cuda-driver/src/qwen_dispatch/prepare_gr_read_set.rs b/crates/cuda-driver/src/qwen_dispatch/prepare_gr_read_set.rs index 770ef46c..bf103350 100644 --- a/crates/cuda-driver/src/qwen_dispatch/prepare_gr_read_set.rs +++ b/crates/cuda-driver/src/qwen_dispatch/prepare_gr_read_set.rs @@ -1,9 +1,9 @@ -//! Functions: `prepare_gr_read_set`, `load_gr_missing`, `load_gr_entry`, `unload_gr_pending` and 12 more. -//! Split out of `qwen_dispatch` to keep its files under the line limit. +//! Kernel-set preparation and operand checks of the GR read path. +//! Loads the six fixed GR read kernels all-or-nothing (published only after every entry resolves), unloads the cache, +//! and validates operand ranges, launch geometry and output aliasing of a Qwen operation. use super::{Backend, Cache, Error, OPERATIONS, Operation, Result, combine, ffi, qwen_ffi, restore}; // used only with some cargo features or targets of this crate -#[allow(unused_imports)] use super::{Asset, Cell, Context, FixedKernel}; #[cfg(all(any(target_os = "linux", target_os = "windows"), target_arch = "x86_64", feature = "cuda-driver"))] diff --git a/crates/cuda-driver/src/qwen_dispatch/queued_gr_installed.rs b/crates/cuda-driver/src/qwen_dispatch/queued_gr_installed.rs index ce910b5a..48d83da9 100644 --- a/crates/cuda-driver/src/qwen_dispatch/queued_gr_installed.rs +++ b/crates/cuda-driver/src/qwen_dispatch/queued_gr_installed.rs @@ -1,5 +1,5 @@ -//! Functions: `execute_read`, `read_outputs`, `residual_bytes`, `allocate_all` and 10 more. -//! Split out of `qwen_dispatch` to keep its files under the line limit. +//! GPU-only ignored test: runs the original GR read chain and the queued single-completion chain on the same inputs. +//! It requires identical output words, the injected-guard refusals and a clean status reset, with all buffers freed. use super::*; use crate::{Driver, GrReadInputs, GrReadOutputs}; diff --git a/crates/cuda-driver/src/qwen_shared_tail.rs b/crates/cuda-driver/src/qwen_dispatch/qwen_shared_tail.rs similarity index 91% rename from crates/cuda-driver/src/qwen_shared_tail.rs rename to crates/cuda-driver/src/qwen_dispatch/qwen_shared_tail.rs index 1915001a..93502393 100644 --- a/crates/cuda-driver/src/qwen_shared_tail.rs +++ b/crates/cuda-driver/src/qwen_dispatch/qwen_shared_tail.rs @@ -109,24 +109,14 @@ enum Command { } #[cfg(all(test, any(target_os = "linux", target_os = "windows"), target_arch = "x86_64"))] -#[path = "qwen_shared_tail_gpu.rs"] mod shared_tail_gpu; -#[path = "qwen_shared_tail/shared_expert_workspace.rs"] mod shared_expert_workspace; -#[path = "qwen_shared_tail/shared_expert_workspace_drop.rs"] mod shared_expert_workspace_drop; -#[path = "qwen_shared_tail/shared_gu_kind.rs"] mod shared_gu_kind; -#[allow(unused_imports)] use shared_expert_workspace_drop::append_finite; -#[allow(unused_imports)] use shared_expert_workspace_drop::append_projection; -#[allow(unused_imports)] use shared_expert_workspace_drop::first_refusal; -#[allow(unused_imports)] use shared_expert_workspace_drop::staging; -#[allow(unused_imports)] use shared_expert_workspace_drop::status_spans; -#[allow(unused_imports)] use shared_expert_workspace_drop::{ProjectionDims, ProjectionScratch}; diff --git a/crates/cuda-driver/src/qwen_shared_tail/shared_expert_workspace.rs b/crates/cuda-driver/src/qwen_dispatch/qwen_shared_tail/shared_expert_workspace.rs similarity index 54% rename from crates/cuda-driver/src/qwen_shared_tail/shared_expert_workspace.rs rename to crates/cuda-driver/src/qwen_dispatch/qwen_shared_tail/shared_expert_workspace.rs index abc7b085..69aa082e 100644 --- a/crates/cuda-driver/src/qwen_shared_tail/shared_expert_workspace.rs +++ b/crates/cuda-driver/src/qwen_dispatch/qwen_shared_tail/shared_expert_workspace.rs @@ -1,5 +1,5 @@ -//! Groups the submodules `shared_expert_workspace_append_close`, `shared_expert_workspace_bring_up`, `shared_expert_... -//! Split out of `qwen_shared_tail` to keep its files under the line limit. +//! Shared-expert workspace: groups bring-up, composition, and append/teardown, which share the workspace struct. +//! Each part keeps one lifecycle responsibility. use super::{ Admission, Arguments, Command, Context, DenseFormat, DeviceBuffer, Error, Kernels, OPERATIONS, Operation, Pair, @@ -8,11 +8,7 @@ use super::{ first_refusal, qwen_ffi, registered, staging, status_spans, }; -#[path = "shared_expert_workspace/shared_expert_workspace_append_close.rs"] mod shared_expert_workspace_append_close; -#[path = "shared_expert_workspace/shared_expert_workspace_bring_up.rs"] mod shared_expert_workspace_bring_up; -#[path = "shared_expert_workspace/shared_expert_workspace_compose.rs"] mod shared_expert_workspace_compose; -#[path = "shared_expert_workspace/shared_phases.rs"] mod shared_phases; diff --git a/crates/cuda-driver/src/qwen_shared_tail/shared_expert_workspace/shared_expert_workspace_append_close.rs b/crates/cuda-driver/src/qwen_dispatch/qwen_shared_tail/shared_expert_workspace/shared_expert_workspace_append_close.rs similarity index 93% rename from crates/cuda-driver/src/qwen_shared_tail/shared_expert_workspace/shared_expert_workspace_append_close.rs rename to crates/cuda-driver/src/qwen_dispatch/qwen_shared_tail/shared_expert_workspace/shared_expert_workspace_append_close.rs index 2174fc99..885f2906 100644 --- a/crates/cuda-driver/src/qwen_shared_tail/shared_expert_workspace/shared_expert_workspace_append_close.rs +++ b/crates/cuda-driver/src/qwen_dispatch/qwen_shared_tail/shared_expert_workspace/shared_expert_workspace_append_close.rs @@ -1,5 +1,5 @@ -//! Methods of `SharedExpertWorkspace`: `append_qwen`, `close`, `close_inner`, `unload_module`. -//! Functions: `release_buffer`. +//! Shared-expert workspace: validated queuing of one Qwen operator, and teardown. +//! Teardown frees every buffer and unloads the kernel module under the guard, or leaks them on a poisoned context. use super::{ Admission, Arguments, Command, Context, DeviceBuffer, Error, Operation, Result, SharedExpertWorkspace, admission, diff --git a/crates/cuda-driver/src/qwen_shared_tail/shared_expert_workspace/shared_expert_workspace_bring_up.rs b/crates/cuda-driver/src/qwen_dispatch/qwen_shared_tail/shared_expert_workspace/shared_expert_workspace_bring_up.rs similarity index 96% rename from crates/cuda-driver/src/qwen_shared_tail/shared_expert_workspace/shared_expert_workspace_bring_up.rs rename to crates/cuda-driver/src/qwen_dispatch/qwen_shared_tail/shared_expert_workspace/shared_expert_workspace_bring_up.rs index d79c4ec2..2fc3d49f 100644 --- a/crates/cuda-driver/src/qwen_shared_tail/shared_expert_workspace/shared_expert_workspace_bring_up.rs +++ b/crates/cuda-driver/src/qwen_dispatch/qwen_shared_tail/shared_expert_workspace/shared_expert_workspace_bring_up.rs @@ -1,5 +1,5 @@ -//! Methods of `SharedExpertWorkspace`: `new`, `init_resources`, `load_kernels`, `allocated_bytes` and 6 more. -//! Functions: `check_new`, `common_pair`, `projection_pairs`. +//! Bring-up of the shared-expert workspace: asset and budget checks, buffer allocation, kernel loading, accessors. +//! Also the admission of caller inputs: right size, same context, and no overlap with the workspace-owned buffers. use super::{ Context, DenseFormat, DeviceBuffer, Error, Kernels, OPERATIONS, Pair, ProjectionKind, ProjectionStyle, RESERVE, diff --git a/crates/cuda-driver/src/qwen_shared_tail/shared_expert_workspace/shared_expert_workspace_compose.rs b/crates/cuda-driver/src/qwen_dispatch/qwen_shared_tail/shared_expert_workspace/shared_expert_workspace_compose.rs similarity index 86% rename from crates/cuda-driver/src/qwen_shared_tail/shared_expert_workspace/shared_expert_workspace_compose.rs rename to crates/cuda-driver/src/qwen_dispatch/qwen_shared_tail/shared_expert_workspace/shared_expert_workspace_compose.rs index a00818ad..2826a316 100644 --- a/crates/cuda-driver/src/qwen_shared_tail/shared_expert_workspace/shared_expert_workspace_compose.rs +++ b/crates/cuda-driver/src/qwen_dispatch/qwen_shared_tail/shared_expert_workspace/shared_expert_workspace_compose.rs @@ -1,7 +1,6 @@ -//! Methods of `SharedExpertWorkspace`: `compose`. -//! Split out of `shared_expert_workspace` to keep its files under the line limit. +//! Entry point of one shared-expert tail run: admits the inputs, drains the queue under the context guard. +//! Numeric flags are arbitrated after the final drain, so the workspace stays a bounded queue, not an operator API. -#[allow(unused_imports)] use super::shared_phases::SharedStaging; use super::{DeviceBuffer, Error, Result, SharedExpertWeights, SharedExpertWorkspace, SharedTailCompletion}; diff --git a/crates/cuda-driver/src/qwen_shared_tail/shared_expert_workspace/shared_phases.rs b/crates/cuda-driver/src/qwen_dispatch/qwen_shared_tail/shared_expert_workspace/shared_phases.rs similarity index 100% rename from crates/cuda-driver/src/qwen_shared_tail/shared_expert_workspace/shared_phases.rs rename to crates/cuda-driver/src/qwen_dispatch/qwen_shared_tail/shared_expert_workspace/shared_phases.rs diff --git a/crates/cuda-driver/src/qwen_shared_tail/shared_expert_workspace_drop.rs b/crates/cuda-driver/src/qwen_dispatch/qwen_shared_tail/shared_expert_workspace_drop.rs similarity index 96% rename from crates/cuda-driver/src/qwen_shared_tail/shared_expert_workspace_drop.rs rename to crates/cuda-driver/src/qwen_dispatch/qwen_shared_tail/shared_expert_workspace_drop.rs index eb503d59..15e2fc33 100644 --- a/crates/cuda-driver/src/qwen_shared_tail/shared_expert_workspace_drop.rs +++ b/crates/cuda-driver/src/qwen_dispatch/qwen_shared_tail/shared_expert_workspace_drop.rs @@ -1,5 +1,5 @@ -//! Methods of `Command`: `launch`. Implements `Drop for SharedExpertWorkspace`. -//! Functions: `staging`, `status_spans`, `first_refusal`, `append_finite` and 3 more. +//! Drop of the shared-expert workspace plus the helpers that queue its work: status-word spans, finite guards, +//! quantize-and-project commands and the stage arbitration that maps a status word to a refusal. use super::{ Command, Context, Error, Pair, ProjectionSpec, ProjectionStyle, Result, STAGES, SharedExpertWorkspace, diff --git a/crates/cuda-driver/src/qwen_shared_tail/shared_gu_kind.rs b/crates/cuda-driver/src/qwen_dispatch/qwen_shared_tail/shared_gu_kind.rs similarity index 89% rename from crates/cuda-driver/src/qwen_shared_tail/shared_gu_kind.rs rename to crates/cuda-driver/src/qwen_dispatch/qwen_shared_tail/shared_gu_kind.rs index 8da85b14..48e04ad4 100644 --- a/crates/cuda-driver/src/qwen_shared_tail/shared_gu_kind.rs +++ b/crates/cuda-driver/src/qwen_dispatch/qwen_shared_tail/shared_gu_kind.rs @@ -1,5 +1,5 @@ -//! Methods of `SharedGuKind`: `index`, `weight_bytes`. Methods of `SharedDownKind`: `index`, `weight_bytes`. -//! Split out of `qwen_shared_tail` to keep its files under the line limit. +//! Per-kind constants of the shared-expert weights (index and byte size of each gate/up and down format), +//! the accessors of a finished shared-tail run, and the context method that creates the workspace. use super::{ Context, Result, SharedDownKind, SharedExpertWorkspace, SharedGuKind, SharedTailCompletion, SharedTailRefusal, diff --git a/crates/cuda-driver/src/qwen_shared_tail_gpu.rs b/crates/cuda-driver/src/qwen_dispatch/qwen_shared_tail/shared_tail_gpu.rs similarity index 90% rename from crates/cuda-driver/src/qwen_shared_tail_gpu.rs rename to crates/cuda-driver/src/qwen_dispatch/qwen_shared_tail/shared_tail_gpu.rs index 0aa6e0d8..a71e838d 100644 --- a/crates/cuda-driver/src/qwen_shared_tail_gpu.rs +++ b/crates/cuda-driver/src/qwen_dispatch/qwen_shared_tail/shared_tail_gpu.rs @@ -116,39 +116,20 @@ fn assert_totals(report: &Report) { assert_eq!((report.guards, report.faults, report.resets), (9, 10, 10)); } -#[path = "qwen_shared_tail_gpu/read.rs"] mod read; -#[allow(unused_imports)] use read::down_payload; -#[allow(unused_imports)] use read::f32_bytes; -#[allow(unused_imports)] use read::finite; -#[allow(unused_imports)] use read::gu_payload; -#[allow(unused_imports)] use read::input; -#[allow(unused_imports)] use read::original_projection; -#[allow(unused_imports)] use read::packet; -#[allow(unused_imports)] use read::read; -#[allow(unused_imports)] use read::scalar_weights; -#[allow(unused_imports)] use read::weights; -#[path = "qwen_shared_tail_gpu/original.rs"] mod original; -#[allow(unused_imports)] use original::compare; -#[allow(unused_imports)] use original::original; -#[allow(unused_imports)] use original::{ComposeCase, ProjectionKinds}; -#[path = "qwen_shared_tail_gpu/guard_probe.rs"] mod guard_probe; -#[allow(unused_imports)] -use guard_probe::guard_probe; -#[allow(unused_imports)] use guard_probe::run; diff --git a/crates/cuda-driver/src/qwen_shared_tail_gpu/guard_probe.rs b/crates/cuda-driver/src/qwen_dispatch/qwen_shared_tail/shared_tail_gpu/guard_probe.rs similarity index 98% rename from crates/cuda-driver/src/qwen_shared_tail_gpu/guard_probe.rs rename to crates/cuda-driver/src/qwen_dispatch/qwen_shared_tail/shared_tail_gpu/guard_probe.rs index 5ea71dc0..0bc983a7 100644 --- a/crates/cuda-driver/src/qwen_shared_tail_gpu/guard_probe.rs +++ b/crates/cuda-driver/src/qwen_dispatch/qwen_shared_tail/shared_tail_gpu/guard_probe.rs @@ -1,5 +1,5 @@ -//! Functions: `refused`, `probe_inputs`, `probe_weights`, `probe_alias` and 12 more. -//! Split out of `shared_tail_gpu` to keep its files under the line limit. +//! Shared-tail GPU test: per-kind compose cases, fault injection and the admission-guard probes. +//! Compares the workspace with the old per-role path and checks that short, foreign or aliasing operands are refused. use super::{ ComposeCase, Context, DOWN, DeviceBuffer, Error, GU, Oracle, ProjectionKinds, Report, RestoreHandle, Result, diff --git a/crates/cuda-driver/src/qwen_shared_tail_gpu/original.rs b/crates/cuda-driver/src/qwen_dispatch/qwen_shared_tail/shared_tail_gpu/original.rs similarity index 97% rename from crates/cuda-driver/src/qwen_shared_tail_gpu/original.rs rename to crates/cuda-driver/src/qwen_dispatch/qwen_shared_tail/shared_tail_gpu/original.rs index ad4f16a5..ed03249e 100644 --- a/crates/cuda-driver/src/qwen_shared_tail_gpu/original.rs +++ b/crates/cuda-driver/src/qwen_dispatch/qwen_shared_tail/shared_tail_gpu/original.rs @@ -1,5 +1,5 @@ -//! Methods of `OldPath`: `stage`, `product`, `gate`, `up` and 6 more. Methods of `RestoreHandle`: `new`. -//! Implements `Drop for RestoreHandle`. Functions: `refused`, `chain`, `original`, `compare` and 1 more. +//! Shared-tail GPU test oracle: replays the old multi-call path stage by stage for the expected products and refusal. +//! It then composes the same case on the workspace and compares every product, status and refusal word by word. use super::{ Context, DenseFormat, DeviceBuffer, Error, Oracle, ProjectionKind, ProjectionSpec, Report, RestoreHandle, Result, diff --git a/crates/cuda-driver/src/qwen_shared_tail_gpu/read.rs b/crates/cuda-driver/src/qwen_dispatch/qwen_shared_tail/shared_tail_gpu/read.rs similarity index 96% rename from crates/cuda-driver/src/qwen_shared_tail_gpu/read.rs rename to crates/cuda-driver/src/qwen_dispatch/qwen_shared_tail/shared_tail_gpu/read.rs index 96db614f..dc1a2a57 100644 --- a/crates/cuda-driver/src/qwen_shared_tail_gpu/read.rs +++ b/crates/cuda-driver/src/qwen_dispatch/qwen_shared_tail/shared_tail_gpu/read.rs @@ -1,5 +1,5 @@ -//! Functions: `read`, `f32_bytes`, `finite`, `input` and 7 more. -//! Split out of `shared_tail_gpu` to keep its files under the line limit. +//! Shared-tail GPU test fixtures: deterministic activations, routed packet, scalar weights and packed payloads +//! with finite scales, plus device read-back and the old-path projection call used as the oracle. use super::{ Context, DenseFormat, DeviceBuffer, ProjectionKind, ProjectionSpec, Q5KProjectionShape, Q6KProjectionShape, Result, diff --git a/crates/cuda-driver/src/qwen_dispatch/tests.rs b/crates/cuda-driver/src/qwen_dispatch/tests.rs index db3e76ca..0f2db625 100644 --- a/crates/cuda-driver/src/qwen_dispatch/tests.rs +++ b/crates/cuda-driver/src/qwen_dispatch/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of `qwen_dispatch`. +//! Host-only tests of the Qwen dispatch layer on a mock backend that records driver calls and injects faults. +//! Submodules pin the cache and slot publication, poison handling, atomic registration and that a launch always syncs. use super::*; use std::cell::RefCell; @@ -77,13 +78,8 @@ fn nested(primary: Error, secondary: Error) -> Error { Error::Multiple { primary: Box::new(primary), secondary: Box::new(secondary) } } -#[path = "tests/full_s2_bank_extent.rs"] mod full_s2_bank_extent; -#[path = "tests/moe_new_preflight_requires_exact.rs"] mod moe_new_preflight_requires_exact; -#[path = "tests/qsa_new_slots_keep_atomic.rs"] mod qsa_new_slots_keep_atomic; -#[path = "tests/qwen_actual_owner_poison_missing.rs"] mod qwen_actual_owner_poison_missing; -#[path = "tests/qwen_attempted_launch_always_syncs.rs"] mod qwen_attempted_launch_always_syncs; diff --git a/crates/cuda-driver/src/qwen_dispatch/tests/qsa_new_slots_keep_atomic.rs b/crates/cuda-driver/src/qwen_dispatch/tests/qsa_new_slots_keep_atomic.rs index cd040117..f99b45f9 100644 --- a/crates/cuda-driver/src/qwen_dispatch/tests/qsa_new_slots_keep_atomic.rs +++ b/crates/cuda-driver/src/qwen_dispatch/tests/qsa_new_slots_keep_atomic.rs @@ -13,7 +13,6 @@ use super::full_s2_bank_extent::{platform_context, synthetic_buffer}; use super::{ Asset, Cache, Cell, Error, Mock, Operation, Rc, arguments, error, execute, nested, qwen_ffi, ready, unload, }; -use crate::{QsaIndexAppendSource, QsaPackedKv, QsaPooledImage}; #[test] fn qsa_new_slots_keep_atomic_lookup_and_uncertain_completion_owners() { diff --git a/crates/cuda-driver/src/qwen_dispatch/tests/qwen_actual_owner_poison_missing.rs b/crates/cuda-driver/src/qwen_dispatch/tests/qwen_actual_owner_poison_missing.rs index 03eec93c..e9b47cea 100644 --- a/crates/cuda-driver/src/qwen_dispatch/tests/qwen_actual_owner_poison_missing.rs +++ b/crates/cuda-driver/src/qwen_dispatch/tests/qwen_actual_owner_poison_missing.rs @@ -10,7 +10,6 @@ )))] use super::full_s2_bank_extent::{platform_context, synthetic_buffer}; use super::{Backend, Cache, Error, Mock, Operation, ffi, prepare_pair, qwen_ffi, ranges_layout, ready}; -use crate::MtpDenseKv; #[cfg(not(all( feature = "cuda-driver", diff --git a/crates/cuda-driver/src/qwen_ffi.rs b/crates/cuda-driver/src/qwen_ffi.rs index 5f873247..9a4dc440 100644 --- a/crates/cuda-driver/src/qwen_ffi.rs +++ b/crates/cuda-driver/src/qwen_ffi.rs @@ -14,142 +14,73 @@ mod tests; mod mtp_s2_full_layout; mod operation; -#[allow(unused_imports)] pub(super) use mtp_s2_full_layout::mtp_dense_layout; -#[allow(unused_imports)] use mtp_s2_full_layout::mtp_extended_layout; -#[allow(unused_imports)] use mtp_s2_full_layout::mtp_input_layout; -#[allow(unused_imports)] pub(super) use mtp_s2_full_layout::mtp_s2_full_layout; mod qsa_layout; -#[allow(unused_imports)] use qsa_layout::gdn_layout; -#[allow(unused_imports)] use qsa_layout::moe_layout; -#[allow(unused_imports)] use qsa_layout::ple_layout; -#[allow(unused_imports)] pub(super) use qsa_layout::qsa_layout; mod asset_validation_and_bf16_layout; -#[allow(unused_imports)] pub(super) use asset_validation_and_bf16_layout::bf16_layout; -#[allow(unused_imports)] use asset_validation_and_bf16_layout::gdn_asset; -#[allow(unused_imports)] use asset_validation_and_bf16_layout::gr_asset; -#[allow(unused_imports)] use asset_validation_and_bf16_layout::inspect_ptx; -#[allow(unused_imports)] pub(super) use asset_validation_and_bf16_layout::kar_ple_layout; -#[allow(unused_imports)] use asset_validation_and_bf16_layout::moe_asset; -#[allow(unused_imports)] use asset_validation_and_bf16_layout::ple_asset; -#[allow(unused_imports)] use asset_validation_and_bf16_layout::qsa_asset; mod asset; -#[allow(unused_imports)] pub(super) use asset::asset; -#[allow(unused_imports)] pub(crate) use asset::sha256; mod mock_asset; -#[allow(unused_imports)] pub(super) use mock_asset::gr_batch_preview_ptx; #[cfg(test)] -#[allow(unused_imports)] pub(super) use mock_asset::mock_asset; #[cfg(all(any(target_os = "linux", target_os = "windows"), target_arch = "x86_64", feature = "cuda-driver"))] -#[allow(unused_imports)] pub(crate) use mock_asset::q6_batch_preview_ptx; mod n_types; -#[allow(unused_imports)] pub(super) use n_types::Asset; -#[allow(unused_imports)] pub(super) use n_types::H; -#[allow(unused_imports)] pub(super) use n_types::HC; -#[allow(unused_imports)] pub(super) use n_types::Layout; -#[allow(unused_imports)] pub(super) use n_types::N; -#[allow(unused_imports)] pub(super) use n_types::OPERATIONS; -#[allow(unused_imports)] pub(super) use n_types::Operation; -#[allow(unused_imports)] use n_types::PTX_PROOFS; -#[allow(unused_imports)] use n_types::PtxProof; -#[allow(unused_imports)] pub(super) use n_types::QSA_OPERATIONS; -#[allow(unused_imports)] use n_types::ROUTE_ASSET; -#[allow(unused_imports)] -use n_types::ROUTE_RECEIPT; -#[allow(unused_imports)] pub(super) use n_types::Receipt; mod bf16_receipt_types; -#[allow(unused_imports)] use bf16_receipt_types::BF16_ASSETS; -#[allow(unused_imports)] -use bf16_receipt_types::BF16_RECEIPT; -#[allow(unused_imports)] use bf16_receipt_types::GDN_ASSETS; -#[allow(unused_imports)] use bf16_receipt_types::GDN_RECEIPT; -#[allow(unused_imports)] use bf16_receipt_types::GR_ASSETS; -#[allow(unused_imports)] use bf16_receipt_types::GR_RECEIPT; -#[allow(unused_imports)] use bf16_receipt_types::MOE_ASSETS; -#[allow(unused_imports)] use bf16_receipt_types::MOE_RECEIPT; -#[allow(unused_imports)] use bf16_receipt_types::PLE_ASSETS; -#[allow(unused_imports)] use bf16_receipt_types::PLE_RECEIPT; -#[allow(unused_imports)] use bf16_receipt_types::PLE_VALUE_FULL_ASSET; -#[allow(unused_imports)] -use bf16_receipt_types::PLE_VALUE_FULL_RECEIPT; -#[allow(unused_imports)] use bf16_receipt_types::QSA_NATIVE_RECEIPT; -#[allow(unused_imports)] use bf16_receipt_types::QSA_SELECT_RECEIPT; mod qsa_attention_receipt_types; -#[allow(unused_imports)] use qsa_attention_receipt_types::KAR_PLE_ASSETS; -#[allow(unused_imports)] +#[cfg(test)] use qsa_attention_receipt_types::KAR_PLE_RECEIPT; -#[allow(unused_imports)] use qsa_attention_receipt_types::MTP_DENSE_ASSETS; -#[allow(unused_imports)] -use qsa_attention_receipt_types::MTP_DENSE_RECEIPT; -#[allow(unused_imports)] use qsa_attention_receipt_types::MTP_GR_RECEIPT; -#[allow(unused_imports)] use qsa_attention_receipt_types::MTP_INPUT_ASSETS; -#[allow(unused_imports)] -use qsa_attention_receipt_types::MTP_INPUT_RECEIPT; -#[allow(unused_imports)] use qsa_attention_receipt_types::MTP_S2_RECEIPT; -#[allow(unused_imports)] use qsa_attention_receipt_types::QSA_ASSETS; -#[allow(unused_imports)] use qsa_attention_receipt_types::QSA_ATTENTION_RECEIPT; -#[allow(unused_imports)] use qsa_attention_receipt_types::QSA_GATE_RECEIPT; mod mtp_extended_assets_types; -#[allow(unused_imports)] pub(super) use mtp_extended_assets_types::Arguments; -#[allow(unused_imports)] use mtp_extended_assets_types::MTP_EXTENDED_ASSETS; -#[allow(unused_imports)] use mtp_extended_assets_types::MTP_S2_FULL_ASSETS; -#[allow(unused_imports)] -use mtp_extended_assets_types::MTP_S2_FULL_RECEIPT; -#[allow(unused_imports)] use mtp_extended_assets_types::Storage; diff --git a/crates/cuda-driver/src/qwen_ffi/asset.rs b/crates/cuda-driver/src/qwen_ffi/asset.rs index da68ecf2..73feaa2b 100644 --- a/crates/cuda-driver/src/qwen_ffi/asset.rs +++ b/crates/cuda-driver/src/qwen_ffi/asset.rs @@ -1,5 +1,5 @@ -//! Methods of `Arguments`: `new`, `with_layout`, `layout`, `operation` and 2 more. Implements `Drop for Arguments`. -//! Functions: `asset`, `asset_group_0`, `asset_group_1`, `asset_group_2` and 10 more. +//! Sealed PTX asset lookup per Qwen operation, the launch-argument block handed to the driver, and a SHA-256. +//! Arguments owns heap storage whose parameter array points at its own fields; the digest pins the PTX in receipts. use super::{ Arguments, Asset, BF16_ASSETS, GDN_ASSETS, GR_ASSETS, KAR_PLE_ASSETS, Layout, MOE_ASSETS, MTP_DENSE_ASSETS, diff --git a/crates/cuda-driver/src/qwen_ffi/asset_validation_and_bf16_layout.rs b/crates/cuda-driver/src/qwen_ffi/asset_validation_and_bf16_layout.rs index 9521794e..261951ac 100644 --- a/crates/cuda-driver/src/qwen_ffi/asset_validation_and_bf16_layout.rs +++ b/crates/cuda-driver/src/qwen_ffi/asset_validation_and_bf16_layout.rs @@ -1,5 +1,5 @@ -//! Methods of `Operation`: `has_epsilon`. -//! Methods of `Asset`: `validate`, `identity_admitted`, `receipt_complete`, `validate_with_memo`. +//! Admission checks of a PTX asset (identity, pin equals receipt, complete provenance, memoized content digest) +//! and the launch layouts of the KAR PLE and BF16 projection kernels, plus the constructors of pinned assets. use super::{ Asset, Error, GDN_RECEIPT, GR_RECEIPT, H, HC, Layout, MOE_RECEIPT, N, OnceLock, Operation, PLE_RECEIPT, PTX_PROOFS, diff --git a/crates/cuda-driver/src/qwen_ffi/bf16_receipt_types.rs b/crates/cuda-driver/src/qwen_ffi/bf16_receipt_types.rs index 336e4fe2..454cb4cd 100644 --- a/crates/cuda-driver/src/qwen_ffi/bf16_receipt_types.rs +++ b/crates/cuda-driver/src/qwen_ffi/bf16_receipt_types.rs @@ -1,5 +1,5 @@ -//! Items of the parent module. -//! BF16_RECEIPT, BF16_ASSETS, PLE_RECEIPT, PLE_ASSETS, PLE_VALUE_FULL_RECEIPT, PLE_VALUE_FULL_ASSET .... +//! Frozen producer receipts and sealed assets for the BF16 projection, PLE, GR, GDN, MoE and QSA native/select kernels. +//! Constant tables only: each receipt pins the source, PTX and oracle hashes and records how the kernel was qualified. use super::{Asset, H, HC, N, Operation, Receipt, gdn_asset, gr_asset, moe_asset, ple_asset}; diff --git a/crates/cuda-driver/src/qwen_ffi/mock_asset.rs b/crates/cuda-driver/src/qwen_ffi/mock_asset.rs index 2412819a..53626da6 100644 --- a/crates/cuda-driver/src/qwen_ffi/mock_asset.rs +++ b/crates/cuda-driver/src/qwen_ffi/mock_asset.rs @@ -1,5 +1,5 @@ -//! Functions: `mock_asset`, `q6_batch_preview_ptx`, `gr_batch_preview_ptx`. -//! Split out of `qwen_ffi` to keep its files under the line limit. +//! Test-only mock asset for CPU-side dispatch tests (never reaches CUDA) and the pinned PTX of the Q6/GR previews. +//! The preview entry points check the PTX digest and are kept out of the production asset map. use super::{Error, Result, inspect_ptx}; #[cfg(test)] diff --git a/crates/cuda-driver/src/qwen_ffi/mtp_extended_assets_types.rs b/crates/cuda-driver/src/qwen_ffi/mtp_extended_assets_types.rs index 1040f3ae..1b30c50c 100644 --- a/crates/cuda-driver/src/qwen_ffi/mtp_extended_assets_types.rs +++ b/crates/cuda-driver/src/qwen_ffi/mtp_extended_assets_types.rs @@ -1,5 +1,5 @@ -//! Defines `Storage`, `Arguments`. -//! MTP_EXTENDED_ASSETS, MTP_S2_FULL_RECEIPT, MTP_S2_FULL_ASSETS, Storage, Arguments. +//! Receipt-pinned assets of the extended MTP kernels and of the full S2 expert kernels. +//! Also the launch-argument records: Storage is the raw parameter block and Arguments is its owning handle. use super::{Asset, Layout, MTP_GR_RECEIPT, MTP_S2_RECEIPT, NonNull, Operation, Receipt, c_void}; diff --git a/crates/cuda-driver/src/qwen_ffi/mtp_s2_full_layout.rs b/crates/cuda-driver/src/qwen_ffi/mtp_s2_full_layout.rs index 8557b485..f2391a80 100644 --- a/crates/cuda-driver/src/qwen_ffi/mtp_s2_full_layout.rs +++ b/crates/cuda-driver/src/qwen_ffi/mtp_s2_full_layout.rs @@ -1,5 +1,5 @@ -//! Methods of `Layout`: `flat`. -//! Functions: `mtp_s2_full_layout`, `mtp_extended_layout`, `mtp_gr_geometry`, `mtp_tile_geometry` and 2 more. +//! Fixed launch layouts of the MTP kernels: full S2 expert gate/up and down, extended GR and tile ops, input, dense. +//! Geometry comes only from constants, the expert index or the position, never from caller extents; also Layout::flat. use super::{Error, Layout, Operation, Result}; diff --git a/crates/cuda-driver/src/qwen_ffi/n_types.rs b/crates/cuda-driver/src/qwen_ffi/n_types.rs index 59056ad3..d191827e 100644 --- a/crates/cuda-driver/src/qwen_ffi/n_types.rs +++ b/crates/cuda-driver/src/qwen_ffi/n_types.rs @@ -1,5 +1,5 @@ -//! Defines `Operation`, `Layout`, `Receipt` and 2 more. -//! N, HC, H, Operation, OPERATIONS, QSA_OPERATIONS .... +//! Core types of the Qwen FFI layer: model dimensions N, HC and H, the Operation enum with its lists, +//! the launch Layout, the producer Receipt, the PTX Asset and PTX proof memo, and the router receipt and asset. use super::OnceLock; diff --git a/crates/cuda-driver/src/qwen_ffi/operation.rs b/crates/cuda-driver/src/qwen_ffi/operation.rs index e4aafc87..0b810b76 100644 --- a/crates/cuda-driver/src/qwen_ffi/operation.rs +++ b/crates/cuda-driver/src/qwen_ffi/operation.rs @@ -1,5 +1,5 @@ -//! Methods of `Operation`: `entry`, `entry_group_0`, `entry_group_1`, `entry_group_2` and 10 more. -//! Functions: `router_layout`. +//! Per-operation data of the Qwen kernels: the entry point name and the launch Layout of each Operation. +//! Layout selection delegates to the MTP, dense, KAR, QSA, MoE, PLE, GDN, router and elementwise families. use super::{ CStr, H, HC, Layout, N, Operation, QSA_OPERATIONS, bf16_layout, gdn_layout, kar_ple_layout, moe_layout, diff --git a/crates/cuda-driver/src/qwen_ffi/qsa_attention_receipt_types.rs b/crates/cuda-driver/src/qwen_ffi/qsa_attention_receipt_types.rs index 24fa6f56..d47a582c 100644 --- a/crates/cuda-driver/src/qwen_ffi/qsa_attention_receipt_types.rs +++ b/crates/cuda-driver/src/qwen_ffi/qsa_attention_receipt_types.rs @@ -1,5 +1,5 @@ -//! Items of the parent module. -//! QSA_ATTENTION_RECEIPT, QSA_GATE_RECEIPT, QSA_ASSETS, KAR_PLE_RECEIPT, KAR_PLE_ASSETS, MTP_INPUT_RECEIPT .... +//! Frozen receipts and sealed assets for the QSA attention and gate kernels, KAR PLE, and the MTP kernels. +//! Constant tables only: each receipt pins source, PTX and oracle hashes and records how the kernel was qualified. use super::{Asset, H, HC, N, Operation, Receipt, qsa_asset}; diff --git a/crates/cuda-driver/src/qwen_ffi/qsa_layout.rs b/crates/cuda-driver/src/qwen_ffi/qsa_layout.rs index 27e5f5f8..af62cdc6 100644 --- a/crates/cuda-driver/src/qwen_ffi/qsa_layout.rs +++ b/crates/cuda-driver/src/qwen_ffi/qsa_layout.rs @@ -1,5 +1,5 @@ -//! Functions: `qsa_layout`, `check_qsa_value`, `qsa_geometry`, `qsa_plain_geometry` and 5 more. Defines `QsaGeometry`. -//! Split out of `qwen_ffi` to keep its files under the line limit. +//! Fixed launch layouts of the QSA kernels (extents set by position or selected width) and of the PLE, MoE, GDN ones. +//! Every size and grid is a closed constant or a bounded function of one scalar, never a caller-supplied geometry. use super::{Error, Layout, Operation, QSA_OPERATIONS, Result}; diff --git a/crates/cuda-driver/src/qwen_ffi/tests.rs b/crates/cuda-driver/src/qwen_ffi/tests.rs index c1dc6949..d07c9506 100644 --- a/crates/cuda-driver/src/qwen_ffi/tests.rs +++ b/crates/cuda-driver/src/qwen_ffi/tests.rs @@ -1,12 +1,9 @@ -//! Unit tests of `qwen_ffi`. +//! Host tests of the Qwen FFI layer: layouts, ABI sizes, pointer order, receipts and the qualified assets. +//! Submodules are grouped by operation family (full S2, MoE, MTP, QSA). use super::*; -#[path = "tests/full_s2_expert_scalar.rs"] mod full_s2_expert_scalar; -#[path = "tests/moe_fixed_pointer_abi_extents.rs"] mod moe_fixed_pointer_abi_extents; -#[path = "tests/mtp_new_qualified_assets.rs"] mod mtp_new_qualified_assets; -#[path = "tests/qsa_new_literal_abi_scalar.rs"] mod qsa_new_literal_abi_scalar; diff --git a/crates/cuda-driver/src/root_exports.rs b/crates/cuda-driver/src/root_exports.rs index e8e55d89..6ab48a34 100644 --- a/crates/cuda-driver/src/root_exports.rs +++ b/crates/cuda-driver/src/root_exports.rs @@ -1,229 +1,235 @@ //! Plain `pub use` re-exports of the crate root, moved out of `lib.rs` by STRA-338 (the public paths are unchanged). -#[allow(unused_imports)] -use super::*; - -pub use device_ref::DeviceRef; -pub use device_slab::{DeviceSlice, SlabAllocator, SlabPolicy, SlabStats}; -pub use gdn_state_finite_guard::GdnStateFiniteGuard; -pub use head_greedy::{HEAD_GREEDY_WORKSPACE_BYTES, HeadGreedySelection, HeadGreedyWorkspace}; -pub use mmq::resident::original_group::{ +pub use crate::device_ref::DeviceRef; +pub use crate::device_slab::{DeviceSlice, SlabAllocator, SlabPolicy, SlabStats}; +pub use crate::gdn_state_finite_guard::GdnStateFiniteGuard; +pub use crate::head_greedy::{HEAD_GREEDY_WORKSPACE_BYTES, HeadGreedySelection, HeadGreedyWorkspace}; +pub use crate::mmq::resident::original_group::{ OriginalMmqCopySchedule, OriginalMmqLayer, OriginalMmqOutput, OriginalStreamAllLayer, PrefetchSource, PrefetchTarget, RingExperts, original_mmq_group_bank_bytes, }; -pub use mmq::resident::{FiniteMmqOutput, MmqChunkActivation, MmqGroupActivation, MmqHidden, MmqWorkspace}; -pub use mmq::{MmqExperiment, MmqFormat, MmqProfile, MmqRequest, MmqWeights}; -pub use mtp_dense_kv::MTP_ORIGINAL_WINDOW; -pub use mtp_dense_kv::MtpDenseKvRing; -pub use mtp_dense_kv::{ +pub use crate::mmq::resident::{FiniteMmqOutput, MmqChunkActivation, MmqGroupActivation, MmqHidden, MmqWorkspace}; +pub use crate::mmq::{MmqExperiment, MmqFormat, MmqProfile, MmqRequest, MmqWeights}; +pub use crate::mtp_dense_kv::MTP_ORIGINAL_WINDOW; +pub use crate::mtp_dense_kv::MtpDenseKvRing; +pub use crate::mtp_dense_kv::{ CompletedMtpAttention, CompletedMtpKvReplay, MtpInt8OwnerId, MtpInt8Snapshot, MtpOriginalInt8, MtpOriginalMixed, MtpOriginalQuery, }; -pub use original_expert_cache::{OriginalExpertCache, RefillBatchOptions}; -pub use original_gpu_schedule::{ +pub use crate::original_expert_cache::{OriginalExpertCache, RefillBatchOptions}; +pub use crate::original_gpu_schedule::{ OriginalCapture, OriginalCapturePolicy, OriginalEventKind, OriginalGpuEvent, OriginalGpuGraph, OriginalGpuStream, OriginalGraphFlight, OriginalGraphKey, OriginalGraphRegistry, OriginalGraphResources, OriginalStreamKind, OriginalWait, }; -pub use original_moe_prompt_device::{ +pub use crate::original_moe_prompt_device::{ ExpertStreamLayer, OriginalLayerExpertSources, OriginalMoePromptDevice, OriginalMoePromptLayer, SharedExpertLayout, }; -pub use original_mtp_actor::{ActorRefusal as OriginalMtpActorRefusal, DraftSettings as OriginalMtpDraftSettings}; +pub use crate::original_mtp_actor::{ + ActorRefusal as OriginalMtpActorRefusal, DraftSettings as OriginalMtpDraftSettings, +}; #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] -pub use original_mtp_actor::{OriginalMtpActor, OriginalMtpLoadEvidence, OriginalMtpLoadMeter, OriginalMtpLoadedParts}; -pub use original_mtp_bank::{ +pub use crate::original_mtp_actor::{ + OriginalMtpActor, OriginalMtpLoadEvidence, OriginalMtpLoadMeter, OriginalMtpLoadedParts, +}; +pub use crate::original_mtp_bank::{ OriginalMtpLoadFailure, OriginalMtpRtBank, OriginalMtpRtTensor, OriginalMtpTensorKind, original_mtp_draft_vocab_bytes, }; #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] -pub use original_mtp_draft_head::{FullForwardHead, OriginalMainHead, OriginalMtpDraftHead}; -pub use original_mtp_loader::{ - CoupledPlan as OriginalMtpCoupledPlan, KvFormat as OriginalMtpKvFormat, KvMode as OriginalMtpKvMode, - KvPlan as OriginalMtpKvPlan, LoaderError as OriginalMtpPlanError, OriginalMtpCapture, OriginalMtpKvStartup, - OriginalMtpLoadPlan, WeightBankPlan as OriginalMtpWeightBankPlan, original_mtp_bind_reserve, -}; -pub use original_prefill_arena::{OriginalPrefillArena, OriginalPromptLeaseIdentity, OriginalPromptRows}; -pub use original_prefill_layout::{ +pub use crate::original_mtp_draft_head::{FullForwardHead, OriginalMainHead, OriginalMtpDraftHead}; +pub use crate::original_prefill_arena::{OriginalPrefillArena, OriginalPromptLeaseIdentity, OriginalPromptRows}; +pub use crate::original_prefill_layout::{ OriginalPrefillLayout, PrefillKvStage, PrefillLayoutOptions, PrefillPhase, PrefillSpan, }; -pub use original_session_state::{ +pub use crate::original_session_state::{ OriginalGeometryFacts, OriginalHostKv, OriginalIdxKind, OriginalKvLayer, OriginalKvPool, OriginalQsaFacts, OriginalRegion, OriginalRingBlocks, OriginalSessionBytes, OriginalSessionControl, OriginalSessionFacts, }; -pub use qsa_selected_kv::{QsaKvMisses, QsaSelectedKvProducts, QsaSelectedKvWorkspace}; -pub use qwen_dispatch::fixed_operands::{ +pub use crate::qsa_selected_kv::{QsaKvMisses, QsaSelectedKvProducts, QsaSelectedKvWorkspace}; +pub use crate::qwen_dispatch::fixed_operands::{ GdnConvResult, GdnGates, GdnOutNormInput, GdnQkv, GdnStepProducts, GdnStepResult, GrReadInputs, GrReadOutputs, MtpDenseKv, MtpGrMlpOutputs, MtpGrMlpResidual, MtpGrProducts, MtpGrWeights, MtpQuantizedInput, MtpRingWindow, MtpS2SelectedExpert, MtpS2TileWeights, PleConvResult, QsaIndexAppendSource, QsaPackedKv, QsaPooledImage, }; -pub use qwen_dispatch::gr_batch_read::{GrMicroValues, GrMicrobatchRead}; -pub use routed_group_workspace::RoutedColumnsLoan; -pub use routed_group_workspace::{RoutedDownShape, RoutedGroupWorkspace}; -pub use routed_stage_finite_guard::{RoutedFiniteStage, RoutedStageFiniteGuard}; -pub use serving_context::{ +pub use crate::qwen_dispatch::gr_batch_read::{GrMicroValues, GrMicrobatchRead}; +pub use crate::routed_group_workspace::RoutedColumnsLoan; +pub use crate::routed_group_workspace::{RoutedDownShape, RoutedGroupWorkspace}; +pub use crate::routed_stage_finite_guard::{RoutedFiniteStage, RoutedStageFiniteGuard}; +pub use leleka_cuda_model::original_mtp_loader::{ + CoupledPlan as OriginalMtpCoupledPlan, KvFormat as OriginalMtpKvFormat, KvMode as OriginalMtpKvMode, + KvPlan as OriginalMtpKvPlan, LoaderError as OriginalMtpPlanError, OriginalMtpCapture, OriginalMtpKvStartup, + OriginalMtpLoadPlan, WeightBankPlan as OriginalMtpWeightBankPlan, original_mtp_bind_reserve, +}; +pub use leleka_cuda_model::serving_context::{ KV_RESIDENT_DEFAULT_CELLS, KV_RESIDENT_MIN_CELLS, MAX_CONTEXT_CELLS, ServingContext, TRAINED_CONTEXT_CELLS, configure_kv_resident, configure_serving_context, kv_resident_cells, serving_context, }; #[cfg(all(any(target_os = "linux", target_os = "windows"), target_arch = "x86_64", feature = "cuda-driver"))] -pub use qwen_dispatch::batch_gr_preview::GrBatchModule; -pub use qwen_dispatch::batch_gr_preview::{GrInjectBuffers, GrNormBuffers}; +pub use crate::qwen_dispatch::batch_gr_preview::GrBatchModule; +pub use crate::qwen_dispatch::batch_gr_preview::{GrInjectBuffers, GrNormBuffers}; -pub use qwen_dispatch::qwen_shared_tail::{ +pub use crate::qwen_dispatch::qwen_shared_tail::{ SharedDownKind, SharedExpertWeights, SharedExpertWorkspace, SharedGuKind, SharedTailCompletion, SharedTailRefusal, }; // Additive closed MTP input transport owners. -pub use qwen_dispatch::gdn_closed_queue::{ +pub use crate::qwen_dispatch::gdn_closed_queue::{ GdnConvBuffers, GdnOutNormBuffers, GdnQueueStage, GdnRecurrenceBuffers, GdnRowCompletion, GdnRowPrefix, GdnRowQueue, }; #[cfg(all(any(target_os = "linux", target_os = "windows"), target_arch = "x86_64", feature = "cuda-driver"))] -pub use qwen_dispatch::gdn_fused_t1::{ +pub use crate::qwen_dispatch::gdn_fused_t1::{ GDN_FUSED_T1_PERSISTENT_BYTES, GDN_FUSED_T1_STATE_BYTES, GdnAbBuffers, GdnFusedCompletion, GdnFusedPrefix, GdnFusedStage, GdnFusedT1, GdnReplayBuffers, }; #[cfg(all(any(target_os = "linux", target_os = "windows"), target_arch = "x86_64", feature = "cuda-driver"))] -pub(crate) use qwen_dispatch::gdn_native_batch::GdnGeometry; +pub(crate) use crate::qwen_dispatch::gdn_native_batch::GdnGeometry; #[cfg(all(any(target_os = "linux", target_os = "windows"), target_arch = "x86_64", feature = "cuda-driver"))] -pub use qwen_dispatch::gdn_native_batch::{ +pub use crate::qwen_dispatch::gdn_native_batch::{ GDN_BATCH_EPSILON, GDN_BATCH_MAX_TOKENS, GdnBatchCompletion, GdnBatchPrefix, GdnBatchStage, GdnGemm, GdnNativeFormat, GdnPrefillBatch, GdnPromptOptions, GdnStream, GemmShape, OriginalGdnPromptDevice, OriginalGdnPromptState, OriginalGdnPromptWeights, }; #[cfg(all(any(target_os = "linux", target_os = "windows"), target_arch = "x86_64", feature = "cuda-driver"))] -pub use qwen_dispatch::moe_prefill_batch::{ +pub use crate::qwen_dispatch::moe_prefill_batch::{ MOE_BATCH_MAX_TOKENS, MOE_BATCH_SCRATCH_BYTES, MoeBatchCompletion, MoeBatchPrefix, MoeBatchStage, MoeCombineInputs, MoePrefillBatch, MoeRouteBatch, }; -pub use qwen_dispatch::mtp_input_workspace::{MtpInputCompletion, MtpInputPrefix, MtpInputRefusal, MtpInputWorkspace}; +pub use crate::qwen_dispatch::mtp_input_workspace::{ + MtpInputCompletion, MtpInputPrefix, MtpInputRefusal, MtpInputWorkspace, +}; -pub use async_owned_copy::{CompletedOwnedCopy, MAX_ASYNC_COPY_PAIRS, OwnedCopyPairs, OwnedCopyPoll, PendingOwnedCopy}; +pub use crate::async_owned_copy::{ + CompletedOwnedCopy, MAX_ASYNC_COPY_PAIRS, OwnedCopyPairs, OwnedCopyPoll, PendingOwnedCopy, +}; #[cfg(all(any(target_os = "linux", target_os = "windows"), target_arch = "x86_64", feature = "cuda-driver"))] -pub use qwen_dispatch::gr_batch_inject_workspace::{ +pub use crate::qwen_dispatch::gr_batch_inject_workspace::{ GR_BATCH_INJECT_WORKSPACE_BYTES, GrBatchInjectShape, GrBatchInjectWorkspace, GrInjectInputs, }; -pub use routed_resident_queue::{ +pub use crate::routed_resident_queue::{ RoutedResidentCompletion, RoutedResidentOutputs, RoutedResidentQueue, RoutedResidentRefusal, RoutedResidentWeights, }; -pub use mapped_expert_bank::{ +pub use crate::mapped_expert_bank::{ MappedExpertBank, MappedExpertCopyCompletion, MappedExpertCopyScratch, PendingMappedExpertCopy, }; -pub use qwen_dispatch::ple_closed_queue::{ +pub use crate::qwen_dispatch::ple_closed_queue::{ PleClosedCompletion, PleClosedParts, PleClosedQueue, PleClosedRefusal, PleClosedWeights, }; #[cfg(all(any(target_os = "linux", target_os = "windows"), target_arch = "x86_64"))] -pub use gdn_batch_gemm::NativeGdnGemm; -pub use native_batch_workspace::{NATIVE_BATCH_WORKSPACE_BYTES, NativeBatchWorkspace}; -pub use ple_batch_queue::{ +pub use crate::gdn_batch_gemm::NativeGdnGemm; +pub use crate::native_batch_workspace::{NATIVE_BATCH_WORKSPACE_BYTES, NativeBatchWorkspace}; +pub use crate::ple_batch_queue::{ PLE_BATCH_QUEUE_BYTES, PleBatchCompletion, PleBatchQueue, PleBatchRow, PleBatchSources, PleBf16Mode, }; #[cfg(all(any(target_os = "linux", target_os = "windows"), target_arch = "x86_64"))] -pub use qsa_native_batch::{ +pub use crate::qsa_native_batch::{ QSA_NATIVE_BATCH_BYTES, QsaNativeBatchWorkspace, QsaNativeKind, QsaNativePacking, QsaNativeProjections, }; #[cfg(all(any(target_os = "linux", target_os = "windows"), target_arch = "x86_64"))] -pub use qsa_native_batch::{QsaGatedAttention, QsaInputWeights, QsaNativeWeight}; -pub use qsa_native_decode::{QSA_NATIVE_DECODE_BYTES, QsaNativeDecode, QsaNativeDecodeCompletion}; +pub use crate::qsa_native_batch::{QsaGatedAttention, QsaInputWeights, QsaNativeWeight}; +pub use crate::qsa_native_decode::{QSA_NATIVE_DECODE_BYTES, QsaNativeDecode, QsaNativeDecodeCompletion}; #[cfg(all(any(target_os = "linux", target_os = "windows"), target_arch = "x86_64"))] -pub use qsa_prompt_attention::{ +pub use crate::qsa_prompt_attention::{ QSA_PROMPT_ATTENTION_BYTES, QsaAttendedKv, QsaAttentionInputs, QsaPromptAttention, QsaPromptAttentionCompletion, }; #[cfg(all(any(target_os = "linux", target_os = "windows"), target_arch = "x86_64"))] -pub use qsa_prompt_index::{ +pub use crate::qsa_prompt_index::{ OriginalQsaDeviceSelection, OriginalQsaPromptDevice, OriginalQsaPromptWeights, OriginalQsaResidentAppendTarget, QSA_PROMPT_INDEX_BYTES, QsaChunkPrior, QsaChunkRows, QsaIndexPrior, QsaKvAppendTarget, QsaPromptIndexPrefix, QsaPromptIndexState, QsaPromptIndexWorkspace, QsaPromptSelection, ResidentContinuation, ScalarStepRows, }; #[cfg(all(any(target_os = "linux", target_os = "windows"), target_arch = "x86_64"))] -pub use qsa_prompt_kv::{ +pub use crate::qsa_prompt_kv::{ CompletedQsaKvAppend, QSA_PROMPT_MAPPED_HOST_BYTES, QSA_PROMPT_MAX_SNAPSHOT_METADATA_BYTES, QSA_PROMPT_MAX_SNAPSHOT_PAYLOAD_BYTES, QSA_PROMPT_RESIDENT_BYTES, QSA_PROMPT_STAGE_BYTES, QsaKvInputs, QsaKvOwnerId, QsaKvSnapshot, QsaPromptKv, QsaPromptStage, }; -pub use qsa_prompt_resolver::KvStreamCounters; -pub use qwen_dispatch::gr_native_batch::{GrNativeBatch, GrNativeProfile}; +pub use crate::qsa_prompt_resolver::KvStreamCounters; +pub use crate::qwen_dispatch::gr_native_batch::{GrNativeBatch, GrNativeProfile}; -pub use gpu_report::gpu_kernel_report; -pub use native_prompt_device::{ +pub use crate::gpu_report::gpu_kernel_report; +pub use crate::native_prompt_device::{ OriginalDeviceBlock, OriginalDeviceGrRead, OriginalDeviceNormedResidual, OriginalDeviceResidual, OriginalPleHistory, OriginalPromptDevice, PromptInputStage, }; -pub use original_sampler::{OriginalSampler, SampleRequest, SampleWindow, SamplerParams, SamplerPath}; -pub use prefill_stage::{ +pub use crate::original_sampler::{OriginalSampler, SampleRequest, SampleWindow, SamplerParams, SamplerPath}; +pub use crate::prefill_stage::{ set_gdn_nostore_override as set_prefill_gdn_nostore_override, set_gdn_override as set_prefill_gdn_override, }; -pub use qsa_cluster::{requested as qsa_cluster_requested, set_override as set_qsa_cluster_override}; -pub use qsa_late::set_override as set_qsa_late_override; -pub use qsa_late::set_topk_override as set_qsa_topk_override; +pub use crate::qsa_cluster::{requested as qsa_cluster_requested, set_override as set_qsa_cluster_override}; +pub use crate::qsa_late::set_override as set_qsa_late_override; +pub use crate::qsa_late::set_topk_override as set_qsa_topk_override; #[cfg(all(any(target_os = "linux", target_os = "windows"), target_arch = "x86_64"))] -pub use qsa_native_decode::OriginalQsaResidentDecodeCompletion; -pub use qsa_native_gate::QsaNativeGate; +pub use crate::qsa_native_decode::OriginalQsaResidentDecodeCompletion; +pub use crate::qsa_native_gate::QsaNativeGate; #[cfg(all(any(target_os = "linux", target_os = "windows"), target_arch = "x86_64"))] -pub use qsa_prompt_attention::OriginalQsaResidentAttention; +pub use crate::qsa_prompt_attention::OriginalQsaResidentAttention; #[cfg(all(any(target_os = "linux", target_os = "windows"), target_arch = "x86_64"))] -pub use qsa_prompt_index::{ +pub use crate::qsa_prompt_index::{ OriginalQsaIndexBatch, OriginalQsaIndexCheckpoint, OriginalQsaResidentIndex, OriginalQsaResidentPromptDevice, OriginalQsaResidentScalarIndex, OriginalQsaResidentScalarSelection, OriginalQsaResidentSelection, }; -pub use qsa_prompt_kv::set_qsa_prefetch_override; +pub use crate::qsa_prompt_kv::set_qsa_prefetch_override; #[cfg(all(any(target_os = "linux", target_os = "windows"), target_arch = "x86_64"))] -pub use qsa_prompt_kv::{ +pub use crate::qsa_prompt_kv::{ OriginalQsaMappedAppend, OriginalQsaMappedJournal, OriginalQsaMappedPrefix, OriginalQsaResidentTransport, }; -pub use mtp_dense_kv::{ +pub use crate::mtp_dense_kv::{ CompletedDraftKv, CompressedEmbedding, DraftKvFallback, DraftKvOutcome, DraftKvPolicy, DraftKvSources, OriginalMtpEmbedding, OriginalMtpPrefill, OriginalMtpPrefillWeights, PrefillRows, RecordRun, }; #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] -pub use mtp_dense_kv::{ +pub use crate::mtp_dense_kv::{ CompletedOriginalMtpDraft, OriginalMtpDraftProgram, OriginalMtpDrafter, OriginalMtpForwardProgram, OriginalMtpFullForward, OriginalMtpFullPolicy, OriginalMtpRetainedFullWeights, OriginalMtpRetainedPrefix, OriginalMtpStepOutput, }; #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] -pub use mtp_dense_kv::{OriginalMtpSkipPrior, OriginalMtpSkippedPrefix}; +pub use crate::mtp_dense_kv::{OriginalMtpSkipPrior, OriginalMtpSkippedPrefix}; #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] -pub use native_parity::{ +pub use crate::native_parity::{ NativeParity, NativeParityExpert, native_parity_embed_supported, native_parity_iq_supported, native_parity_row_bytes, }; #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] -pub use original_expert_stager::{ +pub use crate::original_expert_stager::{ OriginalExpertStager, OriginalFileExpertBlob, OriginalStagerBatch, OriginalStagerCompleted, OriginalStagerJob, OriginalStagerOptions, OriginalStreamAll, OriginalStreamAllCompleted, OriginalStreamAllForward, OriginalStreamAllOptions, }; #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] -pub use mtp_dense_kv::{ +pub use crate::mtp_dense_kv::{ OriginalMtpGrVariant, OriginalMtpRetainedScalarWeights, OriginalMtpScalarPolicy, OriginalMtpScalarPrefill, ScalarDraftKvSources, }; #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] -pub use native_head::{ +pub use crate::native_head::{ NativeEmbedFlight, NativeHeadDispatch, NativeHeadFlight, NativeHeadPayload, NativeHeadProjectionFlight, NativeHeadSampling, NativeHeadSelection, OriginalNativeEmbed, OriginalNativeEmbedRows, OriginalNativeHead, OriginalNativeHeadGraphResources, OriginalNativeHeadRows, native_embed_supported, native_head_row_bytes, native_head_supported, }; #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] -pub use original_file_expert_source::{ +pub use crate::original_file_expert_source::{ OriginalFileExpertSource, OriginalFileSourceBlob, OriginalFileSourceCounters, OriginalResidentOptions, OriginalSourceSwap, }; #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] -pub use original_gpu_schedule::OriginalStreamDrained; -pub use original_gpu_schedule::capture_timing as original_capture_timing; +pub use crate::original_gpu_schedule::OriginalStreamDrained; +pub use crate::original_gpu_schedule::capture_timing as original_capture_timing; #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] -pub use original_mtp_draft_round::{AcceptedWindow, DraftOutput, DraftSampling, DraftTarget, RepeatRowWindow}; +pub use crate::original_mtp_draft_round::{AcceptedWindow, DraftOutput, DraftSampling, DraftTarget, RepeatRowWindow}; #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] -pub use original_verify::chain::set_down_override as set_chain_down_override; -pub use original_verify::sm120::set_overrides as set_sm120_overrides; +pub use crate::original_verify::chain::set_down_override as set_chain_down_override; #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] -pub use original_verify::{ +pub use crate::original_verify::sm120::set_overrides as set_sm120_overrides; +#[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] +pub use crate::original_verify::{ MAX_PCIE_FETCHES as ORIGINAL_VERIFY_MAX_PCIE_FETCHES, OriginalVerifier, OriginalVerifyBank, OriginalVerifyCanonicalGdn, OriginalVerifyCpuRows, OriginalVerifyCpuSink, OriginalVerifyGdnJournal, OriginalVerifyGdnStage, OriginalVerifyGdnWeights, OriginalVerifyGeometry, OriginalVerifyGpuPlan, @@ -232,33 +238,29 @@ pub use original_verify::{ OriginalVerifyWindowTokens, }; // Live verifier release/diagnostic owner, profile report and completed-logit readout. -#[allow(unused_imports)] -pub use context_matvec_k_quant_projections::MatvecDims; +pub use crate::context_matvec_k_quant_projections::MatvecDims; #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] -#[allow(unused_imports)] -pub use device_buffer::chain_selects_mtp; +pub use crate::device_buffer::chain_selects_mtp; #[cfg(not(all( feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64" )))] -#[allow(unused_imports)] -pub use device_buffer::chain_selects_mtp; +pub use crate::device_buffer::chain_selects_mtp; #[cfg(not(all( feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64" )))] -#[allow(unused_imports)] -pub use device_buffer::set_chain_down_override; -pub use moe_group_down_columns::DownColumns; +pub use crate::device_buffer::set_chain_down_override; +pub use crate::moe_group_down_columns::DownColumns; #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] -pub use original_serve_assets::{ +pub use crate::original_serve_assets::{ OriginalAssetKind, OriginalAssetStatus, original_serve_asset_status, original_serve_assets_sealed, unsealed_original_serve_assets, }; #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] -pub use original_verify::{ +pub use crate::original_verify::{ ExpertTier, HcHalf, LogitRows, LogprobReadout, OriginalVerifyDiag, OriginalVerifyExpertLayout, OriginalVerifyProfile, OriginalVerifyWindowResources, PROFILE_STAMPS_PER_LAYER, PlanLayout, Projection, QuantSource, RowLogprob, Rows as OriginalVerifyRows, UNBOUND_PRODUCERS, WINDOW_LAYERS, @@ -269,7 +271,7 @@ pub use original_verify::{ write_window_logprobs, }; #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] -pub use original_verify::{ +pub use crate::original_verify::{ HcHalfBuffers, HcLayerBuffers, HcOutputBuffers, OriginalVerifyExpertFormats, OriginalVerifyGdnProjections, OriginalVerifyGrBinding, OriginalVerifyMoeBinding, OriginalVerifyMoeLayerWeights, OriginalVerifyNativeMatrix, OriginalVerifyProjBinding, OriginalVerifyQsaBinding, OriginalVerifyQsaKvBinding, OriginalVerifyQsaLayerWeights, @@ -282,36 +284,21 @@ pub use original_verify::{ any(target_os = "linux", target_os = "windows"), target_pointer_width = "64" ))] -pub use original_verify::{OriginalExpertTierProbe, expert_probe_geometry}; -#[allow(unused_imports)] -pub use prompt_sync_trace_types::Bf16ProjectionShape; -#[allow(unused_imports)] -pub use prompt_sync_trace_types::Context; -#[allow(unused_imports)] -pub use prompt_sync_trace_types::DenseFormat; -#[allow(unused_imports)] -pub use prompt_sync_trace_types::Device; -#[allow(unused_imports)] -pub use prompt_sync_trace_types::Driver; -#[allow(unused_imports)] -pub use prompt_sync_trace_types::Error; -#[allow(unused_imports)] -pub use prompt_sync_trace_types::ProjectionKind; -#[allow(unused_imports)] -pub use prompt_sync_trace_types::ProjectionSpec; -#[allow(unused_imports)] -pub use prompt_sync_trace_types::PromptSyncTrace; -#[allow(unused_imports)] -pub use prompt_sync_trace_types::Q5KProjectionShape; -#[allow(unused_imports)] -pub use prompt_sync_trace_types::Q6KProjectionShape; -#[allow(unused_imports)] -pub use prompt_sync_trace_types::Result; -#[allow(unused_imports)] -pub use prompt_sync_trace_types::RoutedFormat; -#[allow(unused_imports)] -pub use prompt_sync_trace_types::RoutedGateUpQ8; -#[allow(unused_imports)] -pub use q5_kshape_types::DeviceBuffer; +pub use crate::original_verify::{OriginalExpertTierProbe, expert_probe_geometry}; +pub use crate::prompt_sync_trace_types::Bf16ProjectionShape; +pub use crate::prompt_sync_trace_types::Context; +pub use crate::prompt_sync_trace_types::DenseFormat; +pub use crate::prompt_sync_trace_types::Device; +pub use crate::prompt_sync_trace_types::Driver; +pub use crate::prompt_sync_trace_types::Error; +pub use crate::prompt_sync_trace_types::ProjectionKind; +pub use crate::prompt_sync_trace_types::ProjectionSpec; +pub use crate::prompt_sync_trace_types::PromptSyncTrace; +pub use crate::prompt_sync_trace_types::Q5KProjectionShape; +pub use crate::prompt_sync_trace_types::Q6KProjectionShape; +pub use crate::prompt_sync_trace_types::Result; +pub use crate::prompt_sync_trace_types::RoutedFormat; +pub use crate::prompt_sync_trace_types::RoutedGateUpQ8; +pub use crate::q5_kshape_types::DeviceBuffer; #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] -pub use qsa_prompt_index::{OriginalQsaOwners, OriginalVerifyQsaJournal, OriginalVerifyRope}; +pub use crate::qsa_prompt_index::{OriginalQsaOwners, OriginalVerifyQsaJournal, OriginalVerifyRope}; diff --git a/crates/cuda-driver/src/routed_group_workspace.rs b/crates/cuda-driver/src/routed_group_workspace.rs index 0b291ae6..a6fc5ead 100644 --- a/crates/cuda-driver/src/routed_group_workspace.rs +++ b/crates/cuda-driver/src/routed_group_workspace.rs @@ -30,7 +30,6 @@ pub struct RoutedGroupWorkspace<'ctx> { any(target_os = "linux", target_os = "windows"), target_pointer_width = "64" ))] -#[path = "routed_group_workspace_gpu.rs"] mod gpu; // Additive closed column loan: all preceding workspace methods are byte-exact. @@ -43,7 +42,6 @@ pub struct RoutedColumnsLoan<'ws, 'cols, 'activation, 'ctx> { } #[cfg(all(test, feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_arch = "x86_64"))] -#[path = "routed_columns_loan_gpu.rs"] mod loan_gpu; mod context; diff --git a/crates/cuda-driver/src/routed_group_workspace/context.rs b/crates/cuda-driver/src/routed_group_workspace/context.rs index ec197dd6..be9f6a42 100644 --- a/crates/cuda-driver/src/routed_group_workspace/context.rs +++ b/crates/cuda-driver/src/routed_group_workspace/context.rs @@ -1,5 +1,5 @@ -//! Methods of `Context`: `routed_group_workspace`. -//! Methods of `RoutedGroupWorkspace`: `allocated_bytes`, `is_failed`, `validate`, `disjoint` and 12 more. +//! Routed grouped-projection workspace: creation under the context budget, ownership and validation of its table, +//! Q8 and status buffers, the gate/up and down column projections with their admission checks, and release. use super::{ ALLOCATED_BYTES, Context, DeviceBuffer, Error, FixedKernel, FixedOperation, NativeWeights, ProjectionKind, diff --git a/crates/cuda-driver/src/routed_group_workspace_gpu.rs b/crates/cuda-driver/src/routed_group_workspace/gpu.rs similarity index 98% rename from crates/cuda-driver/src/routed_group_workspace_gpu.rs rename to crates/cuda-driver/src/routed_group_workspace/gpu.rs index e0a62115..6894ccd2 100644 --- a/crates/cuda-driver/src/routed_group_workspace_gpu.rs +++ b/crates/cuda-driver/src/routed_group_workspace/gpu.rs @@ -194,9 +194,7 @@ struct Subject<'a, 'c, 'w, 'x> { context: &'a Context<'c>, workspace: &'w mut RoutedGroupWorkspace<'x>, } -#[path = "routed_group_workspace_gpu/gu_case.rs"] mod gu_case; use gu_case::gu_case; -#[path = "routed_group_workspace_gpu/down_case.rs"] mod down_case; use down_case::down_case; diff --git a/crates/cuda-driver/src/routed_group_workspace_gpu/down_case.rs b/crates/cuda-driver/src/routed_group_workspace/gpu/down_case.rs similarity index 100% rename from crates/cuda-driver/src/routed_group_workspace_gpu/down_case.rs rename to crates/cuda-driver/src/routed_group_workspace/gpu/down_case.rs diff --git a/crates/cuda-driver/src/routed_group_workspace_gpu/gu_case.rs b/crates/cuda-driver/src/routed_group_workspace/gpu/gu_case.rs similarity index 100% rename from crates/cuda-driver/src/routed_group_workspace_gpu/gu_case.rs rename to crates/cuda-driver/src/routed_group_workspace/gpu/gu_case.rs diff --git a/crates/cuda-driver/src/routed_columns_loan_gpu.rs b/crates/cuda-driver/src/routed_group_workspace/loan_gpu.rs similarity index 99% rename from crates/cuda-driver/src/routed_columns_loan_gpu.rs rename to crates/cuda-driver/src/routed_group_workspace/loan_gpu.rs index b124eb3b..c10417a7 100644 --- a/crates/cuda-driver/src/routed_columns_loan_gpu.rs +++ b/crates/cuda-driver/src/routed_group_workspace/loan_gpu.rs @@ -151,6 +151,5 @@ struct LoanProof<'a, 'x, 'y> { finite: &'a mut RoutedStageFiniteGuard<'y>, report: &'a mut Report, } -#[path = "routed_columns_loan_gpu/loan_cases.rs"] mod loan_cases; use loan_cases::{case, mixed_pair}; diff --git a/crates/cuda-driver/src/routed_columns_loan_gpu/loan_cases.rs b/crates/cuda-driver/src/routed_group_workspace/loan_gpu/loan_cases.rs similarity index 100% rename from crates/cuda-driver/src/routed_columns_loan_gpu/loan_cases.rs rename to crates/cuda-driver/src/routed_group_workspace/loan_gpu/loan_cases.rs diff --git a/crates/cuda-driver/src/routed_group_workspace/routed_group_down_projection.rs b/crates/cuda-driver/src/routed_group_workspace/routed_group_down_projection.rs index 3911c749..7007893d 100644 --- a/crates/cuda-driver/src/routed_group_workspace/routed_group_down_projection.rs +++ b/crates/cuda-driver/src/routed_group_workspace/routed_group_down_projection.rs @@ -2,7 +2,6 @@ //! quantization and the column launches. //! Apart from `routed_group_workspace.rs`, which holds the types and the gate/up side. -#[allow(unused_imports)] use super::context::{check_table, reserve_pointers}; use super::{ Context, DeviceBuffer, Error, FixedKernel, FixedOperation, NativeWeights, ProjectionKind, ProjectionShape, diff --git a/crates/cuda-driver/src/routed_resident_queue.rs b/crates/cuda-driver/src/routed_resident_queue.rs index 452ec6a7..3b0538ca 100644 --- a/crates/cuda-driver/src/routed_resident_queue.rs +++ b/crates/cuda-driver/src/routed_resident_queue.rs @@ -68,14 +68,11 @@ enum Command { any(target_os = "linux", target_os = "windows"), target_pointer_width = "64" ))] -#[path = "routed_resident_queue_gpu.rs"] mod gpu; mod compose_phases; mod routed_resident_completion; mod routed_resident_queue_drop; mod routed_resident_queue_operations; -#[allow(unused_imports)] use routed_resident_queue_drop::gu_operation; -#[allow(unused_imports)] use routed_resident_queue_drop::scan; diff --git a/crates/cuda-driver/src/routed_resident_queue_gpu.rs b/crates/cuda-driver/src/routed_resident_queue/gpu.rs similarity index 83% rename from crates/cuda-driver/src/routed_resident_queue_gpu.rs rename to crates/cuda-driver/src/routed_resident_queue/gpu.rs index aaddc3c8..8b48b2c6 100644 --- a/crates/cuda-driver/src/routed_resident_queue_gpu.rs +++ b/crates/cuda-driver/src/routed_resident_queue/gpu.rs @@ -55,31 +55,14 @@ fn original_first_routed_resident_pipeline_all_products_refusals_reset_and_clean eprintln!("ROUTED-RESIDENT-QUEUE {report:?}"); } -#[path = "routed_resident_queue_gpu/upload.rs"] mod upload; -#[allow(unused_imports)] use upload::activation; -#[allow(unused_imports)] -use upload::compare; -#[allow(unused_imports)] -use upload::finite; -#[allow(unused_imports)] -use upload::original; -#[allow(unused_imports)] use upload::pair; -#[allow(unused_imports)] use upload::read; -#[allow(unused_imports)] use upload::upload; -#[allow(unused_imports)] use upload::view; -#[allow(unused_imports)] use upload::weights; -#[path = "routed_resident_queue_gpu/queue_cases.rs"] mod queue_cases; -#[allow(unused_imports)] use queue_cases::{CaseSpec, QueueProof, case}; -#[path = "routed_resident_queue_gpu/run.rs"] mod run; -#[allow(unused_imports)] use run::run; diff --git a/crates/cuda-driver/src/routed_resident_queue_gpu/queue_cases.rs b/crates/cuda-driver/src/routed_resident_queue/gpu/queue_cases.rs similarity index 98% rename from crates/cuda-driver/src/routed_resident_queue_gpu/queue_cases.rs rename to crates/cuda-driver/src/routed_resident_queue/gpu/queue_cases.rs index 4dc5bb0d..5c00626c 100644 --- a/crates/cuda-driver/src/routed_resident_queue_gpu/queue_cases.rs +++ b/crates/cuda-driver/src/routed_resident_queue/gpu/queue_cases.rs @@ -1,5 +1,5 @@ -//! Methods of `CaseRig`: `allocate`, `run`, `pair_over_inputs`, `refusal_pass` and 3 more. -//! Functions: `with_columns`, `block_width`, `case`, `refusal_step` and 2 more. +//! GPU proof cases of the routed resident queue: for each gate/up and down format and column count, it runs the +//! original path first, then the queue, and pins identical products, bad-count and foreign-weight refusals. use super::{ Context, DeviceBuffer, Error, Report, Result, RoutedFormat, RoutedGateUpQ8, RoutedResidentOutputs, diff --git a/crates/cuda-driver/src/routed_resident_queue_gpu/run.rs b/crates/cuda-driver/src/routed_resident_queue/gpu/run.rs similarity index 86% rename from crates/cuda-driver/src/routed_resident_queue_gpu/run.rs rename to crates/cuda-driver/src/routed_resident_queue/gpu/run.rs index 8fa12fd1..ff7d4390 100644 --- a/crates/cuda-driver/src/routed_resident_queue_gpu/run.rs +++ b/crates/cuda-driver/src/routed_resident_queue/gpu/run.rs @@ -1,5 +1,5 @@ -//! Functions: `run`. -//! Split out of `gpu` to keep its files under the line limit. +//! Driver of the routed resident queue GPU proof: runs every gate/up and down format pair at 1 and 64 columns +//! plus one fault case on a single queue, then checks the allocation charge and closes the queue. use super::{CHARGE, CaseSpec, Context, Error, Report, Result, RoutedFormat, RoutedResidentQueue, case, combine}; diff --git a/crates/cuda-driver/src/routed_resident_queue_gpu/upload.rs b/crates/cuda-driver/src/routed_resident_queue/gpu/upload.rs similarity index 97% rename from crates/cuda-driver/src/routed_resident_queue_gpu/upload.rs rename to crates/cuda-driver/src/routed_resident_queue/gpu/upload.rs index 9c2a4176..f2bd5cf5 100644 --- a/crates/cuda-driver/src/routed_resident_queue_gpu/upload.rs +++ b/crates/cuda-driver/src/routed_resident_queue/gpu/upload.rs @@ -1,5 +1,5 @@ -//! Functions: `upload`, `read`, `weights`, `activation` and 9 more. Defines `Refusal`. -//! Split out of `gpu` to keep its files under the line limit. +//! Fixtures and the original-path oracle of the routed resident queue GPU proof: uploads, deterministic weights and +//! activations, the original per-stage products with their refusal, and the comparison of the queue's completion. use super::{ Context, DeviceBuffer, DownColumns, Error, QueueProof, Report, Result, RoutedFormat, RoutedGateUpQ8, diff --git a/crates/cuda-driver/src/routed_resident_queue/routed_resident_completion.rs b/crates/cuda-driver/src/routed_resident_queue/routed_resident_completion.rs index da16ad00..b7dd8bb6 100644 --- a/crates/cuda-driver/src/routed_resident_queue/routed_resident_completion.rs +++ b/crates/cuda-driver/src/routed_resident_queue/routed_resident_completion.rs @@ -1,5 +1,5 @@ -//! Methods of `RoutedResidentCompletion`: `numerical_refusal`, `completed_hidden`, `completed_down`. -//! Methods of `Context`: `routed_resident_queue`. +//! Completion view of a routed resident queue run (which stage refused, the usable hidden and down products) +//! and bring-up of the queue: budget check, buffer allocation and warming of the grouped and finite kernels. use super::{ CHARGE, Context, DeviceBuffer, Error, FixedOperation, Q8, RESERVE, Result, RoutedResidentCompletion, diff --git a/crates/cuda-driver/src/routed_resident_queue/routed_resident_queue_drop.rs b/crates/cuda-driver/src/routed_resident_queue/routed_resident_queue_drop.rs index 95057b5f..00d1920b 100644 --- a/crates/cuda-driver/src/routed_resident_queue/routed_resident_queue_drop.rs +++ b/crates/cuda-driver/src/routed_resident_queue/routed_resident_queue_drop.rs @@ -1,5 +1,5 @@ -//! Methods of `Command`: `launch`. Implements `Drop for RoutedResidentQueue`. Functions: `gu_operation`, `scan`. -//! Split out of `routed_resident_queue` to keep its files under the line limit. +//! Drop of the routed resident queue, the mapping of a gate/up format to its grouped kernel, the finite scan command, +//! and the launch of each queued command kind through the driver. use super::{Command, Context, Error, FixedOperation, Result, RoutedFormat, RoutedResidentQueue, ffi}; diff --git a/crates/cuda-driver/src/routed_resident_queue/routed_resident_queue_operations.rs b/crates/cuda-driver/src/routed_resident_queue/routed_resident_queue_operations.rs index 7da97152..a49de14d 100644 --- a/crates/cuda-driver/src/routed_resident_queue/routed_resident_queue_operations.rs +++ b/crates/cuda-driver/src/routed_resident_queue/routed_resident_queue_operations.rs @@ -2,7 +2,6 @@ //! allocated-bytes and failed queries. //! Apart from `routed_resident_queue.rs`, which holds the types and fields. -#[allow(unused_imports)] use super::compose_phases::{ComposeHostBuffers, compose_operations, zeroed_staging}; use super::{ DeviceBuffer, Error, Q8, Rc, Result, RoutedGateUpQ8, RoutedResidentCompletion, RoutedResidentOutputs, diff --git a/crates/cuda-driver/src/routed_stage_finite_guard.rs b/crates/cuda-driver/src/routed_stage_finite_guard.rs index 5523d37b..5fccf55b 100644 --- a/crates/cuda-driver/src/routed_stage_finite_guard.rs +++ b/crates/cuda-driver/src/routed_stage_finite_guard.rs @@ -231,5 +231,4 @@ impl Drop for RoutedStageFiniteGuard<'_> { } #[cfg(all(test, any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))] -#[path = "routed_stage_finite_guard_gpu.rs"] mod gpu; diff --git a/crates/cuda-driver/src/routed_stage_finite_guard_gpu.rs b/crates/cuda-driver/src/routed_stage_finite_guard/gpu.rs similarity index 100% rename from crates/cuda-driver/src/routed_stage_finite_guard_gpu.rs rename to crates/cuda-driver/src/routed_stage_finite_guard/gpu.rs diff --git a/crates/cuda-driver/src/tests.rs b/crates/cuda-driver/src/tests.rs index fd82d1f7..c9ed593e 100644 --- a/crates/cuda-driver/src/tests.rs +++ b/crates/cuda-driver/src/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of `crate`. +//! Tests of the CUDA driver crate root: GPU-only owned read-back (original first, raw words kept), checked subspans, +//! size and error composition, vector and matvec shape boundaries, and refusals that need no CUDA. #[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_arch = "x86_64"))] fn readback_source(size: usize, round: u32) -> Vec { diff --git a/crates/cuda-driver/tests/mock_driver.rs b/crates/cuda-driver/tests/mock_driver.rs index aad1961d..ff34c8b5 100644 --- a/crates/cuda-driver/tests/mock_driver.rs +++ b/crates/cuda-driver/tests/mock_driver.rs @@ -8,188 +8,70 @@ mod isolated_cpu_elf_matrix; #[path = "mock_driver/trace.rs"] mod trace; -#[allow(unused_imports)] -use trace::bootstrap_allocation_bounds; -#[allow(unused_imports)] -use trace::bootstrap_buffer_bounds; -#[allow(unused_imports)] -use trace::bootstrap_buffer_path; -#[allow(unused_imports)] use trace::bootstrap_child; -#[allow(unused_imports)] -use trace::bootstrap_create; -#[allow(unused_imports)] -use trace::bootstrap_early_fault; -#[allow(unused_imports)] use trace::bootstrap_load_failure; -#[allow(unused_imports)] -use trace::configure_faults; -#[allow(unused_imports)] use trace::cuda_errors; -#[allow(unused_imports)] use trace::run_fixture_case; -#[allow(unused_imports)] -use trace::scenario_command; -#[allow(unused_imports)] -use trace::scenario_failure; -#[allow(unused_imports)] use trace::trace; -#[allow(unused_imports)] use trace::valid_context_trace; #[path = "mock_driver/bootstrap_copies.rs"] mod bootstrap_copies; -#[allow(unused_imports)] use bootstrap_copies::bootstrap_close; -#[allow(unused_imports)] use bootstrap_copies::bootstrap_copies; -#[allow(unused_imports)] -use bootstrap_copies::bootstrap_copy_errors; -#[allow(unused_imports)] use bootstrap_copies::bootstrap_copy_trace; -#[allow(unused_imports)] -use bootstrap_copies::bootstrap_dtoh_fault; -#[allow(unused_imports)] -use bootstrap_copies::bootstrap_failed_copy_sync; -#[allow(unused_imports)] use bootstrap_copies::bootstrap_final_trace; -#[allow(unused_imports)] -use bootstrap_copies::bootstrap_htod_fault; -#[allow(unused_imports)] -use bootstrap_copies::bootstrap_pending_trace; -#[allow(unused_imports)] use bootstrap_copies::bootstrap_release; -#[allow(unused_imports)] use bootstrap_copies::vector_call; -#[allow(unused_imports)] use bootstrap_copies::vector_child; -#[allow(unused_imports)] -use bootstrap_copies::vector_count; -#[allow(unused_imports)] -use bootstrap_copies::vector_fixture; #[path = "mock_driver/vector_bounds.rs"] mod vector_bounds; -#[allow(unused_imports)] use vector_bounds::vector_bounds; -#[allow(unused_imports)] -use vector_bounds::vector_cache_trace; -#[allow(unused_imports)] use vector_bounds::vector_close; -#[allow(unused_imports)] use vector_bounds::vector_error; -#[allow(unused_imports)] -use vector_bounds::vector_expected; -#[allow(unused_imports)] -use vector_bounds::vector_fault_trace; -#[allow(unused_imports)] -use vector_bounds::vector_launch_sync; -#[allow(unused_imports)] use vector_bounds::vector_poison_refusals; -#[allow(unused_imports)] -use vector_bounds::vector_second_context; -#[allow(unused_imports)] use vector_bounds::vector_success; -#[allow(unused_imports)] -use vector_bounds::vector_successful_cache_trace; -#[allow(unused_imports)] use vector_bounds::vector_trace; #[path = "mock_driver/vector_module_context_trace.rs"] mod vector_module_context_trace; -#[allow(unused_imports)] -use vector_module_context_trace::check_arithmetic_fixture; -#[allow(unused_imports)] use vector_module_context_trace::check_f32_output; -#[allow(unused_imports)] -use vector_module_context_trace::check_matvec_dimensions; -#[allow(unused_imports)] -use vector_module_context_trace::check_matvec_foreign; -#[allow(unused_imports)] use vector_module_context_trace::f32_bytes; -#[allow(unused_imports)] use vector_module_context_trace::matvec_arithmetic; -#[allow(unused_imports)] -use vector_module_context_trace::matvec_bounds; -#[allow(unused_imports)] use vector_module_context_trace::matvec_call; -#[allow(unused_imports)] use vector_module_context_trace::matvec_child; -#[allow(unused_imports)] -use vector_module_context_trace::matvec_fixture; -#[allow(unused_imports)] use vector_module_context_trace::matvec_oracle; -#[allow(unused_imports)] -use vector_module_context_trace::matvec_rows; -#[allow(unused_imports)] -use vector_module_context_trace::rounded_add; -#[allow(unused_imports)] -use vector_module_context_trace::rounded_product; -#[allow(unused_imports)] use vector_module_context_trace::vector_module_context_trace; #[path = "mock_driver/check_matvec_lengths.rs"] mod check_matvec_lengths; -#[allow(unused_imports)] -use check_matvec_lengths::check_matvec_bad_length; -#[allow(unused_imports)] -use check_matvec_lengths::check_matvec_cache_trace; -#[allow(unused_imports)] use check_matvec_lengths::check_matvec_close; -#[allow(unused_imports)] use check_matvec_lengths::check_matvec_error; -#[allow(unused_imports)] use check_matvec_lengths::check_matvec_lengths; -#[allow(unused_imports)] use check_matvec_lengths::check_matvec_trace; -#[allow(unused_imports)] use check_matvec_lengths::check_poison_trace; -#[allow(unused_imports)] -use check_matvec_lengths::matvec_interleave; -#[allow(unused_imports)] use check_matvec_lengths::matvec_poison_refusals; -#[allow(unused_imports)] -use check_matvec_lengths::matvec_second_context; -#[allow(unused_imports)] use check_matvec_lengths::matvec_success; -#[allow(unused_imports)] use check_matvec_lengths::release_poisoned_fixture; #[path = "mock_driver/matvec_launch_count.rs"] mod matvec_launch_count; -#[allow(unused_imports)] use matvec_launch_count::check_launch_sync; -#[allow(unused_imports)] use matvec_launch_count::check_matvec_both_cleanup; -#[allow(unused_imports)] use matvec_launch_count::check_matvec_geometry; -#[allow(unused_imports)] use matvec_launch_count::matvec_launch_count; #[path = "mock_driver/row_types.rs"] mod row_types; -#[allow(unused_imports)] use row_types::ARITHMETIC_FIXTURES; -#[allow(unused_imports)] use row_types::COPY_POISON; -#[allow(unused_imports)] use row_types::Row; -#[allow(unused_imports)] use row_types::SCENARIO_FAILURES; -#[allow(unused_imports)] use row_types::SCENARIOS; -#[allow(unused_imports)] use row_types::VECTOR_ERRORS; -#[allow(unused_imports)] use row_types::VECTOR_EXECUTION_FAILURES; -#[allow(unused_imports)] use row_types::VECTOR_POISON; -#[allow(unused_imports)] use row_types::VectorFixture; -#[allow(unused_imports)] use row_types::WRONG_POP; #[path = "mock_driver/matvec_execution_failures_types.rs"] mod matvec_execution_failures_types; -#[allow(unused_imports)] use matvec_execution_failures_types::MATVEC_ERRORS; -#[allow(unused_imports)] use matvec_execution_failures_types::MATVEC_EXECUTION_FAILURES; -#[allow(unused_imports)] use matvec_execution_failures_types::MATVEC_POISON; -#[allow(unused_imports)] use matvec_execution_failures_types::MatvecFixture; diff --git a/crates/cuda-driver/tests/mock_driver/bootstrap_copies.rs b/crates/cuda-driver/tests/mock_driver/bootstrap_copies.rs index 2d4ba11b..fdc93aed 100644 --- a/crates/cuda-driver/tests/mock_driver/bootstrap_copies.rs +++ b/crates/cuda-driver/tests/mock_driver/bootstrap_copies.rs @@ -1,7 +1,6 @@ //! Functions: `bootstrap_copies`, `bootstrap_copy_errors`, `bootstrap_htod_fault`, `bootstrap_dtoh_fault` and 10 more. //! Split out of `mock_driver` to keep its files under the line limit. -#[allow(unused_imports)] use super::*; pub(super) fn bootstrap_copies( diff --git a/crates/cuda-driver/tests/mock_driver/check_matvec_lengths.rs b/crates/cuda-driver/tests/mock_driver/check_matvec_lengths.rs index 4e19ac21..ff2b9bc0 100644 --- a/crates/cuda-driver/tests/mock_driver/check_matvec_lengths.rs +++ b/crates/cuda-driver/tests/mock_driver/check_matvec_lengths.rs @@ -1,7 +1,6 @@ //! Functions: `check_matvec_lengths`, `check_matvec_bad_length`, `check_matvec_error`, `matvec_poison_refusals` and ... //! Split out of `mock_driver` to keep its files under the line limit. -#[allow(unused_imports)] use super::*; use leleka_cuda_driver::MatvecDims; diff --git a/crates/cuda-driver/tests/mock_driver/isolated_cpu_elf_matrix.rs b/crates/cuda-driver/tests/mock_driver/isolated_cpu_elf_matrix.rs index d741beff..7ed3e4fe 100644 --- a/crates/cuda-driver/tests/mock_driver/isolated_cpu_elf_matrix.rs +++ b/crates/cuda-driver/tests/mock_driver/isolated_cpu_elf_matrix.rs @@ -1,6 +1,5 @@ //! Tests of `mock_driver` by topic: isolated_cpu_elf_matrix, fixture_child. -#[allow(unused_imports)] use super::*; #[test] diff --git a/crates/cuda-driver/tests/mock_driver/matvec_execution_failures_types.rs b/crates/cuda-driver/tests/mock_driver/matvec_execution_failures_types.rs index c7814105..0366f9b8 100644 --- a/crates/cuda-driver/tests/mock_driver/matvec_execution_failures_types.rs +++ b/crates/cuda-driver/tests/mock_driver/matvec_execution_failures_types.rs @@ -1,8 +1,6 @@ //! Defines `MatvecFixture`. //! MATVEC_EXECUTION_FAILURES, MATVEC_POISON, MATVEC_ERRORS, MatvecFixture. -#[allow(unused_imports)] -use super::*; pub(super) const MATVEC_EXECUTION_FAILURES: &[&str] = &[ "matvec_load", diff --git a/crates/cuda-driver/tests/mock_driver/matvec_launch_count.rs b/crates/cuda-driver/tests/mock_driver/matvec_launch_count.rs index 0ddfb76b..d776a880 100644 --- a/crates/cuda-driver/tests/mock_driver/matvec_launch_count.rs +++ b/crates/cuda-driver/tests/mock_driver/matvec_launch_count.rs @@ -1,7 +1,6 @@ //! Functions: `matvec_launch_count`, `check_matvec_geometry`, `check_matvec_both_cleanup`, `check_launch_sync`. //! Split out of `mock_driver` to keep its files under the line limit. -#[allow(unused_imports)] use super::*; pub(super) fn matvec_launch_count(case: &str) -> usize { diff --git a/crates/cuda-driver/tests/mock_driver/row_types.rs b/crates/cuda-driver/tests/mock_driver/row_types.rs index f86771b4..d1374922 100644 --- a/crates/cuda-driver/tests/mock_driver/row_types.rs +++ b/crates/cuda-driver/tests/mock_driver/row_types.rs @@ -1,8 +1,6 @@ //! Defines `Row`, `VectorFixture`. //! Row, SCENARIOS, SCENARIO_FAILURES, WRONG_POP, COPY_POISON, VECTOR_EXECUTION_FAILURES .... -#[allow(unused_imports)] -use super::*; #[derive(Debug)] pub(super) struct Row { diff --git a/crates/cuda-driver/tests/mock_driver/trace.rs b/crates/cuda-driver/tests/mock_driver/trace.rs index 4283d2d0..8f1b2b66 100644 --- a/crates/cuda-driver/tests/mock_driver/trace.rs +++ b/crates/cuda-driver/tests/mock_driver/trace.rs @@ -1,7 +1,6 @@ //! Functions: `trace`, `valid_context_trace`, `cuda_errors`, `run_fixture_case` and 10 more. //! Split out of `mock_driver` to keep its files under the line limit. -#[allow(unused_imports)] use super::*; pub(super) fn trace() -> Vec { diff --git a/crates/cuda-driver/tests/mock_driver/vector_bounds.rs b/crates/cuda-driver/tests/mock_driver/vector_bounds.rs index 5f31926a..3c8a63ee 100644 --- a/crates/cuda-driver/tests/mock_driver/vector_bounds.rs +++ b/crates/cuda-driver/tests/mock_driver/vector_bounds.rs @@ -1,7 +1,6 @@ //! Functions: `vector_bounds`, `vector_error`, `vector_poison_refusals`, `vector_expected` and 8 more. //! Split out of `mock_driver` to keep its files under the line limit. -#[allow(unused_imports)] use super::*; use leleka_cuda_driver::MatvecDims; diff --git a/crates/cuda-driver/tests/mock_driver/vector_module_context_trace.rs b/crates/cuda-driver/tests/mock_driver/vector_module_context_trace.rs index 2186851c..88cf7492 100644 --- a/crates/cuda-driver/tests/mock_driver/vector_module_context_trace.rs +++ b/crates/cuda-driver/tests/mock_driver/vector_module_context_trace.rs @@ -1,7 +1,6 @@ //! Functions: `vector_module_context_trace`, `f32_bytes`, `rounded_product`, `rounded_add` and 11 more. //! Split out of `mock_driver` to keep its files under the line limit. -#[allow(unused_imports)] use super::*; use leleka_cuda_driver::MatvecDims; diff --git a/crates/cuda-driver/tests/original_serve_preflight_probe.rs b/crates/cuda-driver/tests/original_serve_preflight_probe.rs index 7e1a9830..6913b37c 100644 --- a/crates/cuda-driver/tests/original_serve_preflight_probe.rs +++ b/crates/cuda-driver/tests/original_serve_preflight_probe.rs @@ -55,21 +55,12 @@ mod preflight_00_sealed_asset_report; #[path = "original_serve_preflight_probe/synthetic_mtp_owner.rs"] mod synthetic_mtp_owner; -#[allow(unused_imports)] use synthetic_mtp_owner::budget; -#[allow(unused_imports)] -use synthetic_mtp_owner::embed_row_bytes; -#[allow(unused_imports)] use synthetic_mtp_owner::env_list; -#[allow(unused_imports)] use synthetic_mtp_owner::env_usize; -#[allow(unused_imports)] use synthetic_mtp_owner::geometry; -#[allow(unused_imports)] use synthetic_mtp_owner::layout_options; -#[allow(unused_imports)] use synthetic_mtp_owner::{MtpShape, synthetic_mtp}; #[path = "original_serve_preflight_probe/synthetic_verifier.rs"] mod synthetic_verifier; -#[allow(unused_imports)] -use synthetic_verifier::{Drafting, Sizes, synthetic_verifier}; +use synthetic_verifier::{Sizes, synthetic_verifier}; diff --git a/crates/cuda-driver/tests/original_serve_preflight_probe/preflight_00_sealed_asset_report.rs b/crates/cuda-driver/tests/original_serve_preflight_probe/preflight_00_sealed_asset_report.rs index 1768b8cd..c2f4019e 100644 --- a/crates/cuda-driver/tests/original_serve_preflight_probe/preflight_00_sealed_asset_report.rs +++ b/crates/cuda-driver/tests/original_serve_preflight_probe/preflight_00_sealed_asset_report.rs @@ -2,7 +2,6 @@ //! preflight_00_sealed_asset_report, preflight_01_device_limits, preflight_10_lazy_constructors, //! preflight_20_prefill_arena .... -#[allow(unused_imports)] use super::*; /// Which gating assets the build itself reports as unsealed (no GPU needed beyond the process). diff --git a/crates/cuda-driver/tests/original_serve_preflight_probe/synthetic_mtp_owner.rs b/crates/cuda-driver/tests/original_serve_preflight_probe/synthetic_mtp_owner.rs index f2185aa2..a5b9a047 100644 --- a/crates/cuda-driver/tests/original_serve_preflight_probe/synthetic_mtp_owner.rs +++ b/crates/cuda-driver/tests/original_serve_preflight_probe/synthetic_mtp_owner.rs @@ -1,7 +1,6 @@ //! The probe knobs read from the environment and the synthetic MTP owner assembly (`synthetic_mtp`): sizes, layout //! options and the owner built over uninitialised, correctly sized weights. -#[allow(unused_imports)] use super::*; pub(super) fn env_usize(name: &str, default: usize) -> usize { diff --git a/crates/cuda-driver/tests/original_serve_preflight_probe/synthetic_verifier.rs b/crates/cuda-driver/tests/original_serve_preflight_probe/synthetic_verifier.rs index 875df6ee..a3d8b2b8 100644 --- a/crates/cuda-driver/tests/original_serve_preflight_probe/synthetic_verifier.rs +++ b/crates/cuda-driver/tests/original_serve_preflight_probe/synthetic_verifier.rs @@ -1,7 +1,6 @@ //! The synthetic verifier probe: window graphs and the commit graph recorded over uninitialised weights, then //! replayed request by request over the same MTP drafter. -#[allow(unused_imports)] use super::*; use std::rc::Rc; use weights::Weights; diff --git a/crates/cuda-driver/tests/projection_family_mock/common_protocol_matrix.rs b/crates/cuda-driver/tests/projection_family_mock/common_protocol_matrix.rs index b8e1e420..2a9f2a6c 100644 --- a/crates/cuda-driver/tests/projection_family_mock/common_protocol_matrix.rs +++ b/crates/cuda-driver/tests/projection_family_mock/common_protocol_matrix.rs @@ -1,6 +1,5 @@ //! Tests of `projection_family_mock` by topic: common_protocol_matrix. -#[allow(unused_imports)] use super::*; use leleka_cuda_driver::{Context, DeviceBuffer}; use std::{path::Path, process::Output}; diff --git a/crates/cuda-driver/tests/projection_family_mock/family_public_q8_child.rs b/crates/cuda-driver/tests/projection_family_mock/family_public_q8_child.rs index e8372826..cf0a5f3c 100644 --- a/crates/cuda-driver/tests/projection_family_mock/family_public_q8_child.rs +++ b/crates/cuda-driver/tests/projection_family_mock/family_public_q8_child.rs @@ -1,6 +1,5 @@ //! Tests of `projection_family_mock` by topic: family_public_q8_child. -#[allow(unused_imports)] use super::*; use leleka_cuda_driver::{Context, DeviceBuffer}; use std::path::Path; diff --git a/crates/cuda-driver/tests/q6_mock/isolated_q6_protocol_matrix.rs b/crates/cuda-driver/tests/q6_mock/isolated_q6_protocol_matrix.rs index 36476437..0697a88a 100644 --- a/crates/cuda-driver/tests/q6_mock/isolated_q6_protocol_matrix.rs +++ b/crates/cuda-driver/tests/q6_mock/isolated_q6_protocol_matrix.rs @@ -1,6 +1,5 @@ //! Tests of `q6_mock` by topic: isolated_q6_protocol_matrix. -#[allow(unused_imports)] use super::*; use std::path::Path; diff --git a/crates/cuda-driver/tests/q6_mock/q6_fixture_child.rs b/crates/cuda-driver/tests/q6_mock/q6_fixture_child.rs index b19a1f8d..dbe821cb 100644 --- a/crates/cuda-driver/tests/q6_mock/q6_fixture_child.rs +++ b/crates/cuda-driver/tests/q6_mock/q6_fixture_child.rs @@ -1,6 +1,5 @@ //! Tests of `q6_mock` by topic: q6_fixture_child. -#[allow(unused_imports)] use super::*; use leleka_cuda_driver::{Context, Device, DeviceBuffer}; diff --git a/crates/cuda-model/src/bringup_trace.rs b/crates/cuda-model/src/bringup_trace.rs index 0df8203c..e229ed44 100644 --- a/crates/cuda-model/src/bringup_trace.rs +++ b/crates/cuda-model/src/bringup_trace.rs @@ -1,9 +1,11 @@ //! The bring-up tracing switch shared by the driver's `bringup_trace!` macro and the command profile. +use crate::env_switch::{EnvSwitch, rules}; + /// Bring-up tracing: `LELEKA_BRINGUP_TRACE` set (any value) enables the `DBG`/`PROBE` diagnostics on stderr. /// Off by default so production serving prints nothing extra. #[inline] pub fn bringup_trace_enabled() -> bool { - static ON: std::sync::OnceLock = std::sync::OnceLock::new(); - *ON.get_or_init(|| crate::settings::var_os("LELEKA_BRINGUP_TRACE").is_some()) + static BRINGUP_TRACE: EnvSwitch = EnvSwitch::new("LELEKA_BRINGUP_TRACE", rules::is_set); + BRINGUP_TRACE.get() } diff --git a/crates/cuda-model/src/command_profile.rs b/crates/cuda-model/src/command_profile.rs index 69488787..1b9c369d 100644 --- a/crates/cuda-model/src/command_profile.rs +++ b/crates/cuda-model/src/command_profile.rs @@ -2,6 +2,7 @@ //! producers (each command drained on its own; attribution only, the drains slow the run). The runtime's //! `PREFILL-PROFILE` takes and prints the totals once per chunk. use std::sync::Mutex; +use crate::env_switch::{EnvSwitch, rules}; use std::time::Duration; static TOTALS: Mutex> = Mutex::new(Vec::new()); @@ -9,10 +10,8 @@ static TOTALS: Mutex> = /// Whether per-command timing is on (both switches set). #[inline] pub fn enabled() -> bool { - static ON: std::sync::OnceLock = std::sync::OnceLock::new(); - *ON.get_or_init(|| { - crate::bringup_trace_enabled() && crate::settings::var_os("LELEKA_PREFILL_PROFILE_SYNC").is_some() - }) + static PROFILE_SYNC: EnvSwitch = EnvSwitch::new("LELEKA_PREFILL_PROFILE_SYNC", rules::is_set); + crate::bringup_trace_enabled() && PROFILE_SYNC.get() } pub fn add(producer: &'static str, index: usize, label: &'static str, elapsed: Duration) { if let Ok(mut totals) = TOTALS.lock() { diff --git a/crates/cuda-model/src/env_switch.rs b/crates/cuda-model/src/env_switch.rs new file mode 100644 index 00000000..ed6ebc56 --- /dev/null +++ b/crates/cuda-model/src/env_switch.rs @@ -0,0 +1,122 @@ +//! An operator switch read once from one environment variable, with the rule that turns its text into a flag. +//! +//! Many tuning and diagnostic switches of the CUDA stack are "on", "off" or "on unless `0`". Each used to carry its own +//! `static ON: OnceLock` and its own comparison. [`EnvSwitch`] names the variable and the [`rules`] in one place, +//! caches the answer on the first [`EnvSwitch::get`] (a hot path pays one atomic load afterwards, never an environment +//! read), and can be judged without touching the process environment through [`EnvSwitch::decide`]. +//! +//! This file is the one place of the model crate where a variable is read and a value is cached for the process life; +//! both are listed in `architecture.json` `exceptions`. + +use std::ffi::OsStr; +use std::sync::OnceLock; + +/// A rule: the variable's text (`None` when it is unset) to the switch position. +pub type Rule = fn(Option<&OsStr>) -> bool; + +/// The rules the switches of this repository use. The names say what makes the switch "on". +pub mod rules { + use std::ffi::OsStr; + + /// On when the variable exists, with any value (also empty). + pub fn is_set(value: Option<&OsStr>) -> bool { + value.is_some() + } + + /// On when the variable exists and is not `0`. + pub fn is_set_and_not_zero(value: Option<&OsStr>) -> bool { + value.is_some_and(|v| v != "0") + } + + /// On only for the value `1`. + pub fn is_one(value: Option<&OsStr>) -> bool { + value.is_some_and(|v| v == "1") + } + + /// On when the variable is valid text that is neither empty nor `0`. + pub fn is_text_not_empty_and_not_zero(value: Option<&OsStr>) -> bool { + value.and_then(OsStr::to_str).is_some_and(|v| !v.is_empty() && v != "0") + } + + /// On unless the variable is `0` (a switch that is on by default). + pub fn is_unset_or_not_zero(value: Option<&OsStr>) -> bool { + value.is_none_or(|v| v != "0") + } + + /// On unless the variable is `off` or `0` (a switch that is on by default). + pub fn is_unset_or_not_off(value: Option<&OsStr>) -> bool { + value.is_none_or(|v| v != "off" && v != "0") + } +} + +/// One switch: the variable, its rule, and the answer cached on the first read. +pub struct EnvSwitch { + name: &'static str, + rule: Rule, + answer: OnceLock, +} + +impl EnvSwitch { + /// A switch over the variable `name`; nothing is read until the first [`Self::get`]. + pub const fn new(name: &'static str, rule: Rule) -> Self { + Self { name, rule, answer: OnceLock::new() } + } + + /// The name of the variable. + pub const fn name(&self) -> &'static str { + self.name + } + + /// The position of the switch: the environment is read on the first call only. + #[inline] + pub fn get(&self) -> bool { + *self.answer.get_or_init(|| (self.rule)(std::env::var_os(self.name).as_deref())) + } + + /// What the rule says for a given value, without reading the environment or the cache. + pub fn decide(&self, value: Option<&OsStr>) -> bool { + (self.rule)(value) + } +} + +#[cfg(test)] +mod tests { + use super::{EnvSwitch, rules}; + use std::ffi::OsStr; + + fn os(text: &str) -> Option<&OsStr> { + Some(OsStr::new(text)) + } + + #[test] + fn presence_rules_judge_unset_empty_and_zero() { + assert!(!rules::is_set(None) && rules::is_set(os("")) && rules::is_set(os("0"))); + assert!(!rules::is_set_and_not_zero(None) && !rules::is_set_and_not_zero(os("0"))); + assert!(rules::is_set_and_not_zero(os("1")) && rules::is_set_and_not_zero(os("yes"))); + } + + #[test] + fn the_one_rule_accepts_only_one() { + assert!(!rules::is_one(None) && !rules::is_one(os("0")) && !rules::is_one(os("yes"))); + assert!(rules::is_one(os("1"))); + } + + #[test] + fn default_on_rules_turn_off_only_on_their_words() { + assert!(rules::is_unset_or_not_zero(None) && !rules::is_unset_or_not_zero(os("0"))); + assert!(rules::is_unset_or_not_zero(os("off")) && rules::is_unset_or_not_zero(os("1"))); + assert!(rules::is_unset_or_not_off(None) && !rules::is_unset_or_not_off(os("off"))); + assert!(!rules::is_unset_or_not_off(os("0")) && rules::is_unset_or_not_off(os("on"))); + } + + #[test] + fn a_switch_over_an_unset_variable_follows_its_rule_and_keeps_its_answer() { + static ABSENT_ON: EnvSwitch = + EnvSwitch::new("LELEKA_TEST_SWITCH_THAT_IS_NEVER_SET", rules::is_unset_or_not_zero); + static ABSENT_OFF: EnvSwitch = EnvSwitch::new("LELEKA_TEST_SWITCH_THAT_IS_NEVER_SET", rules::is_one); + assert!(ABSENT_ON.get() && ABSENT_ON.get()); + assert!(!ABSENT_OFF.get()); + assert_eq!(ABSENT_ON.name(), "LELEKA_TEST_SWITCH_THAT_IS_NEVER_SET"); + assert!(!ABSENT_ON.decide(os("0"))); + } +} diff --git a/crates/cuda-model/src/host_profile.rs b/crates/cuda-model/src/host_profile.rs index 9ac86480..1a0d348d 100644 --- a/crates/cuda-model/src/host_profile.rs +++ b/crates/cuda-model/src/host_profile.rs @@ -1,14 +1,15 @@ //! Operator profile of the driver's host-side spans (`LELEKA_SERVE_PROFILE=1`, off by default), summed per thread //! and printed by the runtime's serve profile next to its own spans. Inclusive wall-clock; nested spans are not //! additive. When the switch is off a span is one cached boolean test. +use crate::env_switch::{EnvSwitch, rules}; use std::cell::RefCell; use std::time::Instant; /// `LELEKA_SERVE_PROFILE` set to anything but `0`, read once. #[inline] pub fn enabled() -> bool { - static ON: std::sync::OnceLock = std::sync::OnceLock::new(); - *ON.get_or_init(|| crate::settings::var("LELEKA_SERVE_PROFILE").is_ok_and(|v| !v.is_empty() && v != "0")) + static SERVE_PROFILE: EnvSwitch = EnvSwitch::new("LELEKA_SERVE_PROFILE", rules::is_text_not_empty_and_not_zero); + SERVE_PROFILE.get() } thread_local! { diff --git a/crates/cuda-model/src/lib.rs b/crates/cuda-model/src/lib.rs index de9bf27c..da5026b7 100644 --- a/crates/cuda-model/src/lib.rs +++ b/crates/cuda-model/src/lib.rs @@ -19,6 +19,7 @@ mod bringup_trace; pub mod command_profile; pub mod device_arena; pub mod draft_check_batch; +pub mod env_switch; mod error; mod error_messages; pub mod host_profile; @@ -33,7 +34,6 @@ pub mod ring_prefetch; pub mod s_gemv_legacy; pub mod serving_context; mod shapes; -mod settings; pub use bringup_trace::bringup_trace_enabled; pub use error::{Error, Result}; diff --git a/crates/cuda-model/src/original_mtp_loader.rs b/crates/cuda-model/src/original_mtp_loader.rs index d62cad49..ff2cc2f6 100644 --- a/crates/cuda-model/src/original_mtp_loader.rs +++ b/crates/cuda-model/src/original_mtp_loader.rs @@ -250,20 +250,8 @@ pub struct OriginalMtpLoadPlan { mod tests; mod loader_error; -#[allow(unused_imports)] -use loader_error::add; -#[allow(unused_imports)] -use loader_error::aligned; -#[allow(unused_imports)] pub use loader_error::bind_bytes; -#[allow(unused_imports)] -use loader_error::ceil; -#[allow(unused_imports)] pub use loader_error::coupled_plan; -#[allow(unused_imports)] pub use loader_error::mapped_staging; -#[allow(unused_imports)] -use loader_error::mul; -#[allow(unused_imports)] pub use loader_error::original_mtp_bind_reserve; mod original_mtp_load_plan; diff --git a/crates/cuda-model/src/original_mtp_loader/loader_error.rs b/crates/cuda-model/src/original_mtp_loader/loader_error.rs index 7ea27db1..d59e71e2 100644 --- a/crates/cuda-model/src/original_mtp_loader/loader_error.rs +++ b/crates/cuda-model/src/original_mtp_loader/loader_error.rs @@ -1,5 +1,5 @@ -//! Methods of `LoaderError`: `message`. Methods of `WeightBankPlan`: `new`, `expert_reads`. -//! Implements `Iterator for ExpertReads`. Functions: `add`, `mul`, `ceil`, `aligned` and 10 more. Defines `Placement`. +//! Sizing arithmetic of the original MTP draft loader: loader error messages, overflow-checked helpers, +//! weight-bank expert read ranges, the draft K/V placement and byte plan, the coupled-sampler plan, the bind reserve. use super::{ BindInputs, COUPLED_HISTORY, CoupledPlan, EXPERT_BLOB_BYTES, EXPERT_READ_BYTES, ExpertReads, KvFormat, KvInputs, diff --git a/crates/cuda-model/src/original_mtp_loader/original_mtp_load_plan.rs b/crates/cuda-model/src/original_mtp_loader/original_mtp_load_plan.rs index 89134258..e8fa45d3 100644 --- a/crates/cuda-model/src/original_mtp_loader/original_mtp_load_plan.rs +++ b/crates/cuda-model/src/original_mtp_loader/original_mtp_load_plan.rs @@ -1,5 +1,5 @@ -//! Methods of `OriginalMtpLoadPlan`: `new`, `kv_inputs`, `check_profile`, `check_session` and 9 more. -//! Split out of `original_mtp_loader` to keep its files under the line limit. +//! The whole load plan of the original MTP draft: validates a startup capture against the one closed profile, +//! then derives the weight bank, K/V plan, mapped staging, bind reserve and coupled layout from it. use super::{ CLOSED_MAX_CELLS, CLOSED_WINDOW, CoupledPlan, KvInputs, KvMode, KvPlan, LoaderError, OriginalMtpCapture, diff --git a/crates/cuda-model/src/original_mtp_loader/tests.rs b/crates/cuda-model/src/original_mtp_loader/tests.rs index 73d047e5..4601297a 100644 --- a/crates/cuda-model/src/original_mtp_loader/tests.rs +++ b/crates/cuda-model/src/original_mtp_loader/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests that pin the MTP load plan: the shipped profile gives the retained ring layout byte for byte, +//! profiles outside the closed set are refused with a reason, and bank, reserve, coupled plan, staging match. use super::*; diff --git a/crates/cuda-model/src/original_prefill_schedule.rs b/crates/cuda-model/src/original_prefill_schedule.rs index e566f0fa..3fafe0e0 100644 --- a/crates/cuda-model/src/original_prefill_schedule.rs +++ b/crates/cuda-model/src/original_prefill_schedule.rs @@ -220,12 +220,8 @@ mod tests; mod ring_policy; pub use ring_policy::FuseFlags; -#[allow(unused_imports)] pub use ring_policy::chunks; -#[allow(unused_imports)] pub use ring_policy::fuse_after_half; -#[allow(unused_imports)] pub use ring_policy::ring_slots; mod planner; -#[allow(unused_imports)] pub use planner::check_trace; diff --git a/crates/cuda-model/src/original_prefill_schedule/planner.rs b/crates/cuda-model/src/original_prefill_schedule/planner.rs index d78213e2..bbe42a1c 100644 --- a/crates/cuda-model/src/original_prefill_schedule/planner.rs +++ b/crates/cuda-model/src/original_prefill_schedule/planner.rs @@ -1,5 +1,5 @@ -//! Methods of `Planner`: `new`, `push`, `issue_until`, `plan_chunk` and 5 more. -//! Functions: `is_stream_all`, `check_config`, `chunk_sequence`, `staging_jobs` and 5 more. +//! Planner of the original prefill expert streaming: builds the per-chunk schedule of copies, waits and computes +//! for the stream_all and staged walks, and a ring/event checker that rejects unsafe slot reuse in a planned trace. use super::{ ChunkStreaming, CopySource, IssueState, JobKind, PlanError, Planner, RING_MAX, STAGE, SchedOp, Slot, SourceView, diff --git a/crates/cuda-model/src/original_prefill_schedule/tests.rs b/crates/cuda-model/src/original_prefill_schedule/tests.rs index 84ef1771..6d7e461b 100644 --- a/crates/cuda-model/src/original_prefill_schedule/tests.rs +++ b/crates/cuda-model/src/original_prefill_schedule/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests that pin the prefill schedule: the traces, PLE read-ahead and fuse rule match golden values from the original; +//! ring slot sizing and chunk hand-off follow its rules, and the checker rejects unsafe or malformed schedules. use super::*; use serde_json::Value; diff --git a/crates/cuda-model/src/qsa_prompt_attention_select.rs b/crates/cuda-model/src/qsa_prompt_attention_select.rs index a58b1bf0..445b39b4 100644 --- a/crates/cuda-model/src/qsa_prompt_attention_select.rs +++ b/crates/cuda-model/src/qsa_prompt_attention_select.rs @@ -130,36 +130,18 @@ pub struct LaunchSlice { mod tests; mod pool_presence; -#[allow(unused_imports)] -use pool_presence::align_up; -#[allow(unused_imports)] pub use pool_presence::hip_wmma_usable; -#[allow(unused_imports)] pub use pool_presence::launch_slices; -#[allow(unused_imports)] pub use pool_presence::pool_row; -#[allow(unused_imports)] pub use pool_presence::reference_attention_f64; -#[allow(unused_imports)] pub use pool_presence::scale_log2; -#[allow(unused_imports)] pub use pool_presence::select; -#[allow(unused_imports)] pub use pool_presence::slice_offsets; -#[allow(unused_imports)] pub use pool_presence::smem_bytes; -#[allow(unused_imports)] pub use pool_presence::smem2_bytes; mod q_prescale; -#[allow(unused_imports)] pub use q_prescale::f16_hi_lo; -#[allow(unused_imports)] pub use q_prescale::f16_round; -#[allow(unused_imports)] pub use q_prescale::f16_to_f32; -#[allow(unused_imports)] pub use q_prescale::f32_to_f16; -#[allow(unused_imports)] -use q_prescale::pow2f; -#[allow(unused_imports)] pub use q_prescale::q_prescale; diff --git a/crates/cuda-model/src/qsa_prompt_attention_select/pool_presence.rs b/crates/cuda-model/src/qsa_prompt_attention_select/pool_presence.rs index 9389e27b..162760a7 100644 --- a/crates/cuda-model/src/qsa_prompt_attention_select/pool_presence.rs +++ b/crates/cuda-model/src/qsa_prompt_attention_select/pool_presence.rs @@ -1,5 +1,5 @@ -//! Methods of `PoolPresence`: `int8`, `fp16`, `hybrid_k8v4`, `q4`. `impl Shapes`. -//! Functions: `align_up`, `smem_bytes`, `smem2_bytes`, `pools_admitted` and 9 more. +//! Kernel selection of the QSA prompt attention: which K/V pools are present, admission of pools and shapes, +//! the port of the original decision tree for CUDA, shared-memory sizes, launch slicing and an FP64 reference. use super::{ CH, CH2, CStr, DEFAULT_SHARED_LIMIT, DeviceCaps, ENTRY_FP16, ENTRY_K8V4, ENTRY_V1_INT8, ENTRY_V2_INT8, G, HD, @@ -70,12 +70,6 @@ impl SelectSwitches { pub fn from_values(qsa_warp: Option<&str>, prompt_attn_v1: Option<&str>) -> Self { Self { qsa_warp_arm: matches!(qsa_warp, Some("1") | Some("attn")), prompt_attn_v1: prompt_attn_v1.is_some() } } - pub fn from_environment() -> Self { - Self::from_values( - crate::settings::var("STRATA_QSA_WARP").ok().as_deref(), - crate::settings::var("STRATA_PROMPT_ATTN_V1").ok().as_deref(), - ) - } } impl PromptAttnKernel { pub const fn kv_mode(self) -> Option { diff --git a/crates/cuda-model/src/qsa_prompt_attention_select/q_prescale.rs b/crates/cuda-model/src/qsa_prompt_attention_select/q_prescale.rs index 0ac6025c..dd08ddf5 100644 --- a/crates/cuda-model/src/qsa_prompt_attention_select/q_prescale.rs +++ b/crates/cuda-model/src/qsa_prompt_attention_select/q_prescale.rs @@ -1,5 +1,5 @@ -//! Functions: `q_prescale`, `pow2f`, `f16_hi_lo`, `f16_round` and 4 more. -//! Split out of `qsa_prompt_attention_select` to keep its files under the line limit. +//! Host model of the q pre-scale and FP16 hi/lo split the prompt attention kernels apply, with exact +//! binary16 rounding and conversion helpers (round to nearest even), so tests can reproduce the kernel numerics. /// The q pre-scale the kernels apply before the hi/lo FP16 split (exact, power of two): returns `(qe, qup, diff --git a/crates/cuda-model/src/qsa_prompt_attention_select/tests.rs b/crates/cuda-model/src/qsa_prompt_attention_select/tests.rs index 46020b0e..626ae88d 100644 --- a/crates/cuda-model/src/qsa_prompt_attention_select/tests.rs +++ b/crates/cuda-model/src/qsa_prompt_attention_select/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests that pin the prompt attention selection: smem sizes match the compiled structs, the decision tree per +//! architecture, pool and geometry, env switches, launch slicing, page-table rows, the entry table and FP16 rounding. use super::*; diff --git a/crates/cuda-model/src/s_gemv_legacy.rs b/crates/cuda-model/src/s_gemv_legacy.rs index 8eb42df9..41ebaefb 100644 --- a/crates/cuda-model/src/s_gemv_legacy.rs +++ b/crates/cuda-model/src/s_gemv_legacy.rs @@ -121,54 +121,25 @@ pub struct Weights<'a> { mod tests; mod s_form_planners; -#[allow(unused_imports)] -use s_form_planners::bits_u8; -#[allow(unused_imports)] -use s_form_planners::ceil_div; -#[allow(unused_imports)] use s_form_planners::check_tpr; -#[allow(unused_imports)] use s_form_planners::grid_for; -#[allow(unused_imports)] -use s_form_planners::group_shift_of; -#[allow(unused_imports)] pub use s_form_planners::plan_s_gemv; -#[allow(unused_imports)] pub use s_form_planners::plan_s_gemv_q8_0_split; -#[allow(unused_imports)] pub use s_form_planners::plan_s_gemv_q8k; -#[allow(unused_imports)] pub use s_form_planners::plan_s_gemv_q8k_split; -#[allow(unused_imports)] pub use s_form_planners::plan_s_gemv_split; -#[allow(unused_imports)] pub use s_form_planners::plan_s2_gemv; -#[allow(unused_imports)] -use s_form_planners::q8_form_ok; mod s2_gemv_planners; -#[allow(unused_imports)] pub use s2_gemv_planners::code_at; -#[allow(unused_imports)] pub use s2_gemv_planners::decode; -#[allow(unused_imports)] pub use s2_gemv_planners::f16_to_f32; -#[allow(unused_imports)] pub use s2_gemv_planners::naive_f32; -#[allow(unused_imports)] pub use s2_gemv_planners::pack_codes; -#[allow(unused_imports)] pub use s2_gemv_planners::plan_s2_gemv_fast; -#[allow(unused_imports)] pub use s2_gemv_planners::plan_s2_gemv_q8; -#[allow(unused_imports)] pub use s2_gemv_planners::plan_s2_gemv_quads; -#[allow(unused_imports)] pub use s2_gemv_planners::q8_0_dequant; -#[allow(unused_imports)] pub use s2_gemv_planners::q8_split_f32; -#[allow(unused_imports)] pub use s2_gemv_planners::q8k_dequant; -#[allow(unused_imports)] pub use s2_gemv_planners::reference_f64; -#[allow(unused_imports)] pub use s2_gemv_planners::split_f32; diff --git a/crates/cuda-model/src/s_gemv_legacy/tests.rs b/crates/cuda-model/src/s_gemv_legacy/tests.rs index 146a3015..e51b5e8f 100644 --- a/crates/cuda-model/src/s_gemv_legacy/tests.rs +++ b/crates/cuda-model/src/s_gemv_legacy/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests that pin the legacy S-GEMV model: golden cases match the shim-executed kernels bit for bit, +//! pack/unpack and FP16 round-trips, kernel entry names against the CUDA source, and launch plans with refusals. use super::*; use serde_json::Value; diff --git a/crates/cuda-model/src/settings.rs b/crates/cuda-model/src/settings.rs deleted file mode 100644 index 4ce948db..00000000 --- a/crates/cuda-model/src/settings.rs +++ /dev/null @@ -1,17 +0,0 @@ -//! The only place of this crate that reads the process environment (`env-read` ratchet of `architecture.json`). -//! The reads keep their call sites and their parsing; a later step replaces these functions by a parsed settings value. - -use std::env::{self, VarError}; -use std::ffi::{OsStr, OsString}; - -/// `std::env::var`: the text of an environment variable. -#[inline] -pub(crate) fn var>(key: K) -> Result { - env::var(key) -} - -/// `std::env::var_os`: an environment variable that may not be valid text. -#[inline] -pub(crate) fn var_os>(key: K) -> Option { - env::var_os(key) -} diff --git a/crates/deploy/src/reconfigure.rs b/crates/deploy/src/reconfigure.rs index 74e12aca..e0b43c2a 100644 --- a/crates/deploy/src/reconfigure.rs +++ b/crates/deploy/src/reconfigure.rs @@ -102,9 +102,9 @@ pub struct Planned { #[cfg(test)] mod tests; -mod plan_and_persist; +mod reconfigure_commit; mod settings; -pub use plan_and_persist::{ +pub use reconfigure_commit::{ new_request_id, persist, persist_offline, plan, read_outcome, record_settings, take_request, write_outcome, write_request, }; diff --git a/crates/deploy/src/reconfigure/plan_and_persist.rs b/crates/deploy/src/reconfigure/reconfigure_commit.rs similarity index 100% rename from crates/deploy/src/reconfigure/plan_and_persist.rs rename to crates/deploy/src/reconfigure/reconfigure_commit.rs diff --git a/crates/deploy/src/steps.rs b/crates/deploy/src/steps.rs index ce2aafe6..521f60ef 100644 --- a/crates/deploy/src/steps.rs +++ b/crates/deploy/src/steps.rs @@ -60,9 +60,9 @@ mod tests; mod downloads; mod model_assets; mod preparation; -mod probes_and_tools; +mod host_actions; mod service_unit; -mod stamps_and_state; +mod state_records; pub use downloads::{ init_api_key, install_cublas, provision_expert_profile, write_secrets_and_env, }; @@ -72,7 +72,7 @@ pub use model_assets::{ ensure_kar, extract_tokenizer, fetch_and_verify_model, import_mtp_pack, write_configs, }; pub use preparation::{config_of, prepare, replan}; -pub use probes_and_tools::{ +pub use host_actions::{ fetch_status, fetch_status_with_key, install_binaries, make_dirs, probe_ready_at, probe_ready_with_key, run_tool, unit_text, }; @@ -80,11 +80,11 @@ use service_unit::kar_runs_tool; #[cfg(unix)] pub use service_unit::{chown_tree, ensure_service_user, hand_over_to_service_user}; pub use service_unit::{install_unit, start_unit, wait_ready}; -pub use stamps_and_state::{ +pub use state_records::{ binaries_state, cublas_lib_dirs, desired_ld_library_path, file_stamp, gather_fs, probe_ready, render_configs, say, sha256_file, stamp_current, stamp_path, }; -use stamps_and_state::{mtp_complete, write_stamp}; +use state_records::{mtp_complete, write_stamp}; #[cfg(test)] use downloads::download_small; diff --git a/crates/deploy/src/steps/probes_and_tools.rs b/crates/deploy/src/steps/host_actions.rs similarity index 100% rename from crates/deploy/src/steps/probes_and_tools.rs rename to crates/deploy/src/steps/host_actions.rs diff --git a/crates/deploy/src/steps/stamps_and_state.rs b/crates/deploy/src/steps/state_records.rs similarity index 100% rename from crates/deploy/src/steps/stamps_and_state.rs rename to crates/deploy/src/steps/state_records.rs diff --git a/crates/deploy/src/wsl.rs b/crates/deploy/src/wsl.rs index 33d30e2f..2053d10f 100644 --- a/crates/deploy/src/wsl.rs +++ b/crates/deploy/src/wsl.rs @@ -90,9 +90,9 @@ const FIND_LELEKA: &str = concat!( mod tests; mod bridge; -mod distros_and_paths; +mod wsl_translation; pub use bridge::{effective_wsl_memory, list_distros, parse_wslconfig, wsl_exe, wslconfig_advice}; -pub use distros_and_paths::{ +pub use wsl_translation::{ decode_console_text, is_drvfs, linux_to_unc, parse_distro_list, parse_size, pick_distro, to_wsl_path, translate_args, }; diff --git a/crates/deploy/src/wsl/distros_and_paths.rs b/crates/deploy/src/wsl/wsl_translation.rs similarity index 100% rename from crates/deploy/src/wsl/distros_and_paths.rs rename to crates/deploy/src/wsl/wsl_translation.rs diff --git a/crates/experimental-ref/src/cache/tests.rs b/crates/experimental-ref/src/cache/tests.rs index 47ab8fae..22e6a047 100644 --- a/crates/experimental-ref/src/cache/tests.rs +++ b/crates/experimental-ref/src/cache/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests of the KV cache CPU twin: Q4 round trip within half a step in the rotated domain, the streaming write rule +//! (host always, VRAM only when resident), K8V4 composition, and refusal of fp16 and bad geometry. use super::*; use crate::fwht; diff --git a/crates/experimental-ref/src/cvec.rs b/crates/experimental-ref/src/cvec.rs index 0e8ccce5..d7a4768e 100644 --- a/crates/experimental-ref/src/cvec.rs +++ b/crates/experimental-ref/src/cvec.rs @@ -109,8 +109,6 @@ pub struct CvecTables { mod tests; mod cvec_reading_and_errors; -#[allow(unused_imports)] pub use cvec_reading_and_errors::*; mod load_control_vectors; -#[allow(unused_imports)] pub use load_control_vectors::*; diff --git a/crates/experimental-ref/src/cvec/load_control_vectors.rs b/crates/experimental-ref/src/cvec/load_control_vectors.rs index 28808825..bcfdfef4 100644 --- a/crates/experimental-ref/src/cvec/load_control_vectors.rs +++ b/crates/experimental-ref/src/cvec/load_control_vectors.rs @@ -1,5 +1,5 @@ -//! Functions: `direction_layer`, `add_scaled`, `add_file`, `steer_row` and 13 more. Defines `CvecRows`. -//! Split out of `cvec` to keep its files under the line limit. +//! Control-vector loading and application: sums the scaled per-layer directions of GGUF files into project/add tables, +//! and a literal twin of the cvec_apply kernel on the residual rows (warp butterfly sums, pending FFN write, steering). use super::{CvecError, CvecMode, CvecOptions, CvecTables, MAXK, THREADS, parse_gguf}; diff --git a/crates/experimental-ref/src/cvec/tests.rs b/crates/experimental-ref/src/cvec/tests.rs index 08d81e76..29e6edae 100644 --- a/crates/experimental-ref/src/cvec/tests.rs +++ b/crates/experimental-ref/src/cvec/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests of control vectors: GGUF parsing (layer 0 and layers past the model ignored), project and add modes, single- +//! layer sources, rejections, steering of the residual streams, the pending FFN write and the warp reduction tree. use super::*; diff --git a/crates/experimental-ref/src/keyless.rs b/crates/experimental-ref/src/keyless.rs index 1a115c62..e5e82708 100644 --- a/crates/experimental-ref/src/keyless.rs +++ b/crates/experimental-ref/src/keyless.rs @@ -309,7 +309,7 @@ fn admit_layer(r: &mut Reader<'_>, g: &KeylessGeometry, seen: &mut BTreeSet pub fn parse_artifact<'a>( bytes: &[u8], g: &KeylessGeometry, - source: &dyn Fn(u32, &str) -> Option>, + source: &(impl Fn(u32, &str) -> Option> + ?Sized), ) -> Result { let mut r = Reader { b: bytes, at: 0 }; let (layers, heads) = read_artifact_header(&mut r, g)?; diff --git a/crates/experimental-ref/src/keyless/tests.rs b/crates/experimental-ref/src/keyless/tests.rs index 6a41c414..6af337c7 100644 --- a/crates/experimental-ref/src/keyless/tests.rs +++ b/crates/experimental-ref/src/keyless/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests of keyless V-only QSA: query routing, output-major routing matrix, position handling, key reconstruction +//! of the first 64 dims, the routing artifact round trip with each admission failure, and block geometry. use super::*; diff --git a/crates/experimental-ref/src/kv_stream.rs b/crates/experimental-ref/src/kv_stream.rs index 39ce41d5..8cb0de22 100644 --- a/crates/experimental-ref/src/kv_stream.rs +++ b/crates/experimental-ref/src/kv_stream.rs @@ -139,8 +139,6 @@ pub struct StreamMap { mod tests; mod map_bytes; -#[allow(unused_imports)] pub use map_bytes::*; mod residency_map; -#[allow(unused_imports)] pub use residency_map::*; diff --git a/crates/experimental-ref/src/kv_stream/map_bytes.rs b/crates/experimental-ref/src/kv_stream/map_bytes.rs index 1ea1d51f..77cf5a67 100644 --- a/crates/experimental-ref/src/kv_stream/map_bytes.rs +++ b/crates/experimental-ref/src/kv_stream/map_bytes.rs @@ -1,5 +1,5 @@ -//! Functions: `map_bytes`, `kv_plan`, `align16`, `qsa_state_bytes` and 2 more. Defines `StateCells`. -//! Split out of `kv_stream` to keep its files under the line limit. +//! KV streaming planner arithmetic: size of the residency map, the kv_plan mode choice (resident, ring, streamed), +//! QSA state and host-copy byte sizes, and the guards of a resolve call. use super::{ CTL_INTS, KV_RESIDENT_MIN, KvFormat, KvPlan, PlanSwitches, QsaShapes, RT, STEP_BYTES, StreamError, StreamFormat, diff --git a/crates/experimental-ref/src/kv_stream/residency_map.rs b/crates/experimental-ref/src/kv_stream/residency_map.rs index a6109cdb..47990a13 100644 --- a/crates/experimental-ref/src/kv_stream/residency_map.rs +++ b/crates/experimental-ref/src/kv_stream/residency_map.rs @@ -1,5 +1,5 @@ -//! Methods of `StreamMap`: `new`, `n_slots`, `reset`, `counters` and 11 more. -//! Functions: `ring_table`, `ring_restore`, `stage_from_host`, `observed_order` and 2 more. +//! The KV residency map (StreamMap): CPU model of the CLOCK resolver that claims slots for missed blocks, plus the +//! ring table, the ring restore and the staging copy from the host pool. use super::{ CTL_INTS, Counters, MissOrder, PoolSet, QsaShapes, RT, ResolveBatch, ResolveReport, RingSpan, StreamError, diff --git a/crates/experimental-ref/src/kv_stream/tests.rs b/crates/experimental-ref/src/kv_stream/tests.rs index 6b9ddab3..50293756 100644 --- a/crates/experimental-ref/src/kv_stream/tests.rs +++ b/crates/experimental-ref/src/kv_stream/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests of KV streaming: plan modes, resolve guards, map consistency and counters after eviction, slots used by +//! the call never being victims, miss-order effects, refusal of too many blocks, ring table and state size. use super::*; diff --git a/crates/experimental-ref/src/layout/tests.rs b/crates/experimental-ref/src/layout/tests.rs index d6b29640..739c9741 100644 --- a/crates/experimental-ref/src/layout/tests.rs +++ b/crates/experimental-ref/src/layout/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests of KV layouts: per-cell byte figures per format, pool arrays summing to them, 16-byte alignment, array +//! order, block bytes, uint4 copy run lengths, and the format selection rules of the Original. use super::*; diff --git a/crates/experimental-ref/src/remote_experts.rs b/crates/experimental-ref/src/remote_experts.rs index d0605e92..b516235a 100644 --- a/crates/experimental-ref/src/remote_experts.rs +++ b/crates/experimental-ref/src/remote_experts.rs @@ -349,7 +349,6 @@ pub fn dispatch( } mod device_image; -#[allow(unused_imports)] pub use device_image::*; mod dispatch_groups; use dispatch_groups::{assign_groups, pack_groups, pick_unclaimed}; diff --git a/crates/experimental-ref/src/remote_experts/device_image.rs b/crates/experimental-ref/src/remote_experts/device_image.rs index 413583f3..e20cfd8d 100644 --- a/crates/experimental-ref/src/remote_experts/device_image.rs +++ b/crates/experimental-ref/src/remote_experts/device_image.rs @@ -9,7 +9,7 @@ use super::{ pub struct RemoteMeta; impl RemoteMeta { - pub fn to_bytes(d: &Dispatch, device_slot: &dyn Fn(i32) -> u64) -> [u8; META_BYTES] { + pub fn to_bytes(d: &Dispatch, device_slot: &(impl Fn(i32) -> u64 + ?Sized)) -> [u8; META_BYTES] { let mut b = [0u8; META_BYTES]; for (g, grp) in d.groups.iter().enumerate() { b[META_PTR_OFFSET + g * 8..][..8].copy_from_slice(&device_slot(grp.slot).to_le_bytes()); diff --git a/crates/experimental-ref/src/remote_experts/tests.rs b/crates/experimental-ref/src/remote_experts/tests.rs index a34e8fe9..47258de5 100644 --- a/crates/experimental-ref/src/remote_experts/tests.rs +++ b/crates/experimental-ref/src/remote_experts/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests of the second-GPU expert tier: device meta layout, expert selection and open failures, slot rounding, +//! dispatch grouping and validation, the meta image with scatter, and the device buffer budget. use super::*; diff --git a/crates/experimental-ref/tests/emulated_kernels/cvec_reduction.rs b/crates/experimental-ref/tests/emulated_kernels/cvec_reduction.rs index 4cc6d2b5..d6dfad83 100644 --- a/crates/experimental-ref/tests/emulated_kernels/cvec_reduction.rs +++ b/crates/experimental-ref/tests/emulated_kernels/cvec_reduction.rs @@ -1,6 +1,5 @@ //! The cvec kernel against its reduction-tree twin. -#[allow(unused_imports)] use super::*; // ------------------------------------------------------------------------------------ control vector diff --git a/crates/experimental-ref/tests/emulated_kernels/fwht_and_q4_append.rs b/crates/experimental-ref/tests/emulated_kernels/fwht_and_q4_append.rs index f74db44b..5be46fb7 100644 --- a/crates/experimental-ref/tests/emulated_kernels/fwht_and_q4_append.rs +++ b/crates/experimental-ref/tests/emulated_kernels/fwht_and_q4_append.rs @@ -1,6 +1,5 @@ //! The FWHT kernel and the q4_0 append, batch and gather kernels against the reference. -#[allow(unused_imports)] use super::*; #[test] diff --git a/crates/experimental-ref/tests/emulated_kernels/int8_and_k8v4_append.rs b/crates/experimental-ref/tests/emulated_kernels/int8_and_k8v4_append.rs index cb56f56d..21ebf380 100644 --- a/crates/experimental-ref/tests/emulated_kernels/int8_and_k8v4_append.rs +++ b/crates/experimental-ref/tests/emulated_kernels/int8_and_k8v4_append.rs @@ -1,6 +1,5 @@ //! The int8 value-only and K8V4 append and gather kernels against the reference. -#[allow(unused_imports)] use super::*; /// The twelve cells every section appends, the page table and the cells it gathers. diff --git a/crates/experimental-ref/tests/emulated_kernels/kv_stream_and_keyless_routing.rs b/crates/experimental-ref/tests/emulated_kernels/kv_stream_and_keyless_routing.rs index a349d4bc..9a07639a 100644 --- a/crates/experimental-ref/tests/emulated_kernels/kv_stream_and_keyless_routing.rs +++ b/crates/experimental-ref/tests/emulated_kernels/kv_stream_and_keyless_routing.rs @@ -1,6 +1,5 @@ //! The KV stream resolver, copy and ring, and the keyless query routing kernel. -#[allow(unused_imports)] use super::*; const N_BLOCKS: usize = 1600; diff --git a/crates/experimental-ref/tests/emulated_kernels/quantized_attention.rs b/crates/experimental-ref/tests/emulated_kernels/quantized_attention.rs index 16008f2d..d77775f4 100644 --- a/crates/experimental-ref/tests/emulated_kernels/quantized_attention.rs +++ b/crates/experimental-ref/tests/emulated_kernels/quantized_attention.rs @@ -1,6 +1,5 @@ //! The quantized attention kernels against the double-precision reference. -#[allow(unused_imports)] use super::*; /// The inputs shared by the three modes: the page table, the cells' keys and values, the queries and the cell diff --git a/crates/gateway-text/src/lib.rs b/crates/gateway-text/src/lib.rs index 0ff1ec92..d897a0e9 100644 --- a/crates/gateway-text/src/lib.rs +++ b/crates/gateway-text/src/lib.rs @@ -4,7 +4,6 @@ //! through `#[path]`. They need only `minijinja`, `serde`, `serde_json`, `sha2`, `regex` and `hex`, so they are a leaf //! crate that both hosts use. -mod env_settings; pub mod prompt; pub mod response_tools; pub mod tool_output; diff --git a/crates/gateway-text/src/prompt.rs b/crates/gateway-text/src/prompt.rs index 4a73b975..de408ed0 100644 --- a/crates/gateway-text/src/prompt.rs +++ b/crates/gateway-text/src/prompt.rs @@ -109,6 +109,8 @@ pub enum Effort { #[path = "prompt/tests.rs"] mod tests; +#[path = "prompt/env_settings.rs"] +mod env_settings; #[path = "prompt/json.rs"] mod json; pub use json::*; diff --git a/crates/gateway-text/src/env_settings.rs b/crates/gateway-text/src/prompt/env_settings.rs similarity index 100% rename from crates/gateway-text/src/env_settings.rs rename to crates/gateway-text/src/prompt/env_settings.rs diff --git a/crates/gateway-text/src/prompt/python_json.rs b/crates/gateway-text/src/prompt/python_json.rs index a4976f5c..6405904e 100644 --- a/crates/gateway-text/src/prompt/python_json.rs +++ b/crates/gateway-text/src/prompt/python_json.rs @@ -3,7 +3,7 @@ //! used to drop completed empty assistant turns from the history. use super::{Error, ErrorKind, Json, Kwargs, State, Value, ValueKind, py_space, python_float}; -use crate::env_settings::keep_empty_turns; +use super::env_settings::keep_empty_turns; pub(super) fn json_string(text: &str, ensure_ascii: bool, out: &mut String) { out.push('"'); diff --git a/crates/gateway-text/src/prompt/template_render.rs b/crates/gateway-text/src/prompt/template_render.rs index 0c7fa083..75de15df 100644 --- a/crates/gateway-text/src/prompt/template_render.rs +++ b/crates/gateway-text/src/prompt/template_render.rs @@ -5,7 +5,7 @@ use super::{ ChatInput, Effort, Json, Message, Part, Plain, Role, chat_tool, pinned, render_native, }; -use crate::env_settings::{keep_empty_turns, reference_render}; +use super::env_settings::{keep_empty_turns, reference_render}; /// The typed counterpart of [`without_empty_assistant_turns`]. pub(super) fn without_empty_turns<'a>(messages: &[Message<'a>]) -> Vec> { diff --git a/crates/gguf/tests/synthetic/hostile_input_and_tensor_layout.rs b/crates/gguf/tests/synthetic/hostile_input_and_tensor_layout.rs index c4d7838b..dc552028 100644 --- a/crates/gguf/tests/synthetic/hostile_input_and_tensor_layout.rs +++ b/crates/gguf/tests/synthetic/hostile_input_and_tensor_layout.rs @@ -1,6 +1,5 @@ //! Hostile counts and lengths, duplicates, bad shapes and tensors out of range. -#[allow(unused_imports)] use super::*; fn assert_huge_tensor_count_is_limited() { diff --git a/crates/gguf/tests/synthetic/limits_and_inventory.rs b/crates/gguf/tests/synthetic/limits_and_inventory.rs index d4967929..e83aa8d5 100644 --- a/crates/gguf/tests/synthetic/limits_and_inventory.rs +++ b/crates/gguf/tests/synthetic/limits_and_inventory.rs @@ -1,6 +1,5 @@ //! Custom alignment, enforced limits and the tensor inventory. -#[allow(unused_imports)] use super::*; #[test] diff --git a/crates/gguf/tests/synthetic/metadata_and_headers.rs b/crates/gguf/tests/synthetic/metadata_and_headers.rs index d7d52bba..47a9b645 100644 --- a/crates/gguf/tests/synthetic/metadata_and_headers.rs +++ b/crates/gguf/tests/synthetic/metadata_and_headers.rs @@ -1,6 +1,5 @@ //! Reading metadata, tensors and geometry; truncated headers; bad magic and versions. -#[allow(unused_imports)] use super::*; #[test] diff --git a/crates/gptoss-igpu/src/prefill_pass.rs b/crates/gptoss-igpu/src/prefill_pass.rs index b54fb793..922ef7bb 100644 --- a/crates/gptoss-igpu/src/prefill_pass.rs +++ b/crates/gptoss-igpu/src/prefill_pass.rs @@ -28,11 +28,12 @@ impl GpuPrefill { pub fn prefill_part( &mut self, job: PrefillJob, - mut progress: &mut dyn FnMut(f64) -> bool, + mut progress: &mut (impl FnMut(f64) -> bool + ?Sized), ) -> Result>, ModelError> { let PrefillJob { model, cache, span, all_hidden } = job; let PrefillSpan { tokens, pos0 } = span; Self::check(model)?; + // Measurement timer, not decision logic (instant-now exception in architecture.json). let started = Instant::now(); self.timings = Timings { tokens: tokens.len(), diff --git a/crates/gptoss-igpu/src/prefill_run.rs b/crates/gptoss-igpu/src/prefill_run.rs index 16cdd473..2d88616a 100644 --- a/crates/gptoss-igpu/src/prefill_run.rs +++ b/crates/gptoss-igpu/src/prefill_run.rs @@ -123,6 +123,7 @@ impl<'a> PrefillRun<'a> { let (tx, rx) = std::sync::mpsc::sync_channel::>(0); scope.spawn(move || upload_layers(gpu, model, tx)); for l in 0..blocks { + // Measurement timer, not decision logic (instant-now exception in architecture.json). let t0 = Instant::now(); let lw = next_layer(&rx)?; self.load_prefix(cache, l)?; diff --git a/crates/gptoss-npu/src/client.rs b/crates/gptoss-npu/src/client.rs index c765fec1..9b4f8af5 100644 --- a/crates/gptoss-npu/src/client.rs +++ b/crates/gptoss-npu/src/client.rs @@ -116,7 +116,7 @@ fn openvino_dirs(root: &Path) -> (PathBuf, PathBuf) { /// The `PATH` for the service: the OpenVINO folders in front of the current one. fn search_path(folders: [PathBuf; 2]) -> Result { - let current = std::env::var_os("PATH").unwrap_or_default(); + let current = crate::settings::search_path(); std::env::join_paths(folders.into_iter().chain(std::env::split_paths(¤t))).map_err(|e| e.to_string()) } diff --git a/crates/gptoss-npu/src/expert_pass.rs b/crates/gptoss-npu/src/expert_pass.rs index 7bef70f6..92381efd 100644 --- a/crates/gptoss-npu/src/expert_pass.rs +++ b/crates/gptoss-npu/src/expert_pass.rs @@ -97,6 +97,7 @@ impl NpuPrefill { let (dispatch, view, layer) = (&ctx.dispatch, &ctx.view, ctx.l); let (e, ff) = (ctx.c.n_embd, ctx.c.n_ff); let layout = self.client.layout; + // Measurement timer, not decision logic (instant-now exception in architecture.json). let t0 = Instant::now(); let plan = ExpertPlan::new(per_expert, m); self.put_gathered(&plan, h2f, e)?; diff --git a/crates/gptoss-npu/src/lib.rs b/crates/gptoss-npu/src/lib.rs index f9017c53..29dafb3a 100644 --- a/crates/gptoss-npu/src/lib.rs +++ b/crates/gptoss-npu/src/lib.rs @@ -13,6 +13,7 @@ pub mod client; mod half; mod par; +mod settings; use client::{Client, ProductRegions, Layout, Region, ServiceConfig, Spec, ServiceTensor}; use leleka_cpu_kernels::Dispatch; diff --git a/crates/gptoss-npu/src/prefill_batch.rs b/crates/gptoss-npu/src/prefill_batch.rs index a88499e5..1ed742c1 100644 --- a/crates/gptoss-npu/src/prefill_batch.rs +++ b/crates/gptoss-npu/src/prefill_batch.rs @@ -42,6 +42,7 @@ impl NpuPrefill { // --- experts --- let moe = self.experts(ctx, &per_expert, &h2f, span.1)?; + // Measurement timer, not decision logic (instant-now exception in architecture.json). let t5 = Instant::now(); par::for_chunks(&mut xs[span.0 * e..(span.0 + span.1) * e], e, |t, row| { for (x, d) in row.iter_mut().zip(&moe[t * e..(t + 1) * e]) { diff --git a/crates/gptoss-npu/src/prefill_part_pass.rs b/crates/gptoss-npu/src/prefill_part_pass.rs index 91947a41..c6ac442c 100644 --- a/crates/gptoss-npu/src/prefill_part_pass.rs +++ b/crates/gptoss-npu/src/prefill_part_pass.rs @@ -51,10 +51,11 @@ impl NpuPrefill { pub fn prefill_part( &mut self, job: PrefillJob, - progress: &mut dyn FnMut(f64) -> bool, + progress: &mut (impl FnMut(f64) -> bool + ?Sized), ) -> Result>, ModelError> { let PrefillJob { model, cache, span, all_hidden } = job; let PrefillSpan { tokens, pos0 } = span; + // Measurement timer, not decision logic (instant-now exception in architecture.json). let started = Instant::now(); self.timings = Timings::starting(tokens.len()); let c = &model.config; diff --git a/crates/gptoss-npu/src/service_transfers.rs b/crates/gptoss-npu/src/service_transfers.rs index a57cd17a..40f7863b 100644 --- a/crates/gptoss-npu/src/service_transfers.rs +++ b/crates/gptoss-npu/src/service_transfers.rs @@ -36,6 +36,7 @@ impl NpuPrefill { io: ProductRegions, ) -> Result<(), ModelError> { let ProductRegions { input, out } = io; + // Measurement timer, not decision logic (instant-now exception in architecture.json). let started = Instant::now(); let shifts = self.client.product(tensor, rows, n, io).map_err(fail)?; match shifts { diff --git a/crates/gptoss-npu/src/settings.rs b/crates/gptoss-npu/src/settings.rs new file mode 100644 index 00000000..b3fbcb94 --- /dev/null +++ b/crates/gptoss-npu/src/settings.rs @@ -0,0 +1,8 @@ +//! The only place of this crate that reads the process environment. + +use std::ffi::OsString; + +/// The `PATH` of this process (empty when unset), to which the service's OpenVINO folders are prepended. +pub(crate) fn search_path() -> OsString { + std::env::var_os("PATH").unwrap_or_default() +} diff --git a/crates/gptoss/src/config.rs b/crates/gptoss/src/config.rs index 9a6aa54e..9d5bb716 100644 --- a/crates/gptoss/src/config.rs +++ b/crates/gptoss/src/config.rs @@ -23,11 +23,7 @@ pub struct Config { /// EXPERIMENTAL and lossy: `LELEKA_EXPERIMENTAL_EXPERTS_USED=N` routes every token to N experts instead of the /// model's own count (fewer expert bytes per decoded token). Off unless set; not covered by any quality gate. pub(super) fn experimental_experts_used(model_value: usize) -> usize { - let Some(n) = crate::settings::var("LELEKA_EXPERIMENTAL_EXPERTS_USED") - .ok() - .and_then(|v| v.parse::().ok()) - .filter(|n| (1..model_value).contains(n)) - else { + let Some(n) = crate::settings::experts_used().filter(|n| (1..model_value).contains(n)) else { return model_value; }; eprintln!("leleka-gptoss: EXPERIMENTAL lossy mode: {n} experts per token instead of {model_value}"); diff --git a/crates/gptoss/src/forward_pass.rs b/crates/gptoss/src/forward_pass.rs index 99d62458..fafcbb6c 100644 --- a/crates/gptoss/src/forward_pass.rs +++ b/crates/gptoss/src/forward_pass.rs @@ -16,6 +16,7 @@ impl Pass { /// Time since the previous lap; starts the next one. pub(super) fn lap(&mut self) -> std::time::Duration { let elapsed = self.lap_start.elapsed(); + // Measurement timer, not decision logic (instant-now exception in architecture.json). self.lap_start = std::time::Instant::now(); elapsed } diff --git a/crates/gptoss/src/generation.rs b/crates/gptoss/src/generation.rs index 9f137fc9..9438c1a1 100644 --- a/crates/gptoss/src/generation.rs +++ b/crates/gptoss/src/generation.rs @@ -16,6 +16,7 @@ impl Model { let Some(last) = xs.last().filter(|_| want_logits) else { return Ok(None); }; + // Measurement timer, not decision logic (instant-now exception in architecture.json). let started = std::time::Instant::now(); let next = self.next_from_hidden(state, last)?; state.profile.lm_head += started.elapsed(); diff --git a/crates/gptoss/src/ops/tests.rs b/crates/gptoss/src/ops/tests.rs index dcebff7b..7b5b22f5 100644 --- a/crates/gptoss/src/ops/tests.rs +++ b/crates/gptoss/src/ops/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests of the gpt-oss CPU ops against f64 references: RMS norm, YaRN RoPE (range, rotation, norm), attention with +//! sinks and head groups across kernel levels, expert routing softmax, and the clamped SwiGLU. use super::*; diff --git a/crates/gptoss/src/prefill.rs b/crates/gptoss/src/prefill.rs index ae9cccb3..1413238a 100644 --- a/crates/gptoss/src/prefill.rs +++ b/crates/gptoss/src/prefill.rs @@ -50,7 +50,7 @@ impl Model { &self, state: &mut State, prompt: &[u32], - progress: &mut dyn FnMut(usize, usize) -> bool, + progress: &mut (impl FnMut(usize, usize) -> bool + ?Sized), ) -> Result, ModelError> { let reused = Self::reusable_prefix(state, prompt)?; state.truncate(reused); @@ -81,7 +81,7 @@ impl Model { state: &mut State, prompt: &[u32], accelerate: PrefillOffload, - progress: &mut dyn FnMut(usize, usize) -> bool, + progress: &mut (impl FnMut(usize, usize) -> bool + ?Sized), ) -> Result, ModelError> { let PrefillOffload { accelerator, min_tokens } = accelerate; let reused = Self::reusable_prefix(state, prompt)?; diff --git a/crates/gptoss/src/quant_probes.rs b/crates/gptoss/src/quant_probes.rs index 9da76d62..1be425c9 100644 --- a/crates/gptoss/src/quant_probes.rs +++ b/crates/gptoss/src/quant_probes.rs @@ -9,10 +9,7 @@ pub(super) fn fake_bits_for(name: &str) -> Option { if !(name.contains("attn_") || name == "output.weight") { return None; } - crate::settings::var("LELEKA_EXPERIMENTAL_FAKE_BITS") - .ok() - .and_then(|v| v.parse::().ok()) - .filter(|b| (2..8).contains(b)) + crate::settings::fake_bits().filter(|b| (2..8).contains(b)) } pub(super) fn fake_quantize_q8_0(bytes: &[u8], bits: u32) -> Vec { @@ -43,16 +40,13 @@ pub(super) fn fake_quantize_q8_0(bytes: &[u8], bits: u32) -> Vec { /// KAR format would cost in quality. Storing in Q8_0 adds at most half an 8-bit step per block. Gives no speed-up. pub(super) fn kar_levels_for(name: &str) -> Option { // `LELEKA_EXPERIMENTAL_KAR_TENSORS=a,b`: only the tensors whose name contains one of these (default: all of them) - let selected = crate::settings::var("LELEKA_EXPERIMENTAL_KAR_TENSORS").map_or(true, |list| { + let selected = crate::settings::kar_tensor_fragments().map_or(true, |list| { list.split(',').any(|part| !part.is_empty() && name.contains(part)) }); if !(name.contains("attn_") || name == "output.weight") || !selected { return None; } - crate::settings::var("LELEKA_EXPERIMENTAL_KAR_LEVELS") - .ok() - .and_then(|v| v.parse::().ok()) - .filter(|l| (1..=8).contains(l)) + crate::settings::kar_levels().filter(|l| (1..=8).contains(l)) } /// Groups of 32 sampled evenly across a tensor to fit its codebook (65,536 values, as the KAR preparer uses). @@ -74,20 +68,11 @@ pub(super) fn kar_expert_levels_for(name: &str) -> Option { if !name.contains("_exps.weight") { return None; } - let (first, last) = crate::settings::var("LELEKA_EXPERIMENTAL_KAR_EXPERT_LAYERS") - .ok() - .and_then(|r| { - let (a, b) = r.split_once('-')?; - Some((a.trim().parse().ok()?, b.trim().parse().ok()?)) - }) - .unwrap_or((0, usize::MAX)); + let (first, last) = crate::settings::kar_expert_layers().unwrap_or((0, usize::MAX)); if !(first..=last).contains(&layer) { return None; } - crate::settings::var("LELEKA_EXPERIMENTAL_KAR_EXPERT_LEVELS") - .ok() - .and_then(|v| v.parse::().ok()) - .filter(|l| (0..=8).contains(l)) + crate::settings::kar_expert_levels().filter(|l| (0..=8).contains(l)) } pub(super) fn kar_roundtrip_mxfp4(bytes: &[u8], levels: u8, name: &str) -> Result, ModelError> { diff --git a/crates/gptoss/src/settings.rs b/crates/gptoss/src/settings.rs index 24f8d322..b9ef55a7 100644 --- a/crates/gptoss/src/settings.rs +++ b/crates/gptoss/src/settings.rs @@ -1,11 +1,34 @@ -//! The only place of this crate that reads the process environment (`env-read` ratchet of `architecture.json`). -//! The reads keep their call sites and their parsing; a later step replaces these functions by a parsed settings value. +//! The only place of this crate that reads the process environment: the operator's EXPERIMENTAL lossy probes, as typed +//! values (none is set in production; none is covered by a quality gate). -use std::env::{self, VarError}; -use std::ffi::OsStr; +/// `LELEKA_EXPERIMENTAL_EXPERTS_USED=N`: route every token to N experts, as written (unchecked). +pub(crate) fn experts_used() -> Option { + std::env::var("LELEKA_EXPERIMENTAL_EXPERTS_USED").ok().and_then(|v| v.parse::().ok()) +} -/// `std::env::var`: the text of an environment variable. -#[inline] -pub(crate) fn var>(key: K) -> Result { - env::var(key) +/// `LELEKA_EXPERIMENTAL_FAKE_BITS=N`: fake-quantize the attention and output tensors to N bits, as written. +pub(crate) fn fake_bits() -> Option { + std::env::var("LELEKA_EXPERIMENTAL_FAKE_BITS").ok().and_then(|v| v.parse::().ok()) +} + +/// `LELEKA_EXPERIMENTAL_KAR_TENSORS=a,b`: the name fragments of the tensors the KAR probe touches. +pub(crate) fn kar_tensor_fragments() -> Option { + std::env::var("LELEKA_EXPERIMENTAL_KAR_TENSORS").ok() +} + +/// `LELEKA_EXPERIMENTAL_KAR_LEVELS=N`: the KAR probe's levels for the attention and output tensors, as written. +pub(crate) fn kar_levels() -> Option { + std::env::var("LELEKA_EXPERIMENTAL_KAR_LEVELS").ok().and_then(|v| v.parse::().ok()) +} + +/// `LELEKA_EXPERIMENTAL_KAR_EXPERT_LAYERS=first-last`: the layers whose experts the KAR probe touches. +pub(crate) fn kar_expert_layers() -> Option<(usize, usize)> { + let text = std::env::var("LELEKA_EXPERIMENTAL_KAR_EXPERT_LAYERS").ok()?; + let (first, last) = text.split_once('-')?; + Some((first.trim().parse().ok()?, last.trim().parse().ok()?)) +} + +/// `LELEKA_EXPERIMENTAL_KAR_EXPERT_LEVELS=N`: the KAR probe's levels for the expert tensors, as written. +pub(crate) fn kar_expert_levels() -> Option { + std::env::var("LELEKA_EXPERIMENTAL_KAR_EXPERT_LEVELS").ok().and_then(|v| v.parse::().ok()) } diff --git a/crates/gptoss/tests/synthetic_model/decoder_and_prefill.rs b/crates/gptoss/tests/synthetic_model/decoder_and_prefill.rs index 1e171b4b..ac0ce36c 100644 --- a/crates/gptoss/tests/synthetic_model/decoder_and_prefill.rs +++ b/crates/gptoss/tests/synthetic_model/decoder_and_prefill.rs @@ -1,7 +1,6 @@ //! The decoder against the f64 reference, every instruction-set level, the sliding window, overflow, and chunked //! prefill. -#[allow(unused_imports)] use super::*; #[test] diff --git a/crates/gptoss/tests/synthetic_model/decoder_runs.rs b/crates/gptoss/tests/synthetic_model/decoder_runs.rs index e1c37e23..d93a9dbe 100644 --- a/crates/gptoss/tests/synthetic_model/decoder_runs.rs +++ b/crates/gptoss/tests/synthetic_model/decoder_runs.rs @@ -1,6 +1,5 @@ //! Running the decoder under test and the argmax of reference logits. -#[allow(unused_imports)] use super::*; // ------------------------------------------------------------------------------------ tests ---- diff --git a/crates/gptoss/tests/synthetic_model/gguf_builder.rs b/crates/gptoss/tests/synthetic_model/gguf_builder.rs index 81b30268..2d049121 100644 --- a/crates/gptoss/tests/synthetic_model/gguf_builder.rs +++ b/crates/gptoss/tests/synthetic_model/gguf_builder.rs @@ -1,6 +1,5 @@ //! The LCG generator and the writer of the synthetic GGUF file. -#[allow(unused_imports)] use super::*; impl Lcg { diff --git a/crates/gptoss/tests/synthetic_model/prefix_copy.rs b/crates/gptoss/tests/synthetic_model/prefix_copy.rs index 212685b3..07a9bdbc 100644 --- a/crates/gptoss/tests/synthetic_model/prefix_copy.rs +++ b/crates/gptoss/tests/synthetic_model/prefix_copy.rs @@ -1,6 +1,5 @@ //! A copied prefix continues bit-identically and leaves its source alone. -#[allow(unused_imports)] use super::*; fn logit_bits(s: &State) -> Vec { diff --git a/crates/gptoss/tests/synthetic_model/prefix_reuse_and_generation.rs b/crates/gptoss/tests/synthetic_model/prefix_reuse_and_generation.rs index fa00c75d..c604c534 100644 --- a/crates/gptoss/tests/synthetic_model/prefix_reuse_and_generation.rs +++ b/crates/gptoss/tests/synthetic_model/prefix_reuse_and_generation.rs @@ -1,6 +1,5 @@ //! Prefix reuse, greedy generation, per-position logits, and batches wider than one kernel call. -#[allow(unused_imports)] use super::*; fn logit_bits(s: &State) -> Vec { diff --git a/crates/gptoss/tests/synthetic_model/reference_forward.rs b/crates/gptoss/tests/synthetic_model/reference_forward.rs index 6ab7598a..81406825 100644 --- a/crates/gptoss/tests/synthetic_model/reference_forward.rs +++ b/crates/gptoss/tests/synthetic_model/reference_forward.rs @@ -1,6 +1,5 @@ //! The independent f64 reference forward pass (quantization, matrix product, norm, RoPE). -#[allow(unused_imports)] use super::*; /// YaRN rotation of one head at `pos`, written from the definition with no recurrence. diff --git a/crates/gptoss/tests/synthetic_model/synthetic_world.rs b/crates/gptoss/tests/synthetic_model/synthetic_world.rs index fcbef38e..4ba68f5d 100644 --- a/crates/gptoss/tests/synthetic_model/synthetic_world.rs +++ b/crates/gptoss/tests/synthetic_model/synthetic_world.rs @@ -1,6 +1,5 @@ //! The synthetic model: its tensors, quantized weights and reference layers. -#[allow(unused_imports)] use super::*; /// The norm weights: one around 1. diff --git a/crates/gptoss/tests/synthetic_model/world_types.rs b/crates/gptoss/tests/synthetic_model/world_types.rs index b05b88ce..ea4238c0 100644 --- a/crates/gptoss/tests/synthetic_model/world_types.rs +++ b/crates/gptoss/tests/synthetic_model/world_types.rs @@ -1,7 +1,5 @@ //! The dimensions and the plain types of the synthetic model. -#[allow(unused_imports)] -use super::*; pub(super) struct Lcg(pub(super) u64); diff --git a/crates/gpu-npu-worker/src/lib.rs b/crates/gpu-npu-worker/src/lib.rs index 1b0f086d..0c95f78e 100644 --- a/crates/gpu-npu-worker/src/lib.rs +++ b/crates/gpu-npu-worker/src/lib.rs @@ -126,6 +126,7 @@ impl LayerCache for SecondPart<'_> { self.cache.capacity() } fn prefix(&self, layer: usize, to: usize) -> Result<(Vec, Vec), ModelError> { + // Measurement timer, not decision logic (instant-now exception in architecture.json). let started = Instant::now(); self.handoff.wait_for(layer)?; self.waited_ns @@ -221,7 +222,7 @@ impl GpuNpuPrefill { fn run( &mut self, job: PrefillJob, - mut progress: &mut dyn FnMut(f64) -> bool, + mut progress: &mut (impl FnMut(f64) -> bool + ?Sized), ) -> Result>, ModelError> { let PrefillJob { model, cache, span, all_hidden } = job; let PrefillSpan { tokens, pos0 } = span; @@ -286,6 +287,7 @@ impl GpuNpuPrefill { } mod split_run; +pub mod settings; use split_run::{SplitJob, join_hidden, run_parts}; impl PrefillAccelerator for GpuNpuPrefill { @@ -298,7 +300,7 @@ impl PrefillAccelerator for GpuNpuPrefill { ) -> Result>, ModelError> { let job = PrefillJob { model, cache: state, span, all_hidden: false }; let out = self.run(job, progress); - if std::env::var_os("LELEKA_SPLIT_LOG").is_some() { + if settings::split_log_enabled() { eprintln!("leleka-gpu-npu: {}", self.timings.report()); } out diff --git a/crates/gpu-npu-worker/src/main.rs b/crates/gpu-npu-worker/src/main.rs index 198a6dd2..c384445c 100644 --- a/crates/gpu-npu-worker/src/main.rs +++ b/crates/gpu-npu-worker/src/main.rs @@ -93,7 +93,7 @@ impl Parsed { .map_or(0x5EED, |d| d.as_nanos() as u64), speculate: false, cache_slots: 1, - openvino_root: std::env::var_os("LELEKA_OPENVINO_ROOT").map(PathBuf::from), + openvino_root: leleka_gpu_npu_worker::settings::openvino_root(), service: None, device: "NPU".to_owned(), gpu_min_tokens: DEFAULT_GPU_MIN_TOKENS, diff --git a/crates/gpu-npu-worker/src/settings.rs b/crates/gpu-npu-worker/src/settings.rs new file mode 100644 index 00000000..0422f10f --- /dev/null +++ b/crates/gpu-npu-worker/src/settings.rs @@ -0,0 +1,13 @@ +//! The only place of this crate that reads the process environment: the operator's switches, as typed values. + +use std::path::PathBuf; + +/// `LELEKA_SPLIT_LOG` is set: print the split-prefill timing line after each pass. +pub(crate) fn split_log_enabled() -> bool { + std::env::var_os("LELEKA_SPLIT_LOG").is_some() +} + +/// `LELEKA_OPENVINO_ROOT`: the OpenVINO runtime folder, when the operator names one. +pub fn openvino_root() -> Option { + std::env::var_os("LELEKA_OPENVINO_ROOT").map(PathBuf::from) +} diff --git a/crates/gpu-npu-worker/src/split_run.rs b/crates/gpu-npu-worker/src/split_run.rs index 4f4a7170..82f9fe17 100644 --- a/crates/gpu-npu-worker/src/split_run.rs +++ b/crates/gpu-npu-worker/src/split_run.rs @@ -60,6 +60,7 @@ fn run_gpu_part( progress: &mut impl FnMut(f64) -> bool, (npu_done, stop): (&AtomicU64, &AtomicBool), ) -> PartOutcome { + // Measurement timer, not decision logic (instant-now exception in architecture.json). let t = Instant::now(); let part = PrefillJob { model: job.model, diff --git a/crates/harmony/src/parse/tests.rs b/crates/harmony/src/parse/tests.rs index e0e97300..71851fb1 100644 --- a/crates/harmony/src/parse/tests.rs +++ b/crates/harmony/src/parse/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests of the Harmony stream parser: analysis, final and return turns, tool calls with the recipient in the channel +//! or the start header, several calls in one generation, dropped unknown channels, and a cut-off call closed at finish. use super::*; use Piece::{Special as S, Text as T}; diff --git a/crates/harmony/src/render.rs b/crates/harmony/src/render.rs index 5713d605..1ea21f1c 100644 --- a/crates/harmony/src/render.rs +++ b/crates/harmony/src/render.rs @@ -53,8 +53,6 @@ struct Out { } mod render_options; -#[allow(unused_imports)] pub use render_options::*; mod render_namespace; -#[allow(unused_imports)] pub use render_namespace::*; diff --git a/crates/harmony/src/render/render_namespace.rs b/crates/harmony/src/render/render_namespace.rs index c644e664..f4f51735 100644 --- a/crates/harmony/src/render/render_namespace.rs +++ b/crates/harmony/src/render/render_namespace.rs @@ -1,5 +1,5 @@ -//! Methods of `Out`: `new`, `lit`, `text`. -//! Functions: `render_namespace`, `render_tool_definition`, `render_tool_parameter`, `render_parameter_default` and ... +//! Harmony prompt renderer: assembles system, developer, user, assistant and tool messages into the gpt-oss prompt, +//! and renders the tool namespace (TypeScript-like definitions of tools and their parameters) with an output buffer. use super::{ HarmonyError, Message, Out, RenderOptions, Role, SENTINELS, Tool, ToolCall, Value, as_concat_str, err, render_type, diff --git a/crates/harmony/src/render/render_options.rs b/crates/harmony/src/render/render_options.rs index 8723dced..e7cf5705 100644 --- a/crates/harmony/src/render/render_options.rs +++ b/crates/harmony/src/render/render_options.rs @@ -1,5 +1,5 @@ -//! Methods of `RenderOptions`: `new`. Functions: `err`, `truthy`, `to_json`, `write_json_string` and 13 more. -//! Split out of `render` to keep its files under the line limit. +//! Render options and Jinja-compatible helpers of the Harmony chat template: truthiness, tojson output, string +//! concatenation, and rendering of JSON-schema types and required names as TypeScript-like text. use super::{HarmonyError, Map, NESTED_INDENT, ONE_OF_DEFAULT_INDENT, RenderOptions, Value}; diff --git a/crates/igpu/src/device.rs b/crates/igpu/src/device.rs index 00b5a08c..44b37e2c 100644 --- a/crates/igpu/src/device.rs +++ b/crates/igpu/src/device.rs @@ -47,13 +47,7 @@ pub(super) const STORAGE: wgpu::BufferUsages = wgpu::BufferUsages::STORAGE /// Experiment hook: `LELEKA_IGPU_MOE_TILE=TMxTN` sets the expert kernel's tile, else it is `tm` x `tn`. fn moe_tile_from_env(tm: u32, tn: u32) -> (u32, u32) { - std::env::var("LELEKA_IGPU_MOE_TILE") - .ok() - .and_then(|s| { - let (a, b) = s.split_once('x')?; - Some((a.parse().ok()?, b.parse().ok()?)) - }) - .unwrap_or((tm, tn)) + crate::settings::moe_tile().unwrap_or((tm, tn)) } /// The stand-in binding for a product without bias. diff --git a/crates/igpu/src/lib.rs b/crates/igpu/src/lib.rs index 374f33bf..912de57e 100644 --- a/crates/igpu/src/lib.rs +++ b/crates/igpu/src/lib.rs @@ -9,6 +9,7 @@ //! aligned for 32-bit access, so quants and scales go to separate word arrays (see [`shaders::gemm`]). pub mod shaders; +mod settings; use std::fmt; use wgpu::util::DeviceExt; diff --git a/crates/igpu/src/matrices_and_moe_plan.rs b/crates/igpu/src/matrices_and_moe_plan.rs index de88c279..735c85af 100644 --- a/crates/igpu/src/matrices_and_moe_plan.rs +++ b/crates/igpu/src/matrices_and_moe_plan.rs @@ -184,6 +184,7 @@ impl Gpu { rec.submit() }; run(1)?; + // Measurement timer, not decision logic (instant-now exception in architecture.json). let start = std::time::Instant::now(); run(iterations)?; Ok(start.elapsed().as_secs_f64() / iterations as f64) diff --git a/crates/igpu/src/recorder_moe.rs b/crates/igpu/src/recorder_moe.rs index 90e71c57..0f19f6ed 100644 --- a/crates/igpu/src/recorder_moe.rs +++ b/crates/igpu/src/recorder_moe.rs @@ -1,6 +1,5 @@ //! The expert matrix product and the weighted combine of expert outputs. -#[allow(unused_imports)] use super::recorder_core::product_dims; use super::{ Buf, CombineBufs, GpuActivations, GpuError, GpuMatrix, MoePlan, Operands, ProductOutput, Quad, Recorder, diff --git a/crates/igpu/src/settings.rs b/crates/igpu/src/settings.rs new file mode 100644 index 00000000..b63ca229 --- /dev/null +++ b/crates/igpu/src/settings.rs @@ -0,0 +1,8 @@ +//! The only place of this crate that reads the process environment: the operator's experiment hooks, as typed values. + +/// `LELEKA_IGPU_MOE_TILE=TMxTN`: the tile of the expert kernel; `None` when unset or malformed. +pub(crate) fn moe_tile() -> Option<(u32, u32)> { + let text = std::env::var("LELEKA_IGPU_MOE_TILE").ok()?; + let (rows, columns) = text.split_once('x')?; + Some((rows.parse().ok()?, columns.parse().ok()?)) +} diff --git a/crates/igpu/src/shaders.rs b/crates/igpu/src/shaders.rs index 3e1da441..8d46ac67 100644 --- a/crates/igpu/src/shaders.rs +++ b/crates/igpu/src/shaders.rs @@ -8,7 +8,6 @@ use crate::WeightKind; mod gemm; mod gemm_template; -#[allow(unused_imports)] pub use gemm::*; mod tiling_norm_and_rope; diff --git a/crates/igpu/src/shaders/gemm.rs b/crates/igpu/src/shaders/gemm.rs index 71482f7f..1059b6e7 100644 --- a/crates/igpu/src/shaders/gemm.rs +++ b/crates/igpu/src/shaders/gemm.rs @@ -1,5 +1,5 @@ -//! Methods of `Unrolled`: `new`, `cell`, `operands_and_scales`, `holes`. -//! Functions: `gemm`, `store_cell`, `weight_holes`, `row_source_holes` and 3 more. Defines `Unrolled`. +//! WGSL source generator for the tiled Q8_0 / MXFP4 integer GEMM (plain and mixture-of-experts row source): fills the +//! shared template with tile sizes, unrolled accumulators, weight-format and row-source parts. use super::{F16_ROUND, WeightKind}; use super::gemm_template::TEMPLATE; diff --git a/crates/leleka-memory/src/census.rs b/crates/leleka-memory/src/census.rs index 4e703d01..02cc12e0 100644 --- a/crates/leleka-memory/src/census.rs +++ b/crates/leleka-memory/src/census.rs @@ -148,22 +148,33 @@ fn drift_of(name: &'static str, values: &[f64], tolerance: u64) -> Option }) } +/// The drift of one measured quantity (`get` reads it from a census) over the post-warm-up samples. +fn series_drift( + tail: &[Census], + name: &'static str, + get: impl Fn(&Census) -> Option, + tolerance: u64, +) -> Option { + let values: Vec = tail.iter().filter_map(get).collect(); + drift_of(name, &values, tolerance) +} + /// Judge a series of censuses taken between requests. Fewer than 8 post-warm-up samples is not a judgement: not ok. pub fn check_flat(series: &[Census], warmup: usize, tol: &Tolerances) -> FlatReport { let tail = series.get(warmup..).unwrap_or(&[]); - let mut drifts = Vec::new(); - let mut add = |name: &'static str, get: &dyn Fn(&Census) -> Option, tolerance: u64| { - let values: Vec = tail.iter().filter_map(get).collect(); - drifts.extend(drift_of(name, &values, tolerance)); - }; - add("rss", &|c| Some(c.rss as f64), tol.rss); - add("swap", &|c| Some(c.swap as f64), tol.swap); - add("pinned", &|c| Some(c.pinned as f64), tol.pinned); - add("locked", &|c| Some(c.locked as f64), tol.locked); - add("threads", &|c| Some(c.threads as f64), tol.threads); - add("fds", &|c| Some(c.fds as f64), tol.fds); - add("device", &|c| c.device_used.map(|v| v as f64), tol.device); - add("device_acct", &|c| c.device_accounted.map(|v| v as f64), tol.device); + let drifts: Vec = [ + series_drift(tail, "rss", |c| Some(c.rss as f64), tol.rss), + series_drift(tail, "swap", |c| Some(c.swap as f64), tol.swap), + series_drift(tail, "pinned", |c| Some(c.pinned as f64), tol.pinned), + series_drift(tail, "locked", |c| Some(c.locked as f64), tol.locked), + series_drift(tail, "threads", |c| Some(c.threads as f64), tol.threads), + series_drift(tail, "fds", |c| Some(c.fds as f64), tol.fds), + series_drift(tail, "device", |c| c.device_used.map(|v| v as f64), tol.device), + series_drift(tail, "device_acct", |c| c.device_accounted.map(|v| v as f64), tol.device), + ] + .into_iter() + .flatten() + .collect(); let ok = drifts.iter().all(|d| d.ok); FlatReport { samples: series.len(), warmup, drifts, ok } } diff --git a/crates/leleka-memory/src/governor.rs b/crates/leleka-memory/src/governor.rs index e5ac21e2..e8584a3e 100644 --- a/crates/leleka-memory/src/governor.rs +++ b/crates/leleka-memory/src/governor.rs @@ -195,11 +195,6 @@ mod pressure_tests; mod tests; mod governor_config; -#[allow(unused_imports)] pub use governor_config::*; mod operations; -#[allow(unused_imports)] -pub use operations::*; mod sampler_guard; -#[allow(unused_imports)] -pub use sampler_guard::*; diff --git a/crates/leleka-memory/src/governor/governor_config.rs b/crates/leleka-memory/src/governor/governor_config.rs index fc5cf580..f873d5b2 100644 --- a/crates/leleka-memory/src/governor/governor_config.rs +++ b/crates/leleka-memory/src/governor/governor_config.rs @@ -1,5 +1,5 @@ -//! Methods of `Policy`: `apply_env_floors`, `apply_env_psi`. -//! Methods of `GovernorConfig`: `new`, `apply_env_runtime`, `from_env`. Implements `EnvLookup for F`. +//! Governor configuration: GovernorConfig defaults, the LELEKA_MEMORY_* environment overrides (validated, a typo is an +//! error rather than a silent default) and the Policy floors/PSI overrides; also the published report and lock helpers. use super::{GIB, GovernorConfig, LockMode, MIB, Mutex, MutexGuard, PUBLISHED, Policy}; @@ -124,7 +124,11 @@ impl GovernorConfig { /// Defaults for the host, then the `LELEKA_MEMORY_*` overrides. An unparsable override is an error naming the /// variable (a typo must not silently keep the default of a safety setting). - pub fn from_env(mem_total: u64, laptop: bool, env: &dyn Fn(&str) -> Option) -> Result { + pub fn from_env( + mem_total: u64, + laptop: bool, + env: &(impl Fn(&str) -> Option + ?Sized), + ) -> Result { let mut cfg = Self::new(Policy::for_host(mem_total, laptop)); cfg.policy.apply_env_floors(env)?; cfg.policy.apply_env_psi(env)?; diff --git a/crates/leleka-memory/src/governor/operations/admission.rs b/crates/leleka-memory/src/governor/operations/admission.rs index a74cc444..0e099206 100644 --- a/crates/leleka-memory/src/governor/operations/admission.rs +++ b/crates/leleka-memory/src/governor/operations/admission.rs @@ -3,7 +3,7 @@ //! A file of its own: the per-request half of the governor, apart from its setup and its report. use super::{ - Admission, Governor, HostFacts, Level, LockReport, NONE, OnceLock, Ordering, ProcSource, Refusal, Refuse, + Admission, Governor, HostFacts, Level, LockReport, NONE, Ordering, ProcSource, Refusal, Refuse, RequestShape, ShedDirective, WORKING_SET_TRIM_EVERY, gib, lock, }; @@ -84,11 +84,7 @@ impl Governor { /// A/B inside one engine (bring-up): no trim while the file named by LELEKA_NO_TRIM_FILE exists. fn trim_disabled() -> bool { - static NO_TRIM_FILE: OnceLock> = OnceLock::new(); - NO_TRIM_FILE - .get_or_init(|| std::env::var_os("LELEKA_NO_TRIM_FILE").map(std::path::PathBuf::from)) - .as_ref() - .is_some_and(|f| f.exists()) + crate::settings::no_trim_file().is_some_and(|f| f.exists()) } pub(in super::super) fn relieve_working_set_below(&self, facts: HostFacts, threshold: u64) -> HostFacts { diff --git a/crates/leleka-memory/src/governor/tests.rs b/crates/leleka-memory/src/governor/tests.rs index dbbc80cb..b0906615 100644 --- a/crates/leleka-memory/src/governor/tests.rs +++ b/crates/leleka-memory/src/governor/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests of the governor over a fake host: admission, shedding order, hard-floor refusal and recovery, counters and +//! report JSON, validated env overrides, a dead sampler not leaving the gate closed, and the sampler thread. use super::*; use crate::host::FakeProc; diff --git a/crates/leleka-memory/src/ledger.rs b/crates/leleka-memory/src/ledger.rs index 1ad21f57..e7fc3469 100644 --- a/crates/leleka-memory/src/ledger.rs +++ b/crates/leleka-memory/src/ledger.rs @@ -88,10 +88,10 @@ impl Ledger { pub fn with_clock(clock: AnyClock) -> Self { Self { stages: Mutex::default(), clock } } - pub fn begin(&self, name: &str, src: &dyn ProcSource, device: Option) -> OpenStage { + pub fn begin(&self, name: &str, src: &(impl ProcSource + ?Sized), device: Option) -> OpenStage { OpenStage { name: name.to_owned(), started: self.clock.now(), host: HostSample::take(src), device } } - pub fn end(&self, open: OpenStage, src: &dyn ProcSource, device: Option) -> Stage { + pub fn end(&self, open: OpenStage, src: &(impl ProcSource + ?Sized), device: Option) -> Stage { let after = HostSample::take(src); let stage = Stage { name: open.name, diff --git a/crates/leleka-memory/src/lib.rs b/crates/leleka-memory/src/lib.rs index cd533954..aee3a427 100644 --- a/crates/leleka-memory/src/lib.rs +++ b/crates/leleka-memory/src/lib.rs @@ -16,6 +16,7 @@ pub mod plan; pub mod pressure; pub mod pressure_port; pub mod procfs; +mod settings; pub mod smi; pub mod telemetry; pub mod winproc; diff --git a/crates/leleka-memory/src/lock.rs b/crates/leleka-memory/src/lock.rs index 63039d5b..5d469261 100644 --- a/crates/leleka-memory/src/lock.rs +++ b/crates/leleka-memory/src/lock.rs @@ -91,5 +91,4 @@ mod page_locking; mod tests; mod lock_mode; -#[allow(unused_imports)] pub use lock_mode::*; diff --git a/crates/leleka-memory/src/lock/lock_mode.rs b/crates/leleka-memory/src/lock/lock_mode.rs index ef6af070..974db8d0 100644 --- a/crates/leleka-memory/src/lock/lock_mode.rs +++ b/crates/leleka-memory/src/lock/lock_mode.rs @@ -1,5 +1,5 @@ -//! Methods of `LockMode`: `parse`. Methods of `LockOutcome`: `locked_bytes`. -//! Functions: `memlock_advice`, `plan_lock`, `residency_from_smaps`, `spans_bytes` and 2 more. +//! Memory-lock policy for the model archive: parsing of the lock mode, the pure decision whether RLIMIT_MEMLOCK and +//! capabilities allow locking, with operator advice, and span helpers (checks, compact space walk, smaps residency). use super::{CAP_IPC_LOCK_BIT, LockDecision, LockMode, LockOutcome, PAGE, ProcStatus, Residency, Span, procfs}; diff --git a/crates/leleka-memory/src/lock/tests.rs b/crates/leleka-memory/src/lock/tests.rs index f0446d5c..2f289f8a 100644 --- a/crates/leleka-memory/src/lock/tests.rs +++ b/crates/leleka-memory/src/lock/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests of the lock decision and span helpers: limit and capability cases with operator advice, off mode, pages +//! already locked, span validation and compact-space walking, and residency read from the smaps mapping. use super::*; diff --git a/crates/leleka-memory/src/plan.rs b/crates/leleka-memory/src/plan.rs index 6e24e179..23bb3d1d 100644 --- a/crates/leleka-memory/src/plan.rs +++ b/crates/leleka-memory/src/plan.rs @@ -155,8 +155,6 @@ pub struct Refusal { mod tests; mod policy; -#[allow(unused_imports)] pub use policy::*; mod auto_prefix_budget; -#[allow(unused_imports)] pub use auto_prefix_budget::*; diff --git a/crates/leleka-memory/src/plan/auto_prefix_budget.rs b/crates/leleka-memory/src/plan/auto_prefix_budget.rs index ba50df29..1e4d9ceb 100644 --- a/crates/leleka-memory/src/plan/auto_prefix_budget.rs +++ b/crates/leleka-memory/src/plan/auto_prefix_budget.rs @@ -1,5 +1,5 @@ -//! Functions: `auto_prefix_budget`, `explicit_prefix_budget`. -//! Split out of `plan` to keep its files under the line limit. +//! Prefix-cache budget at stack open, recomputed from the memory then available: the auto rule (share of the elastic +//! memory, capped) and the explicit one (the wish clamped to the host, never above the wish). use super::{MIB, Policy}; diff --git a/crates/leleka-memory/src/plan/policy.rs b/crates/leleka-memory/src/plan/policy.rs index 02393ec9..c44ea8f5 100644 --- a/crates/leleka-memory/src/plan/policy.rs +++ b/crates/leleka-memory/src/plan/policy.rs @@ -1,5 +1,5 @@ -//! Methods of `Policy`: `admit_floor`, `for_host`. Methods of `FixedItem`: `new`. -//! Implements `Display for Refusal`, `Error for Refusal`. +//! Plan policy defaults and errors: host-scaled floors, reserve and cache shares (Policy::for_host), the admit +//! floor, FixedItem constructor, the Refusal error type and its text, and the memory plan itself (plan, VRAM check). use super::{ CacheWish, FixedItem, GIB, KarForm, MIB, Plan, PlanInput, Policy, Refusal, Space, VramFacts, VramPlan, wsl_advice, diff --git a/crates/leleka-memory/src/plan/tests.rs b/crates/leleka-memory/src/plan/tests.rs index 845029bf..31895fcb 100644 --- a/crates/leleka-memory/src/plan/tests.rs +++ b/crates/leleka-memory/src/plan/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests of the memory plan: auto and explicit cache sizing, refusals with numbers and advice (also WSL), blind +//! hosts without telemetry, VRAM fit, enforcement off, and caps that never grow while auto budgets do. use super::*; use crate::host::FakeProc; diff --git a/crates/leleka-memory/src/pressure/tests.rs b/crates/leleka-memory/src/pressure/tests.rs index 898ef059..ca930795 100644 --- a/crates/leleka-memory/src/pressure/tests.rs +++ b/crates/leleka-memory/src/pressure/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of `pressure`. +//! Tests of the pressure monitor: escalation at once below the floors, stepping down only after calm samples +//! and the hysteresis margin, unknown memory holding shed, PSI stalls, cgroup OOM events and swap-out storms. use super::*; use crate::plan::GIB; diff --git a/crates/leleka-memory/src/procfs/tests.rs b/crates/leleka-memory/src/procfs/tests.rs index 138df8b3..9248411b 100644 --- a/crates/leleka-memory/src/procfs/tests.rs +++ b/crates/leleka-memory/src/procfs/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests of the procfs parsers: meminfo, status (pinned, locked, swap), memlock limit, PSI, cgroup files and smaps, +//! including refusal of malformed, duplicated or trailing-field input. use super::*; diff --git a/crates/leleka-memory/src/settings.rs b/crates/leleka-memory/src/settings.rs new file mode 100644 index 00000000..239c29e6 --- /dev/null +++ b/crates/leleka-memory/src/settings.rs @@ -0,0 +1,16 @@ +//! The only place of this crate that reads the process environment: the operator's switches, as typed values. + +use std::ffi::OsString; +use std::path::PathBuf; +use std::sync::OnceLock; + +/// `LELEKA_NO_TRIM_FILE`: bring-up A/B inside one engine; no working-set trim while this file exists. Read once. +pub(crate) fn no_trim_file() -> Option<&'static PathBuf> { + static NO_TRIM_FILE: OnceLock> = OnceLock::new(); + NO_TRIM_FILE.get_or_init(|| std::env::var_os("LELEKA_NO_TRIM_FILE").map(PathBuf::from)).as_ref() +} + +/// The `PATH` of this process, when it is set (where `nvidia-smi` is looked for). +pub(crate) fn search_path() -> Option { + std::env::var_os("PATH") +} diff --git a/crates/leleka-memory/src/smi.rs b/crates/leleka-memory/src/smi.rs index e85407bc..3a60918a 100644 --- a/crates/leleka-memory/src/smi.rs +++ b/crates/leleka-memory/src/smi.rs @@ -72,7 +72,7 @@ pub fn parse_csv(text: &str, index: u32) -> Option { /// The first existing `nvidia-smi` in `PATH`, then in [`EXTRA_LOCATIONS`]. pub fn find_binary() -> Option { - let from_path = std::env::var_os("PATH").and_then(|paths| { + let from_path = crate::settings::search_path().and_then(|paths| { std::env::split_paths(&paths).map(|dir| dir.join("nvidia-smi")).find(|candidate| candidate.is_file()) }); from_path.or_else(|| EXTRA_LOCATIONS.iter().map(std::path::PathBuf::from).find(|candidate| candidate.is_file())) @@ -97,7 +97,7 @@ fn spawn_query(binary: &std::path::Path, index: u32) -> Option Option { let mut child = spawn_query(binary, index)?; let mut stdout = child.stdout.take()?; - let started = Instant::now(); + let started = SystemClock.now(); loop { match child.try_wait() { Ok(Some(status)) => { diff --git a/crates/leleka-memory/src/telemetry.rs b/crates/leleka-memory/src/telemetry.rs index c8b617eb..fa1a9220 100644 --- a/crates/leleka-memory/src/telemetry.rs +++ b/crates/leleka-memory/src/telemetry.rs @@ -272,8 +272,6 @@ pub struct Sampler { mod tests; mod lock; -#[allow(unused_imports)] pub use lock::*; mod render; -#[allow(unused_imports)] pub use render::*; diff --git a/crates/leleka-memory/src/telemetry/lock.rs b/crates/leleka-memory/src/telemetry/lock.rs index e9f1f6a2..9729dcb9 100644 --- a/crates/leleka-memory/src/telemetry/lock.rs +++ b/crates/leleka-memory/src/telemetry/lock.rs @@ -1,5 +1,5 @@ -//! Methods of `State`: `fold_prefill`, `fold_decode`. -//! Functions: `lock`, `with_state`, `published_telemetry`, `set_settings` and 20 more. +//! Recording side of telemetry: the global state and published document behind locks, entry points the engine calls +//! as a request starts, delivers tokens, finishes or hits the NaN guard, and the /proc CPU readers and rate helpers. use super::{ Clock, CpuReading, Duration, EMA_ALPHA, Instant, LastRequest, Mutex, MutexGuard, PUBLISHED, Phase, ProcSource, @@ -244,7 +244,7 @@ pub fn parse_stat_cpu(text: &str) -> Option<(u64, u64)> { Some((total.saturating_sub(idle), total)) } -pub fn read_cpu(src: &dyn ProcSource) -> Option { +pub fn read_cpu(src: &(impl ProcSource + ?Sized)) -> Option { let process_ticks = parse_self_stat_ticks(&src.read("/proc/self/stat").ok()?)?; let (system_busy, system_total) = parse_stat_cpu(&src.read("/proc/stat").ok()?)?; Some(CpuReading { process_ticks, system_busy, system_total }) diff --git a/crates/leleka-memory/src/telemetry/render.rs b/crates/leleka-memory/src/telemetry/render.rs index 30d745f7..dbb02047 100644 --- a/crates/leleka-memory/src/telemetry/render.rs +++ b/crates/leleka-memory/src/telemetry/render.rs @@ -1,5 +1,5 @@ -//! Methods of `Sampler`: `stop`. Implements `Drop for Sampler`. -//! Functions: `ram_of`, `live_rate_of`, `live_request_of`, `rates_of` and 12 more. +//! Rendering and sampling side of telemetry: turns the recorded state and one measurement into the JSON document +//! and runs the Sampler thread that measures the host once a period and publishes it; stops on drop. use super::{ Arc, AtomicBool, Cache, Clock, Context, Cpu, CpuReading, Document, Duration, GpuProbe, Instant, LiveRequest, diff --git a/crates/leleka-memory/src/telemetry/tests.rs b/crates/leleka-memory/src/telemetry/tests.rs index efac2ea4..7b54ee2b 100644 --- a/crates/leleka-memory/src/telemetry/tests.rs +++ b/crates/leleka-memory/src/telemetry/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests of telemetry: /proc parsing, the NaN guard counters, the per-request engine line, tier shares, folding +//! of requests into rates, cache and context, in-flight progress, and nulls for unmeasured rates. use super::*; diff --git a/crates/libc-shim/src/cuda_trace/tests.rs b/crates/libc-shim/src/cuda_trace/tests.rs index 501530b5..f330af28 100644 --- a/crates/libc-shim/src/cuda_trace/tests.rs +++ b/crates/libc-shim/src/cuda_trace/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests of the CUDA Driver trace: untouched symbols and foreign handles pass through, a batched copy is described +//! by its count and stream, and the ring names a kernel. use super::*; diff --git a/crates/model-format/src/bulk_read.rs b/crates/model-format/src/bulk_read.rs index 31ad6807..0d088940 100644 --- a/crates/model-format/src/bulk_read.rs +++ b/crates/model-format/src/bulk_read.rs @@ -88,8 +88,6 @@ struct Shared<'a, F> { mod tests; mod strategy; -#[allow(unused_imports)] pub use strategy::*; mod for_each_chunk; -#[allow(unused_imports)] pub use for_each_chunk::*; diff --git a/crates/model-format/src/bulk_read/for_each_chunk.rs b/crates/model-format/src/bulk_read/for_each_chunk.rs index 68a62388..9975b944 100644 --- a/crates/model-format/src/bulk_read/for_each_chunk.rs +++ b/crates/model-format/src/bulk_read/for_each_chunk.rs @@ -1,5 +1,5 @@ -//! Methods of `Shared`: `new`, `begin`. -//! Functions: `for_each_chunk`, `span_file_len`, `run_readers`, `open_strategy` and 2 more. +//! Public entry points of the cold bulk read: for_each_chunk (reader threads over aligned blocks, first error stops +//! all, sink gets each block) and read_into (fills a buffer); also strategy opening and the shared reader state. use super::{ ALIGN, Aligned, AtomicU64, File, Instant, Mutex, Plan, Report, Shared, Strategy, evict, io, open_direct, read_full, @@ -14,6 +14,7 @@ pub fn for_each_chunk(file: &File, start: u64, len: u64, plan: Plan, sink: F) where F: Fn(u64, &[u8]) -> io::Result<()> + Sync, { + // Measurement timer, not decision logic (instant-now exception in architecture.json). let began = Instant::now(); let file_len = span_file_len(file, start, len)?; let chunk = (plan.chunk.max(ALIGN) / ALIGN * ALIGN) as u64; diff --git a/crates/model-format/src/bulk_read/strategy.rs b/crates/model-format/src/bulk_read/strategy.rs index 793f0764..dbf34eec 100644 --- a/crates/model-format/src/bulk_read/strategy.rs +++ b/crates/model-format/src/bulk_read/strategy.rs @@ -1,5 +1,5 @@ -//! Methods of `Strategy`: `as_str`. Methods of `Plan`: `from_env`, `with_overrides`. Implements `Default for Plan`. -//! Functions: `open_direct`, `open_direct`, `read_at`, `read_at` and 3 more. +//! Read configuration and low-level IO of the bulk reader: Strategy and Plan (defaults plus LELEKA_LOAD_* env +//! overrides), aligned bounce buffers, O_DIRECT reopen, pread, fadvise and eviction, and the per-block worker loop. use super::{ALIGN, Aligned, File, Ordering, Plan, Report, Shared, Strategy, io}; @@ -18,7 +18,7 @@ impl Plan { /// `LELEKA_LOAD_CHUNK_MIB=N`, `LELEKA_LOAD_AHEAD_MIB=N`): the switches that let one binary be measured in each /// form. pub fn from_env() -> Plan { - Plan::with_overrides(Plan::default(), |name| crate::settings::var(name).ok()) + Plan::with_overrides(Plan::default(), crate::settings::load_variable) } pub fn with_overrides(mut plan: Plan, var: impl Fn(&str) -> Option) -> Plan { diff --git a/crates/model-format/src/bulk_read/tests.rs b/crates/model-format/src/bulk_read/tests.rs index 8d3a6bd8..4fddd876 100644 --- a/crates/model-format/src/bulk_read/tests.rs +++ b/crates/model-format/src/bulk_read/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Pins the bulk reader: every strategy returns identical bytes for aligned and ragged spans, blocks cover the span +//! exactly once, bad spans and sink errors fail, a short file is UnexpectedEof, and env overrides apply. use super::*; use std::io::Write; diff --git a/crates/model-format/src/gguf.rs b/crates/model-format/src/gguf.rs index 151a6bec..2e6bb604 100644 --- a/crates/model-format/src/gguf.rs +++ b/crates/model-format/src/gguf.rs @@ -163,51 +163,35 @@ pub(crate) struct GgufSourceFence<'source> { } #[cfg(test)] -#[path = "gguf_owned_read_test.rs"] mod owned_read_test; -#[path = "gguf_resident.rs"] mod resident; pub(crate) use resident::{ResidentLoadError, ResidentTensor}; -#[path = "gguf_digest_capture.rs"] mod digest_capture; pub(crate) use digest_capture::open_expert_capture; pub(crate) use digest_capture::open_incremental_expert_capture; -#[path = "gguf_expert_file_source.rs"] mod expert_file_source; pub use expert_file_source::ExpertFileOwner; -#[path = "gguf_native_head.rs"] mod native_head_model; pub use native_head_model::{NativeHeadGgufModel, NativeHeadTensor}; mod stream_buffer_bytes; -#[allow(unused_imports)] pub use stream_buffer_bytes::*; mod verified_gguf_file; -#[allow(unused_imports)] -pub use verified_gguf_file::*; mod parse_artifact_digest; -#[allow(unused_imports)] pub use parse_artifact_digest::*; mod read_metadata_snapshot_with_architecture; -#[allow(unused_imports)] pub use read_metadata_snapshot_with_architecture::*; mod open_regular; -#[allow(unused_imports)] pub use open_regular::*; mod index_parse; -#[allow(unused_imports)] pub use index_parse::*; mod read_index_file; -#[allow(unused_imports)] pub use read_index_file::*; mod cursor; -#[allow(unused_imports)] -pub use cursor::*; mod value_width; -#[allow(unused_imports)] pub use value_width::*; diff --git a/crates/model-format/src/gguf/cursor.rs b/crates/model-format/src/gguf/cursor.rs index d17cb0e8..cd2085c5 100644 --- a/crates/model-format/src/gguf/cursor.rs +++ b/crates/model-format/src/gguf/cursor.rs @@ -1,5 +1,5 @@ -//! Methods of `Cursor`: `new`, `with_test_capacity`, `position`, `skip` and 23 more. -//! Split out of `gguf` to keep its files under the line limit. +//! Cursor: the bounded, buffered GGUF header reader. Reads little-endian scalars, strings, arrays and metadata values +//! with truncation, overflow and duplicate-key checks, and skips values without reading them. use super::{ BufRead, BufReader, Cursor, HashSet, MetadataValue, Read, Result, STREAM_BUFFER_BYTES, Seek, SeekFrom, value_width, diff --git a/crates/model-format/src/gguf_digest_capture.rs b/crates/model-format/src/gguf/digest_capture.rs similarity index 98% rename from crates/model-format/src/gguf_digest_capture.rs rename to crates/model-format/src/gguf/digest_capture.rs index 28d6d6cb..1f5e693d 100644 --- a/crates/model-format/src/gguf_digest_capture.rs +++ b/crates/model-format/src/gguf/digest_capture.rs @@ -67,7 +67,6 @@ fn read_provisional_index(file: &mut File, size: u64, strict: bool) -> Result= crate::bulk_read::MIN_PARALLEL_BYTES - && crate::settings::var("LELEKA_LOAD_READ").as_deref() != Ok("legacy") + && !crate::settings::legacy_sequential_read() { crate::bulk_read::read_into(file, absolute, bytes, crate::bulk_read::Plan::from_env())?; return Ok(()); diff --git a/crates/model-format/src/gguf/read_index_file.rs b/crates/model-format/src/gguf/read_index_file.rs index fe2be0b6..e0dcbfef 100644 --- a/crates/model-format/src/gguf/read_index_file.rs +++ b/crates/model-format/src/gguf/read_index_file.rs @@ -1,5 +1,5 @@ -//! Functions: `read_index_file`, `block_geometry`. -//! Split out of `gguf` to keep its files under the line limit. +//! Strict tensor-index read of a GGUF file (count limits, no wide alignment) and the table of values-per-block and +//! bytes-per-block of each tensor kind (block_geometry), kept in step with the pinned Strata reader. use super::{Cursor, File, IndexRules, Result, Seek, SeekFrom, TensorIndex, parse_index}; diff --git a/crates/model-format/src/gguf/read_metadata_snapshot_with_architecture.rs b/crates/model-format/src/gguf/read_metadata_snapshot_with_architecture.rs index 31acac62..043f829f 100644 --- a/crates/model-format/src/gguf/read_metadata_snapshot_with_architecture.rs +++ b/crates/model-format/src/gguf/read_metadata_snapshot_with_architecture.rs @@ -1,5 +1,5 @@ -//! Methods of `SnapshotBuilder`: `read_entry`, `try_architecture`, `try_split`, `try_tokenizer` and 4 more. -//! Functions: `read_metadata_snapshot_with_architecture`, `validate_tokenizer_metadata`, `check_tokenizer_shape`, `c... +//! Metadata snapshot reader: walks the GGUF key/value entries and keeps only the wanted groups (architecture, split, +//! profile, tokenizer), validates tokenizer shape and merges; also inspect, tensor_index and tensor_sha256. use super::{ BTreeMap, Cursor, Digest, File, HashSet, MetadataSnapshot, MetadataValue, Path, Read, Result, Seek, SeekFrom, diff --git a/crates/model-format/src/gguf_resident.rs b/crates/model-format/src/gguf/resident.rs similarity index 96% rename from crates/model-format/src/gguf_resident.rs rename to crates/model-format/src/gguf/resident.rs index 26d15eac..a24989d3 100644 --- a/crates/model-format/src/gguf_resident.rs +++ b/crates/model-format/src/gguf/resident.rs @@ -43,7 +43,6 @@ pub(crate) struct FileSpan { } #[cfg(test)] -#[path = "gguf_resident_sdet.rs"] mod sdet; #[cfg(test)] @@ -189,15 +188,7 @@ mod retained_lease_test { } } -#[path = "gguf_resident/next_source_id.rs"] mod next_source_id; -#[allow(unused_imports)] pub use next_source_id::*; -#[path = "gguf_resident/verified_gguf_file.rs"] mod verified_gguf_file; -#[allow(unused_imports)] -pub use verified_gguf_file::*; -#[path = "gguf_resident/verified_gguf_capture_retention.rs"] mod verified_gguf_capture_retention; -#[allow(unused_imports)] -pub use verified_gguf_capture_retention::*; diff --git a/crates/model-format/src/gguf_resident/next_source_id.rs b/crates/model-format/src/gguf/resident/next_source_id.rs similarity index 93% rename from crates/model-format/src/gguf_resident/next_source_id.rs rename to crates/model-format/src/gguf/resident/next_source_id.rs index 92182381..19df18c5 100644 --- a/crates/model-format/src/gguf_resident/next_source_id.rs +++ b/crates/model-format/src/gguf/resident/next_source_id.rs @@ -1,5 +1,5 @@ -//! Methods of `ResidentTensor`: `charged_bytes`, `len`, `file_mapped`, `backing`. -//! Methods of `ResidentStorage`: `backing`, `as_slice`, `len`. +//! Backing storage of a resident tensor (owned heap, mapped file span, huge pages): the unique source-id counter, +//! ResidentTensor accessors, and FileSpan, the read-only file mapping that unmaps itself on drop. use super::{FileSpan, NEXT_SOURCE_ID, Ordering, ResidentStorage, ResidentTensor, Result}; diff --git a/crates/model-format/src/gguf_resident_sdet.rs b/crates/model-format/src/gguf/resident/sdet.rs similarity index 100% rename from crates/model-format/src/gguf_resident_sdet.rs rename to crates/model-format/src/gguf/resident/sdet.rs diff --git a/crates/model-format/src/gguf_resident/verified_gguf_capture_retention.rs b/crates/model-format/src/gguf/resident/verified_gguf_capture_retention.rs similarity index 92% rename from crates/model-format/src/gguf_resident/verified_gguf_capture_retention.rs rename to crates/model-format/src/gguf/resident/verified_gguf_capture_retention.rs index 4f443847..7d80fe3b 100644 --- a/crates/model-format/src/gguf_resident/verified_gguf_capture_retention.rs +++ b/crates/model-format/src/gguf/resident/verified_gguf_capture_retention.rs @@ -1,5 +1,5 @@ -//! Methods of `VerifiedGgufFile`: `capture_source_identity`, `admit_captured_tensor`, `validate_capture_identity`, `... -//! Methods of `ResidentTensor`: `into_retained`, `retained_bytes`, `retention_metadata_bytes`. +//! Source identity and admission of captured tensors: VerifiedGgufFile hands out a resident source id, checks that +//! captured or retained bytes match the indexed tensor, and ResidentTensor is retained (Rc) with its metadata size. use super::{ResidentStorage, ResidentTensor, Result, VerifiedGgufFile, next_source_id}; diff --git a/crates/model-format/src/gguf_resident/verified_gguf_file.rs b/crates/model-format/src/gguf/resident/verified_gguf_file.rs similarity index 97% rename from crates/model-format/src/gguf_resident/verified_gguf_file.rs rename to crates/model-format/src/gguf/resident/verified_gguf_file.rs index 7f241af7..c5073725 100644 --- a/crates/model-format/src/gguf_resident/verified_gguf_file.rs +++ b/crates/model-format/src/gguf/resident/verified_gguf_file.rs @@ -1,5 +1,5 @@ -//! Methods of `VerifiedGgufFile`: `load_resident_tensor`, `resident_extent`, `load_huge`, `load_heap` and 7 more. -//! Methods of `GgufSourceFence`: `copy_resident_tensor`. Functions: `mapping_granularity`, `mapping_granularity`. +//! Resident tensor loading from the verified GGUF file: heap or huge-page copies, read-only file mappings (Linux and +//! Windows), and copy-out of a resident span, all under the indexed bounds and same-descriptor size checks. use super::{ FileSpan, GgufSourceFence, ResidentLoadError, ResidentStorage, ResidentTensor, Result, VerifiedGgufFile, diff --git a/crates/model-format/src/gguf/stream_buffer_bytes.rs b/crates/model-format/src/gguf/stream_buffer_bytes.rs index 37844bc7..89d4de41 100644 --- a/crates/model-format/src/gguf/stream_buffer_bytes.rs +++ b/crates/model-format/src/gguf/stream_buffer_bytes.rs @@ -1,5 +1,5 @@ -//! Functions: `stream_buffer_bytes`, `stream_buffer_bytes`, `with_test_stream_buffer`. -//! Split out of `gguf` to keep its files under the line limit. +//! The stream buffer size for tensor span reads: fixed in production, with a thread-local test override +//! (with_test_stream_buffer) so small fixtures can exercise multi-chunk streaming. use super::STREAM_BUFFER_BYTES; #[cfg(test)] diff --git a/crates/model-format/src/gguf/tests.rs b/crates/model-format/src/gguf/tests.rs index 896beac9..a3dd3c11 100644 --- a/crates/model-format/src/gguf/tests.rs +++ b/crates/model-format/src/gguf/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of `gguf`. +//! Shared fixture of the gguf tests: OwnedFixture writes a tiny two-tensor GGUF in a temp directory (with its +//! sha256 digest and field offsets) and removes it on drop; the test cases live in the tests/ submodules. use super::*; @@ -77,11 +78,7 @@ impl Drop for OwnedFixture { } } -#[path = "tests/admits_flash_metadata_and_rejects.rs"] mod admits_flash_metadata_and_rejects; -#[path = "tests/buffered_cursor_preserves_offsets_parsin.rs"] mod buffered_cursor_preserves_offsets_parsin; -#[path = "tests/empty_owned_tensor_validation_preserves.rs"] mod empty_owned_tensor_validation_preserves; -#[path = "tests/original_first_source_fence_retains.rs"] mod original_first_source_fence_retains; diff --git a/crates/model-format/src/gguf/value_width.rs b/crates/model-format/src/gguf/value_width.rs index 63e9b350..af705c08 100644 --- a/crates/model-format/src/gguf/value_width.rs +++ b/crates/model-format/src/gguf/value_width.rs @@ -1,5 +1,5 @@ -//! Methods of `GgufSourceFence`: `validate_tensor`, `stream_tensor`, `read_tensor_owned`, `finish`. -//! Methods of `VerifiedGgufFile`: `validate_empty_tensor_source`, `validate_empty_tensor_span`, `begin_source_fence`. +//! Element width of GGUF array types, and the source fence: a guard over one verified file that validates empty-tensor +//! spans, streams or reads tensors with the original size checks, and finishes with a last size check. use super::{GgufSourceFence, Result, VerifiedGgufFile}; diff --git a/crates/model-format/src/gguf/verified_gguf_file.rs b/crates/model-format/src/gguf/verified_gguf_file.rs index fecfb3a8..aff38499 100644 --- a/crates/model-format/src/gguf/verified_gguf_file.rs +++ b/crates/model-format/src/gguf/verified_gguf_file.rs @@ -1,5 +1,5 @@ -//! Methods of `VerifiedGgufFile`: `open`, `index`, `duplicate_descriptor`, `artifact_sha256` and 10 more. -//! Functions: `verify_digest`, `record_stamp`. +//! VerifiedGgufFile: opens a GGUF against its expected sha256 (with a verification stamp shortcut), keeps the +//! descriptor and strict index, and serves metadata snapshots, bounded tensor streams, owned reads and tensor hashes. use super::{ Digest, File, MetadataSnapshot, Path, QWEN4EXP_BINDING_KEYS, Result, Sha256, TensorIndex, TokenizerMetadata, diff --git a/crates/model-format/src/huge_pages.rs b/crates/model-format/src/huge_pages.rs index 9340b94c..3f0517b2 100644 --- a/crates/model-format/src/huge_pages.rs +++ b/crates/model-format/src/huge_pages.rs @@ -41,7 +41,7 @@ pub fn mode() -> Mode { if !cfg!(target_os = "linux") { return Mode::Off; } - match crate::settings::var("LELEKA_HUGEPAGES").ok().as_deref() { + match crate::settings::huge_pages_text().as_deref() { Some("on") => Mode::On, Some("thp") => Mode::Thp, Some("off") => Mode::Off, @@ -49,7 +49,7 @@ pub fn mode() -> Mode { eprintln!("leleka-hugepages: unknown LELEKA_HUGEPAGES={other:?} (on | thp | off): off"); Mode::Off } - _ if crate::settings::var("LELEKA_BANK_THP").is_ok_and(|v| v == "on") => Mode::Thp, + _ if crate::settings::bank_thp_on() => Mode::Thp, _ => Mode::Off, } }) @@ -326,6 +326,7 @@ mod linux { let mut text = line("after fill", &before); let aligned: u64 = thp_ranges().iter().map(|r| r.1 as u64).sum(); if before.thp_bytes < aligned { + // Measurement timer, not decision logic (instant-now exception in architecture.json). let t = std::time::Instant::now(); let (failed, last_error) = collapse(&thp_ranges()); let after = coverage().unwrap_or(before); diff --git a/crates/model-format/src/kar.rs b/crates/model-format/src/kar.rs index 97ae9c3e..51deaaf1 100644 --- a/crates/model-format/src/kar.rs +++ b/crates/model-format/src/kar.rs @@ -240,11 +240,9 @@ const WARM_ROW_NS: u128 = 20_000; const COLD_SKIP_CALLS: u32 = 256; static COLD_SKIP: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0); -#[path = "kar_nested.rs"] mod nested; pub use nested::{KarNestedRecord, NESTING_TOPDOWN}; -#[path = "kar_extents.rs"] mod extents; pub use extents::{ CensusRecord, EXTENT_ALIGN, Extent, KarCensus, PLE_EXTENTS_SHA256, PLE_PART_NAMES, PLE_PLANES, PLE_ROW_PLANE_BYTES, @@ -269,23 +267,15 @@ mod extents_tests; mod row_read_tests; mod inspection; -#[allow(unused_imports)] pub use inspection::*; mod decode_record_range; -#[allow(unused_imports)] pub use decode_record_range::*; mod inspect_file; -#[allow(unused_imports)] pub use inspect_file::*; mod read_region; -#[allow(unused_imports)] pub use read_region::*; mod kar_ple_profile; -#[allow(unused_imports)] pub use kar_ple_profile::*; mod verified_kar_ple_artifact; -#[allow(unused_imports)] -pub use verified_kar_ple_artifact::*; mod independent_handles; -#[allow(unused_imports)] pub use independent_handles::*; diff --git a/crates/model-format/src/kar/decode_record_range.rs b/crates/model-format/src/kar/decode_record_range.rs index d3c3c3c6..39c97728 100644 --- a/crates/model-format/src/kar/decode_record_range.rs +++ b/crates/model-format/src/kar/decode_record_range.rs @@ -1,5 +1,5 @@ -//! Functions: `decode_record_range`, `decode_raw`, `decode_window`, `decode_nested` and 3 more. Defines `Window`. -//! Split out of `kar` to keep its files under the line limit. +//! CPU quality-oracle decoder of a KAR tensor record: decodes a bounded element range of a RAW F32 tensor or of a +//! nested multi-level tensor, reading only the group scales, level book and bit planes that cover the range. use super::{DecodeSource, ElementRange, File, RECORD_BYTES, ScalarDecoder, read_region, u16_at, u32_at, u64_at}; diff --git a/crates/model-format/src/kar_extents.rs b/crates/model-format/src/kar/extents.rs similarity index 96% rename from crates/model-format/src/kar_extents.rs rename to crates/model-format/src/kar/extents.rs index 3654c3a8..20698628 100644 --- a/crates/model-format/src/kar_extents.rs +++ b/crates/model-format/src/kar/extents.rs @@ -18,7 +18,6 @@ use super::{ KarError, KarInspection, KarNestedRecord, KarTensorSource, PLE_ROWS, Sha256, VerifiedPart, read_at, round_up, }; use sha2::Digest; -use std::fmt::Write as _; /// Granularity of a sparse copy: the page size of the memfd (and of `mlock`). pub const EXTENT_ALIGN: u64 = 4096; @@ -125,11 +124,6 @@ pub struct ClassTotals { pub extent_bytes: u64, } -#[path = "kar_extents/extent.rs"] mod extent; -#[allow(unused_imports)] pub use extent::*; -#[path = "kar_extents/kar_inspection.rs"] mod kar_inspection; -#[allow(unused_imports)] -pub use kar_inspection::*; diff --git a/crates/model-format/src/kar_extents/extent.rs b/crates/model-format/src/kar/extents/extent.rs similarity index 97% rename from crates/model-format/src/kar_extents/extent.rs rename to crates/model-format/src/kar/extents/extent.rs index 721e544f..b70b2f5d 100644 --- a/crates/model-format/src/kar_extents/extent.rs +++ b/crates/model-format/src/kar/extents/extent.rs @@ -1,7 +1,6 @@ -//! Methods of `Extent`: `new`, `end`. Methods of `VerifiedPart`: `reads`. -//! Functions: `extents_bytes`, `normalize_extents`, `extents_cover`, `extents_overlap` and 5 more. +//! Extent arithmetic of the serve read set: page-align and merge, cover and overlap tests, the pinned sparse-copy +//! SHA-256 over an extent list, and the exact byte ranges the serve path reads per PLE partition. -use std::fmt::Write as _; use super::{ DOMAIN, Digest, EXTENT_ALIGN, Extent, HASH_CHUNK, KarError, KarNestedRecord, PLE_ROW_PLANE_BYTES, PLE_ROW_SCALE_BYTES, ServeReads, Sha256, VerifiedPart, read_at, round_up, diff --git a/crates/model-format/src/kar_extents/kar_inspection.rs b/crates/model-format/src/kar/extents/kar_inspection.rs similarity index 98% rename from crates/model-format/src/kar_extents/kar_inspection.rs rename to crates/model-format/src/kar/extents/kar_inspection.rs index 4cbde859..ae6b4c2c 100644 --- a/crates/model-format/src/kar_extents/kar_inspection.rs +++ b/crates/model-format/src/kar/extents/kar_inspection.rs @@ -1,5 +1,5 @@ -//! Methods of `KarInspection`: `payload_offset`, `serve_reads`, `census`. Methods of `RecordClass`: `label`. -//! Functions: `census_record`, `gib`, `pct`. +//! Read-only reports on a KAR archive directory: what the serve path reads (serve_reads), and the census that +//! classifies every record, totals the read and unread bytes and renders the text report. use std::fmt::Write as _; use super::{ diff --git a/crates/model-format/src/kar/independent_handles.rs b/crates/model-format/src/kar/independent_handles.rs index 464e66e7..25686001 100644 --- a/crates/model-format/src/kar/independent_handles.rs +++ b/crates/model-format/src/kar/independent_handles.rs @@ -1,5 +1,5 @@ -//! Methods of `KarPleRowReader`: `read_rows`. -//! Functions: `independent_handles`, `reopen_independent`, `reopen_independent`, `read_rows_parallel` and 11 more. +//! Parallel positional reads of PLE rows: independent file handles, fan-out over threads with a warm-cache probe, +//! the per-read guard that refuses an archive changed since verification, and the three reads of one row. use super::{ COLD_SKIP, COLD_SKIP_CALLS, File, KarError, KarPleRowPacket, KarPleRowReader, PLE_ROWS, VerifiedPart, WARM_ROW_NS, @@ -101,6 +101,7 @@ fn read_warm( COLD_SKIP.fetch_sub(1, Ordering::Relaxed); return Ok(false); } + // Measurement timer, not decision logic (instant-now exception in architecture.json). let started = std::time::Instant::now(); read_rows_chunk(first, parts, &rows[..1], &mut packets[..1])?; if started.elapsed().as_nanos() <= WARM_ROW_NS { @@ -167,12 +168,7 @@ pub(super) fn check_archive_state( /// keep `ctime` stable, for example). Read once; the default is on. pub(super) fn identity_recheck_enabled() -> bool { static ENABLED: std::sync::OnceLock = std::sync::OnceLock::new(); - *ENABLED.get_or_init(|| { - !matches!( - crate::settings::var("LELEKA_KAR_IDENTITY_RECHECK").as_deref().map(str::trim), - Ok("off" | "0" | "no" | "false") - ) - }) + *ENABLED.get_or_init(|| !crate::settings::kar_identity_recheck_disabled()) } pub(super) fn read_rows_chunk( diff --git a/crates/model-format/src/kar/inspect_file.rs b/crates/model-format/src/kar/inspect_file.rs index 31007bfe..17bee5af 100644 --- a/crates/model-format/src/kar/inspect_file.rs +++ b/crates/model-format/src/kar/inspect_file.rs @@ -1,5 +1,5 @@ -//! Functions: `inspect_file`, `read_tables`, `check_directory_digest`. -//! Split out of `kar` to keep its files under the line limit. +//! Metadata inspection of a KAR file: parses the header, reads the name table and directory, checks their digest +//! against the header, and scans every record into the sections, sources and summary of a Parsed archive. use super::{ Digest, File, HEADER_BYTES, HashSet, KarSummary, KarTensorSource, MAX_NAMES, MAX_TENSORS, Parsed, RECORD_BYTES, diff --git a/crates/model-format/src/kar/kar_ple_profile.rs b/crates/model-format/src/kar/kar_ple_profile.rs index 31dc1562..adc6a355 100644 --- a/crates/model-format/src/kar/kar_ple_profile.rs +++ b/crates/model-format/src/kar/kar_ple_profile.rs @@ -1,5 +1,5 @@ -//! Methods of `KarPleProfile`: `new`, `with_total_rows`, `native_shard_sha256`. -//! Methods of `KarPleRowPacket`: `payload`, `partition`. +//! KarPleProfile construction and validation (unique contiguous partitions with row counts and source digests), +//! plus small accessors: row packet payload, trust labels, startup-read total, and the unlinked-file check. use super::{ File, HashSet, KarError, KarPlePartProvenance, KarPleProfile, KarPleProfileSpec, KarPleRowPacket, KarStartupRead, diff --git a/crates/model-format/src/kar_nested.rs b/crates/model-format/src/kar/nested.rs similarity index 99% rename from crates/model-format/src/kar_nested.rs rename to crates/model-format/src/kar/nested.rs index f22b3aa0..3e1e24f6 100644 --- a/crates/model-format/src/kar_nested.rs +++ b/crates/model-format/src/kar/nested.rs @@ -266,5 +266,5 @@ impl WeightSource for KarInspection { } #[cfg(test)] -#[path = "weight_source/kar_inspection_tests.rs"] +#[path = "../weight_source/kar_inspection_tests.rs"] mod weight_source_tests; diff --git a/crates/model-format/src/kar/read_region.rs b/crates/model-format/src/kar/read_region.rs index 60a8ed6e..f7d8e317 100644 --- a/crates/model-format/src/kar/read_region.rs +++ b/crates/model-format/src/kar/read_region.rs @@ -1,5 +1,5 @@ -//! Methods of `SectionCrc`: `new`, `feed`. Functions: `read_region`, `u16_at`, `u32_at`, `u64_at` and 9 more. -//! Defines `SectionCrc`, `ChunkReceiver`. +//! Low-level KAR reads and integrity: bounded region reads, little-endian field readers, CRC-32, the per-section +//! SectionCrc, and the pipelined and reference SHA-256 plus CRC verification of a whole archive. use super::{CRC32_SLICES, CRC32_TABLE, Digest, File, KarError, Read, Section, Seek, SeekFrom, Sha256}; diff --git a/crates/model-format/src/kar/verified_kar_ple_artifact.rs b/crates/model-format/src/kar/verified_kar_ple_artifact.rs index 73ebfba0..faf4b0ff 100644 --- a/crates/model-format/src/kar/verified_kar_ple_artifact.rs +++ b/crates/model-format/src/kar/verified_kar_ple_artifact.rs @@ -1,5 +1,5 @@ -//! Methods of `VerifiedKarPleArtifact`: `verify`, `verify_sparse`, `verify_with`, `serve_extents` and 14 more. -//! Split out of `kar` to keep its files under the line limit. +//! VerifiedKarPleArtifact: an archive verified against its pins (full pass or sparse extents) that serves PLE row +//! reads (16-row, batched or via an owned reader) and exposes digests, extents and startup-read accounting. use super::{ ArchiveView, Extent, FanOut, File, KarError, KarImmutableSource, KarInspection, KarPlePartProvenance, diff --git a/crates/model-format/src/kar_kernel_model.rs b/crates/model-format/src/kar_kernel_model.rs index 6a755608..3b8b07ae 100644 --- a/crates/model-format/src/kar_kernel_model.rs +++ b/crates/model-format/src/kar_kernel_model.rs @@ -115,8 +115,6 @@ pub const MAX_SWIGLU_VALUES: u64 = 1 << 20; mod tests; mod window_plan; -#[allow(unused_imports)] pub use window_plan::*; mod decode_params_valid; -#[allow(unused_imports)] pub use decode_params_valid::*; diff --git a/crates/model-format/src/kar_kernel_model/decode_params_valid.rs b/crates/model-format/src/kar_kernel_model/decode_params_valid.rs index 5e166154..65de60f6 100644 --- a/crates/model-format/src/kar_kernel_model/decode_params_valid.rs +++ b/crates/model-format/src/kar_kernel_model/decode_params_valid.rs @@ -1,5 +1,5 @@ -//! Methods of `MultiplyDims`: `new`. -//! Functions: `decode_params_valid`, `level_and_count_ok`, `group_ok`, `layout_ok` and 12 more. Defines `MultiplyDims`. +//! Host model of the KAR CUDA kernels: the decode argument guard, bit-literal models of the decode, multiply and +//! SwiGLU kernels (MultiplyDims is the multiply launch shape), and the reference stager that fills a packet. use super::{ BLOCK_THREADS, BOOK_REGION_BYTES, DecodeParams, MAX_COLUMNS, MAX_LEVEL, MAX_RANGE_ELEMENTS, MAX_SWIGLU_VALUES, diff --git a/crates/model-format/src/kar_levels.rs b/crates/model-format/src/kar_levels.rs index fc5b33ac..2093d0cd 100644 --- a/crates/model-format/src/kar_levels.rs +++ b/crates/model-format/src/kar_levels.rs @@ -175,11 +175,7 @@ pub trait RangeSource { use crate::kar::KarError; mod class_levels; -#[allow(unused_imports)] -pub use class_levels::*; mod selection; -#[allow(unused_imports)] pub use selection::*; mod expert_scratch; -#[allow(unused_imports)] pub use expert_scratch::*; diff --git a/crates/model-format/src/kar_levels/expert_scratch.rs b/crates/model-format/src/kar_levels/expert_scratch.rs index 179d00c3..9be4eb84 100644 --- a/crates/model-format/src/kar_levels/expert_scratch.rs +++ b/crates/model-format/src/kar_levels/expert_scratch.rs @@ -1,5 +1,5 @@ -//! Functions: `expert_scratch`, `cpu_reference_mlp`. -//! Split out of `kar_levels` to keep its files under the line limit. +//! Device scratch size of one expert FFN (three packets, one F32 matrix and intermediates) and the CPU reference +//! of the same gate/up/SwiGLU/down pipeline that GPU smokes compare against. use super::{GpuRows, KarLevelsError, Result, STATUS_BYTES, ScratchBytes, model}; diff --git a/crates/model-format/src/kar_levels/selection.rs b/crates/model-format/src/kar_levels/selection.rs index 126a3f8c..d227c537 100644 --- a/crates/model-format/src/kar_levels/selection.rs +++ b/crates/model-format/src/kar_levels/selection.rs @@ -1,5 +1,5 @@ -//! Methods of `Selection`: `window_error`, `resident_prefix_bytes`, `window`, `rows` and 1 more. -//! Methods of `GpuWindow`: `new`, `staged_source_bytes`, `scratch`. +//! Selection methods and GPU plan sizes of KAR level selection: resident prefix bytes, element windows, row and +//! expert matrices, per-plan scratch bytes, the ScratchBudget, and the routed-expert tensor name. use super::{ ArchiveSlot, EXPERT_ROLES, GpuRows, GpuWindow, KarError, KarInspection, KarLevelSelector, KarLevelsError, diff --git a/crates/model-format/src/native_dense_plan.rs b/crates/model-format/src/native_dense_plan.rs index a12317e6..c7347dc5 100644 --- a/crates/model-format/src/native_dense_plan.rs +++ b/crates/model-format/src/native_dense_plan.rs @@ -315,7 +315,7 @@ fn matrix_compatible(tensor: &TensorRow, reference: &Canonical) -> bool { /// Everything `NativeDense::load` does before its first `cudaMalloc`, in the Original's order and with its messages. pub fn plan_load( shards: &[ShardInfo], - canonical: &dyn Fn(&str) -> Option, + canonical: &(impl Fn(&str) -> Option + ?Sized), include_ple_key: bool, ) -> Result { if shards.is_empty() { diff --git a/crates/model-format/src/native_dense_plan/tests.rs b/crates/model-format/src/native_dense_plan/tests.rs index 6bf37700..f3baddc8 100644 --- a/crates/model-format/src/native_dense_plan/tests.rs +++ b/crates/model-format/src/native_dense_plan/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Pins the native dense plan: weight bytes follow the Original tables, tensor eligibility by name and type, the +//! two-shard upload plan, the Original's refusal messages, and that an unquantized PLE key is skipped, not refused. use super::*; diff --git a/crates/model-format/src/pinned_arena_plan.rs b/crates/model-format/src/pinned_arena_plan.rs index 93bb036a..ecec1192 100644 --- a/crates/model-format/src/pinned_arena_plan.rs +++ b/crates/model-format/src/pinned_arena_plan.rs @@ -8,8 +8,6 @@ //! trusts the caller); reads use positional I/O (`read_exact_at`) instead of one `FILE*` per thread, which has the same //! effect (no shared seek position) and reaches the disk with the requested chunk size. -use std::fmt::Write as _; - /// Seed constant exactly as written in pinned.cu (`1469598103934665603`, one digit short of the textbook FNV offset). pub const FNV_SEED: u64 = 1_469_598_103_934_665_603; const FNV_PRIME: u64 = 1_099_511_628_211; @@ -105,36 +103,19 @@ pub struct LoadStats { mod tests; mod fnv1a64; -#[allow(unused_imports)] pub use fnv1a64::arena_lock_enabled; -#[allow(unused_imports)] pub use fnv1a64::arena_pin_cap_gib; -#[allow(unused_imports)] -use fnv1a64::atoi; -#[allow(unused_imports)] pub use fnv1a64::decide_pin; -#[allow(unused_imports)] pub use fnv1a64::fnv1a64; #[cfg(unix)] -#[allow(unused_imports)] pub use fnv1a64::open_shared_arena_file; -#[allow(unused_imports)] pub use fnv1a64::pin_sliced; -#[allow(unused_imports)] pub use fnv1a64::plan_shared_file; -#[allow(unused_imports)] pub use fnv1a64::shared_mapping_note; -#[allow(unused_imports)] pub use fnv1a64::sliced_note; -#[allow(unused_imports)] pub use fnv1a64::uniform_bounds; mod expert_parallel_load; #[cfg(unix)] -#[allow(unused_imports)] pub use expert_parallel_load::load_experts; #[cfg(unix)] -#[allow(unused_imports)] pub use expert_parallel_load::load_experts_ranges; -#[cfg(unix)] -#[allow(unused_imports)] -use expert_parallel_load::read_up_to; diff --git a/crates/model-format/src/pinned_arena_plan/expert_parallel_load.rs b/crates/model-format/src/pinned_arena_plan/expert_parallel_load.rs index 2ec1b079..cf00c50a 100644 --- a/crates/model-format/src/pinned_arena_plan/expert_parallel_load.rs +++ b/crates/model-format/src/pinned_arena_plan/expert_parallel_load.rs @@ -1,7 +1,6 @@ -//! Methods of `LoadShared`: `fill`. -//! Functions: `load_experts`, `load_experts_ranges`, `load_failure`, `carve_windows` and 4 more. +//! Parallel expert load into a destination buffer: disjoint per-layer windows carved from the caller's ranges, +//! worker threads reading chunks by positional reads, and a per-layer FNV-1a checksum; a short read is an error. -use std::fmt::Write as _; use super::{ExpertLayout, FNV_SEED, LoadStats, ReadPlan, fnv1a64}; /// `load_experts`: `layers` uniform ranges of `blobs_per_layer * blob_bytes`. @@ -27,6 +26,7 @@ pub fn load_experts_ranges( let ReadPlan { threads, chunk_bytes: chunk } = plan; let mut st = LoadStats { ok: true, layers: layer_off.len() as u64, bytes: layer_bytes.iter().sum(), ..Default::default() }; + // Measurement timer, not decision logic (instant-now exception in architecture.json). let t0 = std::time::Instant::now(); if layer_off.len() != layer_bytes.len() || chunk == 0 { return load_failure(st, "layer offset and size lists differ, or the chunk is empty".into()); diff --git a/crates/model-format/src/pinned_arena_plan/fnv1a64.rs b/crates/model-format/src/pinned_arena_plan/fnv1a64.rs index b53e1c59..dd1b8a2a 100644 --- a/crates/model-format/src/pinned_arena_plan/fnv1a64.rs +++ b/crates/model-format/src/pinned_arena_plan/fnv1a64.rs @@ -1,5 +1,5 @@ -//! Methods of `SharedArenaHeader`: `new`, `describes`, `encode`, `decode`. -//! Methods of `LoadStats`: `gib_per_second`, `read_gib_per_second`. +//! FNV-1a hash, the shared arena file header and its create-or-reuse admission, the pin-registration plan (env +//! cap, uniform slices, sliced registration notes, lock switch) and LoadStats throughput accessors. use std::fmt::Write as _; use super::{ diff --git a/crates/model-format/src/pinned_arena_plan/tests.rs b/crates/model-format/src/pinned_arena_plan/tests.rs index 1968e899..0784d1ad 100644 --- a/crates/model-format/src/pinned_arena_plan/tests.rs +++ b/crates/model-format/src/pinned_arena_plan/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Pins the pinned-arena plan: FNV recurrence, shared header layout and file admission, pin cap and sliced +//! registration decisions with their notes, and that the parallel load equals a serial read with layer checksums. use super::*; diff --git a/crates/model-format/src/ple_reader.rs b/crates/model-format/src/ple_reader.rs index 5d98485d..cb98e071 100644 --- a/crates/model-format/src/ple_reader.rs +++ b/crates/model-format/src/ple_reader.rs @@ -203,14 +203,7 @@ pub struct PleReader { mod tests; mod file_page_source; -#[allow(unused_imports)] pub use file_page_source::*; mod read_queue; -#[allow(unused_imports)] -pub use read_queue::*; mod row_reading; -#[allow(unused_imports)] -pub use row_reading::*; mod ple_reader_debug_drop; -#[allow(unused_imports)] -pub use ple_reader_debug_drop::*; diff --git a/crates/model-format/src/ple_reader/file_page_source.rs b/crates/model-format/src/ple_reader/file_page_source.rs index 583632e2..defe389f 100644 --- a/crates/model-format/src/ple_reader/file_page_source.rs +++ b/crates/model-format/src/ple_reader/file_page_source.rs @@ -1,5 +1,5 @@ -//! Methods of `PleReaderConfig`: `new`. Methods of `ReaderStats`: `percentile`. -//! Implements `PageSource for File`, `Display for PleError` and 1 more. +//! Plumbing of the PLE row reader: the File page source, error display, config and statistics helpers, the row +//! cache, read planning (cache hits and out-of-range rows resolved, the rest grouped by page), aligned buffers. use super::{ AlignedBuf, EMPTY, File, HashMap, Mutex, MutexGuard, PAGE, PageSource, PlannedRead, PleError, PleReaderConfig, @@ -220,13 +220,13 @@ impl AlignedBuf { /// Whether `source` serves one page-aligned page read at the page holding /// `offset`, through a 4 KiB-aligned buffer. Used to accept an unbuffered /// (O_DIRECT) handle only once it demonstrably works on this filesystem. -pub fn probe_aligned_read(source: &dyn PageSource, offset: u64) -> bool { +pub fn probe_aligned_read(source: &(impl PageSource + ?Sized), offset: u64) -> bool { let mut buf = AlignedBuf::new(PAGE); let page = offset / PAGE as u64 * PAGE as u64; matches!(read_full_at(source, buf.window(PAGE), page), Ok(n) if n > 0) } -pub(super) fn read_full_at(source: &dyn PageSource, buf: &mut [u8], offset: u64) -> io::Result { +pub(super) fn read_full_at(source: &(impl PageSource + ?Sized), buf: &mut [u8], offset: u64) -> io::Result { let mut total = 0; while total < buf.len() { match source.read_at(&mut buf[total..], offset + total as u64) { diff --git a/crates/model-format/src/ple_reader/ple_reader_debug_drop.rs b/crates/model-format/src/ple_reader/ple_reader_debug_drop.rs index 50143204..c6b1982a 100644 --- a/crates/model-format/src/ple_reader/ple_reader_debug_drop.rs +++ b/crates/model-format/src/ple_reader/ple_reader_debug_drop.rs @@ -1,5 +1,5 @@ -//! Implements `Debug for PleReader`, `Drop for PleReader`. -//! Split out of `ple_reader` to keep its files under the line limit. +//! Debug output and shutdown of PleReader: Debug shows rows and worker count, and Drop closes the reader +//! (stops its workers). use super::{PleReader, fmt}; diff --git a/crates/model-format/src/ple_reader/read_queue.rs b/crates/model-format/src/ple_reader/read_queue.rs index c4a09c49..5e66995a 100644 --- a/crates/model-format/src/ple_reader/read_queue.rs +++ b/crates/model-format/src/ple_reader/read_queue.rs @@ -171,6 +171,7 @@ impl Shared { /// Take the next job (marking it in flight) or `None` when there is none. pub(super) fn start(&self, st: &mut State) -> Option<(Job, Instant, Duration)> { let job = st.queue.pop_front()?; + // Measurement timer, not decision logic (instant-now exception in architecture.json). let now = Instant::now(); st.inflight += 1; st.keep.last_read = Some(now); diff --git a/crates/model-format/src/ple_reader/row_reading.rs b/crates/model-format/src/ple_reader/row_reading.rs index e1bc037e..710fe992 100644 --- a/crates/model-format/src/ple_reader/row_reading.rs +++ b/crates/model-format/src/ple_reader/row_reading.rs @@ -57,6 +57,7 @@ impl PleReader { let mut st = lock(&shared.state); let id = st.next_ticket; st.next_ticket = st.next_ticket.wrapping_add(1).max(1); + // Measurement timer, not decision logic (instant-now exception in architecture.json). let now = Instant::now(); let rearm = !st.keep.period.is_zero() && st.keep.last_issue.is_none_or(|last| now.duration_since(last) > st.keep.window); diff --git a/crates/model-format/src/ple_reader/tests.rs b/crates/model-format/src/ple_reader/tests.rs index 100459a9..cd9ff032 100644 --- a/crates/model-format/src/ple_reader/tests.rs +++ b/crates/model-format/src/ple_reader/tests.rs @@ -131,9 +131,6 @@ fn flaky_reader(threads: Option, panic: bool) -> Arc { Arc::new(PleReader::open(source, c).unwrap()) } -#[path = "tests/max_inflight_bounds_concurrent_reads.rs"] mod max_inflight_bounds_concurrent_reads; -#[path = "tests/prefetched_keys_are_matched.rs"] mod prefetched_keys_are_matched; -#[path = "tests/rows_match_the_oracle_including.rs"] mod rows_match_the_oracle_including; diff --git a/crates/model-format/src/qwen4exp.rs b/crates/model-format/src/qwen4exp.rs index abb49986..82d7027d 100644 --- a/crates/model-format/src/qwen4exp.rs +++ b/crates/model-format/src/qwen4exp.rs @@ -232,7 +232,6 @@ pub struct RoutedMoeSourceScope<'source> { resident_experts: Option<&'source expert_source_bank::ResidentExpertBank>, } -#[path = "qwen4exp_expert_source_bank.rs"] mod expert_source_bank; pub use expert_source_bank::{ ResidentExpertBankLease, ResidentExpertBankMember, ResidentExpertBankSpan, ResidentExpertSourceError, @@ -244,31 +243,19 @@ pub(crate) use expert_source_bank::test_resident_source_memory_admission; pub use expert_source_bank::ProvisionalExpertSource; -#[path = "qwen4exp_file_expert_source.rs"] mod file_expert_source; pub use file_expert_source::{FileExpertExtent, FileExpertSourceLease}; mod binding_topology; -#[allow(unused_imports)] -pub use binding_topology::*; mod qwen4_exp_artifact; -#[allow(unused_imports)] -pub use qwen4_exp_artifact::*; mod validate_owner_index_split; -#[allow(unused_imports)] pub use validate_owner_index_split::*; mod validate_logical_views; -#[allow(unused_imports)] pub use validate_logical_views::*; mod expected_inventory; -#[allow(unused_imports)] pub use expected_inventory::*; mod validate_role_inventory; -#[allow(unused_imports)] pub use validate_role_inventory::*; mod plan_stream_rows; -#[allow(unused_imports)] pub use plan_stream_rows::*; mod routed_moe_source_opening; -#[allow(unused_imports)] -pub use routed_moe_source_opening::*; diff --git a/crates/model-format/src/qwen4exp/expected_inventory.rs b/crates/model-format/src/qwen4exp/expected_inventory.rs index bc7e0fd6..f6bdcc23 100644 --- a/crates/model-format/src/qwen4exp/expected_inventory.rs +++ b/crates/model-format/src/qwen4exp/expected_inventory.rs @@ -1,5 +1,5 @@ -//! Functions: `expert_roles`, `expected_tensor`, `expected_inventory`, `push_layer`. Defines `LayerEntry`. -//! Split out of `qwen4exp` to keep its files under the line limit. +//! The closed inventory of tensors a Qwen4Exp artifact must hold: per-layer common, full-attention, linear-attention +//! and layer-1 PLE tensors with their names, dimensions and pinned GGUF kinds, plus the routed-expert roles. use super::{ExpectedTensor, GlobalRole, LayerRole, TensorRole}; diff --git a/crates/model-format/src/qwen4exp_expert_source_bank.rs b/crates/model-format/src/qwen4exp/expert_source_bank.rs similarity index 87% rename from crates/model-format/src/qwen4exp_expert_source_bank.rs rename to crates/model-format/src/qwen4exp/expert_source_bank.rs index 649fd78d..fce59644 100644 --- a/crates/model-format/src/qwen4exp_expert_source_bank.rs +++ b/crates/model-format/src/qwen4exp/expert_source_bank.rs @@ -54,7 +54,6 @@ pub(super) struct ResidentExpertBank { copied_bytes: Cell, } -#[path = "qwen4exp_digest_capture.rs"] mod digest_capture; pub use digest_capture::ProvisionalExpertSource; @@ -82,15 +81,7 @@ pub struct ResidentExpertBankSpan { length: usize, } -#[path = "qwen4exp_expert_source_bank/retention_metadata_bytes.rs"] mod retention_metadata_bytes; -#[allow(unused_imports)] pub use retention_metadata_bytes::*; -#[path = "qwen4exp_expert_source_bank/qwen4_exp_artifact.rs"] mod qwen4_exp_artifact; -#[allow(unused_imports)] -pub use qwen4_exp_artifact::*; -#[path = "qwen4exp_expert_source_bank/resident_expert_bank_lease.rs"] mod resident_expert_bank_lease; -#[allow(unused_imports)] -pub use resident_expert_bank_lease::*; diff --git a/crates/model-format/src/qwen4exp_digest_capture.rs b/crates/model-format/src/qwen4exp/expert_source_bank/digest_capture.rs similarity index 76% rename from crates/model-format/src/qwen4exp_digest_capture.rs rename to crates/model-format/src/qwen4exp/expert_source_bank/digest_capture.rs index 5a6a6553..67d7eb31 100644 --- a/crates/model-format/src/qwen4exp_digest_capture.rs +++ b/crates/model-format/src/qwen4exp/expert_source_bank/digest_capture.rs @@ -49,26 +49,12 @@ struct IncrementalCapture { test_available: Option, } #[cfg(test)] -#[path = "qwen4exp_digest_capture_incremental_sdet.rs"] mod incremental_sdet; -#[path = "qwen4exp_digest_capture/capture_admit.rs"] mod capture_admit; -#[allow(unused_imports)] pub use capture_admit::*; -#[path = "qwen4exp_digest_capture/provisional_expert_source.rs"] mod provisional_expert_source; -#[allow(unused_imports)] pub use provisional_expert_source::*; -#[path = "qwen4exp_digest_capture/qwen4_exp_artifact.rs"] mod qwen4_exp_artifact; -#[allow(unused_imports)] -pub use qwen4_exp_artifact::*; -#[path = "qwen4exp_digest_capture/provisional_expert_source_incremental.rs"] mod provisional_expert_source_incremental; -#[allow(unused_imports)] -pub use provisional_expert_source_incremental::*; -#[path = "qwen4exp_digest_capture/provisional_expert_source_test_hooks.rs"] mod provisional_expert_source_test_hooks; -#[allow(unused_imports)] -pub use provisional_expert_source_test_hooks::*; diff --git a/crates/model-format/src/qwen4exp_digest_capture/capture_admit.rs b/crates/model-format/src/qwen4exp/expert_source_bank/digest_capture/capture_admit.rs similarity index 90% rename from crates/model-format/src/qwen4exp_digest_capture/capture_admit.rs rename to crates/model-format/src/qwen4exp/expert_source_bank/digest_capture/capture_admit.rs index 64c84e8f..dd5b5122 100644 --- a/crates/model-format/src/qwen4exp_digest_capture/capture_admit.rs +++ b/crates/model-format/src/qwen4exp/expert_source_bank/digest_capture/capture_admit.rs @@ -1,5 +1,5 @@ -//! Functions: `capture_admit`, `expert_tensor_name`, `provisional_descriptor`. -//! Split out of `digest_capture` to keep its files under the line limit. +//! Admission and naming for provisional expert capture: the memory check against the source cap and headroom, +//! the GGUF name of a routed-expert tensor per role, and the checked bank descriptor built from the tensor index. use super::{ BankDescriptor, FUTURE_HEADROOM, LayerRole, ResidentExpertSourceError, ResolvedTensor, SOURCE_CAP, TensorIndex, diff --git a/crates/model-format/src/qwen4exp_digest_capture_incremental_sdet.rs b/crates/model-format/src/qwen4exp/expert_source_bank/digest_capture/incremental_sdet.rs similarity index 100% rename from crates/model-format/src/qwen4exp_digest_capture_incremental_sdet.rs rename to crates/model-format/src/qwen4exp/expert_source_bank/digest_capture/incremental_sdet.rs diff --git a/crates/model-format/src/qwen4exp_digest_capture/provisional_expert_source.rs b/crates/model-format/src/qwen4exp/expert_source_bank/digest_capture/provisional_expert_source.rs similarity index 97% rename from crates/model-format/src/qwen4exp_digest_capture/provisional_expert_source.rs rename to crates/model-format/src/qwen4exp/expert_source_bank/digest_capture/provisional_expert_source.rs index c9019177..9c43db05 100644 --- a/crates/model-format/src/qwen4exp_digest_capture/provisional_expert_source.rs +++ b/crates/model-format/src/qwen4exp/expert_source_bank/digest_capture/provisional_expert_source.rs @@ -1,5 +1,5 @@ -//! Methods of `ProvisionalExpertSource`: `empty`, `fail`, `geometry_failure`, `prepare` and 12 more. -//! Functions: `check_retained_kar`. +//! ProvisionalExpertSource: a non-readable capture of the routed-expert tensors while shard 0 is digested. Plans +//! cells under memory admission, copies observed chunks in file order, binds the verified file, checks retained KAR. use super::{ BANKS, Bank, BankDescriptor, BindingError, CapturedTensor, FUTURE_OWNERS, File, PINNED_IDENTITIES, diff --git a/crates/model-format/src/qwen4exp_digest_capture/provisional_expert_source_incremental.rs b/crates/model-format/src/qwen4exp/expert_source_bank/digest_capture/provisional_expert_source_incremental.rs similarity index 97% rename from crates/model-format/src/qwen4exp_digest_capture/provisional_expert_source_incremental.rs rename to crates/model-format/src/qwen4exp/expert_source_bank/digest_capture/provisional_expert_source_incremental.rs index 12d524bb..eb0f116f 100644 --- a/crates/model-format/src/qwen4exp_digest_capture/provisional_expert_source_incremental.rs +++ b/crates/model-format/src/qwen4exp/expert_source_bank/digest_capture/provisional_expert_source_incremental.rs @@ -1,5 +1,5 @@ -//! Methods of `ProvisionalExpertSource`: `prepare_incremental`, `prepare_incremental_inner`, `reserve_incremental_ce... -//! Methods of `Qwen4ExpArtifact`: `open_shard0_with_expert_capture_incremental`. +//! Incremental variant of the provisional expert capture: reserves cells and tables up front and lets them grow +//! as chunks arrive; also Qwen4ExpArtifact::open_shard0_with_expert_capture_incremental. use super::{ BANKS, Bank, BankDescriptor, CapturedTensor, FUTURE_OWNERS, File, IncrementalCapture, IncrementalTensor, diff --git a/crates/model-format/src/qwen4exp_digest_capture/provisional_expert_source_test_hooks.rs b/crates/model-format/src/qwen4exp/expert_source_bank/digest_capture/provisional_expert_source_test_hooks.rs similarity index 93% rename from crates/model-format/src/qwen4exp_digest_capture/provisional_expert_source_test_hooks.rs rename to crates/model-format/src/qwen4exp/expert_source_bank/digest_capture/provisional_expert_source_test_hooks.rs index ca6cf52f..3a05d293 100644 --- a/crates/model-format/src/qwen4exp_digest_capture/provisional_expert_source_test_hooks.rs +++ b/crates/model-format/src/qwen4exp/expert_source_bank/digest_capture/provisional_expert_source_test_hooks.rs @@ -1,5 +1,5 @@ -//! Methods of `ProvisionalExpertSource`: `test_incremental_cells`, `test_remaining_commitment`, `test_observe_inner`... -//! Split out of `digest_capture` to keep its files under the line limit. +//! Test-only constructors and probes of ProvisionalExpertSource for the incremental capture (cell setup, remaining +//! commitment, observe), so the capture tests can drive it without a full model. #[cfg(test)] use super::{ diff --git a/crates/model-format/src/qwen4exp_digest_capture/qwen4_exp_artifact.rs b/crates/model-format/src/qwen4exp/expert_source_bank/digest_capture/qwen4_exp_artifact.rs similarity index 98% rename from crates/model-format/src/qwen4exp_digest_capture/qwen4_exp_artifact.rs rename to crates/model-format/src/qwen4exp/expert_source_bank/digest_capture/qwen4_exp_artifact.rs index 7a80b74e..449c88d6 100644 --- a/crates/model-format/src/qwen4exp_digest_capture/qwen4_exp_artifact.rs +++ b/crates/model-format/src/qwen4exp/expert_source_bank/digest_capture/qwen4_exp_artifact.rs @@ -1,5 +1,5 @@ -//! Methods of `Qwen4ExpArtifact`: `open_shard0_with_expert_capture`, `adopt_resident_expert_capture`, `check_capture... -//! Methods of `ProvisionalExpertSource`: `test_cells`, `test_bytes`, `test_discarded`, `test_memory` and 1 more. +//! Artifact-side capture: open shard 0 with expert capture, revalidate every descriptor and adopt the capture as +//! retained resident banks at the bank boundary; also IncrementalCapture chunk appends and test-only helpers. use super::{ BANKS, Bank, BindingError, CapturedTensor, Cell, FUTURE_HEADROOM, FUTURE_OWNERS, File, IncrementalCapture, diff --git a/crates/model-format/src/qwen4exp_expert_source_bank/qwen4_exp_artifact.rs b/crates/model-format/src/qwen4exp/expert_source_bank/qwen4_exp_artifact.rs similarity index 97% rename from crates/model-format/src/qwen4exp_expert_source_bank/qwen4_exp_artifact.rs rename to crates/model-format/src/qwen4exp/expert_source_bank/qwen4_exp_artifact.rs index 79286493..a2eaf8dc 100644 --- a/crates/model-format/src/qwen4exp_expert_source_bank/qwen4_exp_artifact.rs +++ b/crates/model-format/src/qwen4exp/expert_source_bank/qwen4_exp_artifact.rs @@ -1,5 +1,5 @@ -//! Methods of `Qwen4ExpArtifact`: `load_resident_expert_source`, `check_expert_layout`, `plan_banks`, `load_banks` a... -//! Methods of `ResidentExpertBankLease`: `bank_count`, `source_bytes`, `charged_source_bytes`, `file_mapped` and 1 m... +//! Loading the resident expert source onto Qwen4ExpArtifact: layout check, bank plan, memory-admitted reads of all +//! 144 expert banks, report and publish, plus the low-RAM variant mapping banks read-only from shard 0. use super::{ BANKS, Bank, BankDescriptor, BindingError, Cell, FUTURE_HEADROOM, Qwen4ExpArtifact, Rc, ResidentExpertBank, diff --git a/crates/model-format/src/qwen4exp_expert_source_bank/resident_expert_bank_lease.rs b/crates/model-format/src/qwen4exp/expert_source_bank/resident_expert_bank_lease.rs similarity index 95% rename from crates/model-format/src/qwen4exp_expert_source_bank/resident_expert_bank_lease.rs rename to crates/model-format/src/qwen4exp/expert_source_bank/resident_expert_bank_lease.rs index ba3428cc..4d2f4447 100644 --- a/crates/model-format/src/qwen4exp_expert_source_bank/resident_expert_bank_lease.rs +++ b/crates/model-format/src/qwen4exp/expert_source_bank/resident_expert_bank_lease.rs @@ -1,5 +1,5 @@ -//! Methods of `Qwen4ExpArtifact`: `resident_expert_bank_lease`, `resident_expert_bank_member`. -//! Methods of `ResidentExpertBankSpan`: `bytes`, `offset`, `expert`, `role` and 3 more. Functions: `bank_directory_ok`. +//! Read-only lease on the resident expert banks: Qwen4ExpArtifact hands out a ResidentExpertBankLease or member +//! after rechecking the catalog and source, and ResidentExpertBankSpan exposes one expert's bytes and role. use super::{ BANKS, BindingError, LayerRole, Qwen4ExpArtifact, Rc, ResidentExpertBank, ResidentExpertBankLease, diff --git a/crates/model-format/src/qwen4exp_expert_source_bank/retention_metadata_bytes.rs b/crates/model-format/src/qwen4exp/expert_source_bank/retention_metadata_bytes.rs similarity index 97% rename from crates/model-format/src/qwen4exp_expert_source_bank/retention_metadata_bytes.rs rename to crates/model-format/src/qwen4exp/expert_source_bank/retention_metadata_bytes.rs index f473c1e2..14aa9090 100644 --- a/crates/model-format/src/qwen4exp_expert_source_bank/retention_metadata_bytes.rs +++ b/crates/model-format/src/qwen4exp/expert_source_bank/retention_metadata_bytes.rs @@ -1,5 +1,5 @@ -//! Methods of `ResidentExpertBank`: `note_copy`, `report`, `tensor`. -//! Implements `Display for ResidentExpertSourceError`, `Error for ResidentExpertSourceError`. +//! Support for resident expert banks: retention metadata size, error Display, checked bank descriptors and expert +//! shape/stride checks, the MemAvailable reading and admission, and the ResidentExpertBank report and tensor access. use super::{ BANKS, Bank, BankDescriptor, BindingError, Error, FUTURE_HEADROOM, File, LayerRole, Read, ResidentExpertBank, diff --git a/crates/model-format/src/qwen4exp_file_expert_source.rs b/crates/model-format/src/qwen4exp/file_expert_source.rs similarity index 100% rename from crates/model-format/src/qwen4exp_file_expert_source.rs rename to crates/model-format/src/qwen4exp/file_expert_source.rs diff --git a/crates/model-format/src/qwen4exp/plan_stream_rows.rs b/crates/model-format/src/qwen4exp/plan_stream_rows.rs index aa4eb501..8a3a63f3 100644 --- a/crates/model-format/src/qwen4exp/plan_stream_rows.rs +++ b/crates/model-format/src/qwen4exp/plan_stream_rows.rs @@ -1,5 +1,5 @@ -//! Methods of `RoutedMoeSourceScope`: `retarget`, `role`, `tensor`, `validate_descriptor` and 4 more. -//! Functions: `matrix_shape`, `layer_matrix_shape`, `global_matrix_shape`, `plan_stream_rows` and 1 more. +//! Whole-matrix streaming plan: a span of more than 64 rows is admitted only as one complete, known matrix +//! shape (table of role shapes), plus the byte-span arithmetic; also the scoped routed-MoE source loan for one expert. use super::{ BindingError, GlobalRole, LayerRole, ResidentExpertBankSpan, ResolvedTensor, RoutedMoeSourceScope, TensorRole, io, diff --git a/crates/model-format/src/qwen4exp/qwen4_exp_artifact.rs b/crates/model-format/src/qwen4exp/qwen4_exp_artifact.rs index 0be42dc2..3e98a2ba 100644 --- a/crates/model-format/src/qwen4exp/qwen4_exp_artifact.rs +++ b/crates/model-format/src/qwen4exp/qwen4_exp_artifact.rs @@ -1,5 +1,5 @@ -//! Methods of `Qwen4ExpArtifact`: `bind`, `bind_after_identity`, `topology`, `tokenizer` and 9 more. -//! Functions: `check_owner_split`, `read_profile_snapshots`. +//! Binding of the two pinned GGUF shards into a Qwen4ExpArtifact (identity, split and metadata checks), and its +//! read API: tensor lookup and streaming of rows, expert rows, whole matrices and the token embedding table. use super::{ BindingError, GlobalRole, LogicalShardView, MetadataSnapshot, PINNED_IDENTITIES, Qwen4ExpArtifact, diff --git a/crates/model-format/src/qwen4exp/routed_moe_source_opening.rs b/crates/model-format/src/qwen4exp/routed_moe_source_opening.rs index 25fa6119..ad3d9d29 100644 --- a/crates/model-format/src/qwen4exp/routed_moe_source_opening.rs +++ b/crates/model-format/src/qwen4exp/routed_moe_source_opening.rs @@ -1,5 +1,5 @@ -//! Methods of `Qwen4ExpArtifact`: `begin_routed_moe_source`. -//! Split out of `qwen4exp` to keep its files under the line limit. +//! Opens a scoped source loan (RoutedMoeSourceScope) for one routed expert of one layer, taken from shard 0 +//! with its source fence, so the expert matrices can be read under a single fence. use super::{BindingError, LayerRole, Qwen4ExpArtifact, RoutedMoeSourceScope, TensorRole}; diff --git a/crates/model-format/src/qwen4exp/validate_logical_views.rs b/crates/model-format/src/qwen4exp/validate_logical_views.rs index ee835ec5..21335667 100644 --- a/crates/model-format/src/qwen4exp/validate_logical_views.rs +++ b/crates/model-format/src/qwen4exp/validate_logical_views.rs @@ -1,5 +1,5 @@ -//! Functions: `validate_logical_views`, `check_split_numbers`, `check_tensor_counts`. -//! Split out of `qwen4exp` to keep its files under the line limit. +//! Cross-shard validation of the two logical shard views: split numbers and tensor counts, architecture, +//! topology, tokenizer and the tensor role inventory; yields the validated binding view. use super::{ BindingError, LogicalShardView, ValidatedBindingView, gguf, topology, validate_role_inventory, validate_tokenizer, diff --git a/crates/model-format/src/qwen4exp/validate_owner_index_split.rs b/crates/model-format/src/qwen4exp/validate_owner_index_split.rs index b3ee8267..33007200 100644 --- a/crates/model-format/src/qwen4exp/validate_owner_index_split.rs +++ b/crates/model-format/src/qwen4exp/validate_owner_index_split.rs @@ -1,5 +1,5 @@ -//! Functions: `validate_owner_index_split`, `validate_owner_metadata_split`, `required_uint`, `required_u32` and 11 ... -//! Split out of `qwen4exp` to keep its files under the line limit. +//! Pinned-profile metadata checks for the two shards: split numbers in index and metadata, required key readers, +//! the model topology read from metadata, and the special token ids of the tokenizer. use super::{BindingError, MetadataSnapshot, MetadataValue, Qwen4ExpTopology, TokenizerMetadata, VerifiedGgufFile}; diff --git a/crates/model-format/src/qwen4exp/validate_role_inventory.rs b/crates/model-format/src/qwen4exp/validate_role_inventory.rs index 612a5d52..36fa0033 100644 --- a/crates/model-format/src/qwen4exp/validate_role_inventory.rs +++ b/crates/model-format/src/qwen4exp/validate_role_inventory.rs @@ -1,5 +1,5 @@ -//! Functions: `validate_role_inventory`, `index_actual`, `resolve_tensor`, `check_tensor_geometry` and 8 more. -//! Defines `IndexedTensors`. +//! Matches the indexed tensors of both shards to the expected role inventory (shape, kind, byte size, file range, +//! no overlap) and plans exact single-row and row-tile byte spans inside a resolved tensor. use super::{ BTreeMap, BTreeSet, BindingError, ExpectedTensor, LogicalShardView, ResolvedTensor, TensorRole, expected_inventory, diff --git a/crates/model-format/src/qwen4exp/whole_dense_matrix_transport_tests.rs b/crates/model-format/src/qwen4exp/whole_dense_matrix_transport_tests.rs index cf9e58ec..c4def33f 100644 --- a/crates/model-format/src/qwen4exp/whole_dense_matrix_transport_tests.rs +++ b/crates/model-format/src/qwen4exp/whole_dense_matrix_transport_tests.rs @@ -1,5 +1,5 @@ -//! Functions: `two_byte_tensor`, `assert_partial_matrices_are_refused`, `assert_edited_tensor_is_refused`, `assert_p... -//! Split out of `qwen4exp` to keep its files under the line limit. +//! Tests that plan_stream_rows admits closed dense matrices (PLE tiles, whole matrices) with exact offsets and +//! refuses partial, expert-addressed or edited tensors. use super::*; diff --git a/crates/model-format/src/qwen4exp/whole_moe_matrix_sdet.rs b/crates/model-format/src/qwen4exp/whole_moe_matrix_sdet.rs index 85abc3f6..8a3597ad 100644 --- a/crates/model-format/src/qwen4exp/whole_moe_matrix_sdet.rs +++ b/crates/model-format/src/qwen4exp/whole_moe_matrix_sdet.rs @@ -1,5 +1,5 @@ -//! Functions: `complete_moe_spans_match_literal_legacy_tiles_and_refuse_boundary_crossing`, `check_layout`, `check_e... -//! Defines `Expected`. +//! Tests that complete MoE matrix spans equal the literal legacy 64-row tiles for every quantization layout +//! (routed and shared, gate/up and down), and that spans crossing a matrix boundary are refused. use super::*; diff --git a/crates/model-format/src/settings.rs b/crates/model-format/src/settings.rs index 24f8d322..da8e430e 100644 --- a/crates/model-format/src/settings.rs +++ b/crates/model-format/src/settings.rs @@ -1,11 +1,29 @@ -//! The only place of this crate that reads the process environment (`env-read` ratchet of `architecture.json`). -//! The reads keep their call sites and their parsing; a later step replaces these functions by a parsed settings value. +//! The only place of this crate that reads the process environment: the operator's load switches, as typed values. -use std::env::{self, VarError}; -use std::ffi::OsStr; +/// One of the `LELEKA_LOAD_*` variables of the bulk reader (`READ`, `THREADS`, `CHUNK_MIB`, `AHEAD_MIB`), as text. +pub(crate) fn load_variable(name: &str) -> Option { + std::env::var(name).ok() +} -/// `std::env::var`: the text of an environment variable. -#[inline] -pub(crate) fn var>(key: K) -> Result { - env::var(key) +/// `LELEKA_LOAD_READ=legacy`: keep the sequential read loop instead of the parallel bulk reader. +pub(crate) fn legacy_sequential_read() -> bool { + std::env::var("LELEKA_LOAD_READ").as_deref() == Ok("legacy") +} + +/// `LELEKA_HUGEPAGES` (`on | thp | off`), as text, when it is set to valid text. +pub(crate) fn huge_pages_text() -> Option { + std::env::var("LELEKA_HUGEPAGES").ok() +} + +/// `LELEKA_BANK_THP=on`: back the expert bank with transparent huge pages when `LELEKA_HUGEPAGES` says nothing. +pub(crate) fn bank_thp_on() -> bool { + std::env::var("LELEKA_BANK_THP").is_ok_and(|v| v == "on") +} + +/// `LELEKA_KAR_IDENTITY_RECHECK=off|0|no|false`: the per-read comparison with the verified file state is off. +pub(crate) fn kar_identity_recheck_disabled() -> bool { + std::env::var("LELEKA_KAR_IDENTITY_RECHECK") + .as_deref() + .map(str::trim) + .is_ok_and(|text| matches!(text, "off" | "0" | "no" | "false")) } diff --git a/crates/model-format/tests/kar_extents/builder_makes_archives.rs b/crates/model-format/tests/builder_makes_archives.rs similarity index 100% rename from crates/model-format/tests/kar_extents/builder_makes_archives.rs rename to crates/model-format/tests/builder_makes_archives.rs diff --git a/crates/model-format/tests/kar_extents.rs b/crates/model-format/tests/kar_extents.rs index 165db855..478a9792 100644 --- a/crates/model-format/tests/kar_extents.rs +++ b/crates/model-format/tests/kar_extents.rs @@ -364,5 +364,4 @@ fn standard_profile(bytes: &[u8]) -> KarPleProfile { KarPleProfile::with_total_rows(spec, 1777).unwrap() } -#[path = "kar_extents/builder_makes_archives.rs"] mod builder_makes_archives; diff --git a/crates/model-format/tests/qwen_artifact_binding/fixtures.rs b/crates/model-format/tests/qwen_artifact_binding/fixtures.rs index bc887437..ff433fad 100644 --- a/crates/model-format/tests/qwen_artifact_binding/fixtures.rs +++ b/crates/model-format/tests/qwen_artifact_binding/fixtures.rs @@ -52,17 +52,9 @@ struct MetadataLocation { } mod geometry; -#[allow(unused_imports)] pub use geometry::byte_len; -#[allow(unused_imports)] -pub use geometry::geometry; -#[allow(unused_imports)] -pub use geometry::index; -#[allow(unused_imports)] pub use geometry::logical_indexes; mod metadata; -#[allow(unused_imports)] pub use metadata::metadata; -#[allow(unused_imports)] use metadata::string; mod tiny_owner; diff --git a/crates/native-cpu-expert/src/cpu_pool.rs b/crates/native-cpu-expert/src/cpu_pool.rs index 806387cc..b647cdba 100644 --- a/crates/native-cpu-expert/src/cpu_pool.rs +++ b/crates/native-cpu-expert/src/cpu_pool.rs @@ -1,5 +1,5 @@ -//! Methods of `CpuPool`: `new`, `workers`, `charged_bytes`, `admit` and 1 more. Methods of `PendingBatch`: `join`. -//! Implements `Drop for PendingBatch`, `Drop for CpuPool`. Functions: `actor_main`, `serve`. +//! CpuPool: a single actor thread that owns the native expert pool and serves one batch of prepared jobs at a time +//! over channels; PendingBatch joins the result, and either type's drop drains or stops the native workers safely. use super::{ CompletedJob, CpuPool, Error, MAX_BATCH_BYTES, MAX_JOBS, PendingBatch, PhantomData, PreparedJob, Result, ffi, mpsc, diff --git a/crates/native-cpu-expert/src/gate_up_format.rs b/crates/native-cpu-expert/src/gate_up_format.rs index 9dcd172e..3334fd62 100644 --- a/crates/native-cpu-expert/src/gate_up_format.rs +++ b/crates/native-cpu-expert/src/gate_up_format.rs @@ -1,5 +1,5 @@ -//! Methods of `GateUpFormat`: `kind`, `matrix_bytes`, `block`. -//! Methods of `DownFormat`: `kind`, `matrix_bytes`, `block`. Implements `Drop for DirectCpuPool`. +//! Expert job data for the CPU pool: gate/up and down format codes with block sizes, input and header checks, the +//! concatenated G|U|D blob in PreparedJob, and DirectCpuPool, which computes or prefetches a group of experts directly. use super::{ BorrowedExpert, BorrowedGroup, CompletedJob, DirectCpuPool, DownFormat, Error, ExpertBytes, ExpertFormats, FF, diff --git a/crates/native-cpu-expert/src/rust_bench_frontend.rs b/crates/native-cpu-expert/src/rust_bench_frontend.rs index 9454223d..db1d17f4 100644 --- a/crates/native-cpu-expert/src/rust_bench_frontend.rs +++ b/crates/native-cpu-expert/src/rust_bench_frontend.rs @@ -10,9 +10,7 @@ use std::{ ffi::{CString, c_char, c_int, c_void}, time::Instant, }; -#[path = "rust_bench_gpu.rs"] pub mod gpu; -#[path = "rust_bench_model.rs"] mod model; use gpu::ParityGpu; unsafe extern "C" { @@ -85,48 +83,25 @@ const USAGE: &str = concat!( ); mod numerical; -#[allow(unused_imports)] use numerical::bits; -#[allow(unused_imports)] use numerical::dot; -#[allow(unused_imports)] use numerical::elapsed; -#[allow(unused_imports)] use numerical::ggml_rows; -#[allow(unused_imports)] use numerical::iq4nl_hq; -#[allow(unused_imports)] use numerical::name; -#[allow(unused_imports)] use numerical::native_fmt; -#[allow(unused_imports)] use numerical::numerical; -#[allow(unused_imports)] use numerical::outputs; -#[allow(unused_imports)] use numerical::refs; -#[allow(unused_imports)] use numerical::rel; -#[allow(unused_imports)] use numerical::type_of; -#[allow(unused_imports)] use numerical::zeros; mod cpu_blob; -#[allow(unused_imports)] use cpu_blob::cpu_blob; mod float_reference; -#[allow(unused_imports)] use float_reference::check_bf16; -#[allow(unused_imports)] use float_reference::check_blob; -#[allow(unused_imports)] use float_reference::check_q5_one; -#[allow(unused_imports)] -use float_reference::float_reference; mod parity_run; -#[allow(unused_imports)] pub use parity_run::run; -#[allow(unused_imports)] -use parity_run::run_modes; -#[allow(unused_imports)] pub use parity_run::unbound_main; diff --git a/crates/native-cpu-expert/src/rust_bench_frontend/cpu_blob.rs b/crates/native-cpu-expert/src/rust_bench_frontend/cpu_blob.rs index e468135c..51a5b705 100644 --- a/crates/native-cpu-expert/src/rust_bench_frontend/cpu_blob.rs +++ b/crates/native-cpu-expert/src/rust_bench_frontend/cpu_blob.rs @@ -1,5 +1,5 @@ -//! Methods of `Case`: `new`, `gate_up`, `down`. -//! Functions: `quantize_acts`, `cpu_blob`, `iq_gate_up`, `time_ggml_gu` and 15 more. Defines `Fail`, `Case`, `KqCase`. +//! CPU side of the expert benchmark on one blob: quantizes the activations, runs gate/up and down, and checks the +//! native kernels against the ggml reference for width invariance and K-quant/IQ routes, timing both for the report. use super::{ FF, H, Instant, Kind, NT, NativeActivation, NativeFormat, bench, bits, c_int, cpu, dot, elapsed, ggml_rows, diff --git a/crates/native-cpu-expert/src/rust_bench_frontend/float_reference.rs b/crates/native-cpu-expert/src/rust_bench_frontend/float_reference.rs index fdd44937..10df2ae8 100644 --- a/crates/native-cpu-expert/src/rust_bench_frontend/float_reference.rs +++ b/crates/native-cpu-expert/src/rust_bench_frontend/float_reference.rs @@ -1,5 +1,5 @@ -//! Functions: `float_reference`, `reference_shapes_ok`, `swiglu_hidden`, `project_down` and 21 more. Defines `Fail`. -//! Split out of `rust_bench_frontend` to keep its files under the line limit. +//! Reference and parity checks of the expert benchmark: an f64 float reference of one expert, the CPU-vs-GPU checks +//! of a blob (dequantizers, old kernels, embedding rows), plus the Q5_1 stored-sum case and the BF16 gather case. use super::{ CString, Error, FF, H, Kind, NT, NativeFormat, ParityGpu, Q81Owner, Result, bench, bits, cpu, cpu_blob, name, diff --git a/crates/native-cpu-expert/src/rust_bench_gpu.rs b/crates/native-cpu-expert/src/rust_bench_frontend/gpu.rs similarity index 100% rename from crates/native-cpu-expert/src/rust_bench_gpu.rs rename to crates/native-cpu-expert/src/rust_bench_frontend/gpu.rs diff --git a/crates/native-cpu-expert/src/rust_bench_model.rs b/crates/native-cpu-expert/src/rust_bench_frontend/model.rs similarity index 99% rename from crates/native-cpu-expert/src/rust_bench_model.rs rename to crates/native-cpu-expert/src/rust_bench_frontend/model.rs index 078a98c8..e5ccfce3 100644 --- a/crates/native-cpu-expert/src/rust_bench_model.rs +++ b/crates/native-cpu-expert/src/rust_bench_frontend/model.rs @@ -85,7 +85,6 @@ impl Drop for Mapping { } } } -#[path = "rust_bench_model/cursor.rs"] mod cursor; use cursor::{Cursor, copy}; struct Tensor { diff --git a/crates/native-cpu-expert/src/rust_bench_model/cursor.rs b/crates/native-cpu-expert/src/rust_bench_frontend/model/cursor.rs similarity index 100% rename from crates/native-cpu-expert/src/rust_bench_model/cursor.rs rename to crates/native-cpu-expert/src/rust_bench_frontend/model/cursor.rs diff --git a/crates/native-cpu-expert/src/rust_bench_frontend/numerical.rs b/crates/native-cpu-expert/src/rust_bench_frontend/numerical.rs index c4a04d1c..87b6d5f0 100644 --- a/crates/native-cpu-expert/src/rust_bench_frontend/numerical.rs +++ b/crates/native-cpu-expert/src/rust_bench_frontend/numerical.rs @@ -1,5 +1,5 @@ -//! Functions: `numerical`, `zeros`, `refs`, `outputs` and 11 more. -//! Split out of `rust_bench_frontend` to keep its files under the line limit. +//! Small shared helpers of the expert benchmark: error mapping, zeroed allocations, relative and bit-level +//! comparisons, format and kernel-name lookup, the ggml and IQ4_NL row dots, and elapsed-time per iteration. use super::{CString, Error, FF, H, Instant, Kind, NAMES, NT, NativeActivation, NativeFormat, Result, bench, cpu}; diff --git a/crates/native-cpu-expert/src/rust_dequant/iq.rs b/crates/native-cpu-expert/src/rust_dequant/iq.rs index 33e98548..5d373fbe 100644 --- a/crates/native-cpu-expert/src/rust_dequant/iq.rs +++ b/crates/native-cpu-expert/src/rust_dequant/iq.rs @@ -1,5 +1,5 @@ -//! Methods of `Iq2Group`: `lane`. Methods of `Iq3Group`: `sign`, `grid`. -//! Functions: `block`, `iq2_group`, `iq2`, `iq3_group` and 6 more. Defines `Iq2Group`, `Iq3Group`. +//! Scalar block dequantizers of the IQ family (IQ1, IQ2, IQ3, IQ4_NL, IQ4_XS), used as the exact float oracle +//! of the benchmark; each follows the pinned GGML to_float code, separate from the quantized dot accumulation. use super::{h, u16at, u32at}; use crate::rust_codebooks::*; use crate::rust_ggml::Kind; diff --git a/crates/native-cpu-expert/src/rust_dequant/kquant.rs b/crates/native-cpu-expert/src/rust_dequant/kquant.rs index bd28ba9b..924f130e 100644 --- a/crates/native-cpu-expert/src/rust_dequant/kquant.rs +++ b/crates/native-cpu-expert/src/rust_dequant/kquant.rs @@ -1,5 +1,5 @@ -//! Functions: `block`, `q2k`, `q3k`, `q45k` and 4 more. -//! the K-quant and ternary block formats. +//! Scalar block dequantizers of the K-quant (Q2_K to Q6_K) and ternary (TQ1, TQ2) formats, used as the exact +//! float oracle of the benchmark; each follows the pinned GGML to_float code, apart from quantized dot accumulation. use super::{h, k4, six}; use crate::rust_ggml::Kind; pub(super) fn block(kind: Kind, x: &[u8], y: &mut [f32]) { diff --git a/crates/native-cpu-expert/src/rust_dequant/plain.rs b/crates/native-cpu-expert/src/rust_dequant/plain.rs index 40f811bb..f05eeb17 100644 --- a/crates/native-cpu-expert/src/rust_dequant/plain.rs +++ b/crates/native-cpu-expert/src/rust_dequant/plain.rs @@ -1,5 +1,5 @@ -//! Functions: `block`, `q1_zero`, `q2_zero`, `q458` and 3 more. -//! the legacy, 4/5/8-bit and FP4 block formats. +//! Scalar block dequantizers of the plain formats (F32, F16, BF16, the 1/2/4/5/8-bit legacy blocks and MXFP4/NVFP4), +//! used as the exact float oracle of the benchmark; each follows the pinned GGML to_float code. use super::{FP4, e8_half, h, u16at, u32at, ue4}; use crate::rust_ggml::Kind; pub(super) fn block(kind: Kind, x: &[u8], y: &mut [f32]) { diff --git a/crates/native-cpu-expert/src/rust_general_pool.rs b/crates/native-cpu-expert/src/rust_general_pool.rs index 26d3620e..bdfdd016 100644 --- a/crates/native-cpu-expert/src/rust_general_pool.rs +++ b/crates/native-cpu-expert/src/rust_general_pool.rs @@ -111,13 +111,9 @@ pub struct ExpertPool { mod exec; mod job_default; -#[allow(unused_imports)] use job_default::alloc_with; -#[allow(unused_imports)] use job_default::cells; -#[allow(unused_imports)] pub use job_default::install_release_gpu_waits; -#[allow(unused_imports)] use job_default::now_ms; mod epoch_scheduling; mod expert_pool; diff --git a/crates/native-cpu-expert/src/rust_general_pool/expert_pool.rs b/crates/native-cpu-expert/src/rust_general_pool/expert_pool.rs index 02e1d39f..e12e2b4f 100644 --- a/crates/native-cpu-expert/src/rust_general_pool/expert_pool.rs +++ b/crates/native-cpu-expert/src/rust_general_pool/expert_pool.rs @@ -1,5 +1,5 @@ -//! Methods of `ExpertPool`: `new`, `assemble`, `worker_count`, `new_shared` and 14 more. -//! Split out of `rust_general_pool` to keep its files under the line limit. +//! Construction and bookkeeping of the general expert pool: CPU topology and worker count, shared state, worker threads +//! with optional core pinning, byte and timing diagnostics, the phase barrier, and whole-expert and planar run entries. use super::{ Arc, AtomicBool, AtomicI32, AtomicI64, AtomicU32, AtomicU64, Batch, Condvar, CpuTopology, Diagnostic, Duration, diff --git a/crates/native-cpu-expert/src/rust_general_pool/expert_pool_split_multi_run.rs b/crates/native-cpu-expert/src/rust_general_pool/expert_pool_split_multi_run.rs index e34b585b..34f0a040 100644 --- a/crates/native-cpu-expert/src/rust_general_pool/expert_pool_split_multi_run.rs +++ b/crates/native-cpu-expert/src/rust_general_pool/expert_pool_split_multi_run.rs @@ -1,5 +1,5 @@ -//! Methods of `ExpertPool`: `split_headers`, `split_run`, `quantize_single`, `planar_multi_header` and 8 more. -//! Implements `Drop for ExpertPool`. +//! Two-phase split runs of the general expert pool: gate/up, requantize, then down, for single- and multi-token +//! planar and native-format experts, built from validated job headers; also stops and joins the workers on drop. use super::{Error, ExpertPool, FF, H, Instant, Job, NativeFormat, NativeJobMulti, Ordering, PlanarJobMulti, Result}; diff --git a/crates/native-cpu-expert/src/rust_general_pool/job_default.rs b/crates/native-cpu-expert/src/rust_general_pool/job_default.rs index 9634293e..afa731eb 100644 --- a/crates/native-cpu-expert/src/rust_general_pool/job_default.rs +++ b/crates/native-cpu-expert/src/rust_general_pool/job_default.rs @@ -1,5 +1,5 @@ -//! Implements `Default for Job`, `Default for Split` and 3 more. -//! Functions: `alloc_with`, `cells`, `install_release_gpu_waits`, `now_ms`. +//! Defaults of the pool's raw job and scratch types, the Send/Sync claim for Shared with its safety argument, +//! and small helpers: fallible zeroed allocation, the GPU-wait release hook and a process-relative millisecond clock. use super::{ Error, FF, Instant, Job, OnceLock, PlanarActivation, RELEASE_GPU_WAITS, Result, Shared, SingleSplit, Split, diff --git a/crates/native-cpu-expert/src/rust_general_pool/shared_wait_done_and_quantize_lanes.rs b/crates/native-cpu-expert/src/rust_general_pool/shared_wait_done_and_quantize_lanes.rs index 3dcd0d98..17b4e064 100644 --- a/crates/native-cpu-expert/src/rust_general_pool/shared_wait_done_and_quantize_lanes.rs +++ b/crates/native-cpu-expert/src/rust_general_pool/shared_wait_done_and_quantize_lanes.rs @@ -1,5 +1,5 @@ -//! Methods of `Shared`: `wait_done`, `quantize_lanes`. Functions: `quantize_native_lane`. -//! Split out of `rust_general_pool` to keep its files under the line limit. +//! Shared pool state helpers: a spin wait for workers to finish (with a stall report after 60 s) and the requantization +//! of every lane's gate/up output into the down-phase activation, for native and planar formats. use super::{Duration, Instant, Job, NativeFormat, Ordering, Result, Shared, Split}; diff --git a/crates/native-cpu-expert/src/rust_ggml.rs b/crates/native-cpu-expert/src/rust_ggml.rs index 6106d251..ed3106b8 100644 --- a/crates/native-cpu-expert/src/rust_ggml.rs +++ b/crates/native-cpu-expert/src/rust_ggml.rs @@ -125,23 +125,13 @@ mod tests { } mod kind; -#[allow(unused_imports)] -use kind::alloc; -#[allow(unused_imports)] use kind::bf16_bits; mod native_format; -#[allow(unused_imports)] pub use native_format::dot; -#[allow(unused_imports)] use native_format::float_dot; -#[allow(unused_imports)] use native_format::iq4nl_dot; -#[allow(unused_imports)] use native_format::q1_dot; -#[allow(unused_imports)] use native_format::q2_generic; mod quantize_raw; -#[allow(unused_imports)] pub(super) use quantize_raw::dot_raw; -#[allow(unused_imports)] pub(super) use quantize_raw::quantize_raw; diff --git a/crates/native-cpu-expert/src/rust_ggml/kind.rs b/crates/native-cpu-expert/src/rust_ggml/kind.rs index 58610978..39f89de4 100644 --- a/crates/native-cpu-expert/src/rust_ggml/kind.rs +++ b/crates/native-cpu-expert/src/rust_ggml/kind.rs @@ -1,5 +1,5 @@ -//! Methods of `Kind`: `from_original`, `original_id`, `block`, `row_bytes` and 3 more. Methods of `ActKind`: `bytes`. -//! Functions: `alloc`, `store_f16`, `bf16_bits`, `store_bf16` and 1 more. +//! Quantization kinds of the GGML-compatible CPU path: ids, block geometry and row sizes of each Kind, its activation +//! encoding, and the owned f32/f16/bf16 activation storage built from float input by Activation::quantize. use super::{ActKind, Activation, Error, Kind, Result, Storage, to_half}; diff --git a/crates/native-cpu-expert/src/rust_ggml/native_format.rs b/crates/native-cpu-expert/src/rust_ggml/native_format.rs index 0c203d04..4fa0edb2 100644 --- a/crates/native-cpu-expert/src/rust_ggml/native_format.rs +++ b/crates/native-cpu-expert/src/rust_ggml/native_format.rs @@ -1,5 +1,5 @@ -//! Methods of `NativeFormat`: `offsets`, `new`, `validate`. -//! Functions: `iq4nl_dot`, `dot_zero`, `dot_k`, `dot` and 8 more. +//! NativeFormat (a gate/up plus down kind pair with its blob layout and shape checks) and the AVX2 row dot +//! kernels against Q8_0-style, Q8_K and float activations (IQ4_NL, Q1, Q2 too), with the dispatching dot entry point. use super::{ __m256, _mm_loadu_si128, _mm256_add_ps, _mm256_castsi256_ps, _mm256_cvtepi32_ps, _mm256_cvtepu16_epi32, diff --git a/crates/native-cpu-expert/src/rust_ggml/quantize_raw.rs b/crates/native-cpu-expert/src/rust_ggml/quantize_raw.rs index 28c10431..71bbc688 100644 --- a/crates/native-cpu-expert/src/rust_ggml/quantize_raw.rs +++ b/crates/native-cpu-expert/src/rust_ggml/quantize_raw.rs @@ -1,5 +1,5 @@ -//! Functions: `raw_align`, `quantize_half_raw`, `quantize_raw`, `dot_raw_zero` and 2 more. -//! Split out of `rust_ggml` to keep its files under the line limit. +//! Raw-buffer entry points of the GGML CPU path: quantize a float row into a caller-provided encoded activation +//! buffer, and compute a weight-row dot against an already encoded one, with the alignment and extent checks. use super::{ActKind, Kind, Q8K, Q8One, Q8Zero, bf16_bits, float_dot, iq4nl_dot, q1_dot, q2_generic, to_half}; diff --git a/crates/native-cpu-expert/src/rust_iq.rs b/crates/native-cpu-expert/src/rust_iq.rs index bcc379cf..fbb2080b 100644 --- a/crates/native-cpu-expert/src/rust_iq.rs +++ b/crates/native-cpu-expert/src/rust_iq.rs @@ -8,43 +8,21 @@ use std::arch::x86_64::*; mod tests; mod u16; -#[allow(unused_imports)] use u16::decode; -#[allow(unused_imports)] use u16::decoded; -#[allow(unused_imports)] pub(super) use u16::dot_multi256; -#[allow(unused_imports)] pub(super) use u16::dot_multi512; -#[allow(unused_imports)] -use u16::dot_multi512_tn; -#[allow(unused_imports)] use u16::factor; -#[allow(unused_imports)] pub(super) use u16::format_bytes; -#[allow(unused_imports)] use u16::iq3_half; -#[allow(unused_imports)] -use u16::iq3_multi_fast; -#[allow(unused_imports)] use u16::u16; -#[allow(unused_imports)] -use u16::u32; mod dot_multi512; -#[allow(unused_imports)] use dot_multi512::dot_multi512_impl; -#[allow(unused_imports)] pub(super) use dot_multi512::dot_single; -#[allow(unused_imports)] +#[cfg(test)] use dot_multi512::dot_single_generic; -#[allow(unused_imports)] +#[cfg(test)] use dot_multi512::dot_single_iq3; -#[allow(unused_imports)] -use dot_multi512::iq3_single_fast; -#[allow(unused_imports)] pub(super) use dot_multi512::iq4nl; -#[allow(unused_imports)] -use dot_multi512::iq4xs; mod iq4nl_n; -#[allow(unused_imports)] use iq4nl_n::iq4nl_n; diff --git a/crates/native-cpu-expert/src/rust_iq/iq4nl_n.rs b/crates/native-cpu-expert/src/rust_iq/iq4nl_n.rs index d0e72ada..abd6eaaf 100644 --- a/crates/native-cpu-expert/src/rust_iq/iq4nl_n.rs +++ b/crates/native-cpu-expert/src/rust_iq/iq4nl_n.rs @@ -1,5 +1,5 @@ -//! Functions: `iq4nl_values`, `iq4nl_block`, `iq4nl_alternating`, `iq4nl_n`. -//! Split out of `rust_iq` to keep its files under the line limit. +//! AVX2 IQ4_NL row kernel for one to N tokens: decodes each block's codebook values once and accumulates per token, +//! in the exact GGML single-token or the original multi-token order, so results match the reference bit for bit. use super::{ __m128i, __m256, __m256i, _mm_and_si128, _mm_loadu_si128, _mm_set1_epi8, _mm_shuffle_epi8, _mm_srli_epi16, diff --git a/crates/native-cpu-expert/src/rust_iq/tests.rs b/crates/native-cpu-expert/src/rust_iq/tests.rs index 787476c5..6188edd6 100644 --- a/crates/native-cpu-expert/src/rust_iq/tests.rs +++ b/crates/native-cpu-expert/src/rust_iq/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of `rust_iq`. +//! Tests that pin the IQ kernels: IQ3 single- and multi-token summation trees are bitwise equal, the AVX2 IQ4_XS +//! multi-token kernel matches a scalar model of the original row_dot bit for bit, plus a timing bench for IQ3. use super::super::rust_quant::q8_k; use super::*; diff --git a/crates/native-cpu-expert/src/rust_iq/u16.rs b/crates/native-cpu-expert/src/rust_iq/u16.rs index e064d7b9..de895a1e 100644 --- a/crates/native-cpu-expert/src/rust_iq/u16.rs +++ b/crates/native-cpu-expert/src/rust_iq/u16.rs @@ -1,5 +1,5 @@ -//! Functions: `u16`, `u32`, `format_bytes`, `factor` and 17 more. -//! Split out of `rust_iq` to keep its files under the line limit. +//! Shared decoding of IQ-format weight blocks for the AVX2/AVX-512 IQ dot kernels: byte readers, block sizes, +//! per-format sign/grid/scale decode, and the multi-token IQ kernel specialised per format and token count. use super::{ __m256i, _mm_loadl_epi64, _mm256_add_epi32, _mm256_and_si256, _mm256_cvtepi32_ps, _mm256_cvtepu8_epi32, diff --git a/crates/native-cpu-expert/src/rust_legacy.rs b/crates/native-cpu-expert/src/rust_legacy.rs index 2cf586b2..df7800bb 100644 --- a/crates/native-cpu-expert/src/rust_legacy.rs +++ b/crates/native-cpu-expert/src/rust_legacy.rs @@ -34,46 +34,22 @@ pub(super) struct SingleScratch { mod tests; mod set_oracle_q8_zero; -#[allow(unused_imports)] -use set_oracle_q8_zero::dot32; -#[allow(unused_imports)] pub(super) use set_oracle_q8_zero::half; -#[allow(unused_imports)] pub(super) use set_oracle_q8_zero::legacy_supported; -#[allow(unused_imports)] pub use set_oracle_q8_zero::oracle_q8_zero_enabled; -#[allow(unused_imports)] use set_oracle_q8_zero::row; -#[allow(unused_imports)] -use set_oracle_q8_zero::row_oracle; -#[allow(unused_imports)] +#[cfg(test)] use set_oracle_q8_zero::row256; -#[allow(unused_imports)] -use set_oracle_q8_zero::row512; -#[allow(unused_imports)] pub use set_oracle_q8_zero::set_oracle_q8_zero; -#[allow(unused_imports)] -use set_oracle_q8_zero::unpack32; mod pair_rows; -#[allow(unused_imports)] use pair_rows::{GateUpOut, act_refs, down_row, gate_up_pair}; mod admit; -#[allow(unused_imports)] -use admit::admit; -#[allow(unused_imports)] pub use admit::down_rows; -#[allow(unused_imports)] pub use admit::expert; -#[allow(unused_imports)] pub use admit::expert_quantized; -#[allow(unused_imports)] pub use admit::expert_scalar; -#[allow(unused_imports)] pub use admit::gate_up_rows; mod gate_each; -#[allow(unused_imports)] pub(super) use gate_each::down_each; -#[allow(unused_imports)] pub(super) use gate_each::gate_each; -#[allow(unused_imports)] pub(super) use gate_each::whole_single; diff --git a/crates/native-cpu-expert/src/rust_legacy/admit.rs b/crates/native-cpu-expert/src/rust_legacy/admit.rs index 064d0472..8be3c190 100644 --- a/crates/native-cpu-expert/src/rust_legacy/admit.rs +++ b/crates/native-cpu-expert/src/rust_legacy/admit.rs @@ -1,5 +1,5 @@ -//! Functions: `admit`, `gate_up_rows`, `down_rows`, `admit_expert` and 9 more. Defines `RowSpace`. -//! Split out of `rust_legacy` to keep its files under the line limit. +//! Legacy planar expert entry points: row-range gate/up and down passes, the whole multi-token expert call, and +//! the scalar benchmark; each first admits blob size, row bounds, activation chunk count and CPU support. use super::{ ActQ, BLOB, D_CODES, D_SCALES, Error, FF, GU_SCALES, GateUpOut, H, MAX_ROWS, PlanarActivation, PlanarScratch, diff --git a/crates/native-cpu-expert/src/rust_legacy/gate_each.rs b/crates/native-cpu-expert/src/rust_legacy/gate_each.rs index 0b004880..afd06934 100644 --- a/crates/native-cpu-expert/src/rust_legacy/gate_each.rs +++ b/crates/native-cpu-expert/src/rust_legacy/gate_each.rs @@ -1,5 +1,5 @@ -//! Implements `Default for SingleScratch`. Functions: `gate_each`, `down_each`, `whole_single`. -//! Split out of `rust_legacy` to keep its files under the line limit. +//! Per-row callbacks of the legacy planar path (gate_each, down_each) that hand each result to a pool writer, plus +//! whole_single, the one-token whole-expert fallback with its scratch. use super::{ ActQ, FF, GateUpOut, MAX_ROWS, PlanarActivation, SingleScratch, act_refs, down_row, gate_up_pair, diff --git a/crates/native-cpu-expert/src/rust_legacy/set_oracle_q8_zero.rs b/crates/native-cpu-expert/src/rust_legacy/set_oracle_q8_zero.rs index 2a21a21d..a1f30b0b 100644 --- a/crates/native-cpu-expert/src/rust_legacy/set_oracle_q8_zero.rs +++ b/crates/native-cpu-expert/src/rust_legacy/set_oracle_q8_zero.rs @@ -1,5 +1,5 @@ -//! Methods of `PlanarActivation`: `quantize`, `quantize_oracle`, `quantize_native`. -//! Implements `Default for PlanarActivation`, `Default for PlanarScratch`. +//! Legacy planar CPU kernels: the oracle Q8 switch, CPUID/XCR0 admission, half-float decode, PlanarActivation +//! quantization and the AVX2/AVX-512 VNNI row dot leaves (row256, row512, oracle) over ternary expert rows. use super::{ __cpuid, __cpuid_count, __m256, __m256i, __m512, _mm_add_epi32, _mm_cvtsi128_si32, _mm_hadd_epi32, _mm_loadl_epi64, diff --git a/crates/native-cpu-expert/src/rust_legacy/tests.rs b/crates/native-cpu-expert/src/rust_legacy/tests.rs index 35f6b518..4f472d22 100644 --- a/crates/native-cpu-expert/src/rust_legacy/tests.rs +++ b/crates/native-cpu-expert/src/rust_legacy/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of `rust_legacy`. +//! Pins the legacy row leaves: rows longer than the 40-block activation are refused before any load, and the +//! row256 correction is one fused multiply-add, as in the pinned C++ reference. use super::*; use std::panic::{AssertUnwindSafe, catch_unwind}; diff --git a/crates/native-cpu-expert/src/rust_native_general.rs b/crates/native-cpu-expert/src/rust_native_general.rs index fa7f736d..e9ab7111 100644 --- a/crates/native-cpu-expert/src/rust_native_general.rs +++ b/crates/native-cpu-expert/src/rust_native_general.rs @@ -20,47 +20,25 @@ pub struct NativeActivation { mod tests; mod native_activation_quantize; -#[allow(unused_imports)] pub(super) use native_activation_quantize::group_dot; -#[allow(unused_imports)] pub(super) use native_activation_quantize::group_dot_bytes; -#[allow(unused_imports)] -use native_activation_quantize::group_dot_policy; -#[allow(unused_imports)] pub(super) use native_activation_quantize::gu_multi_route; -#[allow(unused_imports)] pub use native_activation_quantize::native_down_rows; -#[allow(unused_imports)] pub use native_activation_quantize::native_gu_rows; mod group_dot_bytes_policy; -#[allow(unused_imports)] use group_dot_bytes_policy::group_dot_bytes_policy; -#[allow(unused_imports)] pub use group_dot_bytes_policy::iq_gu_rows; -#[allow(unused_imports)] pub use group_dot_bytes_policy::iq_rows; -#[allow(unused_imports)] pub use group_dot_bytes_policy::kq_rows; -#[allow(unused_imports)] pub(super) use group_dot_bytes_policy::{DotPolicy, DotRoute, EncodedRow}; -#[allow(unused_imports)] pub use group_dot_bytes_policy::{EncodedRows, GateUpBlob}; -#[allow(unused_imports)] use group_dot_bytes_policy::{check_gu, check_rows, check_weights, kq_dot, store, typed}; mod iq4nl_rows; -#[allow(unused_imports)] pub use iq4nl_rows::cpu_avx2_ok; -#[allow(unused_imports)] pub use iq4nl_rows::cpu_avx512_ok; -#[allow(unused_imports)] pub use iq4nl_rows::iq_supported; -#[allow(unused_imports)] pub use iq4nl_rows::iq4nl_rows; -#[allow(unused_imports)] pub use iq4nl_rows::kq_gu_rows; -#[allow(unused_imports)] pub use iq4nl_rows::kq_supported; -#[allow(unused_imports)] pub use iq4nl_rows::native_experts_available; -#[allow(unused_imports)] pub use iq4nl_rows::q2_rows; diff --git a/crates/native-cpu-expert/src/rust_native_general/group_dot_bytes_policy.rs b/crates/native-cpu-expert/src/rust_native_general/group_dot_bytes_policy.rs index 5059b0fd..98726ee0 100644 --- a/crates/native-cpu-expert/src/rust_native_general/group_dot_bytes_policy.rs +++ b/crates/native-cpu-expert/src/rust_native_general/group_dot_bytes_policy.rs @@ -1,5 +1,5 @@ -//! Functions: `typed_bytes`, `typed`, `kq_dot`, `kq256_enabled` and 16 more. -//! Defines `EncodedRow`, `DotRoute`, `DotPolicy` and 2 more. +//! Kernel routing of a native expert row against up to eight activations (K-quant 256-bit env policy, IQ multi-token, +//! IQ4_NL, generic dot) plus the explicit kq_rows, iq_rows and iq_gu_rows benchmark entries and their admission checks. use super::{Error, Kind, NativeActivation, NativeFormat, Q8K, Q8One, Q8Zero, Result, gu_multi_route}; diff --git a/crates/native-cpu-expert/src/rust_native_general/iq4nl_rows.rs b/crates/native-cpu-expert/src/rust_native_general/iq4nl_rows.rs index 8cf7ae24..f5265ac6 100644 --- a/crates/native-cpu-expert/src/rust_native_general/iq4nl_rows.rs +++ b/crates/native-cpu-expert/src/rust_native_general/iq4nl_rows.rs @@ -1,5 +1,5 @@ -//! Functions: `admit_iq4nl`, `iq4nl_rows`, `native_experts_available`, `kq_supported` and 10 more. -//! Split out of `rust_native_general` to keep its files under the line limit. +//! Explicit row-range entry points for the IQ4_NL, K-quant gate/up and Q2 formats, the kind-support predicates and +//! the shape/CPU admission each performs before dispatching to the 256-bit or 512-bit leaves. use super::{ Error, Kind, NativeActivation, NativeFormat, Q8Zero, Result, check_gu, check_rows, check_weights, kq_dot, store, diff --git a/crates/native-cpu-expert/src/rust_native_general/native_activation_quantize.rs b/crates/native-cpu-expert/src/rust_native_general/native_activation_quantize.rs index a1613e89..5e197de8 100644 --- a/crates/native-cpu-expert/src/rust_native_general/native_activation_quantize.rs +++ b/crates/native-cpu-expert/src/rust_native_general/native_activation_quantize.rs @@ -1,5 +1,5 @@ -//! Methods of `NativeActivation`: `quantize`, `encoded_bytes`, `check`, `raw`. -//! Implements `Default for NativeActivation`. +//! NativeActivation quantization and shape check, the multi-token gate/up kernel choice (gu_multi_route), and the +//! native_gu_rows / native_down_rows entry points that run an expert row by row in groups of eight tokens. use super::{ DotPolicy, DotRoute, EncodedRow, Error, Kind, NativeActivation, NativeFormat, Result, check_gu, check_rows, diff --git a/crates/native-cpu-expert/src/rust_native_general/tests.rs b/crates/native-cpu-expert/src/rust_native_general/tests.rs index 5a07b2f5..1f6b2e89 100644 --- a/crates/native-cpu-expert/src/rust_native_general/tests.rs +++ b/crates/native-cpu-expert/src/rust_native_general/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of `rust_native_general`. +//! Pins the multi-token gate/up kernel choice (gu_multi_route follows native_expert.cpp) and that IQ4_XS gate/up on +//! the AVX2 tree matches the multi-token kernel row by row, re-running itself under forced AVX2 on AVX-512 CPUs. use super::super::rust_simd::{Dispatch, avx2_ok, avx512_ok}; use super::*; diff --git a/crates/native-cpu-expert/src/rust_pool.rs b/crates/native-cpu-expert/src/rust_pool.rs index d9d2e698..4326fcf0 100644 --- a/crates/native-cpu-expert/src/rust_pool.rs +++ b/crates/native-cpu-expert/src/rust_pool.rs @@ -90,13 +90,10 @@ pub(super) struct NativePool { mod exec; mod native_act_default; -#[allow(unused_imports)] use native_act_default::all_finite; -#[allow(unused_imports)] use native_act_default::allocated; mod epoch_scheduling; mod stage; -#[allow(unused_imports)] use epoch_scheduling::tasks_per_thread; mod native_pool; mod trace; diff --git a/crates/native-cpu-expert/src/rust_pool/native_act_default.rs b/crates/native-cpu-expert/src/rust_pool/native_act_default.rs index d1f14617..ca6895b0 100644 --- a/crates/native-cpu-expert/src/rust_pool/native_act_default.rs +++ b/crates/native-cpu-expert/src/rust_pool/native_act_default.rs @@ -1,5 +1,5 @@ -//! Implements `Default for NativeAct`, `Default for Scratch` and 4 more. Functions: `all_finite`, `allocated`. -//! Split out of `rust_pool` to keep its files under the line limit. +//! Default values of the native pool's plain data (activation, scratch, job, split buffers), the unsafe Send/Sync +//! contract of the shared epoch state, the finite-float scan all_finite and the fallible Vec allocator. use super::{ActQ, Error, FF, Job, MAX_ROWS, NativeAct, Q8K, Result, Scratch, Shared, SingleSplit}; diff --git a/crates/native-cpu-expert/src/rust_pool/native_pool.rs b/crates/native-cpu-expert/src/rust_pool/native_pool.rs index 68d228bc..1ce0c37d 100644 --- a/crates/native-cpu-expert/src/rust_pool/native_pool.rs +++ b/crates/native-cpu-expert/src/rust_pool/native_pool.rs @@ -1,5 +1,5 @@ -//! Methods of `NativePool`: `plan`, `new`, `new_shared`, `empty_batch` and 13 more. -//! Split out of `rust_pool` to keep its files under the line limit. +//! NativePool construction and two-phase dispatch: worker planning and spawn, publishing a phase epoch, batch +//! compute with host requantization between gate/up and down, timing/trace readout, and borrowed-matrix prefetch. use super::{ Arc, AtomicBool, AtomicU32, AtomicU64, Batch, Condvar, Duration, Error, FF, H, Instant, Job, Line, MAX_JOBS, diff --git a/crates/native-cpu-expert/src/rust_pool/native_pool_group_compute.rs b/crates/native-cpu-expert/src/rust_pool/native_pool_group_compute.rs index 47297c2b..25d149e2 100644 --- a/crates/native-cpu-expert/src/rust_pool/native_pool_group_compute.rs +++ b/crates/native-cpu-expert/src/rust_pool/native_pool_group_compute.rs @@ -1,5 +1,5 @@ -//! Methods of `NativePool`: `validate_group`, `group_shape`, `check_expert`, `claim_row` and 2 more. -//! Implements `Drop for NativePool`. +//! NativePool::compute_borrowed: runs a whole borrowed expert group straight into the caller's output rows after +//! validating shapes, extents and distinct output rows, and checking outputs finite; also stops workers on Drop. use super::{Error, H, Instant, MAX_JOBS, MAX_ROWS, NativeFmt, NativePool, Ordering, Result, all_finite}; diff --git a/crates/native-cpu-expert/src/rust_weight_iq.rs b/crates/native-cpu-expert/src/rust_weight_iq.rs index 26dd45c6..ac3e4295 100644 --- a/crates/native-cpu-expert/src/rust_weight_iq.rs +++ b/crates/native-cpu-expert/src/rust_weight_iq.rs @@ -31,43 +31,20 @@ unsafe extern "C" { } mod alloc; -#[allow(unused_imports)] -use alloc::alloc; -#[allow(unused_imports)] pub(super) use alloc::free; -#[allow(unused_imports)] use alloc::grid; -#[allow(unused_imports)] -use alloc::grid_kind; -#[allow(unused_imports)] pub(super) use alloc::init; -#[allow(unused_imports)] use alloc::put_h; -#[allow(unused_imports)] -use alloc::signs; -#[allow(unused_imports)] use alloc::totals; -#[allow(unused_imports)] use alloc::{CandidateStep, QuantTarget, quant_candidates}; mod iq2_xxs; -#[allow(unused_imports)] use iq2_xxs::iq2_xs; -#[allow(unused_imports)] use iq2_xxs::iq2_xxs; mod iq3; -#[allow(unused_imports)] -use iq3::compare_pair; -#[allow(unused_imports)] use iq3::iq2_s; -#[allow(unused_imports)] use iq3::iq3; -#[allow(unused_imports)] use iq3::pairs; mod grid; -#[allow(unused_imports)] use grid::iq1_s; mod iq1_m; -#[allow(unused_imports)] -use iq1_m::iq1_m; -#[allow(unused_imports)] pub(super) use iq1_m::row; diff --git a/crates/native-cpu-expert/src/rust_weight_iq/alloc.rs b/crates/native-cpu-expert/src/rust_weight_iq/alloc.rs index 9d23e767..d8aed3b5 100644 --- a/crates/native-cpu-expert/src/rust_weight_iq/alloc.rs +++ b/crates/native-cpu-expert/src/rust_weight_iq/alloc.rs @@ -1,5 +1,5 @@ -//! Methods of `Grid`: `new`, `index_points`, `neighbor_counts`, `distances` and 4 more. -//! Functions: `alloc`, `grid_kind`, `grid`, `init` and 6 more. Defines `QuantTarget`, `CandidateStep`. +//! Codebook Grid of the IQ quantizers: builds each grid's point table and nearest-neighbour lists for off-grid codes, +//! caches one Grid per quant kind (init/free), and holds the sign-split and candidate-resolve helpers they share. use super::{ Arc, CACHE, Error, Grid, KGRID_1BIT_2048, KGRID_2BIT_256, KGRID_2BIT_512, KGRID_2BIT_1024, KGRID_256, KGRID_512, diff --git a/crates/native-cpu-expert/src/rust_weight_iq/grid.rs b/crates/native-cpu-expert/src/rust_weight_iq/grid.rs index d83c13f0..fb4496de 100644 --- a/crates/native-cpu-expert/src/rust_weight_iq/grid.rs +++ b/crates/native-cpu-expert/src/rust_weight_iq/grid.rs @@ -1,5 +1,5 @@ -//! Methods of `Grid`: `resolve_one`, `best_neighbor`. -//! Functions: `point_error`, `abs_max`, `split_levels`, `flip_levels` and 8 more. Defines `Iq1Fit`. +//! IQ1_S block quantizer (split search over sorted values, scale refit, packed scales and group heads) with the +//! Grid point resolution (resolve_one, best_neighbor) and the level helpers it shares with IQ1_M. use super::alloc::{sum_sq, weights}; use super::{Error, Grid, Pair, Result, XM, XP, nearest, pairs, put_h}; diff --git a/crates/native-cpu-expert/src/rust_weight_iq/iq1_m.rs b/crates/native-cpu-expert/src/rust_weight_iq/iq1_m.rs index a503b3fe..6b3e1781 100644 --- a/crates/native-cpu-expert/src/rust_weight_iq/iq1_m.rs +++ b/crates/native-cpu-expert/src/rust_weight_iq/iq1_m.rs @@ -1,5 +1,5 @@ -//! Functions: `iq1_m`, `half_values`, `iq1_m_block`, `iq1_m_search` and 7 more. Defines `Iq1MFit`. -//! Split out of `rust_weight_iq` to keep its files under the line limit. +//! IQ1_M quantizer: per 16-value block split search and scale refit over the shift patterns, packed super-block +//! scales, and row(), the per-kind 256-value block dispatch for the IQ1/IQ2/IQ3 quantizers. use super::alloc::{sum_sq, weights}; use super::grid::{abs_max, flip_levels, split_levels}; diff --git a/crates/native-cpu-expert/src/rust_weight_iq/iq2_xxs.rs b/crates/native-cpu-expert/src/rust_weight_iq/iq2_xxs.rs index 3e8c6036..bd3bad46 100644 --- a/crates/native-cpu-expert/src/rust_weight_iq/iq2_xxs.rs +++ b/crates/native-cpu-expert/src/rust_weight_iq/iq2_xxs.rs @@ -1,5 +1,5 @@ -//! Functions: `iq2_xxs`, `iq2_xxs_finish`, `iq2_xxs_block`, `iq2_xxs_search` and 3 more. -//! Split out of `rust_weight_iq` to keep its files under the line limit. +//! IQ2_XXS and IQ2_XS quantizers: per-block scale search over candidate scales with sign bytes, then packing of +//! the scale levels and grid indices into the super-block. use super::alloc::{Block, Trial, fix_groups, flip, search_scale, sum_sq, vmax, weights}; use super::{CandidateStep, Grid, QuantTarget, Result, nearest, put_h, qp, quant_candidates, totals}; diff --git a/crates/native-cpu-expert/src/rust_weight_iq/iq3.rs b/crates/native-cpu-expert/src/rust_weight_iq/iq3.rs index ae09a9be..3730c0f8 100644 --- a/crates/native-cpu-expert/src/rust_weight_iq/iq3.rs +++ b/crates/native-cpu-expert/src/rust_weight_iq/iq3.rs @@ -1,5 +1,5 @@ -//! Methods of `Iq3Out`: `store`, `finish`. Functions: `iq3`, `iq3_block`, `iq2_s`, `iq2_s_finish` and 3 more. -//! Defines `Iq3Out`, `BlockFit`. +//! IQ3 (XXS/S) and IQ2_S quantizers sharing the Iq3Out packer, plus the value/index pair sort helpers (pairs, +//! compare_pair) used by the sorted-split searches. use super::alloc::{Block, Trial, fix_groups, flip, search_scale, sum_sq, vmax, weights}; use super::{Grid, Kind, Pair, Result, nearest, put_h, qsort}; diff --git a/crates/native-cpu-expert/src/rust_weight_quant.rs b/crates/native-cpu-expert/src/rust_weight_quant.rs index eab61b04..d173b1c5 100644 --- a/crates/native-cpu-expert/src/rust_weight_quant.rs +++ b/crates/native-cpu-expert/src/rust_weight_quant.rs @@ -7,65 +7,30 @@ const EPS: f32 = 1e-15; const FP4: [i8; 16] = [0, 1, 2, 3, 4, 6, 8, 12, 0, -1, -2, -3, -4, -6, -8, -12]; mod nearest; -#[allow(unused_imports)] use nearest::h; -#[allow(unused_imports)] use nearest::max_signed; -#[allow(unused_imports)] pub(super) use nearest::nearest; -#[allow(unused_imports)] use nearest::put_h; -#[allow(unused_imports)] use nearest::q3; -#[allow(unused_imports)] use nearest::qkx; -#[allow(unused_imports)] pub(super) use nearest::qx; -#[allow(unused_imports)] -use nearest::weight; mod qp; -#[allow(unused_imports)] use qp::e8_half; -#[allow(unused_imports)] use qp::pack_ue4; -#[allow(unused_imports)] use qp::pack4; -#[allow(unused_imports)] pub(super) use qp::qp; -#[allow(unused_imports)] use qp::small; -#[allow(unused_imports)] use qp::ue4; mod best_fp4; -#[allow(unused_imports)] -use best_fp4::best_fp4; -#[allow(unused_imports)] use best_fp4::fp4; -#[allow(unused_imports)] -use best_fp4::pack_k2; -#[allow(unused_imports)] -use best_fp4::pack_scale3; -#[allow(unused_imports)] use best_fp4::pack_scale4; -#[allow(unused_imports)] use best_fp4::q2k; -#[allow(unused_imports)] use best_fp4::q3k; -#[allow(unused_imports)] use best_fp4::ternary; -#[allow(unused_imports)] -use best_fp4::unpack_scale3; -#[allow(unused_imports)] use best_fp4::unpack_scale4; mod q45k; -#[allow(unused_imports)] use q45k::best_iq4; -#[allow(unused_imports)] use q45k::q6k; -#[allow(unused_imports)] use q45k::q45k; mod iq4; -#[allow(unused_imports)] -use iq4::iq4; -#[allow(unused_imports)] pub(super) use iq4::row_without_iq; diff --git a/crates/native-cpu-expert/src/rust_weight_quant/best_fp4.rs b/crates/native-cpu-expert/src/rust_weight_quant/best_fp4.rs index 8b91d798..9a8b10cd 100644 --- a/crates/native-cpu-expert/src/rust_weight_quant/best_fp4.rs +++ b/crates/native-cpu-expert/src/rust_weight_quant/best_fp4.rs @@ -1,5 +1,5 @@ -//! Functions: `best_fp4`, `fp4`, `ternary`, `tq2_levels` and 15 more. -//! Split out of `rust_weight_quant` to keep its files under the line limit. +//! Scalar quantizers for the 4-bit float, ternary (TQ1/TQ2), Q2_K and Q3_K formats, with the packing and +//! unpacking of their 3-bit and 4-bit block scales. use super::nearest::{Qkx, Search, sum_sq}; use super::{FP4, Kind, e8_half, h, max_signed, nearest, pack_ue4, put_h, q3, qkx, qp, qx, ue4}; diff --git a/crates/native-cpu-expert/src/rust_weight_quant/iq4.rs b/crates/native-cpu-expert/src/rust_weight_quant/iq4.rs index 1015c4a0..08d3029c 100644 --- a/crates/native-cpu-expert/src/rust_weight_quant/iq4.rs +++ b/crates/native-cpu-expert/src/rust_weight_quant/iq4.rs @@ -1,5 +1,5 @@ -//! Functions: `iq4`, `iq4_search`, `iq4_block`, `iq4_sums` and 5 more. -//! Split out of `rust_weight_quant` to keep its files under the line limit. +//! IQ4_XS and IQ4_NL quantizers (nonlinear 4-bit codebook, per-block scale search, packed 6-bit scales), and the +//! row driver that quantizes every non-IQ-grid kind, leaving the grid kinds to rust_weight_iq. use super::nearest::sum_sq; use super::{ diff --git a/crates/native-cpu-expert/src/rust_weight_quant/nearest.rs b/crates/native-cpu-expert/src/rust_weight_quant/nearest.rs index 14796bcc..178450d3 100644 --- a/crates/native-cpu-expert/src/rust_weight_quant/nearest.rs +++ b/crates/native-cpu-expert/src/rust_weight_quant/nearest.rs @@ -1,5 +1,5 @@ -//! Methods of `Search`: `new`, `record`, `factors`, `steps`. `impl Qkx`. -//! Functions: `nearest`, `put_h`, `h`, `sum_sq` and 15 more. Defines `Search`, `QxStart`, `Qkx` and 2 more. +//! Shared numeric core of the K-quant searches: round-to-nearest, half-float store/load, the per-block Search +//! record, and the least-squares scale searches qx, q3 and qkx (with its parameter set) used by all quantizers. use super::{EPS, half, half_rn}; diff --git a/crates/native-cpu-expert/src/rust_weight_quant/q45k.rs b/crates/native-cpu-expert/src/rust_weight_quant/q45k.rs index 6cb1529d..c0b296d0 100644 --- a/crates/native-cpu-expert/src/rust_weight_quant/q45k.rs +++ b/crates/native-cpu-expert/src/rust_weight_quant/q45k.rs @@ -1,5 +1,5 @@ -//! Functions: `q45k`, `q45k_search`, `q45k_weights`, `q45k_scales` and 7 more. -//! Split out of `rust_weight_quant` to keep its files under the line limit. +//! Q4_K, Q5_K and Q6_K quantizers: importance-weighted per-block scale/minimum search, super-block scale packing, +//! requantization against the stored scales and bit packing; also best_iq4, the nearest IQ4 codebook level. use super::nearest::{Qkx, Search, sum_sq}; use super::{EPS, h, nearest, pack_scale4, put_h, qkx, qp, qx, unpack_scale4}; diff --git a/crates/native-cpu-expert/src/rust_weight_quant/qp.rs b/crates/native-cpu-expert/src/rust_weight_quant/qp.rs index ab80c31d..a980682a 100644 --- a/crates/native-cpu-expert/src/rust_weight_quant/qp.rs +++ b/crates/native-cpu-expert/src/rust_weight_quant/qp.rs @@ -1,5 +1,5 @@ -//! Functions: `qp`, `qp_scale`, `qp_error`, `qp_refine` and 15 more. Defines `Shape`. -//! Split out of `rust_weight_quant` to keep its files under the line limit. +//! Weighted scale search (qp) and the small-block formats of 32 or fewer values per block (F32/F16/BF16, Q1, Q2, Q4/Q5 +//! with and without minimum, Q8), plus the e8/ue4 scale helpers and nibble packing they use. use super::nearest::Qkx; use super::{EPS, Kind, max_signed, nearest, put_h, qkx, qx}; diff --git a/crates/npu-service/src/engine/execution.rs b/crates/npu-service/src/engine/execution.rs index 13ec8fc2..a6c11ba4 100644 --- a/crates/npu-service/src/engine/execution.rs +++ b/crates/npu-service/src/engine/execution.rs @@ -51,6 +51,7 @@ impl Engine { } pub(super) fn run_at(&mut self, list: &[Product], i: usize) -> Result { + // Measurement timer, not decision logic (instant-now exception in architecture.json). let started = Instant::now(); let Self { runtime, diff --git a/crates/obs/src/level.rs b/crates/obs/src/level.rs index 13983f90..0fc9d66d 100644 --- a/crates/obs/src/level.rs +++ b/crates/obs/src/level.rs @@ -1,8 +1,7 @@ -//! Methods of `Level`: `as_str`, `parse`. Methods of `Settings`: `from_env`. -//! Implements `From for V`, `From for V` and 8 more. +//! Log levels and settings (LELEKA_LOG_* environment), conversion of values into log fields, and the pure line +//! formatter: redaction and capping of fields, then one JSON or text event line. use std::fmt::Write as _; -use std::io::Write as _; use super::{ Field, Format, IsTerminal, KeyClass, Level, MAX_LINE, MAX_MSG, MAX_VALUE, Rendered, SETTINGS, Settings, V, classify_key, format_utc_ms, redact, @@ -103,6 +102,11 @@ impl Settings { } } +/// `LELEKA_REQUEST_LOG`: the file that receives a copy of every request line, when the operator names one. +pub(super) fn request_log_path() -> Option { + std::env::var_os("LELEKA_REQUEST_LOG").filter(|path| !path.is_empty()) +} + pub fn settings() -> &'static Settings { SETTINGS.get_or_init(|| Settings::from_env(|name| std::env::var(name).ok(), std::io::stderr().is_terminal())) } diff --git a/crates/obs/src/lib.rs b/crates/obs/src/lib.rs index 35065f46..dbddfe89 100644 --- a/crates/obs/src/lib.rs +++ b/crates/obs/src/lib.rs @@ -19,8 +19,7 @@ pub mod time; pub use redact::{KeyClass, classify_key, register_secret}; pub use time::{format_utc_ms, now_ms, parse_duration_ms, parse_utc_ms}; -use std::fmt::Write as _; -use std::io::{IsTerminal, Write as _}; +use std::io::IsTerminal; use std::sync::{Mutex, OnceLock}; /// Longest string value in a line; longer ones are cut and end in `~`. @@ -267,48 +266,18 @@ mod tests { } mod level; -#[allow(unused_imports)] -use level::clean_key; -#[allow(unused_imports)] -use level::clean_key_dash; -#[allow(unused_imports)] -use level::json_line; -#[allow(unused_imports)] -use level::json_string; -#[allow(unused_imports)] -use level::render_fields; -#[allow(unused_imports)] pub use level::settings; -#[allow(unused_imports)] -use level::text_line; -#[allow(unused_imports)] pub use level::{EventHead, format_line}; mod write_stderr; -#[allow(unused_imports)] pub use write_stderr::debug; -#[allow(unused_imports)] pub use write_stderr::emit; -#[allow(unused_imports)] pub use write_stderr::emit_always; -#[allow(unused_imports)] pub use write_stderr::emit_keyed; -#[allow(unused_imports)] pub use write_stderr::emit_msg; -#[allow(unused_imports)] pub use write_stderr::error; -#[allow(unused_imports)] pub use write_stderr::info; -#[allow(unused_imports)] pub use write_stderr::legacy_line; -#[allow(unused_imports)] pub use write_stderr::new_request_id; -#[allow(unused_imports)] pub use write_stderr::record; -#[allow(unused_imports)] -use write_stderr::request_sink; -#[allow(unused_imports)] pub use write_stderr::trace_msg; -#[allow(unused_imports)] pub use write_stderr::warn; -#[allow(unused_imports)] -use write_stderr::write_stderr; diff --git a/crates/obs/src/redact/tests.rs b/crates/obs/src/redact/tests.rs index 85a0f202..9dada0b3 100644 --- a/crates/obs/src/redact/tests.rs +++ b/crates/obs/src/redact/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of `redact`. +//! Tests of log redaction: key classification, registered secrets, bearer and token shapes, query parameters, +//! that ordinary text, digests and paths pass through, and clipping at character boundaries. use super::*; diff --git a/crates/obs/src/write_stderr.rs b/crates/obs/src/write_stderr.rs index e859d4f0..3c3a567b 100644 --- a/crates/obs/src/write_stderr.rs +++ b/crates/obs/src/write_stderr.rs @@ -1,5 +1,5 @@ -//! Methods of `FileSink`: `new`, `path`, `write_line`. -//! Functions: `write_stderr`, `request_sink`, `emit`, `emit_keyed` and 10 more. +//! Log output: writes lines to stderr or the request log file, with the rate-limited emit family (emit, emit_always, +//! record for per-request lines, level shortcuts) and request id generation. use std::io::Write as _; use super::{ @@ -50,7 +50,7 @@ impl FileSink { pub(super) fn request_sink() -> Option<&'static FileSink> { static SINK: OnceLock> = OnceLock::new(); - SINK.get_or_init(|| std::env::var_os("LELEKA_REQUEST_LOG").filter(|p| !p.is_empty()).map(FileSink::new)).as_ref() + SINK.get_or_init(|| crate::level::request_log_path().map(FileSink::new)).as_ref() } /// Log an event, rate limited per `comp:ev`. Below the configured level nothing happens. diff --git a/crates/sampler-ref/src/chain/tests.rs b/crates/sampler-ref/src/chain/tests.rs index 47c36a21..0626548c 100644 --- a/crates/sampler-ref/src/chain/tests.rs +++ b/crates/sampler-ref/src/chain/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests of the sampler chain: top-k rules, repeat penalty on negative and positive logits, greedy and ordering ties +//! by lowest id, penalty window and history, shape checks, per-row counters, temperature zero and min-p. use super::*; diff --git a/crates/sampler-ref/src/params/tests.rs b/crates/sampler-ref/src/params/tests.rs index 43650c49..1e9c91de 100644 --- a/crates/sampler-ref/src/params/tests.rs +++ b/crates/sampler-ref/src/params/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests of request sampling parameters: Python repr, the Original defaults, top-k and penalty-window normalisation, +//! engine parameters, rejection of invalid fields, config ranges, request overlay and decimal wire floats. use super::*; diff --git a/crates/sampler-ref/src/serve/tests.rs b/crates/sampler-ref/src/serve/tests.rs index 24c4d691..39474365 100644 --- a/crates/sampler-ref/src/serve/tests.rs +++ b/crates/sampler-ref/src/serve/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests of the serve-loop sampling helpers: request parameters, coupled drafting setup, per-window draw counters over +//! literal histories, draft history staging, window rows by confidence floor, and settling a window. use super::*; diff --git a/crates/serving-policy/src/cvec.rs b/crates/serving-policy/src/cvec.rs index 37158a85..c1179941 100644 --- a/crates/serving-policy/src/cvec.rs +++ b/crates/serving-policy/src/cvec.rs @@ -75,8 +75,6 @@ pub struct Tables { mod tests; mod cursor; -#[allow(unused_imports)] pub use cursor::*; mod build_tables; -#[allow(unused_imports)] pub use build_tables::*; diff --git a/crates/serving-policy/src/cvec/build_tables.rs b/crates/serving-policy/src/cvec/build_tables.rs index ddd90f93..c4220efb 100644 --- a/crates/serving-policy/src/cvec/build_tables.rs +++ b/crates/serving-policy/src/cvec/build_tables.rs @@ -1,5 +1,5 @@ -//! Methods of `Sums`: `new`, `add_file`, `add_tensor`, `steer_layers`. Methods of `Steering`: `new`, `steer`. -//! Functions: `build_tables`, `layer_bounds`, `single_layer`, `tables_summary` and 4 more. Defines `Sums`, `Steering`. +//! Builds the control-vector direction and scale tables from parsed vector files (summing scaled directions per +//! layer, project or add mode, single-layer source) and parses the control-vector command-line values. use super::{Mode, Options, Tables, VectorFile, VectorTensor, strtol}; diff --git a/crates/serving-policy/src/cvec/cursor.rs b/crates/serving-policy/src/cvec/cursor.rs index e8d51788..25a9bb54 100644 --- a/crates/serving-policy/src/cvec/cursor.rs +++ b/crates/serving-policy/src/cvec/cursor.rs @@ -1,5 +1,5 @@ -//! Methods of `Cursor`: `take`, `u32`, `u64`, `string`. Implements `Default for Options`. -//! Functions: `value`, `skip_array`, `parse_gguf`, `read_header` and 4 more. Defines `Info`. +//! Reads control-vector GGUF files: the byte Cursor, header, metadata and tensor-info parsing (v2/v3, little endian), +//! f32 tensor values, the default Options, and the C strtol helper the engine parses numbers with. use super::{Cursor, Mode, Options, VectorFile, VectorTensor}; diff --git a/crates/serving-policy/src/cvec/tests.rs b/crates/serving-policy/src/cvec/tests.rs index 5cac83dd..c84f1111 100644 --- a/crates/serving-policy/src/cvec/tests.rs +++ b/crates/serving-policy/src/cvec/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests of control-vector tables: add mode sums scaled files, project mode stores unit vector and norm, loader +//! error wording, command-line value parsing, and GGUF files round-tripping through the parser. use super::*; diff --git a/crates/serving-policy/src/shared.rs b/crates/serving-policy/src/shared.rs index b5ed8d51..34c5ca38 100644 --- a/crates/serving-policy/src/shared.rs +++ b/crates/serving-policy/src/shared.rs @@ -58,8 +58,6 @@ pub struct MergedDefaults { mod tests; mod shared_defaults; -#[allow(unused_imports)] pub use shared_defaults::*; mod sampling_defaults; -#[allow(unused_imports)] pub use sampling_defaults::*; diff --git a/crates/serving-policy/src/shared/shared_defaults.rs b/crates/serving-policy/src/shared/shared_defaults.rs index 8c7ad455..f1932b34 100644 --- a/crates/serving-policy/src/shared/shared_defaults.rs +++ b/crates/serving-policy/src/shared/shared_defaults.rs @@ -1,5 +1,5 @@ -//! Methods of `SharedDefaults`: `is_empty`, `to_json`, `sampling`. -//! Functions: `float_value`, `py_repr`, `push_escaped`, `py_str_repr` and 10 more. +//! Validation and JSON form of the server-wide shared defaults (POST /settings): clean_shared_defaults with the +//! Original error texts, SharedDefaults JSON and sampling conversion, and Python repr helpers for those messages. use super::{Map, Number, RequestSampling, SharedDefaults, Value, py_float_repr}; diff --git a/crates/serving-policy/src/shared/tests.rs b/crates/serving-policy/src/shared/tests.rs index dd413943..111187e0 100644 --- a/crates/serving-policy/src/shared/tests.rs +++ b/crates/serving-policy/src/shared/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests of shared defaults: unknown and empty keys, normalisation like the Original, config range checks, the +//! precedence request over shared over config, llama-server names in props, aliases, and Python repr of values. use super::*; use serde_json::json; diff --git a/crates/serving-policy/src/vision/tests.rs b/crates/serving-policy/src/vision/tests.rs index 7b1e291a..ce69842d 100644 --- a/crates/serving-policy/src/vision/tests.rs +++ b/crates/serving-policy/src/vision/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests of the host-side image path: M-RoPE positions for text and images, failure wording, image sources, +//! image markers after vision start only, native formats passing through, and lenient base64 decoding. use super::*; use serde_json::json; diff --git a/crates/tokenizer/src/construction.rs b/crates/tokenizer/src/construction.rs index ea245c07..031a24f9 100644 --- a/crates/tokenizer/src/construction.rs +++ b/crates/tokenizer/src/construction.rs @@ -204,7 +204,7 @@ fn marks_of(tokens: &[String], types: &[u32]) -> Result { /// Kill switch for an operator who suspects the fast path: `LELEKA_TOKENIZER_REFERENCE=1` runs the original /// implementation only. fn fast_path(vocab: &HashMap, merges: &[String], byte_chars: &[char; 256]) -> Option { - if std::env::var_os("LELEKA_TOKENIZER_REFERENCE").is_some_and(|v| v == "1") { + if crate::settings::reference_only() { return None; } let pairs: Vec<(String, String)> = merges @@ -217,8 +217,5 @@ fn fast_path(vocab: &HashMap, merges: &[String], byte_chars: &[char /// `LELEKA_TOKENIZER_SEGMENT_CACHE_MIB=n` sizes the segment cache (0 turns it off). fn segment_cache_budget() -> usize { - std::env::var("LELEKA_TOKENIZER_SEGMENT_CACHE_MIB") - .ok() - .and_then(|value| value.parse::().ok()) - .map_or(cache::DEFAULT_BUDGET, |mib| mib << 20) + crate::settings::segment_cache_mib().map_or(cache::DEFAULT_BUDGET, |mib| mib << 20) } diff --git a/crates/tokenizer/src/fast.rs b/crates/tokenizer/src/fast.rs index af85cc24..170b0a49 100644 --- a/crates/tokenizer/src/fast.rs +++ b/crates/tokenizer/src/fast.rs @@ -56,8 +56,4 @@ pub struct Scratch { } mod unicode_ranges; -#[allow(unused_imports)] -pub use unicode_ranges::*; mod piece_merging; -#[allow(unused_imports)] -pub use piece_merging::*; diff --git a/crates/tokenizer/src/fast/unicode_ranges.rs b/crates/tokenizer/src/fast/unicode_ranges.rs index 56327871..e304423f 100644 --- a/crates/tokenizer/src/fast/unicode_ranges.rs +++ b/crates/tokenizer/src/fast/unicode_ranges.rs @@ -1,5 +1,5 @@ -//! Methods of `Classes`: `new`, `flags_of`, `at`, `letters_end` and 4 more. -//! Methods of `PairTable`: `with_capacity`, `slot`, `insert`, `get`. +//! Character classes of the fast pre-tokenizer: Unicode letter, mark, number and space ranges flattened into an ASCII +//! table plus sorted boundaries, the pre-token splitting rules built on them, and the open-addressing merge-pair table. use super::{Class, Classes, EMPTY, HirKind, LETTER, LETTER_OR_MARK, MARK, NUMBER, PairTable, ParserBuilder, SPACE}; diff --git a/crates/tokenizer/src/gguf_bpe.rs b/crates/tokenizer/src/gguf_bpe.rs index b1986bb3..705598c7 100644 --- a/crates/tokenizer/src/gguf_bpe.rs +++ b/crates/tokenizer/src/gguf_bpe.rs @@ -76,12 +76,7 @@ mod tests; mod build; mod error_messages; -#[allow(unused_imports)] pub use error_messages::*; mod codec; -#[allow(unused_imports)] -pub use codec::*; mod symbols; mod utf8_stream; -#[allow(unused_imports)] -pub use utf8_stream::*; diff --git a/crates/tokenizer/src/gguf_bpe/codec.rs b/crates/tokenizer/src/gguf_bpe/codec.rs index d4e579c3..bbd3d656 100644 --- a/crates/tokenizer/src/gguf_bpe/codec.rs +++ b/crates/tokenizer/src/gguf_bpe/codec.rs @@ -2,7 +2,6 @@ //! back to text, and look tokens up. //! Apart from `symbols` and `build`, which hold the vocabulary tables; this file is the public use of them. -#[allow(unused_imports)] use super::{build, symbols::Symbols, *}; impl GgufBpe { diff --git a/crates/tokenizer/src/gguf_bpe/tests.rs b/crates/tokenizer/src/gguf_bpe/tests.rs index b53e5ae5..b8b35e68 100644 --- a/crates/tokenizer/src/gguf_bpe/tests.rs +++ b/crates/tokenizer/src/gguf_bpe/tests.rs @@ -1,4 +1,5 @@ -//! Unit tests of this module (split out of its file; the test ids are unchanged). +//! Tests of the GGUF BPE tokenizer: GPT-2 byte map, merges in rank order, special tokens on request, byte round trip, +//! o200k-style pre-tokenizer splitting, long pieces, the UTF-8 streaming decoder and refusal of bad vocabularies. use super::*; diff --git a/crates/tokenizer/src/gguf_bpe/utf8_stream.rs b/crates/tokenizer/src/gguf_bpe/utf8_stream.rs index cfdfb5ba..ee173dfc 100644 --- a/crates/tokenizer/src/gguf_bpe/utf8_stream.rs +++ b/crates/tokenizer/src/gguf_bpe/utf8_stream.rs @@ -1,5 +1,5 @@ -//! Methods of `Utf8Stream`: `push`, `finish`. -//! Split out of `gguf_bpe` to keep its files under the line limit. +//! Streaming UTF-8 decoder for token bytes: returns the longest valid text so far (bad bytes become U+FFFD) and holds +//! back an incomplete trailing character until the next push, so a character is never split across tokens. use super::Utf8Stream; diff --git a/crates/tokenizer/src/lib.rs b/crates/tokenizer/src/lib.rs index 719269ae..120daae6 100644 --- a/crates/tokenizer/src/lib.rs +++ b/crates/tokenizer/src/lib.rs @@ -16,6 +16,7 @@ use serde::Deserialize; mod cache; mod fast; +mod settings; mod marks; pub use cache::{DEFAULT_BUDGET as DEFAULT_SEGMENT_CACHE_BYTES, MIN_SEGMENT_BYTES}; diff --git a/crates/tokenizer/src/settings.rs b/crates/tokenizer/src/settings.rs new file mode 100644 index 00000000..6c7618f8 --- /dev/null +++ b/crates/tokenizer/src/settings.rs @@ -0,0 +1,12 @@ +//! The only place of this crate that reads the process environment: the operator's tokenizer switches, as typed values. + +/// `LELEKA_TOKENIZER_REFERENCE=1`: run the original implementation only (a kill switch for the fast path). +pub(crate) fn reference_only() -> bool { + std::env::var_os("LELEKA_TOKENIZER_REFERENCE").is_some_and(|v| v == "1") +} + +/// `LELEKA_TOKENIZER_SEGMENT_CACHE_MIB=n`: the size of the segment cache in MiB (0 turns it off); `None` when unset or +/// not a number. +pub(crate) fn segment_cache_mib() -> Option { + std::env::var("LELEKA_TOKENIZER_SEGMENT_CACHE_MIB").ok().and_then(|value| value.parse::().ok()) +} diff --git a/docs/architecture/tech-debt.md b/docs/architecture/tech-debt.md index fc8aad06..22b71f63 100644 --- a/docs/architecture/tech-debt.md +++ b/docs/architecture/tech-debt.md @@ -205,6 +205,27 @@ their doc comment now says by which phase), `ConversationManager` (a domain type | `path-include` (engine 100, `desktop-core` 2) | not in the owner's list for this pass | `mod x;` through the directory layout with `git mv`, one directory at a time | | generated doc headers (`Methods of ...`, `Functions: ...`) in about 430 files of these crates | the sentence on why the file is separate needs the author's knowledge | by directory, together with the next feature that touches it | +### (c3) Stage 10 for the low-level crates (owner order 2026-11-14, branches `claude/debt-low` and `claude/debt-hot-low`) + +The order: every ratchet of `architecture-baseline.json` goes to zero in the code, or to a named entry of the `exceptions` list of `architecture.json` +(crate, file, ratchet, reason; the gate reads it, an entry that excuses nothing or has no reason is an error). Numbers are production code of the +low-level crates (`cuda-driver`, `cuda-model`, `model-format`, `native-cpu-expert`, `leleka-memory`, `memory-os`, `libc-shim`, `cpu-sys`, the gpt-oss +workers and the small libraries), before -> after, from `scripts/check-architecture.py`. + +| Ratchet | Before | After | How | +|---|---|---|---| +| `allow-unused-imports` | 552 | 0 | `scripts/dev/prune_unused_imports.py`: strips the allow, compiles with one job per feature set (`cuda-driver`, `sm86`, all features), deletes the imports the compiler reports in every compilation unit, puts `#[cfg(test)]` on the ones only the library's unit tests use. Most of the 410 `cuda-driver` allows sat on `pub use` re-exports that needed no allow at all | +| `glob-super-import` | 3 | 2 (cuda-driver, see below) | `root_exports.rs` names its paths (`crate::x`, `leleka_cuda_model::serving_context`) | +| `path-include` | 132 | 0 counted (1 in `cuda-driver`, see below) | `scripts/dev/path_to_layout.py`: walks the module tree (a file loaded by `#[path]` resolves its children next to itself, a default file in a directory of its name), moves the module files to `/.rs` with `git mv`, drops the attribute, rewrites `include_*!` paths and the paths scripts quote (`scripts/dev/update_path_refs.py`). 502 files moved (`cuda-driver` 472, `model-format` 27, `native-cpu-expert` 3); module paths did not change. The gate now treats `#[cfg(test)] #[path = "../tests/x.rs"] mod x;` as test code | +| `env-read` | 30 | 0 outside EXC_ENV exceptions | one reader per crate: new typed `settings.rs` in `cpu-worker`, `tokenizer`, `gptoss-npu`, `gpu-npu-worker`, `igpu`, `npu-service`, `leleka-memory`, `gptoss`, `model-format` (functions named after the variable, returning parsed values); `obs` parses `LELEKA_LOG*` in `level.rs`; `cuda-model` has `env_switch::EnvSwitch` (the name, a typed rule, the answer cached on first read). Exceptions: the readers above, `cpu-kernels` (parses the ISA request), `libc-shim` and `memory-os` (platform adapters), the `npu-worker` and `native-parity-bench` roots | +| `dyn-trait` | 52 outside `cuda-driver` | 0 outside EXC_DYN exceptions | callbacks and probes became generics (`&mut (impl FnMut(..) + ?Sized)`, `&(impl ProcSource + ?Sized)`); what stays is a port boundary (`MemoryPressure`, `ProcSource`, `PageLocking`, `ModelBytes`, `PageSource`, `PrefillAccelerator`, `LayerCache`, the GPU probe closure), a trait method that must be dyn-compatible, `Box` of a library boundary, or the type-erased job of the worker pool | +| `instant-now` | 54 outside the driver and the CPU pool | 0 outside EXC_INSTANT exceptions | the clock adapter (`obs/time/clock.rs`) and measurement timers (stage laps and wall times printed in the workers' timing lines, load reports); each carries a comment that says so. `leleka-memory` reads `SystemClock` | +| `process-global` | 50 outside the driver and the CPU pool | 0 outside EXC_GLOBAL exceptions | immutable tables (regex, half table), operator settings read once, the process-wide logger, the process singletons the S13/S14 injection is for (`Governor::global()`, `Inventory`, the serving context, the verify stamps) | + +The test run (`cargo test`, slim profile) of `cuda-model`, `obs`, `leleka-memory`, `tokenizer`, `model-format`, `gptoss`, `cpu-worker`, `igpu`, +`memory-os`, `experimental-ref` and `npu-service`: all green except the three known `qwen_artifact_binding` tests of `model-format` +(`cargo check --workspace --all-targets` is clean; `cuda-driver` and `native-cpu-expert` follow the hot-path branch, see below). + ### (e) Stage 10 pass: control-plane, desktop-core, deploy and the small crates (owner order 2026-11-14, branch `claude/debt-control`) Crates: `strata-control`, `strata-desktop-core`, `leleka-deploy`, `leleka-gateway-domain`, `leleka-gateway-text`, `leleka-backend-api`, `leleka-runtime-client`, `leleka-npu-service`. Numbers are from `scripts/check-architecture.py`; a site that must stay is a named entry of `exceptions` in `architecture.json` (crate, file, ratchet, reason), not a baseline number. diff --git a/scripts/archcheck/measure.py b/scripts/archcheck/measure.py index 200801b3..87e573a5 100644 --- a/scripts/archcheck/measure.py +++ b/scripts/archcheck/measure.py @@ -76,9 +76,11 @@ def production_lines(text): following = lines[index + 1] if index + 1 < len(lines) else "" if line.startswith("#[cfg(test)]") and following.startswith("mod "): break - opens_test_block = following.startswith("mod ") and following.rstrip().endswith("{") - if _is_test_cfg(line) and line.startswith("#[cfg(") and opens_test_block: - index = _after_block(lines, index + 1) + skipped_to = _test_module_declaration_end(lines, index) + if skipped_to is None and _opens_test_block(line, following): + skipped_to = _after_block(lines, index + 1) + if skipped_to is not None: + index = skipped_to continue if not line.lstrip().startswith("//"): kept.append(line) @@ -86,6 +88,26 @@ def production_lines(text): return kept +def _opens_test_block(line, following): + """A test cfg line whose next line opens an inline `mod x {` block.""" + opens_block = following.startswith("mod ") and following.rstrip().endswith("{") + return _is_test_cfg(line) and line.startswith("#[cfg(") and opens_block + + +def _test_module_declaration_end(lines, index): + """Index after a `mod x;` declaration that a test cfg line starts and further attributes (`#[path = ...]`) follow; + the declaration is test code, the production code after it still counts. None when `index` starts no such one.""" + following = lines[index + 1] if index + 1 < len(lines) else "" + if not (_is_test_cfg(lines[index]) and lines[index].startswith("#[cfg(") and following.startswith("#[")): + return None + cursor = index + 1 + while cursor < len(lines) and lines[cursor].startswith("#["): + cursor += 1 + declaration = lines[cursor] if cursor < len(lines) else "" + names_a_module = declaration.startswith(("mod ", "pub mod ", "pub(crate) mod ")) + return cursor + 1 if names_a_module and declaration.rstrip().endswith(";") else None + + def _after_block(lines, start): """Index of the line after the column-0 `}` that closes the block opened at `start`.""" for index in range(start + 1, len(lines)): diff --git a/scripts/build-original-verify-ptx.sh b/scripts/build-original-verify-ptx.sh index 2bb78e5f..51f592ed 100644 --- a/scripts/build-original-verify-ptx.sh +++ b/scripts/build-original-verify-ptx.sh @@ -151,7 +151,7 @@ required = { ), } -symbols = (Path.cwd() / 'crates/cuda-driver/src/mtp_original_full_symbols.rs').read_text(encoding='utf-8') +symbols = (Path.cwd() / 'crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/symbols.rs').read_text(encoding='utf-8') for asset, exports in __import__('re').findall(r'include_bytes!\(\"([^\"]+\.ptx)\"\).*?&\[(.*?)\]\)', symbols, __import__('re').S): required[asset] = tuple(__import__('re').findall(r'c\"([^\"]+)\"', exports)) diff --git a/scripts/chain/reset_chain_pin.py b/scripts/chain/reset_chain_pin.py index 49b1a65d..568566b3 100644 --- a/scripts/chain/reset_chain_pin.py +++ b/scripts/chain/reset_chain_pin.py @@ -4,7 +4,7 @@ import re import sys ptx = "crates/cuda-driver/src/chain_window.ptx" -rs = "crates/cuda-driver/src/original_verify_window_chain.rs" +rs = "crates/cuda-driver/src/original_verify/chain.rs" with open(ptx, "w", newline="\n") as f: f.write("// UNSEALED placeholder: chain_window.ptx (compile_assets.py / seal_pins.py install the real PTX)\n") s = open(rs, newline="").read() diff --git a/scripts/check_architecture_test.py b/scripts/check_architecture_test.py index 72915a28..cea652ac 100644 --- a/scripts/check_architecture_test.py +++ b/scripts/check_architecture_test.py @@ -236,6 +236,9 @@ class Measurement(unittest.TestCase): unused = dict(listed, file="src/lib.rs", ratchet="x") self.assertEqual(len(rules.exception_findings([unused, dict(listed, reason="")], excused, {"e"})), 2) + def test_a_test_module_declaration_with_a_path_attribute_is_not_production(self): + text = "\n".join(["#[cfg(test)]", '#[path = "../tests/x.rs"]', "mod tests;", "let a = 1;"]) + "\n" + self.assertEqual(measure.production_lines(text), ["let a = 1;"]) if __name__ == "__main__": unittest.main() diff --git a/scripts/decode-sm120/reset_pin.py b/scripts/decode-sm120/reset_pin.py index fc402c86..5961b381 100644 --- a/scripts/decode-sm120/reset_pin.py +++ b/scripts/decode-sm120/reset_pin.py @@ -5,7 +5,7 @@ import sys name = sys.argv[1] ptx = f"crates/cuda-driver/src/{name}.ptx" -rs = "crates/cuda-driver/src/original_verify_window_sm120.rs" +rs = "crates/cuda-driver/src/original_verify/sm120.rs" with open(ptx, "w", newline="\n") as f: f.write(f"// UNSEALED placeholder: {name}.ptx (compile_assets.py / seal_pins.py install the real PTX)\n") s = open(rs, newline="").read() diff --git a/scripts/dev/path_to_layout.py b/scripts/dev/path_to_layout.py new file mode 100644 index 00000000..3f6ad5e6 --- /dev/null +++ b/scripts/dev/path_to_layout.py @@ -0,0 +1,188 @@ +"""Replace `#[path = "x.rs"] mod name;` by the directory layout (`parent/name.rs`) with `git mv` (STRA-338 stage 10). + +Usage: python scripts/dev/path_to_layout.py CRATE_DIR [--apply | --fix-includes] + +The module paths do not change, only where the files live. Walking the module tree from the crate roots, a module whose +declaration carries a `#[path]` (except a `tests.rs` file and a `../` path that leaves the module's directory) gets the +location its parent's directory gives it: `/.rs`, and the children that were resolved next to the +old file move into the directory named after the new one. Then + + * the `#[path]` of every normalised declaration is dropped, the others are rewritten relative to the moved parent; + * `include_str!`, `include_bytes!` and `include!` paths of a moved file are rewritten to reach the same file. + +A file loaded through `#[path]` (like a crate root or `mod.rs`) resolves its own `mod x;` next to itself; a file at its +default place resolves them in a directory named after it. The tool tracks both for the old and the new tree. +Without --apply the plan is printed. A target that already exists is reported and left. After --apply, run +--fix-includes: it rewrites the `include_str!` of source files that other files read and that moved (read from +`git diff -M`). Offline refactoring aid, not part of the product. +""" +import os +import pathlib +import re +import subprocess +import sys + +ROOTS = ("lib.rs", "main.rs", "mod.rs") +PATH_ATTR = re.compile(r'^(\s*)#\[path\s*=\s*"([^"]+)"\]\s*$') +MOD_DECL = re.compile(r"^\s*(?:pub(?:\([^)]*\))?\s+)?mod\s+([A-Za-z_][A-Za-z0-9_]*)\s*;\s*$") +INCLUDE = re.compile(r'(include_str!|include_bytes!|include!)\(\s*"([^"]+)"\s*\)') + + +def is_root(path): + return path.name in ROOTS or path.parent.name == "bin" and path.parent.parent.name == "src" + + +def directory(path, flat): + """Where the `mod x;` declarations of a file are resolved.""" + return path.parent if flat else path.parent / path.stem + + +def declarations(path): + """[(mod name, line index of the mod line, line index of its #[path] line or None, path string or None)].""" + rows = path.read_text(encoding="utf-8").split("\n") + found, path_line, path_value = [], None, None + for index, row in enumerate(rows): + attr = PATH_ATTR.match(row) + if attr: + path_line, path_value = index, attr.group(2) + continue + decl = MOD_DECL.match(row) + if decl: + found.append((decl.group(1), index, path_line, path_value)) + path_line = path_value = None + elif not row.strip().startswith("#[") and row.strip() and not row.strip().startswith("//"): + path_line = path_value = None + return found + + +class Plan: + """The module tree walked from the crate roots: for every module file its old and its new place.""" + + def __init__(self): + self.new, self.flats, self.decls, self.skipped = {}, {}, {}, [] + + def old_child(self, old, old_flat, name, value): + """(file, flat) of the module a declaration names in the old tree.""" + if value: + base = pathlib.Path(os.path.normpath(old.parent / value)) + return (base, True) if base.is_file() else (None, False) + plain = directory(old, old_flat) / f"{name}.rs" + nested = directory(old, old_flat) / name / "mod.rs" + return (plain, False) if plain.is_file() else (nested, True) if nested.is_file() else (None, False) + + def place(self, canonical, child, dirs, normalise, has_attr): + """(new file, flat, normalised) for a child that is not placed yet; flat None keeps the old kind.""" + old_dir, new_dir = dirs + if normalise and child == canonical: + return canonical, False, True + if normalise and not canonical.exists() and canonical not in self.new.values(): + return canonical, False, True + if not has_attr and old_dir != new_dir: + return new_dir / child.relative_to(old_dir), None, False + return child, None, False + + def walk(self, old, new, old_flat, new_flat): + if old in self.new: + return + self.new[old], self.flats[old] = new, new_flat + dirs = directory(old, old_flat), directory(new, new_flat) + rows = [] + for name, mod_line, path_line, value in declarations(old): + child, child_flat = self.old_child(old, old_flat, name, value) + if child is None: + continue + normalise = value is not None and ".." not in value and not value.endswith("tests.rs") + if child in self.new: + target, normalised = self.new[child], False + else: + canonical = dirs[1] / f"{name}.rs" + target, flat, normalised = self.place(canonical, child, dirs, normalise, value is not None) + if normalise and not normalised: + self.skipped.append((str(old), name, "target exists or is taken")) + self.walk(child, target, child_flat, child_flat if flat is None else flat) + rows.append((name, mod_line, path_line, value, target, normalised)) + self.decls[old] = rows + + +def collect(crate_dir): + src = pathlib.Path(crate_dir).resolve() / "src" + plan = Plan() + for root in (p for p in sorted(src.rglob("*.rs")) if is_root(p)): + plan.walk(root, root, True, True) + return plan + + +def relative(target, start): + return pathlib.PurePosixPath(os.path.relpath(target, start).replace("\\", "/")).as_posix() + + +def git(root, *args): + subprocess.run(["git", *args], cwd=root, check=True, capture_output=True) + + +def rewrite_file(old, new, rows_info, text): + rows, drop = text.split("\n"), set() + for _name, _mod_line, path_line, _value, target, normalised in rows_info: + if path_line is None: + continue + if normalised: + drop.add(path_line) + else: + indent = PATH_ATTR.match(rows[path_line]).group(1) + rows[path_line] = f'{indent}#[path = "{relative(target, new.parent)}"]' + text = "\n".join(r for i, r in enumerate(rows) if i not in drop) + if old != new: + text = INCLUDE.sub(lambda m: f'{m.group(1)}("{relative(old.parent / m.group(2), new.parent)}")', text) + return text + + +def apply_plan(plan, root, apply): + moves = {old: new for old, new in plan.new.items() if old != new} + for old, new in sorted(moves.items()): + print(f"mv {old.relative_to(root).as_posix()} -> {new.relative_to(root).as_posix()}") + print(f"{len(moves)} files move; left as they are: {plan.skipped}") + if not apply: + return + contents = {old: old.read_text(encoding="utf-8") for old in plan.new} + for old, new in sorted(moves.items()): + new.parent.mkdir(parents=True, exist_ok=True) + git(root, "mv", str(old), str(new)) + for old, new in plan.new.items(): + text = rewrite_file(old, new, plan.decls.get(old, []), contents[old]) + with open(new, "wb") as handle: + handle.write(text.encode("utf-8")) + + +def fix_includes(crate_dir): + """Rewrite `include_str!`, `include_bytes!` and `include!` of `.rs` files that moved (read from `git diff -M`).""" + root = pathlib.Path(crate_dir).resolve().parents[1] + out = subprocess.run(["git", "diff", "-M", "--name-status", "HEAD"], cwd=root, capture_output=True, text=True).stdout + moved = {} + for line in out.splitlines(): + parts = line.split("\t") + if parts[0].startswith("R"): + moved[pathlib.Path(os.path.normpath(root / parts[1]))] = root / parts[2] + changed = 0 + for path in pathlib.Path(crate_dir).resolve().rglob("*.rs"): + text = path.read_text(encoding="utf-8") + + def fix(match): + target = pathlib.Path(os.path.normpath(path.parent / match.group(2))) + if match.group(2).endswith(".rs") and not target.exists() and target in moved: + return f'{match.group(1)}("{relative(moved[target], path.parent)}")' + return match.group(0) + + new_text = INCLUDE.sub(fix, text) + if new_text != text: + changed += 1 + with open(path, "wb") as handle: + handle.write(new_text.encode("utf-8")) + print(f"include paths fixed in {changed} files") + + +if __name__ == "__main__": + crate = sys.argv[1] + if "--fix-includes" in sys.argv: + fix_includes(crate) + else: + apply_plan(collect(crate), pathlib.Path(crate).resolve().parents[1], "--apply" in sys.argv) diff --git a/scripts/dev/prune_unused_imports.py b/scripts/dev/prune_unused_imports.py new file mode 100644 index 00000000..cf1b4e00 --- /dev/null +++ b/scripts/dev/prune_unused_imports.py @@ -0,0 +1,142 @@ +"""Remove `#[allow(unused_imports)]` from a crate and delete the imports the compiler reports as unused (STRA-338 stage 10). + +Usage: + python scripts/dev/prune_unused_imports.py strip CRATE_DIR remove every bare `#[allow(unused_imports)]` line + python scripts/dev/prune_unused_imports.py check PACKAGE CONFIG LOG cargo check one feature set (CONFIG: cuda|sm86|all|...) + python scripts/dev/prune_unused_imports.py report LOG... count the unused-import diagnostics per file + python scripts/dev/prune_unused_imports.py fix LOG... apply the removals that every LOG agrees on + +The suggestions are the ones `cargo fix` would apply, but a span is removed only when every log (feature set) flags it in +every compilation unit that holds it, and an import that only the library's unit tests use gets `#[cfg(test)]`. +Offline refactoring aid, not part of the product. +""" +import json +import pathlib +import re +import subprocess +import sys + +ROOT = pathlib.Path(__file__).resolve().parents[2] +CONFIGS = { + "default": "", + "cuda": "--features cuda-driver", + "sm86": "--features cuda-driver,sm86", + "probe": "--features cuda-driver,expert-tier-probe", + "all": "--all-features", +} + + +def write(path, data): + with open(path, "wb") as handle: + handle.write(data) + + +def strip(crate_dir): + changed = 0 + for path in sorted(pathlib.Path(crate_dir).rglob("*.rs")): + if "target" in path.parts: + continue + rows = path.read_bytes().decode("utf-8").split("\n") + kept = [r for r in rows if r.strip() != "#[allow(unused_imports)]"] + if len(kept) != len(rows): + changed += len(rows) - len(kept) + write(path, "\n".join(kept).encode("utf-8")) + print(f"removed {changed} lines") + + +def check(package, config, log): + flags = CONFIGS.get(config, config) + packages = " ".join(f"-p {name}" for name in package.split(",")) + cmd = f"check -j1 {packages} --all-targets {flags} --message-format=json" + subprocess.run(["bash", str(ROOT / "scripts/dev/wsl-cargo.sh"), log, *cmd.split()], check=True, cwd=ROOT) + + +def diagnostics(log): + """{(file, start, end, replacement): {unit}} of the unused-import removal suggestions of one log. A unit is the + compilation that reported it: `lib`, `lib-test` or `:` (an integration test, an example). Cargo runs with + one job, so the messages of one rustc process come right before its `compiler-artifact` line, which names the unit.""" + found, buffered = {}, [] + for line in pathlib.Path(ROOT / log).read_text(encoding="utf-8", errors="replace").splitlines(): + if not line.startswith("{"): + continue + record = json.loads(line) + if record.get("reason") == "compiler-message": + message = record["message"] + if (message.get("code") or {}).get("code") == "unused_imports": + buffered.append(message) + elif record.get("reason") == "compiler-artifact": + kind = record["target"]["kind"][0] + if kind == "lib": + unit = "lib-test" if record["profile"]["test"] else "lib" + else: + unit = f"{kind}:{record['target']['name']}" + for message in buffered: + for child in message["children"]: + for span in child["spans"]: + if span.get("suggested_replacement") is not None: + key = (span["file_name"], span["byte_start"], span["byte_end"], span["suggested_replacement"]) + found.setdefault(key, set()).add(unit) + buffered = [] + return found + + +def report(logs): + per = {} + for log in logs: + for file, *_ in diagnostics(log): + per[file] = per.get(file, 0) + 1 + for file, n in sorted(per.items(), key=lambda kv: -kv[1]): + print(n, file) + print("total", sum(per.values()), "in", len(per), "files") + + +def decide(logs): + """(remove, test_only): spans every log flags. `remove`: flagged in every unit that compiles the span. + `test_only`: flagged in the library but used by the library's unit tests (needs `#[cfg(test)]`).""" + maps = [diagnostics(log) for log in logs] + keys = set.intersection(*[set(m) for m in maps]) + remove, test_only = set(), set() + for key in keys: + units = [m[key] for m in maps] + outside_lib = "/tests/" in key[0] or "/examples/" in key[0] + both = all(("lib" in u) == ("lib-test" in u) for u in units) or all(u == {"lib-test"} for u in units) + only_lib = all("lib" in u and "lib-test" not in u for u in units) + if outside_lib or both: + remove.add(key) + elif only_lib: + test_only.add(key) + return remove, test_only + + +def fix(logs): + remove, test_only = decide(logs) + edits = {} + for key in remove: + edits.setdefault(key[0], []).append((key[1], key[2], key[3])) + held = [] + for key in test_only: + text = (ROOT / key[0]).read_bytes()[key[1] : key[2]].decode() + if re.match(r"(pub(\([^)]*\))?\s+)?use\s[^{}]*;\s*$", text.strip()): + edits.setdefault(key[0], []).append((key[1], key[1], "#[cfg(test)]\n")) + else: + held.append((key[0], text.strip()[:60])) + for file, items in edits.items(): + data = (ROOT / file).read_bytes() + for start, end, replacement in sorted(items, reverse=True): + data = data[:start] + replacement.encode() + data[end:] + write(ROOT / file, data) + print(f"removed {len(remove)}, gated `#[cfg(test)]` {len(test_only) - len(held)}, left {len(held)}") + for item in held: + print(" left:", item) + + +if __name__ == "__main__": + action, args = sys.argv[1], sys.argv[2:] + if action == "strip": + strip(args[0]) + elif action == "check": + check(*args) + elif action == "report": + report(args) + elif action == "fix": + fix(args) diff --git a/scripts/dev/update_path_refs.py b/scripts/dev/update_path_refs.py new file mode 100644 index 00000000..8233c0f1 --- /dev/null +++ b/scripts/dev/update_path_refs.py @@ -0,0 +1,57 @@ +"""After `git mv` of Rust files, rewrite the repository-relative paths that tools and gates quote (STRA-338 stage 10). + +Usage: python scripts/dev/update_path_refs.py REV [--apply] + +Reads the renames of `.rs` files from `git diff -M --name-status REV` (REV is the commit before the moves) and replaces +each old path by the new one in `scripts/`, `.github/` and the JSON files at the repository root (the limits gate keys +its allowlist and baselines by file path). Docs are not touched: a document that cites a path keeps the path of its time. +Offline refactoring aid, not part of the product. +""" +import pathlib +import subprocess +import sys + +ROOT = pathlib.Path(__file__).resolve().parents[2] +EXTENSIONS = {".py", ".sh", ".json", ".yml", ".yaml", ".toml", ".ps1"} + + +def renames(rev): + out = subprocess.run(["git", "diff", "-M", "--name-status", rev], cwd=ROOT, capture_output=True, text=True).stdout + pairs = {} + for line in out.splitlines(): + parts = line.split("\t") + if parts[0].startswith("R") and parts[1].endswith(".rs"): + pairs[parts[1]] = parts[2] + return pairs + + +def targets(): + roots = [ROOT / "scripts", ROOT / ".github"] + files = [p for r in roots if r.exists() for p in r.rglob("*") if p.is_file() and p.suffix in EXTENSIONS] + return files + [p for p in ROOT.glob("*.json")] + + +def main(rev, apply): + pairs = renames(rev) + ordered = sorted(pairs, key=len, reverse=True) + touched = 0 + for path in targets(): + data = path.read_bytes() + try: + text = data.decode("utf-8") + except UnicodeDecodeError: + continue + new = text + for old in ordered: + if old in new: + new = new.replace(old, pairs[old]) + if new != text: + touched += 1 + print("updated", path.relative_to(ROOT).as_posix()) + if apply: + path.write_bytes(new.encode("utf-8")) + print(f"{len(pairs)} renamed Rust files; {touched} files quote a moved path") + + +if __name__ == "__main__": + main(sys.argv[1], "--apply" in sys.argv) diff --git a/scripts/gpu-bringup/bringup_lib.py b/scripts/gpu-bringup/bringup_lib.py index 8a9e6311..7acdbc0a 100644 --- a/scripts/gpu-bringup/bringup_lib.py +++ b/scripts/gpu-bringup/bringup_lib.py @@ -80,7 +80,7 @@ class Asset: atomic_group: Optional[str] = None # all members must be sealed together notes: List[str] = field(default_factory=list) seal_fields: bool = False # the plan entry carries seal_sha256/seal_length slots to fill - entries_from_symbols: bool = False # entry names live in crates/cuda-driver/src/mtp_original_full_symbols.rs + entries_from_symbols: bool = False # entry names live in crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/symbols.rs flag_overrides: List[str] = field(default_factory=list) # operator overrides applied (recorded in the manifest) @property @@ -269,9 +269,9 @@ ROPE_FASTMATH_SOURCES = ("qsa_prompt_indexer", "qsa_decode_postops") # decimal-pin hits expected in the Rust tree for the committed digests (found by scanning, see seal_pins) ROPE_REPIN_EXPECT = { "qsa_prompt_indexer": {}, - "qsa_prompt_postops": {"crates/cuda-driver/src/original_verify_window_qsa.rs": 1}, - "qsa_decode_postops": {"crates/cuda-driver/src/original_verify_window_qsa.rs": 1}, - "qsa_prompt_resolver": {"crates/cuda-driver/src/original_verify_window_qsa.rs": 1}, + "qsa_prompt_postops": {"crates/cuda-driver/src/original_verify/qsa.rs": 1}, + "qsa_decode_postops": {"crates/cuda-driver/src/original_verify/qsa.rs": 1}, + "qsa_prompt_resolver": {"crates/cuda-driver/src/original_verify/qsa.rs": 1}, } # hex pins in the window plan (sealed_assets_bound) ROPE_HEX_DOC = "docs/cuda-seal-plan-additions-window.json" @@ -577,7 +577,7 @@ def fill_derived_entries(root: Path, asset: Asset) -> None: asset.entries_derived = True -SYMBOLS_FILE = "crates/cuda-driver/src/mtp_original_full_symbols.rs" +SYMBOLS_FILE = "crates/cuda-driver/src/mtp_dense_kv/original_int8/prefill/scalar/full_forward/symbols.rs" def _symbols_text(root: Path) -> str: diff --git a/scripts/gpu-bringup/extra-seal-plan.json b/scripts/gpu-bringup/extra-seal-plan.json index 606f5e92..391c3385 100644 --- a/scripts/gpu-bringup/extra-seal-plan.json +++ b/scripts/gpu-bringup/extra-seal-plan.json @@ -148,7 +148,7 @@ "atomic_group": "reseal-fastmath", "mandatory": true, "repin_expect": { - "crates/cuda-driver/src/original_verify_window_proj.rs": 1 + "crates/cuda-driver/src/original_verify/proj.rs": 1 }, "include_profile": "standard", "entries_from_symbols": true @@ -195,7 +195,7 @@ "atomic_group": "reseal-fastmath", "mandatory": true, "repin_expect": { - "crates/cuda-driver/src/original_verify_window_moe.rs": 1 + "crates/cuda-driver/src/original_verify/moe.rs": 1 }, "include_profile": "standard", "entries_from_symbols": true @@ -217,7 +217,7 @@ "atomic_group": "reseal-fastmath", "mandatory": true, "repin_expect": { - "crates/cuda-driver/src/original_verify_window_gr.rs": 1 + "crates/cuda-driver/src/original_verify/gr.rs": 1 }, "include_profile": "standard", "entries_from_symbols": true @@ -239,7 +239,7 @@ "atomic_group": "reseal-fastmath", "mandatory": true, "repin_expect": { - "crates/cuda-driver/src/original_verify_window_gr.rs": 1 + "crates/cuda-driver/src/original_verify/gr.rs": 1 }, "include_profile": "standard", "entries_from_symbols": true @@ -259,7 +259,7 @@ "atomic_group": "reseal-fastmath", "mandatory": true, "repin_expect": { - "crates/cuda-driver/src/original_verify_window_gr.rs": 1, + "crates/cuda-driver/src/original_verify/gr.rs": 1, "crates/cuda-driver/src/ple_batch_queue.rs": 1 }, "rust_fields_to_fill": { @@ -760,7 +760,7 @@ "group": "chain-window", "optional": false, "repin_expect": { - "crates/cuda-driver/src/original_verify_window_chain.rs": 1 + "crates/cuda-driver/src/original_verify/chain.rs": 1 } }, { @@ -898,7 +898,7 @@ ], "encoding": "concat_include_str", "rust_fields_to_fill": { - "crates/cuda-driver/src/original_verify/original_verify_window_down.rs": [ + "crates/cuda-driver/src/original_verify/down.rs": [ "DOWN_SUB16.sha" ] }, @@ -1021,7 +1021,7 @@ ], "encoding": "concat_include_str", "rust_fields_to_fill": { - "crates/cuda-driver/src/original_verify_window_qsa/fused_prelude.rs": [ + "crates/cuda-driver/src/original_verify/qsa/fused_prelude.rs": [ "KV_ROWS.sha" ] }, @@ -1046,7 +1046,7 @@ ], "encoding": "concat_include_str", "rust_fields_to_fill": { - "crates/cuda-driver/src/original_verify_window_qsa/fused_prelude.rs": [ + "crates/cuda-driver/src/original_verify/qsa/fused_prelude.rs": [ "INDEX_ROWS.sha" ] }, @@ -1128,7 +1128,7 @@ ], "encoding": "concat_include_str", "rust_fields_to_fill": { - "crates/cuda-driver/src/original_verify_window_ops/wait_rows.rs": [ + "crates/cuda-driver/src/original_verify/window_ops/wait_rows.rs": [ "WAIT_COPY_ROWS.sha" ] }, @@ -1177,7 +1177,7 @@ ], "encoding": "concat_include_str", "rust_fields_to_fill": { - "crates/cuda-driver/src/original_verify_window_gr/fused_down.rs": [ + "crates/cuda-driver/src/original_verify/gr/fused_down.rs": [ "GR_DOWN_FUSED.sha" ] }, @@ -1203,7 +1203,7 @@ ], "encoding": "concat_include_str", "rust_fields_to_fill": { - "crates/cuda-driver/src/original_verify_window_gr/head_chain.rs": [ + "crates/cuda-driver/src/original_verify/gr/head_chain.rs": [ "HEAD_CHAIN.sha" ] }, diff --git a/scripts/gpu-bringup/tests/test_gpu_bringup.py b/scripts/gpu-bringup/tests/test_gpu_bringup.py index d2101830..43a4460b 100644 --- a/scripts/gpu-bringup/tests/test_gpu_bringup.py +++ b/scripts/gpu-bringup/tests/test_gpu_bringup.py @@ -334,7 +334,7 @@ class RustPinForms(unittest.TestCase): self.assertTrue(R.read_field(t, s, V), (name, s)) def test_already_sealed_consumers_are_recognised_as_resealable(self): - t = (REPO / "crates/cuda-driver/src/gdn_fused_t1.rs").read_text() + t = (REPO / "crates/cuda-driver/src/qwen_dispatch/gdn_fused_t1.rs").read_text() t2 = R.apply_field(R.apply_field(t, "FUSED_PTX_LEN", V), "FUSED_PTX_SHA256", V) self.assertEqual(R.read_plain(t2, "FUSED_PTX_LEN"), 1234) self.assertNotEqual(t, t2) @@ -611,7 +611,7 @@ class RealTreeFakeSeal(unittest.TestCase): queue = (scratch / "crates/cuda-driver/src/ple_batch_queue.rs").read_text() self.assertEqual(R.read_plain(queue, "PTX_BYTES"), ple["raw_bytes"]) self.assertEqual(R.read_plain(queue, "PTX_SHA256"), bytes.fromhex(ple["raw_sha256"])) - gr = (scratch / "crates/cuda-driver/src/original_verify_window_gr.rs").read_text() + gr = (scratch / "crates/cuda-driver/src/original_verify/gr.rs").read_text() self.assertEqual(len(R.find_decimal_pins(gr, bytes.fromhex(ple["raw_sha256"]))), 1) # idempotent on the second run of identical output code, _, err = run_quiet(S.main, ["--ptx-dir", str(out), "--root", str(scratch), "--allow-fake", "--write",