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: Yet another batch of compilation tweaks #2396

Merged
merged 18 commits into from
Jul 8, 2024
Merged

Conversation

FabioLuporini
Copy link
Contributor

These are mostly to improve code generation and performance of elastic-like PDEs.

except AttributeError:
# E.g., `self=R<f,[cy]>` and `self.itintervals=(y,)` => `sai=None`
pass

# In some cases, the distance degenerates because `self` 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.

Note: aside from the "Case 3", the rest is just lifted from approximately 40 lines below

Copy link

codecov bot commented Jul 2, 2024

Codecov Report

Attention: Patch coverage is 74.08638% with 78 lines in your changes missing coverage. Please review.

Project coverage is 86.72%. Comparing base (f67e7af) to head (2d0f60a).

Files Patch % Lines
tests/test_gpu_openmp.py 0.00% 22 Missing ⚠️
tests/test_gpu_openacc.py 0.00% 14 Missing ⚠️
devito/passes/iet/engine.py 57.89% 7 Missing and 1 partial ⚠️
devito/types/basic.py 72.00% 4 Missing and 3 partials ⚠️
devito/passes/iet/languages/openacc.py 14.28% 6 Missing ⚠️
devito/ir/support/basic.py 86.48% 2 Missing and 3 partials ⚠️
tests/test_dle.py 86.48% 4 Missing and 1 partial ⚠️
devito/passes/iet/parpragma.py 76.47% 4 Missing ⚠️
devito/core/gpu.py 0.00% 2 Missing ⚠️
devito/ir/iet/visitors.py 83.33% 1 Missing ⚠️
... and 4 more
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.
📢 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.

Mostly cleanup, look goog.

Few minorcomments

@@ -2,6 +2,7 @@
from functools import cached_property

from sympy import S
import sympy
Copy link
Contributor

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?

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 would, but to make a neat distinction with our own Interval...

devito/passes/iet/languages/utils.py Show resolved Hide resolved
@@ -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)
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 parametrize this test with autopadding so y_stride1 case is there for "mixed" padding

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 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

@FabioLuporini FabioLuporini force-pushed the moar-elastic-tweaks branch from b55adb2 to afe0719 Compare July 3, 2024 09:06
Copy link
Contributor

@georgebisbas georgebisbas left a 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.

devito/ir/support/basic.py Show resolved Hide resolved
devito/core/gpu.py Show resolved Hide resolved
devito/ir/clusters/algorithms.py Show resolved Hide resolved
@@ -480,7 +480,7 @@ def visit_Expression(self, o):
code = c.Assign(lhs, rhs)

if o.pragmas:
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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:
Copy link
Contributor

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

Copy link
Contributor Author

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)
Copy link
Contributor

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

Copy link
Contributor Author

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:
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

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?

@@ -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
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch, fixing

padding = [(0, 0)]*self.ndim
padding[self.dimensions.index(d)] = dpadding
# The padded Dimension
candidates = self.space_dimensions
Copy link
Contributor

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]

Copy link
Contributor Author

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):
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

adding docstring

devito/__init__.py Outdated Show resolved Hide resolved
@mloubout mloubout merged commit 156db8e into master Jul 8, 2024
30 of 31 checks passed
@mloubout mloubout deleted the moar-elastic-tweaks branch July 8, 2024 13:07
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.

4 participants