Warning: This file is not a C or C++ file. It does not have highlighting.

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 "DeviceTypes.h"
16
17namespace ompx {
18
19namespace mapping {
20
21enum {
22 DIM_X = __GPU_X_DIM,
23 DIM_Y = __GPU_Y_DIM,
24 DIM_Z = __GPU_Z_DIM,
25};
26
27inline constexpr uint32_t MaxThreadsPerTeam = 1024;
28
29/// Initialize the mapping machinery.
30void init(bool IsSPMD);
31
32/// Return true if the kernel is executed in SPMD mode.
33bool isSPMDMode();
34
35/// Return true if the kernel is executed in generic mode.
36bool isGenericMode();
37
38/// Return true if the executing thread is the main thread in generic mode.
39/// These functions will lookup state and it is required that that is OK for the
40/// thread and location. See also `isInitialThreadInLevel0` for a stateless
41/// alternative for certain situations, e.g. during initialization.
42bool isMainThreadInGenericMode();
43bool isMainThreadInGenericMode(bool IsSPMD);
44
45/// Return true if this thread is the initial thread in parallel level 0.
46///
47/// The thread for which this returns true should be used for single threaded
48/// initialization tasks. We pick a special thread to ensure there are no
49/// races between the initialization and the first read of initialized state.
50bool isInitialThreadInLevel0(bool IsSPMD);
51
52/// Return true if the executing thread has the lowest Id of the active threads
53/// in the warp.
54bool isLeaderInWarp();
55
56/// Return a mask describing all active threads in the warp.
57LaneMaskTy activemask();
58
59/// Return a mask describing all threads with a smaller Id in the warp.
60LaneMaskTy lanemaskLT();
61
62/// Return a mask describing all threads with a larger Id in the warp.
63LaneMaskTy lanemaskGT();
64
65/// Return the thread Id in the warp, in [0, getWarpSize()).
66uint32_t getThreadIdInWarp();
67
68/// Return the warp size, thus number of threads in the warp.
69uint32_t getWarpSize();
70
71/// Return the warp id in the block, in [0, getNumberOfWarpsInBlock()]
72uint32_t getWarpIdInBlock();
73
74/// Return the number of warps in the block.
75uint32_t getNumberOfWarpsInBlock();
76
77/// Return the thread Id in the block, in [0, getNumberOfThreadsInBlock(Dim)).
78uint32_t getThreadIdInBlock(int32_t Dim = DIM_X);
79
80/// Return the block size, thus number of threads in the block.
81uint32_t getNumberOfThreadsInBlock(int32_t Dim = DIM_X);
82
83/// Return the block Id in the kernel, in [0, getNumberOfBlocksInKernel(Dim)).
84uint32_t getBlockIdInKernel(int32_t Dim = DIM_X);
85
86/// Return the number of blocks in the kernel.
87uint32_t getNumberOfBlocksInKernel(int32_t Dim = DIM_X);
88
89/// Return the kernel size, thus number of threads in the kernel.
90uint32_t getNumberOfThreadsInKernel();
91
92/// Return the maximal number of threads in the block usable for a team (=
93/// parallel region).
94///
95/// Note: The version taking \p IsSPMD mode explicitly can be used during the
96/// initialization of the target region, that is before `mapping::isSPMDMode()`
97/// can be called by any thread other than the main one.
98uint32_t getMaxTeamThreads();
99uint32_t getMaxTeamThreads(bool IsSPMD);
100
101/// Return the number of processing elements on the device.
102uint32_t getNumberOfProcessorElements();
103
104} // namespace mapping
105
106} // namespace ompx
107
108#endif
109

Warning: This file is not a C or C++ file. It does not have highlighting.

Provided by KDAB

Privacy Policy
Update your C++ knowledge – Modern C++11/14/17 Training
Find out more

source code of offload/DeviceRTL/include/Mapping.h