Skip to content

Commit

Permalink
Added column pitch computation to SoAMetadata class.
Browse files Browse the repository at this point in the history
Integrated the definition of the subclass to the main one as we new have macro-generated members.
  • Loading branch information
ericcano committed Sep 8, 2021
1 parent ab40213 commit 453b4e7
Showing 1 changed file with 53 additions and 19 deletions.
72 changes: 53 additions & 19 deletions src/cudadev/DataFormats/SoAMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,39 @@ struct EigenConstMapMaker {
#define _DECLARE_SOA_DUMP_INFO(R, DATA, TYPE_NAME) \
BOOST_PP_EXPAND(_DECLARE_SOA_DUMP_INFO_IMPL TYPE_NAME)


/**
* SoAMetadata member computing column pitch
*/
#define _COMPUTE_SOA_COLUMN_PITCH_IMPL(VALUE_TYPE, CPP_TYPE, NAME) \
_SWITCH_ON_TYPE(VALUE_TYPE, \
/* Scalar */ \
size_t BOOST_PP_CAT(NAME, Pitch()) const { \
return (((sizeof(CPP_TYPE) - 1) / parent_.byteAlignment_) + 1) * parent_.byteAlignment_; \
} \
, \
/* Column */ \
size_t BOOST_PP_CAT(NAME, Pitch()) const { \
return (((parent_.nElements_ * sizeof(CPP_TYPE) - 1) / parent_.byteAlignment_) + 1) * parent_.byteAlignment_; \
} \
, \
/* Eigen column */ \
size_t BOOST_PP_CAT(NAME, Pitch()) const { \
return (((parent_.nElements_ * sizeof(CPP_TYPE::Scalar) - 1) / parent_.byteAlignment_) + 1) * parent_.byteAlignment_ \
* CPP_TYPE::RowsAtCompileTime * CPP_TYPE::ColsAtCompileTime; \
} \
, \
/* Fundamental type column */ \
size_t BOOST_PP_CAT(NAME, Pitch()) const { \
return (((parent_.nElements_ * sizeof(CPP_TYPE) - 1) / parent_.byteAlignment_) + 1) * parent_.byteAlignment_; \
} \
)

#define _COMPUTE_SOA_COLUMN_PITCH(R, DATA, TYPE_NAME) \
_COMPUTE_SOA_COLUMN_PITCH_IMPL TYPE_NAME



/**
* Computation of the column or scalar pointer location in the memory layout (at SoA construction time)
*/
Expand Down Expand Up @@ -503,23 +536,6 @@ struct EigenConstMapMaker {
#define _DO_RANGECHECK false
#endif

/**
* Helper/friend class allowing SoA introspection.
*/
template <class C>
struct SoAIntrospector {
friend C;
SOA_HOST_DEVICE_INLINE size_t size() const { return parent_.nElements_; }
SOA_HOST_DEVICE_INLINE size_t byteSize() const { return parent_.byteSize_; }
SOA_HOST_DEVICE_INLINE size_t byteAlignment() const { return parent_.byteAlignment_; }
SOA_HOST_DEVICE_INLINE std::byte* data() const { return parent_.mem_; }
SOA_HOST_DEVICE_INLINE C cloneToNewAddress(std::byte* addr) { return C(addr, parent_.nElements_, parent_.byteAlignment_ ); }

private:
SoAIntrospector(const C& parent): parent_(parent) {}
const C& parent_;
};

/*
* A macro defining a SoA (structure of variable sized arrays variant).
*/
Expand Down Expand Up @@ -552,8 +568,26 @@ struct CLASS {
return ret; \
} \
\
friend SoAIntrospector<CLASS>; \
SOA_HOST_DEVICE_INLINE const SoAIntrospector<CLASS> soaMetadata() const { return SoAIntrospector<CLASS>(*this); } \
/** \
* Helper/friend class allowing SoA introspection. \
*/ \
struct SoAMetadata { \
friend CLASS; \
SOA_HOST_DEVICE_INLINE size_t size() const { return parent_.nElements_; } \
SOA_HOST_DEVICE_INLINE size_t byteSize() const { return parent_.byteSize_; } \
SOA_HOST_DEVICE_INLINE size_t byteAlignment() const { return parent_.byteAlignment_; } \
SOA_HOST_DEVICE_INLINE std::byte* data() const { return parent_.mem_; } \
SOA_HOST_DEVICE_INLINE CLASS cloneToNewAddress(std::byte* addr) { \
return CLASS(addr, parent_.nElements_, parent_.byteAlignment_ ); \
} \
_ITERATE_ON_ALL(_COMPUTE_SOA_COLUMN_PITCH, ~, __VA_ARGS__) \
\
private: \
SoAMetadata(const CLASS& parent): parent_(parent) {} \
const CLASS& parent_; \
}; \
friend SoAMetadata; \
SOA_HOST_DEVICE_INLINE const SoAMetadata soaMetadata() const { return SoAMetadata(*this); } \
\
/* Constructor relying on user provided storage */ \
SOA_HOST_ONLY CLASS(std::byte* mem, size_t nElements, size_t byteAlignment = defaultAlignment): \
Expand Down

0 comments on commit 453b4e7

Please sign in to comment.