Jonas Hahnfeld | 4332280 | 2017-12-06 21:59:07 +0000 | [diff] [blame] | 1 | //===---------- private.h - Target independent OpenMP target RTL ----------===// |
| 2 | // |
Chandler Carruth | 57b08b0 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 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 |
Jonas Hahnfeld | 4332280 | 2017-12-06 21:59:07 +0000 | [diff] [blame] | 6 | // |
| 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 Hahnfeld | a7c4f32 | 2017-12-06 21:59:15 +0000 | [diff] [blame] | 20 | extern int target_data_begin(DeviceTy &Device, int32_t arg_num, |
Shilei Tian | 32ed292 | 2020-04-07 14:51:56 -0400 | [diff] [blame] | 21 | void **args_base, void **args, int64_t *arg_sizes, |
| 22 | int64_t *arg_types, |
Shilei Tian | 03ff643 | 2020-04-09 22:40:30 -0400 | [diff] [blame] | 23 | __tgt_async_info *async_info_ptr); |
Jonas Hahnfeld | a7c4f32 | 2017-12-06 21:59:15 +0000 | [diff] [blame] | 24 | |
| 25 | extern int target_data_end(DeviceTy &Device, int32_t arg_num, void **args_base, |
Shilei Tian | 32ed292 | 2020-04-07 14:51:56 -0400 | [diff] [blame] | 26 | void **args, int64_t *arg_sizes, int64_t *arg_types, |
Shilei Tian | 03ff643 | 2020-04-09 22:40:30 -0400 | [diff] [blame] | 27 | __tgt_async_info *async_info_ptr); |
Jonas Hahnfeld | a7c4f32 | 2017-12-06 21:59:15 +0000 | [diff] [blame] | 28 | |
Alexandre Eichenberger | 1b4a666 | 2018-08-23 16:22:42 +0000 | [diff] [blame] | 29 | extern int target_data_update(DeviceTy &Device, int32_t arg_num, |
Jonas Hahnfeld | a7c4f32 | 2017-12-06 21:59:15 +0000 | [diff] [blame] | 30 | void **args_base, void **args, int64_t *arg_sizes, int64_t *arg_types); |
| 31 | |
Jonas Hahnfeld | 4332280 | 2017-12-06 21:59:07 +0000 | [diff] [blame] | 32 | extern 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 Hahnfeld | a7c4f32 | 2017-12-06 21:59:15 +0000 | [diff] [blame] | 36 | extern int CheckDeviceAndCtors(int64_t device_id); |
| 37 | |
Alexandre Eichenberger | 1b4a666 | 2018-08-23 16:22:42 +0000 | [diff] [blame] | 38 | // enum for OMP_TARGET_OFFLOAD; keep in sync with kmp.h definition |
| 39 | enum kmp_target_offload_kind { |
| 40 | tgt_disabled = 0, |
| 41 | tgt_default = 1, |
| 42 | tgt_mandatory = 2 |
| 43 | }; |
| 44 | typedef enum kmp_target_offload_kind kmp_target_offload_kind_t; |
| 45 | extern kmp_target_offload_kind_t TargetOffloadPolicy; |
| 46 | |
Michael Kruse | 2c7a8ea | 2019-08-04 04:18:28 +0000 | [diff] [blame] | 47 | // This structure stores information of a mapped memory region. |
| 48 | struct 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. |
| 61 | struct MapperComponentsTy { |
| 62 | std::vector<MapComponentInfoTy> Components; |
| 63 | }; |
| 64 | |
Alexandre Eichenberger | e9b7d8d | 2018-08-27 18:20:15 +0000 | [diff] [blame] | 65 | //////////////////////////////////////////////////////////////////////////////// |
Kazuaki Ishizaki | 4c6a098 | 2020-01-07 14:03:31 +0800 | [diff] [blame] | 66 | // implementation for fatal messages |
Alexandre Eichenberger | e9b7d8d | 2018-08-27 18:20:15 +0000 | [diff] [blame] | 67 | //////////////////////////////////////////////////////////////////////////////// |
| 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 Rokos | 2878c39 | 2018-03-16 20:40:09 +0000 | [diff] [blame] | 82 | // Implemented in libomp, they are called from within __tgt_* functions. |
George Rokos | 6b9bb5e | 2018-03-17 02:07:42 +0000 | [diff] [blame] | 83 | #ifdef __cplusplus |
| 84 | extern "C" { |
| 85 | #endif |
Alexandre Eichenberger | 1b4a666 | 2018-08-23 16:22:42 +0000 | [diff] [blame] | 86 | // functions that extract info from libomp; keep in sync |
George Rokos | 2878c39 | 2018-03-16 20:40:09 +0000 | [diff] [blame] | 87 | int omp_get_default_device(void) __attribute__((weak)); |
| 88 | int32_t __kmpc_omp_taskwait(void *loc_ref, int32_t gtid) __attribute__((weak)); |
Alexey Bataev | 060921d | 2019-07-08 15:30:23 +0000 | [diff] [blame] | 89 | int32_t __kmpc_global_thread_num(void *) __attribute__((weak)); |
Alexandre Eichenberger | 1b4a666 | 2018-08-23 16:22:42 +0000 | [diff] [blame] | 90 | int __kmpc_get_target_offload(void) __attribute__((weak)); |
George Rokos | 6b9bb5e | 2018-03-17 02:07:42 +0000 | [diff] [blame] | 91 | #ifdef __cplusplus |
| 92 | } |
| 93 | #endif |
George Rokos | 2878c39 | 2018-03-16 20:40:09 +0000 | [diff] [blame] | 94 | |
Jonas Hahnfeld | 4332280 | 2017-12-06 21:59:07 +0000 | [diff] [blame] | 95 | #ifdef OMPTARGET_DEBUG |
| 96 | extern 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 |