alpaka
Abstraction Library for Parallel Kernel Acceleration
WarpSingleThread.hpp
Go to the documentation of this file.
1 /* Copyright 2022 Sergei Bastrakov, David M. Rogers, Bernhard Manfred Gruber, Aurora Perego
2  * SPDX-License-Identifier: MPL-2.0
3  */
4 
5 #pragma once
6 
7 #include "alpaka/warp/Traits.hpp"
8 
9 #include <cstdint>
10 
11 namespace alpaka::warp
12 {
13  //! The single-threaded warp to emulate it on CPUs.
14  class WarpSingleThread : public concepts::Implements<ConceptWarp, WarpSingleThread>
15  {
16  };
17 
18  namespace trait
19  {
20  template<>
22  {
23  static auto getSize(warp::WarpSingleThread const& /*warp*/)
24  {
25  return 1;
26  }
27  };
28 
29  template<>
31  {
32  static auto activemask(warp::WarpSingleThread const& /*warp*/)
33  {
34  return 1u;
35  }
36  };
37 
38  template<>
40  {
41  static auto all(warp::WarpSingleThread const& /*warp*/, std::int32_t predicate)
42  {
43  return predicate;
44  }
45  };
46 
47  template<>
49  {
50  static auto any(warp::WarpSingleThread const& /*warp*/, std::int32_t predicate)
51  {
52  return predicate;
53  }
54  };
55 
56  template<>
58  {
59  static auto ballot(warp::WarpSingleThread const& /*warp*/, std::int32_t predicate)
60  {
61  return predicate ? 1u : 0u;
62  }
63  };
64 
65  template<>
67  {
68  template<typename T>
69  static auto shfl(
70  warp::WarpSingleThread const& /*warp*/,
71  T val,
72  std::int32_t /*srcLane*/,
73  std::int32_t /*width*/)
74  {
75  return val;
76  }
77  };
78 
79  template<>
81  {
82  template<typename T>
83  static auto shfl_up(
84  warp::WarpSingleThread const& /*warp*/,
85  T val,
86  std::uint32_t /*srcLane*/,
87  std::int32_t /*width*/)
88  {
89  return val;
90  }
91  };
92 
93  template<>
95  {
96  template<typename T>
97  static auto shfl_down(
98  warp::WarpSingleThread const& /*warp*/,
99  T val,
100  std::uint32_t /*srcLane*/,
101  std::int32_t /*width*/)
102  {
103  return val;
104  }
105  };
106 
107  template<>
109  {
110  template<typename T>
111  static auto shfl_xor(
112  warp::WarpSingleThread const& /*warp*/,
113  T val,
114  std::int32_t /*srcLane*/,
115  std::int32_t /*width*/)
116  {
117  return val;
118  }
119  };
120  } // namespace trait
121 } // namespace alpaka::warp
The single-threaded warp to emulate it on CPUs.
Tag used in class inheritance hierarchies that describes that a specific concept (TConcept) is implem...
Definition: Concepts.hpp:15
static auto activemask(warp::WarpSingleThread const &)
The active mask trait.
Definition: Traits.hpp:56
static auto all(warp::WarpSingleThread const &, std::int32_t predicate)
The all warp vote trait.
Definition: Traits.hpp:28
static auto any(warp::WarpSingleThread const &, std::int32_t predicate)
The any warp vote trait.
Definition: Traits.hpp:32
static auto ballot(warp::WarpSingleThread const &, std::int32_t predicate)
The ballot warp vote trait.
Definition: Traits.hpp:36
static auto getSize(warp::WarpSingleThread const &)
The warp size trait.
Definition: Traits.hpp:24
static auto shfl_down(warp::WarpSingleThread const &, T val, std::uint32_t, std::int32_t)
The shfl down warp swizzling trait.
Definition: Traits.hpp:48
static auto shfl_up(warp::WarpSingleThread const &, T val, std::uint32_t, std::int32_t)
The shfl up warp swizzling trait.
Definition: Traits.hpp:44
static auto shfl_xor(warp::WarpSingleThread const &, T val, std::int32_t, std::int32_t)
The shfl xor warp swizzling trait.
Definition: Traits.hpp:52
static auto shfl(warp::WarpSingleThread const &, T val, std::int32_t, std::int32_t)
The shfl warp swizzling trait.
Definition: Traits.hpp:40