libr3d: fix the w4a4 activation row pitch (strides are elements, not bytes)

The launcher passed a->stride[0] straight as the byte pitch, but strides are
in elements (abi/rad_types.h): an int4 row of K nibbles is K/2 bytes. The
kernel read row 2*src instead of row src (row 0 correct, every other row from
the wrong source, and past the plane for larger M). The weight side already
converts (r3d_tab_of's s0 = stride*bits/8, the kernel uses w_ld/2); the
activation now does too. The libref reference had the same bug and is fixed on
the w4a4-libref-wip branch, so the two now agree on the correct row.

Missed because r3d_selftest checks finiteness only and ref_test checks status
only on the libref sweep geometries.
This commit is contained in:
Asim Siddiqui authored and StillDeadcode committed 2026-11-05 14:59:08 +01:00
1 parent 28939a99df
commit e3d65f3a7c
1 file changed
+3 -2
+3 -2
View File
@@ -14,7 +14,7 @@
* scale_w[e][n][b] in f32 -- the exact order the libref reference runs, so it agrees bit for bit.
*
* Decode band: at most 16 sorted rows per block (M * top_k <= 16); prefill finds no row and falls
* back. The activation stride a_ld is in BYTES (K/2 per row: K int4 nibbles).
* back. The activation stride a_ld is in BYTES (K/2 per row: stride[0] is K int4 nibbles).
*/
#include <hip/hip_runtime.h>
@@ -197,7 +197,8 @@ int r3d_rad_moe_gemm_w4a4(const RadArgs* a, RadStream s)
R3dMoeTabs tw;
rc = r3d_moe_q_tabs(c, RAD_I4, 4, RAD_BF16, 16, c.N, c.K / kGroup, &tw);
if (rc != RAD_OK) return rc;
const int a_ld = (int)c.a->stride[0], as_ld = (int)c.a_scale->stride[0];
/* Strides are in elements (abi/rad_types.h): an int4 row of K nibbles is K/2 bytes. */
const int a_ld = (int)c.a->stride[0] / 2, as_ld = (int)c.a_scale->stride[0];
const int y_ld = (int)c.y->stride[0];
const int mrows = r3d_geti_or(a, "mrows", 16);