vecmem 1.14.0
Loading...
Searching...
No Matches
view.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/vector_view.hpp"
11#include "vecmem/edm/details/types.hpp"
12#include "vecmem/edm/details/view_traits.hpp"
13#include "vecmem/edm/schema.hpp"
14#include "vecmem/utils/tuple.hpp"
15#include "vecmem/utils/type_traits.hpp"
16#include "vecmem/utils/types.hpp"
17
18// System include(s).
19#include <type_traits>
20
21namespace vecmem {
22
24namespace edm {
25
27template <typename T>
28class view;
29
39template <typename... VARTYPES>
40class view<schema<VARTYPES...>> {
41
42 // Sanity check(s).
43 static_assert(sizeof...(VARTYPES) > 0,
44 "SoA containers without variables are not supported.");
45
46public:
50 using size_type = details::size_type;
52 using size_pointer = std::conditional_t<
53 vecmem::details::disjunction_v<std::is_const<
54 typename details::view_type<VARTYPES>::payload_type>...>,
55 details::const_size_pointer, details::size_pointer>;
57 using const_size_pointer = details::const_size_pointer;
61 using memory_view_type = std::conditional_t<
62 vecmem::details::disjunction_v<std::is_const<
63 typename details::view_type<VARTYPES>::payload_type>...>,
65
68
70 view() = default;
71
77 VECMEM_HOST_AND_DEVICE
78 view(size_type capacity, const memory_view_type& size = {0u, nullptr});
79
91 template <
92 typename... OTHERTYPES,
93 std::enable_if_t<
94 vecmem::details::conjunction_v<std::is_constructible<
97 vecmem::details::disjunction_v<
98 vecmem::details::negation<std::is_same<
101 bool> = true>
102 VECMEM_HOST_AND_DEVICE view(const view<schema<OTHERTYPES...>>& other);
103
111 template <
112 typename... OTHERTYPES,
113 std::enable_if_t<
114 vecmem::details::conjunction_v<std::is_constructible<
117 vecmem::details::disjunction_v<
118 vecmem::details::negation<std::is_same<
121 bool> = true>
122 VECMEM_HOST_AND_DEVICE view& operator=(
124
126
129
131 VECMEM_HOST_AND_DEVICE
132 size_type capacity() const;
133
135 template <std::size_t INDEX>
136 VECMEM_HOST_AND_DEVICE tuple_element_t<INDEX, tuple_type>& get();
138 template <std::size_t INDEX>
139 VECMEM_HOST_AND_DEVICE const tuple_element_t<INDEX, tuple_type>& get()
140 const;
141
143
146
148 VECMEM_HOST_AND_DEVICE
149 tuple_type& variables();
151 VECMEM_HOST_AND_DEVICE
152 const tuple_type& variables() const;
153
155 VECMEM_HOST_AND_DEVICE
156 const memory_view_type& size() const;
157
159 VECMEM_HOST_AND_DEVICE
160 const memory_view_type& payload() const;
161
163 VECMEM_HOST_AND_DEVICE
164 const memory_view_type& layout() const;
167 VECMEM_HOST_AND_DEVICE
168 const memory_view_type& host_layout() const;
169
171
172protected:
177
180
183
189
190}; // class view
191
192} // namespace edm
193} // namespace vecmem
194
195// Include the implementation.
196#include "vecmem/edm/impl/view.ipp"
Class holding data about a 1 dimensional vector/array.
Definition vector_view.hpp:38
std::conditional_t< vecmem::details::disjunction_v< std::is_const< typename details::view_type< VARTYPES >::payload_type >... >, details::const_memory_view, details::memory_view > memory_view_type
Type of the view(s) into the raw data of the view.
Definition view.hpp:64
memory_view_type m_payload
View into the single (device) memory allocation for the "payload".
Definition view.hpp:182
VECMEM_HOST_AND_DEVICE tuple_element_t< INDEX, tuple_type > & get()
Get the view of a specific variable (non-const)
memory_view_type m_host_layout
View into the memory that describes the layout of the container (in host accessible memory)
Definition view.hpp:188
view()=default
Default constructor.
memory_view_type m_size
View into the memory allocated for the container's size variable(s)
Definition view.hpp:179
memory_view_type m_layout
View into the memory that describes the layout of the container.
Definition view.hpp:185
size_type m_capacity
Maximum capacity of the container.
Definition view.hpp:174
std::conditional_t< vecmem::details::disjunction_v< std::is_const< typename details::view_type< VARTYPES >::payload_type >... >, details::const_size_pointer, details::size_pointer > size_pointer
Pointer type to the size of the container.
Definition view.hpp:55
tuple_type m_views
Views for the individual variables.
Definition view.hpp:176
VECMEM_HOST_AND_DEVICE view & operator=(const view< schema< OTHERTYPES... > > &rhs)
Assignment operator from a (possibly/slightly) different view.
details::const_size_pointer const_size_pointer
Constant pointer type to the size of the container.
Definition view.hpp:57
VECMEM_HOST_AND_DEVICE const tuple_element_t< INDEX, tuple_type > & get() const
Get the view of a specific variable (const)
details::size_type size_type
Size type used for the container.
Definition view.hpp:50
schema< VARTYPES... > schema_type
The schema describing the container view.
Definition view.hpp:48
Technical base type for view<schema<VARTYPES...>>
Definition view.hpp:28
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
Implementation for std::negation.
Definition type_traits.hpp:91
Definition view_traits.hpp:33
Meta type describing the "schema" of an SoA container.
Definition schema.hpp:46