Skip to content

Support BFloat16 kernels on devices that accept SPV_KHR_bfloat16 - #603

Merged
maleadt merged 2 commits into
mainfrom
tb/spirv-bfloat16
Nov 5, 2026
Merged

maleadt merged 2 commits into
mainfrom
tb/spirv-bfloat16

Conversation

@maleadt

@maleadt maleadt commented Nov 3, 2026

Copy link
Copy Markdown
Member

On Julia 1.11+, BFloat16 is Core.BFloat16, which Julia lowers to LLVM's bfloat, 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, from cl_khr_spirv_queries). When it lists SPV_KHR_bfloat16, the compiler enables that extension and GPUCompiler's supports_bfloat16. GPUCompiler 2.20 widens the arithmetic to float (JuliaGPU/GPUCompiler.jl#1076), so supports_bfloat16_arithmetic stays 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 an InvalidIRError, which is tested.

BFloat16 isn't added to the GPUArrays testsuite eltypes yet: BFloat16s.jl lacks host operations that suite needs (rem, so mod/fld). test/bfloat16.jl covers copies, arithmetic and conversions against correctly rounded references instead.

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

codecov Bot commented Nov 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.24%. Comparing base (4828021) to head (9316e0c).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@maleadt

maleadt commented Nov 5, 2026

Copy link
Copy Markdown
Member Author

CI failure unrelated.

@maleadt
maleadt merged commit 0070383 into main Nov 5, 2026
17 of 18 checks passed
@maleadt
maleadt deleted the tb/spirv-bfloat16 branch November 5, 2026 10:53
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.

1 participant