Repository navigation
Conversation
SPIR-V can't carry the `contract` flag without SPV_KHR_float_controls2, so `muladd` reaches PoCL as a separate multiply and add, which it never fuses (#865). GPUCompiler can fuse what may be contracted into OpenCL's `fma` before emitting SPIR-V; enable that (`SPIRVCompilerTarget(; fma)`) when the device reports `CL_FP_FMA` in its single-precision capabilities, which PoCL does on x86 only for CPUs with an FMA (OpenCL mandates it for double precision, so that one doesn't tell). The `fma` keyword of `compiler_config` and `@opencl` overrides it. With it, `y[i] = muladd(a[i], x[i], y[i])` compiles to a vectorized `vfmadd231ps` and matches `fma.(a, x, y)` bit for bit; `@simd` reductions still vectorize. Needs the GPUCompiler release with the `fma` field. Assisted-by: Claude Code (Opus 5.5)
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #892 +/- ##
===========================================
- Coverage 82.59% 13.27% -69.33%
===========================================
Files 28 26 -2
Lines 2454 2342 -112
===========================================
- Hits 2027 311 -1716
- Misses 427 2031 +1604 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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 with today's
pocl_standalone_jll. Draft until JuliaGPU/GPUCompiler.jl#1010 is released; this PR should then raise the GPUCompiler compat to that release.SPIR-V can't carry the
contractflag withoutSPV_KHR_float_controls2, somuladdreaches PoCL as a separate multiply and add, which it never fuses. JuliaGPU/GPUCompiler.jl#1010 can instead fuse what may be contracted into OpenCL'sfmabefore emitting SPIR-V (SPIRVCompilerTarget(; fma = true)). Since OpenCL'sfmamust be correctly rounded, that is only worth it on a device with a fused multiply-add. This PR:single_fp_configdevice property to nanoOpenCL (CL_DEVICE_SINGLE_FP_CONFIG);fmaincompiler_configto whether that config hasCL_FP_FMA. PoCL sets the bit on x86 only when the CPU has an FMA. The double-precision config isn't used, because OpenCL mandatesCL_FP_FMAthere, and PoCL's generic fallback always sets it;fmaas a keyword ofcompiler_configand@opencl, to override it.Results
On an AMD Ryzen 9 5950X (AVX2 + FMA),
y[i] = muladd(a[i], x[i], y[i])in a@kernelcompiles to a vectorizedvfmadd231ps, and the result matchesfma.(a, x, y)bit for bit. Without this PR it compiles tovmulps+vaddps. Plaina * x + ystays unfused, and@simdreductions still vectorize (see the GPUCompiler PR for details).Testing
CL_FP_FMA;muladdkernel is fused exactly when it does;fma = falseturns fusion off.Relation to #876: this route works with today's PoCL (LLVM 22). #876 (
SPV_KHR_float_controls2) needs PoCL with LLVM 23. Once both are in, a device that accepts the extension could leave the contraction to the driver instead.🤖 Generated with Claude Code