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