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

dialects: (builtin) fix VectorType scalable dimension representation #3947

Merged
merged 7 commits into from
Feb 24, 2025

Conversation

superlopuh
Copy link
Member

Fixes #3654

Copy link

codecov bot commented Feb 22, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.31%. Comparing base (2d09184) to head (823ff54).
Report is 14 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3947   +/-   ##
=======================================
  Coverage   91.30%   91.31%           
=======================================
  Files         467      468    +1     
  Lines       58068    58141   +73     
  Branches     5581     5580    -1     
=======================================
+ Hits        53021    53091   +70     
- Misses       3616     3623    +7     
+ Partials     1431     1427    -4     

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

Copy link
Collaborator

@alexarice alexarice left a comment

Choose a reason for hiding this comment

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

Could the title be updated to reflect that this is more than just a printing change?

@@ -782,6 +782,27 @@ def unpack(


BoolAttr: TypeAlias = IntegerAttr[Annotated[IntegerType, IntegerType(1)]]
TRUE_ATTR = BoolAttr(True, i1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am in general against the addition of more helper methods that do the same things in questionably more ergonomic syntax. There is already BoolAttr.from_bool() and I feel we should only keep one or the other.

Copy link
Member Author

Choose a reason for hiding this comment

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

I had a feeling we had such a helper but forgot where it was.

num_scalable_dims = IntAttr(num_scalable_dims)
super().__init__([shape, element_type, num_scalable_dims])
if scalable_dims is None:
false = BoolAttr(False, i1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
false = BoolAttr(False, i1)
false = BoolAttr.from_bool(False)

xdsl/printer.py Outdated
(`[x]`).
"""
dim, scalable = pair
if scalable.value:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if scalable.value:
if scalable:

Should work right?


def get_num_dims(self) -> int:
return len(self.shape.data)

def get_num_scalable_dims(self) -> int:
return self.num_scalable_dims.data
# Data for BoolAttr True is -1
return -sum(d.value.data for d in self.scalable_dims)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return -sum(d.value.data for d in self.scalable_dims)
return sum(bool(d) for d in self.scalable_dims)

Copy link
Collaborator

Choose a reason for hiding this comment

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

oh this is much better

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return -sum(d.value.data for d in self.scalable_dims)
return sum(1 for d in self.scalable_dims if d)

Alternative

// RUN: xdsl-opt --print-op-generic %s | mlir-opt --mlir-print-op-generic | xdsl-opt --print-op-generic | filecheck %s

// CHECK: vector<1xindex>
builtin.module attributes {v.v1 = vector<1xindex>} {}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd prefer to test with "test.op"() <{ test = ATTR }> : () -> ()

@superlopuh superlopuh changed the title dialects: (builtin) fix VectorType scalable dimension printing dialects: (builtin) fix VectorType scalable dimension representation Feb 24, 2025
@superlopuh superlopuh merged commit 63b7198 into main Feb 24, 2025
16 checks passed
@superlopuh superlopuh deleted the sasha/vector/scalable-dims branch February 24, 2025 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dialects Changes on the dialects
Projects
None yet
3 participants