Skip to content

llvm_passes: lower atomicrmw fmin and fmax to cmpxchg loops - #1405

Merged
pvelesko merged 2 commits into
mainfrom
2026-07-29-github-1403-lower-fp-atomic-minmax
Aug 24, 2026
Merged

pvelesko merged 2 commits into
mainfrom
2026-07-29-github-1403-lower-fp-atomic-minmax

Conversation

@pvelesko

Copy link
Copy Markdown
Collaborator

Fixes #1403

__hip_atomic_fetch_min and __hip_atomic_fetch_max on a floating point type lower to atomicrmw fmin and fmax, which llvm-spirv can only translate with SPV_EXT_shader_atomic_float_min_max. That extension is not in the allow list chipStar's driver hands the translator, so the link dies.

Widening the allow list was the other option, but it would only move the failure to program build time on drivers without cl_ext_float_atomics. The new pass expands the operation to a cmpxchg loop, which every target chipStar supports can run, and which is what devicelib.cl already does for atomicMin and atomicMax.

New test tests/devicelib/TestAtomicFPMinMaxBuiltins.cpp, verified on Intel Arc B570 (OpenCL): does not link before, PASSED after. It covers float and double, a contended reduction, and the returned previous value.

Found while getting the Kokkos HIP backend running on chipStar; desul uses these builtins, which took out Kokkos_ContainersUnitTest_Serial and Kokkos_ContainersUnitTest_HIP.

@pvelesko

Copy link
Copy Markdown
Collaborator Author

/run-aurora-ci

@pvelesko
pvelesko marked this pull request as draft July 30, 2026 18:32
@pvelesko
pvelesko marked this pull request as ready for review August 23, 2026 10:32
__hip_atomic_fetch_min and __hip_atomic_fetch_max on a floating point
type lower to atomicrmw fmin and fmax, which llvm-spirv refuses without
SPV_EXT_shader_atomic_float_min_max, so the test does not link today.
Clang lowers __hip_atomic_fetch_min and __hip_atomic_fetch_max on a
floating point type to atomicrmw fmin and fmax. llvm-spirv can only
translate those with SPV_EXT_shader_atomic_float_min_max, which is not in
the extension allow list chipStar's driver hands the translator, so the
link dies with

  RequiresExtension: Feature requires the following SPIR-V extension:
   SPV_EXT_shader_atomic_float_min_max

Widening the allow list would only move the failure to program build time
on drivers without cl_ext_float_atomics. Expand the operation to a
cmpxchg loop instead, which every target chipStar supports can run, and
which is what devicelib.cl already does for atomicMin and atomicMax.

Fixes #1403
@pvelesko
pvelesko force-pushed the 2026-07-29-github-1403-lower-fp-atomic-minmax branch from 48e7006 to a517113 Compare August 24, 2026 07:56
@pvelesko
pvelesko merged commit 9743262 into main Aug 24, 2026
18 checks passed
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.

Float atomic min and max abort the SPIR-V translation: RequiresExtension SPV_EXT_shader_atomic_float_min_max

1 participant