prefill_stage: throughput probe of the hyper-connection kernels at T=8192 (1.5-1.6 TB/s: on the traffic floor); plan updated
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
e28f5de2cd
commit
7fc985e454
@@ -170,3 +170,56 @@ fn gr_fused_guards_equal_the_separate_guard_kernels_bit_for_bit() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Timing only (row "256k prefill gap"): the three hyper-connection kernels of the prompt at the real chunk size (T = 8192 rows, a 335.5 MB residual
|
||||
/// R) against the bytes they must move, as achieved GB/s. Prints `PREFILL-GR-TRAFFIC`. The RTX 5090's DRAM peak is 1.79 TB/s (about 1.5 TB/s is what a copy sustains).
|
||||
#[test]
|
||||
#[ignore = "Root-only: needs a CUDA device"]
|
||||
fn gr_kernels_run_near_their_traffic_floor_at_chunk_size() {
|
||||
assert_eq!(std::env::var(ENABLE).ok().as_deref(), Some("yes"));
|
||||
let driver = crate::Driver::load().expect("driver");
|
||||
let device = driver.device(0).expect("device");
|
||||
let context = device.create_context(6usize << 30).expect("context");
|
||||
let workspace = context.native_batch_workspace().expect("workspace");
|
||||
let guard = context.enter().expect("enter");
|
||||
let stage = KernelModule::load(crate::prefill_stage::PTX, crate::prefill_stage::ENTRIES).expect("stage module");
|
||||
guard.finish().expect("finish");
|
||||
let t = 8192usize;
|
||||
let mut rng = Rng(0x1234_5678_9abc_def0);
|
||||
let rnd = |rng: &mut Rng, n: usize, scale: f32| -> Vec<f32> { (0..n).map(|_| ((rng.next() % 20001) as f32 / 10000.0 - 1.0) * scale).collect() };
|
||||
let (r, gamma, g, bo, inj) = (rnd(&mut rng, t * 10240, 3.0), rnd(&mut rng, 10240, 2.0), rnd(&mut rng, t * 10240, 4.0), rnd(&mut rng, t * 2560, 1.0), rnd(&mut rng, t * 4, 2.0));
|
||||
let mk = |n: usize| upload(&context, &vec![0u8; n]);
|
||||
let (r_d, w_d, g_d, bo_d, inj_d) = (upload(&context, &f32_bytes(&r)), upload(&context, &f32_bytes(&gamma)), upload(&context, &f32_bytes(&g)), upload(&context, &f32_bytes(&bo)), upload(&context, &f32_bytes(&inj)));
|
||||
let (rs, xn, mx, m16, mh, fl) = (mk(t * 16), mk(t * 20480), mk(t * 10240), mk(t * 5120), mk(t * 5120), mk(t * 8 * 4));
|
||||
let eps = 1e-6f32;
|
||||
let blas = workspace.blas().expect("blas");
|
||||
let time = |what: &str, bytes: f64, launch: &mut dyn FnMut()| {
|
||||
let guard = context.enter().expect("enter");
|
||||
launch();
|
||||
blas.synchronize().expect("sync");
|
||||
let started = std::time::Instant::now();
|
||||
for _ in 0..20 {
|
||||
launch();
|
||||
}
|
||||
blas.synchronize().expect("sync");
|
||||
let us = started.elapsed().as_secs_f64() * 1e6 / 20.0;
|
||||
guard.finish().expect("finish");
|
||||
eprintln!("PREFILL-GR-TRAFFIC {what}: {us:.0} us per call, {:.0} MB moved, {:.2} TB/s", bytes / 1e6, bytes / us / 1e6);
|
||||
};
|
||||
let r_bytes = (t * 40960) as f64;
|
||||
let mut keep = Vec::new();
|
||||
let mut run = |index: usize, grid: usize, args: Vec<A>| {
|
||||
let mut a = KernelArguments::new(args);
|
||||
stage.launch(index, grid as u32, 256, blas.stream(), &mut a).expect("launch");
|
||||
keep.push(a);
|
||||
};
|
||||
time("norm_rs (R in, xn16 out)", r_bytes + (t * 20480) as f64, &mut || {
|
||||
run(3, t * 4, vec![A::Address(h(&r_d)), A::Address(h(&w_d)), A::F32(eps), A::Address(h(&rs)), A::Address(h(&xn)), A::NullAddress, A::Address(h(&fl))])
|
||||
});
|
||||
time("mix_r (R, g in; mixed f32 + bf16 + f16 out)", 2.0 * r_bytes + (t * (10240 + 5120 + 5120)) as f64, &mut || {
|
||||
run(4, (t * 2560).div_ceil(256), vec![A::Address(h(&r_d)), A::Address(h(&rs)), A::Address(h(&w_d)), A::Address(h(&g_d)), A::Address(h(&mx)), A::Address(h(&m16)), A::I64(t as i64), A::Address(h(&mh)), A::NullAddress, A::Address(h(&fl))])
|
||||
});
|
||||
time("write_norm_rs (R in+out, bo in, xn16 out)", 2.0 * r_bytes + (t * 10240) as f64 + (t * 20480) as f64, &mut || {
|
||||
run(5, t * 4, vec![A::Address(h(&r_d)), A::Address(h(&bo_d)), A::Address(h(&inj_d)), A::I64(4), A::Address(h(&w_d)), A::F32(eps), A::Address(h(&rs)), A::Address(h(&xn)), A::NullAddress, A::Address(h(&fl))])
|
||||
});
|
||||
}
|
||||
|
||||
@@ -213,6 +213,18 @@ With every span drained (so a span shows its own GPU + host time) the chunk is 1
|
||||
|
||||
GPU time of the chunk, summed over its commands (`PREFILL-COMMANDS`, includes the per-command launch overhead of the drained profile): GDN 369, QSA 275 + index 79 + KV 22, GR read / inject 184 (`readn` 124: `gr_mix_r` 48, three GEMMs 72; `injectf` `gr_write_norm_rs` 56), MoE (MMQ + gather + combine, ledger) ~330: about 1.27 s of the 1.56 s. So the GPU idle time is about 0.3 s, but the **purely host-side items that a pipeline could hide add up to about 100-120 ms** (`state_in` 25 + `state_out` 37 + `spans` 26 + the host part of `prepare` ~35 + `input`/`validate`/`init` ~30); the rest of the idle time is launch latency inside chains of small kernels. The cheap host trims that need no redesign (skip the finite scan of an already validated mirror-resident state, reuse the row keys across the 36 GDN layers of a chunk, pool the 3 MB state buffer) are worth about 20-30 ms per chunk (1.5 %), below the 1-2 % noise of a paired A/B. Hiding the rest means keeping layer k+1's route readback / grouping and state upload in flight under layer k's kernels, i.e. double-buffering ownership types that are single-owner by design (`GdnChunkStart` / `GdnChunkRow` capabilities, `OriginalMoePromptLayer`): large, and its ceiling is ~7 % of a chunk. **Not started; a better lever is the GR read / inject pair**, 180 ms of bandwidth-bound passes over the 335 MB residual (R is 4 streams x 8192 x 2560 x 4 B) that run at 2-3x their traffic floor: bit-identical fusion / re-tiling candidates (`gr_mix_r`, `gr_write_norm_rs`, the three read GEMMs) with a model-free byte-compare probe, no ownership changes.
|
||||
|
||||
### The hyper-connection kernels of the prompt are on their traffic floor (model-free probe, 2026-10-27 22:05)
|
||||
|
||||
`prefill_stage_gr_gpu::gr_kernels_run_near_their_traffic_floor_at_chunk_size` (T = 8192 rows, R = 335.5 MB, 20 warm launches; the byte-compare probe `gr_fused_guards_equal_the_separate_guard_kernels_bit_for_bit` already exists and passes: 4 cases, outputs and flag words equal the Original's kernels + separate guards). Achieved bandwidth of the three kernels that make up `readn` / `injectf` (the RTX 5090's DRAM peak is 1.79 TB/s, about 1.5-1.6 TB/s is what a streaming kernel sustains):
|
||||
|
||||
| kernel | us per call | bytes it must move | achieved |
|
||||
|---|---:|---:|---:|
|
||||
| `leleka_prefill_gr_norm_rs` (R in, xn16 out) | 318 | 503 MB | 1.58 TB/s |
|
||||
| `leleka_prefill_gr_mix_r` (R and g in; mixed f32 + bf16 + f16 out) | 523 | 839 MB | 1.60 TB/s |
|
||||
| `leleka_prefill_gr_write_norm_rs` (R in and out, bo in, xn16 out) | 616 | 923 MB | 1.50 TB/s |
|
||||
|
||||
The "floor of 18 ms per pass" quoted before counted only one read of R: `mix_r` also reads the 335 MB gate tensor `g` and writes three images of `mixed`, `write_norm_rs` reads and writes R. Against their real traffic the kernels run at 84-89 % of the DRAM peak, so no re-tiling or fusion of these kernels can buy more than ~10 % of their 180 ms per chunk (about 5-8 ms), and the three GEMMs of `readn` (72 ms) are cuBLAS calls whose algorithm cannot change without changing bits. Same for the other large passes: the GDN convolution reads and writes the 335 MB `h` (0.47 ms per call against a 0.4 ms floor). The 8192-token prompt chunk is therefore bound by the memory traffic of fp32 activations 10,240 wide plus the serial host/GPU chain measured above; the only remaining bit-identical savings are the host trims (20-30 ms) and the launch latency of the small-kernel chains. Reducing the bytes (bf16/f16 activations, fused int8 prompt experts) changes numerics and is row 3.2 territory. No code changed for this item.
|
||||
|
||||
## Not taken (reasons in the digest)
|
||||
|
||||
Qwen3.6-35B-A3B path, Metal/SYCL/HIP-only changes, K8V4 streaming and elastic KV (`--kv-grow`; our serve path excludes K8V4), the installers and host app.
|
||||
|
||||
Reference in New Issue
Block a user