-
Notifications
You must be signed in to change notification settings - Fork 407
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
Add half_t and bhalf_t limits #5778
Conversation
Is this relevant? |
It looks relevant. I don't think all toolchains define these constants though. |
Specifically, changing |
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.
Why define macros rather than provide specialization of the numeric traits?
Yeah: definitely lets just specialize the numeric traits. We need those anyway ... |
Yea, I was thinking about putting them in numeric traits. Let me know if you want the defines somewhere else. I'd prefer to keep the defines. |
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.
We don't need the macros for anything. Those should go away.
Also the numeric traits specialization for half should be in the half header not in the Kokkos_NumericTraits header.
95d5a75
to
7eb3b93
Compare
diff --git a/core/src/Kokkos_Half.hpp b/core/src/Kokkos_Half.hpp
index 656b177cf..59bbac948 100644
--- a/core/src/Kokkos_Half.hpp
+++ b/core/src/Kokkos_Half.hpp
@@ -321,9 +321,7 @@ class alignas(FloatType) floating_point_wrapper {
KOKKOS_FUNCTION
floating_point_wrapper(long long rhs) : val(cast_to_wrapper(rhs, val).val) {}
KOKKOS_FUNCTION
- constexpr floating_point_wrapper(unsigned short rhs) {
- reinterpret_cast<unsigned short>(val) = rhs;
- }
+ constexpr floating_point_wrapper(unsigned short rhs) : val(cast_to_wrapper(rhs, val).val) {}
KOKKOS_FUNCTION
floating_point_wrapper(unsigned int rhs)
: val(cast_to_wrapper(rhs, val).val) {}
@@ -865,7 +863,7 @@ class alignas(FloatType) floating_point_wrapper {
template <class T>
static KOKKOS_INLINE_FUNCTION constexpr Kokkos::Experimental::half_t
cast_to_wrapper(T x, const volatile Kokkos::Impl::half_impl_t::type&) {
- return Kokkos::Experimental::cast_to_half(x);
+ return Kokkos::Experimental::half_t::impl_type(x);
}
#ifdef KOKKOS_IMPL_BHALF_TYPE_DEFINED
@@ -1046,7 +1044,7 @@ struct Kokkos::Experimental::Impl::round_error_helper<
template <>
struct Kokkos::Experimental::Impl::norm_min_helper<
Kokkos::Experimental::half_t> {
- static constexpr int value = 0.000000059604645F;
+ static constexpr Kokkos::Experimental::half_t value = 0.000000059604645F;
};
// Quiet not a half precisioin number
template <>
diff --git a/core/src/SYCL/Kokkos_SYCL_Half_Conversion.hpp b/core/src/SYCL/Kokkos_SYCL_Half_Conversion.hpp
index d7b0271e1..89a167903 100644
--- a/core/src/SYCL/Kokkos_SYCL_Half_Conversion.hpp
+++ b/core/src/SYCL/Kokkos_SYCL_Half_Conversion.hpp
@@ -29,7 +29,7 @@ namespace Experimental {
KOKKOS_INLINE_FUNCTION
half_t cast_to_half(half_t val) { return val; }
-KOKKOS_INLINE_FUNCTION
+constexpr KOKKOS_INLINE_FUNCTION
half_t cast_to_half(float val) { return half_t::impl_type(val); }
KOKKOS_INLINE_FUNCTION
half_t cast_to_half(double val) { return half_t::impl_type(val); } is enough to fix this for |
This reverts commit 1b399bd.
The same changes on CUDA give:
|
Yes, I am seeing
indicating that none of the conversion functions is |
@e10harvey - does this issue need some discussion today? |
@ajpowelsnl - thanks for following up. I think it needs another review by @crtrott and @dalg24 -- please let me know if you have any questions. |
There are failing tests. |
|
Hi @mhoemmen ! Is there a way to invoke CUDA half and bhalf casting intrinsics at compile time? |
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.
Ok I think I get it now.
Uhoh work graph test failed??? |
I mean workgraph is clearly not an issue coming from this I would expect but this is weird |
Retest this please |
Ping |
@dalg24, see response in #5778 (comment). |
I don't see the workgraph failure. Instead, I see that OPENMPTARGET-Clang failed in 0s. How do I triage this? |
Is there documentation somewhere that you can refer to? |
@dalg24: I'm confused. These values are removed now. |
What I am asking is "where would one find out what is the maximum value that is representable with half type". Presumably you looked that up somewhere or you did some experiment. Please document how you came up with these numbers. |
Gotcha. I will document this. Should this be documented in the |
At the very least here in the discussion but if there is a nice reference yes also add as a comment in code. |
OK, thanks for the clarifications, @dalg24. I did not follow a particular reference. I simply looked up definitions of the descriptions for each type of constant, as well as the format of each half precision type (i.e. N bits for significand and M bits for mantissa) and then computed the constants. For the format of the half type I followed https://ieeexplore.ieee.org/abstract/document/9973611. For computing the values, I used https://observablehq.com/@benaubin/floating-point or python, depending on whether I wanted to set individual bits in the half precision type or evaluate an expression. In some cases, I also set the bits via hex constants in the Kokkos half type and used printf to print the base10 representation. In short, I do not have a single reference for where these values came from but I did my best to verify each constant is correct. Perhaps there is a better reference for these constants, but I did not find one during my half precision development work. I also documented the human readable description and equation or high bits above each constants in Kokkos_Half.hpp. I hope this helps. |
Retest this please |
The GCC 8.4.0 pipeline stage in jenkins timed out. |
Retest this please |
We are having some issues with the CPU only testing machines. I would have merged w/o that one :/ |
Retest this please |
Evan dug out a build that had only GCC 8.4 not run |
Move these limits from KokkosKernels. Mostly epsilon is used in unit-tests. ArithTraits also uses the other limits.
Related to kokkos/kokkos-kernels#1414.