From 168a26a6b89548a397915b8359f5b480772444ac Mon Sep 17 00:00:00 2001 From: mici81 Date: Tue, 20 Oct 2026 05:36:49 +0000 Subject: [PATCH] gemm_mxfp4a8_tiled: TN=4 from M >= 1024 TN=4 wins from 1024 rows on (r4d_selftest --perfmx, a rank's weights: Qwen3.8 gate_up 17408x5120 1105.6 -> 1080.8 us, down 5120x8704 618.5 -> 599.1, TranslateGemma gate_up 21504x5376 1395.0 -> 1273.8, its down 5376x10752 793.6 -> 799.6; 1536 rows better on all four; 512 and 768 mixed). It matters to the pipelined prefill's 1024-row pieces and to TranslateGemma's 1024-row chunks. Same bytes: Qwen's KL recording and TranslateGemma's KL (0.054628) unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) --- libr4d/r4d_gemm_mxfp4a8_tiled.hip | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libr4d/r4d_gemm_mxfp4a8_tiled.hip b/libr4d/r4d_gemm_mxfp4a8_tiled.hip index 54a4ee88..df558623 100644 --- a/libr4d/r4d_gemm_mxfp4a8_tiled.hip +++ b/libr4d/r4d_gemm_mxfp4a8_tiled.hip @@ -24,8 +24,9 @@ // 2^(Wref[n]-127) is applied in the epilogue (see r4d_gemm_mxfp4a8_nt_m64.hip). // // Tile: 8 waves as 4 (M) x 2 (N), each owning TM=4 x TN fragments, so a block covers BMF = 256 -// rows and BNF = 2*TN*16 columns. TN=4 halves the column-block count and only wins on long prompts -// (crossover near M=2048 on a 17408x5120 weight), so tn=0 picks TN=4 from M >= 2048. The K slab is +// rows and BNF = 2*TN*16 columns. TN=4 halves the column-block count and wins from M = 1024 on (a +// rank's Qwen3.8 gate_up 17408x5120 -2 %, down 5120x8704 -3 %, TranslateGemma gate_up 21504x5376 +// -9 %, its down 5376x10752 +1 %; mixed below), so tn=0 picks TN=4 from M >= 1024. The K slab is // 128 at TN=2 (64 if K % 128 != 0) and 64 at TN=4, which holds twice the accumulators. // // Barriers fence LDS only: __syncthreads() also drains the global load counter, and nothing in @@ -63,7 +64,7 @@ #define R4D_MXT_NTHR (R4D_MXT_WM * R4D_MXT_WN * 32) #define R4D_MXT_BMF (R4D_MXT_WM * R4D_MXT_TM * 16) #define R4D_MXT_KUNIT 64 // the narrowest K slab, so K must be a multiple of it -#define R4D_MXT_TN4_MIN_M 2048 // tn=0's crossover, see above +#define R4D_MXT_TN4_MIN_M 1024 // tn=0's crossover, see above typedef int mxt_v2i __attribute__((ext_vector_type(2))); typedef unsigned mxt_u2 __attribute__((ext_vector_type(2)));