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
dialects: (stencil) Add access pattern analysis #1409
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #1409 +/- ##
==========================================
- Coverage 90.03% 90.00% -0.04%
==========================================
Files 211 211
Lines 26265 26346 +81
Branches 3902 3924 +22
==========================================
+ Hits 23648 23713 +65
- Misses 2004 2014 +10
- Partials 613 619 +6
☔ View full report in Codecov by Sentry. |
@@ -631,3 +632,31 @@ def test_buffer(): | |||
assert isinstance(buffer, BufferOp) | |||
assert buffer.temp == temp | |||
assert buffer.res.type == res_type | |||
|
|||
|
|||
def test_access_patterns(): |
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.
Nice
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.
Nice! Only minor nitpicks, nothing to block for if using it is urgent 🙂
xdsl/dialects/stencil.py
Outdated
for ax in self.accesses: | ||
for axis in range(n): | ||
lefts[axis] = min(ax[axis], lefts[axis]) | ||
rights[axis] = max(ax[axis], rights[axis]) |
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.
This could reuse extent_in_axis
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 know :( but then it would be O(n^2)
instead of O(n)
...
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 don't see it?
If you swap the loops, the inner one is exactly extent_in_axis, and the total operations are the same, or am I missing something?
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.
Oh, because one of those is element-wise max?
I would prefer readability before this complexity becomes a problem, I'm not sure we'll ever have asymptotically big numbers of accesses.
But it's nitpicking 🙂
xdsl/dialects/stencil.py
Outdated
def halos(self) -> tuple[tuple[int, int], ...]: | ||
n = self.dims | ||
lefts, rights = [0] * n, [0] * n | ||
for ax in self.accesses: | ||
for axis in range(n): | ||
lefts[axis] = min(ax[axis], lefts[axis]) | ||
rights[axis] = max(ax[axis], rights[axis]) | ||
return tuple(zip(lefts, rights)) |
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'd say this one could use a docstring
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.
Oh definitely^^
This adds
.get_accesses()
to the stencil apply operation, which returns anAccessPattern
for each stencil field.Each access pattern contains a list of accesses, and offers some helpers like
is_diagonal
,get_diagonals
, etc.