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 55 #define CMS_SOA_BYTE_SIZE_TYPE std::size_t 70 namespace RestrictQualify {
76 namespace RangeChecking {
82 template <
typename T,
bool RESTRICT_QUALIFY>
106 template <SoAColumnType COLUMN_TYPE,
typename T>
109 template <SoAColumnType COLUMN_TYPE,
typename T>
113 template <SoAColumnType COLUMN_TYPE,
typename T>
141 template <
typename T>
176 template <SoAColumnType COLUMN_TYPE>
178 template <
typename T>
183 template <SoAColumnType COLUMN_TYPE,
typename T>
210 template <
typename T>
244 template <SoAColumnType COLUMN_TYPE>
246 template <
typename T>
252 template <
typename T>
253 constexpr
inline std::remove_const_t<T>* non_const_ptr(
T*
p) {
254 return const_cast<std::remove_const_t<T>*
>(
p);
258 template <SoAColumnType COLUMN_TYPE,
typename T>
264 template <
typename T>
284 using Ptr =
typename Restr::Pointer;
285 using Ref =
typename Restr::Reference;
341 #ifdef EIGEN_WORLD_VERSION 343 template <
class C, byte_
size_type ALIGNMENT,
bool RESTRICT_QUALIFY>
347 using MapType = Eigen::Map<C, 0, Eigen::InnerStride<Eigen::Dynamic>>;
348 using CMapType =
const Eigen::Map<const C, 0, Eigen::InnerStride<Eigen::Dynamic>>;
351 using Ptr =
typename Restr::Pointer;
352 using Ref =
typename Restr::Reference;
353 using PtrToConst =
typename Restr::PointerToConst;
354 using RefToConst =
typename Restr::ReferenceToConst;
357 : val_(
col +
i, C::RowsAtCompileTime, C::ColsAtCompileTime, Eigen::InnerStride<Eigen::Dynamic>(
stride)),
359 cVal_(crCol_ +
i, C::RowsAtCompileTime, C::ColsAtCompileTime, Eigen::InnerStride<Eigen::Dynamic>(
stride)),
364 C::RowsAtCompileTime,
365 C::ColsAtCompileTime,
366 Eigen::InnerStride<Eigen::Dynamic>(
params.stride_)),
369 C::RowsAtCompileTime,
370 C::ColsAtCompileTime,
371 Eigen::InnerStride<Eigen::Dynamic>(
params.stride_)),
372 stride_(
params.stride_) {}
403 template <
class C, byte_
size_type ALIGNMENT,
bool RESTRICT_QUALIFY>
405 static_assert(!
sizeof(
C),
406 "Eigen/Core should be pre-included before the SoA headers to enable support for Eigen columns.");
422 using Ptr =
typename Restr::Pointer;
423 using Ref =
typename Restr::Reference;
468 #ifdef EIGEN_WORLD_VERSION 470 template <
class C, byte_
size_type ALIGNMENT,
bool RESTRICT_QUALIFY>
474 using CMapType = Eigen::Map<const C, 0, Eigen::InnerStride<Eigen::Dynamic>>;
480 cVal_(crCol_ +
i, C::RowsAtCompileTime, C::ColsAtCompileTime, Eigen::InnerStride<Eigen::Dynamic>(
stride)),
486 C::RowsAtCompileTime,
487 C::ColsAtCompileTime,
488 Eigen::InnerStride<Eigen::Dynamic>(
params.stride_)),
489 stride_(
params.stride_) {}
503 const typename C::Scalar* __restrict__ crCol_;
509 template <
class C, byte_
size_type ALIGNMENT,
bool RESTRICT_QUALIFY>
511 static_assert(!
sizeof(
C),
512 "Eigen/Core should be pre-included before the SoA headers to enable support for Eigen columns.");
517 #ifdef EIGEN_WORLD_VERSION 520 using Type = Eigen::Map<const C, Eigen::AlignmentType::Unaligned, Eigen::InnerStride<Eigen::Dynamic>>;
528 data_, C::RowsAtCompileTime, C::ColsAtCompileTime, Eigen::InnerStride<Eigen::Dynamic>(
stride));
535 static DataHolder withData(
const typename C::Scalar*
data) {
return DataHolder(
data); }
541 static_assert(!
sizeof(
C),
542 "Eigen/Core should be pre-included before the SoA headers to enable support for Eigen columns.");
553 #define SOA_SCALAR(TYPE, NAME) (_VALUE_TYPE_SCALAR, TYPE, NAME) 554 #define SOA_COLUMN(TYPE, NAME) (_VALUE_TYPE_COLUMN, TYPE, NAME) 555 #define SOA_EIGEN_COLUMN(TYPE, NAME) (_VALUE_TYPE_EIGEN_COLUMN, TYPE, NAME) 558 #define _ITERATE_ON_ALL_COMMA(MACRO, DATA, ...) \ 559 BOOST_PP_TUPLE_ENUM(BOOST_PP_SEQ_TO_TUPLE(_ITERATE_ON_ALL(MACRO, DATA, __VA_ARGS__))) 562 #define _ITERATE_ON_ALL(MACRO, DATA, ...) BOOST_PP_SEQ_FOR_EACH(MACRO, DATA, BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__)) 565 #define _SWITCH_ON_TYPE(VALUE_TYPE, IF_SCALAR, IF_COLUMN, IF_EIGEN_COLUMN) \ 567 BOOST_PP_EQUAL(VALUE_TYPE, _VALUE_TYPE_SCALAR), \ 570 BOOST_PP_EQUAL(VALUE_TYPE, _VALUE_TYPE_COLUMN), \ 572 BOOST_PP_IF(BOOST_PP_EQUAL(VALUE_TYPE, _VALUE_TYPE_EIGEN_COLUMN), IF_EIGEN_COLUMN, BOOST_PP_EMPTY()))) 579 template <
typename, SoAColumnType, SoAAccessType, byte_
size_type,
bool>
587 template <
typename T, byte_
size_type alignment,
bool restrictQualify>
601 template <
typename T, byte_
size_type alignment,
bool restrictQualify>
615 template <
typename T, byte_
size_type alignment,
bool restrictQualify>
623 assert(
false &&
"Indexed access impossible for SoA scalars.");
631 template <
typename T, byte_
size_type alignment,
bool restrictQualify>
639 assert(
false &&
"Indexed access impossible for SoA scalars.");
647 template <
typename T, byte_
size_type alignment,
bool restrictQualify>
663 template <
typename T, byte_
size_type alignment,
bool restrictQualify>
668 using NoParamReturnType =
typename T::Scalar const*;
679 template <
typename T>
681 template <auto columnType>
683 template <auto accessType>
685 template <auto alignment>
687 template <auto restrictQualify>
716 template <
typename SOA,
718 typename std::enable_if_t<std::is_invocable_v<decltype(&SOA::soaToStreamInternal), SOA&, std::ostream&>>>
720 soa.soaToStreamInternal(os);
724 #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 .