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.
This PR makes f16 and bf16 usable for the spirv target, when using rust-gpu.
The rust-gpu compiler rustc_codegen_spirv compiles most of the core lib, but is extra picky about pointer casts, so operations on str often won't compile. So for target_arch = "spirv", I disabled impls for FromStr, Debug, Display, LowerExp, UpperExp, Binary, Octal, LowerHex, and UpperHex.
Additionally, the leading_zeros method which is used for conversions requires intrinsics on spirv, so I added a fallback in case those intrinsics are not available. I also added a test to validate this algorithm.
Usage
I'm using this in autograph but until now have been borrowing some conversion methods to operate on a pack of 2 bf16 values. But I figured out how to do 16 bit operations with the appropriate hw capabilities, which is much more natural and allows for generic functions.
Related
This could be useful to the Rust-CUDA project as well, which offers a similar operation as rust-gpu, for targeting cuda / nvptx. It would be interesting to see if f16 / bf16 work with or without these changes.