--- /home/dev/simt-retire-work/basecsrc/arbi_serve/weight_quant/gemv/csrc/_gemv_mma.cuh	2026-11-11 23:55:02.000000000 +0000
+++ arbi_serve/weight_quant/gemv/csrc/_gemv_mma.cuh	2026-11-12 01:03:09.102713382 +0000
@@ -75,8 +75,28 @@
 //: routed row counts launch) four and the 64-row LEAN arm three; of the
 //: staged-in-passes arms (a logits head's single slice) the 8-row one four and
 //: the 16-row one three.
+#ifdef LAB_RB16
+#define AG_MMA_REDUCE_BATCH 16
+#endif
+#ifdef LAB_RB8
+#define AG_MMA_REDUCE_BATCH 8
+#endif
+#ifdef LAB_RING4
+#define AG_MMA_RING_W1 4
+#endif
+#ifdef LAB_RING8
+#define AG_MMA_RING_W1 8
+#endif
+#ifdef LAB_MB5
+#define AG_MMA_MIN_BLOCKS(NT, LEAN) 5
+#elif defined(LAB_MB6)
+#define AG_MMA_MIN_BLOCKS(NT, LEAN) 6
+#elif defined(LAB_MB3)
+#define AG_MMA_MIN_BLOCKS(NT, LEAN) 3
+#else
 #define AG_MMA_MIN_BLOCKS(NT, LEAN)                                                      \
     ((LEAN) ? ((NT) <= 4 ? 4 : 3) : ((NT) == 1 ? 4 : ((NT) == 2 ? 3 : 2)))
+#endif
 //: The grouped arms carry the member table too: three blocks an SM when LEAN,
 //: which is what `ag_mma_plan`'s grouped cuts were raced at.
 #define AG_MMA_GROUP_MIN_BLOCKS(NT, LEAN) ((LEAN) ? 3 : 2)
@@ -263,10 +283,49 @@
 // function of the split count alone. Read at L2 (`__ldcg`) because other CTAs wrote the
 // partials in this same launch. Used by the in-launch last-CTA reduction and by
 // the fallback second launch, so the two give the same bits.
-__device__ __forceinline__ void ag_mma_reduce_band(const float* __restrict__ partial,
+//: lab: the rotate-store with the scale words already loaded.
+__device__ __forceinline__ void ag_mma_rotate_store_sv(float4 v, void* __restrict__ C, size_t out_base,
+                                                       uint2 sv, int lane, int out_dtype)
+{
+    ag_had_r128_warp(v, lane);
+    const __half2 s0 = *reinterpret_cast<const __half2*>(&sv.x);
+    const __half2 s1 = *reinterpret_cast<const __half2*>(&sv.y);
+    v.x *= AG_HAD_R128_RSCALE * __low2float(s0);
+    v.y *= AG_HAD_R128_RSCALE * __high2float(s0);
+    v.z *= AG_HAD_R128_RSCALE * __low2float(s1);
+    v.w *= AG_HAD_R128_RSCALE * __high2float(s1);
+    ag_store4(C, out_base + 4 * lane, v, out_dtype);
+}
+
+template <int kB>
+__device__ __forceinline__ void ag_mma_reduce_batch(float4& acc, const float* __restrict__ p0,
+                                                    size_t stride, int s0, int splits)
+{
+    float4 p[kB];
+    #pragma unroll
+    for (int j = 0; j < kB; ++j)
+        p[j] = __ldcg((const float4*)(p0 + (size_t)min(s0 + j, splits - 1) * stride));
+    #pragma unroll
+    for (int j = 0; j < kB; ++j) {
+        if (s0 + j < splits) {
+            acc.x += p[j].x;
+            acc.y += p[j].y;
+            acc.z += p[j].z;
+            acc.w += p[j].w;
+        }
+    }
+}
+
+#ifdef LAB_NI
+#define LAB_REDUCE_INLINE __noinline__
+#else
+#define LAB_REDUCE_INLINE __forceinline__
+#endif
+template <bool WIDE = true>
+__device__ LAB_REDUCE_INLINE void ag_mma_reduce_band(const float* __restrict__ partial,
                                                    void* __restrict__ C, const __half* svh,
                                                    int n0, int size_n, int mrows, int r0, int r1,
-                                                   int splits, int out_dtype)
+                                                   int splits, int out_dtype, uint2 sv_in = make_uint2(0u, 0u))
 {
     const int lane = (int)threadIdx.x & 31;
     const int warp = (int)threadIdx.x >> 5;
@@ -275,6 +334,74 @@
         float4 acc = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
         const float* p0 = partial + (size_t)r * size_n + n0 + 4 * lane;
         const size_t stride = (size_t)mrows * size_n;
+#if defined(LAB_RBN) || defined(LAB_RBM)
+        if (!WIDE) {
+#ifdef LAB_RBM
+            uint2 svn = make_uint2(0u, 0u);
+            if (svh != nullptr) svn = *(const uint2*)(svh + n0 + 4 * lane);
+#endif
+            for (int s0 = 0; s0 < splits; s0 += 12) ag_mma_reduce_batch<12>(acc, p0, stride, s0, splits);
+#ifdef LAB_RBM
+            if (svh != nullptr)
+                ag_mma_rotate_store_sv(acc, C, (size_t)r * size_n + n0, svn, lane, out_dtype);
+#else
+            if (svh != nullptr)
+                ag_rotate_store_128(acc, C, (size_t)r * size_n + n0, svh + n0, lane, out_dtype);
+#endif
+            else
+                ag_store4(C, (size_t)r * size_n + n0 + 4 * lane, acc, out_dtype);
+            continue;
+        }
+#endif
+#ifdef LAB_SV1
+        uint2 sv = make_uint2(0u, 0u);
+#ifdef LAB_SV2
+        sv = sv_in;
+#else
+        if (svh != nullptr) sv = *(const uint2*)(svh + n0 + 4 * lane);
+#endif
+#endif
+#if defined(LAB_V3)
+        if (splits <= 4) ag_mma_reduce_batch<4>(acc, p0, stride, 0, splits);
+        else if (splits <= 8) ag_mma_reduce_batch<8>(acc, p0, stride, 0, splits);
+        else if (splits <= 12) ag_mma_reduce_batch<12>(acc, p0, stride, 0, splits);
+        else if (WIDE && splits <= 16) ag_mma_reduce_batch<16>(acc, p0, stride, 0, splits);
+        else
+            for (int s0 = 0; s0 < splits; s0 += 12) ag_mma_reduce_batch<12>(acc, p0, stride, s0, splits);
+#elif defined(LAB_V2)
+        {
+            int s0 = 0;
+            for (; splits - s0 > (WIDE ? 16 : 12); s0 += 12) ag_mma_reduce_batch<12>(acc, p0, stride, s0, splits);
+            const int rem = splits - s0;
+            if (rem > 12) ag_mma_reduce_batch<16>(acc, p0, stride, s0, splits);
+            else if (rem > 8) ag_mma_reduce_batch<12>(acc, p0, stride, s0, splits);
+            else if (rem > 4) ag_mma_reduce_batch<8>(acc, p0, stride, s0, splits);
+            else ag_mma_reduce_batch<4>(acc, p0, stride, s0, splits);
+        }
+#elif defined(LAB_RBA) || defined(LAB_RBB) || defined(LAB_RBC) || defined(LAB_RBL) || defined(LAB_RB88)
+        for (int s0 = 0; s0 < splits;) {
+            const int rem = splits - s0;
+#ifdef LAB_RBA
+            if (rem > 12 && rem <= 16) { ag_mma_reduce_batch<16>(acc, p0, stride, s0, splits); s0 += 16; }
+            else
+#endif
+#ifdef LAB_RBL
+            if (WIDE && rem > 12 && rem <= 16) { ag_mma_reduce_batch<16>(acc, p0, stride, s0, splits); s0 += 16; }
+            else
+#endif
+#ifdef LAB_RB88
+            if (rem > 12 && rem <= 16) { ag_mma_reduce_batch<8>(acc, p0, stride, s0, splits); s0 += 8; }
+            else
+#endif
+#ifdef LAB_RBC
+            if (rem > 12) { ag_mma_reduce_batch<16>(acc, p0, stride, s0, splits); s0 += 16; }
+            else
+#endif
+            if (rem > 8) { ag_mma_reduce_batch<12>(acc, p0, stride, s0, splits); s0 += 12; }
+            else if (rem > 4) { ag_mma_reduce_batch<8>(acc, p0, stride, s0, splits); s0 += 8; }
+            else { ag_mma_reduce_batch<4>(acc, p0, stride, s0, splits); s0 += 4; }
+        }
+#else
         // Loads issued a batch at a time, THEN summed in split order: the
         // order is unchanged, and the L2 round trips overlap instead of
         // chaining one per split. EVERY LOAD OF A BATCH IS UNCONDITIONAL: a
@@ -297,8 +424,14 @@
                 }
             }
         }
+#endif
+#ifdef LAB_SV1
+        if (svh != nullptr)
+            ag_mma_rotate_store_sv(acc, C, (size_t)r * size_n + n0, sv, lane, out_dtype);
+#else
         if (svh != nullptr)
             ag_rotate_store_128(acc, C, (size_t)r * size_n + n0, svh + n0, lane, out_dtype);
+#endif
         else
             ag_store4(C, (size_t)r * size_n + n0 + 4 * lane, acc, out_dtype);
     }
@@ -541,12 +674,24 @@
 
     // THE RING IS FILLED BEFORE THE ACTIVATION IS STAGED: the weights'
     // addresses do not depend on it, so their latency runs under the staging.
+#ifdef LAB_X0
+    return;
+#endif
     uint32_t ring[kRing][kPer];
     #pragma unroll
     for (int s = 0; s < kRing; ++s)
         if (s < share) ag_mma_load_tile<BITS>(tile_at(s), lane, ring[s], stream);
+#ifdef LAB_ED
+    uint32_t acur[4];
+    decode(ring[0], acur);
+#endif
+#ifndef LAB_NOSTAGE
     stage_pass(0, min(kst, nblk));
+#endif
     __syncthreads();
+#ifdef LAB_X1
+    if (ring[0][0] != 0x12345u) return;
+#endif
 
     float acc[NT][4];
     uint32_t lo[NT][2];
@@ -590,8 +735,10 @@
         }
     };
     const uint32_t* wnext = tile_at(kRing);
+#ifndef LAB_ED
     uint32_t acur[4];
     decode(ring[0], acur);
+#endif
     int ib = 0;  // k tile index within the staged pass
     int pass = 0;
     for (int j0 = 0; j0 < share; j0 += kRing) {
@@ -631,6 +778,10 @@
     // The accumulator: register j of n8 tile t holds column
     // `np*16 + lane/4 + 8*(j/2)` and CTA row `8*t + 2*(lane%4) + (j%2)`.
     float* fin = (float*)mma_smem;
+#ifdef LAB_SVS
+    uint2 svs = make_uint2(0u, 0u);
+    if (splits == 1 && lt.svh != nullptr) svs = *(const uint2*)(lt.svh + n0 + 4 * lane);
+#endif
     __syncthreads();  // the fragments are dead; reuse their space
     {
         const int cb = np * AG_TILE_N + (lane >> 2);
@@ -648,9 +799,15 @@
         for (int r = warp; r < rows_here; r += nwarps) {
             const float4 v = ((const float4*)(fin + r * AG_MMA_BAND))[lane];
             const size_t at = (size_t)(row0 + r) * size_n + n0;
+#ifdef LAB_SVS
+            if (lt.svh != nullptr)
+                ag_mma_rotate_store_sv(v, C, at, svs, lane, out_dtype);
+            else
+#else
             if (lt.svh != nullptr)
                 ag_rotate_store_128(v, C, at, lt.svh + n0, lane, out_dtype);
             else
+#endif
                 ag_store4(C, at + 4 * lane, v, out_dtype);
         }
         return;
@@ -668,16 +825,30 @@
         }
     }
     if (ctr == nullptr) return;
+#ifdef LAB_X3
+    return;
+#endif
 
     // THE LAST SPLIT TO ARRIVE FINISHES THE BAND'S ROWS. Which CTA that is
     // does not enter the sum: the reduction reads every split in index order.
     __shared__ int is_last;
+#ifdef LAB_SV2
+    uint2 svt = make_uint2(0u, 0u);
+    if (lt.svh != nullptr) svt = *(const uint2*)(lt.svh + n0 + 4 * lane);
+#endif
     __syncthreads();  // the CTA's partial rows, released by thread 0's arrival
     if (tid == 0) is_last = (ag_split_arrive(ctr) == splits - 1);
     __syncthreads();  // and the other splits' rows, acquired by it
     if (!is_last) return;
-    ag_mma_reduce_band(partial, C, lt.svh, n0, size_n, mrows, row0, row0 + rows_here, splits,
-                       out_dtype);
+#ifdef LAB_X4
+    return;
+#endif
+    ag_mma_reduce_band<LEAN>(partial, C, lt.svh, n0, size_n, mrows, row0, row0 + rows_here, splits,
+                       out_dtype
+#ifdef LAB_SV2
+                       , svt
+#endif
+                       );
     if (tid == 0) *ctr = 0;  // leave the slot as it was found
 }
 
