[Openmp-commits] [openmp] 133db44 - [libomptarget] Implement most hip atomic functions in terms of intrinsics
via Openmp-commits
openmp-commits at lists.llvm.org
Wed Mar 4 09:56:52 PST 2020
Author: Jon Chesterfield
Date: 2020-03-04T17:56:40Z
New Revision: 133db44996a80db957360a0b727479d4a8d4d1a2
URL: https://github.com/llvm/llvm-project/commit/133db44996a80db957360a0b727479d4a8d4d1a2
DIFF: https://github.com/llvm/llvm-project/commit/133db44996a80db957360a0b727479d4a8d4d1a2.diff
LOG: [libomptarget] Implement most hip atomic functions in terms of intrinsics
Summary:
[libomptarget] Implement hip atomic functions in terms of intrinsics
All but atomicInc can be implemented using type generic clang intrinsics.
There is not yet a corresponding intrinsic for atomicInc in clang, only one in
LLVM. This patch leaves atomicInc as an unresolved symbol.
Reviewers: jdoerfert, ABataev, hfinkel, grokos, arsenm
Reviewed By: arsenm
Subscribers: sri, saiislam, wdng, jvesely, mgorny, jfb, openmp-commits
Tags: #openmp
Differential Revision: https://reviews.llvm.org/D73076
Added:
Modified:
openmp/libomptarget/deviceRTLs/amdgcn/src/hip_atomics.h
Removed:
################################################################################
diff --git a/openmp/libomptarget/deviceRTLs/amdgcn/src/hip_atomics.h b/openmp/libomptarget/deviceRTLs/amdgcn/src/hip_atomics.h
index 9e0edbbbba56..df102c765925 100644
--- a/openmp/libomptarget/deviceRTLs/amdgcn/src/hip_atomics.h
+++ b/openmp/libomptarget/deviceRTLs/amdgcn/src/hip_atomics.h
@@ -11,29 +11,32 @@
#include "target_impl.h"
-DEVICE unsigned atomicAdd(unsigned *address, unsigned val);
-DEVICE int atomicAdd(int *address, int val);
-DEVICE unsigned long long atomicAdd(unsigned long long *address,
- unsigned long long val);
-
+// inc requires an amdgcn specific intrinsic which is not yet available
DEVICE unsigned atomicInc(unsigned *address);
DEVICE unsigned atomicInc(unsigned *address, unsigned max);
DEVICE int atomicInc(int *address);
-DEVICE int atomicMax(int *address, int val);
-DEVICE unsigned atomicMax(unsigned *address, unsigned val);
-DEVICE unsigned long long atomicMax(unsigned long long *address,
- unsigned long long val);
+namespace {
+
+template <typename T> DEVICE T atomicAdd(T *address, T val) {
+ return __atomic_fetch_add(address, val, __ATOMIC_SEQ_CST);
+}
+
+template <typename T> DEVICE T atomicMax(T *address, T val) {
+ return __atomic_fetch_max(address, val, __ATOMIC_SEQ_CST);
+}
-DEVICE int atomicExch(int *address, int val);
-DEVICE unsigned atomicExch(unsigned *address, unsigned val);
-DEVICE unsigned long long atomicExch(unsigned long long *address,
- unsigned long long val);
+template <typename T> DEVICE T atomicExch(T *address, T val) {
+ T r;
+ __atomic_exchange(address, &val, &r, __ATOMIC_SEQ_CST);
+ return r;
+}
-DEVICE unsigned atomicCAS(unsigned *address, unsigned compare, unsigned val);
-DEVICE int atomicCAS(int *address, int compare, int val);
-DEVICE unsigned long long atomicCAS(unsigned long long *address,
- unsigned long long compare,
- unsigned long long val);
+template <typename T> DEVICE T atomicCAS(T *address, T compare, T val) {
+ (void)__atomic_compare_exchange(address, &compare, &val, false,
+ __ATOMIC_SEQ_CST, __ATOMIC_RELAXED);
+ return compare;
+}
+} // namespace
#endif
More information about the Openmp-commits
mailing list