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 void *llvm_omp_get_dynamic_shared();
136 
137 /// Synchronization
138 ///
139 ///{
140 void omp_init_lock(omp_lock_t *Lock);
141 
142 void omp_destroy_lock(omp_lock_t *Lock);
143 
144 void omp_set_lock(omp_lock_t *Lock);
145 
146 void omp_unset_lock(omp_lock_t *Lock);
147 
148 int omp_test_lock(omp_lock_t *Lock);
149 ///}
150 
151 /// Tasking
152 ///
153 ///{
154 int omp_in_final(void);
155 
156 int omp_get_max_task_priority(void);
157 ///}
158 
159 /// Misc
160 ///
161 ///{
162 double omp_get_wtick(void);
163 
164 double omp_get_wtime(void);
165 ///}
166 }
167 
168 extern "C" {
169 /// Allocate \p Bytes in "shareable" memory and return the address. Needs to be
170 /// called balanced with __kmpc_free_shared like a stack (push/pop). Can be
171 /// called by any thread, allocation happens *per thread*.
172 void *__kmpc_alloc_shared(uint64_t Bytes);
173 
174 /// Deallocate \p Ptr. Needs to be called balanced with __kmpc_alloc_shared like
175 /// a stack (push/pop). Can be called by any thread. \p Ptr has to be the
176 /// allocated by __kmpc_alloc_shared by the same thread.
177 void __kmpc_free_shared(void *Ptr, uint64_t Bytes);
178 
179 /// Get a pointer to the memory buffer containing dynamically allocated shared
180 /// memory configured at launch.
181 void *__kmpc_get_dynamic_shared();
182 
183 /// Allocate sufficient space for \p NumArgs sequential `void*` and store the
184 /// allocation address in \p GlobalArgs.
185 ///
186 /// Called by the main thread prior to a parallel region.
187 ///
188 /// We also remember it in GlobalArgsPtr to ensure the worker threads and
189 /// deallocation function know the allocation address too.
190 void __kmpc_begin_sharing_variables(void ***GlobalArgs, uint64_t NumArgs);
191 
192 /// Deallocate the memory allocated by __kmpc_begin_sharing_variables.
193 ///
194 /// Called by the main thread after a parallel region.
195 void __kmpc_end_sharing_variables();
196 
197 /// Store the allocation address obtained via __kmpc_begin_sharing_variables in
198 /// \p GlobalArgs.
199 ///
200 /// Called by the worker threads in the parallel region (function).
201 void __kmpc_get_shared_variables(void ***GlobalArgs);
202 
203 /// External interface to get the thread ID.
204 uint32_t __kmpc_get_hardware_thread_id_in_block();
205 
206 /// External interface to get the number of threads.
207 uint32_t __kmpc_get_hardware_num_threads_in_block();
208 
209 /// External interface to get the warp size.
210 uint32_t __kmpc_get_warp_size();
211 
212 /// Kernel
213 ///
214 ///{
215 int8_t __kmpc_is_spmd_exec_mode();
216 
217 int32_t __kmpc_target_init(IdentTy *Ident, int8_t Mode,
218                            bool UseGenericStateMachine, bool);
219 
220 void __kmpc_target_deinit(IdentTy *Ident, int8_t Mode, bool);
221 
222 ///}
223 
224 /// Reduction
225 ///
226 ///{
227 void __kmpc_nvptx_end_reduce(int32_t TId);
228 
229 void __kmpc_nvptx_end_reduce_nowait(int32_t TId);
230 
231 int32_t __kmpc_nvptx_parallel_reduce_nowait_v2(
232     IdentTy *Loc, int32_t TId, int32_t num_vars, uint64_t reduce_size,
233     void *reduce_data, ShuffleReductFnTy shflFct, InterWarpCopyFnTy cpyFct);
234 
235 int32_t __kmpc_nvptx_teams_reduce_nowait_v2(
236     IdentTy *Loc, int32_t TId, void *GlobalBuffer, uint32_t num_of_records,
237     void *reduce_data, ShuffleReductFnTy shflFct, InterWarpCopyFnTy cpyFct,
238     ListGlobalFnTy lgcpyFct, ListGlobalFnTy lgredFct, ListGlobalFnTy glcpyFct,
239     ListGlobalFnTy glredFct);
240 ///}
241 
242 /// Synchronization
243 ///
244 ///{
245 void __kmpc_ordered(IdentTy *Loc, int32_t TId);
246 
247 void __kmpc_end_ordered(IdentTy *Loc, int32_t TId);
248 
249 int32_t __kmpc_cancel_barrier(IdentTy *Loc_ref, int32_t TId);
250 
251 void __kmpc_barrier(IdentTy *Loc_ref, int32_t TId);
252 
253 void __kmpc_barrier_simple_spmd(IdentTy *Loc_ref, int32_t TId);
254 
255 void __kmpc_barrier_simple_generic(IdentTy *Loc_ref, int32_t TId);
256 
257 int32_t __kmpc_master(IdentTy *Loc, int32_t TId);
258 
259 void __kmpc_end_master(IdentTy *Loc, int32_t TId);
260 
261 int32_t __kmpc_single(IdentTy *Loc, int32_t TId);
262 
263 void __kmpc_end_single(IdentTy *Loc, int32_t TId);
264 
265 void __kmpc_flush(IdentTy *Loc);
266 
267 uint64_t __kmpc_warp_active_thread_mask(void);
268 
269 void __kmpc_syncwarp(uint64_t Mask);
270 
271 void __kmpc_critical(IdentTy *Loc, int32_t TId, CriticalNameTy *Name);
272 
273 void __kmpc_end_critical(IdentTy *Loc, int32_t TId, CriticalNameTy *Name);
274 ///}
275 
276 /// Parallelism
277 ///
278 ///{
279 /// TODO
280 void __kmpc_kernel_prepare_parallel(ParallelRegionFnTy WorkFn);
281 
282 /// TODO
283 bool __kmpc_kernel_parallel(ParallelRegionFnTy *WorkFn);
284 
285 /// TODO
286 void __kmpc_kernel_end_parallel();
287 
288 /// TODO
289 void __kmpc_push_proc_bind(IdentTy *Loc, uint32_t TId, int ProcBind);
290 
291 /// TODO
292 void __kmpc_push_num_teams(IdentTy *Loc, int32_t TId, int32_t NumTeams,
293                            int32_t ThreadLimit);
294 
295 /// TODO
296 uint16_t __kmpc_parallel_level(IdentTy *Loc, uint32_t);
297 
298 ///}
299 
300 /// Tasking
301 ///
302 ///{
303 TaskDescriptorTy *__kmpc_omp_task_alloc(IdentTy *, uint32_t, int32_t,
304                                         uint32_t TaskSizeInclPrivateValues,
305                                         uint32_t SharedValuesSize,
306                                         TaskFnTy TaskFn);
307 
308 int32_t __kmpc_omp_task(IdentTy *Loc, uint32_t TId,
309                         TaskDescriptorTy *TaskDescriptor);
310 
311 int32_t __kmpc_omp_task_with_deps(IdentTy *Loc, uint32_t TId,
312                                   TaskDescriptorTy *TaskDescriptor, int32_t,
313                                   void *, int32_t, void *);
314 
315 void __kmpc_omp_task_begin_if0(IdentTy *Loc, uint32_t TId,
316                                TaskDescriptorTy *TaskDescriptor);
317 
318 void __kmpc_omp_task_complete_if0(IdentTy *Loc, uint32_t TId,
319                                   TaskDescriptorTy *TaskDescriptor);
320 
321 void __kmpc_omp_wait_deps(IdentTy *Loc, uint32_t TId, int32_t, void *, int32_t,
322                           void *);
323 
324 void __kmpc_taskgroup(IdentTy *Loc, uint32_t TId);
325 
326 void __kmpc_end_taskgroup(IdentTy *Loc, uint32_t TId);
327 
328 int32_t __kmpc_omp_taskyield(IdentTy *Loc, uint32_t TId, int);
329 
330 int32_t __kmpc_omp_taskwait(IdentTy *Loc, uint32_t TId);
331 
332 void __kmpc_taskloop(IdentTy *Loc, uint32_t TId,
333                      TaskDescriptorTy *TaskDescriptor, int,
334                      uint64_t *LowerBound, uint64_t *UpperBound, int64_t, int,
335                      int32_t, uint64_t, void *);
336 ///}
337 
338 /// Misc
339 ///
340 ///{
341 int32_t __kmpc_cancellationpoint(IdentTy *Loc, int32_t TId, int32_t CancelVal);
342 
343 int32_t __kmpc_cancel(IdentTy *Loc, int32_t TId, int32_t CancelVal);
344 ///}
345 
346 /// Shuffle
347 ///
348 ///{
349 int32_t __kmpc_shuffle_int32(int32_t val, int16_t delta, int16_t size);
350 int64_t __kmpc_shuffle_int64(int64_t val, int16_t delta, int16_t size);
351 ///}
352 }
353 
354 #endif
355