40 if (!buffer.has_value()) {
43 return buffer.value().get().get_read_access(depends_list);
59 if (!buffer.has_value()) {
62 return buffer.value().get().get_write_access(depends_list);
73 if (buffer.has_value()) {
74 buffer.value().get().complete_event_state(e);
80 return o.get_read_access(depends_list);
85 return o.get_write_access(depends_list);
88 inline auto complete_event_state(Obj &o, sycl::event e) {
89 return o.complete_event_state(e);
93 inline auto get_read_access(std::reference_wrapper<Obj> &o,
sham::EventList &depends_list) {
94 return o.get().get_read_access(depends_list);
98 inline auto get_write_access(
100 return o.get().get_write_access(depends_list);
103 inline auto complete_event_state(std::reference_wrapper<Obj> &o, sycl::event e) {
104 return o.get().complete_event_state(e);
140 template<
class... Targ>
143 using storage_t = std::tuple<shambase::opt_ref<Targ>...>;
164 return std::tuple(details::read_access_optional(__a, depends_list)...);
181 return std::tuple(details::write_access_optional(__a, depends_list)...);
197 ((details::complete_state_optional(e, __in)), ...);
220 template<
class... Targ>
233 template<
class... Targ>
250 return std::tuple(details::get_read_access(__a, depends_list)...);
261 return std::tuple(details::get_write_access(__a, depends_list)...);
272 ((details::complete_event_state(__in, e)), ...);
281 template<
class index_t,
class RefIn,
class RefOut,
class Functor>
287 Functor &&kernel_gen,
298 auto acc_in = in.get_read_access(depends_list);
299 auto acc_in_out = in_out.get_write_access(depends_list);
305 [&](
auto &...__acc_in) {
307 [&](
auto &...__acc_in_out) {
309 e = q.
submit(depends_list, kernel_gen(n, __acc_in..., __acc_in_out...));
315 in.complete_event_state(e);
316 in_out.complete_event_state(e);
320 template<
class index_t,
class RefIn,
class RefOut,
class Functor>
331 typed_index_kernel_call_lambda(
337 = std::forward<Functor>(func)](
u32 n,
auto... __acc_in,
auto... __acc_in_out) {
338 return [=](sycl::handler &cgh) {
339 cgh.parallel_for(sycl::range<1>{n}, [=](sycl::item<1> item) {
341 func, index_t(item.get_linear_id()), __acc_in..., __acc_in_out...);
343 func(index_t(item.get_linear_id()), __acc_in..., __acc_in_out...);
513 template<
class RefIn,
class RefOut,
class Functor>
524 details::typed_index_kernel_call<u32, RefIn, RefOut>(
525 q, in, in_out, n, std::forward<Functor>(func));
529 template<
class RefIn,
class RefOut,
class Functor>
540 details::typed_index_kernel_call<u64, RefIn, RefOut>(
541 q, in, in_out, n, std::forward<Functor>(func));
545 template<
class RefIn,
class RefOut,
class Functor>
546 void kernel_call_hndl(
551 Functor &&kernel_gen,
556 details::typed_index_kernel_call_lambda<u32, RefIn, RefOut>(
557 q, in, in_out, n, std::forward<Functor>(kernel_gen));
561 template<
class RefIn,
class RefOut,
class Functor>
567 Functor &&kernel_gen,
572 details::typed_index_kernel_call_lambda<u64, RefIn, RefOut>(
573 q, in, in_out, n, std::forward<Functor>(kernel_gen));
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
A buffer allocated in USM (Unified Shared Memory)
A SYCL queue associated with a device and a context.
sycl::event submit(Fct &&fct)
Submits a kernel to the SYCL queue.
Class to manage a list of SYCL events.
void typed_index_kernel_call(sham::DeviceQueue &q, RefIn in, RefOut in_out, index_t n, Functor &&func, SourceLocation &&callsite=SourceLocation{})
internal implementation of typed_index_kernel_call
const T * read_access_optional(shambase::opt_ref< sham::DeviceBuffer< T > > buffer, sham::EventList &depends_list)
Get a pointer to the data of an optional device buffer, for reading.
void complete_state_optional(sycl::event e, shambase::opt_ref< T > buffer)
Complete the event state of an optional device buffer.
void typed_index_kernel_call_lambda(sham::DeviceQueue &q, RefIn in, RefOut in_out, index_t n, Functor &&kernel_gen, SourceLocation &&callsite=SourceLocation{})
internal implementation of typed_index_kernel_call
T * write_access_optional(shambase::opt_ref< sham::DeviceBuffer< T > > buffer, sham::EventList &depends_list)
Get a pointer to the data of an optional device buffer, for writing.
Namespace for internal details of the logs module.
namespace for backends this one is named only sham since shambackends is too long to write
shambase::opt_ref< T > to_opt_ref(T &t)
Converts a reference to a given object into an optional reference wrapper.
auto empty_buf_ref()
Returns an empty optional containing a reference to a sham::DeviceBuffer<T>.
void kernel_call_u64(sham::DeviceQueue &q, RefIn in, RefOut in_out, u64 n, Functor &&func, SourceLocation &&callsite=SourceLocation{})
u64 indexed variant of kernel_call
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.
void kernel_call_hndl_u64(sham::DeviceQueue &q, RefIn in, RefOut in_out, u64 n, Functor &&kernel_gen, SourceLocation &&callsite=SourceLocation{})
u64 indexed variant of kernel_call_hndl
namespace for basic c++ utilities
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
std::optional< std::reference_wrapper< T > > opt_ref
Optional reference wrapper.
#define __shamrock_stack_entry_with_callsite(callsite)
Macro to create a stack entry.
#define __shamrock_stack_entry()
Macro to create a stack entry.
#define __shamrock_log_callsite(callsite)
Macro to create a stack entry from a given location. Can be used only on SourceLocation &&.
provide information about the source location
A variant of MultiRef for optional buffers.
void complete_event_state(sycl::event e)
Complete the event state of the buffers.
auto get_write_access(sham::EventList &depends_list)
Get a tuple of pointers to the data of the buffers, for writing.
std::tuple< shambase::opt_ref< Targ >... > storage_t
A tuple of optional references to the buffers.
MultiRefOpt(shambase::opt_ref< Targ >... arg)
Constructor from a tuple of optional references to the buffers.
auto get_read_access(sham::EventList &depends_list)
Get a tuple of pointers to the data of the buffers, for reading.
storage_t storage
The tuple of optional references to the buffers.
A class that references multiple buffers or similar objects.
storage_t storage
A tuple of references to the buffers.
auto get_write_access(sham::EventList &depends_list)
std::tuple< Targ &... > storage_t
A tuple of references to the buffers.
MultiRef(Targ &...arg)
Constructor.
auto get_read_access(sham::EventList &depends_list)
void complete_event_state(sycl::event e)
internal_utility for MultiRef template deduction guide