From a5f4074d85bd7633c6d2cd3abaa7ac169430b32c Mon Sep 17 00:00:00 2001 From: Jon Chesterfield Date: Thu, 26 Aug 2021 17:28:17 +0100 Subject: [PATCH] [libomptarget][amdgpu] Macro for accessing GPU variables from plugin Lets the amdgpu plugin write to omptarget_device_environment to enable debugging. Intend to use in the near future to record the wavesize that a given deviceRTL was compiled with for running on hardware that supports 32 or 64. Patch sets all the attributes that are useful. Notably .data means the variable is set by writing to host memory before copying to the GPU instead of launching a kernel to update the image. Can simplify the plugin slightly to drop the code for patching after load if this is used consistently. NFC on nvptx, cuda plugin seems to work fine without any annotations. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D108698 --- openmp/libomptarget/deviceRTLs/amdgcn/src/target_impl.h | 4 ++++ openmp/libomptarget/deviceRTLs/common/src/omp_data.cu | 1 + openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.h | 1 + 3 files changed, 6 insertions(+) diff --git a/openmp/libomptarget/deviceRTLs/amdgcn/src/target_impl.h b/openmp/libomptarget/deviceRTLs/amdgcn/src/target_impl.h index 6921f9b..5396590 100644 --- a/openmp/libomptarget/deviceRTLs/amdgcn/src/target_impl.h +++ b/openmp/libomptarget/deviceRTLs/amdgcn/src/target_impl.h @@ -30,6 +30,10 @@ typedef uint64_t __kmpc_impl_lanemask_t; #define INLINE inline #define NOINLINE __attribute__((noinline)) #define ALIGN(N) __attribute__((aligned(N))) +#define PLUGIN_ACCESSIBLE \ + __attribute__((used)) /* Don't discard values the plugin reads */ \ + __attribute__((visibility("default"))) /* Access via SHT_HASH */ \ + __attribute__((section(".data"))) /* Not .bss, can write before load */ #include "llvm/Frontend/OpenMP/OMPGridValues.h" diff --git a/openmp/libomptarget/deviceRTLs/common/src/omp_data.cu b/openmp/libomptarget/deviceRTLs/common/src/omp_data.cu index 6c72875..e31217e 100644 --- a/openmp/libomptarget/deviceRTLs/common/src/omp_data.cu +++ b/openmp/libomptarget/deviceRTLs/common/src/omp_data.cu @@ -19,6 +19,7 @@ // global device environment //////////////////////////////////////////////////////////////////////////////// +PLUGIN_ACCESSIBLE omptarget_device_environmentTy omptarget_device_environment; //////////////////////////////////////////////////////////////////////////////// diff --git a/openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.h b/openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.h index 1f64bb9..ab471e3 100644 --- a/openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.h +++ b/openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.h @@ -26,6 +26,7 @@ typedef uint32_t __kmpc_impl_lanemask_t; #define INLINE inline __attribute__((always_inline)) #define NOINLINE __attribute__((noinline)) #define ALIGN(N) __attribute__((aligned(N))) +#define PLUGIN_ACCESSIBLE /* no annotation needed for cuda plugin */ #include "llvm/Frontend/OpenMP/OMPGridValues.h" -- 2.7.4