metrale_kernels/
target_defaults.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2
3//! 2026-09-25: The serving defaults baked from the compiled target's
4//! `kernels/<hw>/HARDWARE.toml` `[defaults]` table.
5//!
6//! Each field is a lever whose default is the target's declaration. The
7//! metrale-model-layers resolver (`layers::ops::target_defaults::resolve`)
8//! lets a parseable environment variable override it and formats the
9//! `target defaults (<hw>): …` line naming every resolved value.
10//!
11//! Owner: kernels crate (target defaults).
12//! Invariants:
13//! - A `[defaults]` key with no arm in `build_defaults::parse_defaults`
14//!   panics the build.
15//! - A target without a `[defaults]` table, or a key it omits, gets
16//!   `build_defaults::baseline`.
17
18/// 2026-09-25: One compiled target's serving defaults. A `const` that
19/// `build.rs` writes into `OUT_DIR/target_ptx.rs` and `lib.rs` `include!`s,
20/// so [`crate::TARGET_DEFAULTS`] is known at compile time.
21#[derive(Debug, Clone, Copy, PartialEq, Eq)]
22pub struct TargetDefaults {
23    /// 2026-09-25: The `kernels/<hw>` directory this binary was built for
24    /// (`METRALE_TARGET_HW`, else `build_diagnose::DEFAULT_HW`). It is set even
25    /// when that tree has no HARDWARE.toml: `read_defaults` then returns
26    /// `baseline(hw)`.
27    pub hw: &'static str,
28    /// 2026-09-25: Upper edge of the BF16 decode head's batched-GEMV band
29    /// (metrale-model-engine `model/trait_impl/lm_head_batched.rs`). The
30    /// resolver clamps it to `DENSE_GEMV_BATCHM_MAX_M` (`resolve_batchm_max`).
31    /// hopper declares 16; gb10, b200 and b300 declare the baseline 8.
32    pub lm_head_batchm_max: u32,
33    /// 2026-09-25: Batched recurrent launch on the GDN decode path
34    /// (metrale-model-layers `layers/qwen3_ssm/gdn_flags.rs`). True on
35    /// hopper.
36    pub ssm_batched_recurrent: bool,
37    /// 2026-09-25: The tensor-core GDN chunked-prefill family, including the
38    /// `gated_delta_rule_chunk_delta_h_tcfuse_x2` state spine
39    /// (`kernels/hopper/common/gated_delta_rule_chunk_tc.cu`), selected in
40    /// metrale-model-layers `layers/ops/ssm_gdn_a3.rs`. True on hopper.
41    pub gdn_prefill_tc: bool,
42    /// 2026-09-25: `dense_gemm_ba_gates_prefill_hopper`, one CTA per token,
43    /// for the SSM BA projection and GDN gate transforms
44    /// (metrale-model-layers `layers/ops/ssm_ba_gates_hopper.rs`). True on
45    /// hopper. Its source exists only under `kernels/hopper`, so the row has
46    /// no effect elsewhere. `SSM-BA-GATES-ATTRIBUTION.md` holds the
47    /// measurements.
48    pub ssm_ba_gates_hopper: bool,
49    /// 2026-09-25: `per_token_group_quant_fp8_hopper`
50    /// (`kernels/hopper/common/fp8_act_quant_hopper.cu`) for the per-token FP8
51    /// activation quantizer. True on hopper. The twin takes a launch only when
52    /// its grid reaches the CTA floor in metrale-model-layers
53    /// `layers/ops/fp8_act_quant_floor.rs`. Its source exists only under
54    /// `kernels/hopper`, so the row has no effect elsewhere.
55    /// `FP8-ACT-QUANT-ATTRIBUTION.md` holds the measurements.
56    pub fp8_act_quant_hopper: bool,
57    /// 2026-09-25: Split SiLU+down on the decode path
58    /// (`ModelLevers::decode_split_silu`). True on every declaring target;
59    /// `METRALE_NO_DECODE_SPLIT_SILU` turns it off.
60    pub decode_split_silu: bool,
61    /// 2026-09-25: How the paged-decode attention path picks its KV split
62    /// count: `legacy`, `auto` or a pinned count, parsed by
63    /// [`crate::attn_splitk::parse`]. hopper declares `auto`; every other
64    /// target declares or defaults to `legacy`.
65    pub attn_decode_splitk: &'static str,
66    /// 2026-09-25: The `w8a16_gemm_m16` tensor-core tier on the dense-FFN
67    /// decode arm (metrale-model-layers `layers/dense_ffn_m16_tc.rs`). False
68    /// on every target, hopper included; the hopper HARDWARE.toml records
69    /// why.
70    pub ffn_m16_tc: bool,
71    /// 2026-09-25: The `w8a16_gemm_m16{,_strided}` tensor-core tiers on the
72    /// decode Q/K/V and o_proj projections. True on hopper.
73    pub attn_m16_tc: bool,
74    /// 2026-09-25: The `dense_gemm_m16_bf16` tensor-core arm on the BF16
75    /// decode head (metrale-model-engine `model/trait_impl/lm_head_batched.rs`).
76    /// True on hopper. It reassociates the K reduction relative to
77    /// `dense_gemv_bf16`, so a near-tie argmax can change.
78    pub lm_head_m16_tc: bool,
79    /// 2026-09-25: `w8a16_gemv_batch16_ncol{2,4}` on the decode attention
80    /// projections (metrale-model-layers
81    /// `layers/qwen3_attention/attn_ncol_gemv.rs`). False on every target.
82    pub attn_ncol_gemv: bool,
83    /// 2026-09-25: One fused `[gate | up]` GEMM at `N = 2 * intermediate`
84    /// instead of two at `N = intermediate` (metrale-model-layers
85    /// `layers/dense_ffn_gateup_fused.rs`). True only on hopper; its
86    /// strided-SiLU consumer (`kernels/hopper/common/silu_mul_strided.cu`)
87    /// exists only in the hopper tree.
88    pub ffn_gateup_fused: bool,
89    /// 2026-09-25: Upper `M` for the W8A8 block-scaled dense-FFN prefill on a
90    /// widening projection (`n > k`: gate/up), read in metrale-model-layers
91    /// `layers/dense_ffn_w8a8_prefill.rs`. `u32::MAX` means no cap. gb10
92    /// declares 64; its HARDWARE.toml records the measurement.
93    pub w8a8_prefill_max_m_widening: u32,
94    /// 2026-09-25: Upper `M` for the same path on a narrowing projection
95    /// (`n <= k`: down). gb10 declares 384. See
96    /// [`Self::w8a8_prefill_max_m_widening`].
97    pub w8a8_prefill_max_m_narrowing: u32,
98}