Add host-side bfloat16 helpers for platforms without std::bfloat16_t#3110
Open
thomthehound wants to merge 7 commits into
Open
Add host-side bfloat16 helpers for platforms without std::bfloat16_t#3110thomthehound wants to merge 7 commits into
thomthehound wants to merge 7 commits into
Conversation
Signed-off-by: thomthehound <thomthehound@gmail.com>
Signed-off-by: thomthehound <thomthehound@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Under the C++23 standard,
std::bfloat16_tsupport is optional. The current MSVC toolchain has chosen not to exercise that option, while the Linux toolchain does. Therefore, host-side example code that manipulates bfloat16 data cannot usestd::bfloat16_tsafely when compiled with MSVC, as is the intended route on native Windows.This patch adds
test_utils::bfloat16_t(and related helpers) totest_utils.h. When the standard type is available,test_utils::bfloat16_tresolves directly tostd::bfloat16_t, preserving native execution. Otherwise, it usesstd::uint16_tstorage and performs host-side conversion/math throughfloat(rounding back to 16 bits by the nearest-even method).In the trivial case, the type selection works as so:
These changes are host-side only; device code is unaffected. The examples have been updated to use
test_utils::bfloat16_tconsistently for host-side bfloat16 data (including those that are not obviously Windows-portable) so there are not two competing vocabularies.This workaround is not intended to permanently solve host-side
bfloat16portability for all user code. It is intended to draw attention to this limitation, and to prepare the programming examples for cross-platform conversion. In the future, it may be reasonable to provide a better API boundary for this, but doing so would create a new public convention and is therefore a separate consideration.