| 1 | #include <cassert> |
| 2 | #include <cstdint> |
| 3 | #include <iostream> |
| 4 | #include <string> |
| 5 | |
| 6 | extern "C" { |
| 7 | struct ident_t; |
| 8 | |
| 9 | using kmp_int32 = int32_t; |
| 10 | using kmp_int64 = int64_t; |
| 11 | using kmp_routine_entry_t = kmp_int32 (*)(kmp_int32, void *); |
| 12 | using kmp_intptr_t = intptr_t; |
| 13 | |
| 14 | typedef struct kmp_depend_info { |
| 15 | kmp_intptr_t base_addr; |
| 16 | size_t len; |
| 17 | union { |
| 18 | unsigned char flag; |
| 19 | struct { |
| 20 | #if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) |
| 21 | unsigned all : 1; |
| 22 | unsigned unused : 3; |
| 23 | unsigned set : 1; |
| 24 | unsigned mtx : 1; |
| 25 | unsigned out : 1; |
| 26 | unsigned in : 1; |
| 27 | #else |
| 28 | unsigned in : 1; |
| 29 | unsigned out : 1; |
| 30 | unsigned mtx : 1; |
| 31 | unsigned set : 1; |
| 32 | unsigned unused : 3; |
| 33 | unsigned all : 1; |
| 34 | #endif |
| 35 | } flags; |
| 36 | }; |
| 37 | } kmp_depend_info_t; |
| 38 | |
| 39 | typedef union kmp_cmplrdata { |
| 40 | kmp_int32 priority; |
| 41 | kmp_routine_entry_t destructors; |
| 42 | } kmp_cmplrdata_t; |
| 43 | |
| 44 | typedef struct kmp_task { |
| 45 | void *shareds; |
| 46 | kmp_routine_entry_t routine; |
| 47 | kmp_int32 part_id; |
| 48 | kmp_cmplrdata_t data1; |
| 49 | kmp_cmplrdata_t data2; |
| 50 | } kmp_task_t; |
| 51 | |
| 52 | int32_t __kmpc_global_thread_num(void *); |
| 53 | kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32, kmp_int32, size_t, |
| 54 | size_t, kmp_routine_entry_t); |
| 55 | kmp_task_t *__kmpc_omp_target_task_alloc(ident_t *, kmp_int32, kmp_int32, |
| 56 | size_t, size_t, kmp_routine_entry_t, |
| 57 | kmp_int64); |
| 58 | kmp_int32 __kmpc_omp_taskwait(ident_t *, kmp_int32); |
| 59 | kmp_int32 __kmpc_omp_task(ident_t *, kmp_int32, kmp_task_t *); |
| 60 | kmp_int32 __kmpc_omp_task_with_deps(ident_t *loc_ref, kmp_int32 gtid, |
| 61 | kmp_task_t *new_task, kmp_int32 ndeps, |
| 62 | kmp_depend_info_t *dep_list, |
| 63 | kmp_int32 ndeps_noalias, |
| 64 | kmp_depend_info_t *noalias_dep_list); |
| 65 | void __kmpc_taskgroup(ident_t *, kmp_int32); |
| 66 | void __kmpc_end_taskgroup(ident_t *, kmp_int32); |
| 67 | } |
| 68 | |
| 69 | static kmp_int32 get_num_hidden_helper_threads() { |
| 70 | static kmp_int32 __kmp_hidden_helper_threads_num = 8; |
| 71 | if (const char *env = std::getenv(name: "LIBOMP_NUM_HIDDEN_HELPER_THREADS" )) { |
| 72 | return std::stoi(str: env); |
| 73 | } |
| 74 | return __kmp_hidden_helper_threads_num; |
| 75 | } |
| 76 | |