28#if defined(__has_include)
29 #if __has_include(<AdaptiveCpp/algorithms/numeric.hpp>)
30 #include <AdaptiveCpp/algorithms/numeric.hpp>
31 #define ACPP_ALG_AVAILABLE
39 void scan_exclusive_sum_in_place_std_scan_single_task_acpp(
44 sycl::queue &q_s = q.q;
50 auto e = q.submit(deps, [&](sycl::handler &cgh) {
51 cgh.single_task([=]() {
52 std::exclusive_scan(in_out_ptr, in_out_ptr + len, in_out_ptr, T{});
59 std::exclusive_scan(acc_src.begin(), acc_src.end(), acc_src.begin(), T{});
68 std::exclusive_scan(acc_src.begin(), acc_src.end(), acc_src.begin(), 0);
72#ifdef SYCL2020_FEATURE_GROUP_REDUCTION
75 shamalgs::numeric::details::exclusive_sum_atomic_decoupled_v5_usm_in_place<T, 512>(
80#ifdef ACPP_ALG_AVAILABLE
85 acpp::algorithms::util::allocation_cache cache{
86 acpp::algorithms::util::allocation_type::device};
87 acpp::algorithms::util::allocation_group scratch{&cache, q.get_device()};
93 T *temp_ptr = temp.get_write_access(deps);
95 sycl::event e = adaptivecpp::algorithms::exclusive_scan(
96 q, scratch, in_out_ptr, in_out_ptr + len, temp_ptr, T{}, deps.
get_events());
100 temp.complete_event_state(e);
114 static constexpr std::string_view variant_type_name =
"std_scan";
120 struct StdScanSingleTaskAcpp {
121 static constexpr std::string_view variant_type_name =
"std_scan_single_task_acpp";
125#ifdef SYCL2020_FEATURE_GROUP_REDUCTION
127 struct DecoupledLookback512 {
128 static constexpr std::string_view variant_type_name =
"decoupled_lookback_512";
132#ifdef ACPP_ALG_AVAILABLE
134 struct AdaptiveCppAlg {
135 static constexpr std::string_view variant_type_name =
"acpp_alg";
143 StdScanSingleTaskAcpp
145#ifdef SYCL2020_FEATURE_GROUP_REDUCTION
149#ifdef ACPP_ALG_AVAILABLE
154 scan_exclusive_sum_in_place_impl{[](
const sham::DeviceScheduler_ptr &,
auto &self) {
157 self.set(StdScanSingleTaskAcpp{});
162 #ifdef SYCL2020_FEATURE_GROUP_REDUCTION
163 self.set(DecoupledLookback512{});
172 return scan_exclusive_sum_in_place_impl.get_default_config_list();
177 return scan_exclusive_sum_in_place_impl.get_current_config();
182 return scan_exclusive_sum_in_place_impl.is_set();
188 "algs",
"setting scan_exclusive_sum_in_place implementation to impl :",
impl);
189 scan_exclusive_sum_in_place_impl.set(
impl);
194 const sham::DeviceScheduler_ptr &dev_sched) {
195 scan_exclusive_sum_in_place_impl.autoselect(dev_sched);
198 "defaulting scan_exclusive_sum_in_place implementation to impl :",
213 "The buffer is smaller than the length of the scan\n"
214 "len > buf1.get_size(), len = {}, buf1.get_size() = {}",
219 if (!impl::scan_exclusive_sum_in_place_impl.is_set()) {
226 scan_exclusive_sum_in_place_fallback(buf1, len);
229 [&](impl::StdScanSingleTaskAcpp) {
230 scan_exclusive_sum_in_place_std_scan_single_task_acpp(buf1, len);
233#ifdef SYCL2020_FEATURE_GROUP_REDUCTION
234 [&](impl::DecoupledLookback512) {
235 scan_exclusive_sum_in_place_decoupled_lookback_512(buf1, len);
238#ifdef ACPP_ALG_AVAILABLE
239 [&](impl::AdaptiveCppAlg) {
240 scan_exclusive_sum_in_place_adaptivecpp(buf1, len);
244 impl::scan_exclusive_sum_in_place_impl.get());
Generic std::variant-based implementation selector.
std::uint32_t u32
32 bit unsigned integer
A buffer allocated in USM (Unified Shared Memory).
void complete_event_state(sycl::event e) const
Complete the event state of the buffer.
void copy_from_stdvec(const std::vector< T > &vec)
Copy the content of a std::vector into the buffer.
T * get_write_access(sham::EventList &depends_list, SourceLocation src_loc=SourceLocation{})
Get a read-write pointer to the buffer's data.
std::shared_ptr< DeviceScheduler > & get_dev_scheduler_ptr()
Gets the Device scheduler pointer corresponding to the held allocation.
void copy_from(const DeviceBuffer< T, new_target > &other, size_t copy_size)
Copies the content of another buffer to this one.
size_t get_size() const
Gets the number of elements in the buffer.
std::vector< T > copy_to_stdvec_idx_range(size_t begin, size_t end) const
Copies a specified range of elements from the buffer to a std::vector.
const T * get_read_access(sham::EventList &depends_list, SourceLocation src_loc=SourceLocation{}) const
Get a read-only pointer to the buffer's data.
Class to manage a list of SYCL events.
void set_consumed(bool consumed)
Set the consumed state of the EventList (to be used with interop).
std::vector< sycl::event > & get_events()
Get the list of events.
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.
namespace to control implementation behavior
std::vector< std::string > get_default_impl_list_scan_exclusive_sum_in_place()
Get list of available scan_exclusive_sum_in_place implementations.
bool is_impl_set_scan_exclusive_sum_in_place()
Check if an implementation has been selected for scan_exclusive_sum_in_place.
void set_impl_scan_exclusive_sum_in_place(const std::string &impl)
Set the implementation for scan_exclusive_sum_in_place, from a config json string.
void autoselect_impl_scan_exclusive_sum_in_place(const sham::DeviceScheduler_ptr &dev_sched)
Select the default implementation for scan_exclusive_sum_in_place.
std::string get_current_impl_scan_exclusive_sum_in_place()
Get the current implementation for scan_exclusive_sum_in_place.
namespace for primitive algorithm (e.g. sort, scan, reductions, ...)
void scan_exclusive_sum_in_place(sham::DeviceBuffer< T > &buf1, u32 len)
Compute exclusive prefix sum in-place on a device buffer.
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
In-place exclusive scan (prefix sum) algorithm for device buffers.
std::exclusive_scan on a host copy of the buffer (portable fallback)
Build an overload set out of several callables, for use with std::visit.