diff options
author | Johannes Doerfert <johannes@jdoerfert.de> | 2023-11-29 16:04:19 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-29 16:04:19 -0800 |
commit | 2e7f47d4a8a5206fbc565d3eb8c1595c2cb875f8 (patch) | |
tree | cd4c9466f9422f28e2eb8ce98c25a5578bd91b2d /openmp | |
parent | a0bd6361d4840f159e48c7359807ae279d006fb0 (diff) | |
download | llvm-2e7f47d4a8a5206fbc565d3eb8c1595c2cb875f8.zip llvm-2e7f47d4a8a5206fbc565d3eb8c1595c2cb875f8.tar.gz llvm-2e7f47d4a8a5206fbc565d3eb8c1595c2cb875f8.tar.bz2 |
[OpenMP][NFC] Move out plugin API and APITypes into standalone headers (#73868)
Diffstat (limited to 'openmp')
-rw-r--r-- | openmp/libomptarget/include/Shared/APITypes.h | 91 | ||||
-rw-r--r-- | openmp/libomptarget/include/Shared/PluginAPI.h (renamed from openmp/libomptarget/include/omptargetplugin.h) | 18 | ||||
-rw-r--r-- | openmp/libomptarget/include/omptarget.h | 65 | ||||
-rw-r--r-- | openmp/libomptarget/plugins-nextgen/common/src/PluginInterface.cpp | 3 | ||||
-rw-r--r-- | openmp/libomptarget/plugins-nextgen/common/src/Utils/ELF.cpp | 1 | ||||
-rw-r--r-- | openmp/libomptarget/plugins-nextgen/common/src/Utils/ELF.h | 4 | ||||
-rw-r--r-- | openmp/libomptarget/tools/kernelreplay/llvm-omp-kernel-replay.cpp | 4 |
7 files changed, 108 insertions, 78 deletions
diff --git a/openmp/libomptarget/include/Shared/APITypes.h b/openmp/libomptarget/include/Shared/APITypes.h new file mode 100644 index 0000000..fc494cd --- /dev/null +++ b/openmp/libomptarget/include/Shared/APITypes.h @@ -0,0 +1,91 @@ +//===-- Shared/APITypes.h - Offload and plugin API types --------*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// +// +// This file defines types used in the interface between the user code, the +// target independent offload runtime library, and target dependent plugins. +// +//===----------------------------------------------------------------------===// + +#ifndef OMPTARGET_SHARED_API_TYPES_H +#define OMPTARGET_SHARED_API_TYPES_H + +#include "Environment.h" + +#include "llvm/ADT/SmallVector.h" + +#include <cstddef> +#include <cstdint> + +extern "C" { + +/// This struct is a record of an entry point or global. For a function +/// entry point the size is expected to be zero +struct __tgt_offload_entry { + void *addr; // Pointer to the offload entry info (function or global) + char *name; // Name of the function or global + size_t size; // Size of the entry info (0 if it is a function) + int32_t flags; // Flags associated with the entry, e.g. 'link'. + int32_t reserved; // Reserved, to be used by the runtime library. +}; + +/// This struct is a record of the device image information +struct __tgt_device_image { + void *ImageStart; // Pointer to the target code start + void *ImageEnd; // Pointer to the target code end + __tgt_offload_entry *EntriesBegin; // Begin of table with all target entries + __tgt_offload_entry *EntriesEnd; // End of table (non inclusive) +}; + +struct __tgt_device_info { + void *Context = nullptr; + void *Device = nullptr; +}; + +/// This struct contains information about a given image. +struct __tgt_image_info { + const char *Arch; +}; + +/// This struct is a record of all the host code that may be offloaded to a +/// target. +struct __tgt_bin_desc { + int32_t NumDeviceImages; // Number of device types supported + __tgt_device_image *DeviceImages; // Array of device images (1 per dev. type) + __tgt_offload_entry *HostEntriesBegin; // Begin of table with all host entries + __tgt_offload_entry *HostEntriesEnd; // End of table (non inclusive) +}; + +/// This struct contains the offload entries identified by the target runtime +struct __tgt_target_table { + __tgt_offload_entry *EntriesBegin; // Begin of the table with all the entries + __tgt_offload_entry + *EntriesEnd; // End of the table with all the entries (non inclusive) +}; + +// clang-format on + +/// This struct contains information exchanged between different asynchronous +/// operations for device-dependent optimization and potential synchronization +struct __tgt_async_info { + // A pointer to a queue-like structure where offloading operations are issued. + // We assume to use this structure to do synchronization. In CUDA backend, it + // is CUstream. + void *Queue = nullptr; + + /// A collection of allocations that are associated with this stream and that + /// should be freed after finalization. + llvm::SmallVector<void *, 2> AssociatedAllocations; + + /// The kernel launch environment used to issue a kernel. Stored here to + /// ensure it is a valid location while the transfer to the device is + /// happening. + KernelLaunchEnvironmentTy KernelLaunchEnvironment; +}; +} + +#endif // OMPTARGET_SHARED_API_TYPES_H diff --git a/openmp/libomptarget/include/omptargetplugin.h b/openmp/libomptarget/include/Shared/PluginAPI.h index 8bdb39d..94beab2 100644 --- a/openmp/libomptarget/include/omptargetplugin.h +++ b/openmp/libomptarget/include/Shared/PluginAPI.h @@ -1,4 +1,4 @@ -//===-- omptargetplugin.h - Target dependent OpenMP Plugin API --*- C++ -*-===// +//===-- Shared/PluginAPI.h - Target independent plugin API ------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -11,14 +11,15 @@ // //===----------------------------------------------------------------------===// -#ifndef _OMPTARGETPLUGIN_H_ -#define _OMPTARGETPLUGIN_H_ +#ifndef OMPTARGET_SHARED_PLUGIN_API_H +#define OMPTARGET_SHARED_PLUGIN_API_H -#include <omptarget.h> +#include <cstddef> +#include <cstdint> + +#include "Shared/APITypes.h" -#ifdef __cplusplus extern "C" { -#endif // First method called on the plugin int32_t __tgt_rtl_init_plugin(); @@ -214,9 +215,6 @@ int32_t __tgt_rtl_data_notify_unmapped(int32_t ID, void *HstPtr); // Set the global device identifier offset, such that the plugin may determine a // unique device number. int32_t __tgt_rtl_set_device_offset(int32_t DeviceIdOffset); - -#ifdef __cplusplus } -#endif -#endif // _OMPTARGETPLUGIN_H_ +#endif // OMPTARGET_SHARED_PLUGIN_API_H diff --git a/openmp/libomptarget/include/omptarget.h b/openmp/libomptarget/include/omptarget.h index 34cee21..45fb40c 100644 --- a/openmp/libomptarget/include/omptarget.h +++ b/openmp/libomptarget/include/omptarget.h @@ -14,6 +14,7 @@ #ifndef _OMPTARGET_H_ #define _OMPTARGET_H_ +#include "Shared/APITypes.h" #include "Shared/Environment.h" #include "Shared/SourceInfo.h" @@ -147,65 +148,6 @@ inline KernelArgsTy CTorDTorKernelArgs = {1, 0, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, 0, {0,0}, {1, 0, 0}, {1, 0, 0}, 0}; -/// This struct is a record of an entry point or global. For a function -/// entry point the size is expected to be zero -struct __tgt_offload_entry { - void *addr; // Pointer to the offload entry info (function or global) - char *name; // Name of the function or global - size_t size; // Size of the entry info (0 if it is a function) - int32_t flags; // Flags associated with the entry, e.g. 'link'. - int32_t reserved; // Reserved, to be used by the runtime library. -}; - -/// This struct is a record of the device image information -struct __tgt_device_image { - void *ImageStart; // Pointer to the target code start - void *ImageEnd; // Pointer to the target code end - __tgt_offload_entry *EntriesBegin; // Begin of table with all target entries - __tgt_offload_entry *EntriesEnd; // End of table (non inclusive) -}; - -/// This struct contains information about a given image. -struct __tgt_image_info { - const char *Arch; -}; - -/// This struct is a record of all the host code that may be offloaded to a -/// target. -struct __tgt_bin_desc { - int32_t NumDeviceImages; // Number of device types supported - __tgt_device_image *DeviceImages; // Array of device images (1 per dev. type) - __tgt_offload_entry *HostEntriesBegin; // Begin of table with all host entries - __tgt_offload_entry *HostEntriesEnd; // End of table (non inclusive) -}; - -/// This struct contains the offload entries identified by the target runtime -struct __tgt_target_table { - __tgt_offload_entry *EntriesBegin; // Begin of the table with all the entries - __tgt_offload_entry - *EntriesEnd; // End of the table with all the entries (non inclusive) -}; - -// clang-format on - -/// This struct contains information exchanged between different asynchronous -/// operations for device-dependent optimization and potential synchronization -struct __tgt_async_info { - // A pointer to a queue-like structure where offloading operations are issued. - // We assume to use this structure to do synchronization. In CUDA backend, it - // is CUstream. - void *Queue = nullptr; - - /// A collection of allocations that are associated with this stream and that - /// should be freed after finalization. - llvm::SmallVector<void *, 2> AssociatedAllocations; - - /// The kernel launch environment used to issue a kernel. Stored here to - /// ensure it is a valid location while the transfer to the device is - /// happening. - KernelLaunchEnvironmentTy KernelLaunchEnvironment; -}; - struct DeviceTy; /// The libomptarget wrapper around a __tgt_async_info object directly @@ -366,11 +308,6 @@ struct __tgt_target_non_contig { uint64_t Stride; }; -struct __tgt_device_info { - void *Context = nullptr; - void *Device = nullptr; -}; - #ifdef __cplusplus extern "C" { #endif diff --git a/openmp/libomptarget/plugins-nextgen/common/src/PluginInterface.cpp b/openmp/libomptarget/plugins-nextgen/common/src/PluginInterface.cpp index 2ba9aca..c580817 100644 --- a/openmp/libomptarget/plugins-nextgen/common/src/PluginInterface.cpp +++ b/openmp/libomptarget/plugins-nextgen/common/src/PluginInterface.cpp @@ -10,14 +10,15 @@ #include "PluginInterface.h" +#include "Shared/APITypes.h" #include "Shared/Debug.h" #include "Shared/Environment.h" +#include "Shared/PluginAPI.h" #include "GlobalHandler.h" #include "JIT.h" #include "Utils/ELF.h" #include "omptarget.h" -#include "omptargetplugin.h" #ifdef OMPT_SUPPORT #include "OpenMP/OMPT/Callback.h" diff --git a/openmp/libomptarget/plugins-nextgen/common/src/Utils/ELF.cpp b/openmp/libomptarget/plugins-nextgen/common/src/Utils/ELF.cpp index 7089e26..0643d00 100644 --- a/openmp/libomptarget/plugins-nextgen/common/src/Utils/ELF.cpp +++ b/openmp/libomptarget/plugins-nextgen/common/src/Utils/ELF.cpp @@ -12,6 +12,7 @@ #include "ELF.h" +#include "Shared/APITypes.h" #include "Shared/Debug.h" #include "llvm/BinaryFormat/Magic.h" diff --git a/openmp/libomptarget/plugins-nextgen/common/src/Utils/ELF.h b/openmp/libomptarget/plugins-nextgen/common/src/Utils/ELF.h index 6b1ce43..b3740a1 100644 --- a/openmp/libomptarget/plugins-nextgen/common/src/Utils/ELF.h +++ b/openmp/libomptarget/plugins-nextgen/common/src/Utils/ELF.h @@ -13,7 +13,7 @@ #ifndef LLVM_OPENMP_LIBOMPTARGET_PLUGINS_ELF_UTILS_H #define LLVM_OPENMP_LIBOMPTARGET_PLUGINS_ELF_UTILS_H -#include "omptargetplugin.h" +#include "Shared/PluginAPI.h" #include "llvm/Object/ELF.h" #include "llvm/Object/ELFObjectFile.h" @@ -23,7 +23,7 @@ namespace elf { /// Return non-zero, if the given \p image is an ELF object, which /// e_machine matches \p target_id; return zero otherwise. -EXTERN int32_t checkMachine(__tgt_device_image *Image, uint16_t TargetId); +int32_t checkMachine(__tgt_device_image *Image, uint16_t TargetId); /// Returns the symbol associated with the \p Name in the \p ELFObj. It will /// first search for the hash sections to identify symbols from the hash table. diff --git a/openmp/libomptarget/tools/kernelreplay/llvm-omp-kernel-replay.cpp b/openmp/libomptarget/tools/kernelreplay/llvm-omp-kernel-replay.cpp index 5041173..fc3ff07 100644 --- a/openmp/libomptarget/tools/kernelreplay/llvm-omp-kernel-replay.cpp +++ b/openmp/libomptarget/tools/kernelreplay/llvm-omp-kernel-replay.cpp @@ -12,7 +12,9 @@ //===----------------------------------------------------------------------===// #include "omptarget.h" -#include "omptargetplugin.h" + +#include "Shared/PluginAPI.h" + #include "llvm/Support/CommandLine.h" #include "llvm/Support/JSON.h" #include "llvm/Support/MemoryBuffer.h" |