Skip to content

Commit 346bd07

Browse files
committed
[OpenMP][NFC] Create an "OpenMP" folder in the include folder
Not everything in libomptarget is "OpenMP", but some things most certainly are. This commit moves some code around to start making this distinction without the intention to change functionality.
1 parent 7233e42 commit 346bd07

File tree

7 files changed

+141
-80
lines changed

7 files changed

+141
-80
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//===-- OpenMP/InternalTypes.h -- Internal OpenMP 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+
// Private type declarations and helper macros for OpenMP.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef OMPTARGET_OPENMP_INTERNAL_TYPES_H
14+
#define OMPTARGET_OPENMP_INTERNAL_TYPES_H
15+
16+
#include <cstddef>
17+
#include <cstdint>
18+
19+
typedef intptr_t kmp_intptr_t;
20+
21+
extern "C" {
22+
23+
// Compiler sends us this info:
24+
typedef struct kmp_depend_info {
25+
kmp_intptr_t base_addr;
26+
size_t len;
27+
struct {
28+
bool in : 1;
29+
bool out : 1;
30+
bool mtx : 1;
31+
} flags;
32+
} kmp_depend_info_t;
33+
34+
} // extern "C"
35+
36+
#endif // OMPTARGET_OPENMP_INTERNAL_TYPES_H
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//===-- OpenMP/InteropAPI.h - OpenMP interoperability types and API - 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+
//===----------------------------------------------------------------------===//
10+
11+
#ifndef OMPTARGET_OPENMP_INTEROP_API_H
12+
#define OMPTARGET_OPENMP_INTEROP_API_H
13+
14+
#include "omp.h"
15+
16+
#include "omptarget.h"
17+
18+
extern "C" {
19+
20+
typedef enum kmp_interop_type_t {
21+
kmp_interop_type_unknown = -1,
22+
kmp_interop_type_platform,
23+
kmp_interop_type_device,
24+
kmp_interop_type_tasksync,
25+
} kmp_interop_type_t;
26+
27+
/// The interop value type, aka. the interop object.
28+
typedef struct omp_interop_val_t {
29+
/// Device and interop-type are determined at construction time and fix.
30+
omp_interop_val_t(intptr_t device_id, kmp_interop_type_t interop_type)
31+
: interop_type(interop_type), device_id(device_id) {}
32+
const char *err_str = nullptr;
33+
__tgt_async_info *async_info = nullptr;
34+
__tgt_device_info device_info;
35+
const kmp_interop_type_t interop_type;
36+
const intptr_t device_id;
37+
const omp_foreign_runtime_ids_t vendor_id = cuda;
38+
const intptr_t backend_type_id = omp_interop_backend_type_cuda_1;
39+
} omp_interop_val_t;
40+
41+
} // extern "C"
42+
43+
#endif // OMPTARGET_OPENMP_INTEROP_API_H

openmp/libomptarget/include/interop.h renamed to openmp/libomptarget/include/OpenMP/omp.h

Lines changed: 24 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
//===----------------------------------------------------------------------===//
1+
//===-- OpenMP/omp.h - Copies of OpenMP user facing types and APIs - 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.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
8+
//
9+
// This copies some OpenMP user facing types and APIs for easy reach within the
10+
// implementation.
11+
//
12+
//===----------------------------------------------------------------------===//
813

9-
#ifndef _INTEROP_H_
10-
#define _INTEROP_H_
14+
#ifndef OMPTARGET_OPENMP_OMP_H
15+
#define OMPTARGET_OPENMP_OMP_H
1116

12-
#include "omptarget.h"
13-
#include <assert.h>
17+
#include <cstdint>
1418

1519
#if defined(_WIN32)
1620
#define __KAI_KMPC_CONVENTION __cdecl
@@ -24,9 +28,13 @@
2428
#endif
2529
#endif
2630

27-
#ifdef __cplusplus
2831
extern "C" {
29-
#endif
32+
33+
int omp_get_default_device(void) __attribute__((weak));
34+
35+
/// InteropAPI
36+
///
37+
///{
3038

3139
/// TODO: Include the `omp.h` of the current build
3240
/* OpenMP 5.1 interop */
@@ -81,9 +89,8 @@ int __KAI_KMPC_CONVENTION omp_get_num_interop_properties(const omp_interop_t);
8189
* The `omp_get_interop_int` routine retrieves an integer property from an
8290
* `omp_interop_t` object.
8391
*/
84-
omp_intptr_t __KAI_KMPC_CONVENTION omp_get_interop_int(const omp_interop_t,
85-
omp_interop_property_t,
86-
int *);
92+
omp_intptr_t __KAI_KMPC_CONVENTION
93+
omp_get_interop_int(const omp_interop_t, omp_interop_property_t, int *);
8794
/*!
8895
* The `omp_get_interop_ptr` routine retrieves a pointer property from an
8996
* `omp_interop_t` object.
@@ -94,9 +101,8 @@ void *__KAI_KMPC_CONVENTION omp_get_interop_ptr(const omp_interop_t,
94101
* The `omp_get_interop_str` routine retrieves a string property from an
95102
* `omp_interop_t` object.
96103
*/
97-
const char *__KAI_KMPC_CONVENTION omp_get_interop_str(const omp_interop_t,
98-
omp_interop_property_t,
99-
int *);
104+
const char *__KAI_KMPC_CONVENTION
105+
omp_get_interop_str(const omp_interop_t, omp_interop_property_t, int *);
100106
/*!
101107
* The `omp_get_interop_name` routine retrieves a property name from an
102108
* `omp_interop_t` object.
@@ -121,13 +127,6 @@ typedef enum omp_interop_backend_type_t {
121127
omp_interop_backend_type_cuda_1 = 1,
122128
} omp_interop_backend_type_t;
123129

124-
typedef enum kmp_interop_type_t {
125-
kmp_interop_type_unknown = -1,
126-
kmp_interop_type_platform,
127-
kmp_interop_type_device,
128-
kmp_interop_type_tasksync,
129-
} kmp_interop_type_t;
130-
131130
typedef enum omp_foreign_runtime_ids {
132131
cuda = 1,
133132
cuda_driver = 2,
@@ -137,21 +136,8 @@ typedef enum omp_foreign_runtime_ids {
137136
level_zero = 6,
138137
} omp_foreign_runtime_ids_t;
139138

140-
/// The interop value type, aka. the interop object.
141-
typedef struct omp_interop_val_t {
142-
/// Device and interop-type are determined at construction time and fix.
143-
omp_interop_val_t(intptr_t device_id, kmp_interop_type_t interop_type)
144-
: interop_type(interop_type), device_id(device_id) {}
145-
const char *err_str = nullptr;
146-
__tgt_async_info *async_info = nullptr;
147-
__tgt_device_info device_info;
148-
const kmp_interop_type_t interop_type;
149-
const intptr_t device_id;
150-
const omp_foreign_runtime_ids_t vendor_id = cuda;
151-
const intptr_t backend_type_id = omp_interop_backend_type_cuda_1;
152-
} omp_interop_val_t;
153-
154-
#ifdef __cplusplus
155-
}
156-
#endif
157-
#endif
139+
///} InteropAPI
140+
141+
} // extern "C"
142+
143+
#endif // OMPTARGET_OPENMP_OMP_H

openmp/libomptarget/src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ add_llvm_library(omptarget
1818
api.cpp
1919
device.cpp
2020
interface.cpp
21-
interop.cpp
2221
omptarget.cpp
2322
OmptCallback.cpp
2423
rtl.cpp
2524
LegacyAPI.cpp
25+
OpenMP/InteropAPI.cpp
2626

2727
ADDITIONAL_HEADER_DIRS
2828
${LIBOMPTARGET_INCLUDE_DIR}

openmp/libomptarget/src/interop.cpp renamed to openmp/libomptarget/src/OpenMP/InteropAPI.cpp

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
1-
//===---------------interop.cpp - Implementation of interop directive -----===//
1+
//===-- InteropAPI.cpp - Implementation of OpenMP interoperability API ----===//
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.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "interop.h"
10-
#include "private.h"
9+
#include "OpenMP/InteropAPI.h"
10+
#include "OpenMP/InternalTypes.h"
11+
#include "OpenMP/omp.h"
12+
13+
#include "device.h"
14+
#include "omptarget.h"
15+
16+
extern "C" {
17+
18+
void __kmpc_omp_wait_deps(ident_t *loc_ref, int32_t gtid, int32_t ndeps,
19+
kmp_depend_info_t *dep_list, int32_t ndeps_noalias,
20+
kmp_depend_info_t *noalias_dep_list)
21+
__attribute__((weak));
22+
23+
} // extern "C"
1124

1225
namespace {
1326
omp_interop_rc_t getPropertyErrorType(omp_interop_property_t Property) {
@@ -176,17 +189,14 @@ __OMP_GET_INTEROP_TY3(const char *, type_desc)
176189
__OMP_GET_INTEROP_TY3(const char *, rc_desc)
177190
#undef __OMP_GET_INTEROP_TY3
178191

179-
typedef int64_t kmp_int64;
180-
181-
#ifdef __cplusplus
182192
extern "C" {
183-
#endif
184-
void __tgt_interop_init(ident_t *LocRef, kmp_int32 Gtid,
193+
194+
void __tgt_interop_init(ident_t *LocRef, int32_t Gtid,
185195
omp_interop_val_t *&InteropPtr,
186-
kmp_interop_type_t InteropType, kmp_int32 DeviceId,
187-
kmp_int32 Ndeps, kmp_depend_info_t *DepList,
188-
kmp_int32 HaveNowait) {
189-
kmp_int32 NdepsNoalias = 0;
196+
kmp_interop_type_t InteropType, int32_t DeviceId,
197+
int32_t Ndeps, kmp_depend_info_t *DepList,
198+
int32_t HaveNowait) {
199+
int32_t NdepsNoalias = 0;
190200
kmp_depend_info_t *NoaliasDepList = NULL;
191201
assert(InteropType != kmp_interop_type_unknown &&
192202
"Cannot initialize with unknown interop_type!");
@@ -221,11 +231,11 @@ void __tgt_interop_init(ident_t *LocRef, kmp_int32 Gtid,
221231
}
222232
}
223233

224-
void __tgt_interop_use(ident_t *LocRef, kmp_int32 Gtid,
225-
omp_interop_val_t *&InteropPtr, kmp_int32 DeviceId,
226-
kmp_int32 Ndeps, kmp_depend_info_t *DepList,
227-
kmp_int32 HaveNowait) {
228-
kmp_int32 NdepsNoalias = 0;
234+
void __tgt_interop_use(ident_t *LocRef, int32_t Gtid,
235+
omp_interop_val_t *&InteropPtr, int32_t DeviceId,
236+
int32_t Ndeps, kmp_depend_info_t *DepList,
237+
int32_t HaveNowait) {
238+
int32_t NdepsNoalias = 0;
229239
kmp_depend_info_t *NoaliasDepList = NULL;
230240
assert(InteropPtr && "Cannot use nullptr!");
231241
omp_interop_val_t *InteropVal = InteropPtr;
@@ -249,11 +259,11 @@ void __tgt_interop_use(ident_t *LocRef, kmp_int32 Gtid,
249259
// TODO Flush the queue associated with the interop through the plugin
250260
}
251261

252-
void __tgt_interop_destroy(ident_t *LocRef, kmp_int32 Gtid,
253-
omp_interop_val_t *&InteropPtr, kmp_int32 DeviceId,
254-
kmp_int32 Ndeps, kmp_depend_info_t *DepList,
255-
kmp_int32 HaveNowait) {
256-
kmp_int32 NdepsNoalias = 0;
262+
void __tgt_interop_destroy(ident_t *LocRef, int32_t Gtid,
263+
omp_interop_val_t *&InteropPtr, int32_t DeviceId,
264+
int32_t Ndeps, kmp_depend_info_t *DepList,
265+
int32_t HaveNowait) {
266+
int32_t NdepsNoalias = 0;
257267
kmp_depend_info_t *NoaliasDepList = NULL;
258268
assert(InteropPtr && "Cannot use nullptr!");
259269
omp_interop_val_t *InteropVal = InteropPtr;
@@ -281,6 +291,5 @@ void __tgt_interop_destroy(ident_t *LocRef, kmp_int32 Gtid,
281291
delete InteropPtr;
282292
InteropPtr = omp_interop_none;
283293
}
284-
#ifdef __cplusplus
294+
285295
} // extern "C"
286-
#endif

openmp/libomptarget/src/omptarget.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include "private.h"
1919
#include "rtl.h"
2020

21+
#include "OpenMP/omp.h"
22+
2123
#include "llvm/ADT/StringExtras.h"
2224
#include "llvm/ADT/bit.h"
2325

openmp/libomptarget/src/private.h

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include "Shared/Debug.h"
1717
#include "Shared/SourceInfo.h"
1818

19+
#include "OpenMP/InternalTypes.h"
20+
1921
#include "device.h"
2022
#include "omptarget.h"
2123

@@ -110,7 +112,6 @@ extern "C" {
110112
*/
111113
typedef int kmp_int32;
112114
typedef int64_t kmp_int64;
113-
typedef intptr_t kmp_intptr_t;
114115

115116
typedef void *omp_depend_t;
116117
struct kmp_task;
@@ -154,24 +155,8 @@ typedef struct kmp_tasking_flags { /* Total struct must be exactly 32 bits */
154155
unsigned reserved31 : 7; /* reserved for library use */
155156
} kmp_tasking_flags_t;
156157

157-
// Compiler sends us this info:
158-
typedef struct kmp_depend_info {
159-
kmp_intptr_t base_addr;
160-
size_t len;
161-
struct {
162-
bool in : 1;
163-
bool out : 1;
164-
bool mtx : 1;
165-
} flags;
166-
} kmp_depend_info_t;
167-
// functions that extract info from libomp; keep in sync
168-
int omp_get_default_device(void) __attribute__((weak));
169158
int32_t __kmpc_global_thread_num(void *) __attribute__((weak));
170159
int __kmpc_get_target_offload(void) __attribute__((weak));
171-
void __kmpc_omp_wait_deps(ident_t *loc_ref, kmp_int32 gtid, kmp_int32 ndeps,
172-
kmp_depend_info_t *dep_list, kmp_int32 ndeps_noalias,
173-
kmp_depend_info_t *noalias_dep_list)
174-
__attribute__((weak));
175160
void **__kmpc_omp_get_target_async_handle_ptr(kmp_int32 gtid)
176161
__attribute__((weak));
177162
bool __kmpc_omp_has_task_team(kmp_int32 gtid) __attribute__((weak));

0 commit comments

Comments
 (0)