From e069662deb1fa167b3e5fdce4c9949e663df8082 Mon Sep 17 00:00:00 2001 From: Jon Chesterfield Date: Wed, 20 Jan 2021 15:50:41 +0000 Subject: [PATCH] [libomptarget][devicertl] Wrap source in declare target pragmas [libomptarget][devicertl] Wrap source in declare target pragmas Factored out of D93135 / D94745. C++ and cuda ignore unknown pragmas so this is a NFC for the current implementation language. Removes noise from patches for building deviceRTL as openmp. Reviewed By: tianshilei1992 Differential Revision: https://reviews.llvm.org/D95048 --- openmp/libomptarget/deviceRTLs/amdgcn/src/amdgcn_locks.hip | 3 +++ openmp/libomptarget/deviceRTLs/amdgcn/src/amdgcn_smid.hip | 3 +++ openmp/libomptarget/deviceRTLs/amdgcn/src/target_impl.hip | 3 +++ openmp/libomptarget/deviceRTLs/common/src/cancel.cu | 3 +++ openmp/libomptarget/deviceRTLs/common/src/critical.cu | 3 +++ openmp/libomptarget/deviceRTLs/common/src/data_sharing.cu | 3 +++ openmp/libomptarget/deviceRTLs/common/src/libcall.cu | 3 +++ openmp/libomptarget/deviceRTLs/common/src/loop.cu | 3 +++ openmp/libomptarget/deviceRTLs/common/src/omp_data.cu | 3 +++ openmp/libomptarget/deviceRTLs/common/src/omptarget.cu | 3 +++ openmp/libomptarget/deviceRTLs/common/src/parallel.cu | 3 +++ openmp/libomptarget/deviceRTLs/common/src/reduction.cu | 2 ++ openmp/libomptarget/deviceRTLs/common/src/support.cu | 2 ++ openmp/libomptarget/deviceRTLs/common/src/sync.cu | 3 +++ openmp/libomptarget/deviceRTLs/common/src/task.cu | 3 +++ openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.cu | 3 +++ 16 files changed, 46 insertions(+) diff --git a/openmp/libomptarget/deviceRTLs/amdgcn/src/amdgcn_locks.hip b/openmp/libomptarget/deviceRTLs/amdgcn/src/amdgcn_locks.hip index 4163a14f50bf..f537fb28318c 100644 --- a/openmp/libomptarget/deviceRTLs/amdgcn/src/amdgcn_locks.hip +++ b/openmp/libomptarget/deviceRTLs/amdgcn/src/amdgcn_locks.hip @@ -14,6 +14,7 @@ // a SIMD => wavefront mapping once that is implemented. // //===----------------------------------------------------------------------===// +#pragma omp declare target #include "common/debug.h" @@ -26,3 +27,5 @@ DEVICE void __kmpc_impl_destroy_lock(omp_lock_t *) { warn(); } DEVICE void __kmpc_impl_set_lock(omp_lock_t *) { warn(); } DEVICE void __kmpc_impl_unset_lock(omp_lock_t *) { warn(); } DEVICE int __kmpc_impl_test_lock(omp_lock_t *lock) { warn(); } + +#pragma omp end declare target diff --git a/openmp/libomptarget/deviceRTLs/amdgcn/src/amdgcn_smid.hip b/openmp/libomptarget/deviceRTLs/amdgcn/src/amdgcn_smid.hip index 74d0d167137f..c85045570de2 100644 --- a/openmp/libomptarget/deviceRTLs/amdgcn/src/amdgcn_smid.hip +++ b/openmp/libomptarget/deviceRTLs/amdgcn/src/amdgcn_smid.hip @@ -5,6 +5,7 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// +#pragma omp declare target #include "target_impl.h" @@ -59,3 +60,5 @@ DEVICE uint32_t __kmpc_impl_smid() { ENCODE_HWREG(HW_ID_SE_ID_SIZE, HW_ID_SE_ID_OFFSET, HW_ID)); return (se_id << HW_ID_CU_ID_SIZE) + cu_id; } + +#pragma omp end declare target diff --git a/openmp/libomptarget/deviceRTLs/amdgcn/src/target_impl.hip b/openmp/libomptarget/deviceRTLs/amdgcn/src/target_impl.hip index 3e70beb85d5b..7388a29215cc 100644 --- a/openmp/libomptarget/deviceRTLs/amdgcn/src/target_impl.hip +++ b/openmp/libomptarget/deviceRTLs/amdgcn/src/target_impl.hip @@ -9,6 +9,7 @@ // Definitions of target specific functions // //===----------------------------------------------------------------------===// +#pragma omp declare target #include "target_impl.h" @@ -151,3 +152,5 @@ EXTERN uint32_t __kmpc_amdgcn_gpu_num_threads() { // Stub implementations DEVICE void *__kmpc_impl_malloc(size_t) { return nullptr; } DEVICE void __kmpc_impl_free(void *) {} + +#pragma omp end declare target diff --git a/openmp/libomptarget/deviceRTLs/common/src/cancel.cu b/openmp/libomptarget/deviceRTLs/common/src/cancel.cu index 9540f5647699..0e5cd2b60554 100644 --- a/openmp/libomptarget/deviceRTLs/common/src/cancel.cu +++ b/openmp/libomptarget/deviceRTLs/common/src/cancel.cu @@ -9,6 +9,7 @@ // Interface to be used in the implementation of OpenMP cancel. // //===----------------------------------------------------------------------===// +#pragma omp declare target #include "interface.h" #include "common/debug.h" @@ -26,3 +27,5 @@ EXTERN int32_t __kmpc_cancel(kmp_Ident *loc, int32_t global_tid, // disabled return 0; } + +#pragma omp end declare target diff --git a/openmp/libomptarget/deviceRTLs/common/src/critical.cu b/openmp/libomptarget/deviceRTLs/common/src/critical.cu index ee4b056ddad9..3fd89c50aa46 100644 --- a/openmp/libomptarget/deviceRTLs/common/src/critical.cu +++ b/openmp/libomptarget/deviceRTLs/common/src/critical.cu @@ -9,6 +9,7 @@ // This file contains the implementation of critical with KMPC interface // //===----------------------------------------------------------------------===// +#pragma omp declare target #include "interface.h" #include "common/debug.h" @@ -26,3 +27,5 @@ void __kmpc_end_critical(kmp_Ident *loc, int32_t global_tid, PRINT0(LD_IO, "call to kmpc_end_critical()\n"); omp_unset_lock((omp_lock_t *)lck); } + +#pragma omp end declare target diff --git a/openmp/libomptarget/deviceRTLs/common/src/data_sharing.cu b/openmp/libomptarget/deviceRTLs/common/src/data_sharing.cu index 9b116aba2fc3..577c50a8bb84 100644 --- a/openmp/libomptarget/deviceRTLs/common/src/data_sharing.cu +++ b/openmp/libomptarget/deviceRTLs/common/src/data_sharing.cu @@ -9,6 +9,8 @@ // This file contains the implementation of data sharing environments // //===----------------------------------------------------------------------===// +#pragma omp declare target + #include "common/omptarget.h" #include "target_impl.h" @@ -275,3 +277,4 @@ EXTERN void __kmpc_restore_team_static_memory(int16_t isSPMDExecutionMode, omptarget_nvptx_simpleMemoryManager.Release(); } +#pragma omp end declare target diff --git a/openmp/libomptarget/deviceRTLs/common/src/libcall.cu b/openmp/libomptarget/deviceRTLs/common/src/libcall.cu index cfa438ff1717..69b27f11a8d4 100644 --- a/openmp/libomptarget/deviceRTLs/common/src/libcall.cu +++ b/openmp/libomptarget/deviceRTLs/common/src/libcall.cu @@ -10,6 +10,7 @@ // invoked by the user in an OpenMP region // //===----------------------------------------------------------------------===// +#pragma omp declare target #include "common/omptarget.h" #include "common/target_atomic.h" @@ -362,3 +363,5 @@ EXTERN int omp_test_lock(omp_lock_t *lock) { PRINT(LD_IO, "call omp_test_lock() return %d\n", rc); return rc; } + +#pragma omp end declare target diff --git a/openmp/libomptarget/deviceRTLs/common/src/loop.cu b/openmp/libomptarget/deviceRTLs/common/src/loop.cu index f625d9ea9e23..dfe6c7fd5af7 100644 --- a/openmp/libomptarget/deviceRTLs/common/src/loop.cu +++ b/openmp/libomptarget/deviceRTLs/common/src/loop.cu @@ -11,6 +11,7 @@ // interface as loops. // //===----------------------------------------------------------------------===// +#pragma omp declare target #include "common/omptarget.h" #include "target_impl.h" @@ -754,3 +755,5 @@ void __kmpc_for_static_init_8u_simple_generic( EXTERN void __kmpc_for_static_fini(kmp_Ident *loc, int32_t global_tid) { PRINT0(LD_IO, "call kmpc_for_static_fini\n"); } + +#pragma omp end declare target diff --git a/openmp/libomptarget/deviceRTLs/common/src/omp_data.cu b/openmp/libomptarget/deviceRTLs/common/src/omp_data.cu index 5bef3b89a172..b69affdc274a 100644 --- a/openmp/libomptarget/deviceRTLs/common/src/omp_data.cu +++ b/openmp/libomptarget/deviceRTLs/common/src/omp_data.cu @@ -9,6 +9,7 @@ // This file contains the data objects used on the GPU device. // //===----------------------------------------------------------------------===// +#pragma omp declare target #include "common/omptarget.h" #include "common/device_environment.h" @@ -66,3 +67,5 @@ DEVICE SHARED void *ReductionScratchpadPtr; // Data sharing related variables. //////////////////////////////////////////////////////////////////////////////// DEVICE SHARED omptarget_nvptx_SharedArgs omptarget_nvptx_globalArgs; + +#pragma omp end declare target diff --git a/openmp/libomptarget/deviceRTLs/common/src/omptarget.cu b/openmp/libomptarget/deviceRTLs/common/src/omptarget.cu index d9ee95e4f423..82d1db1dce3e 100644 --- a/openmp/libomptarget/deviceRTLs/common/src/omptarget.cu +++ b/openmp/libomptarget/deviceRTLs/common/src/omptarget.cu @@ -9,6 +9,7 @@ // This file contains the initialization code for the GPU // //===----------------------------------------------------------------------===// +#pragma omp declare target #include "common/omptarget.h" #include "target_impl.h" @@ -157,3 +158,5 @@ EXTERN int8_t __kmpc_is_spmd_exec_mode() { PRINT0(LD_IO | LD_PAR, "call to __kmpc_is_spmd_exec_mode\n"); return isSPMDMode(); } + +#pragma omp end declare target diff --git a/openmp/libomptarget/deviceRTLs/common/src/parallel.cu b/openmp/libomptarget/deviceRTLs/common/src/parallel.cu index 20b03e9bab1b..790730ffdec9 100644 --- a/openmp/libomptarget/deviceRTLs/common/src/parallel.cu +++ b/openmp/libomptarget/deviceRTLs/common/src/parallel.cu @@ -31,6 +31,7 @@ // To make a long story short... // //===----------------------------------------------------------------------===// +#pragma omp declare target #include "common/omptarget.h" #include "target_impl.h" @@ -300,3 +301,5 @@ EXTERN void __kmpc_push_proc_bind(kmp_Ident *loc, uint32_t tid, int proc_bind) { PRINT(LD_IO, "call kmpc_push_proc_bind %d\n", (int)proc_bind); } + +#pragma omp end declare target diff --git a/openmp/libomptarget/deviceRTLs/common/src/reduction.cu b/openmp/libomptarget/deviceRTLs/common/src/reduction.cu index 7604f024eeb4..92b34d77bd8a 100644 --- a/openmp/libomptarget/deviceRTLs/common/src/reduction.cu +++ b/openmp/libomptarget/deviceRTLs/common/src/reduction.cu @@ -9,6 +9,7 @@ // This file contains the implementation of reduction with KMPC interface. // //===----------------------------------------------------------------------===// +#pragma omp declare target #include "common/omptarget.h" #include "common/target_atomic.h" @@ -312,3 +313,4 @@ EXTERN int32_t __kmpc_nvptx_teams_reduce_nowait_v2( return 0; } +#pragma omp end declare target diff --git a/openmp/libomptarget/deviceRTLs/common/src/support.cu b/openmp/libomptarget/deviceRTLs/common/src/support.cu index e02c533e78b2..f9b4ad300053 100644 --- a/openmp/libomptarget/deviceRTLs/common/src/support.cu +++ b/openmp/libomptarget/deviceRTLs/common/src/support.cu @@ -9,6 +9,7 @@ // Wrapper implementation to some functions natively supported by the GPU. // //===----------------------------------------------------------------------===// +#pragma omp declare target #include "common/support.h" #include "common/debug.h" @@ -264,3 +265,4 @@ DEVICE char *GetTeamsReductionScratchpad() { return static_cast(ReductionScratchpadPtr) + 256; } +#pragma omp end declare target diff --git a/openmp/libomptarget/deviceRTLs/common/src/sync.cu b/openmp/libomptarget/deviceRTLs/common/src/sync.cu index 824094cc3f78..0a00f2fa08b8 100644 --- a/openmp/libomptarget/deviceRTLs/common/src/sync.cu +++ b/openmp/libomptarget/deviceRTLs/common/src/sync.cu @@ -9,6 +9,7 @@ // Include all synchronization. // //===----------------------------------------------------------------------===// +#pragma omp declare target #include "common/omptarget.h" #include "target_impl.h" @@ -135,3 +136,5 @@ EXTERN void __kmpc_syncwarp(__kmpc_impl_lanemask_t Mask) { PRINT0(LD_IO, "call __kmpc_syncwarp\n"); __kmpc_impl_syncwarp(Mask); } + +#pragma omp end declare target diff --git a/openmp/libomptarget/deviceRTLs/common/src/task.cu b/openmp/libomptarget/deviceRTLs/common/src/task.cu index 5e5bc350d277..f28cd2b81c69 100644 --- a/openmp/libomptarget/deviceRTLs/common/src/task.cu +++ b/openmp/libomptarget/deviceRTLs/common/src/task.cu @@ -26,6 +26,7 @@ // - end // //===----------------------------------------------------------------------===// +#pragma omp declare target #include "common/omptarget.h" @@ -214,3 +215,5 @@ EXTERN void __kmpc_taskloop(kmp_Ident *loc, uint32_t global_tid, __kmpc_omp_task_with_deps(loc, global_tid, newKmpTaskDescr, 0, 0, 0, 0); } + +#pragma omp end declare target diff --git a/openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.cu b/openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.cu index b68d3265a758..8052b92a7dee 100644 --- a/openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.cu +++ b/openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.cu @@ -9,6 +9,7 @@ // Definitions of target specific functions // //===----------------------------------------------------------------------===// +#pragma omp declare target #include "target_impl.h" #include "common/debug.h" @@ -158,3 +159,5 @@ DEVICE int __kmpc_impl_test_lock(omp_lock_t *lock) { DEVICE void *__kmpc_impl_malloc(size_t x) { return malloc(x); } DEVICE void __kmpc_impl_free(void *x) { free(x); } + +#pragma omp end declare target