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