alpaka
Abstraction Library for Parallel Kernel Acceleration
Traits.hpp
Go to the documentation of this file.
1 /* Copyright 2022 Sergei Bastrakov, Bernhard Manfred Gruber
2  * SPDX-License-Identifier: MPL-2.0
3  */
4 
5 #pragma once
6 
7 #include "alpaka/core/Common.hpp"
9 
10 #include <cstdint>
11 #include <type_traits>
12 
13 namespace alpaka
14 {
16  {
17  };
18 
19  //! The intrinsics traits.
20  namespace trait
21  {
22  //! The popcount trait.
23  template<typename TWarp, typename TSfinae = void>
24  struct Popcount;
25 
26  //! The ffs trait.
27  template<typename TWarp, typename TSfinae = void>
28  struct Ffs;
29  } // namespace trait
30 
31  //! Returns the number of 1 bits in the given 32-bit value.
32  //!
33  //! \tparam TIntrinsic The intrinsic implementation type.
34  //! \param intrinsic The intrinsic implementation.
35  //! \param value The input value.
37  template<typename TIntrinsic>
38  ALPAKA_FN_ACC auto popcount(TIntrinsic const& intrinsic, std::uint32_t value) -> std::int32_t
39  {
41  return trait::Popcount<ImplementationBase>::popcount(intrinsic, value);
42  }
43 
44  //! Returns the number of 1 bits in the given 64-bit value.
45  //!
46  //! \tparam TIntrinsic The intrinsic implementation type.
47  //! \param intrinsic The intrinsic implementation.
48  //! \param value The input value.
50  template<typename TIntrinsic>
51  ALPAKA_FN_ACC auto popcount(TIntrinsic const& intrinsic, std::uint64_t value) -> std::int32_t
52  {
54  return trait::Popcount<ImplementationBase>::popcount(intrinsic, value);
55  }
56 
57  //! Returns the 1-based position of the least significant bit set to 1
58  //! in the given 32-bit value. Returns 0 for input value 0.
59  //!
60  //! \tparam TIntrinsic The intrinsic implementation type.
61  //! \param intrinsic The intrinsic implementation.
62  //! \param value The input value.
64  template<typename TIntrinsic>
65  ALPAKA_FN_ACC auto ffs(TIntrinsic const& intrinsic, std::int32_t value) -> std::int32_t
66  {
68  return trait::Ffs<ImplementationBase>::ffs(intrinsic, value);
69  }
70 
71  //! Returns the 1-based position of the least significant bit set to 1
72  //! in the given 64-bit value. Returns 0 for input value 0.
73  //!
74  //! \tparam TIntrinsic The intrinsic implementation type.
75  //! \param intrinsic The intrinsic implementation.
76  //! \param value The input value.
78  template<typename TIntrinsic>
79  ALPAKA_FN_ACC auto ffs(TIntrinsic const& intrinsic, std::int64_t value) -> std::int32_t
80  {
82  return trait::Ffs<ImplementationBase>::ffs(intrinsic, value);
83  }
84 } // namespace alpaka
#define ALPAKA_FN_ACC
All functions that can be used on an accelerator have to be attributed with ALPAKA_FN_ACC or ALPAKA_F...
Definition: Common.hpp:38
#define ALPAKA_NO_HOST_ACC_WARNING
Disable nvcc warning: 'calling a host function from host device function.' Usage: ALPAKA_NO_HOST_ACC_...
Definition: Common.hpp:82
typename detail::ImplementationBaseType< TConcept, TDerived >::type ImplementationBase
Returns the type that implements the given concept in the inheritance hierarchy.
Definition: Concepts.hpp:66
The alpaka accelerator library.
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_ACC auto popcount(TIntrinsic const &intrinsic, std::uint64_t value) -> std::int32_t
Returns the number of 1 bits in the given 64-bit value.
Definition: Traits.hpp:51
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_ACC auto ffs(TIntrinsic const &intrinsic, std::int64_t value) -> std::int32_t
Returns the 1-based position of the least significant bit set to 1 in the given 64-bit value....
Definition: Traits.hpp:79
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_ACC auto ffs(TIntrinsic const &intrinsic, std::int32_t value) -> std::int32_t
Returns the 1-based position of the least significant bit set to 1 in the given 32-bit value....
Definition: Traits.hpp:65
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_ACC auto popcount(TIntrinsic const &intrinsic, std::uint32_t value) -> std::int32_t
Returns the number of 1 bits in the given 32-bit value.
Definition: Traits.hpp:38
The ffs trait.
Definition: Traits.hpp:28
The popcount trait.
Definition: Traits.hpp:24