Snitch Runtime
Loading...
Searching...
No Matches
kmp.h
1// Copyright 2021 ETH Zurich and University of Bologna.
2// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3// SPDX-License-Identifier: Apache-2.0
4
5#ifndef KMP_H
6#define KMP_H
7
8#ifdef __cplusplus
9extern "C" {
10#endif
11
13// debug
15
16#ifdef KMP_DEBUG_LEVEL
17#include "../../../deps/riscv-opcodes/encoding.h"
18#include "printf.h"
19#define _KMP_PRINTF(...) \
20 if (1) { \
21 printf("[kmc] "__VA_ARGS__); \
22 }
23#define KMP_PRINTF(d, ...) \
24 if (KMP_DEBUG_LEVEL >= d) { \
25 _KMP_PRINTF(__VA_ARGS__); \
26 }
27#else
28#define KMP_PRINTF(d, ...)
29#endif
30
32// kmp specific types
33// Code taken from
34// https://github.com/llvm/llvm-project/blob/main/openmp/runtime/src/kmp.h
36
42typedef int32_t kmp_int32;
43typedef uint32_t kmp_uint32;
44typedef int64_t kmp_int64;
45typedef uint64_t kmp_uint64;
46typedef kmp_uint64 _kmp_ptr64;
47typedef kmp_uint32 _kmp_ptr32;
48
49typedef struct ident {
50 kmp_int32 reserved_1;
51 kmp_int32 flags;
53 kmp_int32
55 kmp_int32 reserved_3;
56 char const *psource;
60} ident_t;
61
66enum sched_type : kmp_int32 {
67 kmp_sch_lower = 32,
68 kmp_sch_static_chunked = 33,
69 kmp_sch_static = 34,
70 kmp_sch_dynamic_chunked = 35,
71 kmp_sch_guided_chunked = 36,
72 kmp_sch_runtime = 37,
73 kmp_sch_auto = 38,
74 kmp_sch_trapezoidal = 39,
75
76 /* accessible only through KMP_SCHEDULE environment variable */
77 kmp_sch_static_greedy = 40,
78 kmp_sch_static_balanced = 41,
79 /* accessible only through KMP_SCHEDULE environment variable */
80 kmp_sch_guided_iterative_chunked = 42,
81 kmp_sch_guided_analytical_chunked = 43,
82 /* accessible only through KMP_SCHEDULE environment variable */
83 kmp_sch_static_steal = 44,
84
85 /* static with chunk adjustment (e.g., simd) */
86 kmp_sch_static_balanced_chunked = 45,
87 kmp_sch_guided_simd = 46,
88 kmp_sch_runtime_simd = 47,
90 /* accessible only through KMP_SCHEDULE environment variable */
91 kmp_sch_upper,
93 kmp_ord_lower =
94 64,
95 kmp_ord_static_chunked = 65,
96 kmp_ord_static = 66,
97 kmp_ord_dynamic_chunked = 67,
98 kmp_ord_guided_chunked = 68,
99 kmp_ord_runtime = 69,
100 kmp_ord_auto = 70,
101 kmp_ord_trapezoidal = 71,
102 kmp_ord_upper,
104 /* Schedules for Distribute construct */
105 kmp_distribute_static_chunked = 91,
106 kmp_distribute_static = 92,
108 /* For the "nomerge" versions, kmp_dispatch_next*() will always return a
109 single iteration/chunk, even if the loop is serialized. For the schedule
110 types listed above, the entire iteration vector is returned if the loop
111 is serialized. This doesn't work for gcc/gcomp sections. */
112 kmp_nm_lower = 160,
114 kmp_nm_static_chunked =
115 (kmp_sch_static_chunked - kmp_sch_lower + kmp_nm_lower),
116 kmp_nm_static = 162,
117 kmp_nm_dynamic_chunked = 163,
118 kmp_nm_guided_chunked = 164,
119 kmp_nm_runtime = 165,
120 kmp_nm_auto = 166,
121 kmp_nm_trapezoidal = 167,
122
123 /* accessible only through KMP_SCHEDULE environment variable */
124 kmp_nm_static_greedy = 168,
125 kmp_nm_static_balanced = 169,
126 /* accessible only through KMP_SCHEDULE environment variable */
127 kmp_nm_guided_iterative_chunked = 170,
128 kmp_nm_guided_analytical_chunked = 171,
129 kmp_nm_static_steal =
130 172, /* accessible only through OMP_SCHEDULE environment variable */
131
132 kmp_nm_ord_static_chunked = 193,
133 kmp_nm_ord_static = 194,
134 kmp_nm_ord_dynamic_chunked = 195,
135 kmp_nm_ord_guided_chunked = 196,
136 kmp_nm_ord_runtime = 197,
137 kmp_nm_ord_auto = 198,
138 kmp_nm_ord_trapezoidal = 199,
139 kmp_nm_upper,
141 /* Support for OpenMP 4.5 monotonic and nonmonotonic schedule modifiers.
142 Since we need to distinguish the three possible cases (no modifier,
143 monotonic modifier, nonmonotonic modifier), we need separate bits for
144 each modifier. The absence of monotonic does not imply nonmonotonic,
145 especially since 4.5 says that the behaviour of the "no modifier" case is
146 implementation defined in 4.5, but will become "nonmonotonic" in 5.0.
147
148 Since we're passing a full 32 bit value, we can use a couple of high bits
149 for these flags; out of paranoia we avoid the sign bit.
150
151 These modifiers can be or-ed into non-static schedules by the compiler to
152 pass the additional information. They will be stripped early in the
153 processing in __kmp_dispatch_init when setting up schedules, so most of
154 the code won't ever see schedules with these bits set. */
155 kmp_sch_modifier_monotonic =
156 (1 << 29),
157 kmp_sch_modifier_nonmonotonic =
158 (1 << 30),
160#define SCHEDULE_WITHOUT_MODIFIERS(s) \
161 (enum sched_type)( \
162 (s) & ~(kmp_sch_modifier_nonmonotonic | kmp_sch_modifier_monotonic))
163#define SCHEDULE_HAS_MONOTONIC(s) (((s)&kmp_sch_modifier_monotonic) != 0)
164#define SCHEDULE_HAS_NONMONOTONIC(s) (((s)&kmp_sch_modifier_nonmonotonic) != 0)
165#define SCHEDULE_HAS_NO_MODIFIERS(s) \
166 (((s) & (kmp_sch_modifier_nonmonotonic | kmp_sch_modifier_monotonic)) == 0)
167#define SCHEDULE_GET_MODIFIERS(s) \
168 ((enum sched_type)( \
169 (s) & (kmp_sch_modifier_nonmonotonic | kmp_sch_modifier_monotonic)))
170#define SCHEDULE_SET_MODIFIERS(s, m) \
171 (s = (enum sched_type)((kmp_int32)s | (kmp_int32)m))
172#define SCHEDULE_NONMONOTONIC 0
173#define SCHEDULE_MONOTONIC 1
174
175 kmp_sch_default = kmp_sch_static
176};
177
178typedef void (*kmpc_micro)(kmp_int32 *global_tid, kmp_int32 *bound_tid, ...);
179
181// data
183
184extern _kmp_ptr32 *kmpc_args;
185
186#ifdef __cplusplus
187}
188#endif
189
190#endif /* KMP_H */
Definition interface.h:28
char const * psource
Definition interface.h:35
kmp_int32 reserved_1
Definition interface.h:29
kmp_int32 reserved_2
Definition interface.h:33
kmp_int32 reserved_3
Definition interface.h:34
kmp_int32 flags
Definition interface.h:30