vecmem 1.18.0
Loading...
Searching...
No Matches
copy.hpp
1/*
2 * VecMem project, part of the ACTS project (R&D line)
3 *
4 * (c) 2021-2025 CERN for the benefit of the ACTS project
5 *
6 * Mozilla Public License Version 2.0
7 */
8#pragma once
9
10// VecMem include(s).
11#include "vecmem/containers/data/jagged_vector_buffer.hpp"
12#include "vecmem/containers/data/jagged_vector_view.hpp"
13#include "vecmem/containers/data/vector_buffer.hpp"
14#include "vecmem/containers/data/vector_view.hpp"
15#include "vecmem/edm/buffer.hpp"
16#include "vecmem/edm/details/schema_traits.hpp"
17#include "vecmem/edm/host.hpp"
18#include "vecmem/edm/view.hpp"
19#include "vecmem/memory/memory_resource.hpp"
20#include "vecmem/utils/abstract_event.hpp"
21#include "vecmem/utils/attributes.hpp"
22#include "vecmem/vecmem_core_export.hpp"
23
24// System include(s).
25#include <cstddef>
26#include <memory>
27#include <type_traits>
28#include <vector>
29
30namespace vecmem {
31
43
44public:
51 struct type {
53 enum copy_type {
55 host_to_device = 0,
57 device_to_host = 1,
59 host_to_host = 2,
61 device_to_device = 3,
63 unknown = 4,
65 count = 5
66 }; // enum copy_type
67 }; // struct type
68
70 using event_type = std::unique_ptr<abstract_event>;
71
74
76 virtual ~copy() = default;
77
79 template <typename TYPE>
80 VECMEM_NODISCARD event_type setup(data::vector_view<TYPE> data) const;
81
83 template <typename TYPE>
85 int value) const;
86
88 template <typename TYPE>
90 const data::vector_view<TYPE>& data, memory_resource& resource,
91 type::copy_type cptype = type::unknown) const;
92
94 template <typename TYPE>
95 VECMEM_NODISCARD event_type
96 operator()(const data::vector_view<std::add_const_t<TYPE>>& from,
98 type::copy_type cptype = type::unknown) const;
99
101 template <typename TYPE, typename ALLOC>
102 VECMEM_NODISCARD event_type
103 operator()(const data::vector_view<std::add_const_t<TYPE>>& from,
104 std::vector<TYPE, ALLOC>& to,
105 type::copy_type cptype = type::unknown) const;
106
108 template <typename TYPE>
109 typename data::vector_view<TYPE>::size_type get_size(
110 const data::vector_view<TYPE>& data) const;
111
113
116
118 template <typename TYPE>
119 VECMEM_NODISCARD event_type
121
123 template <typename TYPE>
125 int value) const;
126
128 template <typename TYPE>
130 const data::jagged_vector_view<TYPE>& data, memory_resource& resource,
131 memory_resource* host_access_resource = nullptr,
132 type::copy_type cptype = type::unknown) const;
133
135 template <typename TYPE>
136 VECMEM_NODISCARD event_type
137 operator()(const data::jagged_vector_view<std::add_const_t<TYPE>>& from,
139 type::copy_type cptype = type::unknown) const;
140
142 template <typename TYPE, typename ALLOC1, typename ALLOC2>
143 VECMEM_NODISCARD event_type
144 operator()(const data::jagged_vector_view<std::add_const_t<TYPE>>& from,
145 std::vector<std::vector<TYPE, ALLOC2>, ALLOC1>& to,
146 type::copy_type cptype = type::unknown) const;
147
149 template <typename TYPE>
150 std::vector<typename data::vector_view<TYPE>::size_type> get_sizes(
151 const data::jagged_vector_view<TYPE>& data) const;
152
154 template <typename TYPE>
155 VECMEM_NODISCARD event_type set_sizes(
156 const std::vector<typename data::vector_view<TYPE>::size_type>& sizes,
158
160
163
165 template <typename SCHEMA>
166 VECMEM_NODISCARD event_type setup(edm::view<SCHEMA> data) const;
167
169 template <typename... VARTYPES>
171 int value) const;
172
174 template <typename... VARTYPES>
175 edm::buffer<edm::details::remove_cv_t<edm::schema<VARTYPES...>>> to(
177 memory_resource& resource,
178 memory_resource* host_access_resource = nullptr,
179 type::copy_type cptype = type::unknown) const;
180
182 template <typename... VARTYPES>
183 VECMEM_NODISCARD event_type operator()(
184 const edm::view<edm::details::add_const_t<edm::schema<VARTYPES...>>>&
185 from,
187 type::copy_type cptype = type::unknown) const;
188
190 template <typename... VARTYPES, template <typename> class INTERFACE>
191 VECMEM_NODISCARD event_type operator()(
192 const edm::view<edm::details::add_const_t<edm::schema<VARTYPES...>>>&
193 from,
195 type::copy_type cptype = type::unknown) const;
196
198 template <typename... VARTYPES>
199 typename edm::view<edm::schema<VARTYPES...>>::size_type get_size(
200 const edm::view<edm::schema<VARTYPES...>>& data) const;
201
203 template <typename... VARTYPES>
204 std::vector<data::vector_view<int>::size_type> get_sizes(
205 const edm::view<edm::schema<VARTYPES...>>& data) const;
206
208
209protected:
211 virtual void do_copy(std::size_t size, const void* from, void* to,
212 type::copy_type cptype) const;
214 virtual void do_memset(std::size_t size, void* ptr, int value) const;
216 VECMEM_NODISCARD virtual event_type create_event() const;
217
218private:
220 template <typename TYPE>
221 bool copy_view_impl(const data::vector_view<std::add_const_t<TYPE>>& from,
223 type::copy_type cptype) const;
225 template <typename TYPE>
226 bool copy_view_impl(
227 const data::jagged_vector_view<std::add_const_t<TYPE>>& from,
230 template <typename TYPE>
231 void copy_views_impl(
232 const std::vector<typename data::vector_view<TYPE>::size_type>& sizes,
233 const data::vector_view<std::add_const_t<TYPE>>* from,
236 template <typename TYPE>
237 void copy_views_contiguous_impl(
238 const std::vector<typename data::vector_view<TYPE>::size_type>& sizes,
239 const data::vector_view<std::add_const_t<TYPE>>* from,
242 template <typename TYPE>
243 std::vector<typename data::vector_view<TYPE>::size_type> get_sizes_impl(
244 const data::vector_view<TYPE>* data, std::size_t size) const;
246 template <typename TYPE>
247 static bool is_contiguous(const data::vector_view<TYPE>* data,
248 std::size_t size);
250 template <std::size_t INDEX, typename... VARTYPES>
251 void memset_impl(edm::view<edm::schema<VARTYPES...>> data, int value) const;
253 template <std::size_t INDEX, typename... VARTYPES,
254 template <typename> class INTERFACE>
255 void resize_impl(
256 const edm::view<edm::details::add_const_t<edm::schema<VARTYPES...>>>&
257 from,
259 type::copy_type cptype) const;
261 template <std::size_t INDEX, typename... VARTYPES>
262 void copy_sizes_impl(
263 const edm::view<edm::details::add_const_t<edm::schema<VARTYPES...>>>&
264 from,
267 template <std::size_t INDEX, typename... VARTYPES>
268 void copy_payload_impl(
269 const edm::view<edm::details::add_const_t<edm::schema<VARTYPES...>>>&
270 from,
273 template <std::size_t INDEX, typename... VARTYPES>
274 std::vector<data::vector_view<int>::size_type> get_sizes_impl(
276
277}; // class copy
278
279} // namespace vecmem
280
281// Include the implementation.
282#include "vecmem/utils/impl/copy.ipp"
An allocator class that wraps a memory resource.
Definition allocator.hpp:37
Class implementing (synchronous) host <-> device memory copies.
Definition copy.hpp:42
VECMEM_NODISCARD event_type setup(data::jagged_vector_view< TYPE > data) const
Copy the internal state of a jagged vector buffer to the target device.
VECMEM_NODISCARD event_type set_sizes(const std::vector< typename data::vector_view< TYPE >::size_type > &sizes, data::jagged_vector_view< TYPE > data) const
Helper function for setting the sizes of a resizable jagged vector.
VECMEM_NODISCARD event_type operator()(const data::vector_view< std::add_const_t< TYPE > > &from, data::vector_view< TYPE > to, type::copy_type cptype=type::unknown) const
Copy a 1-dimensional vector's data between two existing memory blocks.
VECMEM_NODISCARD event_type setup(data::vector_view< TYPE > data) const
Set up the internal state of a vector buffer correctly on a device.
VECMEM_NODISCARD event_type operator()(const edm::view< edm::details::add_const_t< edm::schema< VARTYPES... > > > &from, edm::host< edm::schema< VARTYPES... >, INTERFACE > &to, type::copy_type cptype=type::unknown) const
Copy from a view, into a host container.
VECMEM_NODISCARD event_type operator()(const data::jagged_vector_view< std::add_const_t< TYPE > > &from, std::vector< std::vector< TYPE, ALLOC2 >, ALLOC1 > &to, type::copy_type cptype=type::unknown) const
Copy a jagged vector's data into a vector object.
VECMEM_NODISCARD event_type operator()(const data::vector_view< std::add_const_t< TYPE > > &from, std::vector< TYPE, ALLOC > &to, type::copy_type cptype=type::unknown) const
Copy a 1-dimensional vector's data into a vector object.
std::unique_ptr< abstract_event > event_type
Event type used by the copy class.
Definition copy.hpp:70
VECMEM_NODISCARD event_type memset(edm::view< edm::schema< VARTYPES... > > data, int value) const
Set all bytes of the container to some value.
VECMEM_NODISCARD event_type operator()(const edm::view< edm::details::add_const_t< edm::schema< VARTYPES... > > > &from, edm::view< edm::schema< VARTYPES... > > to, type::copy_type cptype=type::unknown) const
Copy between two views.
VECMEM_NODISCARD event_type memset(data::jagged_vector_view< TYPE > data, int value) const
Set all bytes of the jagged vector to some value.
VECMEM_NODISCARD event_type operator()(const data::jagged_vector_view< std::add_const_t< TYPE > > &from, data::jagged_vector_view< TYPE > to, type::copy_type cptype=type::unknown) const
Copy a jagged vector's data between two existing allocations.
VECMEM_NODISCARD event_type setup(edm::view< SCHEMA > data) const
Set up the internal state of a buffer correctly on a device.
VECMEM_NODISCARD event_type memset(data::vector_view< TYPE > data, int value) const
Set all bytes of the vector to some value.
virtual ~copy()=default
Virtual destructor.
Object owning all the data of a jagged vector.
Definition jagged_vector_buffer.hpp:30
A view for jagged vectors.
Definition jagged_vector_view.hpp:45
Object owning the data held by it.
Definition vector_buffer.hpp:29
Class holding data about a 1 dimensional vector/array.
Definition vector_view.hpp:38
Technical base type for buffer<schema<VARTYPES...>>
Definition buffer.hpp:28
Technical base type for host<schema<VARTYPES...>,INTERFACE>
Definition host.hpp:28
Technical base type for view<schema<VARTYPES...>>
Definition view.hpp:29
Main namespace for the vecmem classes/functions.
Definition atomic_ref.hpp:16
Wrapper struct around the copy_type enumeration.
Definition copy.hpp:51
copy_type
Types of memory copies to handle.
Definition copy.hpp:53
Meta type describing the "schema" of an SoA container.
Definition schema.hpp:46