Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dsl: Move SubDimension thickness evaluation to the thicknesses themselves #2470

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

EdCaunt
Copy link
Contributor

@EdCaunt EdCaunt commented Oct 18, 2024

Fixes issues with standalone use of SubDimension.symbolic_min or SubDimension.symbolic_max in an operator. Previously variants on

x = Dimension('x')
ix = SubDimension.left('ix', x, 2)
f = Function(name="f", dimensions=(ix,), shape=(5,), dtype=np.int32)

eqns = Eq(f[ix.symbolic_max], 1)

op = Operator(eqns)
op(x_m=0)

would suffer from two issues:

  1. The SubDimension thickness (ix.symbolic_max) would not be concretised from x_ltkn to x_ltkn0
  2. The SubDimension thickness would never be given a value by _arg_values unless the user explicitly passed it to the operator (and even then, it would not be adjusted to reflect any MPI decomposition)

These are rectified by this PR.

Copy link
Contributor

@FabioLuporini FabioLuporini left a comment

Choose a reason for hiding this comment

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

Looks like a very nice clean up!

@@ -640,6 +642,11 @@ def _prepare_arguments(self, autotune=None, **kwargs):
for d in reversed(toposort):
args.update(d._arg_values(self._dspace[d], grid, **kwargs))

# Process SubDimensionThicknesses
for p in self.parameters:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be triggered from within SubDimension._arg_values itself

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, the issue is that the SubDimension isn't necessarily available to the operator. You can craft legal Operators which only contain the thickness, not the parent subdimension, hence the reworking in this PR

devito/types/dimension.py Outdated Show resolved Hide resolved
@@ -536,6 +535,81 @@ def _arg_check(self, *args, **kwargs):
# The Dimensions below are exposed in the user API. They can only be created by
# the user

class SubDimensionThickness(DataSymbol):
"""A DataSymbol to represent a thickness of a SubDimension"""
Copy link
Contributor

Choose a reason for hiding this comment

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

full stop

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thought we didn't do those on single line docstrings?

devito/types/dimension.py Outdated Show resolved Hide resolved
rtkn = r_rtkn or 0

return {i.name: v for i, v in zip(self._thickness_map, (ltkn, rtkn))}
# SubDimension thicknesses at runtime are calculated by the thicknesses
Copy link
Contributor

Choose a reason for hiding this comment

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

as I wrote in another comment, this SubDimension should trigger the processing of its own arguments, namely its own Thicknesses

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They shouldn't (or at least it would be redundant if it did), see my other comment

Copy link

codecov bot commented Oct 18, 2024

Codecov Report

Attention: Patch coverage is 81.60000% with 23 lines in your changes missing coverage. Please review.

Project coverage is 57.49%. Comparing base (7795225) to head (1d056ab).

Files with missing lines Patch % Lines
tests/test_dimension.py 9.09% 10 Missing ⚠️
devito/types/dimension.py 94.50% 3 Missing and 2 partials ⚠️
devito/ir/equations/algorithms.py 72.72% 3 Missing ⚠️
tests/test_symbolics.py 0.00% 3 Missing ⚠️
tests/test_caching.py 0.00% 2 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (7795225) and HEAD (1d056ab). Click for more details.

HEAD has 7 uploads less than BASE
Flag BASE (7795225) HEAD (1d056ab)
16 9
Additional details and impacted files
@@             Coverage Diff             @@
##           master    #2470       +/-   ##
===========================================
- Coverage   87.17%   57.49%   -29.68%     
===========================================
  Files         239      238        -1     
  Lines       45160    45155        -5     
  Branches     4007     4007               
===========================================
- Hits        39367    25961    -13406     
- Misses       5112    18373    +13261     
- Partials      681      821      +140     

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

Copy link
Contributor

@mloubout mloubout left a comment

Choose a reason for hiding this comment

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

some mnior comments

devito/types/dimension.py Outdated Show resolved Hide resolved
devito/types/dimension.py Outdated Show resolved Hide resolved

mapper[d] = d._rebuild(symbolic_min=left, symbolic_max=right, thickness=thickness)
tkns = tuple(t._rebuild(name=sregistry.make_name(prefix=t.name)) for t in d.tkns)
mapper.update({t0: t1 for t0, t1 in zip(d.tkns, tkns)})
Copy link
Contributor

Choose a reason for hiding this comment

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

I would avoid t0 and t1 due to name clash with time buffers.
It's not about correctness, but mostly when grepping

# Dimension is of type `left`/`right` - compute the offset
# and then add 1 to get the appropriate thickness
if self.value is not None:
tkn = grid.distributor.glb_to_loc(self.root, r_tkn-1, self.side)
Copy link
Contributor

Choose a reason for hiding this comment

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

why r_tkn-1?

@property
def is_abstract(self):
return all(i is None for i in flatten(self.thickness))
tkns = thickness # Shortcut for thickness
Copy link
Contributor

Choose a reason for hiding this comment

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

should this not be a cached propertry?

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.

4 participants