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>();
78 shamalgs::ImplVariantGlobal<
80#ifdef SYCL2020_FEATURE_GROUP_REDUCTION
85 reduction_impl{[](
const sham::DeviceScheduler_ptr &,
auto &self) {
86#ifdef SYCL2020_FEATURE_GROUP_REDUCTION
87 self.set(GroupReduction{});
95 return reduction_impl.get_default_config_list();
106 shamlog_info_ln(
"algs",
"setting reduction implementation to impl :",
impl);
107 reduction_impl.set(
impl);
112 reduction_impl.autoselect(dev_sched);
115 "defaulting reduction implementation to impl :",
123 const sham::DeviceScheduler_ptr &sched,
128 using namespace shamalgs::reduction::details;
130 if (!impl::reduction_impl.is_set()) {
137 return sum_usm_fallback(sched, buf1, start_id, end_id);
139#ifdef SYCL2020_FEATURE_GROUP_REDUCTION
140 [&](impl::GroupReduction cfg) {
141 return sum_usm_group(sched, buf1, start_id, end_id, cfg.group_size);
145 impl::reduction_impl.get());
150 const sham::DeviceScheduler_ptr &sched,
155 using namespace shamalgs::reduction::details;
157 if (!impl::reduction_impl.is_set()) {
164 return min_usm_fallback(sched, buf1, start_id, end_id);
166#ifdef SYCL2020_FEATURE_GROUP_REDUCTION
167 [&](impl::GroupReduction cfg) {
168 return min_usm_group(sched, buf1, start_id, end_id, cfg.group_size);
172 impl::reduction_impl.get());
177 const sham::DeviceScheduler_ptr &sched,
182 using namespace shamalgs::reduction::details;
184 if (!impl::reduction_impl.is_set()) {
191 return max_usm_fallback(sched, buf1, start_id, end_id);
193#ifdef SYCL2020_FEATURE_GROUP_REDUCTION
194 [&](impl::GroupReduction cfg) {
195 return max_usm_group(sched, buf1, start_id, end_id, cfg.group_size);
199 impl::reduction_impl.get());
226 template _arg_ sum<_arg_>( \
227 const sham::DeviceScheduler_ptr &sched, \
228 const sham::DeviceBuffer<_arg_> &buf1, \
231 template _arg_ min<_arg_>( \
232 const sham::DeviceScheduler_ptr &sched, \
233 const sham::DeviceBuffer<_arg_> &buf1, \
236 template _arg_ max<_arg_>( \
237 const sham::DeviceScheduler_ptr &sched, \
238 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).
This header file contains utility functions related to exception handling in the code.
namespace to control implementation behavior
bool is_impl_set_reduction()
Check if an implementation has been selected for reduction.
void autoselect_impl_reduction(const sham::DeviceScheduler_ptr &dev_sched)
Select the default implementation for reduction.
std::string get_current_impl_reduction()
Get the current implementation for reduction, as a config json string.
std::vector< std::string > get_default_impl_list_reduction()
Get list of available reduction implementations, as config json strings.
void set_impl_reduction(const std::string &impl)
Set the implementation for reduction, from a config json string.
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.