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 /// Get a pointer to the memory buffer containing dynamically allocated shared
178 /// memory configured at launch.
179 void *__kmpc_get_dynamic_shared();
180 
181 /// Allocate sufficient space for \p NumArgs sequential `void*` and store the
182 /// allocation address in \p GlobalArgs.
183 ///
184 /// Called by the main thread prior to a parallel region.
185 ///
186 /// We also remember it in GlobalArgsPtr to ensure the worker threads and
187 /// deallocation function know the allocation address too.
188 void __kmpc_begin_sharing_variables(void ***GlobalArgs, uint64_t NumArgs);
189 
190 /// Deallocate the memory allocated by __kmpc_begin_sharing_variables.
191 ///
192 /// Called by the main thread after a parallel region.
193 void __kmpc_end_sharing_variables();
194 
195 /// Store the allocation address obtained via __kmpc_begin_sharing_variables in
196 /// \p GlobalArgs.
197 ///
198 /// Called by the worker threads in the parallel region (function).
199 void __kmpc_get_shared_variables(void ***GlobalArgs);
200 
201 /// External interface to get the thread ID.
202 uint32_t __kmpc_get_hardware_thread_id_in_block();
203 
204 /// Kernel
205 ///
206 ///{
207 int8_t __kmpc_is_spmd_exec_mode();
208 
209 int32_t __kmpc_target_init(IdentTy *Ident, int8_t Mode,
210                            bool UseGenericStateMachine, bool);
211 
212 void __kmpc_target_deinit(IdentTy *Ident, int8_t Mode, bool);
213 
214 ///}
215 
216 /// Reduction
217 ///
218 ///{
219 void __kmpc_nvptx_end_reduce(int32_t TId);
220 
221 void __kmpc_nvptx_end_reduce_nowait(int32_t TId);
222 
223 int32_t __kmpc_nvptx_parallel_reduce_nowait_v2(
224     IdentTy *Loc, int32_t TId, int32_t num_vars, uint64_t reduce_size,
225     void *reduce_data, ShuffleReductFnTy shflFct, InterWarpCopyFnTy cpyFct);
226 
227 int32_t __kmpc_nvptx_teams_reduce_nowait_v2(
228     IdentTy *Loc, int32_t TId, void *GlobalBuffer, uint32_t num_of_records,
229     void *reduce_data, ShuffleReductFnTy shflFct, InterWarpCopyFnTy cpyFct,
230     ListGlobalFnTy lgcpyFct, ListGlobalFnTy lgredFct, ListGlobalFnTy glcpyFct,
231     ListGlobalFnTy glredFct);
232 ///}
233 
234 /// Synchronization
235 ///
236 ///{
237 void __kmpc_ordered(IdentTy *Loc, int32_t TId);
238 
239 void __kmpc_end_ordered(IdentTy *Loc, int32_t TId);
240 
241 int32_t __kmpc_cancel_barrier(IdentTy *Loc_ref, int32_t TId);
242 
243 void __kmpc_barrier(IdentTy *Loc_ref, int32_t TId);
244 
245 void __kmpc_barrier_simple_spmd(IdentTy *Loc_ref, int32_t TId);
246 
247 int32_t __kmpc_master(IdentTy *Loc, int32_t TId);
248 
249 void __kmpc_end_master(IdentTy *Loc, int32_t TId);
250 
251 int32_t __kmpc_single(IdentTy *Loc, int32_t TId);
252 
253 void __kmpc_end_single(IdentTy *Loc, int32_t TId);
254 
255 void __kmpc_flush(IdentTy *Loc);
256 
257 uint64_t __kmpc_warp_active_thread_mask(void);
258 
259 void __kmpc_syncwarp(uint64_t Mask);
260 
261 void __kmpc_critical(IdentTy *Loc, int32_t TId, CriticalNameTy *Name);
262 
263 void __kmpc_end_critical(IdentTy *Loc, int32_t TId, CriticalNameTy *Name);
264 ///}
265 
266 /// Parallelism
267 ///
268 ///{
269 /// TODO
270 void __kmpc_kernel_prepare_parallel(ParallelRegionFnTy WorkFn);
271 
272 /// TODO
273 bool __kmpc_kernel_parallel(ParallelRegionFnTy *WorkFn);
274 
275 /// TODO
276 void __kmpc_kernel_end_parallel();
277 
278 /// TODO
279 void __kmpc_serialized_parallel(IdentTy *Loc, uint32_t);
280 
281 /// TODO
282 void __kmpc_end_serialized_parallel(IdentTy *Loc, uint32_t);
283 
284 /// TODO
285 void __kmpc_push_proc_bind(IdentTy *Loc, uint32_t TId, int ProcBind);
286 
287 /// TODO
288 void __kmpc_push_num_teams(IdentTy *Loc, int32_t TId, int32_t NumTeams,
289                            int32_t ThreadLimit);
290 
291 /// TODO
292 uint16_t __kmpc_parallel_level(IdentTy *Loc, uint32_t);
293 
294 /// TODO
295 void __kmpc_push_num_threads(IdentTy *Loc, int32_t, int32_t NumThreads);
296 ///}
297 
298 /// Tasking
299 ///
300 ///{
301 TaskDescriptorTy *__kmpc_omp_task_alloc(IdentTy *, uint32_t, int32_t,
302                                         uint32_t TaskSizeInclPrivateValues,
303                                         uint32_t SharedValuesSize,
304                                         TaskFnTy TaskFn);
305 
306 int32_t __kmpc_omp_task(IdentTy *Loc, uint32_t TId,
307                         TaskDescriptorTy *TaskDescriptor);
308 
309 int32_t __kmpc_omp_task_with_deps(IdentTy *Loc, uint32_t TId,
310                                   TaskDescriptorTy *TaskDescriptor, int32_t,
311                                   void *, int32_t, void *);
312 
313 void __kmpc_omp_task_begin_if0(IdentTy *Loc, uint32_t TId,
314                                TaskDescriptorTy *TaskDescriptor);
315 
316 void __kmpc_omp_task_complete_if0(IdentTy *Loc, uint32_t TId,
317                                   TaskDescriptorTy *TaskDescriptor);
318 
319 void __kmpc_omp_wait_deps(IdentTy *Loc, uint32_t TId, int32_t, void *, int32_t,
320                           void *);
321 
322 void __kmpc_taskgroup(IdentTy *Loc, uint32_t TId);
323 
324 void __kmpc_end_taskgroup(IdentTy *Loc, uint32_t TId);
325 
326 int32_t __kmpc_omp_taskyield(IdentTy *Loc, uint32_t TId, int);
327 
328 int32_t __kmpc_omp_taskwait(IdentTy *Loc, uint32_t TId);
329 
330 void __kmpc_taskloop(IdentTy *Loc, uint32_t TId,
331                      TaskDescriptorTy *TaskDescriptor, int,
332                      uint64_t *LowerBound, uint64_t *UpperBound, int64_t, int,
333                      int32_t, uint64_t, void *);
334 ///}
335 
336 /// Misc
337 ///
338 ///{
339 int32_t __kmpc_cancellationpoint(IdentTy *Loc, int32_t TId, int32_t CancelVal);
340 
341 int32_t __kmpc_cancel(IdentTy *Loc, int32_t TId, int32_t CancelVal);
342 ///}
343 
344 /// Shuffle
345 ///
346 ///{
347 int32_t __kmpc_shuffle_int32(int32_t val, int16_t delta, int16_t size);
348 int64_t __kmpc_shuffle_int64(int64_t val, int16_t delta, int16_t size);
349 ///}
350 }
351 
352 #endif
353