Skip to content

Only inject thread barriers where threads disagree about memory - #9390

Open
abadams wants to merge 2 commits into
abadams/block_to_vectorfrom
abadams/gpu_barrier_flattening
Open

Only inject thread barriers where threads disagree about memory#9390
abadams wants to merge 2 commits into
abadams/block_to_vectorfrom
abadams/gpu_barrier_flattening

Conversation

@abadams

@abadams abadams commented Aug 25, 2026

Copy link
Copy Markdown
Member

InjectThreadBarriers visited Blocks pairwise, so it put a barrier at every join in a sequence of statements regardless of whether the two halves touched any of the same memory. Take the whole sequence at once and compare each statement's footprint against everything since the last barrier, emitting one only for a genuine read-after-write, write-after-read, or write-after-write.

A barrier only fences the memory spaces named in its mask, so it only clears the footprint of those spaces. Accesses in a space it did not fence are still waiting for a barrier of their own.

The footprint is keyed on the storage a Func ends up in rather than its name. ExtractSharedAndHeapAllocations pools allocations with disjoint lifetimes onto the same memory, so two differently named Funcs can be the same bytes at different times, and the hazard between them is real. allocate_funcs takes its argument by value, because the grouping is now asked for twice and sorting the caller's vector would make the second answer depend on the first.

Textures are counted too. They are reached through image_load and image_store rather than Load and Store, so walking for the latter alone would miss a Func stored in MemoryType::GPUTexture entirely.

Across the correctness tests this drops the number of barriers emitted from 259 to 181.

abadams and others added 2 commits August 25, 2026 10:18
InjectThreadBarriers visited Blocks pairwise, so it put a barrier at
every join in a sequence of statements regardless of whether the two
halves touched any of the same memory. Take the whole sequence at once
and compare each statement's footprint against everything since the last
barrier, emitting one only for a genuine read-after-write,
write-after-read, or write-after-write.

A barrier only fences the memory spaces named in its mask, so it only
clears the footprint of those spaces. Accesses in a space it did not
fence are still waiting for a barrier of their own.

The footprint is keyed on the storage a Func ends up in rather than its
name. ExtractSharedAndHeapAllocations pools allocations with disjoint
lifetimes onto the same memory, so two differently named Funcs can be
the same bytes at different times, and the hazard between them is real.
allocate_funcs takes its argument by value, because the grouping is now
asked for twice and sorting the caller's vector would make the second
answer depend on the first.

Textures are counted too. They are reached through image_load and
image_store rather than Load and Store, so walking for the latter alone
would miss a Func stored in MemoryType::GPUTexture entirely.

Across the correctness tests this drops the number of barriers emitted
from 259 to 181.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@codecov

codecov Bot commented Aug 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.05%. Comparing base (dd9ecf9) to head (1067c09).

Files with missing lines Patch % Lines
src/FuseGPUThreadLoops.cpp 91.66% 3 Missing and 4 partials ⚠️
Additional details and impacted files
@@                     Coverage Diff                     @@
##           abadams/block_to_vector    #9390      +/-   ##
===========================================================
- Coverage                    70.11%   70.05%   -0.07%     
===========================================================
  Files                          261      261              
  Lines                        79190    79355     +165     
  Branches                     19305    19336      +31     
===========================================================
+ Hits                         55524    55591      +67     
- Misses                       17893    17920      +27     
- Partials                      5773     5844      +71     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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