34 for (
u32 i = 0; i < cnt; i++) {
60 [](
u32 i,
const T *in,
u32 *out) {
66 return count_true == cnt;
77 auto &q = dev_sched->get_queue();
115 sham::kernel_call_hndl(
120 [=](
u32,
const T *buf,
u32 *stop) {
121 return [=](sycl::handler &cgh) {
122 cgh.parallel_for(range, [=](sycl::nd_item<1> item) {
123 auto grp = item.get_group();
124 u32 lid = item.get_local_linear_id();
129 u32 stop_val = sycl::group_broadcast(grp, (lid == 0) ? *stop :
u32{0}, 0);
136 u32 gid = item.get_global_linear_id();
138 bool local = (gid < cnt) ? (buf[gid] != 0) :
true;
141 bool result = sycl::all_of_group(grp, local);
145 if (!result && !(*stop)) {
148 sycl::memory_order_relaxed,
149 sycl::memory_scope_device,
150 sycl::access::address_space::global_space>
159 return stop_flag.get_val_at_idx(0) == 0;
168 static constexpr std::string_view variant_type_name =
"host";
173 static constexpr std::string_view variant_type_name =
"sum_reduction";
178 static constexpr std::string_view variant_type_name =
"atomic_early_exit";
179 u32 group_size = 256;
192 return {{
"group_size", p.group_size}};
196 if (j.contains(
"group_size")) {
197 p.group_size = j.at(
"group_size").get<
u32>();
209 [](
const sham::DeviceScheduler_ptr &,
auto &self) {
215 return is_all_true_impl.get_default_config_list();
226 shamlog_info_ln(
"algs",
"setting is_all_true implementation to impl :",
impl);
227 is_all_true_impl.set(
impl);
232 is_all_true_impl.autoselect(dev_sched);
235 "defaulting is_all_true implementation to impl :",
244 if (!impl::is_all_true_impl.is_set()) {
251 return is_all_true_host(buf, cnt);
254 return is_all_true_sum_reduction(buf, cnt);
257 return is_all_true_early_group_exit(buf, cnt, cfg.group_size);
260 impl::is_all_true_impl.get());
272 sycl::host_accessor acc{buf, sycl::read_only};
274 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.
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
bool is_impl_set_is_all_true()
Check if an implementation has been selected for is_all_true.
void autoselect_impl_is_all_true(const sham::DeviceScheduler_ptr &dev_sched)
Select the default implementation for is_all_true.
void set_impl_is_all_true(const std::string &impl)
Set the implementation for is_all_true, from a config json string.
std::string get_current_impl_is_all_true()
Get the current implementation for is_all_true, as a config json string.
std::vector< std::string > get_default_impl_list_is_all_true()
Get list of available is_all_true implementations, as config json strings.
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.