Repository navigation
Conversation
Base SPIR-V can't carry the `contract` fast-math flag, so `muladd` reaches PoCL as a separate multiply and add (and the SPIR-V back-end marks every kernel `ContractionOff`), which PoCL never fuses into an FMA (#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 query the SPIR-V extensions the device accepts (cl_khr_spirv_queries) and enable it only when it is among them. Explicitly passed `extensions` replace this default. Assisted-by: Claude Code (Opus 5.5)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #876 +/- ##
==========================================
+ Coverage 80.49% 80.57% +0.07%
==========================================
Files 26 26
Lines 2210 2219 +9
==========================================
+ Hits 1779 1788 +9
Misses 431 431 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
Benchmark ResultsShow table
Benchmark PlotsA plot of the benchmark results have been uploaded as an artifact to the workflow run for this PR. |
This was referenced Oct 13, 2026
SPIR-V: fuse contractable multiply-adds into
fma on devices with an FMA
JuliaGPU/GPUCompiler.jl#1010
Draft
This branch has not been deployed
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.
Fixes the PoCL half of #865, once PoCL accepts the extension. Draft until JuliaGPU/GPUCompiler.jl#1007 is released (see below).
Base SPIR-V can't carry LLVM's
contractfast-math flag. Somuladdreaches PoCL as a separateOpFMul+OpFAdd, the SPIR-V back-end marks every kernelContractionOff, and PoCL never emits an FMA.SPV_KHR_float_controls2carries the flag asFPFastMathMode AllowContract, and the SPIR-V back-end emits that when the extension is enabled.Once enabled, though, the back-end declares the extension in every float kernel, and drivers that don't accept it reject the module. So this PR:
spirv_extensionsdevice property to nanoOpenCL (CL_DEVICE_SPIRV_EXTENSIONS_KHR, fromcl_khr_spirv_queries; empty when the device doesn't support the query);extensionsincompiler_configto theOPTIONAL_SPIRV_EXTENSIONS(currently justSPV_KHR_float_controls2) that the device lists. Explicitly passedextensionsreplace that default.Dependencies:
pocl_standalone_jll(PoCL 7.2, LLVM 22.1.8) doesn't report it, so with today's jll this PR changes nothing.contractoperations once the extension is on. It omits theFloatControls2capability that its implicitFPFastMathDefaultneeds. SPIR-V: declare FloatControls2 for kernels with SPV_KHR_float_controls2 GPUCompiler.jl#1007 works around this. Before merging, this PR should raise the GPUCompiler compat to the release that contains it.Testing:
FPFastMathMode AllowContract; andextensions = ""turns it off.pocl_standalone_jll, the extension isn't reported, the testset passes, and kernels are unchanged.libpocl_pathpreference) and SPIR-V: declare FloatControls2 for kernels with SPV_KHR_float_controls2 GPUCompiler.jl#1007:@kernellaunch ofy[i] = muladd(a[i], x[i], y[i])compiles tovfmaddand gives results bit-identical tofma.(a, x, y). Without this PR it compiles tovmulsd/vaddsd.mainon the same PoCL, plus the new testset. One testset is excluded on both: "CPU back-end", where that PoCL 8.0-pre/LLVM 23 build aborts withCould not find a dominating alternative variableonmaintoo.Same change for OpenCL.jl: JuliaGPU/OpenCL.jl#562
🤖 Generated with Claude Code