1 //===-------- Interface.h - OpenMP interface ---------------------- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 //
10 //===----------------------------------------------------------------------===//
11 
12 #ifndef OMPTARGET_DEVICERTL_INTERFACE_H
13 #define OMPTARGET_DEVICERTL_INTERFACE_H
14 
15 #include "Types.h"
16 
17 /// External API
18 ///
19 ///{
20 
21 extern "C" {
22 
23 /// ICV: dyn-var, constant 0
24 ///
25 /// setter: ignored.
26 /// getter: returns 0.
27 ///
28 ///{
29 void omp_set_dynamic(int);
30 int omp_get_dynamic(void);
31 ///}
32 
33 /// ICV: nthreads-var, integer
34 ///
35 /// scope: data environment
36 ///
37 /// setter: ignored.
38 /// getter: returns false.
39 ///
40 /// implementation notes:
41 ///
42 ///
43 ///{
44 void omp_set_num_threads(int);
45 int omp_get_max_threads(void);
46 ///}
47 
48 /// ICV: thread-limit-var, computed
49 ///
50 /// getter: returns thread limited defined during launch.
51 ///
52 ///{
53 int omp_get_thread_limit(void);
54 ///}
55 
56 /// ICV: max-active-level-var, constant 1
57 ///
58 /// setter: ignored.
59 /// getter: returns 1.
60 ///
61 ///{
62 void omp_set_max_active_levels(int);
63 int omp_get_max_active_levels(void);
64 ///}
65 
66 /// ICV: places-partition-var
67 ///
68 ///
69 ///{
70 ///}
71 
72 /// ICV: active-level-var, 0 or 1
73 ///
74 /// getter: returns 0 or 1.
75 ///
76 ///{
77 int omp_get_active_level(void);
78 ///}
79 
80 /// ICV: level-var
81 ///
82 /// getter: returns parallel region nesting
83 ///
84 ///{
85 int omp_get_level(void);
86 ///}
87 
88 /// ICV: run-sched-var
89 ///
90 ///
91 ///{
92 void omp_set_schedule(omp_sched_t, int);
93 void omp_get_schedule(omp_sched_t *, int *);
94 ///}
95 
96 /// TODO this is incomplete.
97 int omp_get_num_threads(void);
98 int omp_get_thread_num(void);
99 void omp_set_nested(int);
100 
101 int omp_get_nested(void);
102 
103 void omp_set_max_active_levels(int Level);
104 
105 int omp_get_max_active_levels(void);
106 
107 omp_proc_bind_t omp_get_proc_bind(void);
108 
109 int omp_get_num_places(void);
110 
111 int omp_get_place_num_procs(int place_num);
112 
113 void omp_get_place_proc_ids(int place_num, int *ids);
114 
115 int omp_get_place_num(void);
116 
117 int omp_get_partition_num_places(void);
118 
119 void omp_get_partition_place_nums(int *place_nums);
120 
121 int omp_get_cancellation(void);
122 
123 void omp_set_default_device(int deviceId);
124 
125 int omp_get_default_device(void);
126 
127 int omp_get_num_devices(void);
128 
129 int omp_get_num_teams(void);
130 
131 int omp_get_team_num();
132 
133 int omp_get_initial_device(void);
134 
135 /// Synchronization
136 ///
137 ///{
138 void omp_init_lock(omp_lock_t *Lock);
139 
140 void omp_destroy_lock(omp_lock_t *Lock);
141 
142 void omp_set_lock(omp_lock_t *Lock);
143 
144 void omp_unset_lock(omp_lock_t *Lock);
145 
146 int omp_test_lock(omp_lock_t *Lock);
147 ///}
148 
149 /// Tasking
150 ///
151 ///{
152 int omp_in_final(void);
153 
154 int omp_get_max_task_priority(void);
155 ///}
156 
157 /// Misc
158 ///
159 ///{
160 double omp_get_wtick(void);
161 
162 double omp_get_wtime(void);
163 ///}
164 }
165 
166 extern "C" {
167 /// Allocate \p Bytes in "shareable" memory and return the address. Needs to be
168 /// called balanced with __kmpc_free_shared like a stack (push/pop). Can be
169 /// called by any thread, allocation happens *per thread*.
170 void *__kmpc_alloc_shared(uint64_t Bytes);
171 
172 /// Deallocate \p Ptr. Needs to be called balanced with __kmpc_alloc_shared like
173 /// a stack (push/pop). Can be called by any thread. \p Ptr has to be the
174 /// allocated by __kmpc_alloc_shared by the same thread.
175 void __kmpc_free_shared(void *Ptr, uint64_t Bytes);
176 
177 /// Allocate sufficient space for \p NumArgs sequential `void*` and store the
178 /// allocation address in \p GlobalArgs.
179 ///
180 /// Called by the main thread prior to a parallel region.
181 ///
182 /// We also remember it in GlobalArgsPtr to ensure the worker threads and
183 /// deallocation function know the allocation address too.
184 void __kmpc_begin_sharing_variables(void ***GlobalArgs, uint64_t NumArgs);
185 
186 /// Deallocate the memory allocated by __kmpc_begin_sharing_variables.
187 ///
188 /// Called by the main thread after a parallel region.
189 void __kmpc_end_sharing_variables(void **GlobalArgs, uint64_t NumArgs);
190 
191 /// Store the allocation address obtained via __kmpc_begin_sharing_variables in
192 /// \p GlobalArgs.
193 ///
194 /// Called by the worker threads in the parallel region (function).
195 void __kmpc_get_shared_variables(void ***GlobalArgs);
196 
197 /// Kernel
198 ///
199 ///{
200 int8_t __kmpc_is_spmd_exec_mode();
201 
202 int32_t __kmpc_target_init(IdentTy *Ident, bool IsSPMD,
203                            bool UseGenericStateMachine, bool);
204 
205 void __kmpc_target_deinit(IdentTy *Ident, bool IsSPMD, bool);
206 
207 ///}
208 
209 /// Reduction
210 ///
211 ///{
212 void __kmpc_nvptx_end_reduce(int32_t TId);
213 
214 void __kmpc_nvptx_end_reduce_nowait(int32_t TId);
215 
216 int32_t __kmpc_nvptx_parallel_reduce_nowait_v2(
217     IdentTy *Loc, int32_t TId, int32_t num_vars, uint64_t reduce_size,
218     void *reduce_data, ShuffleReductFnTy shflFct, InterWarpCopyFnTy cpyFct);
219 
220 int32_t __kmpc_nvptx_teams_reduce_nowait_v2(
221     IdentTy *Loc, int32_t TId, void *GlobalBuffer, uint32_t num_of_records,
222     void *reduce_data, ShuffleReductFnTy shflFct, InterWarpCopyFnTy cpyFct,
223     ListGlobalFnTy lgcpyFct, ListGlobalFnTy lgredFct, ListGlobalFnTy glcpyFct,
224     ListGlobalFnTy glredFct);
225 ///}
226 
227 /// Synchronization
228 ///
229 ///{
230 void __kmpc_ordered(IdentTy *Loc, int32_t TId);
231 
232 void __kmpc_end_ordered(IdentTy *Loc, int32_t TId);
233 
234 int32_t __kmpc_cancel_barrier(IdentTy *Loc_ref, int32_t TId);
235 
236 void __kmpc_barrier(IdentTy *Loc_ref, int32_t TId);
237 
238 void __kmpc_barrier_simple_spmd(IdentTy *Loc_ref, int32_t TId);
239 
240 int32_t __kmpc_master(IdentTy *Loc, int32_t TId);
241 
242 void __kmpc_end_master(IdentTy *Loc, int32_t TId);
243 
244 int32_t __kmpc_single(IdentTy *Loc, int32_t TId);
245 
246 void __kmpc_end_single(IdentTy *Loc, int32_t TId);
247 
248 void __kmpc_flush(IdentTy *Loc);
249 
250 __kmpc_impl_lanemask_t __kmpc_warp_active_thread_mask();
251 
252 void __kmpc_syncwarp(__kmpc_impl_lanemask_t Mask);
253 
254 void __kmpc_critical(IdentTy *Loc, int32_t TId, CriticalNameTy *Name);
255 
256 void __kmpc_end_critical(IdentTy *Loc, int32_t TId, CriticalNameTy *Name);
257 ///}
258 
259 /// Parallelism
260 ///
261 ///{
262 /// TODO
263 void __kmpc_kernel_prepare_parallel(ParallelRegionFnTy WorkFn);
264 
265 /// TODO
266 bool __kmpc_kernel_parallel(ParallelRegionFnTy *WorkFn);
267 
268 /// TODO
269 void __kmpc_kernel_end_parallel();
270 
271 /// TODO
272 void __kmpc_serialized_parallel(IdentTy *Loc, uint32_t);
273 
274 /// TODO
275 void __kmpc_end_serialized_parallel(IdentTy *Loc, uint32_t);
276 
277 /// TODO
278 void __kmpc_push_proc_bind(IdentTy *Loc, uint32_t TId, int ProcBind);
279 
280 /// TODO
281 void __kmpc_push_num_teams(IdentTy *Loc, int32_t TId, int32_t NumTeams,
282                            int32_t ThreadLimit);
283 
284 /// TODO
285 uint16_t __kmpc_parallel_level(IdentTy *Loc, uint32_t);
286 
287 /// TODO
288 void __kmpc_push_num_threads(IdentTy *Loc, int32_t, int32_t NumThreads);
289 ///}
290 
291 /// Tasking
292 ///
293 ///{
294 TaskDescriptorTy *__kmpc_omp_task_alloc(IdentTy *, uint32_t, int32_t,
295                                         uint32_t TaskSizeInclPrivateValues,
296                                         uint32_t SharedValuesSize,
297                                         TaskFnTy TaskFn);
298 
299 int32_t __kmpc_omp_task(IdentTy *Loc, uint32_t TId,
300                         TaskDescriptorTy *TaskDescriptor);
301 
302 int32_t __kmpc_omp_task_with_deps(IdentTy *Loc, uint32_t TId,
303                                   TaskDescriptorTy *TaskDescriptor, int32_t,
304                                   void *, int32_t, void *);
305 
306 void __kmpc_omp_task_begin_if0(IdentTy *Loc, uint32_t TId,
307                                TaskDescriptorTy *TaskDescriptor);
308 
309 void __kmpc_omp_task_complete_if0(IdentTy *Loc, uint32_t TId,
310                                   TaskDescriptorTy *TaskDescriptor);
311 
312 void __kmpc_omp_wait_deps(IdentTy *Loc, uint32_t TId, int32_t, void *, int32_t,
313                           void *);
314 
315 void __kmpc_taskgroup(IdentTy *Loc, uint32_t TId);
316 
317 void __kmpc_end_taskgroup(IdentTy *Loc, uint32_t TId);
318 
319 int32_t __kmpc_omp_taskyield(IdentTy *Loc, uint32_t TId, int);
320 
321 int32_t __kmpc_omp_taskwait(IdentTy *Loc, uint32_t TId);
322 
323 void __kmpc_taskloop(IdentTy *Loc, uint32_t TId,
324                      TaskDescriptorTy *TaskDescriptor, int,
325                      uint64_t *LowerBound, uint64_t *UpperBound, int64_t, int,
326                      int32_t, uint64_t, void *);
327 ///}
328 
329 /// Misc
330 ///
331 ///{
332 int32_t __kmpc_cancellationpoint(IdentTy *Loc, int32_t TId, int32_t CancelVal);
333 
334 int32_t __kmpc_cancel(IdentTy *Loc, int32_t TId, int32_t CancelVal);
335 ///}
336 
337 /// Shuffle
338 ///
339 ///{
340 int32_t __kmpc_shuffle_int32(int32_t val, int16_t delta, int16_t size);
341 int64_t __kmpc_shuffle_int64(int64_t val, int16_t delta, int16_t size);
342 ///}
343 }
344 
345 #endif
346