Repository navigation
POCL: support BFloat16 kernels when PoCL accepts SPV_KHR_bfloat16 - #946
Conversation
On Julia 1.11+, `BFloat16` is `Core.BFloat16`, which lowers to LLVM's `bfloat`, so any kernel touching a `BFloat16` array failed GPUCompiler's validation. Query the device's SPIR-V extensions (cl_khr_spirv_queries) and, when PoCL lists SPV_KHR_bfloat16 (from pocl_standalone_jll 7.2.3+3), enable it together with GPUCompiler's `supports_bfloat16`. Arithmetic is widened to `float` by GPUCompiler 2.20; older PoCL builds keep failing cleanly with an `InvalidIRError`. Closes #921.
Benchmark resultsCompared with c10ff8cf4, the merge base. Times are the minimum time of every benchmark. A change is unusual when it exceeds both three times the benchmark's typical change between consecutive runs on the default branch and a minimum per category (performance 3%, latency 5%, applications 3%, other 3%). A benchmark that starts or stops allocating is listed however few the allocations. A single run can still be a fluke, so rerun before drawing conclusions.
No unusual changes. All benchmarks
|
BFloat16s.jl 0.6.4 rounds them correctly; the reason left is that vectorized ones 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 #946 +/- ##
==========================================
- Coverage 83.46% 82.83% -0.64%
==========================================
Files 31 31
Lines 2571 2534 -37
==========================================
- Hits 2146 2099 -47
- Misses 425 435 +10 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
On Julia 1.11+,
BFloat16isCore.BFloat16, which Julia lowers to LLVM'sbfloat. The POCL back end never set GPUCompiler'ssupports_bfloat16, so every kernel touching aBFloat16array, even a copy, failed withInvalidIRError: unsupported use of bfloat value(#921).This queries the device's SPIR-V extensions (
CL_DEVICE_SPIRV_EXTENSIONS_KHR, fromcl_khr_spirv_queries) and, when PoCL listsSPV_KHR_bfloat16, enables that extension andsupports_bfloat16. The pieces this relies on:SPV_KHR_bfloat16, plus a fix forabs(INT_MIN)that Julia 1.13's integer toBFloat16conversions hit: [pocl] Accept SPV_KHR_bfloat16 SPIR-V on the CPU devices JuliaPackaging/Yggdrasil#15429, shipped as pocl_standalone_jll 7.2.3+3. The PoCL version stayed the same, so compat can't require that build; the run-time query handles it, and older builds keep failing cleanly with anInvalidIRError.bfloatarithmetic tofloatfor SPIR-V (SPIR-V: work around missing bfloat arithmetic legalization in the back-ends GPUCompiler.jl#1076, in 2.20), as PoCL accepts no bfloat16 arithmetic extension. Hence the compat bump.Tests cover #921's copy kernel, arithmetic and conversions from
Float32/Float64/Int32/Int64/UInt64, checked against correctly rounded references. The references are computed inFloat32(arithmetic) andBigFloat(conversions) rather than with the host'sBFloat16operations: on Julia 1.11, vectorizedBFloat16code on the host either crashes LLVM (Cannot select ... X86ISD::VFPROUNDon AVX512-BF16 CPUs) or, forcopysign, gives wrong results. On Julia 1.10,BFloat16is still BFloat16s.jl's 16-bit primitive type and the tests pass as before.Closes #921