blob: 7aaa295d9686e169a105b2dd1aa9c6cb7e3cfb8f [file] [log] [blame]
Jonas Hahnfeld43322802017-12-06 21:59:07 +00001//===---------- private.h - Target independent OpenMP target RTL ----------===//
2//
Chandler Carruth57b08b02019-01-19 10:56:40 +00003// 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
Jonas Hahnfeld43322802017-12-06 21:59:07 +00006//
7//===----------------------------------------------------------------------===//
8//
9// Private function declarations and helper macros for debugging output.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef _OMPTARGET_PRIVATE_H
14#define _OMPTARGET_PRIVATE_H
15
16#include <omptarget.h>
17
18#include <cstdint>
19
Jonas Hahnfelda7c4f322017-12-06 21:59:15 +000020extern int target_data_begin(DeviceTy &Device, int32_t arg_num,
21 void **args_base, void **args, int64_t *arg_sizes, int64_t *arg_types);
22
23extern int target_data_end(DeviceTy &Device, int32_t arg_num, void **args_base,
24 void **args, int64_t *arg_sizes, int64_t *arg_types);
25
Alexandre Eichenberger1b4a6662018-08-23 16:22:42 +000026extern int target_data_update(DeviceTy &Device, int32_t arg_num,
Jonas Hahnfelda7c4f322017-12-06 21:59:15 +000027 void **args_base, void **args, int64_t *arg_sizes, int64_t *arg_types);
28
Jonas Hahnfeld43322802017-12-06 21:59:07 +000029extern int target(int64_t device_id, void *host_ptr, int32_t arg_num,
30 void **args_base, void **args, int64_t *arg_sizes, int64_t *arg_types,
31 int32_t team_num, int32_t thread_limit, int IsTeamConstruct);
32
Jonas Hahnfelda7c4f322017-12-06 21:59:15 +000033extern int CheckDeviceAndCtors(int64_t device_id);
34
Alexandre Eichenberger1b4a6662018-08-23 16:22:42 +000035// enum for OMP_TARGET_OFFLOAD; keep in sync with kmp.h definition
36enum kmp_target_offload_kind {
37 tgt_disabled = 0,
38 tgt_default = 1,
39 tgt_mandatory = 2
40};
41typedef enum kmp_target_offload_kind kmp_target_offload_kind_t;
42extern kmp_target_offload_kind_t TargetOffloadPolicy;
43
Michael Kruse2c7a8ea2019-08-04 04:18:28 +000044// This structure stores information of a mapped memory region.
45struct 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.
58struct MapperComponentsTy {
59 std::vector<MapComponentInfoTy> Components;
60};
61
Alexandre Eichenbergere9b7d8d2018-08-27 18:20:15 +000062////////////////////////////////////////////////////////////////////////////////
Kazuaki Ishizaki4c6a0982020-01-07 14:03:31 +080063// implementation for fatal messages
Alexandre Eichenbergere9b7d8d2018-08-27 18:20:15 +000064////////////////////////////////////////////////////////////////////////////////
65
66#define FATAL_MESSAGE0(_num, _str) \
67 do { \
68 fprintf(stderr, "Libomptarget fatal error %d: %s\n", _num, _str); \
69 exit(1); \
70 } while (0)
71
72#define FATAL_MESSAGE(_num, _str, ...) \
73 do { \
74 fprintf(stderr, "Libomptarget fatal error %d:" _str "\n", _num, \
75 __VA_ARGS__); \
76 exit(1); \
77 } while (0)
78
George Rokos2878c392018-03-16 20:40:09 +000079// Implemented in libomp, they are called from within __tgt_* functions.
George Rokos6b9bb5e2018-03-17 02:07:42 +000080#ifdef __cplusplus
81extern "C" {
82#endif
Alexandre Eichenberger1b4a6662018-08-23 16:22:42 +000083// functions that extract info from libomp; keep in sync
George Rokos2878c392018-03-16 20:40:09 +000084int omp_get_default_device(void) __attribute__((weak));
85int32_t __kmpc_omp_taskwait(void *loc_ref, int32_t gtid) __attribute__((weak));
Alexey Bataev060921d2019-07-08 15:30:23 +000086int32_t __kmpc_global_thread_num(void *) __attribute__((weak));
Alexandre Eichenberger1b4a6662018-08-23 16:22:42 +000087int __kmpc_get_target_offload(void) __attribute__((weak));
George Rokos6b9bb5e2018-03-17 02:07:42 +000088#ifdef __cplusplus
89}
90#endif
George Rokos2878c392018-03-16 20:40:09 +000091
Jonas Hahnfeld43322802017-12-06 21:59:07 +000092#ifdef OMPTARGET_DEBUG
93extern int DebugLevel;
94
95#define DP(...) \
96 do { \
97 if (DebugLevel > 0) { \
98 DEBUGP("Libomptarget", __VA_ARGS__); \
99 } \
100 } while (false)
101#else // OMPTARGET_DEBUG
102#define DP(...) {}
103#endif // OMPTARGET_DEBUG
104
105#endif