cuda-driver (hot path, awaiting the identity gate): 22 OnceLock<bool> env switches become EnvSwitch entries of the settings catalogue; &dyn ArenaMap and &mut dyn Write parameters become generics
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
50084eac2f
commit
dce1676baf
@@ -5,7 +5,7 @@
|
||||
"source": {
|
||||
"allow-unused-imports:leleka-engine-core": 18,
|
||||
"allow-unused-imports:leleka-engine-qwen35-cuda": 166,
|
||||
"dyn-trait:leleka-cuda-driver": 45,
|
||||
"dyn-trait:leleka-cuda-driver": 26,
|
||||
"dyn-trait:leleka-engine-core": 18,
|
||||
"dyn-trait:leleka-engine-fake": 1,
|
||||
"dyn-trait:leleka-engine-qwen35-cuda": 53,
|
||||
@@ -19,7 +19,7 @@
|
||||
"instant-now:strata-control": 15,
|
||||
"instant-now:strata-desktop-core": 4,
|
||||
"path-include:leleka-cuda-driver": 1,
|
||||
"process-global:leleka-cuda-driver": 96,
|
||||
"process-global:leleka-cuda-driver": 43,
|
||||
"process-global:leleka-engine-qwen35-cuda": 59,
|
||||
"process-global:leleka-native-cpu-expert": 27,
|
||||
"process-global:strata-control": 2
|
||||
|
||||
@@ -14,9 +14,8 @@ use super::imp;
|
||||
/// exactly the one of the sealed code.
|
||||
pub(crate) fn stream_k_off() -> bool {
|
||||
use std::sync::atomic::Ordering::Relaxed;
|
||||
static FIXED: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
static PATHS: std::sync::OnceLock<[Option<std::path::PathBuf>; 2]> = std::sync::OnceLock::new();
|
||||
let fixed = *FIXED.get_or_init(|| crate::settings::var_os("LELEKA_MMQ_NO_STREAMK").is_some_and(|v| v != "0"));
|
||||
let fixed = crate::settings::MMQ_NO_STREAMK.get();
|
||||
let paths = PATHS.get_or_init(|| {
|
||||
["LELEKA_MMQ_NO_STREAMK_FILE", "LELEKA_MMQ_STREAMK_FILE"]
|
||||
.map(|name| crate::settings::var_os(name).map(std::path::PathBuf::from))
|
||||
@@ -69,12 +68,11 @@ pub(crate) fn forced_sms(real: u32) -> u32 {
|
||||
/// decode before it) can overlap the next.
|
||||
pub(crate) fn chunk_drain() -> bool {
|
||||
use std::sync::atomic::{AtomicBool, AtomicU64, Ordering::Relaxed};
|
||||
static FIXED: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
static PATH: std::sync::OnceLock<Option<std::path::PathBuf>> = std::sync::OnceLock::new();
|
||||
static START: std::sync::OnceLock<std::time::Instant> = std::sync::OnceLock::new();
|
||||
static LAST_MS: AtomicU64 = AtomicU64::new(u64::MAX);
|
||||
static PRESENT: AtomicBool = AtomicBool::new(false);
|
||||
if *FIXED.get_or_init(|| crate::settings::var_os("LELEKA_CHUNK_DRAIN").is_some_and(|v| v != "0")) {
|
||||
if crate::settings::CHUNK_DRAIN.get() {
|
||||
return true;
|
||||
}
|
||||
let Some(path) =
|
||||
|
||||
@@ -96,9 +96,8 @@ pub(crate) fn note_alloc(what: &str, bytes: usize) {
|
||||
if background() == 0 {
|
||||
return;
|
||||
}
|
||||
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
static SEEN: AtomicUsize = AtomicUsize::new(0);
|
||||
if !*ON.get_or_init(|| crate::settings::var_os("LELEKA_PREFILL_ALLOC_TRACE").is_some_and(|v| v == "1")) {
|
||||
if !crate::settings::PREFILL_ALLOC_TRACE.get() {
|
||||
return;
|
||||
}
|
||||
if SEEN.fetch_add(1, Ordering::Relaxed) < 64 {
|
||||
@@ -141,8 +140,7 @@ pub(crate) fn timed<T>(kind: usize, f: impl FnOnce() -> T) -> T {
|
||||
/// LELEKA_PREFILL_STALL_TRACE=1: every blocking call over 2 ms (first 40 per chunk) with its callers, and a
|
||||
/// per-call-site histogram of the host-to-device / device-to-host / memset / device-to-device calls
|
||||
fn stall_trace() -> bool {
|
||||
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
*ON.get_or_init(|| crate::settings::var_os("LELEKA_PREFILL_STALL_TRACE").is_some_and(|v| v == "1"))
|
||||
crate::settings::PREFILL_STALL_TRACE.get()
|
||||
}
|
||||
/// The driver and runtime frames of a backtrace taken in `timed`, past `timed` itself.
|
||||
fn stall_frames(trace: &str) -> String {
|
||||
@@ -190,12 +188,11 @@ pub fn set_zero_memset(on: bool) {
|
||||
/// Whether all-zero host-to-device uploads become device memsets while a chunk stream is in flight (the upload is a
|
||||
/// copy-engine transfer that waits behind the expert copies; the memset is not).
|
||||
pub(crate) fn zero_memset() -> bool {
|
||||
static ENV: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
background() != 0
|
||||
&& match ZERO_MEMSET.load(Ordering::Relaxed) {
|
||||
0 => false,
|
||||
1 => true,
|
||||
_ => *ENV.get_or_init(|| crate::settings::var_os("LELEKA_PREFILL_ZERO_MEMSET").is_none_or(|v| v != "0")),
|
||||
_ => crate::settings::PREFILL_ZERO_MEMSET.get(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -59,8 +59,7 @@ fn refuse_if_set(row: &[u8], stage: usize, labels: &[&'static str]) -> Result<()
|
||||
|
||||
/// Read once: the switch. Off by default (experimental mode).
|
||||
pub(crate) fn enabled() -> bool {
|
||||
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
*ON.get_or_init(|| crate::settings::var("LELEKA_PREFILL_DEFER_GUARDS").map_or(true, |v| v != "0"))
|
||||
crate::settings::PREFILL_DEFER_GUARDS.get()
|
||||
}
|
||||
|
||||
/// One deferred check: the status words (`bytes` of them at `status`), their `stride`, the streams to order after the
|
||||
|
||||
@@ -158,6 +158,5 @@ impl MappedExpertBank<'_> {
|
||||
}
|
||||
/// `LELEKA_PREFILL_ALIGNED_COPY=0` turns the page-aligned expert copies off (the A/B switch; default on).
|
||||
pub(crate) fn aligned_copy_enabled() -> bool {
|
||||
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
*ON.get_or_init(|| crate::settings::var("LELEKA_PREFILL_ALIGNED_COPY").map_or(true, |v| v != "0"))
|
||||
crate::settings::PREFILL_ALIGNED_COPY.get()
|
||||
}
|
||||
|
||||
+1
-2
@@ -7,8 +7,7 @@ use super::{Arc, Job, NON_FINITE, NORMAL_PRIORITY, Ordering, Shared, thread};
|
||||
/// Bring-up: `LELEKA_BRINGUP_TRACE` and `LELEKA_STAGE_VERIFY` compare every staged buffer with its source when its DMA
|
||||
/// is released.
|
||||
pub(super) fn verify_enabled() -> bool {
|
||||
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
*ON.get_or_init(|| crate::bringup_trace_enabled() && crate::settings::var_os("LELEKA_STAGE_VERIFY").is_some())
|
||||
crate::bringup_trace_enabled() && crate::settings::STAGE_VERIFY.get()
|
||||
}
|
||||
|
||||
/// Memory priority for the page-cache pages of the experts a layer's helpers read (Windows only,
|
||||
|
||||
@@ -9,8 +9,7 @@ use super::{
|
||||
/// `LELEKA_PREFILL_DIAG_SKIP_EXPERT_DMA=1` (EXPERIMENTAL, diagnostic, wrong outputs): the copy ring issues no
|
||||
/// expert copies, so a profile shows the ring's compute alone. Never set in serving.
|
||||
pub(super) fn skip_expert_dma() -> bool {
|
||||
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
*ON.get_or_init(|| crate::settings::var_os("LELEKA_PREFILL_DIAG_SKIP_EXPERT_DMA").is_some_and(|v| v == "1"))
|
||||
crate::settings::PREFILL_DIAG_SKIP_EXPERT_DMA.get()
|
||||
}
|
||||
#[cfg(not(all(
|
||||
feature = "cuda-driver",
|
||||
@@ -62,12 +61,11 @@ impl RingArena for crate::OriginalDeviceGrRead<'_, '_, '_> {
|
||||
}
|
||||
pub(super) fn serialize_ring(which: Drain) -> bool {
|
||||
use std::sync::atomic::{AtomicBool, AtomicU64, Ordering::Relaxed};
|
||||
static FIXED: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
static START: std::sync::OnceLock<std::time::Instant> = std::sync::OnceLock::new();
|
||||
static PATHS: std::sync::OnceLock<[Option<std::path::PathBuf>; 3]> = std::sync::OnceLock::new();
|
||||
static LAST_MS: AtomicU64 = AtomicU64::new(u64::MAX);
|
||||
static PRESENT: [AtomicBool; 3] = [const { AtomicBool::new(false) }; 3];
|
||||
if *FIXED.get_or_init(|| crate::settings::var_os("LELEKA_RING_SERIALIZE").is_some_and(|v| v != "0")) {
|
||||
if crate::settings::RING_SERIALIZE.get() {
|
||||
return true;
|
||||
}
|
||||
let paths = PATHS.get_or_init(|| {
|
||||
|
||||
@@ -15,8 +15,7 @@ impl MtpInt8OwnerId {
|
||||
/// `LELEKA_MTP_SNAPSHOT_MEMO=off`: scan every page of a snapshot on each `validate_snapshot` (the earlier behaviour;
|
||||
/// the A/B control).
|
||||
pub(super) fn snapshot_memo() -> bool {
|
||||
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
*ON.get_or_init(|| !crate::settings::var("LELEKA_MTP_SNAPSHOT_MEMO").is_ok_and(|v| v == "off" || v == "0"))
|
||||
crate::settings::MTP_SNAPSHOT_MEMO.get()
|
||||
}
|
||||
impl Pages {
|
||||
pub(super) fn empty() -> Self {
|
||||
|
||||
+1
-2
@@ -42,8 +42,7 @@ pub(super) fn push(
|
||||
/// byte-identical to the Original's by the probe) instead of the Original's chunk kernel and
|
||||
/// `chain_qsa_decode_merge_n`. sm_120 only.
|
||||
pub(super) fn daily_mtp() -> bool {
|
||||
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
*ON.get_or_init(|| crate::settings::var("LELEKA_SM120_ATTN_DAILY_MTP").is_ok_and(|v| v == "1"))
|
||||
crate::settings::SM120_ATTN_DAILY_MTP.get()
|
||||
}
|
||||
/// `LELEKA_CHAIN` selects a group that launches from the chain module inside the MTP draft program.
|
||||
pub(super) fn chain_mtp_assets() -> bool {
|
||||
|
||||
@@ -134,8 +134,7 @@ pub(crate) fn with_flags<R>(flags: ChainFlags, f: impl FnOnce() -> R) -> R {
|
||||
/// The hyper-connection up projection with 8 columns per block (320 blocks, 5.7 us at 4 rows against 7.7 us for 16
|
||||
/// columns and 8.9 us for the Original's, job 9c1); `LELEKA_CHAIN_UP8=0` selects the 16-column shape.
|
||||
pub(crate) fn up8() -> bool {
|
||||
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
*ON.get_or_init(|| crate::settings::var("LELEKA_CHAIN_UP8").map_or(true, |v| v != "0"))
|
||||
crate::settings::CHAIN_UP8.get()
|
||||
}
|
||||
|
||||
/// The hyper-connection down projection tiled over rows AND tokens (8 rows x 2 tokens per block, `ceil(T / 2)` x 41
|
||||
@@ -148,8 +147,7 @@ pub(crate) fn down_tiled() -> bool {
|
||||
1 => return true,
|
||||
_ => {}
|
||||
}
|
||||
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
*ON.get_or_init(|| crate::settings::var("LELEKA_CHAIN_DOWN").map_or(true, |v| v != "w8"))
|
||||
crate::settings::CHAIN_DOWN.get()
|
||||
}
|
||||
|
||||
/// Per-arm override of the down-projection shape for paired A/B arms inside one process (-1: none, 0: the 8-row x
|
||||
|
||||
@@ -70,7 +70,7 @@ pub struct OriginalVerifyDiag {
|
||||
}
|
||||
impl OriginalVerifyDiag {
|
||||
/// Same line as `Verifier::diag` (#31).
|
||||
pub fn write_to(&self, f: &mut dyn Write) -> std::io::Result<()> {
|
||||
pub fn write_to(&self, f: &mut (impl Write + ?Sized)) -> std::io::Result<()> {
|
||||
writeln!(
|
||||
f,
|
||||
" verify window{}: {} tokens at position {}, host at layer step {}; the GPU rang {}; \
|
||||
@@ -158,7 +158,7 @@ pub fn original_verify_diagnostics() -> Vec<OriginalVerifyDiag> {
|
||||
registry().iter().map(|s| snapshot(s)).collect()
|
||||
}
|
||||
/// `diag_active_verifier` for all live verifiers.
|
||||
pub fn write_original_verify_diagnostics(f: &mut dyn Write) -> std::io::Result<()> {
|
||||
pub fn write_original_verify_diagnostics(f: &mut (impl Write + ?Sized)) -> std::io::Result<()> {
|
||||
for d in original_verify_diagnostics() {
|
||||
d.write_to(f)?;
|
||||
}
|
||||
@@ -210,7 +210,7 @@ fn wait_drained(live: &[Arc<Shared>], start: Instant, timeout: Duration) -> bool
|
||||
drained
|
||||
}
|
||||
|
||||
fn note_released(f: &mut dyn Write, drained: bool, start: Instant, timeout: Duration) {
|
||||
fn note_released(f: &mut (impl Write + ?Sized), drained: bool, start: Instant, timeout: Duration) {
|
||||
let _ = if drained {
|
||||
writeln!(
|
||||
f,
|
||||
|
||||
@@ -39,8 +39,7 @@ pub(crate) static DRAFT_COMMIT_QSA: AssetSpec = AssetSpec {
|
||||
/// `LELEKA_DRAFT_FUSED_COMMIT=on|1`: record the commit graph with the fused kernels. Read once per process (it
|
||||
/// decides which kernels the commit graph records).
|
||||
pub(crate) fn fused_commit() -> bool {
|
||||
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
*ON.get_or_init(|| fused_commit_from(crate::settings::var("LELEKA_DRAFT_FUSED_COMMIT").ok().as_deref()))
|
||||
crate::settings::DRAFT_FUSED_COMMIT.get()
|
||||
}
|
||||
pub(crate) fn fused_commit_from(value: Option<&str>) -> bool {
|
||||
value.is_some_and(|v| matches!(v.trim().to_ascii_lowercase().as_str(), "on" | "1" | "yes" | "true"))
|
||||
|
||||
@@ -137,7 +137,7 @@ pub(super) fn check_rows(geo: &OriginalVerifyGeometry, rows: Rows) -> Result<()>
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
pub(super) fn row_span(arena: &dyn ArenaMap, name: &str, row: usize, row_bytes: usize) -> Result<u64> {
|
||||
pub(super) fn row_span(arena: &(impl ArenaMap + ?Sized), name: &str, row: usize, row_bytes: usize) -> Result<u64> {
|
||||
arena.span(name, row * row_bytes, row_bytes)
|
||||
}
|
||||
pub(super) fn refuse(producer: &'static str) -> Error {
|
||||
|
||||
@@ -47,7 +47,7 @@ pub(super) fn hc_read_of_rows(
|
||||
|
||||
/// The per-row argument spans of the window rows; the attention half reads `inj2` and writes `inj`, the FFN the
|
||||
/// reverse.
|
||||
pub(super) fn hc_read_rows(arena: &dyn ArenaMap, half: HcHalf, rows: Rows) -> Result<Vec<RowArgs>> {
|
||||
pub(super) fn hc_read_rows(arena: &(impl ArenaMap + ?Sized), half: HcHalf, rows: Rows) -> Result<Vec<RowArgs>> {
|
||||
let (inj_prev_name, inj_out_name) = match half {
|
||||
HcHalf::Attention => ("inj2", "inj"),
|
||||
HcHalf::Ffn => ("inj", "inj2"),
|
||||
@@ -184,7 +184,7 @@ pub(super) fn hc_read_up(chain_gr: bool, full: Vec<u64>) -> Result<Launch> {
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
/// `gr_write(Rt(t), bo_ + t*N, inj2_ + t*HC, gs, Rt(t), cs)` for one window row: `native_gr_post`.
|
||||
pub(super) fn write_row(arena: &dyn ArenaMap, cfg: &GrConfig, row: usize, producer: &'static str) -> Result<Launch> {
|
||||
pub(super) fn write_row(arena: &(impl ArenaMap + ?Sized), cfg: &GrConfig, row: usize, producer: &'static str) -> Result<Launch> {
|
||||
if !cfg.native_mmvf {
|
||||
return Err(refuse(producer));
|
||||
}
|
||||
@@ -201,7 +201,7 @@ pub(super) fn write_row(arena: &dyn ArenaMap, cfg: &GrConfig, row: usize, produc
|
||||
|
||||
/// `for t in [tb, te): gr_write(Rt(t), bo_+t*N, inj2_+t*HC, gs, Rt(t), cs)` of the last layer.
|
||||
pub(crate) fn plan_final_write(
|
||||
arena: &dyn ArenaMap,
|
||||
arena: &(impl ArenaMap + ?Sized),
|
||||
geo: &OriginalVerifyGeometry,
|
||||
cfg: &GrConfig,
|
||||
rows: Rows,
|
||||
@@ -253,7 +253,7 @@ pub(crate) fn plan_head_mix(
|
||||
|
||||
/// The five launches of one head row `t`: norm, down gemv, down-silu, up gemv, final pre-mix.
|
||||
fn head_mix_row(
|
||||
arena: &dyn ArenaMap,
|
||||
arena: &(impl ArenaMap + ?Sized),
|
||||
geo: &OriginalVerifyGeometry,
|
||||
w: &HeadAddrs,
|
||||
mixed_base: u64,
|
||||
|
||||
@@ -91,7 +91,7 @@ impl PleScratch {
|
||||
}
|
||||
|
||||
/// key = ple_key @ emb (BF16 MMVF, or q8_1 quantize + MMVQ for a native key).
|
||||
fn plan_ple_key(arena: &dyn ArenaMap, ple: &PleConfig, a: &PleAddrs, emb: u64, out: &mut Vec<Launch>) -> Result<()> {
|
||||
fn plan_ple_key(arena: &(impl ArenaMap + ?Sized), ple: &PleConfig, a: &PleAddrs, emb: u64, out: &mut Vec<Launch>) -> Result<()> {
|
||||
let key = PleScratch::at(a.scratch).key;
|
||||
match a.key {
|
||||
PleKey::Bf16(w) => out.push(plan_bf16_gemv(
|
||||
|
||||
@@ -123,7 +123,7 @@ pub fn top_k(row: &[f32], k: usize) -> Vec<(i32, f64)> {
|
||||
|
||||
/// One tab-separated line, same columns as Original:
|
||||
/// `pos target logprob top top_logprob hit extra_logprob target_without_extra [id:logprob ...]`.
|
||||
pub fn write_row_line(out: &mut dyn Write, r: &RowLogprob, topk: &[(i32, f64)]) -> std::io::Result<()> {
|
||||
pub fn write_row_line(out: &mut (impl Write + ?Sized), r: &RowLogprob, topk: &[(i32, f64)]) -> std::io::Result<()> {
|
||||
write!(
|
||||
out,
|
||||
"{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}",
|
||||
@@ -159,7 +159,7 @@ pub struct LogprobReadout {
|
||||
|
||||
/// The whole readout over `rows` consecutive logit rows of width `vocab`.
|
||||
pub fn write_window_logprobs(
|
||||
out: &mut dyn Write,
|
||||
out: &mut (impl Write + ?Sized),
|
||||
rows: LogitRows<'_>,
|
||||
targets: &[i32],
|
||||
first_position: i64,
|
||||
|
||||
@@ -52,8 +52,7 @@ mod enabled {
|
||||
/// runs over a whole verify group's CPU output (rows x top-10 x hidden floats) once per layer on the decode
|
||||
/// critical path. `LELEKA_SINK_SCAN=legacy` (A/B arm) keeps the element-wise `any` scan.
|
||||
pub(crate) fn all_finite(rows: &[f32]) -> bool {
|
||||
static LEGACY: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
if *LEGACY.get_or_init(|| crate::settings::var("LELEKA_SINK_SCAN").as_deref() == Ok("legacy")) {
|
||||
if crate::settings::SINK_SCAN_LEGACY.get() {
|
||||
return !rows.iter().any(|v| !v.is_finite());
|
||||
}
|
||||
let mut bad = 0u32;
|
||||
|
||||
@@ -234,14 +234,14 @@ pub(super) fn check_rows(g: &OriginalVerifyGeometry, rows: Rows) -> Result<usize
|
||||
Ok(rows.len())
|
||||
}
|
||||
/// `n_elems` consecutive `elem`-byte items of a span starting at item `first`.
|
||||
pub(super) fn items(arena: &dyn ArenaMap, name: &str, first: usize, count: usize, elem: usize) -> Result<u64> {
|
||||
pub(super) fn items(arena: &(impl ArenaMap + ?Sized), name: &str, first: usize, count: usize, elem: usize) -> Result<u64> {
|
||||
arena.span(name, first * elem, count * elem)
|
||||
}
|
||||
pub(super) fn f32s(arena: &dyn ArenaMap, name: &str, first: usize, count: usize) -> Result<u64> {
|
||||
pub(super) fn f32s(arena: &(impl ArenaMap + ?Sized), name: &str, first: usize, count: usize) -> Result<u64> {
|
||||
items(arena, name, first, count, 4)
|
||||
}
|
||||
/// Word `word` of group `group`'s device plan copy (`plan_ + group * (plan_i32_ + 16)`).
|
||||
pub(super) fn plan_word(arena: &dyn ArenaMap, g: &OriginalVerifyGeometry, group: usize, word: usize) -> Result<u64> {
|
||||
pub(super) fn plan_word(arena: &(impl ArenaMap + ?Sized), g: &OriginalVerifyGeometry, group: usize, word: usize) -> Result<u64> {
|
||||
let layout = PlanLayout::new(g.max_t * g.k);
|
||||
if group > 1 || word >= layout.words {
|
||||
return Err(Error::InvalidQwenShape);
|
||||
|
||||
@@ -196,7 +196,7 @@ pub(crate) fn quant_source_width(geo: &OriginalVerifyGeometry, source: QuantSour
|
||||
/// `native_quantize_q8_1(src + tb*width, xq_, width, n)`: the group's rows are quantized into the
|
||||
/// START of `xq_` (every group overwrites it; the MMVQs that follow read it from row 0).
|
||||
pub(crate) fn plan_window_quantize(
|
||||
arena: &dyn ArenaMap,
|
||||
arena: &(impl ArenaMap + ?Sized),
|
||||
geo: &OriginalVerifyGeometry,
|
||||
source: QuantSource,
|
||||
rows: Rows,
|
||||
@@ -272,7 +272,7 @@ pub(super) fn projection_first_row(
|
||||
/// `native_mmvq(type, w, xq_, y + tb*rows_stride, n_in, n_out, n)`: the weight reads the q8_1 rows the
|
||||
/// preceding `plan_window_quantize` left at the start of `xq_`.
|
||||
pub(crate) fn plan_window_mmvq(
|
||||
arena: &dyn ArenaMap,
|
||||
arena: &(impl ArenaMap + ?Sized),
|
||||
geo: &OriginalVerifyGeometry,
|
||||
site: WindowProjectionSite,
|
||||
weight: &NativeWeight,
|
||||
|
||||
@@ -9,8 +9,7 @@ use super::{
|
||||
|
||||
/// `STRATA_COMMIT_SYNC`, read once (it sat on the per-round commit path).
|
||||
pub(super) fn commit_sync_forced() -> bool {
|
||||
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
*ON.get_or_init(|| crate::settings::var_os("STRATA_COMMIT_SYNC").is_some())
|
||||
crate::settings::STRATA_COMMIT_SYNC.get()
|
||||
}
|
||||
impl OriginalVerifyCpuSink<'_, '_> {
|
||||
pub fn with_output<R>(&mut self, produce: impl FnOnce(&mut [f32]) -> Result<R>) -> Result<R> {
|
||||
|
||||
@@ -163,7 +163,7 @@ impl<'ctx, R: OriginalVerifyGraphResources<'ctx> + OriginalNativeHeadGraphResour
|
||||
pub fn diag(&self) -> Option<OriginalVerifyDiag> {
|
||||
self.registration.as_ref().map(diag::Registration::snapshot)
|
||||
}
|
||||
pub fn write_diag(&self, f: &mut dyn Write) -> std::io::Result<()> {
|
||||
pub fn write_diag(&self, f: &mut (impl Write + ?Sized)) -> std::io::Result<()> {
|
||||
match self.diag() {
|
||||
Some(d) => d.write_to(f),
|
||||
None => Ok(()),
|
||||
|
||||
+2
-2
@@ -75,10 +75,10 @@ impl<'ctx, R: OriginalVerifyGraphResources<'ctx> + OriginalNativeHeadGraphResour
|
||||
}
|
||||
/// `Verifier::window_logprobs` with `STRATA_LOGPOS_TOPK` from the environment: one line per row of
|
||||
/// the last completed window. `targets[t]` is the token at `first_position + t + 1`.
|
||||
pub fn window_logprobs(&self, targets: &[i32], extra_id: i32, out: &mut dyn Write) -> Result<()> {
|
||||
pub fn window_logprobs(&self, targets: &[i32], extra_id: i32, out: &mut (impl Write + ?Sized)) -> Result<()> {
|
||||
self.window_logprobs_topk(targets, extra_id, logpos_topk_from_environment(), out)
|
||||
}
|
||||
pub fn window_logprobs_topk(&self, targets: &[i32], extra_id: i32, topk: usize, out: &mut dyn Write) -> Result<()> {
|
||||
pub fn window_logprobs_topk(&self, targets: &[i32], extra_id: i32, topk: usize, out: &mut (impl Write + ?Sized)) -> Result<()> {
|
||||
self.with_completed_logits(|logits, rows, vocabulary, first| {
|
||||
if targets.is_empty() || targets.len() > rows {
|
||||
return Err(Error::InvalidQwenShape);
|
||||
|
||||
+1
-2
@@ -9,8 +9,7 @@ use super::{
|
||||
|
||||
/// `LELEKA_WINDOW_MODULE_CACHE=off`: every verifier bank loads its window modules again (A/B control).
|
||||
pub(in super::super) fn share_window_modules() -> bool {
|
||||
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
*ON.get_or_init(|| !crate::settings::var("LELEKA_WINDOW_MODULE_CACHE").is_ok_and(|v| v == "off" || v == "0"))
|
||||
crate::settings::WINDOW_MODULE_CACHE.get()
|
||||
}
|
||||
pub(in super::super) fn admission(c: &Context<'_>, n: usize) -> Result<()> {
|
||||
let need = n.checked_add(RESERVE).ok_or(Error::InvalidSize)?;
|
||||
|
||||
@@ -41,13 +41,9 @@ pub(crate) const GDN_REC: usize = 16;
|
||||
pub(crate) const GDN_REC_KH: usize = 17;
|
||||
pub(crate) const GDN_OUT_NORM_Y16: usize = 18;
|
||||
|
||||
fn switch(name: &'static str, cell: &'static std::sync::OnceLock<bool>) -> bool {
|
||||
*cell.get_or_init(|| crate::settings::var(name).map_or(true, |v| v != "0"))
|
||||
}
|
||||
/// `LELEKA_PREFILL_FUSED_SCANS=0`: the separate finite-guard kernels of the GR read/inject and the GDN chain (A/B arm).
|
||||
pub(crate) fn fused_scans() -> bool {
|
||||
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
switch("LELEKA_PREFILL_FUSED_SCANS", &ON)
|
||||
crate::settings::PREFILL_FUSED_SCANS.get()
|
||||
}
|
||||
/// `LELEKA_PREFILL_FAST_REC=1` (EXPERIMENTAL, off by default): the two-barrier recurrence kernel. Bit-identical to the
|
||||
/// original on the 3080 probe but not faster there, so it is not the default until a 5090 A/B shows a gain.
|
||||
@@ -57,8 +53,7 @@ pub(crate) fn fast_rec() -> bool {
|
||||
2 => return true,
|
||||
_ => {}
|
||||
}
|
||||
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
*ON.get_or_init(|| crate::settings::var("LELEKA_PREFILL_FAST_REC").is_ok_and(|v| v == "1"))
|
||||
crate::settings::PREFILL_FAST_REC.get()
|
||||
}
|
||||
/// Per-arm override of the prompt recurrence for paired A/B passes in one process (-1: none, 0: the sealed Original
|
||||
/// kernel, 1: the kh kernel, 2: the two-barrier kernel).
|
||||
@@ -75,8 +70,7 @@ pub(crate) fn gdn_nostore() -> bool {
|
||||
1 => return true,
|
||||
_ => {}
|
||||
}
|
||||
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
*ON.get_or_init(|| crate::settings::var("LELEKA_PREFILL_GDN_NOSTORE").map_or(GDN_NOSTORE_DEFAULT, |v| v != "0"))
|
||||
crate::settings::PREFILL_GDN_NOSTORE.get()
|
||||
}
|
||||
/// Default of `LELEKA_PREFILL_GDN_NOSTORE` (flipped after its identity gate).
|
||||
pub(crate) const GDN_NOSTORE_DEFAULT: bool = true;
|
||||
@@ -95,12 +89,7 @@ pub(crate) fn gdn_kh_requested() -> bool {
|
||||
0 | 2 => return false,
|
||||
_ => {}
|
||||
}
|
||||
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
*ON.get_or_init(|| match crate::settings::var("LELEKA_PREFILL_GDN_KH").ok().as_deref() {
|
||||
Some("1") => true,
|
||||
Some(_) => false,
|
||||
None => GDN_KH_DEFAULT,
|
||||
})
|
||||
crate::settings::PREFILL_GDN_KH.get()
|
||||
}
|
||||
/// Default of `LELEKA_PREFILL_GDN_KH` (flipped only after its gates, see the plan).
|
||||
pub(crate) const GDN_KH_DEFAULT: bool = false;
|
||||
@@ -129,8 +118,7 @@ pub(crate) fn gdn_kh_usable(context: &crate::Context<'_>) -> bool {
|
||||
}
|
||||
/// `LELEKA_PREFILL_FAST_DEQUANT=0`: the original one-thread-per-32-values GDN weight dequantization (A/B arm).
|
||||
pub(crate) fn fast_dequant() -> bool {
|
||||
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
switch("LELEKA_PREFILL_FAST_DEQUANT", &ON)
|
||||
crate::settings::PREFILL_FAST_DEQUANT.get()
|
||||
}
|
||||
/// Frozen by `scripts/gpu-bringup/seal_pins.py` after `compile_assets.py` (extra-seal-plan.json, group prefill-stage).
|
||||
pub(crate) const PIN: PtxPin = PtxPin {
|
||||
|
||||
@@ -44,8 +44,7 @@ pub(crate) fn enabled() -> bool {
|
||||
1 => return true,
|
||||
_ => {}
|
||||
}
|
||||
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
*ON.get_or_init(|| crate::settings::var("LELEKA_QSA_LATE").map_or(true, |v| v != "0"))
|
||||
crate::settings::QSA_LATE.get()
|
||||
}
|
||||
/// Row 2.5: which top-k kernel a prompt tile of `tile_reach` indexer blocks takes. `LELEKA_QSA_TOPK=fast` keeps
|
||||
/// `leleka_qsa_topk_fast` (256 threads); `wide` takes the 1,024-thread kernel from `TOPK_WIDE_MIN_BLOCKS` on (Strata
|
||||
@@ -60,15 +59,10 @@ pub fn set_topk_override(value: i8) {
|
||||
/// Default of `LELEKA_QSA_TOPK` (flipped after its R gate).
|
||||
pub(crate) const TOPK_DEFAULT_WIDE: bool = true;
|
||||
pub(crate) fn topk_entry(tile_reach: usize) -> (usize, u32) {
|
||||
static WIDE: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
let wide = match TOPK_OVERRIDE.load(std::sync::atomic::Ordering::Relaxed) {
|
||||
0 => false,
|
||||
1 => true,
|
||||
_ => *WIDE.get_or_init(|| match crate::settings::var("LELEKA_QSA_TOPK").ok().as_deref() {
|
||||
Some("wide") => true,
|
||||
Some(_) => false,
|
||||
None => TOPK_DEFAULT_WIDE,
|
||||
}),
|
||||
_ => crate::settings::QSA_TOPK_WIDE.get(),
|
||||
};
|
||||
static SAID: std::sync::Once = std::sync::Once::new();
|
||||
SAID.call_once(|| {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//! 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 leleka_cuda_model::env_switch::{EnvSwitch, rules};
|
||||
use std::env::{self, VarError};
|
||||
use std::ffi::{OsStr, OsString};
|
||||
|
||||
@@ -15,3 +16,69 @@ pub(crate) fn var<K: AsRef<OsStr>>(key: K) -> Result<String, VarError> {
|
||||
pub(crate) fn var_os<K: AsRef<OsStr>>(key: K) -> Option<OsString> {
|
||||
env::var_os(key)
|
||||
}
|
||||
|
||||
// The operator's on/off switches: each is read from its variable on first use and cached
|
||||
// (`leleka_cuda_model::env_switch`).
|
||||
pub(crate) static CHAIN_UP8: EnvSwitch = EnvSwitch::new("LELEKA_CHAIN_UP8", rules::is_unset_or_not_zero);
|
||||
pub(crate) static CHUNK_DRAIN: EnvSwitch = EnvSwitch::new("LELEKA_CHUNK_DRAIN", rules::is_set_and_not_zero);
|
||||
pub(crate) static MMQ_NO_STREAMK: EnvSwitch = EnvSwitch::new("LELEKA_MMQ_NO_STREAMK", rules::is_set_and_not_zero);
|
||||
pub(crate) static MTP_SNAPSHOT_MEMO: EnvSwitch = EnvSwitch::new("LELEKA_MTP_SNAPSHOT_MEMO", rules::is_unset_or_not_off);
|
||||
pub(crate) static PREFILL_ALIGNED_COPY: EnvSwitch =
|
||||
EnvSwitch::new("LELEKA_PREFILL_ALIGNED_COPY", rules::is_unset_or_not_zero);
|
||||
pub(crate) static PREFILL_ALLOC_TRACE: EnvSwitch = EnvSwitch::new("LELEKA_PREFILL_ALLOC_TRACE", rules::is_one);
|
||||
pub(crate) static PREFILL_DEFER_GUARDS: EnvSwitch =
|
||||
EnvSwitch::new("LELEKA_PREFILL_DEFER_GUARDS", rules::is_unset_or_not_zero);
|
||||
pub(crate) static PREFILL_DIAG_SKIP_EXPERT_DMA: EnvSwitch =
|
||||
EnvSwitch::new("LELEKA_PREFILL_DIAG_SKIP_EXPERT_DMA", rules::is_one);
|
||||
pub(crate) static PREFILL_FAST_REC: EnvSwitch = EnvSwitch::new("LELEKA_PREFILL_FAST_REC", rules::is_one);
|
||||
pub(crate) static PREFILL_STALL_TRACE: EnvSwitch = EnvSwitch::new("LELEKA_PREFILL_STALL_TRACE", rules::is_one);
|
||||
pub(crate) static PREFILL_ZERO_MEMSET: EnvSwitch =
|
||||
EnvSwitch::new("LELEKA_PREFILL_ZERO_MEMSET", rules::is_unset_or_not_zero);
|
||||
pub(crate) static QSA_LATE: EnvSwitch = EnvSwitch::new("LELEKA_QSA_LATE", rules::is_unset_or_not_zero);
|
||||
pub(crate) static RING_SERIALIZE: EnvSwitch = EnvSwitch::new("LELEKA_RING_SERIALIZE", rules::is_set_and_not_zero);
|
||||
pub(crate) static SM120_ATTN_DAILY_MTP: EnvSwitch = EnvSwitch::new("LELEKA_SM120_ATTN_DAILY_MTP", rules::is_one);
|
||||
pub(crate) static STRATA_COMMIT_SYNC: EnvSwitch = EnvSwitch::new("STRATA_COMMIT_SYNC", rules::is_set);
|
||||
pub(crate) static VRAM_LEDGER: EnvSwitch = EnvSwitch::new("LELEKA_VRAM_LEDGER", rules::is_one);
|
||||
pub(crate) static WINDOW_MODULE_CACHE: EnvSwitch =
|
||||
EnvSwitch::new("LELEKA_WINDOW_MODULE_CACHE", rules::is_unset_or_not_off);
|
||||
|
||||
// Switches whose rule is not one of the plain ones: the default is a named constant of the module that uses the switch.
|
||||
pub(crate) static PREFILL_FUSED_SCANS: EnvSwitch =
|
||||
EnvSwitch::new("LELEKA_PREFILL_FUSED_SCANS", rules::is_unset_or_not_zero);
|
||||
pub(crate) static PREFILL_FAST_DEQUANT: EnvSwitch =
|
||||
EnvSwitch::new("LELEKA_PREFILL_FAST_DEQUANT", rules::is_unset_or_not_zero);
|
||||
pub(crate) static STAGE_VERIFY: EnvSwitch = EnvSwitch::new("LELEKA_STAGE_VERIFY", rules::is_set);
|
||||
pub(crate) static CHAIN_DOWN: EnvSwitch = EnvSwitch::new("LELEKA_CHAIN_DOWN", chain_down);
|
||||
pub(crate) static DRAFT_FUSED_COMMIT: EnvSwitch = EnvSwitch::new("LELEKA_DRAFT_FUSED_COMMIT", draft_fused_commit);
|
||||
pub(crate) static SINK_SCAN_LEGACY: EnvSwitch = EnvSwitch::new("LELEKA_SINK_SCAN", is_legacy);
|
||||
pub(crate) static PREFILL_GDN_NOSTORE: EnvSwitch = EnvSwitch::new("LELEKA_PREFILL_GDN_NOSTORE", gdn_nostore);
|
||||
pub(crate) static PREFILL_GDN_KH: EnvSwitch = EnvSwitch::new("LELEKA_PREFILL_GDN_KH", gdn_kh);
|
||||
pub(crate) static QSA_TOPK_WIDE: EnvSwitch = EnvSwitch::new("LELEKA_QSA_TOPK", qsa_topk_wide);
|
||||
|
||||
fn text(value: Option<&OsStr>) -> Option<&str> {
|
||||
value.and_then(OsStr::to_str)
|
||||
}
|
||||
|
||||
fn draft_fused_commit(value: Option<&OsStr>) -> bool {
|
||||
crate::original_verify::draft::fused_commit_from(text(value))
|
||||
}
|
||||
|
||||
fn chain_down(value: Option<&OsStr>) -> bool {
|
||||
text(value).is_none_or(|v| v != "w8")
|
||||
}
|
||||
|
||||
fn is_legacy(value: Option<&OsStr>) -> bool {
|
||||
text(value) == Some("legacy")
|
||||
}
|
||||
|
||||
fn gdn_nostore(value: Option<&OsStr>) -> bool {
|
||||
text(value).map_or(crate::prefill_stage::GDN_NOSTORE_DEFAULT, |v| v != "0")
|
||||
}
|
||||
|
||||
fn gdn_kh(value: Option<&OsStr>) -> bool {
|
||||
text(value).map_or(crate::prefill_stage::GDN_KH_DEFAULT, |v| v == "1")
|
||||
}
|
||||
|
||||
fn qsa_topk_wide(value: Option<&OsStr>) -> bool {
|
||||
text(value).map_or(crate::qsa_late::TOPK_DEFAULT_WIDE, |v| v == "wide")
|
||||
}
|
||||
|
||||
@@ -183,8 +183,7 @@ fn state() -> &'static Mutex<Ledger> {
|
||||
|
||||
/// `LELEKA_VRAM_LEDGER=1`.
|
||||
pub fn enabled() -> bool {
|
||||
static ON: OnceLock<bool> = OnceLock::new();
|
||||
*ON.get_or_init(|| crate::settings::var_os("LELEKA_VRAM_LEDGER").is_some_and(|v| v == "1"))
|
||||
crate::settings::VRAM_LEDGER.get()
|
||||
}
|
||||
|
||||
pub(crate) fn note_alloc(address: u64, bytes: usize) {
|
||||
|
||||
Reference in New Issue
Block a user