Skip to content

devicelib: provide __builtin_amdgcn_atomic_inc32 and dec32 on SPIR-V - #1392

Merged
pvelesko merged 2 commits into
mainfrom
2026-07-29-github-1390-amdgcn-atomic-inc-dec
Aug 20, 2026
Merged

devicelib: provide __builtin_amdgcn_atomic_inc32 and dec32 on SPIR-V#1392
pvelesko merged 2 commits into
mainfrom
2026-07-29-github-1390-amdgcn-atomic-inc-dec

Conversation

@pvelesko

Copy link
Copy Markdown
Collaborator

Fixes #1390

Clang declares these builtins only for the amdgcn target, so HIP code written against ROCm that uses them does not compile for SPIR-V. desul, bundled by Kokkos, uses them for atomic_fetch_inc_mod and atomic_fetch_dec_mod.

Their semantics match atomicInc and atomicDec, already implemented by __chip_atomic_inc2_u and __chip_atomic_dec2_u, so the shims forward to those.

New test tests/devicelib/TestAtomicIncDecMod.cpp, verified on Intel Arc B570 (OpenCL): fails to compile before the header change, PASSED after.

__builtin_amdgcn_atomic_inc32 and __builtin_amdgcn_atomic_dec32 are
undeclared on the SPIR-V target, so the test fails to compile today.
It checks the modular semantics step by step for a single thread and
the wrapped total for a contended counter.
Clang declares these builtins only for the amdgcn target, so HIP code
written against ROCm that uses them does not compile for SPIR-V. desul,
which Kokkos bundles, uses them for atomic_fetch_inc_mod and
atomic_fetch_dec_mod, which takes out every Kokkos translation unit that
includes desul/atomics/Fetch_Op_HIP.hpp.

Their semantics match atomicInc and atomicDec, already implemented by
__chip_atomic_inc2_u and __chip_atomic_dec2_u, so forward to those.

Fixes #1390
@pvelesko
pvelesko force-pushed the 2026-07-29-github-1390-amdgcn-atomic-inc-dec branch from 54feded to e4c1998 Compare August 19, 2026 15:32
@pvelesko
pvelesko merged commit 81bd754 into main Aug 20, 2026
26 of 28 checks passed
@pvelesko
pvelesko deleted the 2026-07-29-github-1390-amdgcn-atomic-inc-dec branch August 20, 2026 12:51
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.

__builtin_amdgcn_atomic_inc32 and __builtin_amdgcn_atomic_dec32 are undeclared on SPIR-V, so no Kokkos translation unit that pulls in desul compiles

1 participant