-
Notifications
You must be signed in to change notification settings - Fork 769
[SYCL][bfloat16] Simplify bfloat16 class #17258
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
Conversation
This change makes a few changes aiming to make the code more readable. * Move declaration of the bfloat16 class right on top of the header file and move all declarations with the implementation helpers after the class declaration. * Converted ConvertToBfloat16 class to namespace. The class doesn't represent any object, it's a collection of static methods. * Declare public API of the class first. * Define bfloat16 class as final. * Move Bfloat16StorageT declaration from the detail namespace directly into bfloat16 class definition. * Co-locate declaration of functions with similar functionality (e.g. conversion functions). * Simplified uniry operator- implementation by removing additional branch for the SPIR target. Generic code for SPIR target produces exactly the same code. * Added compile time checks for the array size inside conversion helper functions. Device side implementation of these functions work correctly only for certain array sizes. * Include C++ header instead of C (i.e. cstdint instead of stdint.h). * Applied "no-else-after-return" and "no-braces-for-single-statement-if" coding style changes.
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.
Nice.
When I saw the title I was hoping that it would also give blfloat16 a constexpr contstructor and operator==, but still a bridge too far.
That's good feedback. I suggest we apply a "rule of zero" to this class to make constructor constexpr. Regarding operator==. I'll try to make all binary operators constexpr. |
Okay, I think I understand why both these ideas haven't been implemented yet.
Let's leave I suppose we significantly simplify the implementation by switching to from |
This change makes a few changes aiming to make the code more readable.
Move declaration of the bfloat16 class right on top of the header file
and move all declarations with the implementation helpers after the
class declaration.
Converted ConvertToBfloat16 class to namespace. The class doesn't
represent any object, it's a collection of static methods.
Declare public API of the class first.
Move Bfloat16StorageT declaration from the detail namespace directly
into bfloat16 class definition.
Co-locate declaration of functions with similar functionality (e.g.
conversion functions).
Simplified uniry operator- implementation by removing additional
branch for the SPIR target. Generic code for SPIR target produces
exactly the same code.
Added compile time checks for the array size inside conversion helper
functions. Device side implementation of these functions work
correctly only for certain array sizes.
Include C++ header instead of C (i.e. cstdint instead of stdint.h).
Applied "no-else-after-return" and "no-braces-for-single-statement-if"
coding style changes.