Repository navigation
Support BFloat16 kernels on devices that accept SPV_KHR_bfloat16 - #603
Merged
Merged
Conversation
On Julia 1.11+, `BFloat16` is `Core.BFloat16`, which lowers to LLVM's `bfloat`, so kernels using it failed GPUCompiler's validation. Add `Device.spirv_extensions` (cl_khr_spirv_queries) and, when it lists SPV_KHR_bfloat16, enable that extension and GPUCompiler's `supports_bfloat16` on the SPIR-V paths. GPUCompiler 2.20 widens the arithmetic to `float`. PoCL reports the extension from pocl_jll 7.2.2+15; the OpenCL C path (spirv2clc) has no bfloat16 and keeps rejecting such kernels.
The bfloat16 change adds the extension on devices that report it, which broke the test's exact comparison of the extension list. Also correct the reason the conversion test avoids the host's BFloat16 conversions: BFloat16s.jl 0.6.4 rounds them correctly, but vectorized ones still crash LLVM on Julia 1.11 on AVX512-BF16 hosts.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #603 +/- ##
==========================================
- Coverage 90.71% 90.24% -0.48%
==========================================
Files 18 18
Lines 1799 1743 -56
==========================================
- Hits 1632 1573 -59
- Misses 167 170 +3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Member
Author
|
CI failure unrelated. |
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.
On Julia 1.11+,
BFloat16isCore.BFloat16, which Julia lowers to LLVM'sbfloat, so kernels using it failed GPUCompiler's validation (same issue as JuliaGPU/KernelAbstractions.jl#921).This adds
Device.spirv_extensions(CL_DEVICE_SPIRV_EXTENSIONS_KHR, fromcl_khr_spirv_queries). When it listsSPV_KHR_bfloat16, the compiler enables that extension and GPUCompiler'ssupports_bfloat16. GPUCompiler 2.20 widens the arithmetic tofloat(JuliaGPU/GPUCompiler.jl#1076), sosupports_bfloat16_arithmeticstays off. The check works for any driver that implements the query. PoCL reports the extension from pocl_jll 7.2.2+15 (JuliaPackaging/Yggdrasil#15429). The OpenCL C path (spirv2clc) has no bfloat16 support and keeps rejecting these kernels with anInvalidIRError, which is tested.BFloat16isn't added to the GPUArrays testsuite eltypes yet: BFloat16s.jl lacks host operations that suite needs (rem, somod/fld).test/bfloat16.jlcovers copies, arithmetic and conversions against correctly rounded references instead.