[Openmp-commits] [openmp] cee6918 - [OpenMP][NFC] Move api.cpp to OpenMP/API.cpp

Johannes Doerfert via Openmp-commits openmp-commits at lists.llvm.org
Mon Dec 11 17:30:59 PST 2023


Author: Johannes Doerfert
Date: 2023-12-11T17:30:34-08:00
New Revision: cee6918d876cb1650c4fd232e8da0e726061653c

URL: https://github.com/llvm/llvm-project/commit/cee6918d876cb1650c4fd232e8da0e726061653c
DIFF: https://github.com/llvm/llvm-project/commit/cee6918d876cb1650c4fd232e8da0e726061653c.diff

LOG: [OpenMP][NFC] Move api.cpp to OpenMP/API.cpp

Added: 
    openmp/libomptarget/src/OpenMP/API.cpp

Modified: 
    openmp/libomptarget/include/OpenMP/InternalTypes.h
    openmp/libomptarget/src/CMakeLists.txt
    openmp/libomptarget/src/private.h

Removed: 
    openmp/libomptarget/src/api.cpp


################################################################################
diff  --git a/openmp/libomptarget/include/OpenMP/InternalTypes.h b/openmp/libomptarget/include/OpenMP/InternalTypes.h
index fd5836e973aedf..bd84c38fb20115 100644
--- a/openmp/libomptarget/include/OpenMP/InternalTypes.h
+++ b/openmp/libomptarget/include/OpenMP/InternalTypes.h
@@ -75,6 +75,78 @@ bool __kmpc_omp_has_task_team(int32_t gtid) __attribute__((weak));
 void **__kmpc_omp_get_target_async_handle_ptr(int32_t gtid)
     __attribute__((weak));
 
+/**
+ * The argument set that is passed from asynchronous memory copy to block
+ * version of memory copy invoked in helper task
+ */
+struct TargetMemcpyArgsTy {
+  /**
+   * Common attribuutes
+   */
+  void *Dst;
+  const void *Src;
+  int DstDevice;
+  int SrcDevice;
+
+  /**
+   * The flag that denotes single dimensional or rectangle dimensional copy
+   */
+  bool IsRectMemcpy;
+
+  /**
+   * Arguments for single dimensional copy
+   */
+  size_t Length;
+  size_t DstOffset;
+  size_t SrcOffset;
+
+  /**
+   * Arguments for rectangle dimensional copy
+   */
+  size_t ElementSize;
+  int NumDims;
+  const size_t *Volume;
+  const size_t *DstOffsets;
+  const size_t *SrcOffsets;
+  const size_t *DstDimensions;
+  const size_t *SrcDimensions;
+
+  /**
+   * Constructor for single dimensional copy
+   */
+  TargetMemcpyArgsTy(void *Dst, const void *Src, size_t Length,
+                     size_t DstOffset, size_t SrcOffset, int DstDevice,
+                     int SrcDevice)
+      : Dst(Dst), Src(Src), DstDevice(DstDevice), SrcDevice(SrcDevice),
+        IsRectMemcpy(false), Length(Length), DstOffset(DstOffset),
+        SrcOffset(SrcOffset), ElementSize(0), NumDims(0), Volume(0),
+        DstOffsets(0), SrcOffsets(0), DstDimensions(0), SrcDimensions(0){};
+
+  /**
+   * Constructor for rectangle dimensional copy
+   */
+  TargetMemcpyArgsTy(void *Dst, const void *Src, size_t ElementSize,
+                     int NumDims, const size_t *Volume,
+                     const size_t *DstOffsets, const size_t *SrcOffsets,
+                     const size_t *DstDimensions, const size_t *SrcDimensions,
+                     int DstDevice, int SrcDevice)
+      : Dst(Dst), Src(Src), DstDevice(DstDevice), SrcDevice(SrcDevice),
+        IsRectMemcpy(true), Length(0), DstOffset(0), SrcOffset(0),
+        ElementSize(ElementSize), NumDims(NumDims), Volume(Volume),
+        DstOffsets(DstOffsets), SrcOffsets(SrcOffsets),
+        DstDimensions(DstDimensions), SrcDimensions(SrcDimensions){};
+};
+
+struct TargetMemsetArgsTy {
+  // Common attributes of a memset operation
+  void *Ptr;
+  int C;
+  size_t N;
+  int DeviceNum;
+
+  // no constructors defined, because this is a PoD
+};
+
 } // extern "C"
 
 #endif // OMPTARGET_OPENMP_INTERNAL_TYPES_H

diff  --git a/openmp/libomptarget/src/CMakeLists.txt b/openmp/libomptarget/src/CMakeLists.txt
index 429a670be84957..42674e2d9daa79 100644
--- a/openmp/libomptarget/src/CMakeLists.txt
+++ b/openmp/libomptarget/src/CMakeLists.txt
@@ -15,7 +15,6 @@ libomptarget_say("Building offloading runtime library libomptarget.")
 add_llvm_library(omptarget
   SHARED
 
-  api.cpp
   device.cpp
   interface.cpp
   omptarget.cpp
@@ -24,6 +23,7 @@ add_llvm_library(omptarget
   PluginManager.cpp
   DeviceImage.cpp
 
+  OpenMP/API.cpp
   OpenMP/Mapping.cpp
   OpenMP/InteropAPI.cpp
   OpenMP/OMPT/Callback.cpp

diff  --git a/openmp/libomptarget/src/api.cpp b/openmp/libomptarget/src/OpenMP/API.cpp
similarity index 93%
rename from openmp/libomptarget/src/api.cpp
rename to openmp/libomptarget/src/OpenMP/API.cpp
index 0341e0c7546490..b73315f2b77a3f 100644
--- a/openmp/libomptarget/src/api.cpp
+++ b/openmp/libomptarget/src/OpenMP/API.cpp
@@ -13,9 +13,9 @@
 #include "PluginManager.h"
 #include "device.h"
 #include "omptarget.h"
-#include "private.h"
 #include "rtl.h"
 
+#include "OpenMP/InternalTypes.h"
 #include "OpenMP/omp.h"
 #include "Shared/Profile.h"
 
@@ -26,6 +26,37 @@
 #include <cstring>
 #include <mutex>
 
+void *targetAllocExplicit(size_t Size, int DeviceNum, int Kind,
+                          const char *Name);
+void targetFreeExplicit(void *DevicePtr, int DeviceNum, int Kind,
+                        const char *Name);
+void *targetLockExplicit(void *HostPtr, size_t Size, int DeviceNum,
+                         const char *Name);
+void targetUnlockExplicit(void *HostPtr, int DeviceNum, const char *Name);
+
+// Implemented in libomp, they are called from within __tgt_* functions.
+extern "C" {
+int __kmpc_get_target_offload(void) __attribute__((weak));
+kmp_task_t *__kmpc_omp_task_alloc(ident_t *loc_ref, int32_t gtid, int32_t flags,
+                                  size_t sizeof_kmp_task_t,
+                                  size_t sizeof_shareds,
+                                  kmp_routine_entry_t task_entry)
+    __attribute__((weak));
+
+kmp_task_t *
+__kmpc_omp_target_task_alloc(ident_t *loc_ref, int32_t gtid, int32_t flags,
+                             size_t sizeof_kmp_task_t, size_t sizeof_shareds,
+                             kmp_routine_entry_t task_entry, int64_t device_id)
+    __attribute__((weak));
+
+int32_t __kmpc_omp_task_with_deps(ident_t *loc_ref, int32_t gtid,
+                                  kmp_task_t *new_task, int32_t ndeps,
+                                  kmp_depend_info_t *dep_list,
+                                  int32_t ndeps_noalias,
+                                  kmp_depend_info_t *noalias_dep_list)
+    __attribute__((weak));
+}
+
 EXTERN int omp_get_num_devices(void) {
   TIMESCOPE();
   size_t NumDevices = PM->getNumDevices();

diff  --git a/openmp/libomptarget/src/private.h b/openmp/libomptarget/src/private.h
index 607c2a0dd86a35..d569f2af5433c9 100644
--- a/openmp/libomptarget/src/private.h
+++ b/openmp/libomptarget/src/private.h
@@ -38,115 +38,6 @@ extern int target_replay(ident_t *Loc, DeviceTy &Device, void *HostPtr,
 
 extern void handleTargetOutcome(bool Success, ident_t *Loc);
 extern bool checkDeviceAndCtors(int64_t &DeviceID, ident_t *Loc);
-extern void *targetAllocExplicit(size_t Size, int DeviceNum, int Kind,
-                                 const char *Name);
-extern void targetFreeExplicit(void *DevicePtr, int DeviceNum, int Kind,
-                               const char *Name);
-extern void *targetLockExplicit(void *HostPtr, size_t Size, int DeviceNum,
-                                const char *Name);
-extern void targetUnlockExplicit(void *HostPtr, int DeviceNum,
-                                 const char *Name);
-
-// Implemented in libomp, they are called from within __tgt_* functions.
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int __kmpc_get_target_offload(void) __attribute__((weak));
-kmp_task_t *__kmpc_omp_task_alloc(ident_t *loc_ref, int32_t gtid, int32_t flags,
-                                  size_t sizeof_kmp_task_t,
-                                  size_t sizeof_shareds,
-                                  kmp_routine_entry_t task_entry)
-    __attribute__((weak));
-
-kmp_task_t *
-__kmpc_omp_target_task_alloc(ident_t *loc_ref, int32_t gtid, int32_t flags,
-                             size_t sizeof_kmp_task_t, size_t sizeof_shareds,
-                             kmp_routine_entry_t task_entry, int64_t device_id)
-    __attribute__((weak));
-
-int32_t __kmpc_omp_task_with_deps(ident_t *loc_ref, int32_t gtid,
-                                  kmp_task_t *new_task, int32_t ndeps,
-                                  kmp_depend_info_t *dep_list,
-                                  int32_t ndeps_noalias,
-                                  kmp_depend_info_t *noalias_dep_list)
-    __attribute__((weak));
-
-/**
- * The argument set that is passed from asynchronous memory copy to block
- * version of memory copy invoked in helper task
- */
-struct TargetMemcpyArgsTy {
-  /**
-   * Common attribuutes
-   */
-  void *Dst;
-  const void *Src;
-  int DstDevice;
-  int SrcDevice;
-
-  /**
-   * The flag that denotes single dimensional or rectangle dimensional copy
-   */
-  bool IsRectMemcpy;
-
-  /**
-   * Arguments for single dimensional copy
-   */
-  size_t Length;
-  size_t DstOffset;
-  size_t SrcOffset;
-
-  /**
-   * Arguments for rectangle dimensional copy
-   */
-  size_t ElementSize;
-  int NumDims;
-  const size_t *Volume;
-  const size_t *DstOffsets;
-  const size_t *SrcOffsets;
-  const size_t *DstDimensions;
-  const size_t *SrcDimensions;
-
-  /**
-   * Constructor for single dimensional copy
-   */
-  TargetMemcpyArgsTy(void *Dst, const void *Src, size_t Length,
-                     size_t DstOffset, size_t SrcOffset, int DstDevice,
-                     int SrcDevice)
-      : Dst(Dst), Src(Src), DstDevice(DstDevice), SrcDevice(SrcDevice),
-        IsRectMemcpy(false), Length(Length), DstOffset(DstOffset),
-        SrcOffset(SrcOffset), ElementSize(0), NumDims(0), Volume(0),
-        DstOffsets(0), SrcOffsets(0), DstDimensions(0), SrcDimensions(0){};
-
-  /**
-   * Constructor for rectangle dimensional copy
-   */
-  TargetMemcpyArgsTy(void *Dst, const void *Src, size_t ElementSize,
-                     int NumDims, const size_t *Volume,
-                     const size_t *DstOffsets, const size_t *SrcOffsets,
-                     const size_t *DstDimensions, const size_t *SrcDimensions,
-                     int DstDevice, int SrcDevice)
-      : Dst(Dst), Src(Src), DstDevice(DstDevice), SrcDevice(SrcDevice),
-        IsRectMemcpy(true), Length(0), DstOffset(0), SrcOffset(0),
-        ElementSize(ElementSize), NumDims(NumDims), Volume(Volume),
-        DstOffsets(DstOffsets), SrcOffsets(SrcOffsets),
-        DstDimensions(DstDimensions), SrcDimensions(SrcDimensions){};
-};
-
-struct TargetMemsetArgsTy {
-  // Common attributes of a memset operation
-  void *Ptr;
-  int C;
-  size_t N;
-  int DeviceNum;
-
-  // no constructors defined, because this is a PoD
-};
-
-#ifdef __cplusplus
-}
-#endif
 
 ////////////////////////////////////////////////////////////////////////////////
 /// Print out the names and properties of the arguments to each kernel


        


More information about the Openmp-commits mailing list