xref: /llvm-project/offload/test/mapping/declare_mapper_api.cpp (revision 330d8983d25d08580fc1642fea48b2473f47a9da)
1 // RUN: %libomptarget-compilexx-run-and-check-generic
2 
3 #include <cinttypes>
4 #include <cstdio>
5 #include <cstdlib>
6 #include <vector>
7 
8 // Data structure definitions copied from OpenMP RTL.
9 struct MapComponentInfoTy {
10   void *Base;
11   void *Begin;
12   int64_t Size;
13   int64_t Type;
14   void *Name;
15   MapComponentInfoTy() = default;
MapComponentInfoTyMapComponentInfoTy16   MapComponentInfoTy(void *Base, void *Begin, int64_t Size, int64_t Type,
17                      void *Name)
18       : Base(Base), Begin(Begin), Size(Size), Type(Type), Name(Name) {}
19 };
20 
21 struct MapperComponentsTy {
22   std::vector<MapComponentInfoTy> Components;
23 };
24 
25 // OpenMP RTL interfaces
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 int64_t __tgt_mapper_num_components(void *rt_mapper_handle);
30 void __tgt_push_mapper_component(void *rt_mapper_handle, void *base,
31                                  void *begin, int64_t size, int64_t type,
32                                  void *name);
33 #ifdef __cplusplus
34 }
35 #endif
36 
main(int argc,char * argv[])37 int main(int argc, char *argv[]) {
38   MapperComponentsTy MC;
39   void *base, *begin;
40   int64_t size, type;
41   // Push 2 elements into MC.
42   __tgt_push_mapper_component((void *)&MC, base, begin, size, type, nullptr);
43   __tgt_push_mapper_component((void *)&MC, base, begin, size, type, nullptr);
44   int64_t num = __tgt_mapper_num_components((void *)&MC);
45   // CHECK: num=2
46   printf("num=%" PRId64 "\n", num);
47   return 0;
48 }
49