Repository navigation
Conversation
A SubGrid Function used in an equation is now read at the left-hand side's
location, the convention staggered Functions already follow -- no wrapper and
no flag:
sub = SubGrid(grid, factor=1.5)
vp = Function(name='vp', grid=sub)
Eq(u, vp*u)
`SubGrid` accepts non-integer and sub-unit factors, dispatching on the factor:
integer factors keep the strided ConditionalDimension lowering, anything else
gets its own SpaceDimensions and interpolates. `is_interpolated` distinguishes
the two, and a factor of exactly 1 passes the parent's Dimension through.
`Function._eval_at` emits a `SubGridInterp` marker that FD lowering leaves
inert, and the new Cluster pass `subgrid_interp` expands it once the iteration
space is known -- the same deferral `IndexDerivative` uses. Reading a SubGrid at
the parent's point `x` evaluates at `x*q/p` for `factor = p/q`, so the base
index is `(x*q)//p` and the fractional part repeats with period `p`. The weights
are therefore constants within a phase and live in a compile-time table indexed
by `Mod(x, p)`: no phase loop, no branch, and unit-stride loops over the
parent's Dimensions alone.
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
Contributor
Author
|
Opened prematurely without approval; work is not ready for review. Closing. |
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.
Part 2 of subgrid support, on top of #3080 (integer subsampling). Merge #3080 first — this PR targets that branch, so the diff here is a single commit.
API
A SubGrid Function used in an equation is read at the left-hand side's location, the convention staggered Functions already follow. No wrapper, no flag:
SubGridnow dispatches on the factor:is_interpolatedFalseTrueshapeceil(n/factor)floor((n-1)/factor) + 1dimensionsConditionalDimensionsSpaceDimensionsPer-axis factors are independent; a factor of exactly 1 passes the parent's own Dimension through. Factors below 1 refine rather than coarsen.
Lowering
Three steps, each in the layer that owns the information:
Function._eval_atemits aSubGridInterpmarker.generate_indicesneeds a compile-timemid, and the subgrid offset varies with the iteration index.subgrid_interpexpands it once the iteration space is known.IndexDerivativeis the precedent for exactly this deferral.Reading a SubGrid at the parent's point
xevaluates atx*q/pforfactor = p/q, sofracdepends onxonly throughx % p, so there arepphases and the weights are constants within a phase. They live in a compile-time table indexed byMod(x, p)— which means no phase loop at all, and the inner loops stay unit-stride and branch-free:No
LocalSum(benchmarked 1.7–3.5x slower and non-vectorizing), nofloorf, no guard.Two subtleties worth reviewer attention
d in ispace.itdimstest silently fails and 3D ends up half-relocated. Fixed viaispace.promote(lambda d: d.is_Block), the same idiom asir/stree/algorithms.py:194.xs is x), so it must not be projected out of the IterationSpace — dropping it leaves a loop bound with no runtime value.Both have dedicated regression tests, each verified to fail when its fix is reverted.
Tests
tests/test_subgrid.py, 27 tests: relocation follows the LHS; parent Dimensions only in the ispace; plain stencil (noLocalSum, no branch); tap counts; the two subtleties above; exactness on linear fields in 1D/2D/3D; constant field (weights sum to 1 at every phase);factor < 1refines; integer factors keep Part 1's lowering.Verified:
DEVITO_LANGUAGE∈ {C, CXX, openmp, CXXopenmp} (withtests/test_subsampling.py, incl. 14 MPI tests)test_dimension,test_operator,test_dse,test_derivatives,test_staggered_utils,test_interpolation(2, 1.5),(2, 1.5, 1.0)The tutorial
examples/userapi/10_subgrids.ipynbgains an interpolation section showing the generated code for each case.Not in this PR
vp[IntDiv(...) + o], not affine, so affine inference does not see them;HaloComms.callbackadditionally gates ond._defines & hs.distributed_aindices, which fails because the loop iterates the parent's Dimensions while the halo is keyed on the subgrid's.🤖 Generated with Claude Code