35 static constexpr std::string_view variant_type_name =
"fallback";
38#ifdef SYCL2020_FEATURE_GROUP_REDUCTION
40 struct GroupReduction {
41 static constexpr std::string_view variant_type_name =
"group_reduction";
45 static std::vector<GroupReduction> variant_custom_defaults() {
57#ifdef SYCL2020_FEATURE_GROUP_REDUCTION
60 static nlohmann::json
to_json(
const shamalgs::primitives::impl::GroupReduction &p) {
61 return {{
"group_size", p.group_size}};
63 static shamalgs::primitives::impl::GroupReduction
from_json(
const nlohmann::json &j) {
64 shamalgs::primitives::impl::GroupReduction p{};
65 if (j.contains(
"group_size")) {
66 p.group_size = j.at(
"group_size").get<
u32>();
83#ifdef SYCL2020_FEATURE_GROUP_REDUCTION
88 reduction_impl{[](
const sham::DeviceScheduler_ptr &,
auto &self) {
89#ifdef SYCL2020_FEATURE_GROUP_REDUCTION
90 self.set(GroupReduction{});
103 const sham::DeviceScheduler_ptr &sched,
108 using namespace shamalgs::reduction::details;
110 if (!impl::reduction_impl.is_set()) {
117 return sum_usm_fallback(sched, buf1, start_id, end_id);
119#ifdef SYCL2020_FEATURE_GROUP_REDUCTION
120 [&](impl::GroupReduction cfg) {
121 return sum_usm_group(sched, buf1, start_id, end_id, cfg.group_size);
125 impl::reduction_impl.get());
130 const sham::DeviceScheduler_ptr &sched,
135 using namespace shamalgs::reduction::details;
137 if (!impl::reduction_impl.is_set()) {
144 return min_usm_fallback(sched, buf1, start_id, end_id);
146#ifdef SYCL2020_FEATURE_GROUP_REDUCTION
147 [&](impl::GroupReduction cfg) {
148 return min_usm_group(sched, buf1, start_id, end_id, cfg.group_size);
152 impl::reduction_impl.get());
157 const sham::DeviceScheduler_ptr &sched,
162 using namespace shamalgs::reduction::details;
164 if (!impl::reduction_impl.is_set()) {
171 return max_usm_fallback(sched, buf1, start_id, end_id);
173#ifdef SYCL2020_FEATURE_GROUP_REDUCTION
174 [&](impl::GroupReduction cfg) {
175 return max_usm_group(sched, buf1, start_id, end_id, cfg.group_size);
179 impl::reduction_impl.get());
206 template _arg_ sum<_arg_>( \
207 const sham::DeviceScheduler_ptr &sched, \
208 const sham::DeviceBuffer<_arg_> &buf1, \
211 template _arg_ min<_arg_>( \
212 const sham::DeviceScheduler_ptr &sched, \
213 const sham::DeviceBuffer<_arg_> &buf1, \
216 template _arg_ max<_arg_>( \
217 const sham::DeviceScheduler_ptr &sched, \
218 const sham::DeviceBuffer<_arg_> &buf1, \
Generic std::variant-based implementation selector.
std::uint32_t u32
32 bit unsigned integer
A buffer allocated in USM (Unified Shared Memory).
Drop-in replacement for the hand-rolled "global variable + enum + name mapping.
This header file contains utility functions related to exception handling in the code.
Name-keyed registry of the implementation selectors (IImplVariant) of every algorithm.
#define SHAMALGS_REGISTER_IMPL(name, impl)
Register the implementation selector impl under name at static initialization.
void autoselect_impl(std::string_view alg, const sham::DeviceScheduler_ptr &sched)
Select the default implementation of alg for the device behind sched.
namespace to control implementation behavior
constexpr std::string_view reduction_impl_name
Registry name, shared by its registration and the dispatch site(s).
namespace for primitive algorithm (e.g. sort, scan, reductions, ...)
T sum(const sham::DeviceScheduler_ptr &sched, const sham::DeviceBuffer< T > &buf1, u32 start_id, u32 end_id)
Compute the sum of elements in a device buffer within a specified range.
T min(const sham::DeviceScheduler_ptr &sched, const sham::DeviceBuffer< T > &buf1, u32 start_id, u32 end_id)
Find the minimum element in a device buffer within a specified range.
T max(const sham::DeviceScheduler_ptr &sched, const sham::DeviceBuffer< T > &buf1, u32 start_id, u32 end_id)
Find the maximum element in a device buffer within a specified range.
namespace to contain everything implemented by shamalgs
Customization point controlling how an alternative's fields (if any) are serialized to / parsed from ...
static Alt from_json(const nlohmann::json &)
Parse the alternative's fields back (default: no fields, ignored).
static nlohmann::json to_json(const Alt &)
Serialize the alternative's fields (default: no fields, empty object).
Fallback USM reduction (portable, no group reduction support required).
Build an overload set out of several callables, for use with std::visit.