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

transform: (stencil-tensorize-z-dimension) Tensorize arith.constant directly #2970

Merged
merged 8 commits into from
Aug 2, 2024

Conversation

n-io
Copy link
Collaborator

@n-io n-io commented Jul 31, 2024

Add support for directly tensorising arith.constant, e.g.

%0 = arith.constant dense<1.666600e-01> : tensor<510xf32>

The more generic way of tensorising any scalar operand (independent of its source) would be linalg.filling the value a newly created empty tensor. This still works as a generic way. However, in the special case that the scalar operand is a constant, this is much shorter.

@n-io n-io added minor For minor PRs, easy and quick to review, quickly mergeable transformations Changes or adds a transformatio labels Jul 31, 2024
@n-io n-io requested review from AntonLydike, PapyChacal and dk949 July 31, 2024 13:27
@n-io n-io self-assigned this Jul 31, 2024
Copy link

codecov bot commented Jul 31, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.84%. Comparing base (09e3157) to head (781293e).
Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2970      +/-   ##
==========================================
- Coverage   89.86%   89.84%   -0.02%     
==========================================
  Files         409      409              
  Lines       51085    51167      +82     
  Branches     7923     7938      +15     
==========================================
+ Hits        45908    45972      +64     
- Misses       3925     3932       +7     
- Partials     1252     1263      +11     

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

xdsl/dialects/arith.py Outdated Show resolved Hide resolved
@n-io
Copy link
Collaborator Author

n-io commented Aug 1, 2024

This PR depends on #2969, re-run test when this is merged.

@n-io n-io requested a review from superlopuh August 1, 2024 19:33
@n-io n-io requested a review from superlopuh August 2, 2024 08:51
Copy link
Member

@superlopuh superlopuh left a comment

Choose a reason for hiding this comment

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

Code changes look good, but I'm not sure about the pass in general, and the test file. It seems like there's quite a lot of inspection and rewriting of operands, when the usual approach is to match directly on the uses. This matters a bit for composability of rewrites, and rewriting some of this tensorization as transformations on the uses would make it easier to read and to test. For example, the linalg.fill where the operand is a constant could be replaced with a new arith.constant of a tensor, leaving the original constant in place (and letting it be dce-ed away in a later stage in the pipeline). Similarly for the arith operations.

@n-io
Copy link
Collaborator Author

n-io commented Aug 2, 2024

Code changes look good, but I'm not sure about the pass in general, and the test file. It seems like there's quite a lot of inspection and rewriting of operands, when the usual approach is to match directly on the uses. This matters a bit for composability of rewrites, and rewriting some of this tensorization as transformations on the uses would make it easier to read and to test. For example, the linalg.fill where the operand is a constant could be replaced with a new arith.constant of a tensor, leaving the original constant in place (and letting it be dce-ed away in a later stage in the pipeline). Similarly for the arith operations.

Thanks, done as discussed :)

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.

Nice!

@n-io n-io merged commit 1fd1d39 into main Aug 2, 2024
9 checks passed
@n-io n-io deleted the nicolai/use-arith-tensor-consts branch August 2, 2024 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor For minor PRs, easy and quick to review, quickly mergeable transformations Changes or adds a transformatio
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants