blob: dbc5bafbab5bf5d2f3fc8ea9a4f415d9912a8b79 [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,
Shilei Tian32ed2922020-04-07 14:51:56 -040021 void **args_base, void **args, int64_t *arg_sizes,
22 int64_t *arg_types,
Shilei Tian03ff6432020-04-09 22:40:30 -040023 __tgt_async_info *async_info_ptr);
Jonas Hahnfelda7c4f322017-12-06 21:59:15 +000024
25extern int target_data_end(DeviceTy &Device, int32_t arg_num, void **args_base,
Shilei Tian32ed2922020-04-07 14:51:56 -040026 void **args, int64_t *arg_sizes, int64_t *arg_types,
Shilei Tian03ff6432020-04-09 22:40:30 -040027 __tgt_async_info *async_info_ptr);
Jonas Hahnfelda7c4f322017-12-06 21:59:15 +000028
Alexandre Eichenberger1b4a6662018-08-23 16:22:42 +000029extern int target_data_update(DeviceTy &Device, int32_t arg_num,
Jonas Hahnfelda7c4f322017-12-06 21:59:15 +000030 void **args_base, void **args, int64_t *arg_sizes, int64_t *arg_types);
31
Jonas Hahnfeld43322802017-12-06 21:59:07 +000032extern int target(int64_t device_id, void *host_ptr, int32_t arg_num,
33 void **args_base, void **args, int64_t *arg_sizes, int64_t *arg_types,
34 int32_t team_num, int32_t thread_limit, int IsTeamConstruct);
35
Jonas Hahnfelda7c4f322017-12-06 21:59:15 +000036extern int CheckDeviceAndCtors(int64_t device_id);
37
Alexandre Eichenberger1b4a6662018-08-23 16:22:42 +000038// enum for OMP_TARGET_OFFLOAD; keep in sync with kmp.h definition
39enum kmp_target_offload_kind {
40 tgt_disabled = 0,
41 tgt_default = 1,
42 tgt_mandatory = 2
43};
44typedef enum kmp_target_offload_kind kmp_target_offload_kind_t;
45extern kmp_target_offload_kind_t TargetOffloadPolicy;
46
Michael Kruse2c7a8ea2019-08-04 04:18:28 +000047// This structure stores information of a mapped memory region.
48struct MapComponentInfoTy {
49 void *Base;
50 void *Begin;
51 int64_t Size;
52 int64_t Type;
53 MapComponentInfoTy() = default;
54 MapComponentInfoTy(void *Base, void *Begin, int64_t Size, int64_t Type)
55 : Base(Base), Begin(Begin), Size(Size), Type(Type) {}
56};
57
58// This structure stores all components of a user-defined mapper. The number of
59// components are dynamically decided, so we utilize C++ STL vector
60// implementation here.
61struct MapperComponentsTy {
62 std::vector<MapComponentInfoTy> Components;
63};
64
Alexandre Eichenbergere9b7d8d2018-08-27 18:20:15 +000065////////////////////////////////////////////////////////////////////////////////
Kazuaki Ishizaki4c6a0982020-01-07 14:03:31 +080066// implementation for fatal messages
Alexandre Eichenbergere9b7d8d2018-08-27 18:20:15 +000067////////////////////////////////////////////////////////////////////////////////
68
69#define FATAL_MESSAGE0(_num, _str) \
70 do { \
71 fprintf(stderr, "Libomptarget fatal error %d: %s\n", _num, _str); \
72 exit(1); \
73 } while (0)
74
75#define FATAL_MESSAGE(_num, _str, ...) \
76 do { \
77 fprintf(stderr, "Libomptarget fatal error %d:" _str "\n", _num, \
78 __VA_ARGS__); \
79 exit(1); \
80 } while (0)
81
George Rokos2878c392018-03-16 20:40:09 +000082// Implemented in libomp, they are called from within __tgt_* functions.
George Rokos6b9bb5e2018-03-17 02:07:42 +000083#ifdef __cplusplus
84extern "C" {
85#endif
Alexandre Eichenberger1b4a6662018-08-23 16:22:42 +000086// functions that extract info from libomp; keep in sync
George Rokos2878c392018-03-16 20:40:09 +000087int omp_get_default_device(void) __attribute__((weak));
88int32_t __kmpc_omp_taskwait(void *loc_ref, int32_t gtid) __attribute__((weak));
Alexey Bataev060921d2019-07-08 15:30:23 +000089int32_t __kmpc_global_thread_num(void *) __attribute__((weak));
Alexandre Eichenberger1b4a6662018-08-23 16:22:42 +000090int __kmpc_get_target_offload(void) __attribute__((weak));
George Rokos6b9bb5e2018-03-17 02:07:42 +000091#ifdef __cplusplus
92}
93#endif
George Rokos2878c392018-03-16 20:40:09 +000094
Jonas Hahnfeld43322802017-12-06 21:59:07 +000095#ifdef OMPTARGET_DEBUG
96extern int DebugLevel;
97
98#define DP(...) \
99 do { \
100 if (DebugLevel > 0) { \
101 DEBUGP("Libomptarget", __VA_ARGS__); \
102 } \
103 } while (false)
104#else // OMPTARGET_DEBUG
105#define DP(...) {}
106#endif // OMPTARGET_DEBUG
107
108#endif