Skip to content

Enable SPV_KHR_float_controls2 when the device accepts it - #562

Draft
vchuravy wants to merge 1 commit into
mainfrom
vc/spirv-float-controls2
Draft

vchuravy wants to merge 1 commit into
mainfrom
vc/spirv-float-controls2

Conversation

@vchuravy

Copy link
Copy Markdown
Member

Draft until JuliaGPU/GPUCompiler.jl#1007 is released (see below). Same change as JuliaGPU/KernelAbstractions.jl#876.

Base SPIR-V can't carry LLVM's contract fast-math flag. So muladd reaches the driver as a separate OpFMul + OpFAdd, the SPIR-V back-end marks every kernel ContractionOff, and the driver never emits an FMA (JuliaGPU/KernelAbstractions.jl#865). SPV_KHR_float_controls2 carries the flag as FPFastMathMode AllowContract, and both SPIR-V back-ends emit that when the extension is enabled.

Once enabled, though, the back-ends declare the extension in every float kernel, and drivers that don't accept it reject the module. So this PR:

  • adds a spirv_extensions device property (CL_DEVICE_SPIRV_EXTENSIONS_KHR, from cl_khr_spirv_queries; empty when the device doesn't support the query);
  • defaults extensions in the compiler config to the OPTIONAL_SPIRV_EXTENSIONS (currently just SPV_KHR_float_controls2) that the device lists. Programs built through spirv2clc don't get it, and explicitly passed extensions replace the default;
  • adds a missing comma in propertynames(::Device), which made :non_uniform_work_group_support :extensions parse as a range, so calling it threw.

Dependencies:

Testing:

  • spirv_extensions is added to the device-info test, and a new "fast-math contraction" test checks three things: AllowContract is emitted exactly when the config enables the extension; the extension is enabled when the device reports it; and extensions = String[] turns it off.
  • device and execution tests on every platform on this machine (PoCL, PoCL-C, Intel CPU, AMD APP, NVIDIA, rusticl): the same results as main, plus the new tests. The existing failures match main: Intel device 1, AMD device 2, AMD execution 1, rusticl execution 1.
  • Full suite, with a PoCL build of Enable SPV_KHR_float_controls2 for the CPU devices pocl/pocl#2393 (LLVM 23.1.1) and SPIR-V: declare FloatControls2 for kernels with SPV_KHR_float_controls2 GPUCompiler.jl#1007: 30,515 passes versus 30,509 on main with the same PoCL, where the extra 6 are the new tests. Both runs crash in the same two files, pocl/intrinsics and poclc/intrinsics, with illegal instructions from that PoCL dev build.
  • End to end on that PoCL: @opencl of y[i] = muladd(a[i], x[i], y[i]) compiles to vfmadd and gives results bit-identical to fma.(a, x, y).

🤖 Generated with Claude Code

Base SPIR-V can't carry the `contract` fast-math flag, so `muladd`
reaches the driver as a separate multiply and add (and the SPIR-V
back-end marks every kernel `ContractionOff`), which drivers never fuse
into an FMA (JuliaGPU/KernelAbstractions.jl#865).
SPV_KHR_float_controls2 carries the flag as `FPFastMathMode
AllowContract`.

Enabling the extension makes the back-end declare it in every kernel,
which drivers that don't accept it reject, so add a `spirv_extensions`
device property (cl_khr_spirv_queries) and enable the extension only
when the device lists it. Explicitly passed `extensions` replace this
default, and programs built through spirv2clc don't get it.

Also add a missing comma in `propertynames(::Device)`, which made it
throw.

Assisted-by: Claude Code (Opus 5.5)
@codecov

codecov Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.08%. Comparing base (7b8d2c4) to head (8e929c9).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #562      +/-   ##
==========================================
+ Coverage   86.06%   86.08%   +0.01%     
==========================================
  Files          17       17              
  Lines        1615     1617       +2     
==========================================
+ Hits         1390     1392       +2     
  Misses        225      225              

☔ 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.

This branch has not been deployed

No deployments
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