Skip to content

compiler: Prevent HaloTouches from blocking topological fusion - #3128

Open
EdCaunt wants to merge 5 commits into
mainfrom
fix-halotouch-toposort
Open

EdCaunt wants to merge 5 commits into
mainfrom
fix-halotouch-toposort

Conversation

@EdCaunt

@EdCaunt EdCaunt commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Every HaloTouch wrote the same mock Symbol, so all HaloTouches were totally ordered via output dependences. Combined with the mock WARs tying each HaloTouch to the Functions its owner writes, this could pin a HaloTouch between independent Clusters, preventing their fusion depending on the order of the input equations (e.g. equations over SubDomains given per equation rather than per SubDomain).

  • Each HaloTouch now writes its own mock Symbol, named via the SymbolRegistry
  • Introduce _sink_halospots to mpi.py to push halospots down to the first loop nest reading them (for computation-communication overlap)
  • More permissive halospot merging where computation-communication overlap isn't required

@codecov

codecov Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.93617% with 98 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.93%. Comparing base (bbf8169) to head (77452eb).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
tests/test_mpi.py 6.89% 54 Missing ⚠️
devito/passes/iet/mpi.py 7.31% 37 Missing and 1 partial ⚠️
devito/passes/clusters/fusion.py 95.08% 2 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3128      +/-   ##
==========================================
- Coverage   83.99%   83.93%   -0.07%     
==========================================
  Files         261      263       +2     
  Lines       60017    60554     +537     
  Branches     5065     5135      +70     
==========================================
+ Hits        50413    50826     +413     
- Misses       8760     8879     +119     
- Partials      844      849       +5     
Flag Coverage Δ
pytest-gpu-aomp-amdgpuX 67.95% <56.35%> (-0.31%) ⬇️
pytest-gpu-gcc- 78.73% <73.93%> (-0.07%) ⬇️
pytest-gpu-icx- 78.69% <73.93%> (-0.02%) ⬇️
pytest-gpu-nvc-nvidiaX 68.77% <56.35%> (-0.33%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

Comment thread devito/passes/iet/mpi.py


def _merge_halospots(iet):
def _sink_halospots(iet):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed as a result of the changes in algorithms.py to ensure that test_avoid_merging_if_diff_functions still retains its original behaviour (with MPI modes featuring computation-communication overlap - more permissive merging of halo exchanges is preferable otherwise).

@EdCaunt EdCaunt added MPI mpi-related compiler python Pull requests that update python code labels Dec 1, 2026
@EdCaunt
EdCaunt requested a review from FabioLuporini December 1, 2026 16:20
EdCaunt and others added 2 commits December 2, 2026 14:39
Every HaloTouch wrote the same mock Symbol, so all HaloTouches were totally
ordered via output dependences. Combined with the mock WARs tying each
HaloTouch to the Functions its owner writes, this could pin a HaloTouch
between independent Clusters, preventing their fusion depending on the
order of the input equations (e.g. equations over SubDomains given per
equation rather than per SubDomain).

* Each HaloTouch now writes its own mock Symbol, named via the SymbolRegistry
* Fusion's topological sorting no longer schedules HaloTouches: they are
  drained as soon as ready, and reinserted after their predecessors and
  before their earliest successor, within the run of loop nests sharing
  loops with the latter, at the gap splitting the fewest shared loops. This
  preserves the existing halo exchange placement (e.g. no merging of the
  exchanges of different Functions) while allowing the fusion

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@EdCaunt
EdCaunt force-pushed the fix-halotouch-toposort branch from ffbc420 to 36570b4 Compare December 2, 2026 14:40
EdCaunt and others added 3 commits December 3, 2026 13:41
Replace the greedy choice in `Fusion._toposort` with ordered typed fusion
[Kennedy & McKinley, 1993]: one type at a time, each ClusterGroup joins the
first group of its type it may fuse with (compatible IterationSpace, no fence
or prefix anti-dependence in between, contraction keeps the DAG acyclic), and
groups are emitted in topological order, ready HaloTouches first. The greedy
choice could not see that scheduling a HaloTouch unblocks a fusible successor.

Output dependences not carried by the prefix no longer glue Clusters into the
same ClusterGroup at inner levels, as they only impose an order. Conservative
WAWs between disjoint SubDomains made such groups atomic, preventing fusion.

`Keys.type` extends `Keys.full` with the data type and the iteration
Dimensions, which `Cluster.from_clusters` also requires, and keys both typed
fusion and the actual fusion of adjacent Clusters.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Add `toposort='topdown'`, which reorders Clusters from the outermost level
inwards, so that each level is ordered before being divided, and then fuses
them. With `toposort=True`, a Cluster moved at an outer level never reaches the
inner groups it may fuse with, so the outcome depends on equation order.

* `Reorder` runs ordered typed fusion top-down: a fine pass by `Keys.type`,
  then a coarse pass merging the groups that may share an outer loop
* Clusters sharing storage the shared loop doesn't index (e.g. contracted
  temporaries) stay one indivisible unit
* Unless tasks are fused, Clusters with locks stay in program order
* HaloTouches no longer type a ClusterGroup nor constrain its compatibility,
  which also fixes `toposort=True`
* Core CPU and GPU pipelines switch to `toposort='topdown'`

Co-Authored-By: Claude Opus 5.5 <[email protected]>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler MPI mpi-related python Pull requests that update python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants