diff --git a/openmp/libomptarget/include/Shared/APITypes.h b/openmp/libomptarget/include/Shared/APITypes.h new file mode 100644 index 0000000000000..fc494cd5f5865 --- /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 +#include + +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 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 similarity index 97% rename from openmp/libomptarget/include/omptargetplugin.h rename to openmp/libomptarget/include/Shared/PluginAPI.h index 8bdb39de9da9e..94beab2dcea19 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 +#include +#include + +#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 34cee21f16078..45fb40c397afe 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 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 2ba9aca9e141a..c580817987a50 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 7089e26754aa5..0643d004df17e 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 6b1ce434f0c4e..b3740a104d613 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 5041173d21eba..fc3ff078a81fb 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"