[Openmp-commits] [PATCH] D83132: [libomptarget] Implement atomic inc and fence functions for AMDGCN using clang builtins

Saiyedul Islam via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Tue Jul 7 00:32:03 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG38d6640ba55e: [libomptarget] Implement atomic inc and fence functions for AMDGCN using clang… (authored by saiislam).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83132

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


Index: openmp/libomptarget/deviceRTLs/amdgcn/src/target_impl.h
===================================================================
--- openmp/libomptarget/deviceRTLs/amdgcn/src/target_impl.h
+++ openmp/libomptarget/deviceRTLs/amdgcn/src/target_impl.h
@@ -120,9 +120,17 @@
   __builtin_amdgcn_s_barrier();
 }
 
-DEVICE void __kmpc_impl_threadfence(void);
-DEVICE void __kmpc_impl_threadfence_block(void);
-DEVICE void __kmpc_impl_threadfence_system(void);
+INLINE void __kmpc_impl_threadfence() {
+  __builtin_amdgcn_fence(__ATOMIC_SEQ_CST, "agent");
+}
+
+INLINE void __kmpc_impl_threadfence_block() {
+  __builtin_amdgcn_fence(__ATOMIC_SEQ_CST, "workgroup");
+}
+
+INLINE void __kmpc_impl_threadfence_system() {
+  __builtin_amdgcn_fence(__ATOMIC_SEQ_CST, "");
+}
 
 // Calls to the AMDGCN layer (assuming 1D layout)
 INLINE int GetThreadIdInBlock() { return __builtin_amdgcn_workitem_id_x(); }
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,11 +11,6 @@
 
 #include "target_impl.h"
 
-// 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);
-
 namespace {
 
 template <typename T> DEVICE T atomicAdd(T *address, T val) {
@@ -38,5 +33,9 @@
   return compare;
 }
 
+INLINE uint32_t atomicInc(uint32_t *address, uint32_t max) {
+  return __builtin_amdgcn_atomic_inc32(address, max, __ATOMIC_SEQ_CST, "");
+}
+
 } // namespace
 #endif


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83132.275647.patch
Type: text/x-patch
Size: 1704 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20200707/de921afe/attachment.bin>


More information about the Openmp-commits mailing list