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

(dialect+transform): stencil to new csl_stencil dialect and transform #2766

Merged
merged 26 commits into from
Jun 24, 2024

Conversation

n-io
Copy link
Collaborator

@n-io n-io commented Jun 21, 2024

Introduces an intermediate dialect with ops:

  • csl_stencil.prefetch to indicate prefetched buffer transfers
  • csl_stencil.access performs a stencil.access to a prefetched buffer

The stencil-to-csl-stencil transform:

  • lowers dmp.swap to csl_stencil.prefetch
  • adds prefetched buffers to signature of stencil.apply
  • lowers stencil.access to csl_stencil.access iff they are accesses to prefetched buffers

For a more detailed description see the document in #2747. This PR implements Step 1 outlined there.

@n-io n-io self-assigned this Jun 21, 2024
@n-io n-io added dialects Changes on the dialects transformations Changes or adds a transformatio labels Jun 21, 2024
n-io and others added 2 commits June 21, 2024 19:11
Copy link

codecov bot commented Jun 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.79%. Comparing base (0f6558a) to head (93f2e05).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2766      +/-   ##
==========================================
- Coverage   89.81%   89.79%   -0.03%     
==========================================
  Files         372      375       +3     
  Lines       47817    48012     +195     
  Branches     7331     7362      +31     
==========================================
+ Hits        42945    43110     +165     
- Misses       3736     3752      +16     
- Partials     1136     1150      +14     

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

@n-io
Copy link
Collaborator Author

n-io commented Jun 24, 2024

I'd welcome suggestions on file structure/layout.

As for the dialect, riscv takes the approach of having several riscv_*.py files in xdsl/dialects, while x86 has its own subdir. A subdir named csl would clash with the current csl.py, so I wanted to get feedback on how to structure that and where to place the intermediate dialect file (to be clear, the current csl_ dir name is not supposed to be committed, only for the purposes of reviewing). Alternatively, it can go into experimental.

As for the transform, it is currently placed in transform/experimental. Alternatively, it can also be moved to transform or to backend/csl/lowering. I'd tend towards the latter, while wondering if it has any impact on where to place the dialect.

Copy link
Collaborator

@PapyChacal PapyChacal left a comment

Choose a reason for hiding this comment

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

Minor comment but LGTM generally!

On the file layout situation, I would be in favor of a csl directory containing a nested dialect file. Nothing enforces it to be directly in xdsl/dialects.
If you're concerned about the module path, i.e from xdsl.dialects.csl.csl import CSL, you could, in xdsl/dialects/csl/__init__.py import the dialect to expose it from there, enabling from xdsl.dialects.csl import CSL event if it is nested.
Note: I would personally not like xdsl/dialects/csl/__init__.py to contain the dialect definition itself though.
All of this being in answer to your mention of the topic; I wouldn't be against merging for any file layout point myself!

xdsl/transforms/experimental/stencil_to_csl_stencil.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@AntonLydike AntonLydike left a comment

Choose a reason for hiding this comment

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

I think I have conceptual questions on both the csl_stencil dialect and the rewrite, maybe it makes sense to split the two off?

Also, this PR is severely lacking comments and docstrings. A lot of things are difficult to review for me, as I have to reconstruct what the method/op/rewrite/pass does from the code. This makes the review error prone as well, as I am never sure if you intended something or if it's a bug...

xdsl/dialects/csl_/csl_stencil.py Outdated Show resolved Hide resolved
xdsl/dialects/csl_/csl_stencil.py Outdated Show resolved Hide resolved
xdsl/dialects/csl_/csl_stencil.py Outdated Show resolved Hide resolved
xdsl/dialects/csl_/csl_stencil.py Outdated Show resolved Hide resolved
xdsl/dialects/csl_/csl_stencil.py Outdated Show resolved Hide resolved
xdsl/transforms/experimental/stencil_to_csl_stencil.py Outdated Show resolved Hide resolved
xdsl/transforms/experimental/stencil_to_csl_stencil.py Outdated Show resolved Hide resolved
xdsl/dialects/csl_/csl_stencil.py Outdated Show resolved Hide resolved
xdsl/transforms/experimental/stencil_to_csl_stencil.py Outdated Show resolved Hide resolved
xdsl/dialects/csl_/csl_stencil.py Outdated Show resolved Hide resolved
@n-io
Copy link
Collaborator Author

n-io commented Jun 24, 2024

Minor comment but LGTM generally!

On the file layout situation, I would be in favor of a csl directory containing a nested dialect file. Nothing enforces it to be directly in xdsl/dialects. If you're concerned about the module path, i.e from xdsl.dialects.csl.csl import CSL, you could, in xdsl/dialects/csl/__init__.py import the dialect to expose it from there, enabling from xdsl.dialects.csl import CSL event if it is nested. Note: I would personally not like xdsl/dialects/csl/__init__.py to contain the dialect definition itself though. All of this being in answer to your mention of the topic; I wouldn't be against merging for any file layout point myself!

@PapyChacal I believe having an __init__.py with something like

from .csl import *

__all__ = ["csl"]

will unfortunately result in an F405 error. Not entirely sure how to go about it.

@PapyChacal
Copy link
Collaborator

Minor comment but LGTM generally!
On the file layout situation, I would be in favor of a csl directory containing a nested dialect file. Nothing enforces it to be directly in xdsl/dialects. If you're concerned about the module path, i.e from xdsl.dialects.csl.csl import CSL, you could, in xdsl/dialects/csl/__init__.py import the dialect to expose it from there, enabling from xdsl.dialects.csl import CSL event if it is nested. Note: I would personally not like xdsl/dialects/csl/__init__.py to contain the dialect definition itself though. All of this being in answer to your mention of the topic; I wouldn't be against merging for any file layout point myself!

@PapyChacal I believe having an __init__.py with something like

from .csl import *

__all__ = ["csl"]

will unfortunately result in an F405 error. Not entirely sure how to go about it.

We do this in a few places already, you could just add # noqa: TID251 on that line

Or list explicitly what you want to expose

@AntonLydike
Copy link
Collaborator

AntonLydike commented Jun 24, 2024 via email

@n-io n-io requested a review from AntonLydike June 24, 2024 13:27
xdsl/transforms/stencil_to_csl_stencil.py Outdated Show resolved Hide resolved
xdsl/dialects/csl_/csl_stencil.py Outdated Show resolved Hide resolved
xdsl/dialects/csl/csl_stencil.py Outdated Show resolved Hide resolved
xdsl/dialects/csl/csl_stencil.py Outdated Show resolved Hide resolved
xdsl/transforms/experimental/stencil_to_csl_stencil.py Outdated Show resolved Hide resolved
xdsl/transforms/stencil_to_csl_stencil.py Outdated Show resolved Hide resolved
xdsl/transforms/stencil_to_csl_stencil.py Outdated Show resolved Hide resolved
xdsl/transforms/stencil_to_csl_stencil.py Show resolved Hide resolved
Copy link
Collaborator

@AntonLydike AntonLydike left a comment

Choose a reason for hiding this comment

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

Added more code-level comments to the rewrite itself

xdsl/transforms/stencil_to_csl_stencil.py Outdated Show resolved Hide resolved
xdsl/transforms/stencil_to_csl_stencil.py Outdated Show resolved Hide resolved
xdsl/transforms/stencil_to_csl_stencil.py Outdated Show resolved Hide resolved
xdsl/transforms/stencil_to_csl_stencil.py Outdated Show resolved Hide resolved
xdsl/transforms/stencil_to_csl_stencil.py Outdated Show resolved Hide resolved
xdsl/transforms/stencil_to_csl_stencil.py Show resolved Hide resolved
Copy link
Collaborator

@AntonLydike AntonLydike left a comment

Choose a reason for hiding this comment

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

🚀

@n-io n-io merged commit bb51086 into main Jun 24, 2024
10 checks passed
@n-io n-io deleted the nicolai/csl-stencil-initial-op-and-transform branch June 24, 2024 16:37
n-io added a commit that referenced this pull request Jun 26, 2024
Follow-up from #2766

The original plan was to lower `stencil.access` to `csl_stencil.access`
if and only if the access is to neighbour data (i.e. prefetched), while
accesses to own data were supposed to remain `stencil.access` without
being lowered.

This runs into the very practical problem, that `stencil.access` can
only exist within a `stencil.apply` op - which we also want to lower,
but this cannot be done with `stencil.access` ops.

---------

Co-authored-by: n-io <n-io@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dialects Changes on the dialects transformations Changes or adds a transformatio
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants