[libclc] Add generic implementation of some atomic functions in OpenCL spec section 6.15.12.7#146814
Merged
Conversation
…L spec section 6.15.12.7 Add corresponding clc functions, which are implemented with clang __scoped_atomic builtins. OpenCL functions are implemented as a wrapper over clc functions. Also change legacy atomic_inc and atomic_dec to re-use the newly added clc_atomic_inc/dec implementations. llvm-diff only no change to atomic_inc and atomic_dec in bitcode. Notes: * Generic OpenCL built-ins functions uses __ATOMIC_SEQ_CST and __MEMORY_SCOPE_SYSTEM for memory order and memory scope parameters. Ideally we should check if __opencl_c_atomic_order_seq_cst, __opencl_c_atomic_scope_all_devices and __opencl_c_atomic_scope_device feature macros should be checked. However, none of them are defined for nvptx64 and amdgcn arch yet. We can add the check when the backends are fixed. * OpenCL atomic_*_explicit, atomic_flag* built-ins are not implemented yet. * OpenCL built-ins of atomic_intptr_t, atomic_uintptr_t, atomic_size_t and atomic_ptrdiff_t types are not implemented yet. * llvm-diff only shows new built-ins are added to nvptx64--nvidiacl.bc and amdgcn--amdhsa.bc. The number of newly added built-ins in amdgcn--amdhsa.bc is higher than in nvptx64--nvidiacl.bc because 64-bit atomics are enabled for amdgcn--amdhsa.
frasercrmck
reviewed
Jul 10, 2025
…_opencl_c_atomic_scope_device
…c_atomic_scope_device macro is required for the new built-ins
frasercrmck
reviewed
Jul 14, 2025
frasercrmck
left a comment
Contributor
There was a problem hiding this comment.
Can we do anything about the warnings I'm seeing while building this? They're noisy.
In file included from /llvm-project/libclc/clc/lib/generic/atomic/clc_atomic_fetch_min.cl:18:
In file included from /llvm-project/libclc/clc/include/clc/math/gentype.inc:239:
/llvm-project/libclc/clc/lib/generic/atomic/atomic_def.inc:59:1: warning: large atomic operation may incur significant performance penalty; the access size (2 bytes) exceeds the max lock-free size (0 bytes) [-Watomic-alignment]
59 | __CLC_DEFINE_ATOMIC()
| ^
/llvm-project/libclc/clc/lib/generic/atomic/atomic_def.inc:51:9: note: expanded from macro '__CLC_DEFINE_ATOMIC'
51 | __IMPL_FUNCTION((ADDRSPACE __CLC_PTR_CASTTYPE *)Ptr, Value, \
| ^
/llvm-project/libclc/clc/lib/generic/atomic/clc_atomic_fetch_min.cl:12:25: note: expanded from macro '__IMPL_FUNCTION'
12 | #define __IMPL_FUNCTION __scoped_atomic_fetch_min
| ^
wenju-he
added a commit
to wenju-he/llvm-project
that referenced
this pull request
Jul 16, 2025
…for spir64 Set MaxAtomicInlineWidth the same way as SPIR-V targets in 3cfd0c0. This PR fixes build warning in scoped atomic built-in in llvm#146814: `warning: large atomic operation may incur significant performance penalty`
Contributor
Author
thanks @frasercrmck |
frasercrmck
approved these changes
Jul 16, 2025
wenju-he
added a commit
that referenced
this pull request
Jul 17, 2025
…for spir64 (#148997) Set MaxAtomicInlineWidth the same way as SPIR-V targets in 3cfd0c0. This PR fixes build warning in scoped atomic built-in in #146814: `warning: large atomic operation may incur significant performance penalty; ; the access size (2 bytes) exceeds the max lock-free size (0 bytes) [-Watomic-alignment]`
…ning 'large atomic operation may incur significant performance penalty' Also rename clc/lib/generic/atomic/atomic_def.inc to clc_atomic_def.inc
Contributor
Author
|
@frasercrmck please review new two changes in c88bf9b:
|
frasercrmck
approved these changes
Jul 17, 2025
This was referenced Jul 23, 2025
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.
Add corresponding clc functions, which are implemented with clang __scoped_atomic builtins. OpenCL functions are implemented as a wrapper over clc functions.
Also change legacy atomic_inc and atomic_dec to re-use the newly added clc_atomic_inc/dec implementations. llvm-diff only no change to atomic_inc and atomic_dec in bitcode.
Notes: