19#ifdef ALPAKA_ACC_SYCL_ENABLED
21# include <sycl/sycl.hpp>
26 template<
typename TDim>
27 class WarpGenericSycl :
public interface::Implements<alpaka::warp::ConceptWarp, WarpGenericSycl<TDim>>
30 using mask_type = std::uint32_t;
32 WarpGenericSycl(sycl::nd_item<TDim::value> my_item) : m_item_warp{my_item}
36 sycl::nd_item<TDim::value> m_item_warp;
44# if ALPAKA_COMP_ICPX >= ALPAKA_VERSION_NUMBER(2026, 0, 0)
45 using sycl::ext::oneapi::experimental::this_work_item::get_opportunistic_group;
47 using sycl::ext::oneapi::experimental::this_kernel::get_opportunistic_group;
50 template<
typename TDim>
51 struct GetSize<warp::WarpGenericSycl<TDim>>
53 static auto getSize(warp::WarpGenericSycl<TDim>
const& warp) -> std::int32_t
55 auto const sub_group = warp.m_item_warp.get_sub_group();
57 return static_cast<std::int32_t
>(sub_group.get_max_local_range()[0]);
61 template<
typename TDim>
62 struct GetSizeCompileTime<warp::WarpGenericSycl<TDim>>
71 template<
typename TDim>
72 struct GetSizeUpperLimit<warp::WarpGenericSycl<TDim>>
81 template<
typename TDim>
82 struct Activemask<warp::WarpGenericSycl<TDim>>
87 static auto activemask(warp::WarpGenericSycl<TDim>
const& ) -> warp::WarpGenericSycl<TDim>::mask_type
89 sycl::sub_group sg = sycl::ext::oneapi::this_work_item::get_sub_group();
90 auto const mask = sycl::ext::oneapi::group_ballot(sg,
true);
91 std::uint32_t bits = 0;
92 mask.extract_bits(bits);
97 template<
typename TDim>
98 struct All<warp::WarpGenericSycl<TDim>>
100 static auto all(warp::WarpGenericSycl<TDim>
const& , std::int32_t predicate) -> std::int32_t
102 auto activegroup = get_opportunistic_group();
103 return static_cast<std::int32_t
>(sycl::all_of_group(activegroup,
static_cast<bool>(predicate)));
107 template<
typename TDim>
108 struct Any<warp::WarpGenericSycl<TDim>>
110 static auto any(warp::WarpGenericSycl<TDim>
const& , std::int32_t predicate) -> std::int32_t
112 auto activegroup = get_opportunistic_group();
113 return static_cast<std::int32_t
>(sycl::any_of_group(activegroup,
static_cast<bool>(predicate)));
117 template<
typename TDim>
118 struct Ballot<warp::WarpGenericSycl<TDim>>
123 static auto ballot(warp::WarpGenericSycl<TDim>
const& , std::int32_t predicate)
124 -> warp::WarpGenericSycl<TDim>::mask_type
126 auto sub_group = sycl::ext::oneapi::this_work_item::get_sub_group();
127 auto const mask = sycl::ext::oneapi::group_ballot(sub_group,
static_cast<bool>(predicate));
131 std::uint32_t bits = 0;
132 mask.extract_bits(bits);
137 template<
typename TDim>
138 struct Shfl<warp::WarpGenericSycl<TDim>>
142 warp::WarpGenericSycl<TDim>
const& ,
144 std::int32_t srcLane,
156 auto actual_group = get_opportunistic_group();
157 std::uint32_t
const w =
static_cast<std::uint32_t
>(width);
158 std::uint32_t
const start_index = actual_group.get_local_linear_id() / w * w;
159 return sycl::select_from_group(actual_group, value, start_index +
static_cast<std::uint32_t
>(srcLane) % w);
163 template<
typename TDim>
164 struct ShflUp<warp::WarpGenericSycl<TDim>>
168 warp::WarpGenericSycl<TDim>
const& ,
170 std::uint32_t offset,
173 auto actual_group = get_opportunistic_group();
174 std::uint32_t
const w =
static_cast<std::uint32_t
>(width);
175 std::uint32_t
const id = actual_group.get_local_linear_id();
176 std::uint32_t
const start_index =
id / w * w;
177 T result = sycl::shift_group_right(actual_group, value, offset);
178 if((
id - start_index) < offset)
186 template<
typename TDim>
187 struct ShflDown<warp::WarpGenericSycl<TDim>>
191 warp::WarpGenericSycl<TDim>
const& ,
193 std::uint32_t offset,
196 auto actual_group = get_opportunistic_group();
197 std::uint32_t
const w =
static_cast<std::uint32_t
>(width);
198 std::uint32_t
const id = actual_group.get_local_linear_id();
199 std::uint32_t
const end_index = (
id / w + 1) * w;
200 T result = sycl::shift_group_left(actual_group, value, offset);
201 if((
id + offset) >= end_index)
209 template<
typename TDim>
210 struct ShflXor<warp::WarpGenericSycl<TDim>>
214 warp::WarpGenericSycl<TDim>
const& ,
219 auto actual_group = get_opportunistic_group();
220 std::uint32_t
const w =
static_cast<std::uint32_t
>(width);
221 std::uint32_t
const id = actual_group.get_local_linear_id();
222 std::uint32_t
const start_index =
id / w * w;
223 std::uint32_t
const target_offset = (
id % w) ^
static_cast<std::uint32_t
>(mask);
224 return sycl::select_from_group(actual_group, value, target_offset < w ? start_index + target_offset : id);
#define ALPAKA_ASSERT_ACC(...)
ALPAKA_ASSERT_ACC is an assert-like macro.
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_ACC auto ballot(TWarp const &warp, std::int32_t predicate) -> typename TWarp::mask_type
Evaluates predicate for all non-exited threads in a warp and returns a 32- or 64-bit unsigned integer...
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 ...
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....
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...
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 ...
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....
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_ACC auto getSize(TWarp const &warp) -> std::int32_t
Returns warp size.
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...
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_ACC auto activemask(TWarp const &warp) -> typename TWarp::mask_type
Returns a 32- or 64-bit unsigned integer (depending on the accelerator) whose Nth bit is set if and o...
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.
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.