vecmem 1.21.0
Loading...
Searching...
No Matches
view.hpp
1/* VecMem project, part of the ACTS project (R&D line)
2 *
3 * (c) 2023-2025 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#include <vector>
21
22namespace vecmem {
23
25namespace edm {
26
28template <typename T>
29class view;
30
40template <typename... VARTYPES>
41class view<schema<VARTYPES...>> {
42
43 // Sanity check(s).
44 static_assert(sizeof...(VARTYPES) > 0,
45 "SoA containers without variables are not supported.");
46
47public:
51 using size_type = details::size_type;
53 using size_pointer = std::conditional_t<
54 vecmem::details::disjunction_v<std::is_const<
56 details::const_size_pointer, details::size_pointer>;
58 using const_size_pointer = details::const_size_pointer;
62 using memory_view_type = std::conditional_t<
63 vecmem::details::disjunction_v<std::is_const<
66
69
71 view() = default;
72
78 VECMEM_HOST_AND_DEVICE
79 view(size_type capacity, const memory_view_type& size = {0u, nullptr});
80
92 template <
93 typename... OTHERTYPES,
94 std::enable_if_t<
95 vecmem::details::conjunction_v<std::is_constructible<
98 vecmem::details::disjunction_v<
99 vecmem::details::negation<std::is_same<
102 bool> = true>
103 VECMEM_HOST_AND_DEVICE view(const view<schema<OTHERTYPES...>>& other);
104
112 template <
113 typename... OTHERTYPES,
114 std::enable_if_t<
115 vecmem::details::conjunction_v<std::is_constructible<
118 vecmem::details::disjunction_v<
119 vecmem::details::negation<std::is_same<
122 bool> = true>
123 VECMEM_HOST_AND_DEVICE view& operator=(
125
127
130
132 VECMEM_HOST_AND_DEVICE
133 size_type capacity() const;
134
136 template <std::size_t INDEX>
137 VECMEM_HOST_AND_DEVICE tuple_element_t<INDEX, tuple_type>& get();
139 template <std::size_t INDEX>
140 VECMEM_HOST_AND_DEVICE const tuple_element_t<INDEX, tuple_type>& get()
141 const;
142
144
147
149 VECMEM_HOST_AND_DEVICE
150 tuple_type& variables();
152 VECMEM_HOST_AND_DEVICE
153 const tuple_type& variables() const;
154
156 VECMEM_HOST_AND_DEVICE
157 const memory_view_type& size() const;
158
160 VECMEM_HOST_AND_DEVICE
161 const memory_view_type& payload() const;
162
164 VECMEM_HOST_AND_DEVICE
165 const memory_view_type& layout() const;
168 VECMEM_HOST_AND_DEVICE
169 const memory_view_type& host_layout() const;
170
172
173protected:
178
181
184
190
191}; // class view
192
202template <typename... VARTYPES>
203VECMEM_HOST std::vector<vecmem::data::vector_view<int>::size_type>
205
206} // namespace edm
207} // namespace vecmem
208
209// Include the implementation.
210#include "vecmem/edm/impl/view.ipp"
An allocator class that wraps a memory resource.
Definition allocator.hpp:37
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:65
memory_view_type m_payload
View into the single (device) memory allocation for the "payload".
Definition view.hpp:183
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:189
view()=default
Default constructor.
memory_view_type m_size
View into the memory allocated for the container's size variable(s)
Definition view.hpp:180
memory_view_type m_layout
View into the memory that describes the layout of the container.
Definition view.hpp:186
size_type m_capacity
Maximum capacity of the container.
Definition view.hpp:175
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:56
tuple_type m_views
Views for the individual variables.
Definition view.hpp:177
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:58
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:51
Technical base type for view<schema<VARTYPES...>>
Definition view.hpp:29
VECMEM_HOST std::vector< vecmem::data::vector_view< int >::size_type > get_capacities(const view< schema< VARTYPES... > > &soa)
Helper function to get the capacities of the jagged vectors in a view.
Definition view.ipp:198
Main namespace for the vecmem classes/functions.
Definition atomic_ref.hpp:16
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