Skip to content

[SYCL] Add std::hash and std::numeric_limits specialization for bfloat16 #19838

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

Open
wants to merge 2 commits into
base: sycl
Choose a base branch
from

Conversation

steffenlarsen
Copy link
Contributor

This commit adds the missing std::hash and std::numeric_limits specializations for the sycl::ext::oneapi::bfloat16 class.

This commit adds the missing std::hash and std::numeric_limits
specializations for the sycl::ext::oneapi::bfloat16 class.

Signed-off-by: Larsen, Steffen <[email protected]>
@steffenlarsen
Copy link
Contributor Author

@gmlueck - These are also specialized for sycl::half despite not being explicitly mentioned by the specification. Is it fine to add these without changing the extensions for bfloat16 or do we need associated extension spec mentions?

Signed-off-by: Larsen, Steffen <[email protected]>
@gmlueck
Copy link
Contributor

gmlueck commented Aug 20, 2025

@gmlueck - These are also specialized for sycl::half despite not being explicitly mentioned by the specification. Is it fine to add these without changing the extensions for bfloat16 or do we need associated extension spec mentions?

I think we should update the bfloat16 extension spec to say that the extension does provide these specializations. Using sycl::half as a precedent is not a good idea because it is so poorly specified currently. (There is a SYCL spec issue about this.)

For example, we could add a new section to the spec titled something like "Standard C++ library specializations"

Comment on lines +155 to +157
// Friend traits.
friend std::numeric_limits<bfloat16>;
friend std::hash<bfloat16>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have any guarantees on the layout/size? If so, can we use bit_cast instead of friendship?

Comment on lines +630 to +631
// Specialization of some functions in namespace `std`.
namespace std {
Copy link
Contributor

Choose a reason for hiding this comment

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

Subjective, but I prefer

// in global ns
template <> struct std::{type}<types...> { ... };

Comment on lines +3 to +4
// RUN: %{build} -o %t.out
// RUN: %{run} %t.out
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this belongs to sycl/test, not sycl/test-e2e

Copy link
Contributor

Choose a reason for hiding this comment

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

Or even sycl/unittests

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.

4 participants