alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
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
8
9#include <cstdint>
10
11namespace alpaka::warp
12{
13 //! The single-threaded warp to emulate it on CPUs.
14 class WarpSingleThread : public interface::Implements<ConceptWarp, WarpSingleThread>
15 {
16 };
17
18 namespace trait
19 {
20 template<>
21 struct GetSize<WarpSingleThread>
22 {
23 static auto getSize(warp::WarpSingleThread const& /*warp*/) -> std::int32_t
24 {
25 return 1;
26 }
27 };
28
29 template<>
30 struct GetSizeCompileTime<WarpSingleThread>
31 {
32 static constexpr auto getSizeCompileTime() -> std::int32_t
33 {
34 return 1;
35 }
36 };
37
38 template<>
39 struct GetSizeUpperLimit<WarpSingleThread>
40 {
41 static constexpr auto getSizeUpperLimit() -> std::int32_t
42 {
43 return 1;
44 }
45 };
46
47 template<>
48 struct Activemask<WarpSingleThread>
49 {
50 static auto activemask(warp::WarpSingleThread const& /*warp*/)
51 {
52 return 1u;
53 }
54 };
55
56 template<>
57 struct All<WarpSingleThread>
58 {
59 static auto all(warp::WarpSingleThread const& /*warp*/, std::int32_t predicate)
60 {
61 return predicate;
62 }
63 };
64
65 template<>
66 struct Any<WarpSingleThread>
67 {
68 static auto any(warp::WarpSingleThread const& /*warp*/, std::int32_t predicate)
69 {
70 return predicate;
71 }
72 };
73
74 template<>
75 struct Ballot<WarpSingleThread>
76 {
77 static auto ballot(warp::WarpSingleThread const& /*warp*/, std::int32_t predicate)
78 {
79 return predicate ? 1u : 0u;
80 }
81 };
82
83 template<>
84 struct Shfl<WarpSingleThread>
85 {
86 template<typename T>
87 static auto shfl(
88 warp::WarpSingleThread const& /*warp*/,
89 T val,
90 std::int32_t /*srcLane*/,
91 std::int32_t /*width*/)
92 {
93 return val;
94 }
95 };
96
97 template<>
98 struct ShflUp<WarpSingleThread>
99 {
100 template<typename T>
101 static auto shfl_up(
102 warp::WarpSingleThread const& /*warp*/,
103 T val,
104 std::uint32_t /*srcLane*/,
105 std::int32_t /*width*/)
106 {
107 return val;
108 }
109 };
110
111 template<>
112 struct ShflDown<WarpSingleThread>
113 {
114 template<typename T>
115 static auto shfl_down(
116 warp::WarpSingleThread const& /*warp*/,
117 T val,
118 std::uint32_t /*srcLane*/,
119 std::int32_t /*width*/)
120 {
121 return val;
122 }
123 };
124
125 template<>
126 struct ShflXor<WarpSingleThread>
127 {
128 template<typename T>
129 static auto shfl_xor(
130 warp::WarpSingleThread const& /*warp*/,
131 T val,
132 std::int32_t /*srcLane*/,
133 std::int32_t /*width*/)
134 {
135 return val;
136 }
137 };
138 } // namespace trait
139} // namespace alpaka::warp
The single-threaded warp to emulate it on CPUs.
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_ACC auto all(TWarp const &warp, std::int32_t predicate) -> std::int32_t
Evaluates predicate for all active threads of the warp and returns non-zero if and only if predicate ...
Definition Traits.hpp:145
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_ACC auto ballot(TWarp const &warp, std::int32_t predicate)
Evaluates predicate for all non-exited threads in a warp and returns a 32- or 64-bit unsigned integer...
Definition Traits.hpp:195
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_ACC auto shfl_up(TWarp const &warp, T value, std::uint32_t offset, std::int32_t width=0)
Exchange data between threads within a warp. It copies from a lane with lower ID relative to caller....
Definition Traits.hpp:267
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_ACC auto activemask(TWarp const &warp) -> decltype(trait::Activemask< interface::ImplementationBase< ConceptWarp, TWarp > >::activemask(warp))
Returns a 32- or 64-bit unsigned integer (depending on the accelerator) whose Nth bit is set if and o...
Definition Traits.hpp:121
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_ACC constexpr auto getSizeUpperLimit() -> std::int32_t
If the warp size is available as a compile-time constant returns its value; otherwise returns an uppe...
Definition Traits.hpp:96
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_ACC auto any(TWarp const &warp, std::int32_t predicate) -> std::int32_t
Evaluates predicate for all active threads of the warp and returns non-zero if and only if predicate ...
Definition Traits.hpp:168
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_ACC auto shfl_down(TWarp const &warp, T value, std::uint32_t offset, std::int32_t width=0)
Exchange data between threads within a warp. It copies from a lane with higher ID relative to caller....
Definition Traits.hpp:305
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_ACC auto getSize(TWarp const &warp) -> std::int32_t
Returns warp size.
Definition Traits.hpp:73
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_ACC auto shfl_xor(TWarp const &warp, T value, std::int32_t mask, std::int32_t width=0)
Exchange data between threads within a warp. It copies from a lane based on bitwise XOR of own lane I...
Definition Traits.hpp:343
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_ACC constexpr auto getSizeCompileTime() -> std::int32_t
If the warp size is available as a compile-time constant returns its value; otherwise returns 0.
Definition Traits.hpp:84
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_ACC auto shfl(TWarp const &warp, T value, std::int32_t srcLane, std::int32_t width=0)
Exchange data between threads within a warp.
Definition Traits.hpp:229
Tag used in class inheritance hierarchies that describes that a specific interface (TInterface) is im...
Definition Interface.hpp:15