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 const std::vector<SIZE_TYPE, SIZE_ALLOC>&
capacities, memory_resource&
mr,
87 memory_resource*
host_mr, std::index_sequence<INDICES...>) {
90 static_assert(
sizeof...(VARTYPES) ==
sizeof...(
INDICES),
91 "Invalid number of indices");
94 std::tuple<typename details::view_type<VARTYPES>::layout_ptr...>
96 std::tuple<typename details::view_type<VARTYPES>::layout_ptr...>
98 std::tuple<typename details::view_type<VARTYPES>::payload_ptr...>
102 std::tie(m_memory, std::get<INDICES>(
layout_ptrs)...,
111 view_type::m_layout = details::find_layout_view<
VARTYPES...>(
114 view_type::m_payload = details::find_payload_view<
VARTYPES...>(
116 {details::buffer_alloc<VARTYPES>::payload_size(
capacities)...});
119 if (host_mr !=
nullptr) {
122 std::tie(m_host_memory, std::get<INDICES>(host_layout_ptrs)...) =
124 typename details::view_type<VARTYPES>::layout_type...>(
126 details::buffer_alloc<VARTYPES>::layout_size(capacities)...);
129 view_type::m_host_layout = details::find_layout_view<VARTYPES...>(
131 {details::buffer_alloc<VARTYPES>::layout_size(capacities)...});
134 view_type::m_host_layout = view_type::m_layout;
139 details::make_buffer_views<SIZE_TYPE, SIZE_ALLOC, VARTYPES...>(
140 capacities, layout_ptrs, host_layout_ptrs, payload_ptrs,
141 std::index_sequence_for<VARTYPES...>{});
144template <
typename... VARTYPES>
145template <
typename SIZE_TYPE,
typename SIZE_ALLOC, std::size_t... INDICES>
146VECMEM_HOST
void buffer<schema<VARTYPES...>>::setup_resizable(
147 const std::vector<SIZE_TYPE, SIZE_ALLOC>& capacities, memory_resource& mr,
148 memory_resource* host_mr, std::index_sequence<INDICES...>) {
151 static_assert(
sizeof...(VARTYPES) ==
sizeof...(INDICES),
152 "Invalid number of indices");
154 std::disjunction_v<type::details::is_vector<VARTYPES>...>,
155 "Trying to create a resizable container without any vector variables!");
158 constexpr bool has_jagged_vectors =
159 std::disjunction_v<type::details::is_jagged_vector<VARTYPES>...>;
162 std::tuple<typename details::view_type<VARTYPES>::size_ptr...> sizes_ptrs;
165 std::tuple<typename details::view_type<VARTYPES>::layout_ptr...>
167 std::tuple<typename details::view_type<VARTYPES>::layout_ptr...>
169 std::tuple<typename details::view_type<VARTYPES>::payload_ptr...>
175 if constexpr (has_jagged_vectors) {
177 std::tie(m_memory, std::get<INDICES>(sizes_ptrs)...,
178 std::get<INDICES>(layout_ptrs)...,
179 std::get<INDICES>(payload_ptrs)...) =
181 typename details::view_type<VARTYPES>::size_type...,
182 typename details::view_type<VARTYPES>::layout_type...,
183 typename details::view_type<VARTYPES>::payload_type...>(
184 mr, details::buffer_alloc<VARTYPES>::layout_size(capacities)...,
185 details::buffer_alloc<VARTYPES>::layout_size(capacities)...,
186 details::buffer_alloc<VARTYPES>::payload_size(capacities)...);
188 view_type::m_size = {
189 static_cast<typename view_type::memory_view_type::size_type
>(
190 (details::buffer_alloc<VARTYPES>::layout_size(capacities) +
192 sizeof(
typename view_type::size_type)),
193 reinterpret_cast<typename view_type::memory_view_type::pointer
>(
194 details::find_first_pointer(
195 sizes_ptrs, std::index_sequence_for<VARTYPES...>{}))};
198 typename view_type::size_pointer size =
nullptr;
199 std::tie(m_memory, size, std::get<INDICES>(layout_ptrs)...,
200 std::get<INDICES>(payload_ptrs)...) =
202 typename view_type::size_type,
203 typename details::view_type<VARTYPES>::layout_type...,
204 typename details::view_type<VARTYPES>::payload_type...>(
206 details::buffer_alloc<VARTYPES>::layout_size(capacities)...,
207 details::buffer_alloc<VARTYPES>::payload_size(capacities)...);
209 view_type::m_size = {
210 static_cast<typename view_type::memory_view_type::size_type
>(
211 sizeof(
typename view_type::size_type)),
212 reinterpret_cast<typename view_type::memory_view_type::pointer
>(
215 ((std::get<INDICES>(sizes_ptrs) = size), ...);
219 view_type::m_layout = details::find_layout_view<VARTYPES...>(
221 {details::buffer_alloc<VARTYPES>::layout_size(capacities)...});
222 view_type::m_payload = details::find_payload_view<VARTYPES...>(
224 {details::buffer_alloc<VARTYPES>::payload_size(capacities)...});
227 if (host_mr !=
nullptr) {
230 std::tie(m_host_memory, std::get<INDICES>(host_layout_ptrs)...) =
232 typename details::view_type<VARTYPES>::layout_type...>(
234 details::buffer_alloc<VARTYPES>::layout_size(capacities)...);
237 view_type::m_host_layout = details::find_layout_view<VARTYPES...>(
239 {details::buffer_alloc<VARTYPES>::layout_size(capacities)...});
242 view_type::m_host_layout = view_type::m_layout;
247 details::make_buffer_views<SIZE_TYPE, SIZE_ALLOC, VARTYPES...>(
248 capacities, sizes_ptrs, layout_ptrs, host_layout_ptrs, payload_ptrs,
249 std::index_sequence_for<VARTYPES...>{});
254template <
typename... VARTYPES>
261template <
typename... VARTYPES>
262VECMEM_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