[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

GitOrigin-RevId: e069662deb1fa167b3e5fdce4c9949e663df8082
diff --git a/libomptarget/deviceRTLs/amdgcn/src/amdgcn_locks.hip b/libomptarget/deviceRTLs/amdgcn/src/amdgcn_locks.hip
index 4163a14..f537fb2 100644
--- a/libomptarget/deviceRTLs/amdgcn/src/amdgcn_locks.hip
+++ b/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_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/libomptarget/deviceRTLs/amdgcn/src/amdgcn_smid.hip b/libomptarget/deviceRTLs/amdgcn/src/amdgcn_smid.hip
index 74d0d16..c850455 100644
--- a/libomptarget/deviceRTLs/amdgcn/src/amdgcn_smid.hip
+++ b/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 @@
       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/libomptarget/deviceRTLs/amdgcn/src/target_impl.hip b/libomptarget/deviceRTLs/amdgcn/src/target_impl.hip
index 3e70beb..7388a29 100644
--- a/libomptarget/deviceRTLs/amdgcn/src/target_impl.hip
+++ b/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 @@
 // 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/libomptarget/deviceRTLs/common/src/cancel.cu b/libomptarget/deviceRTLs/common/src/cancel.cu
index 9540f56..0e5cd2b 100644
--- a/libomptarget/deviceRTLs/common/src/cancel.cu
+++ b/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 @@
   // disabled
   return 0;
 }
+
+#pragma omp end declare target
diff --git a/libomptarget/deviceRTLs/common/src/critical.cu b/libomptarget/deviceRTLs/common/src/critical.cu
index ee4b056..3fd89c5 100644
--- a/libomptarget/deviceRTLs/common/src/critical.cu
+++ b/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 @@
   PRINT0(LD_IO, "call to kmpc_end_critical()\n");
   omp_unset_lock((omp_lock_t *)lck);
 }
+
+#pragma omp end declare target
diff --git a/libomptarget/deviceRTLs/common/src/data_sharing.cu b/libomptarget/deviceRTLs/common/src/data_sharing.cu
index 9b116ab..577c50a 100644
--- a/libomptarget/deviceRTLs/common/src/data_sharing.cu
+++ b/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 @@
   omptarget_nvptx_simpleMemoryManager.Release();
 }
 
+#pragma omp end declare target
diff --git a/libomptarget/deviceRTLs/common/src/libcall.cu b/libomptarget/deviceRTLs/common/src/libcall.cu
index cfa438f..69b27f1 100644
--- a/libomptarget/deviceRTLs/common/src/libcall.cu
+++ b/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 @@
   PRINT(LD_IO, "call omp_test_lock() return %d\n", rc);
   return rc;
 }
+
+#pragma omp end declare target
diff --git a/libomptarget/deviceRTLs/common/src/loop.cu b/libomptarget/deviceRTLs/common/src/loop.cu
index f625d9e..dfe6c7f 100644
--- a/libomptarget/deviceRTLs/common/src/loop.cu
+++ b/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 @@
 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/libomptarget/deviceRTLs/common/src/omp_data.cu b/libomptarget/deviceRTLs/common/src/omp_data.cu
index 5bef3b8..b69affd 100644
--- a/libomptarget/deviceRTLs/common/src/omp_data.cu
+++ b/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 @@
 // Data sharing related variables.
 ////////////////////////////////////////////////////////////////////////////////
 DEVICE SHARED omptarget_nvptx_SharedArgs omptarget_nvptx_globalArgs;
+
+#pragma omp end declare target
diff --git a/libomptarget/deviceRTLs/common/src/omptarget.cu b/libomptarget/deviceRTLs/common/src/omptarget.cu
index d9ee95e..82d1db1 100644
--- a/libomptarget/deviceRTLs/common/src/omptarget.cu
+++ b/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 @@
   PRINT0(LD_IO | LD_PAR, "call to __kmpc_is_spmd_exec_mode\n");
   return isSPMDMode();
 }
+
+#pragma omp end declare target
diff --git a/libomptarget/deviceRTLs/common/src/parallel.cu b/libomptarget/deviceRTLs/common/src/parallel.cu
index 20b03e9..790730f 100644
--- a/libomptarget/deviceRTLs/common/src/parallel.cu
+++ b/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 @@
                                   int proc_bind) {
   PRINT(LD_IO, "call kmpc_push_proc_bind %d\n", (int)proc_bind);
 }
+
+#pragma omp end declare target
diff --git a/libomptarget/deviceRTLs/common/src/reduction.cu b/libomptarget/deviceRTLs/common/src/reduction.cu
index 7604f02..92b34d7 100644
--- a/libomptarget/deviceRTLs/common/src/reduction.cu
+++ b/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 @@
   return 0;
 }
 
+#pragma omp end declare target
diff --git a/libomptarget/deviceRTLs/common/src/support.cu b/libomptarget/deviceRTLs/common/src/support.cu
index e02c533..f9b4ad3 100644
--- a/libomptarget/deviceRTLs/common/src/support.cu
+++ b/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 @@
   return static_cast<char *>(ReductionScratchpadPtr) + 256;
 }
 
+#pragma omp end declare target
diff --git a/libomptarget/deviceRTLs/common/src/sync.cu b/libomptarget/deviceRTLs/common/src/sync.cu
index 824094c..0a00f2f 100644
--- a/libomptarget/deviceRTLs/common/src/sync.cu
+++ b/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 @@
   PRINT0(LD_IO, "call __kmpc_syncwarp\n");
   __kmpc_impl_syncwarp(Mask);
 }
+
+#pragma omp end declare target
diff --git a/libomptarget/deviceRTLs/common/src/task.cu b/libomptarget/deviceRTLs/common/src/task.cu
index 5e5bc35..f28cd2b 100644
--- a/libomptarget/deviceRTLs/common/src/task.cu
+++ b/libomptarget/deviceRTLs/common/src/task.cu
@@ -26,6 +26,7 @@
 //    - end
 //
 //===----------------------------------------------------------------------===//
+#pragma omp declare target
 
 #include "common/omptarget.h"
 
@@ -214,3 +215,5 @@
 
   __kmpc_omp_task_with_deps(loc, global_tid, newKmpTaskDescr, 0, 0, 0, 0);
 }
+
+#pragma omp end declare target
diff --git a/libomptarget/deviceRTLs/nvptx/src/target_impl.cu b/libomptarget/deviceRTLs/nvptx/src/target_impl.cu
index b68d326..8052b92 100644
--- a/libomptarget/deviceRTLs/nvptx/src/target_impl.cu
+++ b/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 void *__kmpc_impl_malloc(size_t x) { return malloc(x); }
 DEVICE void __kmpc_impl_free(void *x) { free(x); }
+
+#pragma omp end declare target