[Openmp-commits] [PATCH] D73076: [libomptarget] Implement most hip atomic functions in terms of intrinsics

Jon Chesterfield via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Tue Mar 3 10:56:24 PST 2020


JonChesterfield updated this revision to Diff 247956.
JonChesterfield added a comment.

- Simplify, drop atomicInc impl


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73076/new/

https://reviews.llvm.org/D73076

Files:
  openmp/libomptarget/deviceRTLs/amdgcn/src/hip_atomics.h


Index: openmp/libomptarget/deviceRTLs/amdgcn/src/hip_atomics.h
===================================================================
--- openmp/libomptarget/deviceRTLs/amdgcn/src/hip_atomics.h
+++ 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73076.247956.patch
Type: text/x-patch
Size: 2248 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20200303/0792c5c0/attachment.bin>


More information about the Openmp-commits mailing list