29#if defined(__has_include)
30 #if __has_include(<AdaptiveCpp/algorithms/numeric.hpp>)
31 #include <AdaptiveCpp/algorithms/numeric.hpp>
32 #define ACPP_ALG_AVAILABLE
40 void scan_exclusive_sum_in_place_std_scan_single_task_acpp(
45 sycl::queue &q_s = q.q;
51 auto e = q.submit(deps, [&](sycl::handler &cgh) {
52 cgh.single_task([=]() {
53 std::exclusive_scan(in_out_ptr, in_out_ptr + len, in_out_ptr, T{});
60 std::exclusive_scan(acc_src.begin(), acc_src.end(), acc_src.begin(), T{});
69 std::exclusive_scan(acc_src.begin(), acc_src.end(), acc_src.begin(), 0);
73#ifdef SYCL2020_FEATURE_GROUP_REDUCTION
76 shamalgs::numeric::details::exclusive_sum_atomic_decoupled_v5_usm_in_place<T, 512>(
81#ifdef ACPP_ALG_AVAILABLE
86 acpp::algorithms::util::allocation_cache cache{
87 acpp::algorithms::util::allocation_type::device};
88 acpp::algorithms::util::allocation_group scratch{&cache, q.get_device()};
94 T *temp_ptr = temp.get_write_access(deps);
96 sycl::event e = adaptivecpp::algorithms::exclusive_scan(
97 q, scratch, in_out_ptr, in_out_ptr + len, temp_ptr, T{}, deps.
get_events());
101 temp.complete_event_state(e);
115 static constexpr std::string_view variant_type_name =
"std_scan";
121 struct StdScanSingleTaskAcpp {
122 static constexpr std::string_view variant_type_name =
"std_scan_single_task_acpp";
126#ifdef SYCL2020_FEATURE_GROUP_REDUCTION
128 struct DecoupledLookback512 {
129 static constexpr std::string_view variant_type_name =
"decoupled_lookback_512";
133#ifdef ACPP_ALG_AVAILABLE
135 struct AdaptiveCppAlg {
136 static constexpr std::string_view variant_type_name =
"acpp_alg";
142 =
"scan_exclusive_sum_in_place";
148 StdScanSingleTaskAcpp
150#ifdef SYCL2020_FEATURE_GROUP_REDUCTION
154#ifdef ACPP_ALG_AVAILABLE
159 scan_exclusive_sum_in_place_impl{[](
const sham::DeviceScheduler_ptr &,
auto &self) {
162 self.set(StdScanSingleTaskAcpp{});
167 #ifdef SYCL2020_FEATURE_GROUP_REDUCTION
168 self.set(DecoupledLookback512{});
190 "The buffer is smaller than the length of the scan\n"
191 "len > buf1.get_size(), len = {}, buf1.get_size() = {}",
196 if (!impl::scan_exclusive_sum_in_place_impl.is_set()) {
204 scan_exclusive_sum_in_place_fallback(buf1, len);
207 [&](impl::StdScanSingleTaskAcpp) {
208 scan_exclusive_sum_in_place_std_scan_single_task_acpp(buf1, len);
211#ifdef SYCL2020_FEATURE_GROUP_REDUCTION
212 [&](impl::DecoupledLookback512) {
213 scan_exclusive_sum_in_place_decoupled_lookback_512(buf1, len);
216#ifdef ACPP_ALG_AVAILABLE
217 [&](impl::AdaptiveCppAlg) {
218 scan_exclusive_sum_in_place_adaptivecpp(buf1, len);
222 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.
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 scan_exclusive_sum_in_place_impl_name
Registry name, shared by its registration and the dispatch site(s).
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.