Repository navigation
Fix bar.red (__syncthreads_count/and/or) parsing and results - #155
Open
shatalov-alex wants to merge 4 commits into
Open
shatalov-alex wants to merge 4 commits into
shatalov-alex wants to merge 4 commits into
Conversation
bar.red.popc.u32, which nvcc emits for __syncthreads_count, stopped the PTX parser at its assertion for unhandled instruction options: the grammar accepts .popc as an atomic_operation_spec, but the option switch in the ptx_instruction constructor handled only .and and .or of the three bar.red operators. Store it as the operation, like them.
reduction_storage was zeroed once, when the core was created, and never again: every bar.red on a barrier added to the counts of all the earlier ones in the same CTA slot, so a second __syncthreads_count in a kernel returned the sum of both counts (and a CTA that later reused the slot started from the last one). Reset the barrier's storage once broadcast_barrier_reduction has given every waiting thread its result, before any warp can reach the next reduction.
With PTX_SIM_MODE_FUNC=1 the destination of bar.red was never written: the timing model delivers the result through shader_core_ctx::broadcast_barrier_reduction when the barrier releases, and functionalCoreSim had no counterpart, so __syncthreads_count returned whatever the register held (0 in practice). Keep each warp's bar.red instruction while it waits, and when every live warp has reached the barrier, run its callbacks and reset the barrier's storage, as the timing model does.
Both wrote the reduction as a plain 0 or 1 into their .pred destination. GPGPU-Sim's predicate registers hold a zero flag (setp_impl writes 1 for false), so every result was inverted. .and also accumulated with &= into storage that starts at 0, so it was always 0 before the inversion: __syncthreads_and returned true and __syncthreads_or returned the opposite of the vote. Count the false votes for .and (true when there are none), turn the count into the operator's result in bar_callback, and write predicate destinations in the zero-flag form.
shatalov-alex
added a commit
to shatalov-alex/qpel
that referenced
this pull request
Nov 13, 2026
…mitted upstream (accel-sim/gpgpu-sim_distribution#155); self-test checks __syncthreads_and/or; image qpel11
This was referenced Nov 14, 2026
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.
Four fixes to
bar.red(__syncthreads_count,__syncthreads_and,__syncthreads_or), one commit each. Before them, a kernel using__syncthreads_countaborted in the PTX parser; once it parsed, the results were wrong in both simulation modes.bar.red.popc.u32hits the assertion for unhandled instruction options in theptx_instructionconstructor (.andand.orwere handled,.popcwas not)reduction_storageis zeroed only when the core is created, so each reduction on a barrier builds on the previous ones in that CTA slotPTX_SIM_MODE_FUNC=1the destination is never written: only the timing model'sbroadcast_barrier_reductionruns the callbacks.preddestination as a plain 0/1, but predicate registers hold a zero flag (assetp_implwrites them), so it is inverted;.andalso accumulates with&=into storage that starts at 0Testing
Results of the reproducer below for block 0, after each commit (
devaborts in the parser). Each commit builds on its own with the Makefile flow on aarch64 (CUDA 12.6.3, gcc 13.2), with #153's Makefile change applied, which aarch64 needs.clang-format16.0.6 reports no changes.PTX_SIM_MODE_FUNC=1devExpected (CUDA semantics):
10 1 0 1 0 3. Block 1 gives the same. I found the.popcproblems running the rasterizer of Microsoft TRELLIS.2 (o-voxel), and the.and/.orone while testing these fixes. I have not built or run them on x86, and I could not run theshort-testsregressions (self-hosted runner).This PR is independent of #154 (it applies to
devon its own) and merges cleanly with it.Reproducer (
nvcc -O2 -cudart shared -gencode arch=compute_75,code=compute_75, SM75_RTX2060 config)