-
Notifications
You must be signed in to change notification settings - Fork 788
[SYCL] Added the support for std::numeric_limits<cl::sycl::half> #536
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.
Just a couple of questions.
@keryell, @ilyastepykin, could you revisit, please? |
@tianshilei1992, we recently enforced new policy "no new warnings" by treating warnings as errors and this patch introduces new warnings on Windows. D:\buildbot\Product_worker_intel\sycl-win-x64-pr\llvm.src\sycl\include\CL/sycl/half_type.hpp(208): error C2220: warning treated as error - no 'object' file generated Could you fix these warnings, please? |
@bader Will do. |
@tianshilei1992 |
Implemented the partial specilization of the template class `std::numeric_limits<HALF_TYPE>` where HALF_TYPE is `_Float16` on device side and `cl::sycl::detail::half_impl::half` on host side. Also defined some marcros corresponding to its FP32 counterpart like `HLF_MIN`, `HLF_MAX`, etc. Signed-off-by: Shilei Tian <[email protected]>
@alexeyvoronov Sorry I didn't get your point. Do you mean in the test case? |
Why? I've opened an issue on the SYCL specification document: KhronosGroup/SYCL-Docs#40. According to the first comment, we shouldn't use |
By SYCL specification half is fundamental builtin type and available inside global namespace. But in the specification cl::sycl::half does not exist. |
I didn't say add a global space specifier, just |
What's the difference? |
|
@alexeyvoronov The |
I suggest @alexeyvoronov to make the change he proposed in a separate patch, as it's not related to goal of this change. |
static CONSTEXPR_QUALIFIER half round_error() noexcept { return 0.5F; } | ||
|
||
static CONSTEXPR_QUALIFIER half infinity() noexcept { | ||
return __builtin_huge_valf(); |
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.
Does MSVC compiler have __builtin_huge_valf?
Can we use std::numeric_limitscl::sycl::half::infinity() in SYCL lib? For Microsoft Windows we compile SYCL via MSVC compiler.
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.
Isn't std::numeric_limits<cl::sycl::half>::infinity()
what we're implementing 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.
Hm, I have an idea for an experiment.
There is a code with W/A for half type in source\detail\builtins_math.cpp.
Can you try fix it?
s::cl_half nan(s::cl_ushort nancode) __NOEXC {
return s::cl_half(d::quiet_NaN<s::cl_float>());
}
to
s::cl_half nan(s::cl_ushort nancode) __NOEXC {
return d::quiet_NaN<s::cl_half>(); // or td::numeric_limits<s::cl_half>::quiet_NaN() if you have a problem with constexpr
}
If you can pass the tests, then all is well.
Otherwise your implementation differs from for double and float.
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.
It does. The pre-check-in passes. :) I'll also take a look at the W/A later.
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.
It does. The pre-check-in passes. :) I'll also take a look at the W/A later.
Good. On Microsoft Windows too(I'm worried about)?
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. The pre-check-in includes testing on both Linux and Windows.
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.
it's wonderful
I can do appropriate edits later if this patch is urgent. |
It's not urgent, but they seems to be unrelated to |
@@ -103,17 +103,97 @@ void verify_vec(queue &q) { | |||
assert(e.get_access<access::mode::read>()[0] == 0); | |||
} | |||
|
|||
void verify_numeric_limits(queue &q) { | |||
// Verify on host side |
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 believe that you can delete this part, because it will tested in kernel side code via // RUN: env SYCL_DEVICE_TYPE=HOST %t.out
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.
No. They have different types during the two compilation stages. One is for _Float16
and another is for the half I implemented.
Thanks a lot for working on this! |
@bader You're welcome! My another PR will be fixed once I get GPU machine. Will be soon. :) |
Implemented the partial specilization of the template class
std::numeric_limits<HALF_TYPE>
where HALF_TYPE is_Float16
ondevice side and
cl::sycl::detail::half_impl::half
on host side.Also defined some marcros corresponding to its FP32 counterpart
like
HLF_MIN
,HLF_MAX
, etc.Signed-off-by: Shilei Tian [email protected]