10#include "vecmem/edm/details/schema_traits.hpp"
11#include "vecmem/edm/details/view_traits.hpp"
12#include "vecmem/edm/schema.hpp"
13#include "vecmem/edm/view.hpp"
14#include "vecmem/memory/unique_ptr.hpp"
15#include "vecmem/utils/tuple.hpp"
16#include "vecmem/utils/types.hpp"
25namespace vecmem::edm::details {
30template <
typename TYPE>
33template <
typename TYPE>
36 template <
typename SIZE_TYPE = std::
size_t>
37 VECMEM_HOST
static std::size_t
payload_size(
const std::vector<SIZE_TYPE>&) {
41 template <
typename SIZE_TYPE = std::
size_t>
42 VECMEM_HOST
static std::size_t
layout_size(
const std::vector<SIZE_TYPE>&) {
46 template <
typename SIZE_TYPE = std::
size_t>
48 const std::vector<SIZE_TYPE>&,
unsigned int*,
56template <
typename TYPE>
59 template <
typename SIZE_TYPE = std::
size_t>
61 const std::vector<SIZE_TYPE>&
sizes) {
65 template <
typename SIZE_TYPE = std::
size_t>
66 VECMEM_HOST
static std::size_t
layout_size(
const std::vector<SIZE_TYPE>&) {
70 template <
typename SIZE_TYPE = std::
size_t>
72 const std::vector<SIZE_TYPE>& capacity,
unsigned int* size,
83template <
typename TYPE>
86 template <
typename SIZE_TYPE = std::
size_t>
88 const std::vector<SIZE_TYPE>&
sizes) {
89 return std::accumulate(
sizes.begin(),
sizes.end(),
90 static_cast<std::size_t
>(0));
93 template <
typename SIZE_TYPE = std::
size_t>
95 const std::vector<SIZE_TYPE>&
sizes) {
99 template <
typename SIZE_TYPE = std::
size_t>
109 (host_layout !=
nullptr ? host_layout : layout);
125 layout, host_layout};
133VECMEM_HOST
auto make_buffer_views(
134 const std::vector<SIZE_TYPE>&
sizes,
135 const std::tuple<
typename view_type<TYPES>::layout_ptr...>&
layouts,
136 const std::tuple<
typename view_type<TYPES>::layout_ptr...>&
host_layouts,
137 const std::tuple<
typename view_type<TYPES>::payload_ptr...>&
payloads,
138 std::index_sequence<INDICES...>) {
147VECMEM_HOST
auto make_buffer_views(
149 const std::tuple<
typename view_type<TYPES>::size_ptr...>&
sizes,
150 const std::tuple<
typename view_type<TYPES>::layout_ptr...>&
layouts,
151 const std::tuple<
typename view_type<TYPES>::layout_ptr...>&
host_layouts,
152 const std::tuple<
typename view_type<TYPES>::payload_ptr...>&
payloads,
153 const std::index_sequence<INDICES...>) {
156 constexpr auto is_jagged_vector =
157 std::make_tuple(type::details::is_jagged_vector<TYPES>::value...);
158 constexpr bool has_jagged_vector =
159 std::disjunction_v<type::details::is_jagged_vector<TYPES>...>;
167 ((has_jagged_vector && (!std::get<INDICES>(is_jagged_vector)))
176VECMEM_HOST
constexpr void* find_first_pointer(
177 const std::tuple<TYPES...>&
pointers,
178 std::index_sequence<INDEX, INDICES...>) {
180 auto ptr = std::get<INDEX>(
pointers);
181 if (ptr !=
nullptr) {
184 if constexpr (
sizeof...(INDICES) > 0) {
185 return find_first_pointer<
TYPES...>(
195VECMEM_HOST
constexpr void* find_last_pointer(
196 const std::tuple<TYPES...>&
pointers,
197 const std::array<std::size_t,
sizeof...(
TYPES)>&
sizes,
198 std::index_sequence<INDEX, INDICES...>) {
201 if (ptr !=
nullptr) {
202 return ptr + std::get<
sizeof...(TYPES) - 1 -
INDEX>(
sizes);
204 if constexpr (
sizeof...(INDICES) > 0) {
205 return find_last_pointer<
TYPES...>(
214template <
typename...
TYPES>
215VECMEM_HOST
constexpr typename view<schema<
TYPES...> >::memory_view_type
217 const std::tuple<
typename view_type<TYPES>::layout_ptr...>&
layouts,
218 const std::array<std::size_t,
sizeof...(
TYPES)>&
sizes) {
224 typename result_type::pointer ptr =
225 reinterpret_cast<typename result_type::pointer
>(
226 find_first_pointer(
layouts, std::index_sequence_for<TYPES...>()));
228 typename result_type::pointer
end_ptr =
229 reinterpret_cast<typename result_type::pointer
>(find_last_pointer(
233 return {
static_cast<typename result_type::size_type
>(
end_ptr - ptr), ptr};
237template <
typename...
TYPES>
238VECMEM_HOST
constexpr typename view<schema<
TYPES...> >::memory_view_type
240 const std::tuple<
typename view_type<TYPES>::payload_ptr...>&
payloads,
241 const std::array<std::size_t,
sizeof...(
TYPES)>&
sizes) {
247 typename result_type::pointer ptr =
248 reinterpret_cast<typename result_type::pointer
>(
249 find_first_pointer(
payloads, std::index_sequence_for<TYPES...>()));
251 typename result_type::pointer
end_ptr =
252 reinterpret_cast<typename result_type::pointer
>(find_last_pointer(
256 return {
static_cast<typename result_type::size_type
>(
end_ptr - ptr), ptr};
vector< vector< T > > jagged_vector
Alias type for jagged vectors with our polymorphic allocator.
Definition jagged_vector.hpp:30
VECMEM_HOST_AND_DEVICE constexpr tuple< typename std::decay< Ts >::type... > make_tuple(Ts &&... args)
Make a tuple with automatic type deduction.
Definition tuple.ipp:88
VECMEM_HOST_AND_DEVICE constexpr const auto & get(const tuple< Ts... > &t) noexcept
Get a constant element out of a tuple.
Definition tuple.ipp:58
std::vector< T, vecmem::polymorphic_allocator< T > > vector
Alias type for vectors with our polymorphic allocator.
Definition vector.hpp:35
static VECMEM_HOST view_type< type::jagged_vector< TYPE > >::type make_view(const std::vector< SIZE_TYPE > &capacities, unsigned int *sizes, typename view_type< type::jagged_vector< TYPE > >::layout_ptr layout, typename view_type< type::jagged_vector< TYPE > >::layout_ptr host_layout, typename view_type< type::jagged_vector< TYPE > >::payload_ptr ptr)
Construct a view for a jagged vector variable.
Definition buffer_traits.hpp:101
static VECMEM_HOST std::size_t layout_size(const std::vector< SIZE_TYPE > &sizes)
The number of "layout meta-objects" to allocate for the payload.
Definition buffer_traits.hpp:94
static VECMEM_HOST std::size_t payload_size(const std::vector< SIZE_TYPE > &sizes)
The number of TYPE elements to allocate for the payload.
Definition buffer_traits.hpp:87
static VECMEM_HOST view_type< type::scalar< TYPE > >::type make_view(const std::vector< SIZE_TYPE > &, unsigned int *, typename view_type< type::scalar< TYPE > >::layout_ptr, typename view_type< type::scalar< TYPE > >::layout_ptr, typename view_type< type::scalar< TYPE > >::payload_ptr ptr)
Construct a view for a scalar variable.
Definition buffer_traits.hpp:47
static VECMEM_HOST std::size_t payload_size(const std::vector< SIZE_TYPE > &)
The number of TYPE elements to allocate for the payload.
Definition buffer_traits.hpp:37
static VECMEM_HOST std::size_t layout_size(const std::vector< SIZE_TYPE > &)
The number of "layout meta-objects" to allocate for the payload.
Definition buffer_traits.hpp:42
static VECMEM_HOST std::size_t payload_size(const std::vector< SIZE_TYPE > &sizes)
The number of TYPE elements to allocate for the payload.
Definition buffer_traits.hpp:60
static VECMEM_HOST view_type< type::vector< TYPE > >::type make_view(const std::vector< SIZE_TYPE > &capacity, unsigned int *size, typename view_type< type::vector< TYPE > >::layout_ptr, typename view_type< type::vector< TYPE > >::layout_ptr, typename view_type< type::vector< TYPE > >::payload_ptr ptr)
Construct a view for a vector variable.
Definition buffer_traits.hpp:71
static VECMEM_HOST std::size_t layout_size(const std::vector< SIZE_TYPE > &)
The number of "layout meta-objects" to allocate for the payload.
Definition buffer_traits.hpp:66
Definition buffer_traits.hpp:31
Definition view_traits.hpp:33
1D vector variable
Definition schema.hpp:26