[LD][HIP] Contiguous expert arena + device-routed MXFP8/NVFP4 GEMV (graph-capturable MoE foundation)

ExpertArena loads a whole layer expert tensor in ONE contiguous device buffer
(the safetensors already store [n_exp,N,K/2] NVFP4 / [n_exp,N,K] MXFP8), with a
per-expert outer_scale array. The indirect GEMV indexes expert id from a DEVICE
buffer (ids[slot]) => static launch params, no host ids round-trip.

Add MXFP8 f16 indirect kernel (mirrors NVFP4: shared device body + direct +
indirect wrappers). expert_arena_gemv_f16 dispatches NVFP4/MXFP8.

Parity on REAL weights: arena-indirect BIT-EXACT vs per-expert direct for layer 0
(NVFP4) and layer 20 (MXFP8), 4 routed experts each. Additive — forward default
unchanged (wiring into the device-resident MoE path is the next brick).

Verified: ld GPU 19 + hip GPU 19 green, workspace CPU -D warnings green, 6 Lean
proofs 0 sorryAx.
This commit is contained in:
adm committed 2026-12-01 22:39:39 +01:00
1 parent 4c82040610
commit 752edeaade
3 files changed
+151 -1

No files matched your search

+14
View File
@@ -85,6 +85,10 @@ mod ffi {
) -> c_int;
pub fn vetta_mxfp8_gemv(weights: *const u8, scales: *const u8, x: *const c_float, y: *mut c_float, n: c_int, k: c_int, stream: *mut c_void) -> c_int;
pub fn vetta_mxfp8_gemv_f16(weights: *const u8, scales: *const u8, x: *const u16, y: *mut c_float, n: c_int, k: c_int, stream: *mut c_void) -> c_int;
pub fn vetta_mxfp8_gemv_f16_indirect(
arena_weights: *const u8, arena_scales: *const u8, ids: *const c_int, slot: c_int,
x: *const u16, y: *mut c_float, n: c_int, k: c_int, w_stride: c_long, sc_stride: c_long, stream: *mut c_void,
) -> c_int;
pub fn vetta_situ(gu: *const c_float, act: *mut c_float, inter: c_int, beta: c_float, lb: c_float, stream: *mut c_void) -> c_int;
pub fn vetta_situ_f16(gu: *const c_float, act: *mut u16, inter: c_int, beta: c_float, lb: c_float, stream: *mut c_void) -> c_int;
pub fn vetta_moe_reduce(y_part: *const c_float, tk_w: *const c_float, out: *mut c_float, top_k: c_int, hidden: c_int, stream: *mut c_void) -> c_int;
@@ -471,6 +475,16 @@ pub fn mxfp8_gemv_f16(weights: &DeviceBuf, scales: &DeviceBuf, x: &DeviceBuf, y:
Ok(())
}
/// Device-routed MXFP8 f16 GEMV (arena + ids[slot]); graph-capturable, no outer.
#[cfg(feature = "hip")]
pub fn mxfp8_gemv_f16_indirect(arena_weights: &DeviceBuf, arena_scales: &DeviceBuf, ids: &DeviceBuf, slot: i32, x: &DeviceBuf, y: &DeviceBuf, n: i32, k: i32, w_stride: i64, sc_stride: i64) -> Result<(), String> {
let rc = unsafe {
ffi::vetta_mxfp8_gemv_f16_indirect(arena_weights.ptr as *const u8, arena_scales.ptr as *const u8, ids.ptr as *const i32, slot, x.ptr as *const u16, y.ptr as *mut f32, n, k, w_stride, sc_stride, std::ptr::null_mut())
};
if rc != 0 { return Err("mxfp8_gemv_f16_indirect launch failed".into()); }
Ok(())
}
/// Launch k_situ_f16: SiTU computed in f32, stored FP16 (exact strata act_out).
#[cfg(feature = "hip")]
pub fn situ_f16(gu: &DeviceBuf, act: &DeviceBuf, inter: i32, beta: f32, lb: f32) -> Result<(), String> {