logicaffeine_compile/codegen_cuda/provenance.rs
1//! Where an emitted CUDA program came from, stated in its first line. Every whole-program emitter takes its
2//! header from [`header`], so no program can claim a provenance it does not have — in particular, a hand-written
3//! lane cannot say it was compiled from a model's `.lg`.
4
5/// How a CUDA program was produced.
6#[derive(Clone, Copy, Debug, PartialEq, Eq)]
7pub enum Provenance {
8 /// Compiled from a program's tensor statements: every kernel launch is a stage the tensor front end lifted from
9 /// the source (or several, fused), and a statement it cannot lift refuses the compile
10 /// ([`super::qwen_emit::forward_graph`], [`super::lane`]).
11 Compiled,
12 /// A lane written by hand for one model: its kernels and launch sequence are templates in this crate, driven by
13 /// the model's configuration. It is held to the model's `.lg` forward by golden-token locks, not compiled from it.
14 HandWritten {
15 model: &'static str,
16 lane: &'static str,
17 },
18}
19
20/// The program's first line, newline included.
21pub fn header(p: Provenance) -> String {
22 match p {
23 Provenance::Compiled => {
24 "// LOGOS: compiled from the program's tensor statements — every launch is a stage lifted from the source.\n"
25 .to_string()
26 }
27 Provenance::HandWritten { model, lane } => format!(
28 "// LOGOS: hand-written {lane} lane for {model} — not compiled from its `.lg`; held to it by golden-token locks.\n"
29 ),
30 }
31}