Files
llvm/libclc/opencl/lib/generic/atomic/atom_max.cl
Wenju He 79620d8ac0 [libclc] Add OpenCL atomic_*_explicit builtins (#168318)
Implement atomic_*_explicit (e.g. atomic_store_explicit) with
memory_order plus optional memory_scope.

OpenCL memory_order maps 1:1 to Clang (e.g. OpenCL memory_order_relaxed
== Clang __ATOMIC_RELAXED), so we pass it unchanged to clc_atomic_*
function which forwards to Clang _scoped_atomic* builtins.

Other changes:
* Add __opencl_get_clang_memory_scope helper in opencl/utils.h (OpenCL
scope -> Clang scope).
* Correct atomic_compare_exchange return type to bool.
* Fix atomic_compare_exchange to return true when value stored in the
pointer equals expected value.
* Remove volatile from CLC functions so that volatile isn't present in
LLVM IR.
* Add '-fdeclare-opencl-builtins -finclude-default-header' flag to
include
declaration of memory_scope. Some constants in libclc are already
provided
  by Clang’s OpenCL header; disable those in OpenCL library build and
  enable them only for CLC library build.
2025-12-05 10:12:25 +08:00

41 lines
1.6 KiB
Common Lisp

//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include <clc/atomic/clc_atomic_fetch_max.h>
#include <clc/opencl/atomic/atom_max.h>
// Non-volatile overloads are for backward compatibility with OpenCL 1.0.
#define __CLC_IMPL(AS, TYPE) \
_CLC_OVERLOAD _CLC_DEF TYPE atom_max(AS TYPE *p, TYPE val) { \
return __clc_atomic_fetch_max(p, val, __ATOMIC_RELAXED, \
__MEMORY_SCOPE_DEVICE); \
} \
_CLC_OVERLOAD _CLC_DEF TYPE atom_max(volatile AS TYPE *p, TYPE val) { \
return atom_max((AS TYPE *)p, val); \
}
#ifdef cl_khr_global_int32_extended_atomics
__CLC_IMPL(global, int)
__CLC_IMPL(global, unsigned int)
#endif // cl_khr_global_int32_extended_atomics
#ifdef cl_khr_local_int32_extended_atomics
__CLC_IMPL(local, int)
__CLC_IMPL(local, unsigned int)
#endif // cl_khr_local_int32_extended_atomics
#ifdef cl_khr_int64_extended_atomics
__CLC_IMPL(global, long)
__CLC_IMPL(global, unsigned long)
__CLC_IMPL(local, long)
__CLC_IMPL(local, unsigned long)
#endif // cl_khr_int64_extended_atomics