371 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8//9//10//===----------------------------------------------------------------------===//11 12#ifndef OMPTARGET_DEVICERTL_INTERFACE_H13#define OMPTARGET_DEVICERTL_INTERFACE_H14 15#include "Shared/Environment.h"16 17#include "DeviceTypes.h"18 19/// External API20///21///{22 23extern "C" {24 25/// ICV: dyn-var, constant 026///27/// setter: ignored.28/// getter: returns 0.29///30///{31void omp_set_dynamic(int);32int omp_get_dynamic(void);33///}34 35/// ICV: nthreads-var, integer36///37/// scope: data environment38///39/// setter: ignored.40/// getter: returns false.41///42/// implementation notes:43///44///45///{46void omp_set_num_threads(int);47int omp_get_max_threads(void);48///}49 50/// ICV: thread-limit-var, computed51///52/// getter: returns thread limited defined during launch.53///54///{55int omp_get_thread_limit(void);56///}57 58/// ICV: max-active-level-var, constant 159///60/// setter: ignored.61/// getter: returns 1.62///63///{64void omp_set_max_active_levels(int);65int omp_get_max_active_levels(void);66///}67 68/// ICV: places-partition-var69///70///71///{72///}73 74/// ICV: active-level-var, 0 or 175///76/// getter: returns 0 or 1.77///78///{79int omp_get_active_level(void);80///}81 82/// ICV: level-var83///84/// getter: returns parallel region nesting85///86///{87int omp_get_level(void);88///}89 90/// ICV: run-sched-var91///92///93///{94void omp_set_schedule(omp_sched_t, int);95void omp_get_schedule(omp_sched_t *, int *);96///}97 98/// TODO this is incomplete.99int omp_get_num_threads(void);100int omp_get_thread_num(void);101void omp_set_nested(int);102 103int omp_get_nested(void);104 105void omp_set_max_active_levels(int Level);106 107int omp_get_max_active_levels(void);108 109omp_proc_bind_t omp_get_proc_bind(void);110 111int omp_get_num_places(void);112 113int omp_get_place_num_procs(int place_num);114 115void omp_get_place_proc_ids(int place_num, int *ids);116 117int omp_get_place_num(void);118 119int omp_get_partition_num_places(void);120 121void omp_get_partition_place_nums(int *place_nums);122 123int omp_get_cancellation(void);124 125void omp_set_default_device(int deviceId);126 127int omp_get_default_device(void);128 129int omp_get_num_devices(void);130 131int omp_get_device_num(void);132 133int omp_get_device_from_uid(const char *DeviceUid);134 135const char *omp_get_uid_from_device(int DeviceNum);136 137int omp_get_num_teams(void);138 139int omp_get_team_num();140 141int omp_get_initial_device(void);142 143void *llvm_omp_target_dynamic_shared_alloc();144 145/// Synchronization146///147///{148void omp_init_lock(omp_lock_t *Lock);149 150void omp_destroy_lock(omp_lock_t *Lock);151 152void omp_set_lock(omp_lock_t *Lock);153 154void omp_unset_lock(omp_lock_t *Lock);155 156int omp_test_lock(omp_lock_t *Lock);157///}158 159/// Tasking160///161///{162int omp_in_final(void);163 164int omp_get_max_task_priority(void);165///}166 167/// Misc168///169///{170double omp_get_wtick(void);171 172double omp_get_wtime(void);173///}174}175 176extern "C" {177/// Allocate \p Bytes in "shareable" memory and return the address. Needs to be178/// called balanced with __kmpc_free_shared like a stack (push/pop). Can be179/// called by any thread, allocation happens *per thread*.180void *__kmpc_alloc_shared(uint64_t Bytes);181 182/// Deallocate \p Ptr. Needs to be called balanced with __kmpc_alloc_shared like183/// a stack (push/pop). Can be called by any thread. \p Ptr has to be the184/// allocated by __kmpc_alloc_shared by the same thread.185void __kmpc_free_shared(void *Ptr, uint64_t Bytes);186 187/// Get a pointer to the memory buffer containing dynamically allocated shared188/// memory configured at launch.189void *__kmpc_get_dynamic_shared();190 191/// Allocate sufficient space for \p NumArgs sequential `void*` and store the192/// 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 and197/// deallocation function know the allocation address too.198void __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.203void __kmpc_end_sharing_variables();204 205/// Store the allocation address obtained via __kmpc_begin_sharing_variables in206/// \p GlobalArgs.207///208/// Called by the worker threads in the parallel region (function).209void __kmpc_get_shared_variables(void ***GlobalArgs);210 211/// External interface to get the thread ID.212uint32_t __kmpc_get_hardware_thread_id_in_block();213 214/// External interface to get the number of threads.215uint32_t __kmpc_get_hardware_num_threads_in_block();216 217/// External interface to get the warp size.218uint32_t __kmpc_get_warp_size();219 220/// Kernel221///222///{223// Forward declaration224struct KernelEnvironmentTy;225 226int8_t __kmpc_is_spmd_exec_mode();227 228int32_t __kmpc_target_init(KernelEnvironmentTy &KernelEnvironment,229 KernelLaunchEnvironmentTy &KernelLaunchEnvironment);230 231void __kmpc_target_deinit();232 233///}234 235/// Reduction236///237///{238void *__kmpc_reduction_get_fixed_buffer();239 240int32_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 246int32_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/// Synchronization254///255///{256void __kmpc_ordered(IdentTy *Loc, int32_t TId);257 258void __kmpc_end_ordered(IdentTy *Loc, int32_t TId);259 260int32_t __kmpc_cancel_barrier(IdentTy *Loc_ref, int32_t TId);261 262void __kmpc_barrier(IdentTy *Loc_ref, int32_t TId);263 264void __kmpc_barrier_simple_spmd(IdentTy *Loc_ref, int32_t TId);265 266void __kmpc_barrier_simple_generic(IdentTy *Loc_ref, int32_t TId);267 268int32_t __kmpc_master(IdentTy *Loc, int32_t TId);269 270void __kmpc_end_master(IdentTy *Loc, int32_t TId);271 272int32_t __kmpc_masked(IdentTy *Loc, int32_t TId, int32_t Filter);273 274void __kmpc_end_masked(IdentTy *Loc, int32_t TId);275 276int32_t __kmpc_single(IdentTy *Loc, int32_t TId);277 278void __kmpc_end_single(IdentTy *Loc, int32_t TId);279 280void __kmpc_flush(IdentTy *Loc);281 282uint64_t __kmpc_warp_active_thread_mask(void);283 284void __kmpc_syncwarp(uint64_t Mask);285 286void __kmpc_critical(IdentTy *Loc, int32_t TId, CriticalNameTy *Name);287 288void __kmpc_end_critical(IdentTy *Loc, int32_t TId, CriticalNameTy *Name);289///}290 291/// Parallelism292///293///{294/// TODO295void __kmpc_kernel_prepare_parallel(ParallelRegionFnTy WorkFn);296 297/// TODO298bool __kmpc_kernel_parallel(ParallelRegionFnTy *WorkFn);299 300/// TODO301void __kmpc_kernel_end_parallel();302 303/// TODO304void __kmpc_push_proc_bind(IdentTy *Loc, uint32_t TId, int ProcBind);305 306/// TODO307void __kmpc_push_num_teams(IdentTy *Loc, int32_t TId, int32_t NumTeams,308 int32_t ThreadLimit);309 310/// TODO311uint16_t __kmpc_parallel_level(IdentTy *Loc, uint32_t);312 313///}314 315/// Tasking316///317///{318TaskDescriptorTy *__kmpc_omp_task_alloc(IdentTy *, int32_t, int32_t,319 size_t TaskSizeInclPrivateValues,320 size_t SharedValuesSize,321 TaskFnTy TaskFn);322 323int32_t __kmpc_omp_task(IdentTy *Loc, uint32_t TId,324 TaskDescriptorTy *TaskDescriptor);325 326int32_t __kmpc_omp_task_with_deps(IdentTy *Loc, uint32_t TId,327 TaskDescriptorTy *TaskDescriptor, int32_t,328 void *, int32_t, void *);329 330void __kmpc_omp_task_begin_if0(IdentTy *Loc, uint32_t TId,331 TaskDescriptorTy *TaskDescriptor);332 333void __kmpc_omp_task_complete_if0(IdentTy *Loc, uint32_t TId,334 TaskDescriptorTy *TaskDescriptor);335 336void __kmpc_omp_wait_deps(IdentTy *Loc, uint32_t TId, int32_t, void *, int32_t,337 void *);338 339void __kmpc_taskgroup(IdentTy *Loc, uint32_t TId);340 341void __kmpc_end_taskgroup(IdentTy *Loc, uint32_t TId);342 343int32_t __kmpc_omp_taskyield(IdentTy *Loc, uint32_t TId, int);344 345int32_t __kmpc_omp_taskwait(IdentTy *Loc, uint32_t TId);346 347void __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/// Misc354///355///{356int32_t __kmpc_cancellationpoint(IdentTy *Loc, int32_t TId, int32_t CancelVal);357 358int32_t __kmpc_cancel(IdentTy *Loc, int32_t TId, int32_t CancelVal);359///}360 361/// Shuffle362///363///{364int32_t __kmpc_shuffle_int32(int32_t val, int16_t delta, int16_t size);365int64_t __kmpc_shuffle_int64(int64_t val, int16_t delta, int16_t size);366 367///}368}369 370#endif371