Skip to content
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

Move half traits to private header and add half/bhalf infinity trait #6055

Merged
merged 3 commits into from
May 14, 2023

Conversation

e10harvey
Copy link
Contributor

@e10harvey e10harvey commented Apr 13, 2023

Summary of changes

  • core/src: Move half traits to private header
  • core/src: Add half_t and bhalf_t infinity trait

Related to #6045 and kokkos/kokkos-kernels#1774.

Copy link
Member

@dalg24 dalg24 left a comment

Choose a reason for hiding this comment

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

Please update the title line of your PR and make sure it mentions this is adding the half precision specializations of the infinity traits that were missing.
This is the most relevant of your PR because that is the only part that is meant to be observable by the user.

core/src/Kokkos_Half_NumericTraits.hpp Outdated Show resolved Hide resolved
@e10harvey e10harvey changed the title core/src: Move half traits to private header core/src: Move half traits to private header and add missing infinity trait Apr 13, 2023
dalg24
dalg24 previously approved these changes Apr 13, 2023
/// bit index: 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
///
template <>
struct Kokkos::Experimental::Impl::infinity_helper<Kokkos::Experimental::half_t> {
Copy link
Member

Choose a reason for hiding this comment

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

you are relying on transitive includes for half_t

Copy link
Member

Choose a reason for hiding this comment

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

either make the new header self contained or discuss why this is ok here

@dalg24 dalg24 dismissed their stale review April 13, 2023 20:32

Withdrawing because new header is not self contained

@e10harvey e10harvey requested a review from dalg24 April 18, 2023 13:09
Comment on lines 20 to 35
// This header must be included at the bottom of Kokkos_Half.hpp
// since this is when we know whether half_t and bhalf_t are
// aliased to float via KOKKOS_HALF_T_IS_FLOAT and
// KOKKOS_BHALF_T_IS_FLOAT. If half_t and bhalf_t are aliases,
// we do not want to re-define traits for float.
// An alternative approach would be to make this header
// standalone by including Kokkos_Half.hpp here. However,
// this leads to a circular include if we want to include
// since they are included in Kokkos_Half.hpp. Nonetheless,
// we cannot define these traits without first having the
// user-facing half_t and bhalf_t types defined. Yet another
// approach would be to make this header user-facing and
// include them in Kokkos_Core.hpp like we do with
// Kokkos_NumericTraits.hpp. However, this could lead to
// usability challenges since half_t and bhalf_t must first
// be defined.
Copy link
Contributor

Choose a reason for hiding this comment

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

What about moving the content of Kokkos_Half.hpp to an impl header and then only include the impl header and this file in Kokkos_Half.hpp?

@e10harvey e10harvey changed the title core/src: Move half traits to private header and add missing infinity trait Move half traits to private header and add missing infinity trait Apr 21, 2023
@dalg24 dalg24 mentioned this pull request Apr 24, 2023
Copy link
Contributor

@masterleinad masterleinad left a comment

Choose a reason for hiding this comment

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

Please split the one commit in such a way that one commit solely moves code without changing anything and other commits fix typos and add stuff. Otherwise, it is very hard to see what the real changes in this pull request are.

@e10harvey e10harvey changed the title Move half traits to private header and add missing infinity trait Move half traits to private header and add half/bhalf infinity trait May 10, 2023
@dalg24
Copy link
Member

dalg24 commented May 10, 2023

Just posting it here in case it saves some time to other reviewers
The 1st commit is not per se a move (I pasted the diff below) but I suppose it is ok. develop has comments about the infinity trait and the actual implementation had been lost somewhere in translation.

--- develop
+++ this_pr
@@ -39,17 +39,7 @@
 //           2**15 * (1 + 0.9990234375) =
 //           65504.0
 //
-
-/// \brief: Infinity.
-///
-/// base2 encoding: bits [10,14] set
-/// #define KOKKOS_IMPL_HALF_T_HUGE_VALH 0x7c00
-/// Binary16 encoding:
-///             [s  e  e  e  e  e  f f f f f f f f f f]
-///             [0  1  1  1  1  1  0 0 0 0 0 0 0 0 0 0]
-/// bit index:  15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
 #if defined(KOKKOS_HALF_T_IS_FLOAT) && !KOKKOS_HALF_T_IS_FLOAT
-
 /// \brief: Minimum normalized number
 ///
 /// Stdc defines this as the smallest number (representable in binary16).
@@ -194,7 +184,7 @@

 /// \brief: This is the smallest possible exponent value
 ///
-/// Stdc defines this as the smallest possible exponent value for type binary16.
+/// Stdc defines this as the smallest possible exponent val`ue for type binary16.
 /// More precisely, it is the minimum negative integer such that the value min_exponent_helper
 /// raised to this power minus 1 can be represented as a normalized floating point number of type float.
 ///
@@ -309,4 +299,4 @@
   static constexpr int value = 128;
 };
 #endif
-////////////// END BHALF_T (bfloat16) limits //////////////
+////////////// END BHALF_T (bfloat16) limits //////////

Please expand the description. Say something like:

This PR does 2 things
* move the numeric traits specializations for `half_t` and `bhalf_t` to a new `<core/src/impl/Kokkos_Half_NumericTraits.hpp>` header
* add the infinity trait for the half types that was missing (oversight)

Copy link
Contributor

@masterleinad masterleinad left a comment

Choose a reason for hiding this comment

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

Looks OK to me now (pending Damien's comments).

Co-authored-by: Damien L-G <dalg24+github@gmail.com>
@dalg24
Copy link
Member

dalg24 commented May 14, 2023

Failures are unrelated (HIP build timing out)
Counting Daniel's approval which is not showing since a new review was requested.

@dalg24 dalg24 merged commit 8a541b5 into kokkos:develop May 14, 2023
27 of 28 checks passed
@dalg24 dalg24 mentioned this pull request May 15, 2023
nliber pushed a commit to nliber/kokkos that referenced this pull request Jun 22, 2023
…okkos#6055)

* core/src: Move half traits to private header

* core/src: Add half_t and bhalf_t infinity trait

* Update core/src/impl/Kokkos_Half_NumericTraits.hpp

Co-authored-by: Damien L-G <dalg24+github@gmail.com>

---------

Co-authored-by: Damien L-G <dalg24+github@gmail.com>
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.

None yet

4 participants