Repository navigation
Make GPU- and system-scope memory barriers wait for store acks - #152
Open
karthikbhata97 wants to merge 1 commit into
Open
karthikbhata97 wants to merge 1 commit into
karthikbhata97 wants to merge 1 commit into
Conversation
shader_core_ctx::warp_waiting_at_mem_barrier() released a warp from a
memory barrier as soon as the scoreboard had no pending register writes
for it. The scoreboard tracks only instruction output registers, and a
store has none, so a membar never waited for the warp's stores to be
acknowledged, although the comment in that function says a memory barrier
must "wait for all pending writes till they are acked". The per-warp store
counter shd_warp_t::m_stores_outstanding (stores_done()) already exists
but was consulted only at warp exit. As a result membar.cta, membar.gl and
membar.sys all cost the same, and GPU- and system-scope fences were modeled
as too cheap.
Record the scope of a memory barrier on inst_t (membar_scope:
MEMBAR_SCOPE_{UNKNOWN,CTA,GPU,SYS}), set it from the PTX membar level in
ptx_instruction::set_opcode_and_latency(), and pass it to the warp at
issue. A barrier that is not CTA-scope now also waits until every
instruction the warp issued up to and including the barrier has left the
pipeline (so their memory requests have been sent and counted) and until
stores_done(). CTA-scope barriers keep the old behavior. A barrier whose
scope is unknown waits for the stores too: that is never too optimistic,
and it is what trace-driven MEMBARs get until the trace front end sets the
scope from the SASS opcode.
Functional results are unchanged; only the timing of fences changes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
karthikbhata97
marked this pull request as ready for review
November 5, 2026 15:31
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
shader_core_ctx::warp_waiting_at_mem_barrier()(src/gpgpu-sim/shader.cc) releases a warp from a memory barrier as soon asm_scoreboard->pendingWrites(warp_id)is false:The scoreboard reserves only instruction output registers (
Scoreboard::reserveRegisters). A store has no output register, so a fence never waits for the warp's stores to be acknowledged, even though the comment above says it must. The per-warp store counter already exists:shd_warp_t::m_stores_outstanding/stores_done()is incremented when the LDST unit sends a store request and decremented inshader_core_ctx::store_ack(). Today it is checked only when the warp exits.As a result,
membar.cta,membar.glandmembar.sysall cost the same, and GPU- and system-scope fences are modeled as too cheap. Functional results are not affected, because the functional model executes in order. The same code is ingpgpu-sim/gpgpu-sim_distributionmaster.Fix
inst_tgets a memory-barrier scope (membar_scope:MEMBAR_SCOPE_{UNKNOWN,CTA,GPU,SYS}), next to the existing fence-proxy fields.PTX mode:
ptx_instruction::set_opcode_and_latency()sets the scope from themembarlevel (.cta/.gl/.sys).issue_warp()passes the scope to the warp:set_membar(next_inst->get_membar_scope()).warp_waiting_at_mem_barrier(): a barrier that is not CTA-scope keeps the warp waiting until two things hold:num_issued_inst_in_pipeline() == 0);stores_done()).After that, the existing register-write check and the L1 flush apply as before. CTA-scope barriers keep today's behavior.
Why the pipeline condition:
inc_store_req()runs only when the LDST unit sends the store's requests. A store issued one or two cycles before the fence is usually still in the operand collector or the LDST pipe when the fence is checked, sostores_done()alone misses it. In the microbenchmark below,stores_done()alone captures less than half of the effect (QV100: 7357 cycles, compared with 8640 for the full fix). The fence itself goes down the MEM pipe, so the condition also covers the fence's own trip through the LDST unit. This cannot block forever: every in-flight instruction completes without the warp issuing anything else, and a warp already needsstores_done()before it can exit.Unknown scope waits (conservative). A barrier whose scope is not set (
MEMBAR_SCOPE_UNKNOWN) is treated like a GPU-scope one. For an unknown fence, waiting can only make timing too pessimistic, while not waiting would silently repeat the bug. Trace-driven MEMBARs are in this case until the trace front end sets the scope. That is a companion PR in accel-sim-framework: accel-sim/accel-sim-framework#580. Until it is merged, trace-drivenMEMBAR.CTAalso waits for store acks.Tests
Built on Ubuntu with CUDA 12.4 (the Makefile build for PTX mode; the accel-sim-framework
devCMake build, which also compiles this tree, for trace mode). No new compiler warnings.format-code.sh(clang-format 16.0.6) leaves the tree unchanged.Microbenchmark, PTX mode. 80 CTAs x 256 threads, each doing 16 iterations of a global store followed by a fence. The table shows
gpu_tot_sim_cycle, before -> after:__threadfence_block()(membar.cta)__threadfence()(membar.gl)__threadfence_system()(membar.sys)membar.ctaruns give the same statistics output as before, line for line, apart from wall-clock rates and host addresses. This holds on all five configs.threadFenceReduction(cuda-samples v12.4,--n=65536, SM7_QV100, PTX mode):gpu_tot_sim_cycle855536 -> 873736 (+2.1%). The instruction count is the same and the GPU result matches the CPU result. This sample issues only one__threadfence()per block, so the effect is small.rodinia_2.0-ft, PTX mode (SM7_QV100, the 10 apps and arguments of
define-all-apps.yml, gpu-app-collection built with CUDA 12.4). None of these apps has amembar.gpu_tot_sim_cycle, instruction counts and all other statistics are identical in every app, with one exception: per-stream*_stats_breakdownlines differ in bfs, lud, nw, srad_v2 and streamcluster.m_membar_scopefield toinst_t, with no logic change. Against that control build, this PR's statistics are identical in all 10 apps.kernel_stream_idchanges from build to build).Trace mode (accel-sim-framework
devbuilt against this branch):rodinia_2.0-ftV100 traces (the CI set) on SM7_QV100: the output is identical in all 10 apps.MEMBAR.SC.CTA/MEMBAR.SC.GPU/MEMBAR.SC.SYS), on SM86_RTX3070:MEMBAR.SC.GPUandMEMBAR.SC.SYS: 7422 -> 9467 (+27.6%);MEMBAR.SC.CTAwith this PR alone: 7391 -> 9424 (the conservative unknown-scope wait);MEMBAR.SC.CTAwith this PR plus the companion PR: 7391, identical output to before.Measured effect on real workloads. On a research fork of Accel-Sim, a prototype of this change (GPU-scope MEMBARs in SASS traces wait for store acks) changed the simulated time of fence-heavy kernels by up to 24%.
🤖 Generated with Claude Code