-
Notifications
You must be signed in to change notification settings - Fork 83
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
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.
Could the title be updated to reflect that this is more than just a printing change?
xdsl/dialects/builtin.py
Outdated
@@ -782,6 +782,27 @@ def unpack( | |||
|
|||
|
|||
BoolAttr: TypeAlias = IntegerAttr[Annotated[IntegerType, IntegerType(1)]] | |||
TRUE_ATTR = BoolAttr(True, i1) |
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 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.
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 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) |
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.
false = BoolAttr(False, i1) | |
false = BoolAttr.from_bool(False) |
xdsl/printer.py
Outdated
(`[x]`). | ||
""" | ||
dim, scalable = pair | ||
if scalable.value: |
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.
if scalable.value: | |
if scalable: |
Should work right?
xdsl/dialects/builtin.py
Outdated
|
||
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) |
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.
return -sum(d.value.data for d in self.scalable_dims) | |
return sum(bool(d) for d in self.scalable_dims) |
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 this is much better
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.
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>} {} |
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 prefer to test with "test.op"() <{ test = ATTR }> : () -> ()
Fixes #3654