vecmem 1.14.0
Loading...
Searching...
No Matches
buffer.hpp
1/* VecMem project, part of the ACTS project (R&D line)
2 *
3 * (c) 2023 CERN for the benefit of the ACTS project
4 *
5 * Mozilla Public License Version 2.0
6 */
7#pragma once
8
9// Local include(s).
10#include "vecmem/containers/data/buffer_type.hpp"
11#include "vecmem/edm/details/schema_traits.hpp"
12#include "vecmem/edm/schema.hpp"
13#include "vecmem/edm/view.hpp"
14#include "vecmem/memory/memory_resource.hpp"
15#include "vecmem/memory/unique_ptr.hpp"
16#include "vecmem/utils/types.hpp"
17
18// System include(s).
19#include <type_traits>
20#include <utility>
21#include <vector>
22
23namespace vecmem {
24namespace edm {
25
27template <typename T>
28class buffer;
29
159template <typename... VARTYPES>
160class buffer<schema<VARTYPES...>> : public view<schema<VARTYPES...>> {
161
162 // Make sure that all variable types are supported. It needs to be possible
163 // to copy the contents of all variables with simple memory copies, and
164 // it has to be possible to trivially destruct all objects.
165 static_assert(
166 std::conjunction<
167 std::is_trivially_destructible<typename VARTYPES::type>...>::value,
168 "Unsupported variable type");
169 static_assert(std::conjunction<std::is_trivially_assignable<
170 std::add_lvalue_reference_t<typename VARTYPES::type>,
171 typename VARTYPES::type>...>::value,
172 "Unsupported variable type");
173
174public:
180 using size_type = typename view_type::size_type;
183
185 buffer() = default;
187 buffer(buffer&&) = default;
188
190 buffer& operator=(buffer&&) = default;
191
198 VECMEM_HOST
199 buffer(
200 size_type capacity, memory_resource& mr,
202
217 template <typename SIZE_TYPE = std::size_t,
218 std::enable_if_t<std::is_integral<SIZE_TYPE>::value &&
219 std::is_unsigned<SIZE_TYPE>::value,
220 bool> = true>
221 VECMEM_HOST buffer(
222 const std::vector<SIZE_TYPE>& capacities, memory_resource& mr,
223 memory_resource* host_mr = nullptr,
225
226private:
228 template <typename SIZE_TYPE = std::size_t, std::size_t... INDICES>
229 VECMEM_HOST void setup_fixed(const std::vector<SIZE_TYPE>& capacities,
230 memory_resource& mr, memory_resource* host_mr,
231 std::index_sequence<INDICES...>);
233 template <typename SIZE_TYPE = std::size_t, std::size_t... INDICES>
234 VECMEM_HOST void setup_resizable(const std::vector<SIZE_TYPE>& capacities,
235 memory_resource& mr,
236 memory_resource* host_mr,
237 std::index_sequence<INDICES...>);
238
240 memory_type m_memory;
242 memory_type m_host_memory;
243
244}; // class buffer
245
246} // namespace edm
247
254template <typename... VARTYPES>
255VECMEM_HOST edm::view<edm::schema<VARTYPES...>> get_data(
257
264template <typename... VARTYPES>
265VECMEM_HOST edm::view<edm::details::add_const_t<edm::schema<VARTYPES...>>>
267
268} // namespace vecmem
269
270// Include the implementation.
271#include "vecmem/edm/impl/buffer.ipp"
schema< VARTYPES... > schema_type
The schema describing the buffer's payload.
Definition buffer.hpp:176
buffer()=default
Default constructor.
buffer(buffer &&)=default
Move constructor.
unique_alloc_ptr< char[]> memory_type
Type holding on to the memory managed by this object.
Definition buffer.hpp:182
buffer & operator=(buffer &&)=default
Move assignment operator.
typename view_type::size_type size_type
Size type used for the container.
Definition buffer.hpp:180
Technical base type for buffer<schema<VARTYPES...>>
Definition buffer.hpp:28
Technical base type for view<schema<VARTYPES...>>
Definition view.hpp:28
buffer_type
"Overall type" for a buffer object
Definition buffer_type.hpp:13
@ fixed_size
The buffer has a fixed number of elements.
Main namespace for the vecmem classes/functions.
Definition atomic_ref.hpp:16
std::vector< T, vecmem::polymorphic_allocator< T > > vector
Alias type for vectors with our polymorphic allocator.
Definition vector.hpp:35
VECMEM_HOST data::vector_view< T > get_data(array< T, N > &a)
Helper function creating a vecmem::data::vector_view object.
Definition array.ipp:217
Meta type describing the "schema" of an SoA container.
Definition schema.hpp:46