[LD][HIP] Device-resident MoE path (opt-in VETTA_DEVICE_MOE): no host ids/output round-trip

moe_device runs the whole MoE on device: router ids/weights stay on device, the
arena indirect GEMV selects experts on device, per-expert outputs accumulate in a
device y_part via a STATIC y_offset=kk*hidden (added to both indirect kernels).
No ids D2H, no per-expert output D2H/H2D => the MoE block is now graph-capturable.

WeightCache gains a memoized expert_arena(ip,mat) accessor. Both SWA and full-attn
MoE blocks dispatch to moe_device under VETTA_DEVICE_MOE=1; the default f32 host
path is unchanged (parity baseline preserved).

Parity: 16/16 greedy tokens IDENTICAL between VETTA_DEVICE_MOE=1 and the
VETTA_F16_EXPERT=1 host path (same kernels/data). Arena indirect bit-exact vs
direct on real weights (NVFP4 layer 0 + MXFP8 layer 20).

Verified: ld GPU 19 + hip GPU 19 green, workspace CPU -D warnings green, 6 Lean
proofs 0 sorryAx. Next: device-resident depth-block/bank machinery, then HIP graph
capture of the decode step.
This commit is contained in:
adm committed 2026-12-01 22:43:47 +01:00
1 parent 752edeaade
commit 0914fae8c8
4 files changed
+87 -34

No files matched your search

+8 -8
View File
@@ -808,22 +808,22 @@ __global__ void __launch_bounds__(256) k_nvfp4_gemv_f16_indirect(
const int* __restrict__ ids, int slot,
const uint16_t* __restrict__ x,
float* __restrict__ y, int N, int K,
long w_stride, long sc_stride) {
long w_stride, long sc_stride, long y_offset) {
const int id = ids[slot];
nvfp4_gemv_f16_body(arena_packed + (long)id * w_stride,
arena_scales + (long)id * sc_stride,
outer_arena[id], x, y, N, K);
outer_arena[id], x, y + y_offset, N, K);
}
extern "C" int vetta_nvfp4_gemv_f16_indirect(const uint8_t* arena_packed,
const uint8_t* arena_scales, const float* outer_arena,
const int* ids, int slot, const uint16_t* x, float* y,
int N, int K, long w_stride, long sc_stride,
int N, int K, long w_stride, long sc_stride, long y_offset,
vetta_stream_t stream) {
if (N <= 0 || K <= 0 || (K % 16) != 0 || slot < 0) return 1;
hipStream_t s = stream ? (hipStream_t)stream : (hipStream_t)0;
k_nvfp4_gemv_f16_indirect<<<(N + 7) / 8, 256, 0, s>>>(
arena_packed, arena_scales, outer_arena, ids, slot, x, y, N, K, w_stride, sc_stride);
arena_packed, arena_scales, outer_arena, ids, slot, x, y, N, K, w_stride, sc_stride, y_offset);
HIP_CHECK(hipGetLastError());
return 0;
}
@@ -932,19 +932,19 @@ __global__ void k_mxfp8_gemv_f16_indirect(const uint8_t* __restrict__ arena_weig
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) {
int N, int K, long w_stride, long sc_stride, long y_offset) {
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);
arena_scales + (long)id * sc_stride, x, y + y_offset, 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) {
long w_stride, long sc_stride, long y_offset, 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);
k_mxfp8_gemv_f16_indirect<<<N, 256, 0, s>>>(arena_weights, arena_scales, ids, slot, x, y, N, K, w_stride, sc_stride, y_offset);
HIP_CHECK(hipGetLastError());
return 0;
}