[sanitizer] Improve FreeBSD ASLR detection
[llvm-project.git] / openmp / libomptarget / DeviceRTL / include / Mapping.h
blob4f65d28da513f69949cc0700d33e5293f5cd1eda
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 //===----------------------------------------------------------------------===//
12 #ifndef OMPTARGET_MAPPING_H
13 #define OMPTARGET_MAPPING_H
15 #include "Types.h"
17 namespace _OMP {
19 namespace mapping {
21 #pragma omp declare target
23 inline constexpr uint32_t MaxThreadsPerTeam = 1024;
25 #pragma omp end declare target
27 /// Initialize the mapping machinery.
28 void init(bool IsSPMD);
30 /// Return true if the kernel is executed in SPMD mode.
31 bool isSPMDMode();
33 /// Return true if the kernel is executed in generic mode.
34 bool isGenericMode();
36 /// Return true if the executing thread is the main thread in generic mode.
37 /// These functions will lookup state and it is required that that is OK for the
38 /// thread and location. See also `isInitialThreadInLevel0` for a stateless
39 /// alternative for certain situations, e.g. during initialization.
40 bool isMainThreadInGenericMode();
41 bool isMainThreadInGenericMode(bool IsSPMD);
43 /// Return true if this thread is the initial thread in parallel level 0.
44 ///
45 /// The thread for which this returns true should be used for single threaded
46 /// initialization tasks. We pick a special thread to ensure there are no
47 /// races between the initialization and the first read of initialized state.
48 bool isInitialThreadInLevel0(bool IsSPMD);
50 /// Return true if the executing thread has the lowest Id of the active threads
51 /// in the warp.
52 bool isLeaderInWarp();
54 /// Return a mask describing all active threads in the warp.
55 LaneMaskTy activemask();
57 /// Return a mask describing all threads with a smaller Id in the warp.
58 LaneMaskTy lanemaskLT();
60 /// Return a mask describing all threads with a larget Id in the warp.
61 LaneMaskTy lanemaskGT();
63 /// Return the thread Id in the warp, in [0, getWarpSize()).
64 uint32_t getThreadIdInWarp();
66 /// Return the thread Id in the block, in [0, getBlockSize()).
67 uint32_t getThreadIdInBlock();
69 /// Return the warp id in the block.
70 uint32_t getWarpId();
72 /// Return the warp size, thus number of threads in the warp.
73 uint32_t getWarpSize();
75 /// Return the number of warps in the block.
76 uint32_t getNumberOfWarpsInBlock();
78 /// Return the block Id in the kernel, in [0, getKernelSize()).
79 uint32_t getBlockId();
81 /// Return the block size, thus number of threads in the block.
82 uint32_t getBlockSize();
84 /// Return the number of blocks in the kernel.
85 uint32_t getNumberOfBlocks();
87 /// Return the kernel size, thus number of threads in the kernel.
88 uint32_t getKernelSize();
90 /// Return the number of processing elements on the device.
91 uint32_t getNumberOfProcessorElements();
93 } // namespace mapping
95 } // namespace _OMP
97 #endif