1#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
19pub enum Kind {
20 Fused,
21 Primitive,
22 Placement,
23 Numerics,
24 Schedule,
25}
26
27#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
29pub enum Origin {
30 Ledger,
32 Book,
34 Ours,
36}
37
38#[derive(Clone, Copy, Debug, PartialEq, Eq)]
40pub enum Exemplar {
41 Program { source: &'static str, pattern: &'static [&'static str] },
42 None(&'static str),
43}
44
45#[derive(Clone, Copy, Debug, PartialEq, Eq)]
47pub struct Class {
48 pub class: ClassId,
49 pub id: &'static str,
50 pub kind: Kind,
51 pub origin: Origin,
52 pub exemplar: Exemplar,
53}
54
55const fn class(class: ClassId, id: &'static str, kind: Kind, origin: Origin, exemplar: Exemplar) -> Class {
56 Class { class, id, kind, origin, exemplar }
57}
58
59const fn ex(source: &'static str, pattern: &'static [&'static str]) -> Exemplar {
60 Exemplar::Program { source, pattern }
61}
62
63const NO_SUGAR: &str = "no sugar writes it yet";
64const SCHEDULE: &str = "a schedule property: how a chip runs a program, which no program states";
65const MULTI_CHIP: &str = "it spans chips, and no exemplar runs on more than one";
66const NUMERICS: &str = "a value's representation, which a chip's numerics choose and no program states";
67
68use Kind::{Fused, Numerics, Placement, Primitive, Schedule};
69use Origin::{Book, Ledger, Ours};
70
71macro_rules! registry {
74 ($($name:ident = $id:literal, $kind:expr, $origin:expr, $exemplar:expr;)*) => {
75 #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
78 pub enum ClassId {
79 $($name),*
80 }
81
82 impl ClassId {
83 pub const ALL: &'static [ClassId] = &[$(ClassId::$name),*];
85
86 pub const fn id(self) -> &'static str {
88 match self {
89 $(ClassId::$name => $id),*
90 }
91 }
92 }
93
94 pub const CLASSES: &[Class] = &[$(class(ClassId::$name, $id, $kind, $origin, $exemplar)),*];
96 };
97}
98
99registry! {
100 NormWeight = "norm_weight", Primitive, Ledger, ex("## Main\nLet X be a 2 by 8 tensor of Real.\nLet W be a 1 by 8 tensor of Real.\nLet Y be rmsnorm of X with weight W.\n", &["FusedRow"]);
101 AddNorm = "add_norm", Fused, Ledger, ex(
102 "## Main\nLet A be a 1 by 8 tensor of Real.\nLet B be a 1 by 8 tensor of Real.\nLet W be a 1 by 8 tensor of Real.\nLet S be A plus B.\nLet Y be rmsnorm of S with weight W.\n",
103 &["Elementwise", "FusedRow"],
104 );
105 NormThenAdd = "norm_then_add", Fused, Ledger, ex(
106 "## Main\nLet A be a 1 by 8 tensor of Real.\nLet X be a 1 by 8 tensor of Real.\nLet W be a 1 by 8 tensor of Real.\nLet V be a 1 by 8 tensor of Real.\nLet N be rmsnorm of X with weight W.\nLet S be A plus N.\nLet Y be rmsnorm of S with weight V.\n",
107 &["FusedRow", "Elementwise", "FusedRow"],
108 );
109 NormScale = "norm_scale", Fused, Ledger, ex(
110 "## Main\nLet X be a 1 by 8 tensor of Real.\nLet W be a 1 by 8 tensor of Real.\nLet N be rmsnorm of X with weight W.\nLet Y be N scaled by 0.5.\n",
111 &["FusedRow", "Scale"],
112 );
113 NormWeightOffset = "norm_weight_offset", Fused, Book, Exemplar::None("the norm's (1 + w) is the checkpoint's binding, not a statement");
114 NormQuant = "norm_quant", Fused, Ledger, Exemplar::None(NUMERICS);
115 AddNormQuant = "add_norm_quant", Fused, Ledger, Exemplar::None(NUMERICS);
116 DualNorm = "dual_norm", Fused, Book, ex(
117 "## Main\nLet A be a 1 by 8 tensor of Real.\nLet B be a 1 by 8 tensor of Real.\nLet W be a 1 by 8 tensor of Real.\nLet V be a 1 by 8 tensor of Real.\nLet Y be rmsnorm of A with weight W.\nLet Z be rmsnorm of B with weight V.\n",
118 &["FusedRow", "FusedRow"],
119 );
120 GatedNorm = "gated_norm", Fused, Book, ex(
121 "## Main\nLet Q be a 1 by 64 tensor of Real.\nLet K be a 1 by 64 tensor of Real.\nLet V be a 1 by 128 tensor of Real.\nLet Z be a 1 by 128 tensor of Real.\nLet B be a 1 by 4 tensor of Real.\nLet A be a 1 by 4 tensor of Real.\nLet S be a 128 by 32 tensor of Real.\nLet G be a 1 by 32 tensor of Real.\nLet O be gated delta of Q over K and V with gate Z beta B decay A state S norm G with 4 heads 2 groups.\n",
122 &["GatedDelta"],
123 );
124 EmbedNorm = "embed_norm", Fused, Book, ex(
125 "## Main\nLet E be a 16 by 8 tensor of Real.\nLet W be a 1 by 8 tensor of Real.\nLet tok be 3.\nLet X be row tok of E.\nLet Y be rmsnorm of X with weight W.\n",
126 &["RowGather", "FusedRow"],
127 );
128 EmbedScale = "embed_scale", Fused, Ours, ex(
129 "## Main\nLet E be a 16 by 8 tensor of Real.\nLet tok be 3.\nLet X be row tok of E.\nLet Y be X scaled by 2.0.\n",
130 &["RowGather", "Scale"],
131 );
132 GemvNormEpilogue = "gemv_norm_epilogue", Fused, Book, ex(
133 "## Main\nLet X be a 1 by 8 tensor of Real.\nLet M be a 8 by 8 tensor of Real.\nLet R be a 1 by 8 tensor of Real.\nLet W be a 1 by 8 tensor of Real.\nLet P be X matmul M.\nLet S be R plus P.\nLet Y be rmsnorm of S with weight W.\n",
134 &["Matmul", "Elementwise", "FusedRow"],
135 );
136 PrefillNormEpilogues = "prefill_norm_epilogues", Fused, Book, ex(
137 "## Main\nLet X be a 4 by 8 tensor of Real.\nLet M be a 8 by 8 tensor of Real.\nLet R be a 4 by 8 tensor of Real.\nLet W be a 1 by 8 tensor of Real.\nLet P be X matmul M.\nLet S be R plus P.\nLet Y be rmsnorm of S with weight W.\n",
138 &["Matmul", "Elementwise", "FusedRow"],
139 );
140 AttnResidualNorm = "attn_residual_norm", Fused, Book, Exemplar::None(NO_SUGAR);
141 CompensatedResidual = "compensated_residual", Numerics, Book, Exemplar::None(NUMERICS);
142 RecomputeFanout = "recompute_fanout", Fused, Book, ex(
143 "## Main\nLet X be a 1 by 8 tensor of Real.\nLet S be silu of X.\nLet A be S plus X.\nLet B be S hadamard X.\n",
144 &["Silu", "Elementwise", "Elementwise"],
145 );
146 QkNormRope = "qk_norm_rope", Fused, Ledger, ex(
147 "## Main\nLet Q be a 1 by 16 tensor of Real.\nLet N be a 1 by 8 tensor of Real.\nLet RC be a 1 by 4 tensor of Real.\nLet RS be a 1 by 4 tensor of Real.\nLet M be rmsnorm of Q with weight N across 2 heads.\nLet P be rope of M with cos RC and sin RS.\n",
148 &["FusedRow", "Rope"],
149 );
150 QkNormRopeKvAppend = "qk_norm_rope_kv_append", Fused, Ledger, ex(
151 "## Main\nLet K be a 1 by 8 tensor of Real.\nLet N be a 1 by 8 tensor of Real.\nLet RC be a 4 by 4 tensor of Real.\nLet RS be a 4 by 4 tensor of Real.\nLet C be a 4 by 8 tensor of Real.\nLet pos be 2.\nLet M be rmsnorm of K with weight N across 1 heads.\nLet P be rope of M with cos RC and sin RS from position pos across 1 heads.\nSet row pos of C to P.\n",
152 &["FusedRow", "Rope", "SetRow"],
153 );
154 RopeKvAppend = "rope_kv_append", Fused, Ledger, ex(
155 "## Main\nLet K be a 1 by 8 tensor of Real.\nLet RC be a 4 by 4 tensor of Real.\nLet RS be a 4 by 4 tensor of Real.\nLet C be a 4 by 8 tensor of Real.\nLet pos be 2.\nLet P be rope of K with cos RC and sin RS from position pos across 1 heads.\nSet row pos of C to P.\n",
156 &["Rope", "SetRow"],
157 );
158 RopeQkOneLaunch = "rope_qk_one_launch", Fused, Book, ex(
159 "## Main\nLet Q be a 1 by 16 tensor of Real.\nLet K be a 1 by 8 tensor of Real.\nLet RC be a 1 by 4 tensor of Real.\nLet RS be a 1 by 4 tensor of Real.\nLet P be rope of Q with cos RC and sin RS.\nLet R be rope of K with cos RC and sin RS.\n",
160 &["Rope", "Rope"],
161 );
162 QkNormRopeGateSplit = "qk_norm_rope_gate_split", Fused, Book, Exemplar::None("its pattern is a gated attention's query and gate, held by the tiny Qwen3.5 cuts");
163 QkvHeadEpilogue = "qkv_head_epilogue", Fused, Book, ex(
164 "## Main\nLet X be a 1 by 8 tensor of Real.\nLet M be a 8 by 8 tensor of Real.\nLet N be a 1 by 8 tensor of Real.\nLet RC be a 1 by 4 tensor of Real.\nLet RS be a 1 by 4 tensor of Real.\nLet K be X matmul M.\nLet H be rmsnorm of K with weight N across 1 heads.\nLet P be rope of H with cos RC and sin RS.\n",
165 &["Matmul", "FusedRow", "Rope"],
166 );
167 HorizontalNormRopeInsert = "horizontal_norm_rope_insert", Fused, Book, Exemplar::None("its pattern is a layer's query and key branches, held by the tiny Qwen3 cuts");
168 KvCacheQuant = "kv_cache_quant", Numerics, Ledger, Exemplar::None(NUMERICS);
169 HadamardRotation = "hadamard_rotation", Numerics, Book, Exemplar::None(NUMERICS);
170 CrossLayerLaunch = "cross_layer_launch", Fused, Book, ex(
171 "## Main\nLet A be a 1 by 8 tensor of Real.\nLet B be a 1 by 8 tensor of Real.\nLet C be a 4 by 8 tensor of Real.\nLet D be a 4 by 8 tensor of Real.\nLet pos be 2.\nSet row pos of C to A.\nSet row pos of D to B.\n",
172 &["SetRow", "SetRow"],
173 );
174 HostResidentKv = "host_resident_kv", Schedule, Book, Exemplar::None(SCHEDULE);
175 Mla = "mla", Fused, Ledger, Exemplar::None("its pattern is a whole latent attention block, held by the tiny DeepSeek-V2 cuts");
176 MlaPrologue = "mla_prologue", Fused, Book, Exemplar::None("its pattern is a whole latent attention block, held by the tiny DeepSeek-V2 cuts");
177 FlashDecode = "flash_decode", Primitive, Ledger, ex(
178 "## Main\nLet Q be a 1 by 8 tensor of Real.\nLet K be a 4 by 4 tensor of Real.\nLet V be a 4 by 4 tensor of Real.\nLet pos be 3.\nLet C be attention of Q over K and V with 2 heads 1 groups up to pos.\n",
179 &["Attention"],
180 );
181 FlashPrefill = "flash_prefill", Primitive, Ledger, ex(
182 "## Main\nLet Q be a 2 by 8 tensor of Real.\nLet K be a 4 by 4 tensor of Real.\nLet V be a 4 by 4 tensor of Real.\nLet pos be 2.\nLet C be causal attention of Q over K and V with 2 heads 1 groups from pos.\n",
183 &["Attention"],
184 );
185 AttentionVariantsInline = "attention_variants_inline", Primitive, Ledger, ex(
186 "## Main\nLet Q be a 1 by 8 tensor of Real.\nLet K be a 4 by 4 tensor of Real.\nLet V be a 4 by 4 tensor of Real.\nLet pos be 4.\nLet C be attention of Q over K and V with 2 heads 1 groups up to pos within a window of 2.\n",
187 &["Attention"],
188 );
189 Softcap = "softcap", Primitive, Ledger, ex("## Main\nLet X be a 2 by 8 tensor of Real.\nLet Y be X capped at 30.0.\n", &["Softcap"]);
190 AttnOutputQuant = "attn_output_quant", Fused, Ledger, Exemplar::None(NUMERICS);
191 AttnOutputGate = "attn_output_gate", Fused, Ours, ex(
192 "## Main\nLet Q be a 1 by 8 tensor of Real.\nLet K be a 4 by 4 tensor of Real.\nLet V be a 4 by 4 tensor of Real.\nLet G be a 1 by 8 tensor of Real.\nLet pos be 3.\nLet C be attention of Q over K and V with 2 heads 1 groups up to pos.\nLet S be sigmoid of G.\nLet Y be C hadamard S.\n",
193 &["Attention", "Sigmoid", "Elementwise"],
194 );
195 RowWriteQuant = "row_write_quant", Fused, Ours, Exemplar::None(NUMERICS);
196 AttnGqaRowPacking = "attn_gqa_row_packing", Schedule, Book, Exemplar::None(SCHEDULE);
197 AttnLseMerge = "attn_lse_merge", Schedule, Book, Exemplar::None(SCHEDULE);
198 MlaUnabsorbInFold = "mla_unabsorb_in_fold", Fused, Book, Exemplar::None("its pattern is a whole latent attention block, held by the tiny DeepSeek-V2 cuts");
199 MixedBatchAttention = "mixed_batch_attention", Primitive, Book, Exemplar::None(NO_SUGAR);
200 SparseAttention = "sparse_attention", Primitive, Book, Exemplar::None(NO_SUGAR);
201 GluActMul = "glu_act_mul", Fused, Ledger, ex(
202 "## Main\nLet G be a 1 by 8 tensor of Real.\nLet U be a 1 by 8 tensor of Real.\nLet S be sigmoid of G.\nLet Y be U hadamard S.\n",
203 &["Sigmoid", "Elementwise"],
204 );
205 GluActMulQuant = "glu_act_mul_quant", Fused, Ledger, Exemplar::None(NUMERICS);
206 GemvGateUpGlu = "gemv_gate_up_glu", Fused, Ledger, ex(
207 "## Main\nLet X be a 1 by 8 tensor of Real.\nLet G be a 8 by 16 tensor of Real.\nLet U be a 8 by 16 tensor of Real.\nLet A be X matmul G.\nLet B be X matmul U.\nLet H be swiglu of A and B.\n",
208 &["Matmul", "Matmul", "SwiGlu"],
209 );
210 ElementwiseChains = "elementwise_chains", Fused, Ledger, ex(
211 "## Main\nLet A be a 1 by 8 tensor of Real.\nLet B be a 1 by 8 tensor of Real.\nLet C be a 1 by 8 tensor of Real.\nLet S be A plus B.\nLet Y be S hadamard C.\n",
212 &["Elementwise", "Elementwise"],
213 );
214 ElementwiseRegions = "elementwise_regions", Fused, Book, ex(
215 "## Main\nLet A be a 1 by 8 tensor of Real.\nLet B be a 1 by 8 tensor of Real.\nLet S be A plus B.\nLet P be A hadamard B.\nLet Y be S plus P.\n",
216 &["Elementwise", "Elementwise", "Elementwise"],
217 );
218 ReluSqr = "relu_sqr", Fused, Ledger, ex(
219 "## Main\nLet X be a 1 by 8 tensor of Real.\nLet R be relu of X.\nLet Y be R hadamard R.\n",
220 &["Relu", "Elementwise"],
221 );
222 MaskedExpertActivation = "masked_expert_activation", Fused, Book, Exemplar::None(NO_SUGAR);
223 GemmBias = "gemm_bias", Fused, Ledger, ex(
224 "## Main\nLet X be a 1 by 8 tensor of Real.\nLet M be a 8 by 8 tensor of Real.\nLet B be a 1 by 8 tensor of Real.\nLet P be X matmul M.\nLet Y be P plus B.\n",
225 &["Matmul", "Elementwise"],
226 );
227 GemmScale = "gemm_scale", Fused, Ledger, ex(
228 "## Main\nLet X be a 1 by 8 tensor of Real.\nLet M be a 8 by 8 tensor of Real.\nLet P be X matmul M.\nLet Y be P scaled by 0.25.\n",
229 &["Matmul", "Scale"],
230 );
231 MergedQkv = "merged_qkv", Fused, Ledger, ex(
232 "## Main\nLet X be a 1 by 8 tensor of Real.\nLet Q be a 8 by 8 tensor of Real.\nLet K be a 8 by 4 tensor of Real.\nLet V be a 8 by 4 tensor of Real.\nLet A be X matmul Q.\nLet B be X matmul K.\nLet C be X matmul V.\n",
233 &["Matmul", "Matmul", "Matmul"],
234 );
235 MergedGateUp = "merged_gate_up", Fused, Ledger, ex(
236 "## Main\nLet X be a 1 by 8 tensor of Real.\nLet G be a 8 by 16 tensor of Real.\nLet U be a 8 by 16 tensor of Real.\nLet A be X matmul G.\nLet B be X matmul U.\n",
237 &["Matmul", "Matmul"],
238 );
239 GemmDequantInkernel = "gemm_dequant_inkernel", Primitive, Ledger, ex("## Main\nLet X be a 1 by 8 tensor of Real.\nLet M be a 8 by 8 tensor of Real.\nLet Y be X matmul M.\n", &["Matmul"]);
240 AffineInputFold = "affine_input_fold", Fused, Book, ex(
241 "## Main\nLet X be a 1 by 8 tensor of Real.\nLet M be a 8 by 8 tensor of Real.\nLet S be X scaled by 0.5.\nLet Y be S matmul M.\n",
242 &["Scale", "Matmul"],
243 );
244 RouterTopk = "router_topk", Primitive, Ledger, Exemplar::None("its pattern is a whole mixture, held by the tiny Qwen3-MoE cuts");
245 GroupedTopk = "grouped_topk", Primitive, Book, Exemplar::None(NO_SUGAR);
246 RouterSharedGateMerge = "router_shared_gate_merge", Fused, Book, Exemplar::None("its pattern is a whole mixture with a shared expert, held by the tiny DeepSeek-V2 cuts");
247 MoeTokenSort = "moe_token_sort", Fused, Ledger, Exemplar::None("its pattern is a block's mixtures, held by the tiny Qwen3-MoE prefill cuts");
248 MoeDirectPairs = "moe_direct_pairs", Schedule, Book, Exemplar::None(SCHEDULE);
249 MoeGateUpAct = "moe_gate_up_act", Primitive, Ledger, Exemplar::None("its pattern is a whole mixture, held by the tiny Qwen3-MoE cuts");
250 MoeGatherInOperand = "moe_gather_in_operand", Fused, Book, Exemplar::None("its pattern is a whole mixture, held by the tiny Qwen3-MoE cuts");
251 MoeDownCombine = "moe_down_combine", Primitive, Ledger, Exemplar::None("its pattern is a whole mixture, held by the tiny Qwen3-MoE cuts");
252 MoeDeferredFinalize = "moe_deferred_finalize", Fused, Book, Exemplar::None("its pattern is a whole mixture before its residual, held by the tiny Qwen3-MoE cuts");
253 SharedExpertFusion = "shared_expert_fusion", Fused, Ledger, Exemplar::None("its pattern is a whole mixture with a shared expert, held by the tiny DeepSeek-V2 cuts");
254 GdnStep = "gdn_step", Primitive, Ledger, ex(
255 "## Main\nLet Q be a 1 by 64 tensor of Real.\nLet K be a 1 by 64 tensor of Real.\nLet V be a 1 by 128 tensor of Real.\nLet Z be a 1 by 128 tensor of Real.\nLet B be a 1 by 4 tensor of Real.\nLet A be a 1 by 4 tensor of Real.\nLet S be a 128 by 32 tensor of Real.\nLet G be a 1 by 32 tensor of Real.\nLet O be gated delta of Q over K and V with gate Z beta B decay A state S norm G with 4 heads 2 groups.\n",
256 &["GatedDelta"],
257 );
258 GdnInputEpilogue = "gdn_input_epilogue", Fused, Book, Exemplar::None("its pattern is a whole gated-delta input block, held by the tiny Qwen3.5 cuts");
259 GdnDecodeWhole = "gdn_decode_whole", Fused, Book, ex(
260 "## Main\nLet XQ be a 1 by 64 tensor of Real.\nLet XK be a 1 by 64 tensor of Real.\nLet XV be a 1 by 128 tensor of Real.\nLet WQ be a 4 by 64 tensor of Real.\nLet WK be a 4 by 64 tensor of Real.\nLet WV be a 4 by 128 tensor of Real.\nLet CQ be a 4 by 64 tensor of Real.\nLet CK be a 4 by 64 tensor of Real.\nLet CV be a 4 by 128 tensor of Real.\nLet Z be a 1 by 128 tensor of Real.\nLet S be a 128 by 32 tensor of Real.\nLet G be a 1 by 32 tensor of Real.\nLet BR be a 1 by 4 tensor of Real.\nLet AR be a 1 by 4 tensor of Real.\nLet DT be a 1 by 4 tensor of Real.\nLet AL be a 1 by 4 tensor of Real.\nLet YQ be causal conv of XQ with weight WQ state CQ over 4 taps.\nLet YK be causal conv of XK with weight WK state CK over 4 taps.\nLet YV be causal conv of XV with weight WV state CV over 4 taps.\nLet SQ be silu of YQ.\nLet SK be silu of YK.\nLet V be silu of YV.\nLet Q be l2norm of SQ across 2 heads.\nLet K be l2norm of SK across 2 heads.\nLet BT be sigmoid of BR.\nLet DY be decay of AR with bias DT rate AL.\nLet O be gated delta of Q over K and V with gate Z beta BT decay DY state S norm G with 4 heads 2 groups.\n",
261 &["CausalConv", "CausalConv", "CausalConv", "Silu", "Silu", "Silu", "L2Norm", "L2Norm", "Sigmoid", "Decay", "GatedDelta"],
262 );
263 GdnPostConvPrep = "gdn_post_conv_prep", Fused, Book, Exemplar::None("its pattern is a whole gated-delta input block, held by the tiny Qwen3.5 cuts");
264 ConvBiasSilu = "conv_bias_silu", Fused, Ledger, ex(
265 "## Main\nLet X be a 1 by 8 tensor of Real.\nLet W be a 4 by 8 tensor of Real.\nLet C be a 4 by 8 tensor of Real.\nLet Y be causal conv of X with weight W state C over 4 taps.\nLet S be silu of Y.\n",
266 &["CausalConv", "Silu"],
267 );
268 ConvParts = "conv_parts", Fused, Ours, ex(
269 "## Main\nLet X be a 1 by 8 tensor of Real.\nLet Y be a 1 by 8 tensor of Real.\nLet W be a 4 by 8 tensor of Real.\nLet V be a 4 by 8 tensor of Real.\nLet C be a 4 by 8 tensor of Real.\nLet D be a 4 by 8 tensor of Real.\nLet P be causal conv of X with weight W state C over 4 taps.\nLet R be causal conv of Y with weight V state D over 4 taps.\n",
270 &["CausalConv", "CausalConv"],
271 );
272 GdnGateProjections = "gdn_gate_projections", Fused, Ours, ex(
273 "## Main\nLet Q be a 1 by 64 tensor of Real.\nLet K be a 1 by 64 tensor of Real.\nLet V be a 1 by 128 tensor of Real.\nLet Z be a 1 by 128 tensor of Real.\nLet S be a 128 by 32 tensor of Real.\nLet G be a 1 by 32 tensor of Real.\nLet X be a 1 by 8 tensor of Real.\nLet WB be a 8 by 4 tensor of Real.\nLet WA be a 8 by 4 tensor of Real.\nLet DT be a 1 by 4 tensor of Real.\nLet AL be a 1 by 4 tensor of Real.\nLet BR be X matmul WB.\nLet BT be sigmoid of BR.\nLet AR be X matmul WA.\nLet DY be decay of AR with bias DT rate AL.\nLet O be gated delta of Q over K and V with gate Z beta BT decay DY state S norm G with 4 heads 2 groups.\n",
274 &["Matmul", "Sigmoid", "Matmul", "Decay", "GatedDelta"],
275 );
276 GdnGating = "gdn_gating", Fused, Ours, ex(
277 "## Main\nLet Q be a 1 by 64 tensor of Real.\nLet K be a 1 by 64 tensor of Real.\nLet V be a 1 by 128 tensor of Real.\nLet Z be a 1 by 128 tensor of Real.\nLet S be a 128 by 32 tensor of Real.\nLet G be a 1 by 32 tensor of Real.\nLet BR be a 1 by 4 tensor of Real.\nLet AR be a 1 by 4 tensor of Real.\nLet DT be a 1 by 4 tensor of Real.\nLet AL be a 1 by 4 tensor of Real.\nLet BT be sigmoid of BR.\nLet DY be decay of AR with bias DT rate AL.\nLet O be gated delta of Q over K and V with gate Z beta BT decay DY state S norm G with 4 heads 2 groups.\n",
278 &["Sigmoid", "Decay", "GatedDelta"],
279 );
280 FusedSampling = "fused_sampling", Fused, Ledger, ex("## Main\nLet X be a 1 by 8 tensor of Real.\nLet next be argmax of X.\n", &["ArgMax"]);
281 Sampling = "sampling", Primitive, Book, Exemplar::None(NO_SUGAR);
282 LastLayerRows = "last_layer_rows", Fused, Book, Exemplar::None("its pattern is a prefill chunk's last layer, held by the tiny prefill cuts");
283 StridedRead = "strided_read", Placement, Ours, ex(
284 "## Main\nLet X be a 1 by 64 tensor of Real.\nLet RC be a 1 by 4 tensor of Real.\nLet RS be a 1 by 4 tensor of Real.\nLet P be the last 8 of every 16 of X.\nLet Y be rope of P with cos RC and sin RS.\n",
285 &["HeadSlice", "Rope"],
286 );
287 RowWrite = "row_write", Placement, Book, ex(
288 "## Main\nLet X be a 1 by 8 tensor of Real.\nLet M be a 8 by 8 tensor of Real.\nLet T be a 4 by 8 tensor of Real.\nLet pos be 2.\nLet K be X matmul M.\nSet row pos of T to K.\n",
289 &["Matmul", "SetRow"],
290 );
291 JoinInPlace = "join_in_place", Placement, Ours, ex(
292 "## Main\nLet A be a 1 by 8 tensor of Real.\nLet B be a 1 by 4 tensor of Real.\nLet SA be A scaled by 2.0.\nLet SB be B scaled by 3.0.\nLet J be SA joined with SB across 4 heads.\n",
293 &["Scale", "Scale", "Join"],
294 );
295 StridedValues = "strided_values", Placement, Ours, ex(
296 "## Main\nLet Q be a 1 by 8 tensor of Real.\nLet K be a 4 by 8 tensor of Real.\nLet pos be 3.\nLet V be the first 4 of every 8 of K.\nLet C be attention of Q over K and V with 1 heads 1 groups up to pos.\n",
297 &["HeadSlice", "Attention"],
298 );
299 CudaGraphs = "cuda_graphs", Schedule, Ledger, Exemplar::None(SCHEDULE);
300 PersistentLayerMegakernel = "persistent_layer_megakernel", Schedule, Book, Exemplar::None(SCHEDULE);
301 AllreduceNorm = "allreduce_norm", Fused, Ledger, Exemplar::None(MULTI_CHIP);
302 ConvSiluL2norm = "conv_silu_l2norm", Fused, Ours, ex(
303 "## Main\nLet X be a 1 by 64 tensor of Real.\nLet W be a 4 by 64 tensor of Real.\nLet C be a 4 by 64 tensor of Real.\nLet Y be causal conv of X with weight W state C over 4 taps.\nLet S be silu of Y.\nLet N be l2norm of S across 2 heads.\n",
304 &["CausalConv", "Silu", "L2Norm"],
305 );
306 GdnOutputQuant = "gdn_output_quant", Fused, Ours, Exemplar::None(NUMERICS);
307 GemvQuant = "gemv_quant", Fused, Ours, Exemplar::None(NUMERICS);
308 ElementwiseQuant = "elementwise_quant", Fused, Ours, Exemplar::None(NUMERICS);
309}
310
311impl ClassId {
312 pub fn class(self) -> &'static Class {
314 &CLASSES[self as usize]
315 }
316
317 pub fn named(id: &str) -> Option<ClassId> {
319 ClassId::ALL.iter().copied().find(|c| c.id() == id)
320 }
321}
322
323impl std::fmt::Display for ClassId {
324 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
325 f.write_str(self.id())
326 }
327}
328
329pub fn class_of(id: &str) -> Option<&'static Class> {
331 ClassId::named(id).map(ClassId::class)
332}