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

compiler: Improve IndexDerivatives lowering #2183

Closed
wants to merge 49 commits into from

Conversation

FabioLuporini
Copy link
Contributor

@FabioLuporini FabioLuporini commented Aug 8, 2023

Comments:

  • TODO: rebase and squash away some commits
  • not to be merged until we introduce git-submodule in PRO DONE
  • some notebooks still to be updated DONE
  • no new features added; mostly restructuring, improvements, tweaks, minor fixes

Anyway, open for early reviewing.

EDIT: About time to start reviewing

@@ -1064,3 +1090,147 @@ def r_all(self):
All Relations of the Scope.
"""
return list(self.r_gen())


class ExprGeometry(object):
Copy link
Contributor Author

@FabioLuporini FabioLuporini Aug 8, 2023

Choose a reason for hiding this comment

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

Lifted and tweaked from passes/clusters/aliases.py

@codecov
Copy link

codecov bot commented Aug 8, 2023

Codecov Report

Merging #2183 (9041b7c) into master (7763d03) will decrease coverage by 0.11%.
The diff coverage is 82.93%.

@@            Coverage Diff             @@
##           master    #2183      +/-   ##
==========================================
- Coverage   87.06%   86.95%   -0.11%     
==========================================
  Files         228      228              
  Lines       40299    40774     +475     
  Branches     7357     7483     +126     
==========================================
+ Hits        35088    35457     +369     
- Misses       4625     4724      +99     
- Partials      586      593       +7     
Files Changed Coverage Δ
tests/test_gpu_common.py 1.44% <0.00%> (ø)
devito/ir/support/guards.py 51.77% <9.09%> (-7.74%) ⬇️
devito/types/basic.py 92.46% <33.33%> (-0.79%) ⬇️
devito/tools/data_structures.py 67.69% <36.17%> (-4.98%) ⬇️
devito/operator/operator.py 87.94% <50.00%> (-0.56%) ⬇️
devito/ir/support/space.py 89.74% <54.54%> (-0.81%) ⬇️
devito/passes/clusters/cse.py 96.66% <57.14%> (-3.34%) ⬇️
devito/ir/support/utils.py 84.83% <67.56%> (-5.50%) ⬇️
devito/finite_differences/differentiable.py 93.68% <70.00%> (-0.51%) ⬇️
devito/finite_differences/tools.py 92.96% <75.00%> (-0.76%) ⬇️
... and 32 more

... and 3 files with indirect coverage changes

@FabioLuporini FabioLuporini force-pushed the revamp-opt-derivs-rebased branch from 8f8871e to 4d2f5f2 Compare August 23, 2023 16:25
@georgebisbas georgebisbas changed the title Improve IndexDerivatives lowering compiler: Improve IndexDerivatives lowering Sep 4, 2023
if not expand and indices.expr is not None:
weights = Weights(name='w', dimensions=indices.free_dim, initvalue=weights)

if matvec == transpose:
# For homogenity, always generate e.g. `x + i0` rather than `x - i0`
Copy link
Contributor

Choose a reason for hiding this comment

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

Homogeneity

return Properties(properties)


def tailor_properties(properties, ispace):
Copy link
Contributor

Choose a reason for hiding this comment

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

tailor_*
reduce_*
normalize_*
relax_*

better to add docstrings that would make clear what is the use of each one.
I feel the names are not really helpful to someone who would read the code.
ofc they are all used in different ways, different args and context.... just saying how it feels


# *** Utils

def and_smart(relation, v):
Copy link
Contributor

Choose a reason for hiding this comment

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

simplify_and ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, will change

@@ -916,6 +929,10 @@ def is_compatible(self, other):
def itdimensions(self):
return self.intervals.dimensions

@property
def itdims(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

redundant?
Why not use directly itdimensions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's indeed a shortcut. Itdimensions is painfully long and so we ought to update it everywhere. Maybe I'll do that in this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

doing it

return Extrema(minimum(expr), maximum(expr))


def minmax_index(expr, d):
Copy link
Contributor

Choose a reason for hiding this comment

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

dim_extrema or similar?

except (AttributeError, TypeError):
# E.g., the section has a dynamic loop size
points = np.nan

Copy link
Contributor

Choose a reason for hiding this comment

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

Why gap?

def next(self, prefix, d, clusters):
# If a whole new set of Dimensions, move the tip -- this means `clusters`
# at `d` represents a new loop nest or kernel
x = any(i.dim.is_Block for i in flatten(c.ispace for c in clusters))
Copy link
Contributor

Choose a reason for hiding this comment

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

something different than x?

@@ -57,6 +62,37 @@ def track_subsections(iet, **kwargs):

iet = Transformer(mapper).visit(iet)

# Multi-pass implementations
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this PRO only?

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


def _subs(self, old, new, **hints):
# Wrap in a try to make sure no substitution happens when
# old is an Indexed as only checkink `old is new` would lead to
Copy link
Contributor

Choose a reason for hiding this comment

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

checking

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is from a cherry-picked commit that is now in master

https://github.com/devitocodes/devito/blob/master/devito/types/basic.py#L1467

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.

Will have a proper look later

# For homogenity, always generate e.g. `x + i0` rather than `x - i0`
# for transpose and `x + i0` for direct
indices = indices.transpose()
weights = weights._subs(indices.free_dim, -indices.free_dim)
Copy link
Contributor

Choose a reason for hiding this comment

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

weights.transpose() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was that way, just like the indices above, but I had to change it because... I don't remember exactly

isinstance(other.access, ComponentAccess) and \
self.access.index != other.access.index:
# E.g., `uv(x).x` and `uv(x).y` -- not a real dependence!
return Vector(S.ImaginaryUnit)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use something else there. As we want to add complex support would be better to use something like Inf or NaN

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could do that, but this is several layers of abstraction below, when the imaginary parts (in a mathematical sense) will have already been completely lowered away



def sdims_max(expr):
def _minmax(expr, callback, udims=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

minmax usually used for min-of-max so would use _relational

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK!

@FabioLuporini FabioLuporini force-pushed the revamp-opt-derivs-rebased branch from ab8fd92 to e4f186b Compare September 6, 2023 12:33
@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@FabioLuporini
Copy link
Contributor Author

closing as superseded by #2208

all comments here have been taken care of in #2208

@FabioLuporini FabioLuporini deleted the revamp-opt-derivs-rebased branch October 16, 2023 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants