1 //===--------- Mapping.h - OpenMP device runtime mapping helpers -- 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_MAPPING_H 13 #define OMPTARGET_MAPPING_H 14 15 #include "Types.h" 16 17 namespace _OMP { 18 19 namespace mapping { 20 21 #pragma omp declare target 22 23 inline constexpr uint32_t MaxThreadsPerTeam = 1024; 24 25 #pragma omp end declare target 26 27 /// Initialize the mapping machinery. 28 void init(bool IsSPMD); 29 30 /// Return true if the kernel is executed in SPMD mode. 31 bool isSPMDMode(); 32 33 /// Return true if the kernel is executed in generic mode. 34 bool isGenericMode(); 35 36 /// Return true if the executing thread is the main thread in generic mode. 37 bool isMainThreadInGenericMode(); 38 39 /// Return true if the executing thread has the lowest Id of the active threads 40 /// in the warp. 41 bool isLeaderInWarp(); 42 43 /// Return a mask describing all active threads in the warp. 44 LaneMaskTy activemask(); 45 46 /// Return a mask describing all threads with a smaller Id in the warp. 47 LaneMaskTy lanemaskLT(); 48 49 /// Return a mask describing all threads with a larget Id in the warp. 50 LaneMaskTy lanemaskGT(); 51 52 /// Return the thread Id in the warp, in [0, getWarpSize()). 53 uint32_t getThreadIdInWarp(); 54 55 /// Return the thread Id in the block, in [0, getBlockSize()). 56 uint32_t getThreadIdInBlock(); 57 58 /// Return the warp id in the block. 59 uint32_t getWarpId(); 60 61 /// Return the warp size, thus number of threads in the warp. 62 uint32_t getWarpSize(); 63 64 /// Return the number of warps in the block. 65 uint32_t getNumberOfWarpsInBlock(); 66 67 /// Return the block Id in the kernel, in [0, getKernelSize()). 68 uint32_t getBlockId(); 69 70 /// Return the block size, thus number of threads in the block. 71 uint32_t getBlockSize(); 72 73 /// Return the number of blocks in the kernel. 74 uint32_t getNumberOfBlocks(); 75 76 /// Return the kernel size, thus number of threads in the kernel. 77 uint32_t getKernelSize(); 78 79 /// Return the number of processing elements on the device. 80 uint32_t getNumberOfProcessorElements(); 81 82 } // namespace mapping 83 84 } // namespace _OMP 85 86 #endif 87