Skip to content

Commit 2e7f47d

Browse files
authored
[OpenMP][NFC] Move out plugin API and APITypes into standalone headers (#73868)
1 parent a0bd636 commit 2e7f47d

File tree

7 files changed

+108
-78
lines changed

7 files changed

+108
-78
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
//===-- Shared/APITypes.h - Offload and plugin API types --------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file defines types used in the interface between the user code, the
10+
// target independent offload runtime library, and target dependent plugins.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
#ifndef OMPTARGET_SHARED_API_TYPES_H
15+
#define OMPTARGET_SHARED_API_TYPES_H
16+
17+
#include "Environment.h"
18+
19+
#include "llvm/ADT/SmallVector.h"
20+
21+
#include <cstddef>
22+
#include <cstdint>
23+
24+
extern "C" {
25+
26+
/// This struct is a record of an entry point or global. For a function
27+
/// entry point the size is expected to be zero
28+
struct __tgt_offload_entry {
29+
void *addr; // Pointer to the offload entry info (function or global)
30+
char *name; // Name of the function or global
31+
size_t size; // Size of the entry info (0 if it is a function)
32+
int32_t flags; // Flags associated with the entry, e.g. 'link'.
33+
int32_t reserved; // Reserved, to be used by the runtime library.
34+
};
35+
36+
/// This struct is a record of the device image information
37+
struct __tgt_device_image {
38+
void *ImageStart; // Pointer to the target code start
39+
void *ImageEnd; // Pointer to the target code end
40+
__tgt_offload_entry *EntriesBegin; // Begin of table with all target entries
41+
__tgt_offload_entry *EntriesEnd; // End of table (non inclusive)
42+
};
43+
44+
struct __tgt_device_info {
45+
void *Context = nullptr;
46+
void *Device = nullptr;
47+
};
48+
49+
/// This struct contains information about a given image.
50+
struct __tgt_image_info {
51+
const char *Arch;
52+
};
53+
54+
/// This struct is a record of all the host code that may be offloaded to a
55+
/// target.
56+
struct __tgt_bin_desc {
57+
int32_t NumDeviceImages; // Number of device types supported
58+
__tgt_device_image *DeviceImages; // Array of device images (1 per dev. type)
59+
__tgt_offload_entry *HostEntriesBegin; // Begin of table with all host entries
60+
__tgt_offload_entry *HostEntriesEnd; // End of table (non inclusive)
61+
};
62+
63+
/// This struct contains the offload entries identified by the target runtime
64+
struct __tgt_target_table {
65+
__tgt_offload_entry *EntriesBegin; // Begin of the table with all the entries
66+
__tgt_offload_entry
67+
*EntriesEnd; // End of the table with all the entries (non inclusive)
68+
};
69+
70+
// clang-format on
71+
72+
/// This struct contains information exchanged between different asynchronous
73+
/// operations for device-dependent optimization and potential synchronization
74+
struct __tgt_async_info {
75+
// A pointer to a queue-like structure where offloading operations are issued.
76+
// We assume to use this structure to do synchronization. In CUDA backend, it
77+
// is CUstream.
78+
void *Queue = nullptr;
79+
80+
/// A collection of allocations that are associated with this stream and that
81+
/// should be freed after finalization.
82+
llvm::SmallVector<void *, 2> AssociatedAllocations;
83+
84+
/// The kernel launch environment used to issue a kernel. Stored here to
85+
/// ensure it is a valid location while the transfer to the device is
86+
/// happening.
87+
KernelLaunchEnvironmentTy KernelLaunchEnvironment;
88+
};
89+
}
90+
91+
#endif // OMPTARGET_SHARED_API_TYPES_H

openmp/libomptarget/include/omptargetplugin.h renamed to openmp/libomptarget/include/Shared/PluginAPI.h

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===-- omptargetplugin.h - Target dependent OpenMP Plugin API --*- C++ -*-===//
1+
//===-- Shared/PluginAPI.h - Target independent plugin API ------*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -11,14 +11,15 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14-
#ifndef _OMPTARGETPLUGIN_H_
15-
#define _OMPTARGETPLUGIN_H_
14+
#ifndef OMPTARGET_SHARED_PLUGIN_API_H
15+
#define OMPTARGET_SHARED_PLUGIN_API_H
1616

17-
#include <omptarget.h>
17+
#include <cstddef>
18+
#include <cstdint>
19+
20+
#include "Shared/APITypes.h"
1821

19-
#ifdef __cplusplus
2022
extern "C" {
21-
#endif
2223

2324
// First method called on the plugin
2425
int32_t __tgt_rtl_init_plugin();
@@ -214,9 +215,6 @@ int32_t __tgt_rtl_data_notify_unmapped(int32_t ID, void *HstPtr);
214215
// Set the global device identifier offset, such that the plugin may determine a
215216
// unique device number.
216217
int32_t __tgt_rtl_set_device_offset(int32_t DeviceIdOffset);
217-
218-
#ifdef __cplusplus
219218
}
220-
#endif
221219

222-
#endif // _OMPTARGETPLUGIN_H_
220+
#endif // OMPTARGET_SHARED_PLUGIN_API_H

openmp/libomptarget/include/omptarget.h

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#ifndef _OMPTARGET_H_
1515
#define _OMPTARGET_H_
1616

17+
#include "Shared/APITypes.h"
1718
#include "Shared/Environment.h"
1819
#include "Shared/SourceInfo.h"
1920

@@ -147,65 +148,6 @@ inline KernelArgsTy CTorDTorKernelArgs = {1, 0, nullptr, nullptr,
147148
nullptr, nullptr, nullptr, nullptr,
148149
0, {0,0}, {1, 0, 0}, {1, 0, 0}, 0};
149150

150-
/// This struct is a record of an entry point or global. For a function
151-
/// entry point the size is expected to be zero
152-
struct __tgt_offload_entry {
153-
void *addr; // Pointer to the offload entry info (function or global)
154-
char *name; // Name of the function or global
155-
size_t size; // Size of the entry info (0 if it is a function)
156-
int32_t flags; // Flags associated with the entry, e.g. 'link'.
157-
int32_t reserved; // Reserved, to be used by the runtime library.
158-
};
159-
160-
/// This struct is a record of the device image information
161-
struct __tgt_device_image {
162-
void *ImageStart; // Pointer to the target code start
163-
void *ImageEnd; // Pointer to the target code end
164-
__tgt_offload_entry *EntriesBegin; // Begin of table with all target entries
165-
__tgt_offload_entry *EntriesEnd; // End of table (non inclusive)
166-
};
167-
168-
/// This struct contains information about a given image.
169-
struct __tgt_image_info {
170-
const char *Arch;
171-
};
172-
173-
/// This struct is a record of all the host code that may be offloaded to a
174-
/// target.
175-
struct __tgt_bin_desc {
176-
int32_t NumDeviceImages; // Number of device types supported
177-
__tgt_device_image *DeviceImages; // Array of device images (1 per dev. type)
178-
__tgt_offload_entry *HostEntriesBegin; // Begin of table with all host entries
179-
__tgt_offload_entry *HostEntriesEnd; // End of table (non inclusive)
180-
};
181-
182-
/// This struct contains the offload entries identified by the target runtime
183-
struct __tgt_target_table {
184-
__tgt_offload_entry *EntriesBegin; // Begin of the table with all the entries
185-
__tgt_offload_entry
186-
*EntriesEnd; // End of the table with all the entries (non inclusive)
187-
};
188-
189-
// clang-format on
190-
191-
/// This struct contains information exchanged between different asynchronous
192-
/// operations for device-dependent optimization and potential synchronization
193-
struct __tgt_async_info {
194-
// A pointer to a queue-like structure where offloading operations are issued.
195-
// We assume to use this structure to do synchronization. In CUDA backend, it
196-
// is CUstream.
197-
void *Queue = nullptr;
198-
199-
/// A collection of allocations that are associated with this stream and that
200-
/// should be freed after finalization.
201-
llvm::SmallVector<void *, 2> AssociatedAllocations;
202-
203-
/// The kernel launch environment used to issue a kernel. Stored here to
204-
/// ensure it is a valid location while the transfer to the device is
205-
/// happening.
206-
KernelLaunchEnvironmentTy KernelLaunchEnvironment;
207-
};
208-
209151
struct DeviceTy;
210152

211153
/// The libomptarget wrapper around a __tgt_async_info object directly
@@ -366,11 +308,6 @@ struct __tgt_target_non_contig {
366308
uint64_t Stride;
367309
};
368310

369-
struct __tgt_device_info {
370-
void *Context = nullptr;
371-
void *Device = nullptr;
372-
};
373-
374311
#ifdef __cplusplus
375312
extern "C" {
376313
#endif

openmp/libomptarget/plugins-nextgen/common/src/PluginInterface.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010

1111
#include "PluginInterface.h"
1212

13+
#include "Shared/APITypes.h"
1314
#include "Shared/Debug.h"
1415
#include "Shared/Environment.h"
16+
#include "Shared/PluginAPI.h"
1517

1618
#include "GlobalHandler.h"
1719
#include "JIT.h"
1820
#include "Utils/ELF.h"
1921
#include "omptarget.h"
20-
#include "omptargetplugin.h"
2122

2223
#ifdef OMPT_SUPPORT
2324
#include "OpenMP/OMPT/Callback.h"

openmp/libomptarget/plugins-nextgen/common/src/Utils/ELF.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "ELF.h"
1414

15+
#include "Shared/APITypes.h"
1516
#include "Shared/Debug.h"
1617

1718
#include "llvm/BinaryFormat/Magic.h"

openmp/libomptarget/plugins-nextgen/common/src/Utils/ELF.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#ifndef LLVM_OPENMP_LIBOMPTARGET_PLUGINS_ELF_UTILS_H
1414
#define LLVM_OPENMP_LIBOMPTARGET_PLUGINS_ELF_UTILS_H
1515

16-
#include "omptargetplugin.h"
16+
#include "Shared/PluginAPI.h"
1717

1818
#include "llvm/Object/ELF.h"
1919
#include "llvm/Object/ELFObjectFile.h"
@@ -23,7 +23,7 @@ namespace elf {
2323

2424
/// Return non-zero, if the given \p image is an ELF object, which
2525
/// e_machine matches \p target_id; return zero otherwise.
26-
EXTERN int32_t checkMachine(__tgt_device_image *Image, uint16_t TargetId);
26+
int32_t checkMachine(__tgt_device_image *Image, uint16_t TargetId);
2727

2828
/// Returns the symbol associated with the \p Name in the \p ELFObj. It will
2929
/// first search for the hash sections to identify symbols from the hash table.

openmp/libomptarget/tools/kernelreplay/llvm-omp-kernel-replay.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
//===----------------------------------------------------------------------===//
1313

1414
#include "omptarget.h"
15-
#include "omptargetplugin.h"
15+
16+
#include "Shared/PluginAPI.h"
17+
1618
#include "llvm/Support/CommandLine.h"
1719
#include "llvm/Support/JSON.h"
1820
#include "llvm/Support/MemoryBuffer.h"

0 commit comments

Comments
 (0)