77
88#include < cstdint>
99#include < cassert>
10+ #include < cstring>
11+ #include < memory>
1012#include < ostream>
1113#include < tuple>
1214#include < type_traits>
@@ -123,12 +125,13 @@ namespace cms::soa {
123125 // default constructor
124126 SoAConstParametersImpl () = default ;
125127
126- // constructor from an address
127- SOA_HOST_DEVICE SOA_INLINE constexpr SoAConstParametersImpl (ValueType const * addr) : addr_(addr) {}
128+ // constructor from address and size
129+ SOA_HOST_DEVICE SOA_INLINE constexpr SoAConstParametersImpl (ValueType const * addr, size_type size)
130+ : addr_(addr), size_{size} {}
128131
129132 // constructor from a non-const parameter set
130133 SOA_HOST_DEVICE SOA_INLINE constexpr SoAConstParametersImpl (SoAParametersImpl<columnType, ValueType> const & o)
131- : addr_{o.addr_ } {}
134+ : addr_{o.addr_ }, size_{o. size_ } {}
132135
133136 static constexpr bool checkAlignment (ValueType* addr, byte_size_type alignment) {
134137 return reinterpret_cast <intptr_t >(addr) % alignment;
@@ -139,6 +142,7 @@ namespace cms::soa {
139142 public:
140143 // scalar or column
141144 ValueType const * addr_ = nullptr ;
145+ size_type size_ = 0 ;
142146 };
143147
144148 // Templated const parameter specialisation for Eigen columns
@@ -153,17 +157,19 @@ namespace cms::soa {
153157 // default constructor
154158 SoAConstParametersImpl () = default ;
155159
156- // constructor from individual address and stride
157- SOA_HOST_DEVICE SOA_INLINE constexpr SoAConstParametersImpl (ScalarType const * addr, byte_size_type stride)
158- : addr_(addr), stride_(stride) {}
160+ // constructor from individual address, stride and size
161+ SOA_HOST_DEVICE SOA_INLINE constexpr SoAConstParametersImpl (ScalarType const * addr,
162+ byte_size_type stride,
163+ size_type size)
164+ : addr_(addr), stride_(stride), size_{size} {}
159165
160166 // constructor from address and stride packed in a tuple
161167 SOA_HOST_DEVICE SOA_INLINE constexpr SoAConstParametersImpl (TupleOrPointerType const & tuple)
162168 : addr_(std::get<0 >(tuple)), stride_(std::get<1 >(tuple)) {}
163169
164170 // constructor from a non-const parameter set
165171 SOA_HOST_DEVICE SOA_INLINE constexpr SoAConstParametersImpl (SoAParametersImpl<columnType, ValueType> const & o)
166- : addr_{o.addr_ }, stride_{o.stride_ } {}
172+ : addr_{o.addr_ }, stride_{o.stride_ }, size_{o. size_ } {}
167173
168174 static constexpr bool checkAlignment (TupleOrPointerType const & tuple, byte_size_type alignment) {
169175 const auto & [addr, stride] = tuple;
@@ -173,9 +179,10 @@ namespace cms::soa {
173179 TupleOrPointerType tupleOrPointer () { return {addr_, stride_}; }
174180
175181 public:
176- // address and stride
182+ // address, stride and size
177183 ScalarType const * addr_ = nullptr ;
178184 byte_size_type stride_ = 0 ;
185+ size_type size_ = 0 ;
179186 };
180187
181188 // Matryoshka template to avoid commas inside macros
@@ -200,8 +207,9 @@ namespace cms::soa {
200207 // default constructor
201208 SoAParametersImpl () = default ;
202209
203- // constructor from an address
204- SOA_HOST_DEVICE SOA_INLINE constexpr SoAParametersImpl (ValueType* addr) : addr_(addr) {}
210+ // constructor from address and size
211+ SOA_HOST_DEVICE SOA_INLINE constexpr SoAParametersImpl (ValueType* addr, size_type size)
212+ : addr_(addr), size_{size} {}
205213
206214 static constexpr bool checkAlignment (ValueType* addr, byte_size_type alignment) {
207215 return reinterpret_cast <intptr_t >(addr) % alignment;
@@ -212,6 +220,7 @@ namespace cms::soa {
212220 public:
213221 // scalar or column
214222 ValueType* addr_ = nullptr ;
223+ size_type size_ = 0 ;
215224 };
216225
217226 // Templated parameter specialisation for Eigen columns
@@ -229,9 +238,9 @@ namespace cms::soa {
229238 // default constructor
230239 SoAParametersImpl () = default ;
231240
232- // constructor from individual address and stride
233- SOA_HOST_DEVICE SOA_INLINE constexpr SoAParametersImpl (ScalarType* addr, byte_size_type stride)
234- : addr_(addr), stride_(stride) {}
241+ // constructor from individual address, stride and size
242+ SOA_HOST_DEVICE SOA_INLINE constexpr SoAParametersImpl (ScalarType* addr, byte_size_type stride, size_type size )
243+ : addr_(addr), stride_(stride), size_(size) {}
235244
236245 // constructor from address and stride packed in a tuple
237246 SOA_HOST_DEVICE SOA_INLINE constexpr SoAParametersImpl (TupleOrPointerType const & tuple)
@@ -245,9 +254,10 @@ namespace cms::soa {
245254 TupleOrPointerType tupleOrPointer () { return {addr_, stride_}; }
246255
247256 public:
248- // address and stride
257+ // address, stride and size
249258 ScalarType* addr_ = nullptr ;
250259 byte_size_type stride_ = 0 ;
260+ size_type size_ = 0 ;
251261 };
252262
253263 // Matryoshka template to avoid commas inside macros
@@ -268,13 +278,13 @@ namespace cms::soa {
268278 template <SoAColumnType COLUMN_TYPE, typename T>
269279 SOA_HOST_DEVICE SOA_INLINE constexpr SoAParametersImpl<COLUMN_TYPE, T> const_cast_SoAParametersImpl (
270280 SoAConstParametersImpl<COLUMN_TYPE, T> const & o) {
271- return SoAParametersImpl<COLUMN_TYPE, T>{non_const_ptr (o.addr_ )};
281+ return SoAParametersImpl<COLUMN_TYPE, T>{non_const_ptr (o.addr_ ), o. size_ };
272282 }
273283
274284 template <typename T>
275285 SOA_HOST_DEVICE SOA_INLINE constexpr SoAParametersImpl<SoAColumnType::eigen, T> const_cast_SoAParametersImpl (
276286 SoAConstParametersImpl<SoAColumnType::eigen, T> const & o) {
277- return SoAParametersImpl<SoAColumnType::eigen, T>{non_const_ptr (o.addr_ ), o.stride_ };
287+ return SoAParametersImpl<SoAColumnType::eigen, T>{non_const_ptr (o.addr_ ), o.stride_ , o. size_ };
278288 }
279289
280290 // Helper template managing the value at index idx within a column.
@@ -554,6 +564,7 @@ namespace cms::soa {
554564#endif
555565
556566 // Helper function to compute aligned size
567+ // this is an integer division -> it rounds size to the next multiple of alignment
557568 constexpr inline byte_size_type alignSize (byte_size_type size, byte_size_type alignment) {
558569 return ((size + alignment - 1 ) / alignment) * alignment;
559570 }
@@ -564,11 +575,12 @@ namespace cms::soa {
564575#define SOA_COLUMN (TYPE, NAME ) (_VALUE_TYPE_COLUMN, TYPE, NAME)
565576#define SOA_EIGEN_COLUMN (TYPE, NAME ) (_VALUE_TYPE_EIGEN_COLUMN, TYPE, NAME)
566577
567- /* Iterate on the macro MACRO and return the result as a comma separated list */
578+ /* Iterate on the macro MACRO and return the result as a comma separated list, converting
579+ the boost sequence into tuples and then into list */
568580#define _ITERATE_ON_ALL_COMMA (MACRO, DATA, ...) \
569581 BOOST_PP_TUPLE_ENUM (BOOST_PP_SEQ_TO_TUPLE(_ITERATE_ON_ALL(MACRO, DATA, __VA_ARGS__)))
570582
571- /* Iterate MACRO on all elements */
583+ /* Iterate MACRO on all elements of the boost sequence */
572584#define _ITERATE_ON_ALL (MACRO, DATA, ...) BOOST_PP_SEQ_FOR_EACH(MACRO, DATA, BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__))
573585
574586/* Switch on macros depending on scalar / column type */
@@ -599,6 +611,7 @@ namespace cms::soa {
599611 SOA_HOST_DEVICE SOA_INLINE SoAColumnAccessorsImpl (const SoAParametersImpl<SoAColumnType::column, T>& params)
600612 : params_(params) {}
601613 SOA_HOST_DEVICE SOA_INLINE T* operator ()() { return params_.addr_ ; }
614+
602615 using NoParamReturnType = T*;
603616 using ParamReturnType = T&;
604617 SOA_HOST_DEVICE SOA_INLINE T& operator ()(size_type index) { return params_.addr_ [index]; }
0 commit comments