Skip to content

[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

Merged
merged 1 commit into from
Sep 13, 2019
Merged

[SYCL] Added the support for std::numeric_limits<cl::sycl::half> #536

merged 1 commit into from
Sep 13, 2019

Conversation

shiltian
Copy link
Contributor

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]

@bader bader requested a review from ilyastepykin August 22, 2019 07:59
@bader bader requested a review from ilyastepykin August 29, 2019 17:35
Copy link
Contributor

@keryell keryell left a 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.

@bader
Copy link
Contributor

bader commented Sep 6, 2019

@keryell, @ilyastepykin, could you revisit, please?

keryell
keryell previously approved these changes Sep 11, 2019
ilyastepykin
ilyastepykin previously approved these changes Sep 12, 2019
@bader
Copy link
Contributor

bader commented Sep 12, 2019

@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
D:\buildbot\Product_worker_intel\sycl-win-x64-pr\llvm.src\sycl\include\CL/sycl/half_type.hpp(208): warning C4305: 'argument': truncation from 'double' to 'const float'
D:\buildbot\Product_worker_intel\sycl-win-x64-pr\llvm.src\sycl\include\CL/sycl/half_type.hpp(212): warning C4305: 'argument': truncation from 'double' to 'const float'

Could you fix these warnings, please?

@shiltian
Copy link
Contributor Author

@bader Will do.

@alexeyvoronov-intel
Copy link
Contributor

@tianshilei1992
Can you please not use cl::sycl::half? Just half from global namespace.
Now it is w/a because it is used by Khronos CTS.

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]>
@shiltian
Copy link
Contributor Author

shiltian commented Sep 12, 2019

@alexeyvoronov Sorry I didn't get your point. Do you mean in the test case?

@bader
Copy link
Contributor

bader commented Sep 12, 2019

@tianshilei1992
Can you please not use cl::sycl::half? Just half from global namespace.

Why?

I've opened an issue on the SYCL specification document: KhronosGroup/SYCL-Docs#40.

According to the first comment, we shouldn't use ::half.

@alexeyvoronov-intel
Copy link
Contributor

@alexeyvoronov Sorry I didn't get your point.

By SYCL specification half is fundamental builtin type and available inside global namespace. But in the specification cl::sycl::half does not exist.

@alexeyvoronov-intel
Copy link
Contributor

@tianshilei1992
Can you please not use cl::sycl::half? Just half from global namespace.

Why?

I've opened an issue on the SYCL specification document: KhronosGroup/SYCL-Docs#40.

According to the first comment, we shouldn't use ::half.

I didn't say add a global space specifier, just half.

@bader
Copy link
Contributor

bader commented Sep 12, 2019

@tianshilei1992
Can you please not use cl::sycl::half? Just half from global namespace.

Why?
I've opened an issue on the SYCL specification document: KhronosGroup/SYCL-Docs#40.
According to the first comment, we shouldn't use ::half.

I didn't say add a global space specifier, just half.

What's the difference?

@alexeyvoronov-intel
Copy link
Contributor

@tianshilei1992
Can you please not use cl::sycl::half? Just half from global namespace.

Why?
I've opened an issue on the SYCL specification document: KhronosGroup/SYCL-Docs#40.
According to the first comment, we shouldn't use ::half.

I didn't say add a global space specifier, just half.

What's the difference?
well I didn't see the remark(the first comment), but still this is not the specification..
otherwise there is a mixture of using half in this patch . Both half and cl::sycl::half are used.

@shiltian
Copy link
Contributor Author

@alexeyvoronov The half in the global namespace is not added by me. If it is clear, I'll remove the definition in global namespace.

@bader
Copy link
Contributor

bader commented Sep 12, 2019

@alexeyvoronov The half in the global namespace is not added by me. If it is clear, I'll remove the definition in global namespace.

I suggest @alexeyvoronov to make the change he proposed in a separate patch, as it's not related to goal of this change.
It deserves separate review.

static CONSTEXPR_QUALIFIER half round_error() noexcept { return 0.5F; }

static CONSTEXPR_QUALIFIER half infinity() noexcept {
return __builtin_huge_valf();
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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)?

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's wonderful

@alexeyvoronov-intel
Copy link
Contributor

@alexeyvoronov The half in the global namespace is not added by me. If it is clear, I'll remove the definition in global namespace.

I suggest @alexeyvoronov to make the change he proposed in a separate patch, as it's not related to goal of this change.
It deserves separate review.

@alexeyvoronov The half in the global namespace is not added by me. If it is clear, I'll remove the definition in global namespace.

I suggest @alexeyvoronov to make the change he proposed in a separate patch, as it's not related to goal of this change.
It deserves separate review.

I can do appropriate edits later if this patch is urgent.
You can ignore my comments.

@bader
Copy link
Contributor

bader commented Sep 12, 2019

@alexeyvoronov The half in the global namespace is not added by me. If it is clear, I'll remove the definition in global namespace.

I suggest @alexeyvoronov to make the change he proposed in a separate patch, as it's not related to goal of this change.
It deserves separate review.

@alexeyvoronov The half in the global namespace is not added by me. If it is clear, I'll remove the definition in global namespace.

I suggest @alexeyvoronov to make the change he proposed in a separate patch, as it's not related to goal of this change.
It deserves separate review.

I can do appropriate edits later if this patch is urgent.
You can ignore my comments.

It's not urgent, but they seems to be unrelated to std::numeric_limits support, so I suggest doing it in separate patch.

@@ -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
Copy link
Contributor

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

Copy link
Contributor Author

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.

@bader bader merged commit 6edca52 into intel:sycl Sep 13, 2019
@bader
Copy link
Contributor

bader commented Sep 13, 2019

Thanks a lot for working on this!

@shiltian shiltian deleted the numeric branch September 13, 2019 12:37
@shiltian
Copy link
Contributor Author

@bader You're welcome! My another PR will be fixed once I get GPU machine. Will be soon. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants