Skip to content

AffineCFG: check lockstep dependences on the parallel check's relations - #3405

Merged
wsmoses merged 1 commit into
mainfrom
pb/affine-lockstep-shared-relations
Oct 7, 2026
Merged

wsmoses merged 1 commit into
mainfrom
pb/affine-lockstep-shared-relations

Conversation

@wsmoses

@wsmoses wsmoses commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

Lockstep check: use the same dependence relations as the parallel check.

isLoopMemoryLockStepExecutable, which the raiser asks before running a constant-count loop in lock step, checked dependences with MLIR's checkMemrefAccessDependence. Meanwhile isLoopMemoryParallel builds its own access relations through InvariantTerms:

So an access whose index multiplies two symbols, or one under an scf.if, failed the lockstep check outright, even where the parallel check could analyze it.

The lockstep check now builds the same relations and calls checkAccessDependence, so all of these facts reach it too.

Where the guard facts reach lockstep. The raiser checks lockstep on outlined kernel functions. There, a host-side MFEM_VERIFY is not in the function being raised, so its facts reach only affine-cfg's parallel check, which runs before outlining. A guard inside the raised function does reach the lockstep check. As before, accesses to different memrefs, or two reads, have no dependence. Its rules for which dependences lockstep execution may break are unchanged.

Measured with affine-cfg, canonicalize and raising (enable_lockstep_for=true) on all 143 MFEM translation units. The raiser emits 14 fewer stablehlo.whiles (11,077 → 11,063), in bilininteg_dgtrace_ea (−5), bilininteg_mass_ea (−5), bilininteg_convection_ea (−3) and bilininteg_diffusion_ea (−1). No file gains any, and none fail.

Tests:

  • New raising/affine_to_stablehlo_lockstep_invariant_terms.mlir (full-line goldens), which fails on main: a 3-trip loop copying at an index offset by a product of two symbols now runs in lock step, as one gather and one scatter, instead of a while.
  • raising/affine_to_stablehlo_if_masking.mlir: @test_if_else_masking (per element, if (m[i]) a[i] *= 2 else a[i] *= a[i]) now runs in lock step as two whole-tensor selects instead of a while. That is correct: each iteration reads and writes only its own element.

Lit: every affinecfg* test, plus the raising tests above, against this branch rebased on main (which includes #3404 and #3406).

🤖 Generated with Claude Code

https://claude.ai/code/session_016zErYp7upmqr4NHfhod9UD

@wsmoses
wsmoses force-pushed the pb/affine-lockstep-shared-relations branch 2 times, most recently from 49a0f62 to 5119f9d Compare October 6, 2026 23:41
isLoopMemoryLockStepExecutable checked dependences with MLIR's
checkMemrefAccessDependence, while isLoopMemoryParallel builds its own
access relations (InvariantTerms): loop-invariant products of symbols
abstracted (#3369), domains that stop at the affine scope and read the
bounds defined above it as symbols (#3380), the facts of the nest's
in-bounds accesses (#3400) and of the checks on the way to it (#3404). An
access whose index multiplies two symbols, or one under an scf.if, failed
the lockstep check outright. It now builds the same relations and calls
checkAccessDependence; accesses to different memrefs, or two reads, have no
dependence, as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016zErYp7upmqr4NHfhod9UD
@wsmoses
wsmoses force-pushed the pb/affine-lockstep-shared-relations branch from 5119f9d to 4b0f2f4 Compare October 6, 2026 23:42
@wsmoses
wsmoses merged commit fef6747 into main Oct 7, 2026
12 of 20 checks passed
@wsmoses
wsmoses deleted the pb/affine-lockstep-shared-relations branch October 7, 2026 00:04
@codecov

codecov Bot commented Oct 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 29.61%. Comparing base (9409410) to head (4b0f2f4).
⚠️ Report is 29 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3405   +/-   ##
=======================================
  Coverage   29.61%   29.61%           
=======================================
  Files         240      240           
  Lines       48460    48467    +7     
=======================================
+ Hits        14351    14354    +3     
- Misses      34109    34113    +4     

☔ 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.

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