Hello everyone,
I am investigating whether modern NVIDIA GPUs implement warp‑level out‑of‑order instruction scheduling, focusing on Hopper (SM90) and Blackwell (SM100).
The core instruction flow within each loop iteration is:
memcpy_async(TMA_issue) → barrier.wait → lds(in‑flight, load TMA‑fetched shared‑memory data to per‑thread registers) → add(depends on full lds completion) → syncthreads → next‑loop TMA
For the purpose of validating this hardware question, the kernel explicitly loads all shared‑memory data into per‑thread registers first, then performs add arithmetic using those register values. All content inside shared memory is transferred from global memory by prior TMA memcpy_async operations. If any add instruction gets issued, it implies all preceding lds have completed and all data is already present in registers.
Critical note: The subsequent TMA writes into the same shared‑memory slot whose content is currently being read by outstanding
lds. If this TMA instruction gets issued, its underlying async‑proxy TMA will overwrite the shared‑memory contents that in‑flightldsis consuming.
Core question:
When lds is still in‑flight (not completed, data not yet in registers), its dependent add is held back and has not been issued yet. The following TMA memcpy_async has no register data dependency on lds / add. Can the warp scheduler inside a single warp skip this un‑issued dependency‑blocked add, and directly issue this later independent TMA UBLKCP.S.G instruction?
Below is pseudocode and the inner‑loop instruction sequence of my kernel.
Grid_Dim=1
Block_DIm=32
// phase‑1 (kernel prologue)
thread0: memcpy_async(TMA, global→shared slot0, bar[0]) // shared memory populated by TMA transfer
// main‑loop stage = 1 ~ 7
for stage in [1,2,3,4,5,6,7]:
prev_slot = (stage‑1) & 1
cur_slot = stage & 1
thread0: memcpy_async(TMA, global→shared cur_slot, bar[cur_slot]) // TMA fills cur_slot with global data
barrier.arrive(prev_slot)
barrier.wait(prev_slot) // Wait for async‑proxy TMA write completion on prev_slot
// all threads execute
// Load EVERY element from shared‑memory slot (data brought by earlier TMA) into private per‑thread registers
lds sm_slot[prev_slot] → reg_vec[i]
// add only executes after ALL lds finish and populate reg_vec
add partial_sum, reg_vec[i]
__syncthreads() // CTA synchronization barrier
//fence_proxy_async(shared)
// Next‑iteration TMA will overwrite prev_slot shared memory (originally filled by TMA), no register dependency on lds/add
end‑for
// drain phase for stage=7, data resides in last_slot
...
SASS:
Function : _Z11test_kernelPjS_jjj
.headerflags @"EF_CUDA_ACCELERATORS EF_CUDA_SM100 EF_CUDA_VIRTUAL_SM(EF_CUDA_SM100)"
// ...
// init: barrier init + init fence, then first __syncthreads
/*0370*/ BAR.SYNC.DEFER_BLOCKING 0x0 ; /* 0x0000000000007b1d */
/* 0x004fea0000010000 */
// ...
// tma load: phase-1 prefetch stage0 -> slot0 (issued by pseudo-random issuer thread)
/*0460*/ UBLKCP.S.G [UR8], [UR4], UR10 ; /* 0x00000008040073ba */
/* 0x0001d8000800020a */
// mbarrier expect: arrive bar[0] so the TMA completion flips the phase
/*04b0*/ SYNCS.ARRIVE.TRANS64.RED.A0TR RZ, [UR9], R2 ; /* 0x00000002ffff79a7 */
/* 0x0001e60008300409 */
// begin loop
/*05f0*/ BSSY.RECONVERGENT B0, 0x7c0 ; /* 0x000001c000007945 */
/* 0x000fe60003800200 */
// ... (loop prologue: slot base / per-thread slice address)
// tma load ping-pong: prefetch next stage into cur_slot (issuer thread only)
/*0750*/ UBLKCP.S.G [UR10], [UR4], UR16 ; /* 0x0000000a040073ba */
/* 0x0001d80008000210 */
// mbarrier expect: arrive bar[cur_slot] for the in-flight TMA
/*07a0*/ SYNCS.ARRIVE.TRANS64.RED.A0TR RZ, [UR11], R68 ; /* 0x00000044ffff79a7 */
/* 0x0001e6000830040b */
// arrive prev_slot (token) + start timer, then wait: prev_slot TMA write is done
/*0800*/ SYNCS.ARRIVE.TRANS64.A1T0 R80, [UR5], RZ ; /* 0x000000ffff5079a7 */
/* 0x000e620008100005 */
/*0810*/ CS2R R68, SR_GLOBALTIMERLO ; /* 0x0000000000447805 */
/* 0x001fe20000015200 */
// mbarrier wait
/*0820*/ SYNCS.PHASECHK.TRANS64.TRYWAIT P0, [UR5], R81 ; /* 0x00000051ff0075a7 */
/* 0x002e240008001105 */
// ... (spin-wait until phase complete)
// LDS: consume the ping-pong slot into registers
/*0a80*/ @!P2 LDS.128 R4, [R68] ; /* 0x000000004404a984 */
/* 0x0000680000000c00 */
/*0a90*/ @!P2 LDS.128 R8, [R68+0x10] ; /* 0x000010004408a984 */
/* 0x0000a20000000c00 */
// ... LDS
// add: accumulate the loaded vectors
/*0cc0*/ @!P2 IADD3 R68, PT, PT, R5, R4, R2 ; /* 0x000000040544a210 */
/* 0x00bfc80007ffe002 */
/*0cd0*/ @!P2 IADD3 R68, PT, PT, R7, R68, R6 ; /* 0x000000440744a210 */
/* 0x000fc80007ffe006 */
// ... IADD3
// proxy fence (loop fence): order async-proxy TMA writes before __syncthreads
// WITHOUT this the next TMA could overwrite the slot still being consumed (WAR)
/*0fd0*/ MEMBAR.ALL.CTA ; /* 0x0000000000007992 */
/* 0x0001ec0000008000 */
/*0fe0*/ FENCE.VIEW.ASYNC.S ; /* 0x00000000000073c6 */
/* 0x001e220000000000 */
// __syncthreads: barrier before next TMA may overwrite this slot (WAR guard)
/*1010*/ BAR.SYNC.DEFER_BLOCKING 0x0 ; /* 0x0000000000007b1d */
/* 0x001ff00000010000 */
// loop back
/*1020*/ BRA.U UP0, 0x5d0 ; /* 0xfffffff500687547 */
Background
If the warp scheduler supports out‑of‑order issue within a warp, fence_proxy_async would be required for correctness. Conversely, strict in‑order issue would make this fence unnecessary.
I removed the fence_proxy_async from the code referenced in the PR ( Fix race condition in RHT amax kernels by ksivaman · Pull Request #2695 · NVIDIA/TransformerEngine)and ran tests on H100 and B200. No shared‑memory corruption caused by subsequent TMA overwriting in‑flight lds read data was observed.
Thank you very much.