-
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
core: Print FloatAttr special values #3377
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3377 +/- ##
==========================================
+ Coverage 90.12% 90.13% +0.01%
==========================================
Files 452 452
Lines 57098 57134 +36
Branches 5491 5493 +2
==========================================
+ Hits 51459 51499 +40
+ Misses 4183 4180 -3
+ Partials 1456 1455 -1 ☔ 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.
We do not depend on numpy, and JAX is an optional dependency, so we can't use it for core features.
Co-authored-by: Sasha Lopoukhine <superlopuh@gmail.com>
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.
Thank you!
xdsl/printer.py
Outdated
if isinstance(attr_type, Float16Type): | ||
self.print_string( | ||
f"{hex(struct.unpack('<H', struct.pack('<e', value.data))[0])} : " | ||
) | ||
elif isinstance(attr_type, Float32Type): | ||
self.print_string( | ||
f"{hex(struct.unpack('<I', struct.pack('<f', value.data))[0])} : " | ||
) | ||
elif isinstance(attr_type, Float64Type): | ||
self.print_string( | ||
f"{hex(struct.unpack('<Q', struct.pack('<d', value.data))[0])} : " | ||
) |
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.
Now that I think about it, it feels like it would be better to use the helpers in bitwise_casts
after all, using the struct or ctypes approach. We will need the logic in a few places, such as when storing float data in assembly, and other optimisations, so it would be worth having it in an easily reusable place.
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.
Done as suggested.
I have added further |
`FloatAttr`s can have their values specified by a hexadecimal literal. This should be interpreted as the bit representation of the float. However, it is currently interpreted as an int number and then converted to a float, leading to incorrect behaviour. This PR is the second part of #3370 after #3377 --------- Co-authored-by: n-io <n-io@users.noreply.github.com>
This prints `FloatAttr` special values `nan`, `inf`, `-inf` as a hexadecimal binary representation to align with mlir-opt as described in #3370 Also see the [FloatAttr docs](https://mlir.llvm.org/docs/Dialects/Builtin/#floatattr) or give it a try on [godbolt](https://godbolt.org/z/89TfsvaKT). --------- Co-authored-by: n-io <n-io@users.noreply.github.com>
`FloatAttr`s can have their values specified by a hexadecimal literal. This should be interpreted as the bit representation of the float. However, it is currently interpreted as an int number and then converted to a float, leading to incorrect behaviour. This PR is the second part of #3370 after #3377 --------- Co-authored-by: n-io <n-io@users.noreply.github.com>
This prints `FloatAttr` special values `nan`, `inf`, `-inf` as a hexadecimal binary representation to align with mlir-opt as described in Also see the [FloatAttr docs](https://mlir.llvm.org/docs/Dialects/Builtin/#floatattr) or give it a try on [godbolt](https://godbolt.org/z/89TfsvaKT). --------- Co-authored-by: n-io <n-io@users.noreply.github.com>
This prints `FloatAttr` special values `nan`, `inf`, `-inf` as a hexadecimal binary representation to align with mlir-opt as described in xdslproject#3370 Also see the [FloatAttr docs](https://mlir.llvm.org/docs/Dialects/Builtin/#floatattr) or give it a try on [godbolt](https://godbolt.org/z/89TfsvaKT). --------- Co-authored-by: n-io <n-io@users.noreply.github.com>
…t#3378) `FloatAttr`s can have their values specified by a hexadecimal literal. This should be interpreted as the bit representation of the float. However, it is currently interpreted as an int number and then converted to a float, leading to incorrect behaviour. This PR is the second part of xdslproject#3370 after xdslproject#3377 --------- Co-authored-by: n-io <n-io@users.noreply.github.com>
This prints
FloatAttr
special valuesnan
,inf
,-inf
as a hexadecimal binary representation to align with mlir-opt as described in #3370Also see the FloatAttr docs or give it a try on godbolt.