10#include "vecmem/containers/details/aligned_multiple_placement.hpp"
11#include "vecmem/edm/details/buffer_traits.hpp"
12#include "vecmem/edm/details/schema_traits.hpp"
13#include "vecmem/edm/details/view_traits.hpp"
23template <
typename... VARTYPES>
32 std::disjunction_v<type::details::is_jagged_vector<VARTYPES>...> ==
34 "Use the other buffer constructor with jagged vector variables!");
39 setup_fixed(std::vector<std::size_t>(capacity),
mr,
nullptr,
40 std::index_sequence_for<VARTYPES...>{});
43 setup_resizable(std::vector<std::size_t>(capacity),
mr,
nullptr,
44 std::index_sequence_for<VARTYPES...>{});
47 throw std::invalid_argument(
"Unknown buffer type");
55 std::is_integral_v<SIZE_TYPE> && std::is_unsigned_v<SIZE_TYPE>,
bool>>
57 const std::vector<SIZE_TYPE, SIZE_ALLOC>&
capacities,
65 std::disjunction_v<type::details::is_jagged_vector<VARTYPES>...>,
66 "Use the other buffer constructor without jagged vector variables!");
72 std::index_sequence_for<VARTYPES...>{});
76 std::index_sequence_for<VARTYPES...>{});
79 throw std::invalid_argument(
"Unknown buffer type");
86 return m_memory.get_deleter().resource();
93 return m_host_memory.get_deleter().resource();
99 const std::vector<SIZE_TYPE, SIZE_ALLOC>&
capacities, memory_resource&
mr,
100 memory_resource*
host_mr, std::index_sequence<INDICES...>) {
103 static_assert(
sizeof...(VARTYPES) ==
sizeof...(
INDICES),
104 "Invalid number of indices");
107 std::tuple<typename details::view_type<VARTYPES>::layout_ptr...>
109 std::tuple<typename details::view_type<VARTYPES>::layout_ptr...>
111 std::tuple<typename details::view_type<VARTYPES>::payload_ptr...>
115 std::tie(m_memory, std::get<INDICES>(
layout_ptrs)...,
124 view_type::m_layout = details::find_layout_view<
VARTYPES...>(
127 view_type::m_payload = details::find_payload_view<
VARTYPES...>(
129 {details::buffer_alloc<VARTYPES>::payload_size(
capacities)...});
132 if (host_mr !=
nullptr) {
135 std::tie(m_host_memory, std::get<INDICES>(host_layout_ptrs)...) =
137 typename details::view_type<VARTYPES>::layout_type...>(
139 details::buffer_alloc<VARTYPES>::layout_size(capacities)...);
142 view_type::m_host_layout = details::find_layout_view<VARTYPES...>(
144 {details::buffer_alloc<VARTYPES>::layout_size(capacities)...});
147 view_type::m_host_layout = view_type::m_layout;
152 details::make_buffer_views<SIZE_TYPE, SIZE_ALLOC, VARTYPES...>(
153 capacities, layout_ptrs, host_layout_ptrs, payload_ptrs,
154 std::index_sequence_for<VARTYPES...>{});
157template <
typename... VARTYPES>
158template <
typename SIZE_TYPE,
typename SIZE_ALLOC, std::size_t... INDICES>
159VECMEM_HOST
void buffer<schema<VARTYPES...>>::setup_resizable(
160 const std::vector<SIZE_TYPE, SIZE_ALLOC>& capacities, memory_resource& mr,
161 memory_resource* host_mr, std::index_sequence<INDICES...>) {
164 static_assert(
sizeof...(VARTYPES) ==
sizeof...(INDICES),
165 "Invalid number of indices");
167 std::disjunction_v<type::details::is_vector<VARTYPES>...>,
168 "Trying to create a resizable container without any vector variables!");
171 constexpr bool has_jagged_vectors =
172 std::disjunction_v<type::details::is_jagged_vector<VARTYPES>...>;
175 std::tuple<typename details::view_type<VARTYPES>::size_ptr...> sizes_ptrs;
178 std::tuple<typename details::view_type<VARTYPES>::layout_ptr...>
180 std::tuple<typename details::view_type<VARTYPES>::layout_ptr...>
182 std::tuple<typename details::view_type<VARTYPES>::payload_ptr...>
188 if constexpr (has_jagged_vectors) {
190 std::tie(m_memory, std::get<INDICES>(sizes_ptrs)...,
191 std::get<INDICES>(layout_ptrs)...,
192 std::get<INDICES>(payload_ptrs)...) =
194 typename details::view_type<VARTYPES>::size_type...,
195 typename details::view_type<VARTYPES>::layout_type...,
196 typename details::view_type<VARTYPES>::payload_type...>(
197 mr, details::buffer_alloc<VARTYPES>::layout_size(capacities)...,
198 details::buffer_alloc<VARTYPES>::layout_size(capacities)...,
199 details::buffer_alloc<VARTYPES>::payload_size(capacities)...);
201 view_type::m_size = {
202 static_cast<typename view_type::memory_view_type::size_type
>(
203 (details::buffer_alloc<VARTYPES>::layout_size(capacities) +
205 sizeof(
typename view_type::size_type)),
206 reinterpret_cast<typename view_type::memory_view_type::pointer
>(
207 details::find_first_pointer(
208 sizes_ptrs, std::index_sequence_for<VARTYPES...>{}))};
211 typename view_type::size_pointer size =
nullptr;
212 std::tie(m_memory, size, std::get<INDICES>(layout_ptrs)...,
213 std::get<INDICES>(payload_ptrs)...) =
215 typename view_type::size_type,
216 typename details::view_type<VARTYPES>::layout_type...,
217 typename details::view_type<VARTYPES>::payload_type...>(
219 details::buffer_alloc<VARTYPES>::layout_size(capacities)...,
220 details::buffer_alloc<VARTYPES>::payload_size(capacities)...);
222 view_type::m_size = {
223 static_cast<typename view_type::memory_view_type::size_type
>(
224 sizeof(
typename view_type::size_type)),
225 reinterpret_cast<typename view_type::memory_view_type::pointer
>(
228 ((std::get<INDICES>(sizes_ptrs) = size), ...);
232 view_type::m_layout = details::find_layout_view<VARTYPES...>(
234 {details::buffer_alloc<VARTYPES>::layout_size(capacities)...});
235 view_type::m_payload = details::find_payload_view<VARTYPES...>(
237 {details::buffer_alloc<VARTYPES>::payload_size(capacities)...});
240 if (host_mr !=
nullptr) {
243 std::tie(m_host_memory, std::get<INDICES>(host_layout_ptrs)...) =
245 typename details::view_type<VARTYPES>::layout_type...>(
247 details::buffer_alloc<VARTYPES>::layout_size(capacities)...);
250 view_type::m_host_layout = details::find_layout_view<VARTYPES...>(
252 {details::buffer_alloc<VARTYPES>::layout_size(capacities)...});
255 view_type::m_host_layout = view_type::m_layout;
260 details::make_buffer_views<SIZE_TYPE, SIZE_ALLOC, VARTYPES...>(
261 capacities, sizes_ptrs, layout_ptrs, host_layout_ptrs, payload_ptrs,
262 std::index_sequence_for<VARTYPES...>{});
267template <
typename... VARTYPES>
274template <
typename... VARTYPES>
275VECMEM_HOST edm::view<edm::details::add_const_t<edm::schema<VARTYPES...>>>
An allocator class that wraps a memory resource.
Definition allocator.hpp:37
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
buffer_type
"Overall type" for a buffer object
Definition buffer_type.hpp:13
@ fixed_size
The buffer has a fixed number of elements.
@ resizable
The buffer is resizable/expandable.
std::tuple< vecmem::unique_alloc_ptr< char[]>, std::add_pointer_t< Ts >... > aligned_multiple_placement(vecmem::memory_resource &r, Ps &&... ps)
Allocation of aligned arrays of given types.
Definition aligned_multiple_placement.ipp:137
Main namespace for the vecmem classes/functions.
Definition atomic_ref.hpp:16
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
Definition buffer_traits.hpp:31
Definition view_traits.hpp:33
Meta type describing the "schema" of an SoA container.
Definition schema.hpp:46