Skip to content

Commit 2c7a8ea

Browse files
committedAug 4, 2019
[OpenMP 5.0] libomptarget interface for declare mapper functions.
This patch implements the libomptarget runtime interface for OpenMP 5.0 declare mapper functions. The declare mapper functions generated by Clang will call them to complete the mapping of members. kmpc_mapper_num_components gets the current number of components for a user-defined mapper; kmpc_push_mapper_component pushes back one component for a user-defined mapper. The design slides can be found at https://github.com/lingda-li/public-sharing/blob/master/mapper_runtime_design.pptx Patch by Lingda Li <lildmh@gmail.com> Differential Revision: https://reviews.llvm.org/D60972 llvm-svn: 367772
1 parent 76f0f2e commit 2c7a8ea

File tree

4 files changed

+88
-0
lines changed

4 files changed

+88
-0
lines changed
 

‎openmp/libomptarget/src/exports

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ VERS1.0 {
1313
__tgt_target_data_update_nowait;
1414
__tgt_target_nowait;
1515
__tgt_target_teams_nowait;
16+
__tgt_mapper_num_components;
17+
__tgt_push_mapper_component;
1618
omp_get_num_devices;
1719
omp_get_initial_device;
1820
omp_target_alloc;

‎openmp/libomptarget/src/interface.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,28 @@ EXTERN int __tgt_target_teams_nowait(int64_t device_id, void *host_ptr,
304304
arg_sizes, arg_types, team_num, thread_limit);
305305
}
306306

307+
// Get the current number of components for a user-defined mapper.
308+
EXTERN int64_t __tgt_mapper_num_components(void *rt_mapper_handle) {
309+
auto *MapperComponentsPtr = (struct MapperComponentsTy *)rt_mapper_handle;
310+
int64_t size = MapperComponentsPtr->Components.size();
311+
DP("__tgt_mapper_num_components(Handle=" DPxMOD ") returns %" PRId64 "\n",
312+
DPxPTR(rt_mapper_handle), size);
313+
return size;
314+
}
315+
316+
// Push back one component for a user-defined mapper.
317+
EXTERN void __tgt_push_mapper_component(void *rt_mapper_handle, void *base,
318+
void *begin, int64_t size,
319+
int64_t type) {
320+
DP("__tgt_push_mapper_component(Handle=" DPxMOD
321+
") adds an entry (Base=" DPxMOD ", Begin=" DPxMOD ", Size=%" PRId64
322+
", Type=0x%" PRIx64 ").\n",
323+
DPxPTR(rt_mapper_handle), DPxPTR(base), DPxPTR(begin), size, type);
324+
auto *MapperComponentsPtr = (struct MapperComponentsTy *)rt_mapper_handle;
325+
MapperComponentsPtr->Components.push_back(
326+
MapComponentInfoTy(base, begin, size, type));
327+
}
328+
307329
EXTERN void __kmpc_push_target_tripcount(int64_t device_id,
308330
uint64_t loop_tripcount) {
309331
if (IsOffloadDisabled())

‎openmp/libomptarget/src/private.h

+18
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,24 @@ enum kmp_target_offload_kind {
4141
typedef enum kmp_target_offload_kind kmp_target_offload_kind_t;
4242
extern kmp_target_offload_kind_t TargetOffloadPolicy;
4343

44+
// This structure stores information of a mapped memory region.
45+
struct MapComponentInfoTy {
46+
void *Base;
47+
void *Begin;
48+
int64_t Size;
49+
int64_t Type;
50+
MapComponentInfoTy() = default;
51+
MapComponentInfoTy(void *Base, void *Begin, int64_t Size, int64_t Type)
52+
: Base(Base), Begin(Begin), Size(Size), Type(Type) {}
53+
};
54+
55+
// This structure stores all components of a user-defined mapper. The number of
56+
// components are dynamically decided, so we utilize C++ STL vector
57+
// implementation here.
58+
struct MapperComponentsTy {
59+
std::vector<MapComponentInfoTy> Components;
60+
};
61+
4462
////////////////////////////////////////////////////////////////////////////////
4563
// implemtation for fatal messages
4664
////////////////////////////////////////////////////////////////////////////////
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// RUN: %libomptarget-compile-run-and-check-aarch64-unknown-linux-gnu
2+
// RUN: %libomptarget-compile-run-and-check-powerpc64-ibm-linux-gnu
3+
// RUN: %libomptarget-compile-run-and-check-powerpc64le-ibm-linux-gnu
4+
// RUN: %libomptarget-compile-run-and-check-x86_64-pc-linux-gnu
5+
6+
#include <cstdio>
7+
#include <cstdlib>
8+
9+
// Data structure definitions copied from OpenMP RTL.
10+
struct MapComponentInfoTy {
11+
void *Base;
12+
void *Begin;
13+
int64_t Size;
14+
int64_t Type;
15+
MapComponentInfoTy() = default;
16+
MapComponentInfoTy(void *Base, void *Begin, int64_t Size, int64_t Type)
17+
: Base(Base), Begin(Begin), Size(Size), Type(Type) {}
18+
};
19+
20+
struct MapperComponentsTy {
21+
std::vector<MapComponentInfoTy> Components;
22+
};
23+
24+
// OpenMP RTL interfaces
25+
#ifdef __cplusplus
26+
extern "C" {
27+
#endif
28+
int64_t __tgt_mapper_num_components(void *rt_mapper_handle);
29+
void __tgt_push_mapper_component(void *rt_mapper_handle, void *base,
30+
void *begin, int64_t size, int64_t type);
31+
#ifdef __cplusplus
32+
}
33+
#endif
34+
35+
int main(int argc, char *argv[]) {
36+
MapperComponentsTy MC;
37+
void *base, *begin;
38+
int64_t size, type;
39+
// Push 2 elements into MC.
40+
__tgt_push_mapper_component((void *)&MC, base, begin, size, type);
41+
__tgt_push_mapper_component((void *)&MC, base, begin, size, type);
42+
int64_t num = __tgt_mapper_num_components((void *)&MC);
43+
// CHECK: num=2
44+
printf("num=%lld\n", num);
45+
return 0;
46+
}

0 commit comments

Comments
 (0)
Please sign in to comment.