-
Notifications
You must be signed in to change notification settings - Fork 797
[SYCL] Add half non-assign math operators #6061
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
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 for doing this fix. I have some questions though.
Also, please add a LIT test to this PR.
@rolandschulz - would you please take a look at this fix?
sycl/include/CL/sycl/half_type.hpp
Outdated
__SYCL_CONSTEXPR_HALF friend half operator op(const half &lhs, \ | ||
const half &rhs) { \ | ||
half rtn = lhs; \ | ||
rtn op1 rhs; \ |
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.
rtn op1 rhs; \ | |
rtn op_eq rhs; \ |
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
bd9353c
to
8d9106c
Compare
I have added a test to check for different output types for various inputs. |
OP(+, +=) | ||
OP(-, -=) | ||
OP(*, *=) | ||
OP(/, /=) |
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.
Can you also add support for:
OP(bool, ==)
OP(bool, !=)
OP(bool, <)
OP(bool, >)
OP(bool, <=)
OP(bool, >=)
?
Like this, we will have a more complete list similar to what we have for bfloat16 support currently.
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 have added the logical operators and expanded the test
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 for adding the missing operators
fb7f65c
aa1ccc1
to
fb7f65c
Compare
/verify with intel/llvm-test-suite#1012 |
Some llvm-test-suite tests were failing due to the half changes. I have updated the test-suite to resolve the issues. The changes relate to ambiguous namespaces with ESIMD and an increase in check tolerance now that 16-bit operations are being performed. llvm-test-suite PR: intel/llvm-test-suite#1012 |
static_assert(std::is_same_v<decltype(T1(1) + sycl::half(1)), T_rtn>); | ||
static_assert(std::is_same_v<decltype(T1(1) - sycl::half(1)), T_rtn>); | ||
static_assert(std::is_same_v<decltype(T1(1) * sycl::half(1)), T_rtn>); | ||
static_assert(std::is_same_v<decltype(T1(1) / sycl::half(1)), T_rtn>); | ||
|
||
static_assert(std::is_same_v<decltype(sycl::half(1) + T1(1)), T_rtn>); | ||
static_assert(std::is_same_v<decltype(sycl::half(1) - T1(1)), T_rtn>); | ||
static_assert(std::is_same_v<decltype(sycl::half(1) * T1(1)), T_rtn>); | ||
static_assert(std::is_same_v<decltype(sycl::half(1) / T1(1)), T_rtn>); |
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.
Can we outline that into a helper called from both host/device code to avoid duplication?
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.
Yes, that would make the code much clearer. I have updated the test.
void check_half_math_operator_types(sycl::queue Queue) { | ||
|
||
// Test on host | ||
static_assert(std::is_same_v<decltype(T1(1) + sycl::half(1)), T_rtn>); |
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.
nit: that could also be (I think)
decltype(std::declval<T1>() + std::declval<sycl::half>())
But it's probably not worth decreased signal/noise ratio to be that pedantic here.
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
static_assert(std::is_same_v<decltype(T1(1) == sycl::half(1)), bool>); | ||
static_assert(std::is_same_v<decltype(T1(1) != sycl::half(1)), bool>); | ||
static_assert(std::is_same_v<decltype(T1(1) > sycl::half(1)), bool>); | ||
static_assert(std::is_same_v<decltype(T1(1) < sycl::half(1)), bool>); | ||
static_assert(std::is_same_v<decltype(T1(1) <= sycl::half(1)), bool>); | ||
static_assert(std::is_same_v<decltype(T1(1) <= sycl::half(1)), bool>); | ||
|
||
static_assert(std::is_same_v<decltype(sycl::half(1) == T1(1)), bool>); | ||
static_assert(std::is_same_v<decltype(sycl::half(1) != T1(1)), bool>); | ||
static_assert(std::is_same_v<decltype(sycl::half(1) > T1(1)), bool>); | ||
static_assert(std::is_same_v<decltype(sycl::half(1) < T1(1)), bool>); | ||
static_assert(std::is_same_v<decltype(sycl::half(1) <= T1(1)), bool>); | ||
static_assert(std::is_same_v<decltype(sycl::half(1) <= T1(1)), bool>); |
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.
Likewise about helper routine.
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.
Updated same as above.
} | ||
|
||
template <typename T1> | ||
void check_half_logical_operator_types(sycl::queue Queue) { |
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 very surprised copy-ctor isn't deleted... Regardless of what the standard says, can we turn this into a reference?
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.
Yes that makes sense, I have adjusted this to be pass by reference.
/verify with intel/llvm-test-suite#1012 |
@pvchupin would it be possible to find out what is failing in the llvm-test-suite when run with the intel/llvm-test-suite#1012 changes? Thank you. |
It actually didn't run and failed earlier due to some infrastructure issue. Tagging @tfzhu. |
@AidanBeltonS, I'm restarting it now. |
@AidanBeltonS, restart passed, I'll merge both this and test changes. |
This PR makes some small changes due to the introduction of some missing operators. It changes the namespaces in ext_math.cpp as it was ambiguous as to if the sycl::abs() or sycl::ext::intel::esimd::abs() function should be used. There is also an adjustment of the load store's check tolerance. The checks tolerance is slightly increased, as previously these operations would have been performed as 32-bit floats. Depends on: intel/llvm#6061
@AidanBeltonS , could you please check the following post commit error in Windows Build? Thanks.
|
I think real issue is this one:
|
Thanks for correction, I did not notice "Error C2719" exist before this commit. |
This PR adds a static cast to builtins_relational functions which apply a negative operation to a boolean type. This is only applied to functions which are specialised for cl_half. The cast prevents windows error message C4804. This resolves a windows build issue introduced by #6061
@AidanBeltonS, it seems there was some collision of this change with recent pulldown. Can you please take a look at the latest post-commit issue? |
This PR makes some small changes due to the introduction of some missing operators. It changes the namespaces in ext_math.cpp as it was ambiguous as to if the sycl::abs() or sycl::ext::intel::esimd::abs() function should be used. There is also an adjustment of the load store's check tolerance. The checks tolerance is slightly increased, as previously these operations would have been performed as 32-bit floats. Depends on: intel#6061
This PR adds missing half operations +-*/.
There are existing operations for the legacy class host_half_impl, however these were not extended to the half class. These operations were being performed as floating point operations via the implicit floating conversion. This results in the output being a float not half type.
The template is limited to arithmetic types to prevent ambiguous templating.
A minor change to built-in
__fract
is needed to ensure fmin is not ambiguous.llvm-test-suite PR: intel/llvm-test-suite#1012
Fixes: #6028