-
Notifications
You must be signed in to change notification settings - Fork 199
Add operators for +,-,*,/ for half
with other scalar types
#969
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
Can you comment more on the use case? What is the code you attempt to make work? |
Things like
currently do not compile because the multiplication is ambiguous (the compiler could first create a |
dc42e2a
to
4087bcc
Compare
The SYCL WG agreed that |
return fp16::builtin_add(a._data, b._data), | ||
return fp16::builtin_add(a._data, b._data)) | ||
data = fp16::builtin_add(a._data, b._data), | ||
data = fp16::builtin_add(a._data, b._data)); |
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.
Couldn't you simplify this along the lines of:
return detail::create_half(__hipsycl_backend_switch(
fp16::builtin_add(a._data, b._data),
....
));
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.
Unfortunately not, because __hipsycl_backend_switch
adds semicolons to its arguments, so this becomes something like
return detail::create_half(fp16::builtin_add(a._data, b._data););
which does not compile (this could of course be fixed by removing the semicolons in the definition of __hipsycl_backend_switch
and adding them in the places where the macro is used). However, for the sscp backend, __hipsycl_backend_switch
becomes an if statement, which again doesn't compile, and we can't just change that to a ternary operator because sometimes __hipsycl_backend_switch
is used with return statements as its arguments and these are not allowed as expressions in the ternary operator.
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.
Ugh... even if SSCP might in principle work with ternary operator, it probably won't work with nvc++, where we need if target()
branching.. So you are totally right :(
Can you resolve merge conflicts? |
This also required removing the `explicit` keyword for the constructors and adding three new constructors for `unsigned int`, `unsigned long` and `long`.
We can rely on implicit conversion here, because according to https://en.cppreference.com/w/cpp/language/static_cast, the static cast performs the same conversion as an implicit conversion (and implicit conversions from {integral types, double} -> float are valid according to https://en.cppreference.com/w/cpp/language/implicit_conversion)
Since we removed the half(fp16::half_storage) constructors, we must explicitly construct the half that is returned. Unfortunately, the macro `__hipsycl_backend_switch` contains an if statement for the host pass in the generic backend, so we cannot just write `auto data = __hipsycl_backend_switch(...)`.
2c17376
to
585e08c
Compare
This also required removing the
explicit
keyword for the constructors and adding three new constructors forunsigned int
,unsigned long
andlong
.