Repository navigation
feat(cuda-device): add scalar bf16_to_f32 - #1185
Merged
nihalpasham merged 3 commits intoAug 28, 2026
Merged
Conversation
The scalar inverse of f32_to_bf16 was missing, so call sites open-coded the high-half widen. This is the same bit-shift already used by the packed bf16 unpackers; host unit tests cover 1.0, -0.0, and round-trip through f32_to_bf16. Signed-off-by: Zihua Wu <[email protected]>
Collaborator
|
Sound and mergeable as-is. Verified:
Two small things I added at landing:
CI is approved on the newest head. Labels added. |
bf16_to_f32 places the 16 bits in the f32 high half and f32_to_bf16 truncates them back out, so every u16 pattern (NaNs included) must survive the trip bit-identically. Assert that exhaustively, following the every_non_nan_f16_pattern_round_trips convention. Signed-off-by: nihalpasham <[email protected]>
…hecks gemm_sol, gemm_sol_final, and tcgen05_matmul each carried a private copy of the high-half widen for their host-side result checks. The scalar helper now lives in cuda_device::convert, so drop the local copies and import the library one. Signed-off-by: nihalpasham <[email protected]>
nihalpasham
approved these changes
Aug 28, 2026
nihalpasham
left a comment
Collaborator
There was a problem hiding this comment.
Validation complete on this head (crate tests, per-example gates, compile-only smoketest); CI green. Merging.
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.
cuda_device::converthasf32_to_bf16but not the scalar inverse, so reading a raw bf16 means open-coding the high-half widen at each call site:Added
bf16_to_f32(u16) -> f32f32_to_bf16for values already exact in bf16This is the same bit-shift already used by the packed bf16 unpackers (
cvt_f32x2_bf16x2and friends). The low 16 bits of thef32become zero.Why no generator / no GPU example
This is not a new PTX intrinsic. There is nothing for the generator to admit, and no new GPU example — the same as existing
f32_to_bf16, which is also a host-side bit reinterpret.Tests
0x3F80widens to1.00x8000widens to-0.0(bit-identical)bf16_to_f32(f32_to_bf16(1.0)) == 1.0Host unit tests only;
fmt --checkclean.