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, |
| 21 | void **args_base, void **args, int64_t *arg_sizes, int64_t *arg_types); |
| 22 | |
| 23 | extern 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 Eichenberger | 1b4a666 | 2018-08-23 16:22:42 +0000 | [diff] [blame] | 26 | extern int target_data_update(DeviceTy &Device, int32_t arg_num, |
Jonas Hahnfeld | a7c4f32 | 2017-12-06 21:59:15 +0000 | [diff] [blame] | 27 | void **args_base, void **args, int64_t *arg_sizes, int64_t *arg_types); |
| 28 | |
Jonas Hahnfeld | 4332280 | 2017-12-06 21:59:07 +0000 | [diff] [blame] | 29 | extern 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 Hahnfeld | a7c4f32 | 2017-12-06 21:59:15 +0000 | [diff] [blame] | 33 | extern int CheckDeviceAndCtors(int64_t device_id); |
| 34 | |
Alexandre Eichenberger | 1b4a666 | 2018-08-23 16:22:42 +0000 | [diff] [blame] | 35 | // enum for OMP_TARGET_OFFLOAD; keep in sync with kmp.h definition |
| 36 | enum kmp_target_offload_kind { |
| 37 | tgt_disabled = 0, |
| 38 | tgt_default = 1, |
| 39 | tgt_mandatory = 2 |
| 40 | }; |
| 41 | typedef enum kmp_target_offload_kind kmp_target_offload_kind_t; |
| 42 | extern kmp_target_offload_kind_t TargetOffloadPolicy; |
| 43 | |
Michael Kruse | 2c7a8ea | 2019-08-04 04:18:28 +0000 | [diff] [blame^] | 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 | |
Alexandre Eichenberger | e9b7d8d | 2018-08-27 18:20:15 +0000 | [diff] [blame] | 62 | //////////////////////////////////////////////////////////////////////////////// |
| 63 | // implemtation for fatal messages |
| 64 | //////////////////////////////////////////////////////////////////////////////// |
| 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 Rokos | 2878c39 | 2018-03-16 20:40:09 +0000 | [diff] [blame] | 79 | // Implemented in libomp, they are called from within __tgt_* functions. |
George Rokos | 6b9bb5e | 2018-03-17 02:07:42 +0000 | [diff] [blame] | 80 | #ifdef __cplusplus |
| 81 | extern "C" { |
| 82 | #endif |
Alexandre Eichenberger | 1b4a666 | 2018-08-23 16:22:42 +0000 | [diff] [blame] | 83 | // functions that extract info from libomp; keep in sync |
George Rokos | 2878c39 | 2018-03-16 20:40:09 +0000 | [diff] [blame] | 84 | int omp_get_default_device(void) __attribute__((weak)); |
| 85 | 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] | 86 | int32_t __kmpc_global_thread_num(void *) __attribute__((weak)); |
Alexandre Eichenberger | 1b4a666 | 2018-08-23 16:22:42 +0000 | [diff] [blame] | 87 | int __kmpc_get_target_offload(void) __attribute__((weak)); |
George Rokos | 6b9bb5e | 2018-03-17 02:07:42 +0000 | [diff] [blame] | 88 | #ifdef __cplusplus |
| 89 | } |
| 90 | #endif |
George Rokos | 2878c39 | 2018-03-16 20:40:09 +0000 | [diff] [blame] | 91 | |
Jonas Hahnfeld | 4332280 | 2017-12-06 21:59:07 +0000 | [diff] [blame] | 92 | #ifdef OMPTARGET_DEBUG |
| 93 | extern 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 |