Skip to content

Commit e462b33

Browse files
authored
SoA Proxy Updates, main branch (2025.02.20.) (#309)
* Renamed edm::details::proxy_type to edm::details::proxy_domain. Just because I intend to use "proxy type" for a different thing shortly. * Introduced edm::details::proxy_type. Without making any meaningful use of it yet. * Introduced edm::host::push_back. * Introduced edm::device::push_back.
1 parent 9dc02c6 commit e462b33

12 files changed

+489
-144
lines changed

core/include/vecmem/edm/details/proxy_traits.hpp

+152-69
Large diffs are not rendered by default.

core/include/vecmem/edm/device.hpp

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* VecMem project, part of the ACTS project (R&D line)
22
*
3-
* (c) 2023-2024 CERN for the benefit of the ACTS project
3+
* (c) 2023-2025 CERN for the benefit of the ACTS project
44
*
55
* Mozilla Public License Version 2.0
66
*/
@@ -53,12 +53,18 @@ class device<schema<VARTYPES...>, INTERFACE> {
5353
using interface_type = INTERFACE<T>;
5454
/// The type of the (non-const) proxy objects for the container elements
5555
using proxy_type =
56-
interface_type<proxy<schema_type, details::proxy_type::device,
57-
details::proxy_access::non_constant>>;
56+
interface_type<proxy<schema_type, details::proxy_domain::device,
57+
details::proxy_access::non_constant,
58+
details::proxy_type::reference>>;
5859
/// The type of the (const) proxy objects for the container elements
59-
using const_proxy_type =
60-
interface_type<proxy<schema_type, details::proxy_type::device,
61-
details::proxy_access::constant>>;
60+
using const_proxy_type = interface_type<
61+
proxy<schema_type, details::proxy_domain::device,
62+
details::proxy_access::constant, details::proxy_type::reference>>;
63+
/// Type type of standalone proxy objects for the container
64+
using object_type =
65+
interface_type<proxy<schema_type, details::proxy_domain::device,
66+
details::proxy_access::non_constant,
67+
details::proxy_type::standalone>>;
6268

6369
/// @name Constructors and assignment operators
6470
/// @{
@@ -82,6 +88,8 @@ class device<schema<VARTYPES...>, INTERFACE> {
8288
/// Add one default element to all (vector) variables (thread safe)
8389
VECMEM_HOST_AND_DEVICE
8490
size_type push_back_default();
91+
/// Add one element to all (vector) variables (thread safe)
92+
VECMEM_HOST_AND_DEVICE size_type push_back(const object_type& element);
8593

8694
/// Get a specific variable (non-const)
8795
template <std::size_t INDEX>

core/include/vecmem/edm/host.hpp

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* VecMem project, part of the ACTS project (R&D line)
22
*
3-
* (c) 2023-2024 CERN for the benefit of the ACTS project
3+
* (c) 2023-2025 CERN for the benefit of the ACTS project
44
*
55
* Mozilla Public License Version 2.0
66
*/
@@ -52,12 +52,18 @@ class host<schema<VARTYPES...>, INTERFACE> {
5252
using interface_type = INTERFACE<T>;
5353
/// The type of the (non-const) proxy objects for the container elements
5454
using proxy_type =
55-
interface_type<proxy<schema_type, details::proxy_type::host,
56-
details::proxy_access::non_constant>>;
55+
interface_type<proxy<schema_type, details::proxy_domain::host,
56+
details::proxy_access::non_constant,
57+
details::proxy_type::reference>>;
5758
/// The type of the (const) proxy objects for the container elements
58-
using const_proxy_type =
59-
interface_type<proxy<schema_type, details::proxy_type::host,
60-
details::proxy_access::constant>>;
59+
using const_proxy_type = interface_type<
60+
proxy<schema_type, details::proxy_domain::host,
61+
details::proxy_access::constant, details::proxy_type::reference>>;
62+
/// Type type of standalone proxy objects for the container
63+
using object_type =
64+
interface_type<proxy<schema_type, details::proxy_domain::host,
65+
details::proxy_access::non_constant,
66+
details::proxy_type::standalone>>;
6167

6268
/// @name Constructors and assignment operators
6369
/// @{
@@ -80,6 +86,8 @@ class host<schema<VARTYPES...>, INTERFACE> {
8086
/// Reserve memory for the container
8187
VECMEM_HOST
8288
void reserve(size_type size);
89+
/// Add a new element to the container
90+
VECMEM_HOST void push_back(const object_type& element);
8391

8492
/// Get the vector of a specific variable (non-const)
8593
template <std::size_t INDEX>

core/include/vecmem/edm/impl/device.ipp

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* VecMem project, part of the ACTS project (R&D line)
22
*
3-
* (c) 2023-2024 CERN for the benefit of the ACTS project
3+
* (c) 2023-2025 CERN for the benefit of the ACTS project
44
*
55
* Mozilla Public License Version 2.0
66
*/
@@ -83,6 +83,20 @@ device<schema<VARTYPES...>, INTERFACE>::push_back_default() -> size_type {
8383
return index;
8484
}
8585

86+
template <typename... VARTYPES, template <typename> class INTERFACE>
87+
VECMEM_HOST_AND_DEVICE auto device<schema<VARTYPES...>, INTERFACE>::push_back(
88+
const object_type& element) -> size_type {
89+
90+
// Add a new default element to the container.
91+
const size_type index = push_back_default();
92+
93+
// Set it to the given value.
94+
at(index) = element;
95+
96+
// Return the position of the new variable(s).
97+
return index;
98+
}
99+
86100
template <typename... VARTYPES, template <typename> class INTERFACE>
87101
template <std::size_t INDEX>
88102
VECMEM_HOST_AND_DEVICE

core/include/vecmem/edm/impl/host.ipp

+16
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,22 @@ VECMEM_HOST void host<schema<VARTYPES...>, INTERFACE>::reserve(
6565
std::index_sequence_for<VARTYPES...>{});
6666
}
6767

68+
template <typename... VARTYPES, template <typename> class INTERFACE>
69+
VECMEM_HOST void host<schema<VARTYPES...>, INTERFACE>::push_back(
70+
const object_type& element) {
71+
72+
// Make sure that there are some (jagged) vector types in the container.
73+
static_assert(
74+
std::disjunction_v<type::details::is_vector<VARTYPES>...>,
75+
"This function requires at least one (jagged) vector variable.");
76+
77+
// Add a new element to the container.
78+
const size_type index = size();
79+
resize(index + 1);
80+
// Set the new element.
81+
at(index) = element;
82+
}
83+
6884
template <typename... VARTYPES, template <typename> class INTERFACE>
6985
template <std::size_t INDEX>
7086
VECMEM_HOST typename details::host_type_at<INDEX, VARTYPES...>::return_type
+74-25
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* VecMem project, part of the ACTS project (R&D line)
22
*
3-
* (c) 2024 CERN for the benefit of the ACTS project
3+
* (c) 2024-2025 CERN for the benefit of the ACTS project
44
*
55
* Mozilla Public License Version 2.0
66
*/
@@ -9,53 +9,102 @@
99
namespace vecmem {
1010
namespace edm {
1111

12-
template <typename... VARTYPES, details::proxy_type PTYPE,
13-
details::proxy_access CTYPE>
12+
template <typename... VARTYPES, details::proxy_domain PDOMAIN,
13+
details::proxy_access PACCESS, details::proxy_type PTYPE>
1414
template <typename PARENT>
15-
VECMEM_HOST_AND_DEVICE proxy<schema<VARTYPES...>, PTYPE, CTYPE>::proxy(
16-
PARENT& parent, typename PARENT::size_type index)
17-
: m_data{
18-
details::proxy_data_creator<schema<VARTYPES...>, PTYPE, CTYPE>::make(
19-
index, parent)} {
15+
VECMEM_HOST_AND_DEVICE proxy<schema<VARTYPES...>, PDOMAIN, PACCESS,
16+
PTYPE>::proxy(PARENT& parent,
17+
typename PARENT::size_type index)
18+
: m_data{details::proxy_data_creator<schema<VARTYPES...>, PDOMAIN, PACCESS,
19+
PTYPE>::make(index, parent)} {
2020

21-
static_assert(CTYPE == details::proxy_access::non_constant,
21+
static_assert(PACCESS == details::proxy_access::non_constant,
2222
"This constructor is meant for non-const proxies.");
2323
}
2424

25-
template <typename... VARTYPES, details::proxy_type PTYPE,
26-
details::proxy_access CTYPE>
25+
template <typename... VARTYPES, details::proxy_domain PDOMAIN,
26+
details::proxy_access PACCESS, details::proxy_type PTYPE>
2727
template <typename PARENT>
28-
VECMEM_HOST_AND_DEVICE proxy<schema<VARTYPES...>, PTYPE, CTYPE>::proxy(
29-
const PARENT& parent, typename PARENT::size_type index)
30-
: m_data{
31-
details::proxy_data_creator<schema<VARTYPES...>, PTYPE, CTYPE>::make(
32-
index, parent)} {
28+
VECMEM_HOST_AND_DEVICE proxy<schema<VARTYPES...>, PDOMAIN, PACCESS,
29+
PTYPE>::proxy(const PARENT& parent,
30+
typename PARENT::size_type index)
31+
: m_data{details::proxy_data_creator<schema<VARTYPES...>, PDOMAIN, PACCESS,
32+
PTYPE>::make(index, parent)} {
3333

34-
static_assert(CTYPE == details::proxy_access::constant,
34+
static_assert(PACCESS == details::proxy_access::constant,
3535
"This constructor is meant for constant proxies.");
3636
}
3737

38-
template <typename... VARTYPES, details::proxy_type PTYPE,
39-
details::proxy_access CTYPE>
38+
template <typename... VARTYPES, details::proxy_domain PDOMAIN,
39+
details::proxy_access PACCESS, details::proxy_type PTYPE>
40+
template <details::proxy_domain OPDOMAIN, details::proxy_access OPACCESS,
41+
details::proxy_type OPTYPE>
42+
VECMEM_HOST_AND_DEVICE
43+
proxy<schema<VARTYPES...>, PDOMAIN, PACCESS, PTYPE>::proxy(
44+
const proxy<schema<VARTYPES...>, OPDOMAIN, OPACCESS, OPTYPE>& other)
45+
: m_data(other.variables()) {}
46+
47+
template <typename... VARTYPES, details::proxy_domain PDOMAIN,
48+
details::proxy_access PACCESS, details::proxy_type PTYPE>
49+
VECMEM_HOST_AND_DEVICE
50+
proxy<schema<VARTYPES...>, PDOMAIN, PACCESS, PTYPE>::proxy(
51+
typename details::proxy_var_type<VARTYPES, proxy_domain, access_type,
52+
proxy_type>::type... data)
53+
: m_data(data...) {}
54+
55+
template <typename... VARTYPES, details::proxy_domain PDOMAIN,
56+
details::proxy_access PACCESS, details::proxy_type PTYPE>
57+
template <details::proxy_domain OPDOMAIN, details::proxy_access OPACCESS,
58+
details::proxy_type OPTYPE>
59+
VECMEM_HOST_AND_DEVICE proxy<schema<VARTYPES...>, PDOMAIN, PACCESS, PTYPE>&
60+
proxy<schema<VARTYPES...>, PDOMAIN, PACCESS, PTYPE>::operator=(
61+
const proxy<schema<VARTYPES...>, OPDOMAIN, OPACCESS, OPTYPE>& other) {
62+
63+
if (static_cast<const void*>(this) != static_cast<const void*>(&other)) {
64+
m_data = other.variables();
65+
}
66+
return *this;
67+
}
68+
69+
template <typename... VARTYPES, details::proxy_domain PDOMAIN,
70+
details::proxy_access PACCESS, details::proxy_type PTYPE>
4071
template <std::size_t INDEX>
4172
VECMEM_HOST_AND_DEVICE
42-
typename details::proxy_var_type_at<INDEX, PTYPE, CTYPE,
73+
typename details::proxy_var_type_at<INDEX, PDOMAIN, PACCESS, PTYPE,
4374
VARTYPES...>::return_type
44-
proxy<schema<VARTYPES...>, PTYPE, CTYPE>::get() {
75+
proxy<schema<VARTYPES...>, PDOMAIN, PACCESS, PTYPE>::get() {
4576

4677
return vecmem::get<INDEX>(m_data);
4778
}
4879

49-
template <typename... VARTYPES, details::proxy_type PTYPE,
50-
details::proxy_access CTYPE>
80+
template <typename... VARTYPES, details::proxy_domain PDOMAIN,
81+
details::proxy_access PACCESS, details::proxy_type PTYPE>
5182
template <std::size_t INDEX>
5283
VECMEM_HOST_AND_DEVICE
53-
typename details::proxy_var_type_at<INDEX, PTYPE, CTYPE,
84+
typename details::proxy_var_type_at<INDEX, PDOMAIN, PACCESS, PTYPE,
5485
VARTYPES...>::const_return_type
55-
proxy<schema<VARTYPES...>, PTYPE, CTYPE>::get() const {
86+
proxy<schema<VARTYPES...>, PDOMAIN, PACCESS, PTYPE>::get() const {
5687

5788
return vecmem::get<INDEX>(m_data);
5889
}
5990

91+
template <typename... VARTYPES, details::proxy_domain PDOMAIN,
92+
details::proxy_access PACCESS, details::proxy_type PTYPE>
93+
VECMEM_HOST_AND_DEVICE auto
94+
proxy<schema<VARTYPES...>, PDOMAIN, PACCESS, PTYPE>::variables() const
95+
-> const tuple_type& {
96+
97+
return m_data;
98+
}
99+
100+
template <typename... VARTYPES, details::proxy_domain PDOMAIN,
101+
details::proxy_access PACCESS, details::proxy_type PTYPE>
102+
VECMEM_HOST_AND_DEVICE auto
103+
proxy<schema<VARTYPES...>, PDOMAIN, PACCESS, PTYPE>::variables()
104+
-> tuple_type& {
105+
106+
return m_data;
107+
}
108+
60109
} // namespace edm
61110
} // namespace vecmem

0 commit comments

Comments
 (0)