-
Notifications
You must be signed in to change notification settings - Fork 229
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: Yet another batch of compilation tweaks #2396
Conversation
This is necessary to ensure reconstruction works as expected
except AttributeError: | ||
# E.g., `self=R<f,[cy]>` and `self.itintervals=(y,)` => `sai=None` | ||
pass | ||
|
||
# In some cases, the distance degenerates because `self` and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: aside from the "Case 3", the rest is just lifted from approximately 40 lines below
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2396 +/- ##
==========================================
+ Coverage 86.70% 86.72% +0.01%
==========================================
Files 234 235 +1
Lines 44424 44521 +97
Branches 8219 8242 +23
==========================================
+ Hits 38518 38611 +93
- Misses 5185 5189 +4
Partials 721 721 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly cleanup, look goog.
Few minorcomments
@@ -2,6 +2,7 @@ | |||
from functools import cached_property | |||
|
|||
from sympy import S | |||
import sympy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jusit import Interval above no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would, but to make a neat distinction with our own Interval...
tests/test_linearize.py
Outdated
@@ -611,4 +611,4 @@ def test_different_dtype(): | |||
|
|||
# Check generated code has different strides for different dtypes | |||
assert "bL0(x,y) b[(x)*y_stride0 + (y)]" in str(op1) | |||
assert "L0(x,y) f[(x)*y_stride1 + (y)]" in str(op1) | |||
assert "L0(x,y) f[(x)*y_stride0 + (y)]" in str(op1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we parametrize this test with autopadding so y_stride1
case is there for "mixed" padding
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's not possible by construction anymore; autopadding is now a global choice, in essence. This means that if you have an fp32 and an fp64 the data will be padded to either fp32 or fp64; in the former case, the performance will be suboptimal. But regardless, we will always only generate one stride per dimension. See types/basic.py::AbstractFunction::__padding_dtype__
logic
That said, I've now parametrized the test as you suggested, but the expected outcome is always y_stride0
b55adb2
to
afe0719
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not have something more to add.
@@ -480,7 +480,7 @@ def visit_Expression(self, o): | |||
code = c.Assign(lhs, rhs) | |||
|
|||
if o.pragmas: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These four lines are repeated twice. Worth constructing a utility function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which four lines? I only see two, starting at if o.pragmas
-- which is too little to deserve a separate function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if o.pragmas:
code = c.Module(self._visit(o.pragmas) + (code,))
return code
but tbh, you're probably right
|
||
if d.is_Custom: | ||
subs = {} | ||
elif d.is_Sub and d.is_left: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can middle/right subdimensions be ignored? Genuinely curious
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we just don't treat them as we don't -- practically speaking need to
as per the docstring:
"A rudimentary test ..."
and
"Our implementation focuses on tiny yet relevant cases"
so basically this is a simplistic implementation, to be refined in the future if we ever will have to
m = it.symbolic_min.subs(subs) | ||
M = it.symbolic_max.subs(subs) | ||
|
||
p00 = e0._subs(d, m) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Explanatory comment of the 00, 01, etc would be helpful here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just dummy variable names because you have two "dimensions":
- e0 and e1
- m and M
which leads to four objects
# Some objects may contain an extremely large number of elements, so we | ||
# conservatively use int64 to avoid potential overflows regardless of | ||
# what the user requested via `index-mode` | ||
if f.is_SparseTimeFunction: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just SparseFunction
I would say, given that the issue occurs due to a large number of points, rather than a large nt iirc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
order of millions is fine, order of billions (due to time...) isn't
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, but those are different array dimensions right? Unless the array is linearised?
devito/symbolics/manipulation.py
Outdated
@@ -286,12 +286,12 @@ def pow_to_mul(expr): | |||
except TypeError: | |||
# E.g., a Symbol, or possibly a generic expression | |||
return expr | |||
if exp > 10 or exp < -10 or int(exp) != exp or exp == 0: | |||
if exp > 10 or exp < -10 or exp == 0: | |||
# Large and non-integer powers remain untouched |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"non-integer" part of this comment needs moving to the elif
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch, fixing
devito/types/basic.py
Outdated
padding = [(0, 0)]*self.ndim | ||
padding[self.dimensions.index(d)] = dpadding | ||
# The padded Dimension | ||
candidates = self.space_dimensions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could shorten to:
if not self.space_dimensions:
return nopadding
d = self.space_dimensions[-1]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, fixing
@@ -210,6 +210,21 @@ def test_modulo_dims_generation_v2(self): | |||
assert np.all(f.data[3] == 2) | |||
assert np.all(f.data[4] == 4) | |||
|
|||
def test_degenerate_to_zero(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docstring or a comment explaining what this does would help understanding at a glance
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adding docstring
These are mostly to improve code generation and performance of elastic-like PDEs.