Written by Claude Opus 5.5.
Problem #
Each engine's gpu crate hand-writes a Rust wrapper for every CUDA kernel it launches. The wrapper is an unsafe fn that mirrors the kernel's C signature argument by argument. These wrappers and their call sites are most of the roughly 670 unsafe sites in the GPU crates, and the reason clippy::too_many_arguments is allowed workspace-wide. Nothing checks a wrapper against its kernel: reviewing #5 meant comparing 22 wrapper families against qwen36.cu by hand. Constants shared by a kernel and its Rust side (head dims, rows per block) are duplicated the same way.
Proposal #
Generate the launchers from the kernel sources at build time.
- A strict, documented convention for launchable entry points, for example an annotation macro next to
extern "C" __global__whose parameters use a small set of types:- device pointers to
T(constor not); - scalar integers and floats;
- a few POD structs declared in shared
.cuhheaders.
- device pointers to
- The build script,
firecrest-kernelsor each engine's after the kernels move (#9), parses those signatures and emits a Rust module per kernel file. That module holds:- a typed launcher per entry, taking
&DeviceBuffer<T>/&mut DeviceBuffer<T>and scalars, with grid, block and stream; - the
#defineconstants marked for export; #[repr(C)]mirrors of the shared structs, with size and offset assertions on both sides.
- a typed launcher per entry, taking
- The launch
unsafethen lives in one generated place. It carries one// SAFETY:argument for the whole pattern; a kernel's own bounds contract stays documented at its definition. Hand-writtenkernels.rsfiles disappear. - A proc-macro (
#[kernel(...)]on a Rust declaration, checked against the.cu) is the alternative if parsing in a build script proves too fragile. Its drawback is a second crate and slower builds.
Acceptance #
- One engine (smollm3 or qwen3.6) ported first, with no change to its outputs.
- The convention is documented next to the kernels.
- A mismatch between a wrapper and its kernel becomes a build error.