Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libc / src / __support / GPU / utils.h
blob6505b18dbd331e378506024fff20ce0f9c654c05
1 //===---------------- Implementation of GPU utils ---------------*- 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 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIBC_SRC___SUPPORT_GPU_UTIL_H
10 #define LLVM_LIBC_SRC___SUPPORT_GPU_UTIL_H
12 #include "src/__support/macros/properties/architectures.h"
14 #if defined(LIBC_TARGET_ARCH_IS_AMDGPU)
15 #include "amdgpu/utils.h"
16 #elif defined(LIBC_TARGET_ARCH_IS_NVPTX)
17 #include "nvptx/utils.h"
18 #else
19 #include "generic/utils.h"
20 #endif
22 namespace LIBC_NAMESPACE {
23 namespace gpu {
24 /// Get the first active thread inside the lane.
25 LIBC_INLINE uint64_t get_first_lane_id(uint64_t lane_mask) {
26 return __builtin_ffsl(lane_mask) - 1;
29 /// Conditional that is only true for a single thread in a lane.
30 LIBC_INLINE bool is_first_lane(uint64_t lane_mask) {
31 return gpu::get_lane_id() == get_first_lane_id(lane_mask);
34 } // namespace gpu
35 } // namespace LIBC_NAMESPACE
37 #endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_IO_H