[libclc] [libclc] Replace last of `opencl` atomics with `__scoped_` versions (PR #185515)
Joseph Huber via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 9 13:47:12 PDT 2026
https://github.com/jhuber6 created https://github.com/llvm/llvm-project/pull/185515
Summary:
These were the only uses of the old atomics. The old definition guards
stay as those prevent us from compiling the unsupported uintptr_t atomic
type on nvptx which does not define it. Could probably be improved
later.
>From 6a9a1e0b5ef1fb5c3ce01b971e1c6bc442343300 Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Mon, 9 Mar 2026 15:45:17 -0500
Subject: [PATCH] [libclc] Replace last of `opencl` atomics with `__scoped_`
versions
Summary:
These were the only uses of the old atomics. The old definition guards
stay as those prevent us from compiling the unsupported uintptr_t atomic
type on nvptx which does not define it. Could probably be improved
later.
---
libclc/opencl/lib/amdgcn/printf/__printf_alloc.cl | 10 +++++-----
libclc/opencl/lib/generic/atomic/atomic_fetch_add.cl | 12 ++++++------
libclc/opencl/lib/generic/atomic/atomic_fetch_sub.cl | 12 ++++++------
3 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/libclc/opencl/lib/amdgcn/printf/__printf_alloc.cl b/libclc/opencl/lib/amdgcn/printf/__printf_alloc.cl
index f4a7f46cbbcac..4831d4cbacb24 100644
--- a/libclc/opencl/lib/amdgcn/printf/__printf_alloc.cl
+++ b/libclc/opencl/lib/amdgcn/printf/__printf_alloc.cl
@@ -19,16 +19,16 @@ __global char *__printf_alloc(uint bytes) {
__global char *ptr = (__global char *)args->printf_buffer;
uint size = ((__global uint *)ptr)[1];
- uint offset = __opencl_atomic_load((__global atomic_uint *)ptr,
- memory_order_relaxed, memory_scope_device);
+ uint offset = __scoped_atomic_load_n((__global uint *)ptr, __ATOMIC_RELAXED,
+ __MEMORY_SCOPE_DEVICE);
for (;;) {
if (OFFSET + offset + bytes > size)
return NULL;
- if (__opencl_atomic_compare_exchange_strong(
- (__global atomic_uint *)ptr, &offset, offset + bytes,
- memory_order_relaxed, memory_order_relaxed, memory_scope_device))
+ if (__scoped_atomic_compare_exchange_n(
+ (__global uint *)ptr, &offset, offset + bytes, false,
+ __ATOMIC_RELAXED, __ATOMIC_RELAXED, __MEMORY_SCOPE_DEVICE))
break;
}
diff --git a/libclc/opencl/lib/generic/atomic/atomic_fetch_add.cl b/libclc/opencl/lib/generic/atomic/atomic_fetch_add.cl
index 8e431ace788e0..fb0ee06f95dd6 100644
--- a/libclc/opencl/lib/generic/atomic/atomic_fetch_add.cl
+++ b/libclc/opencl/lib/generic/atomic/atomic_fetch_add.cl
@@ -23,22 +23,22 @@
_CLC_OVERLOAD _CLC_DEF uintptr_t
atomic_fetch_add(volatile __local atomic_uintptr_t *p, ptrdiff_t v) {
- return __opencl_atomic_fetch_add(p, v, memory_order_seq_cst,
- memory_scope_device);
+ return __scoped_atomic_fetch_add((volatile __local uintptr_t *)p, v,
+ __ATOMIC_SEQ_CST, __MEMORY_SCOPE_DEVICE);
}
_CLC_OVERLOAD _CLC_DEF uintptr_t
atomic_fetch_add(volatile __global atomic_uintptr_t *p, ptrdiff_t v) {
- return __opencl_atomic_fetch_add(p, v, memory_order_seq_cst,
- memory_scope_device);
+ return __scoped_atomic_fetch_add((volatile __global uintptr_t *)p, v,
+ __ATOMIC_SEQ_CST, __MEMORY_SCOPE_DEVICE);
}
#if _CLC_GENERIC_AS_SUPPORTED
_CLC_OVERLOAD _CLC_DEF uintptr_t atomic_fetch_add(volatile atomic_uintptr_t *p,
ptrdiff_t v) {
- return __opencl_atomic_fetch_add(p, v, memory_order_seq_cst,
- memory_scope_device);
+ return __scoped_atomic_fetch_add((volatile uintptr_t *)p, v, __ATOMIC_SEQ_CST,
+ __MEMORY_SCOPE_DEVICE);
}
#endif // _CLC_GENERIC_AS_SUPPORTED
diff --git a/libclc/opencl/lib/generic/atomic/atomic_fetch_sub.cl b/libclc/opencl/lib/generic/atomic/atomic_fetch_sub.cl
index e7bd865de7a58..a8ad0c193d2eb 100644
--- a/libclc/opencl/lib/generic/atomic/atomic_fetch_sub.cl
+++ b/libclc/opencl/lib/generic/atomic/atomic_fetch_sub.cl
@@ -23,22 +23,22 @@
_CLC_OVERLOAD _CLC_DEF uintptr_t
atomic_fetch_sub(volatile __local atomic_uintptr_t *p, ptrdiff_t v) {
- return __opencl_atomic_fetch_sub(p, v, memory_order_seq_cst,
- memory_scope_device);
+ return __scoped_atomic_fetch_sub((volatile __local uintptr_t *)p, v,
+ __ATOMIC_SEQ_CST, __MEMORY_SCOPE_DEVICE);
}
_CLC_OVERLOAD _CLC_DEF uintptr_t
atomic_fetch_sub(volatile __global atomic_uintptr_t *p, ptrdiff_t v) {
- return __opencl_atomic_fetch_sub(p, v, memory_order_seq_cst,
- memory_scope_device);
+ return __scoped_atomic_fetch_sub((volatile __global uintptr_t *)p, v,
+ __ATOMIC_SEQ_CST, __MEMORY_SCOPE_DEVICE);
}
#if _CLC_GENERIC_AS_SUPPORTED
_CLC_OVERLOAD _CLC_DEF uintptr_t atomic_fetch_sub(volatile atomic_uintptr_t *p,
ptrdiff_t v) {
- return __opencl_atomic_fetch_sub(p, v, memory_order_seq_cst,
- memory_scope_device);
+ return __scoped_atomic_fetch_sub((volatile uintptr_t *)p, v, __ATOMIC_SEQ_CST,
+ __MEMORY_SCOPE_DEVICE);
}
#endif // _CLC_GENERIC_AS_SUPPORTED
More information about the cfe-commits
mailing list