137 lines
4.8 KiB
Rust
137 lines
4.8 KiB
Rust
//! Root-only ignored smoke of the Strata-prefill MoE router / shared-expert program. It proves transport, order,
|
|
//! geometry, refusal and cleanup of the new program with synthetic data and a host-side stand-in for the closed
|
|
//! cuBLAS adapter. It is NOT the Original17 prefill numerical gate: tensors produced by the real adapter and the
|
|
//! captured prompt-path references are compared by that separate gate.
|
|
use super::*;
|
|
use crate::Driver;
|
|
use std::cell::{Cell, RefCell};
|
|
|
|
const ENABLE: &str = "LELEKA_STRA169_RUN_MOE_PREFILL_BATCH";
|
|
const Q8_0_BLOCK: usize = 34;
|
|
|
|
// ---------------------------------------------------------------- host stand-in for the cuBLAS adapter
|
|
#[derive(Default, Clone, Copy)]
|
|
struct Poison {
|
|
logits: bool,
|
|
sg: bool,
|
|
dm: bool,
|
|
}
|
|
#[derive(Default)]
|
|
struct Captured {
|
|
scratch: Vec<(usize, Vec<u16>)>, // (rows, FP16 matrix prefix) of every f16 call
|
|
x: Vec<(usize, Vec<u8>)>, // (depth, activation bytes) of every call
|
|
y: Vec<(usize, Vec<f32>)>, // (rows, result words) of every call
|
|
}
|
|
struct HostGemm {
|
|
poison: Poison,
|
|
captured: RefCell<Captured>,
|
|
calls: Cell<usize>,
|
|
}
|
|
|
|
struct Fixture<'a> {
|
|
mixed: DeviceBuffer<'a>,
|
|
mixed_h: DeviceBuffer<'a>,
|
|
mixed_bf: DeviceBuffer<'a>,
|
|
mixed_bf_lo: DeviceBuffer<'a>,
|
|
router_w: DeviceBuffer<'a>,
|
|
logits: DeviceBuffer<'a>,
|
|
ids: DeviceBuffer<'a>,
|
|
weights: DeviceBuffer<'a>,
|
|
gate_w: DeviceBuffer<'a>,
|
|
up_w: DeviceBuffer<'a>,
|
|
down_w: DeviceBuffer<'a>,
|
|
scalar_w: DeviceBuffer<'a>,
|
|
scratch: DeviceBuffer<'a>,
|
|
sgate: DeviceBuffer<'a>,
|
|
sup: DeviceBuffer<'a>,
|
|
sh_h: DeviceBuffer<'a>,
|
|
shared: DeviceBuffer<'a>,
|
|
sg: DeviceBuffer<'a>,
|
|
dm: DeviceBuffer<'a>,
|
|
bo: DeviceBuffer<'a>,
|
|
host_mixed: Vec<f32>,
|
|
host_dm: Vec<f32>,
|
|
}
|
|
|
|
#[test]
|
|
#[ignore = "Root-only GPU qualification; never run by the source owner"]
|
|
fn strata_prefill_moe_program_runs_in_order_refuses_earliest_and_cleans_up() {
|
|
assert_eq!(std::env::var(ENABLE).as_deref(), Ok("yes"));
|
|
let driver = Driver::load().unwrap();
|
|
let device = driver.device(0).unwrap();
|
|
let context = device.create_context(512 * 1024 * 1024).unwrap();
|
|
let result = (|| -> Result<()> {
|
|
let mut batch = context.moe_prefill_batch()?;
|
|
if batch.allocated_bytes() != STATUS_BYTES + SLOT_BYTES {
|
|
return mismatch("unexpected owner charge");
|
|
}
|
|
let clean = Poison::default();
|
|
// Router only + shared, combine, lo passes, and the bounds of one window.
|
|
run_case(&context, &mut batch, 3, clean, true, false, None)?;
|
|
run_case(&context, &mut batch, 64, clean, false, false, None)?;
|
|
run_case(&context, &mut batch, 9, clean, true, true, None)?;
|
|
run_case(&context, &mut batch, 1, clean, true, false, None)?;
|
|
// Earliest stage in program order wins and the owner stays usable.
|
|
run_case(
|
|
&context,
|
|
&mut batch,
|
|
4,
|
|
Poison { logits: true, sg: true, ..clean },
|
|
false,
|
|
false,
|
|
Some(MoeBatchStage::Logits),
|
|
)?;
|
|
run_case(&context, &mut batch, 4, Poison { sg: true, ..clean }, false, false, Some(MoeBatchStage::Sg))?;
|
|
run_case(&context, &mut batch, 4, Poison { dm: true, ..clean }, true, false, Some(MoeBatchStage::Bo))?;
|
|
run_case(&context, &mut batch, 3, clean, true, false, None)?;
|
|
// Admission refusals leave nothing behind.
|
|
let idle = HostGemm { poison: clean, captured: RefCell::new(Captured::default()), calls: Cell::new(0) };
|
|
if batch.begin(0, &idle).is_ok() || batch.begin(MOE_BATCH_MAX_TOKENS + 1, &idle).is_ok() {
|
|
return mismatch("token bounds not enforced");
|
|
}
|
|
batch.close()
|
|
})();
|
|
let leaked = context.allocated_bytes();
|
|
assert!(result.is_ok(), "{result:?}");
|
|
assert_eq!(leaked, 0, "bytes still allocated after close");
|
|
}
|
|
|
|
#[path = "moe_prefill_batch_gpu/bytes_of_fn.rs"]
|
|
mod bytes_of_fn;
|
|
#[allow(unused_imports)]
|
|
use bytes_of_fn::bf_bits;
|
|
#[allow(unused_imports)]
|
|
use bytes_of_fn::bf_value;
|
|
#[allow(unused_imports)]
|
|
use bytes_of_fn::bytes_of;
|
|
#[allow(unused_imports)]
|
|
use bytes_of_fn::close;
|
|
#[allow(unused_imports)]
|
|
use bytes_of_fn::f16_bits;
|
|
#[allow(unused_imports)]
|
|
use bytes_of_fn::f16_value;
|
|
#[allow(unused_imports)]
|
|
use bytes_of_fn::halves_of;
|
|
#[allow(unused_imports)]
|
|
use bytes_of_fn::mismatch;
|
|
#[allow(unused_imports)]
|
|
use bytes_of_fn::pattern;
|
|
#[allow(unused_imports)]
|
|
use bytes_of_fn::q8_0;
|
|
#[allow(unused_imports)]
|
|
use bytes_of_fn::read;
|
|
#[allow(unused_imports)]
|
|
use bytes_of_fn::sigm;
|
|
#[allow(unused_imports)]
|
|
use bytes_of_fn::upload;
|
|
#[allow(unused_imports)]
|
|
use bytes_of_fn::words_of;
|
|
#[path = "moe_prefill_batch_gpu/impl_fixture.rs"]
|
|
mod impl_fixture;
|
|
#[allow(unused_imports)]
|
|
use impl_fixture::run_case;
|
|
#[path = "moe_prefill_batch_gpu/check_clean_fn.rs"]
|
|
mod check_clean_fn;
|
|
#[allow(unused_imports)]
|
|
use check_clean_fn::check_clean;
|