Repository navigation
Multigrid: fix transfer caches that ignore the element basis, and reuse transfer loops - #5548
Merged
Merged
Conversation
pbrubeck
force-pushed
the
pbrubeck/mg-transfer-cache
branch
from
October 22, 2026 15:42
259070a to
bd07717
Compare
pbrubeck
force-pushed
the
pbrubeck/mg-transfer-cache
branch
2 times, most recently
from
October 26, 2026 16:21
8bc643e to
0c9cf16
Compare
pbrubeck
force-pushed
the
pbrubeck/mg-transfer-cache
branch
from
October 27, 2026 11:51
0c9cf16 to
aeb048d
Compare
Adaptive refinement leaves the coarse points of unrefined cells unsplit. The values at fine nodes on those points are equal to the values at their coarse nodes, so the transfer kernels do not need to evaluate them. Split the owned fine nodes into refined and unrefined nodes. Run the prolongation and restriction kernels over the refined nodes only. Then copy the coarse values to the unrefined nodes during prolongation, and add the values at the unrefined nodes to their coarse nodes during restriction. Both copies are pyop3 loops through a node-to-node map, which handle the halo reads and the reductions into ghost nodes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The multigrid transfer kernels were cached on the DoF layout of their elements, so element variants with the same entity DoFs (e.g. DG2 equispaced and spectral) shared a kernel that tabulates the wrong basis. Key the kernels on the FInAT elements instead. The node maps of a hierarchy were cached on the entity DoFs alone, but the cell-node map also depends on the entity permutations, which differ between these variants. Add the entity permutations to the node map key. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
prolong, restrict and inject built and hashed new pyop3 loops on every call. Building the loops took about 8 ms per transfer, while executing them took about 0.2 ms. Build the transfer loops once for each pair of function spaces and data layouts, and cache them on the hierarchy. Later calls will execute the cached loops on the Dats of their own arguments, as FormAssembler does for its parloops. On adaptive hierarchies, the cached loops also include the loops that copy the values at unrefined nodes. A repeat solve with pc_type mg (8x8 base mesh, 2 refinements, CG2) drops from 0.33 s to 0.04 s. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
pbrubeck
force-pushed
the
pbrubeck/mg-transfer-cache
branch
from
November 26, 2026 13:36
aeb048d to
febc372
Compare
connorjward
requested changes
Nov 26, 2026
connorjward
left a comment
Contributor
There was a problem hiding this comment.
Otherwise consider this approved. Nice and simple with a big win.
Carry the iterator rename and review comments into the moved transfer loops. Clarify the setup in the multigrid transfer tests. Assisted-by: OpenAI Codex
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.
Stacked on #5288. The cached transfer loops also include the loops that copy the values at unrefined nodes on adaptive hierarchies. Without the cache, each of these copy loops cost about 5 ms per call.
Summary
Two commits, both in
firedrake/mg.1. Fix multigrid caches that ignore the element basis. Element variants with the same entity DoFs, e.g. DG2
equispacedandspectral, collided in two caches on the hierarchy:The cell-node map depends on the entity permutations, which differ between those variants. Each fix alone still gives O(1) errors. The kernel key uses FInAT elements, which hash by identity today and will hash by value with firedrakeproject/fiat#304. Both are correct, and the value-based hash also hits across construction routes.
2. Reuse multigrid transfer loops across calls.
prolong,restrictandinjectbuilt and hashed a new pyop3 loop on every call. Now each loop is built once for each pair of function spaces and data layouts, and replayed with new Dats by name, asFormAssembler.parloopsdoes:The loops are cached on
hierarchy._shared_data_cache["transfer_loops"], next to the node maps, so direct calls benefit as well asTransferManager.Evidence
test_grid_transfer_variants(new) prolongs and injects DG2 for both orders ofequispaced/spectralon one hierarchy:prolongerror 2.2e-01,injecterror 2.3e-01 for the second variant (4 failed)After: 3.7e-16 and 1.1e-15 (4 passed)
test_grid_transfer_reuses_loops(new, 1 and 2 ranks) checks that a second pass of transfers builds no loops, and that a mixed subfunction gets its own loop:After: passes
Timings for CG2 (minimum of repeats, 8×8 base mesh, 2 refinements):
prolongrestrictinjectpc_type: mgMerge Danger
Door: two-way
Blast Radius: moderate
Only multigrid transfers change. The cached loops keep the
Functions used to build them alive while the hierarchy lives, asFormAssemblerdoes with its first tensor.assemble_prolongation_aijstill builds its loop on every call, because it runs once per setup.AI assistance: this PR was written with Claude Code (Claude Opus 5.5).
🤖 Generated with Claude Code
https://claude.ai/code/session_01UuSK81ZfWY2LFahyWYpdPT