Skip to content

Fixing Unit Tests#42

Closed
npoulad1 wants to merge 2 commits into
amd-integrationfrom
fix/npoulad/unittest-fixes-rebase-1.0.0
Closed

Fixing Unit Tests#42
npoulad1 wants to merge 2 commits into
amd-integrationfrom
fix/npoulad/unittest-fixes-rebase-1.0.0

Conversation

@npoulad1

Copy link
Copy Markdown
Collaborator

Fixes a family of wave64-only (gfx94x) correctness bugs surfaced by the block-scan
and device radix-sort unit tests on AMDGPU. It eliminates the entire radix/sort/rank failure class with no
regressions.

npoulad1 and others added 2 commits June 10, 2026 22:30
…uffle

Fixes a family of wave64-only correctness bugs surfaced by the block scan
and device radix sort unit tests on AMDGPU (gfx94x), with no throughput
regression on the Genesis G1 RL scaling benchmark (233k env*steps/s, within
noise of stock).

- block.py: rewrite block inclusive/exclusive scan to a pure-LDS
  double-buffered Hillis-Steele pass, and rewrite the wave64 radix-rank
  match phase to a ballot-based CUB MatchAny. Removes the i64 LDS atomic_or
  + divergent cross-half shuffle hazards that miscompiled on wave64.

- runtime.cpp: fix amdgpu_cross_half_shuffle_i32 lane select to key on
  (target_lane & 32) instead of (target_lane ^ self_lane) & 32. The old form
  inverted the selection for top-half readers, corrupting every cross-half
  read on lanes 32..63 (block scans via shuffle_up first diverged at thread 32).

- llvm_context.cpp: widen the permlane64 LDS-emulation fences from wavefront
  to workgroup scope so SIMemoryLegalizer actually emits the s_waitcnt
  lgkmcnt(0) that orders the LDS round-trip; add a trailing fence to close the
  across-call write-after-read hazard between back-to-back permlane64 calls.

- codegen_amdgpu.cpp: force-inline any range_for body that touches LDS
  (addrspace(3)) regardless of size. Out-of-line bodies get a separate LDS
  frame, so cross-thread SharedArray publish/observe (radix histogram bins,
  block reductions) read stale memory -- the >200-instruction inline gate left
  the radix-rank body out-of-line and nondeterministically wrong. Detection
  descends through ConstantExprs since the SharedArray addrspacecast folds to
  a constant.

Co-authored-by: Cursor <cursoragent@cursor.com>
Fix the two pre-commit failures from CI on this branch:
- block.py: remove the now-unused ``i64`` import (F401). The ballot-based
  radix-rank rewrite no longer references the i64 primitive type.
- llvm_context.cpp: apply clang-format line-length reflow to the permlane64
  LDS-fence comment block.

Co-authored-by: Cursor <cursoragent@cursor.com>
@npoulad1 npoulad1 closed this Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant