Ginkgo  Generated from pipelines/1589998975 branch based on develop. Ginkgo version 1.10.0
A numerical linear algebra library targeting many-core architectures
intrinsics.hpp
1 // SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
2 //
3 // SPDX-License-Identifier: BSD-3-Clause
4 
5 #ifndef GKO_PUBLIC_CORE_BASE_INTRINSICS_HPP_
6 #define GKO_PUBLIC_CORE_BASE_INTRINSICS_HPP_
7 
8 
9 #include <bitset>
10 
11 #include <ginkgo/core/base/types.hpp>
12 
13 
14 namespace gko {
15 namespace detail {
16 
17 
21 GKO_ATTRIBUTES GKO_INLINE int popcount(uint32 bitmask)
22 {
23 #if defined(__CUDA_ARCH__) || defined(__HIP_DEVICE_COMPILE__)
24  return __popc(bitmask);
25 #else
26  std::bitset<32> bits{bitmask};
27  return bits.count();
28 #endif
29 }
30 
31 
35 GKO_ATTRIBUTES GKO_INLINE int popcount(uint64 bitmask)
36 {
37 #if defined(__CUDA_ARCH__) || defined(__HIP_DEVICE_COMPILE__)
38  return __popcll(bitmask);
39 #else
40  std::bitset<64> bits{bitmask};
41  return bits.count();
42 #endif
43 }
44 
45 
46 } // namespace detail
47 } // namespace gko
48 
49 #endif // GKO_PUBLIC_CORE_BASE_INTRINSICS_HPP_
gko
The Ginkgo namespace.
Definition: abstract_factory.hpp:20
gko::uint32
std::uint32_t uint32
32-bit unsigned integral type.
Definition: types.hpp:129
gko::uint64
std::uint64_t uint64
64-bit unsigned integral type.
Definition: types.hpp:135