devicelib: provide __builtin_amdgcn_atomic_inc32 and dec32 on SPIR-V - #1392
Merged
Conversation
__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
force-pushed
the
2026-07-29-github-1390-amdgcn-atomic-inc-dec
branch
from
August 19, 2026 15:32
54feded to
e4c1998
Compare
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 #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.