[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

+31 -1
View File
@@ -889,7 +889,7 @@ extern "C" int vetta_mxfp8_gemv(const uint8_t* weights, const uint8_t* scales,
// ---- k_mxfp8_gemv_f16: FP16-activation variant (exact strata MX8 path) ------
// E4M3 weights are exact in FP16; group-of-32 partial dot then scale-fma.
__global__ void k_mxfp8_gemv_f16(const uint8_t* __restrict__ weights,
__device__ __forceinline__ void mxfp8_gemv_f16_body(const uint8_t* __restrict__ weights,
const uint8_t* __restrict__ scales,
const uint16_t* __restrict__ x, float* __restrict__ y,
int N, int K) {
@@ -919,6 +919,36 @@ __global__ void k_mxfp8_gemv_f16(const uint8_t* __restrict__ weights,
if (tid == 0) y[n] = red[0];
}
__global__ void k_mxfp8_gemv_f16(const uint8_t* __restrict__ weights,
const uint8_t* __restrict__ scales,
const uint16_t* __restrict__ x, float* __restrict__ y,
int N, int K) {
mxfp8_gemv_f16_body(weights, scales, x, y, N, K);
}
// Indirect (device-routed) MXFP8 f16 GEMV: expert id from ids[slot] indexes a
// contiguous arena (weights / scales). MXFP8 has no outer scale. Same body.
__global__ void k_mxfp8_gemv_f16_indirect(const uint8_t* __restrict__ arena_weights,
const uint8_t* __restrict__ arena_scales,
const int* __restrict__ ids, int slot,
const uint16_t* __restrict__ x, float* __restrict__ y,
int N, int K, long w_stride, long sc_stride) {
const int id = ids[slot];
mxfp8_gemv_f16_body(arena_weights + (long)id * w_stride,
arena_scales + (long)id * sc_stride, x, y, N, K);
}
extern "C" int vetta_mxfp8_gemv_f16_indirect(const uint8_t* arena_weights,
const uint8_t* arena_scales, const int* ids, int slot,
const uint16_t* x, float* y, int N, int K,
long w_stride, long sc_stride, vetta_stream_t stream) {
if (N <= 0 || K <= 0 || (K % 32) != 0 || slot < 0) return 1;
hipStream_t s = stream ? (hipStream_t)stream : (hipStream_t)0;
k_mxfp8_gemv_f16_indirect<<<N, 256, 0, s>>>(arena_weights, arena_scales, ids, slot, x, y, N, K, w_stride, sc_stride);
HIP_CHECK(hipGetLastError());
return 0;
}
extern "C" int vetta_mxfp8_gemv_f16(const uint8_t* weights, const uint8_t* scales,
const uint16_t* x, float* y, int N, int K,
vetta_stream_t stream) {