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

bug: (csl-lowering) Make multi-apply lowering work #3614

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

n-io
Copy link
Collaborator

@n-io n-io commented Dec 10, 2024

This PR includes a few small fixes, described below.

@n-io n-io added bug Something isn't working minor For minor PRs, easy and quick to review, quickly mergeable labels Dec 10, 2024
@n-io n-io self-assigned this Dec 10, 2024
Copy link

codecov bot commented Dec 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.47%. Comparing base (e13d337) to head (43a1709).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3614   +/-   ##
=======================================
  Coverage   90.47%   90.47%           
=======================================
  Files         472      472           
  Lines       59284    59289    +5     
  Branches     5638     5639    +1     
=======================================
+ Hits        53639    53644    +5     
  Misses       4206     4206           
  Partials     1439     1439           

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

@n-io n-io requested review from dk949 and emmau678 December 10, 2024 13:15
@@ -385,6 +388,9 @@ def match_and_rewrite(self, op: arith.ConstantOp, rewriter: PatternRewriter, /):
class InjectApplyOutsIntoLinalgOuts(RewritePattern):
@op_type_rewrite_pattern
def match_and_rewrite(self, op: csl_stencil.ApplyOp, rewriter: PatternRewriter, /):
if not op.dest:
return

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Adding support for zero output apply ops.

@@ -94,6 +94,9 @@ def match_and_rewrite(self, op: csl_stencil.ApplyOp, rewriter: PatternRewriter,
# convert args
buf_args: list[SSAValue] = []
to_memrefs: list[Operation] = [buf_iter_arg := to_memref_op(op.accumulator)]
op.accumulator.replace_by_if(
buf_iter_arg.memref, lambda use: use.operation != buf_iter_arg
)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Allowing the bufferization.to_memref (buf_iter_arg) to be used by further apply ops, in case there is more than one.

)
assert isa(ac_op.result.type, AnyTensorType)
dest = tensor.InsertSliceOp.get(
source=ac_op.result,
dest=dest,
static_sizes=ac_op.result.type.get_shape(),
static_sizes=[1, *ac_op.result.type.get_shape()],
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This needs 1 in the 1st dimension to insert 1 slice of z-values (ac_op.result.type.get_shape() are the shape of the z-values)

dest = acc
for i, acc_offset in enumerate(offsets):
ac_op = csl_stencil.AccessOp(
dest, stencil.IndexAttr.get(*acc_offset), chunk_t
buf, stencil.IndexAttr.get(*acc_offset), chunk_t
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Read from the buf, not from the dest (which is the accumulator).

return TensorType(
use.operation.result.type.get_element_type(),
static_sizes,
static_sizes[dimdiff:],
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Small fix for inserting a 1d slice into a 2d tensor.

@n-io n-io marked this pull request as ready for review December 10, 2024 15:41
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.

Your comments on this PR seem like they would also be beneficial in the code :)

@n-io
Copy link
Collaborator Author

n-io commented Dec 10, 2024

Your comments on this PR seem like they would also be beneficial in the code :)

That does actually make sense in most cases, thanks.

@n-io n-io requested a review from superlopuh December 10, 2024 16:11
@n-io n-io marked this pull request as draft December 10, 2024 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working minor For minor PRs, easy and quick to review, quickly mergeable
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants