1 #ifndef DataFormats_SoATemplate_interface_SoACommon_h 2 #define DataFormats_SoATemplate_interface_SoACommon_h 12 #include <type_traits> 14 #include <boost/preprocessor.hpp> 19 #if defined(__CUDACC__) || defined(__HIPCC__) 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)); \ 38 #elif defined(__HIPCC__) && defined(__HIP_DEVICE_COMPILE__) 39 #define SOA_THROW_OUT_OF_RANGE(A) \ 41 printf("%s\n", (A)); \ 45 #define SOA_THROW_OUT_OF_RANGE(A) \ 46 { throw std::out_of_range(A); } 50 #define _VALUE_TYPE_SCALAR 0 51 #define _VALUE_TYPE_COLUMN 1 52 #define _VALUE_TYPE_EIGEN_COLUMN 2 57 #define CMS_SOA_BYTE_SIZE_TYPE std::size_t 72 namespace RestrictQualify {
78 namespace RangeChecking {
84 template <
typename T,
bool RESTRICT_QUALIFY>
108 template <SoAColumnType COLUMN_TYPE,
typename T>
111 template <SoAColumnType COLUMN_TYPE,
typename T>
115 template <SoAColumnType COLUMN_TYPE,
typename T>
145 template <
typename T>
182 template <SoAColumnType COLUMN_TYPE>
184 template <
typename T>
189 template <SoAColumnType COLUMN_TYPE,
typename T>
218 template <
typename T>
254 template <SoAColumnType COLUMN_TYPE>
256 template <
typename T>
262 template <
typename T>
263 constexpr inline std::remove_const_t<T>* non_const_ptr(
T*
p) {
264 return const_cast<std::remove_const_t<T>*
>(
p);
268 template <SoAColumnType COLUMN_TYPE,
typename T>
274 template <
typename T>
294 using Ptr =
typename Restr::Pointer;
295 using Ref =
typename Restr::Reference;
351 #ifdef EIGEN_WORLD_VERSION 353 template <
class C, byte_
size_type ALIGNMENT,
bool RESTRICT_QUALIFY>
357 using MapType = Eigen::Map<C, 0, Eigen::InnerStride<Eigen::Dynamic>>;
358 using CMapType =
const Eigen::Map<const C, 0, Eigen::InnerStride<Eigen::Dynamic>>;
361 using Ptr =
typename Restr::Pointer;
362 using Ref =
typename Restr::Reference;
363 using PtrToConst =
typename Restr::PointerToConst;
364 using RefToConst =
typename Restr::ReferenceToConst;
367 : val_(
col +
i, C::RowsAtCompileTime, C::ColsAtCompileTime, Eigen::InnerStride<Eigen::Dynamic>(
stride)),
369 cVal_(crCol_ +
i, C::RowsAtCompileTime, C::ColsAtCompileTime, Eigen::InnerStride<Eigen::Dynamic>(
stride)),
374 C::RowsAtCompileTime,
375 C::ColsAtCompileTime,
376 Eigen::InnerStride<Eigen::Dynamic>(
params.stride_)),
379 C::RowsAtCompileTime,
380 C::ColsAtCompileTime,
381 Eigen::InnerStride<Eigen::Dynamic>(
params.stride_)),
382 stride_(
params.stride_) {}
413 template <
class C, byte_
size_type ALIGNMENT,
bool RESTRICT_QUALIFY>
415 static_assert(!
sizeof(
C),
416 "Eigen/Core should be pre-included before the SoA headers to enable support for Eigen columns.");
432 using Ptr =
typename Restr::Pointer;
433 using Ref =
typename Restr::Reference;
478 #ifdef EIGEN_WORLD_VERSION 480 template <
class C, byte_
size_type ALIGNMENT,
bool RESTRICT_QUALIFY>
484 using CMapType = Eigen::Map<const C, 0, Eigen::InnerStride<Eigen::Dynamic>>;
490 cVal_(crCol_ +
i, C::RowsAtCompileTime, C::ColsAtCompileTime, Eigen::InnerStride<Eigen::Dynamic>(
stride)),
496 C::RowsAtCompileTime,
497 C::ColsAtCompileTime,
498 Eigen::InnerStride<Eigen::Dynamic>(
params.stride_)),
499 stride_(
params.stride_) {}
513 const typename C::Scalar* __restrict__ crCol_;
519 template <
class C, byte_
size_type ALIGNMENT,
bool RESTRICT_QUALIFY>
521 static_assert(!
sizeof(
C),
522 "Eigen/Core should be pre-included before the SoA headers to enable support for Eigen columns.");
527 #ifdef EIGEN_WORLD_VERSION 530 using Type = Eigen::Map<const C, Eigen::AlignmentType::Unaligned, Eigen::InnerStride<Eigen::Dynamic>>;
538 data_, C::RowsAtCompileTime, C::ColsAtCompileTime, Eigen::InnerStride<Eigen::Dynamic>(
stride));
545 static DataHolder withData(
const typename C::Scalar*
data) {
return DataHolder(
data); }
551 static_assert(!
sizeof(
C),
552 "Eigen/Core should be pre-included before the SoA headers to enable support for Eigen columns.");
563 #define SOA_SCALAR(TYPE, NAME) (_VALUE_TYPE_SCALAR, TYPE, NAME) 564 #define SOA_COLUMN(TYPE, NAME) (_VALUE_TYPE_COLUMN, TYPE, NAME) 565 #define SOA_EIGEN_COLUMN(TYPE, NAME) (_VALUE_TYPE_EIGEN_COLUMN, TYPE, NAME) 568 #define _ITERATE_ON_ALL_COMMA(MACRO, DATA, ...) \ 569 BOOST_PP_TUPLE_ENUM(BOOST_PP_SEQ_TO_TUPLE(_ITERATE_ON_ALL(MACRO, DATA, __VA_ARGS__))) 572 #define _ITERATE_ON_ALL(MACRO, DATA, ...) BOOST_PP_SEQ_FOR_EACH(MACRO, DATA, BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__)) 575 #define _SWITCH_ON_TYPE(VALUE_TYPE, IF_SCALAR, IF_COLUMN, IF_EIGEN_COLUMN) \ 577 BOOST_PP_EQUAL(VALUE_TYPE, _VALUE_TYPE_SCALAR), \ 580 BOOST_PP_EQUAL(VALUE_TYPE, _VALUE_TYPE_COLUMN), \ 582 BOOST_PP_IF(BOOST_PP_EQUAL(VALUE_TYPE, _VALUE_TYPE_EIGEN_COLUMN), IF_EIGEN_COLUMN, BOOST_PP_EMPTY()))) 589 template <
typename, SoAColumnType, SoAAccessType, byte_
size_type,
bool>
597 template <
typename T, byte_
size_type alignment,
bool restrictQualify>
611 template <
typename T, byte_
size_type alignment,
bool restrictQualify>
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>
649 assert(
false &&
"Indexed access impossible for SoA scalars.");
657 template <
typename T, byte_
size_type alignment,
bool restrictQualify>
673 template <
typename T, byte_
size_type alignment,
bool restrictQualify>
678 using NoParamReturnType =
typename T::Scalar const*;
689 template <
typename T>
691 template <auto columnType>
693 template <auto accessType>
695 template <auto alignment>
697 template <auto restrictQualify>
726 template <
typename SOA,
728 typename std::enable_if_t<std::is_invocable_v<decltype(&SOA::soaToStreamInternal), SOA&, std::ostream&>>>
730 soa.soaToStreamInternal(os);
734 #endif // DataFormats_SoATemplate_interface_SoACommon_h static constexpr auto valueSize
ValueType * TupleOrPointerType
typename Restr::PointerToConst PtrToConst
static constexpr bool enforced
TupleOrPointerType tupleOrPointer()
Basic3DVector & operator=(const Basic3DVector &)=default
Assignment operator.
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
constexpr uint32_t stride
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_
ValueType const byte_size_type alignment
TupleOrPointerType tupleOrPointer()
typename Restr::ReferenceToConst RefToConst
TupleOrPointerType tupleOrPointer()
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 .