35 for (
u32 i = 0; i < cnt; i++) {
61 [](
u32 i,
const T *in,
u32 *out) {
67 return count_true == cnt;
78 auto &q = dev_sched->get_queue();
116 sham::kernel_call_hndl(
121 [=](
u32,
const T *buf,
u32 *stop) {
122 return [=](sycl::handler &cgh) {
123 cgh.parallel_for(range, [=](sycl::nd_item<1> item) {
124 auto grp = item.get_group();
125 u32 lid = item.get_local_linear_id();
130 u32 stop_val = sycl::group_broadcast(grp, (lid == 0) ? *stop :
u32{0}, 0);
137 u32 gid = item.get_global_linear_id();
139 bool local = (gid < cnt) ? (buf[gid] != 0) :
true;
142 bool result = sycl::all_of_group(grp, local);
146 if (!result && !(*stop)) {
149 sycl::memory_order_relaxed,
150 sycl::memory_scope_device,
151 sycl::access::address_space::global_space>
160 return stop_flag.get_val_at_idx(0) == 0;
169 static constexpr std::string_view variant_type_name =
"host";
174 static constexpr std::string_view variant_type_name =
"sum_reduction";
179 static constexpr std::string_view variant_type_name =
"atomic_early_exit";
180 u32 group_size = 256;
193 return {{
"group_size", p.group_size}};
197 if (j.contains(
"group_size")) {
198 p.group_size = j.at(
"group_size").get<
u32>();
213 [](
const sham::DeviceScheduler_ptr &,
auto &self) {
225 if (!impl::is_all_true_impl.is_set()) {
233 return is_all_true_host(buf, cnt);
236 return is_all_true_sum_reduction(buf, cnt);
239 return is_all_true_early_group_exit(buf, cnt, cfg.group_size);
242 impl::is_all_true_impl.get());
254 sycl::host_accessor acc{buf, sycl::read_only};
256 for (
u32 i = 0; i < cnt; i++) {
Generic std::variant-based implementation selector.
std::uint32_t u32
32 bit unsigned integer
A buffer allocated in USM (Unified Shared Memory).
std::shared_ptr< DeviceScheduler > & get_dev_scheduler_ptr()
Gets the Device scheduler pointer corresponding to the held allocation.
std::vector< T > copy_to_stdvec() const
Copy the content of the buffer to a std::vector.
Drop-in replacement for the hand-rolled "global variable + enum + name mapping.
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.
Boolean reduction algorithm for checking if all elements are non-zero.
sycl::nd_range< 1 > make_ndrange(u32 wg_size, u32 nthread)
void kernel_call(sham::DeviceQueue &q, RefIn in, RefOut in_out, u32 n, Functor &&func, SourceLocation &&callsite=SourceLocation{})
Submit a kernel to a SYCL queue.
namespace to control implementation behavior
constexpr std::string_view is_all_true_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.
bool is_all_true(sycl::buffer< T > &buf, u32 cnt)
Check if all elements in a sycl::buffer are non-zero.
namespace to contain everything implemented by shamalgs
T & get_check_ref(const std::unique_ptr< T > &ptr, SourceLocation loc=SourceLocation())
Takes a std::unique_ptr and returns a reference to the object it holds. It throws a std::runtime_erro...
A class that references multiple buffers or similar objects.
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).
Check all elements via a sum reduction on device.
static std::vector< AtomicEarlyExit > variant_custom_defaults()
Check all elements on host after copying the buffer back.
Check all elements via a sum reduction on device.
Build an overload set out of several callables, for use with std::visit.