Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
MultiRefOpt.hpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
10#pragma once
11
18
20
21namespace sham {
22
29 template<class T>
31 return t;
32 }
33
41 template<class T>
45
54 template<class... Targ>
55 struct MultiRefOpt {
57 using storage_t = std::tuple<shambase::opt_ref<Targ>...>;
58
61
64
74 auto get_read_access(sham::EventList &depends_list) {
76 return std::apply(
77 [&](auto &...__a) {
78 return std::tuple(details::read_access_optional(__a, depends_list)...);
79 },
80 storage);
81 }
82
91 auto get_write_access(sham::EventList &depends_list) {
93 return std::apply(
94 [&](auto &...__a) {
95 return std::tuple(details::write_access_optional(__a, depends_list)...);
96 },
97 storage);
98 }
99
107 void complete_event_state(sycl::event e) {
109 std::apply(
110 [&](auto &...__in) {
111 ((details::complete_state_optional(e, __in)), ...);
112 },
113 storage);
114 }
115 };
116
117 namespace details {
119 template<class T>
120 struct mapper {
122 using type = T;
123 };
124
126 template<class T>
127 struct mapper<shambase::opt_ref<T>> {
129 using type = T;
130 };
131 } // namespace details
132
134 template<class... Targ>
136} // namespace sham
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.
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.
Class to manage a list of SYCL events.
Definition EventList.hpp:31
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.
MultiRefOpt(Targ... arg) -> MultiRefOpt< typename details::mapper< Targ >::type... >
deduction guide to allow the MutliRefOpt to be build without the use of sham::to_opt_ref
auto empty_buf_ref()
Returns an empty optional containing a reference to a sham::DeviceBuffer<T>.
namespace for basic c++ utilities
std::optional< std::reference_wrapper< T > > opt_ref
Optional reference wrapper.
Definition optional.hpp:26
#define __shamrock_stack_entry()
Macro to create a stack entry.
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.
internal_utility for MultiRef template deduction guide
T type
The mapped type.