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"
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::runtime_error(
"Unknown buffer type");
53 std::enable_if_t<std::is_integral<SIZE_TYPE>::value &&
54 std::is_unsigned<SIZE_TYPE>::value,
64 std::disjunction_v<type::details::is_jagged_vector<VARTYPES>...>,
65 "Use the other buffer constructor without jagged vector variables!");
71 std::index_sequence_for<VARTYPES...>{});
75 std::index_sequence_for<VARTYPES...>{});
78 throw std::runtime_error(
"Unknown buffer type");
85 const std::vector<SIZE_TYPE>&
capacities, memory_resource&
mr,
86 memory_resource*
host_mr, std::index_sequence<INDICES...>) {
89 static_assert(
sizeof...(VARTYPES) ==
sizeof...(
INDICES),
90 "Invalid number of indices");
93 std::tuple<typename details::view_type<VARTYPES>::layout_ptr...>
95 std::tuple<typename details::view_type<VARTYPES>::payload_ptr...>
99 std::tie(m_memory, std::get<INDICES>(
layout_ptrs)...,
103 typename details::view_type<VARTYPES>::payload_type...>(
108 view_type::m_layout = details::find_layout_view<
VARTYPES...>(
111 view_type::m_payload = details::find_payload_view<
VARTYPES...>(
113 {details::buffer_alloc<VARTYPES>::payload_size(
capacities)...});
121 typename details::view_type<VARTYPES>::layout_type...>(
123 details::buffer_alloc<VARTYPES>::layout_size(
capacities)...);
126 view_type::m_host_layout = details::find_layout_view<
VARTYPES...>(
128 {details::buffer_alloc<VARTYPES>::layout_size(
capacities)...});
131 view_type::m_host_layout = view_type::m_layout;
137 std::index_sequence_for<
VARTYPES...>{});
142VECMEM_HOST
void buffer<schema<
VARTYPES...>>::setup_resizable(
143 const std::vector<SIZE_TYPE>&
capacities, memory_resource&
mr,
144 memory_resource*
host_mr, std::index_sequence<INDICES...>) {
147 static_assert(
sizeof...(VARTYPES) ==
sizeof...(
INDICES),
148 "Invalid number of indices");
150 std::disjunction_v<type::details::is_vector<VARTYPES>...>,
151 "Trying to create a resizable container without any vector variables!");
155 std::disjunction_v<type::details::is_jagged_vector<VARTYPES>...>;
158 std::tuple<typename details::view_type<VARTYPES>::size_ptr...>
sizes_ptrs;
161 std::tuple<typename details::view_type<VARTYPES>::layout_ptr...>
163 std::tuple<typename details::view_type<VARTYPES>::payload_ptr...>
171 std::tie(m_memory, std::get<INDICES>(
sizes_ptrs)...,
175 typename details::view_type<VARTYPES>::size_type...,
176 typename details::view_type<VARTYPES>::layout_type...,
177 typename details::view_type<VARTYPES>::payload_type...>(
178 mr, details::buffer_alloc<VARTYPES>::layout_size(
capacities)...,
179 details::buffer_alloc<VARTYPES>::layout_size(
capacities)...,
180 details::buffer_alloc<VARTYPES>::payload_size(
capacities)...);
182 view_type::m_size = {
183 static_cast<typename view_type::memory_view_type::size_type
>(
184 (details::buffer_alloc<VARTYPES>::layout_size(
capacities) +
186 sizeof(
typename view_type::size_type)),
187 reinterpret_cast<typename view_type::memory_view_type::pointer
>(
188 details::find_first_pointer(
189 sizes_ptrs, std::index_sequence_for<VARTYPES...>{}))};
192 typename view_type::size_pointer size =
nullptr;
193 std::tie(m_memory, size, std::get<INDICES>(
layout_ptrs)...,
196 typename view_type::size_type,
197 typename details::view_type<VARTYPES>::layout_type...,
198 typename details::view_type<VARTYPES>::payload_type...>(
200 details::buffer_alloc<VARTYPES>::layout_size(
capacities)...,
201 details::buffer_alloc<VARTYPES>::payload_size(
capacities)...);
203 view_type::m_size = {
204 static_cast<typename view_type::memory_view_type::size_type
>(
205 sizeof(
typename view_type::size_type)),
206 reinterpret_cast<typename view_type::memory_view_type::pointer
>(
209 ((std::get<INDICES>(
sizes_ptrs) = size), ...);
213 view_type::m_layout = details::find_layout_view<
VARTYPES...>(
215 {details::buffer_alloc<VARTYPES>::layout_size(
capacities)...});
216 view_type::m_payload = details::find_payload_view<
VARTYPES...>(
218 {details::buffer_alloc<VARTYPES>::payload_size(
capacities)...});
226 typename details::view_type<VARTYPES>::layout_type...>(
228 details::buffer_alloc<VARTYPES>::layout_size(
capacities)...);
231 view_type::m_host_layout = details::find_layout_view<
VARTYPES...>(
233 {details::buffer_alloc<VARTYPES>::layout_size(
capacities)...});
236 view_type::m_host_layout = view_type::m_layout;
242 std::index_sequence_for<
VARTYPES...>{});
255VECMEM_HOST edm::view<edm::details::add_const_t<edm::schema<
VARTYPES...>>>
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
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
Definition buffer_traits.hpp:31
Definition view_traits.hpp:33
Meta type describing the "schema" of an SoA container.
Definition schema.hpp:46