1 #ifndef DataFormats_SoATemplate_interface_SoACommon_h 2 #define DataFormats_SoATemplate_interface_SoACommon_h 12 #include <type_traits> 14 #include <boost/preprocessor.hpp> 20 #define SOA_HOST_ONLY __host__ 21 #define SOA_DEVICE_ONLY __device__ 22 #define SOA_HOST_DEVICE __host__ __device__ 23 #define SOA_INLINE __forceinline__ 26 #define SOA_DEVICE_ONLY 27 #define SOA_HOST_DEVICE 28 #define SOA_INLINE inline __attribute__((always_inline)) 32 #if defined(__CUDACC__) && defined(__CUDA_ARCH__) 33 #define SOA_THROW_OUT_OF_RANGE(A) \ 35 printf("%s\n", (A)); \ 39 #define SOA_THROW_OUT_OF_RANGE(A) \ 40 { throw std::out_of_range(A); } 44 #define _VALUE_TYPE_SCALAR 0 45 #define _VALUE_TYPE_COLUMN 1 46 #define _VALUE_TYPE_EIGEN_COLUMN 2 49 #define CMS_SOA_BYTE_SIZE_TYPE std::size_t 64 namespace RestrictQualify {
70 namespace RangeChecking {
76 template <
typename T,
bool RESTRICT_QUALIFY>
100 template <SoAColumnType COLUMN_TYPE,
typename T>
103 template <SoAColumnType COLUMN_TYPE,
typename T>
107 template <SoAColumnType COLUMN_TYPE,
typename T>
135 template <
typename T>
170 template <SoAColumnType COLUMN_TYPE>
172 template <
typename T>
177 template <SoAColumnType COLUMN_TYPE,
typename T>
204 template <
typename T>
238 template <SoAColumnType COLUMN_TYPE>
240 template <
typename T>
246 template <
typename T>
247 constexpr
inline std::remove_const_t<T>* non_const_ptr(
T*
p) {
248 return const_cast<std::remove_const_t<T>*
>(
p);
252 template <SoAColumnType COLUMN_TYPE,
typename T>
258 template <
typename T>
278 using Ptr =
typename Restr::Pointer;
279 using Ref =
typename Restr::Reference;
335 #ifdef EIGEN_WORLD_VERSION 337 template <
class C, byte_
size_type ALIGNMENT,
bool RESTRICT_QUALIFY>
341 using MapType = Eigen::Map<C, 0, Eigen::InnerStride<Eigen::Dynamic>>;
342 using CMapType =
const Eigen::Map<const C, 0, Eigen::InnerStride<Eigen::Dynamic>>;
345 using Ptr =
typename Restr::Pointer;
346 using Ref =
typename Restr::Reference;
347 using PtrToConst =
typename Restr::PointerToConst;
348 using RefToConst =
typename Restr::ReferenceToConst;
351 : val_(
col +
i, C::RowsAtCompileTime, C::ColsAtCompileTime, Eigen::InnerStride<Eigen::Dynamic>(
stride)),
353 cVal_(crCol_ +
i, C::RowsAtCompileTime, C::ColsAtCompileTime, Eigen::InnerStride<Eigen::Dynamic>(
stride)),
358 C::RowsAtCompileTime,
359 C::ColsAtCompileTime,
360 Eigen::InnerStride<Eigen::Dynamic>(
params.stride_)),
363 C::RowsAtCompileTime,
364 C::ColsAtCompileTime,
365 Eigen::InnerStride<Eigen::Dynamic>(
params.stride_)),
366 stride_(
params.stride_) {}
397 template <
class C, byte_
size_type ALIGNMENT,
bool RESTRICT_QUALIFY>
399 static_assert(!
sizeof(
C),
400 "Eigen/Core should be pre-included before the SoA headers to enable support for Eigen columns.");
416 using Ptr =
typename Restr::Pointer;
417 using Ref =
typename Restr::Reference;
462 #ifdef EIGEN_WORLD_VERSION 464 template <
class C, byte_
size_type ALIGNMENT,
bool RESTRICT_QUALIFY>
468 using CMapType = Eigen::Map<const C, 0, Eigen::InnerStride<Eigen::Dynamic>>;
474 cVal_(crCol_ +
i, C::RowsAtCompileTime, C::ColsAtCompileTime, Eigen::InnerStride<Eigen::Dynamic>(
stride)),
480 C::RowsAtCompileTime,
481 C::ColsAtCompileTime,
482 Eigen::InnerStride<Eigen::Dynamic>(
params.stride_)),
483 stride_(
params.stride_) {}
497 const typename C::Scalar* __restrict__ crCol_;
503 template <
class C, byte_
size_type ALIGNMENT,
bool RESTRICT_QUALIFY>
505 static_assert(!
sizeof(
C),
506 "Eigen/Core should be pre-included before the SoA headers to enable support for Eigen columns.");
511 #ifdef EIGEN_WORLD_VERSION 514 using Type = Eigen::Map<const C, Eigen::AlignmentType::Unaligned, Eigen::InnerStride<Eigen::Dynamic>>;
522 data_, C::RowsAtCompileTime, C::ColsAtCompileTime, Eigen::InnerStride<Eigen::Dynamic>(
stride));
529 static DataHolder withData(
const typename C::Scalar*
data) {
return DataHolder(
data); }
535 static_assert(!
sizeof(
C),
536 "Eigen/Core should be pre-included before the SoA headers to enable support for Eigen columns.");
547 #define SOA_SCALAR(TYPE, NAME) (_VALUE_TYPE_SCALAR, TYPE, NAME) 548 #define SOA_COLUMN(TYPE, NAME) (_VALUE_TYPE_COLUMN, TYPE, NAME) 549 #define SOA_EIGEN_COLUMN(TYPE, NAME) (_VALUE_TYPE_EIGEN_COLUMN, TYPE, NAME) 552 #define _ITERATE_ON_ALL_COMMA(MACRO, DATA, ...) \ 553 BOOST_PP_TUPLE_ENUM(BOOST_PP_SEQ_TO_TUPLE(_ITERATE_ON_ALL(MACRO, DATA, __VA_ARGS__))) 556 #define _ITERATE_ON_ALL(MACRO, DATA, ...) BOOST_PP_SEQ_FOR_EACH(MACRO, DATA, BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__)) 559 #define _SWITCH_ON_TYPE(VALUE_TYPE, IF_SCALAR, IF_COLUMN, IF_EIGEN_COLUMN) \ 561 BOOST_PP_EQUAL(VALUE_TYPE, _VALUE_TYPE_SCALAR), \ 564 BOOST_PP_EQUAL(VALUE_TYPE, _VALUE_TYPE_COLUMN), \ 566 BOOST_PP_IF(BOOST_PP_EQUAL(VALUE_TYPE, _VALUE_TYPE_EIGEN_COLUMN), IF_EIGEN_COLUMN, BOOST_PP_EMPTY()))) 573 template <
typename, SoAColumnType, SoAAccessType, byte_
size_type,
bool>
581 template <
typename T, byte_
size_type alignment,
bool restrictQualify>
595 template <
typename T, byte_
size_type alignment,
bool restrictQualify>
609 template <
typename T, byte_
size_type alignment,
bool restrictQualify>
617 assert(
false &&
"Indexed access impossible for SoA scalars.");
625 template <
typename T, byte_
size_type alignment,
bool restrictQualify>
633 assert(
false &&
"Indexed access impossible for SoA scalars.");
641 template <
typename T, byte_
size_type alignment,
bool restrictQualify>
657 template <
typename T, byte_
size_type alignment,
bool restrictQualify>
662 using NoParamReturnType =
typename T::Scalar const*;
673 template <
typename T>
675 template <auto columnType>
677 template <auto accessType>
679 template <auto alignment>
681 template <auto restrictQualify>
710 template <
typename SOA,
712 typename std::enable_if_t<std::is_invocable_v<decltype(&SOA::soaToStreamInternal), SOA&, std::ostream&>>>
714 soa.soaToStreamInternal(os);
718 #endif // DataFormats_SoATemplate_interface_SoACommon_h
static constexpr auto valueSize
ValueType * TupleOrPointerType
typename Restr::PointerToConst PtrToConst
static constexpr bool enforced
constexpr byte_size_type alignSize(byte_size_type size, byte_size_type alignment)
static constexpr bool checkAlignment(TupleOrPointerType const &tuple, byte_size_type alignment)
std::ostream & operator<<(std::ostream &os, const SOA &soa)
const ValueType * TupleOrPointerType
mathSSE::Vec4< double > operator &(mathSSE::Vec4< double > a, mathSSE::Vec4< double > b)
static constexpr byte_size_type AMDCPU
static constexpr SoAColumnType columnType
std::tuple< ScalarType *, byte_size_type > TupleOrPointerType
T const & NoParamReturnType
const T & ParamReturnType
SoAConstParametersImpl< COLUMN_TYPE, T > ConstParams
TEMPL(T2) struct Divides void
add_restrict< T, RESTRICT_QUALIFY > Restr
SoAParametersImpl< SoAColumnType::scalar, T > params_
static constexpr auto valueSize
typename T::Scalar ScalarType
typename Restr::PointerToConst PtrToConst
const T * NoParamReturnType
#define _VALUE_TYPE_SCALAR
typename Restr::Value Val
static constexpr byte_size_type IntelCPU
typename Restr::Reference Ref
SoAConstParametersImpl< SoAColumnType::scalar, T > params_
static constexpr byte_size_type ARMCPU
static constexpr byte_size_type defaultSize
const T &__restrict__ ReferenceToConst
T const_cast_SoAParametersImpl(SoAConstParametersImpl< COLUMN_TYPE, T > const &o)
std::size_t byte_size_type
SoAConstParametersImpl()=default
reco::JetExtendedAssociation::JetExtendedData Value
ValueType
Type of the value held by a Value object.
const T & ReferenceToConst
SoAParametersImpl< COLUMN_TYPE, T > params
static constexpr SoAColumnType columnType
SoAParametersImpl< COLUMN_TYPE, T > params
#define _VALUE_TYPE_EIGEN_COLUMN
typename T::Scalar ScalarType
static constexpr bool relaxed
#define _VALUE_TYPE_COLUMN
SoAParametersImpl< SoAColumnType::column, T > params_
typename Restr::ReferenceToConst RefToConst
typename Restr::ReferenceToConst RefToConst
static constexpr byte_size_type NvidiaGPU
typename Restr::Pointer Ptr
typename Restr::Reference Ref
std::tuple< ScalarType *, byte_size_type > TupleOrPointerType
static constexpr bool checkAlignment(ValueType *addr, byte_size_type alignment)
typename SoAValue< SoAColumnType::eigen, T, alignment, restrictQualify >::MapType ParamReturnType
const T *__restrict__ PointerToConst
((always_inline)) typename T typename SoAValue< SoAColumnType::eigen, T, alignment, restrictQualify >::CMapType ParamReturnType
char data[epos_bytes_allocation]
SoAParametersImpl< SoAColumnType::eigen, T > params_
SoAParametersImpl()=default
typename Restr::Value Val
#define CMS_SOA_BYTE_SIZE_TYPE
SoAConstParametersImpl< SoAColumnType::eigen, T > params_
typename T::Scalar * NoParamReturnType
T &__restrict__ Reference
SoAConstParametersImpl< SoAColumnType::column, T > params_
typename Restr::Pointer Ptr
double scalar(const CLHEP::HepGenMatrix &m)
Return the matrix as a scalar. Raise an assertion if the matris is not .