[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
Fri Jul 3 08:02:14 PDT 2020


saiislam created this revision.
saiislam added reviewers: jdoerfert, arsenm, JonChesterfield.
Herald added subscribers: openmp-commits, sstefan1, jfb, wdng, jvesely.
Herald added a project: OpenMP.

These functions use __builtin_amdgcn_atomic_inc32():

  uint32_t atomicInc(uint32_t *address);
  uint32_t atomicInc(uint32_t *address, uint32_t max);

These functions use __builtin_amdgcn_fence():
__kmpc_impl_threadfence()
__kmpc_impl_threadfence_block()
__kmpc_impl_threadfence_system()

They will take place of current mechanism of directly calling IR functions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83132

Files:
  openmp/libomptarget/deviceRTLs/amdgcn/src/amdgcn_threadfence.hip
  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,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,15 @@
   return compare;
 }
 
+// Variants of atomicInc with and without wraparound MAX value
+DEVICE uint32_t atomicInc(uint32_t *address) {
+  return __builtin_amdgcn_atomic_inc32(address, UINT32_MAX, __ATOMIC_SEQ_CST,
+                                       "");
+}
+
+DEVICE uint32_t atomicInc(uint32_t *address, uint32_t max) {
+  return __builtin_amdgcn_atomic_inc32(address, max, __ATOMIC_SEQ_CST, "");
+}
+
 } // namespace
 #endif
Index: openmp/libomptarget/deviceRTLs/amdgcn/src/amdgcn_threadfence.hip
===================================================================
--- /dev/null
+++ openmp/libomptarget/deviceRTLs/amdgcn/src/amdgcn_threadfence.hip
@@ -0,0 +1,21 @@
+//===----- amdgcn_threadfence.hip - AMDGCN fence implementation --- HIP -*-===//
+//
+// 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 "target_impl.h"
+
+EXTERN void __kmpc_impl_threadfence() {
+  __builtin_amdgcn_fence(__ATOMIC_SEQ_CST, "agent");
+}
+
+EXTERN void __kmpc_impl_threadfence_block() {
+  __builtin_amdgcn_fence(__ATOMIC_SEQ_CST, "workgroup");
+}
+
+EXTERN void __kmpc_impl_threadfence_system() {
+  __builtin_amdgcn_fence(__ATOMIC_SEQ_CST, "");
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83132.275393.patch
Type: text/x-patch
Size: 2006 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20200703/10c3b09a/attachment.bin>


More information about the Openmp-commits mailing list