WGMMA: a block-major B tile can read K-major data left in the B buffer (rtlsim)
Maintainers usually reply within 1 day
@youzi27 is already working on this.
Since Nov 27, 2026.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start with hw/rtl/tcu/VX_tcu_bbuf.sv, especially the fetch-slot address recording and block-major residency checks described around lines 236-247 and 425. Reproduce with tests/regression/sgemm_tcu_wg using the supplied ci/blackbox.sh command, then add a regression that mixes K-major and block-major B tiles. Done means rtlsim no longer reuses the stale K-major data and matches the reference results.
Written by the indexing model from the issue text.
Description
Hi there,
On master 2221ee286, a WGMMA whose B descriptor is block-major (stride 0) can compute with B data left in the shared B buffer by the previous WGMMA, when that one used a K-major B descriptor and its last B fetch was keyed on the bank row where the new block-major tile starts. rtlsim then uses the old tile's data for the B blocks of that row. SimX refetches and gets the right result.
To reproduce, let sgemm_tcu_wg stage B K-major on even K tiles and block-major on odd K tiles, the block-major tile one LMEM bank row short of a B tile past the K-major base (both descriptors are legal under smem_desc_check):
diff --git a/tests/regression/sgemm_tcu_wg/kernel.cpp b/tests/regression/sgemm_tcu_wg/kernel.cpp
--- a/tests/regression/sgemm_tcu_wg/kernel.cpp
+++ b/tests/regression/sgemm_tcu_wg/kernel.cpp
@@ -77,6 +77,9 @@ __kernel void kernel_main(kernel_arg_t* __UNIFORM__ arg) {
// Default (block-major): B_smem[(k_blk*N_STEPS + n_blk)*BW + n_in*tcK + k_in]
// WGMMA_KMAJOR_B: B_smem[c * ldb + b_off + r] — N-outer, K-inner.
uint32_t b_size = ctx::tileK * ctx::xtileN;
+ // even K tiles: B K-major; odd K tiles: B block-major, one bank row short of a B tile further on
+ bool b_kmajor = ((k / ctx::tileK) & 1) == 0;
+ auto B_tile = b_kmajor ? B_smem : B_smem + b_size - (VX_CFG_NUM_THREADS * 4) / sizeof(ctx::input_t);
for (uint32_t i = 0; i < b_size; i += num_threads) {
uint32_t idx = i + tid;
uint32_t r = idx / ctx::xtileN;
@@ -84,7 +87,8 @@ __kernel void kernel_main(kernel_arg_t* __UNIFORM__ arg) {
#ifdef WGMMA_KMAJOR_B
B_smem[c * ldb + b_off + r] = pB[(k + r) * N + (tile_col + c)];
#else
- B_smem[ctx::b_blockmajor_idx(r, c)] = pB[(k + r) * N + (tile_col + c)];
+ if (b_kmajor) B_tile[c * ctx::tileK + r] = pB[(k + r) * N + (tile_col + c)];
+ else B_tile[ctx::b_blockmajor_idx(r, c)] = pB[(k + r) * N + (tile_col + c)];
#endif
}
@@ -101,7 +105,7 @@ __kernel void kernel_main(kernel_arg_t* __UNIFORM__ arg) {
#ifdef WGMMA_KMAJOR_B
auto desc_b = vt::vx_make_smem_desc(B_smem + b_off, ldb * sizeof(ctx::input_t));
#else
- auto desc_b = vt::vx_make_smem_desc(B_smem, 0); // block-major: stride field unused
+ auto desc_b = vt::vx_make_smem_desc(B_tile, b_kmajor ? ctx::tileK * sizeof(ctx::input_t) : 0);
#endif
#if defined(WGMMA_RS) && (WGMMA_NRC <= 16)
diff --git a/tests/regression/sgemm_tcu_wg/main.cpp b/tests/regression/sgemm_tcu_wg/main.cpp
--- a/tests/regression/sgemm_tcu_wg/main.cpp
+++ b/tests/regression/sgemm_tcu_wg/main.cpp
@@ -715,7 +715,7 @@ int main(int argc, char *argv[]) {
#else
uint32_t b_smem = wg_cfg::tileK * per_warp_N;
#endif
- uint32_t smem_size = (a_smem + b_smem) * sizeof(itype_t) + SMEM_PAD_BYTES;
+ uint32_t smem_size = (a_smem + 2 * b_smem) * sizeof(itype_t) + SMEM_PAD_BYTES;
vx_event_h launch_ev = nullptr;
{
vx_launch_info_t li = {};
CONFIGS="-DVX_CFG_NUM_THREADS=8 -DVX_CFG_NUM_WARPS=8 -DVX_CFG_ISSUE_WIDTH=4 -DVX_CFG_EXT_TCU_ENABLE -DVX_CFG_TCU_WGMMA_ENABLE -DITYPE=fp16 -DOTYPE=fp32 -DWGMMA_NRC=8 -DWGMMA_SS -DVX_CFG_NUM_ALU_BLOCKS=1 -DVX_CFG_NUM_LSU_BLOCKS=1 -DVX_CFG_NUM_FPU_BLOCKS=1" ./ci/blackbox.sh --driver=rtlsim --app=sgemm_tcu_wg --args="-m 32 -n 8 -k 64"
*** error: [0] expected=13.822495, actual=14.551969
*** error: [1] expected=14.570732, actual=15.075275
*** error: [2] expected=15.396145, actual=14.823661
*** error: [3] expected=13.078876, actual=14.069447
...
PERF: instrs=9988, cycles=26071, IPC=0.383
Found 104 / 256 errors!
FAILED!
Every wrong output is in columns 0-3 of the tile, the two B blocks of the shared bank row (N steps 0 and 1). The same line passes with --driver=simx, and on rtlsim when the odd tiles keep the even tiles' base (same layouts, no shared bank row). It shows with one CTA per core (-n 8); with two co-resident CTAs the other CTA's WGMMA usually refills the buffer in between. At XLEN 64 the two addresses fall in different halves of a bank row and nothing goes wrong.
The cause is in hw/rtl/tcu/VX_tcu_bbuf.sv. Every fetch allocation records the block-major bank-row address of its (step_k, step_n) block as the slot address (slot_a_addr_r <= fetch_addr_a, :425), K-major ones included, but after a K-major fetch the slot holds that block's K-major rows. The block-major residency terms then match on address and sub-half only:
wire bank_row_resident_dense =
slot_a_valid_r && !slot_is_sparse_r
&& (slot_a_addr_r == fetch_addr_dense)
&& (slot_a_sub_half_r == dense_sub_half);
(:236-239; bank_row_resident_sparse at :241-247 likewise), so a block-major request at that address takes the K-major slot as resident. SimX's B buffer key compares the layout first (bbuf_slot_t::same_row, sim/simx/tcu/tcu_unit.cpp:819-820) and refetches.
Requiring !slot_row_major_r in both block-major terms fixes it, and only changes timing where SimX already refetches. A PR follows.
Environment: master 2221ee286, ../configure --xlen=32 --tooldir=..., prebuilt toolchain v3.0.1 (VERSION pins v3.0.3), Verilator 5.052.
Thanks!
- Dominant language
- Verilog
- Stars
- 2.4k
- Forks
- 563
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 71
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from vortexgpgpu/vortex
-
RV64 signed DIV/REM restores the sign from bit 31Possibly taken @zzf2024 claimed this 3 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
vortexgpgpu/vortex#501 · 1 comment ·
Maintainers usually reply within 1 day
-
fpu: sign-extend RV64 FCVT.WU positive overflow resultsPossibly taken @zzf2024 claimed this 3 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
vortexgpgpu/vortex#499 · 1 comment ·
Maintainers usually reply within 1 day
-
WGMMA: the next kernel can compute with the previous kernel's B row left in the B buffer (rtlsim)Possibly taken @youzi27 claimed this 2 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 35/100
vortexgpgpu/vortex#558 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
vortexgpgpu/vortex#521 ·
Maintainers usually reply within 1 day
-
TFR tensor core with DSM drops an MXFP4/NVFP4 NaN block scale when its elements are maskedPossibly taken @youzi27 claimed this 5 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 25/100
vortexgpgpu/vortex#516 ·
Maintainers usually reply within 1 day
All issues in vortexgpgpu/vortex
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 86/100
dsavransky/EXOSIMS#497 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
dginev/latexml-oxide#1132 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
EricZimmerman/evtx#281 ·
-
bugfix
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Maintainers usually reply within 3 days
-
ClickHouse: quantile is read as the exact Quantile, though ClickHouse's quantile is approximateOpen
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day