From c43c08d457c3ed10c2a9cd4dfeeb25dbb64a4ac6 Mon Sep 17 00:00:00 2001 From: David Rohr Date: Sun, 27 Dec 2020 13:04:48 +0100 Subject: [PATCH] GPU: Make more headers compatible to GPU --- .../TPC/include/DataFormatsTPC/TrackTPC.h | 85 ++++++++++--------- .../include/CommonDataFormat/RangeReference.h | 53 ++++++------ 2 files changed, 70 insertions(+), 68 deletions(-) diff --git a/DataFormats/Detectors/TPC/include/DataFormatsTPC/TrackTPC.h b/DataFormats/Detectors/TPC/include/DataFormatsTPC/TrackTPC.h index d26d00b979ff6..0b0ddb49f774c 100644 --- a/DataFormats/Detectors/TPC/include/DataFormatsTPC/TrackTPC.h +++ b/DataFormats/Detectors/TPC/include/DataFormatsTPC/TrackTPC.h @@ -11,6 +11,7 @@ #ifndef ALICEO2_TPC_TRACKTPC #define ALICEO2_TPC_TRACKTPC +#include "GPUCommonDef.h" #include "ReconstructionDataFormats/Track.h" #include "CommonDataFormat/RangeReference.h" #include "DataFormatsTPC/ClusterNative.h" @@ -40,42 +41,42 @@ class TrackTPC : public o2::track::TrackParCov using o2::track::TrackParCov::TrackParCov; // inherit /// Default constructor - TrackTPC() = default; + GPUdDefault() TrackTPC() = default; /// Destructor - ~TrackTPC() = default; - - unsigned short getFlags() const { return mFlags; } - unsigned short getClustersSideInfo() const { return mFlags & HasBothSidesClusters; } - bool hasASideClusters() const { return mFlags & HasASideClusters; } - bool hasCSideClusters() const { return mFlags & HasCSideClusters; } - bool hasBothSidesClusters() const { return (mFlags & (HasASideClusters | HasCSideClusters)) == (HasASideClusters | HasCSideClusters); } - bool hasASideClustersOnly() const { return (mFlags & HasBothSidesClusters) == HasASideClusters; } - bool hasCSideClustersOnly() const { return (mFlags & HasBothSidesClusters) == HasCSideClusters; } - - void setHasASideClusters() { mFlags |= HasASideClusters; } - void setHasCSideClusters() { mFlags |= HasCSideClusters; } - - float getTime0() const { return mTime0; } ///< Reference time of the track, i.e. t-bins of a primary track with eta=0. - float getDeltaTBwd() const { return mDeltaTBwd; } ///< max possible decrement to getTimeVertex - float getDeltaTFwd() const { return mDeltaTFwd; } ///< max possible increment to getTimeVertex - void setDeltaTBwd(float t) { mDeltaTBwd = t; } ///< set max possible decrement to getTimeVertex - void setDeltaTFwd(float t) { mDeltaTFwd = t; } ///< set max possible increment to getTimeVertex - - float getChi2() const { return mChi2; } - const o2::track::TrackParCov& getOuterParam() const { return mOuterParam; } - void setTime0(float v) { mTime0 = v; } - void setChi2(float v) { mChi2 = v; } - void setOuterParam(o2::track::TrackParCov&& v) { mOuterParam = v; } - const ClusRef& getClusterRef() const { return mClustersReference; } - void shiftFirstClusterRef(int dif) { mClustersReference.setFirstEntry(dif + mClustersReference.getFirstEntry()); } - int getNClusters() const { return mClustersReference.getEntries(); } - int getNClusterReferences() const { return getNClusters(); } - void setClusterRef(uint32_t entry, uint16_t ncl) { mClustersReference.set(entry, ncl); } + GPUdDefault() ~TrackTPC() = default; + + GPUd() unsigned short getFlags() const { return mFlags; } + GPUd() unsigned short getClustersSideInfo() const { return mFlags & HasBothSidesClusters; } + GPUd() bool hasASideClusters() const { return mFlags & HasASideClusters; } + GPUd() bool hasCSideClusters() const { return mFlags & HasCSideClusters; } + GPUd() bool hasBothSidesClusters() const { return (mFlags & (HasASideClusters | HasCSideClusters)) == (HasASideClusters | HasCSideClusters); } + GPUd() bool hasASideClustersOnly() const { return (mFlags & HasBothSidesClusters) == HasASideClusters; } + GPUd() bool hasCSideClustersOnly() const { return (mFlags & HasBothSidesClusters) == HasCSideClusters; } + + GPUd() void setHasASideClusters() { mFlags |= HasASideClusters; } + GPUd() void setHasCSideClusters() { mFlags |= HasCSideClusters; } + + GPUd() float getTime0() const { return mTime0; } ///< Reference time of the track, i.e. t-bins of a primary track with eta=0. + GPUd() float getDeltaTBwd() const { return mDeltaTBwd; } ///< max possible decrement to getTimeVertex + GPUd() float getDeltaTFwd() const { return mDeltaTFwd; } ///< max possible increment to getTimeVertex + GPUd() void setDeltaTBwd(float t) { mDeltaTBwd = t; } ///< set max possible decrement to getTimeVertex + GPUd() void setDeltaTFwd(float t) { mDeltaTFwd = t; } ///< set max possible increment to getTimeVertex + + GPUd() float getChi2() const { return mChi2; } + GPUd() const o2::track::TrackParCov& getOuterParam() const { return mOuterParam; } + GPUd() void setTime0(float v) { mTime0 = v; } + GPUd() void setChi2(float v) { mChi2 = v; } + GPUd() void setOuterParam(o2::track::TrackParCov&& v) { mOuterParam = v; } + GPUd() const ClusRef& getClusterRef() const { return mClustersReference; } + GPUd() void shiftFirstClusterRef(int dif) { mClustersReference.setFirstEntry(dif + mClustersReference.getFirstEntry()); } + GPUd() int getNClusters() const { return mClustersReference.getEntries(); } + GPUd() int getNClusterReferences() const { return getNClusters(); } + GPUd() void setClusterRef(uint32_t entry, uint16_t ncl) { mClustersReference.set(entry, ncl); } template - static inline void getClusterReference(T& clinfo, int nCluster, - uint8_t& sectorIndex, uint8_t& rowIndex, uint32_t& clusterIndex, const ClusRef& ref) + GPUd() static inline void getClusterReference(T& clinfo, int nCluster, + uint8_t& sectorIndex, uint8_t& rowIndex, uint32_t& clusterIndex, const ClusRef& ref) { // data for given tracks starts at clinfo[ ref.getFirstEntry() ], // 1st ref.getEntries() cluster indices are stored as uint32_t @@ -90,15 +91,15 @@ class TrackTPC : public o2::track::TrackParCov } template - inline void getClusterReference(T& clinfo, int nCluster, - uint8_t& sectorIndex, uint8_t& rowIndex, uint32_t& clusterIndex) const + GPUd() inline void getClusterReference(T& clinfo, int nCluster, + uint8_t& sectorIndex, uint8_t& rowIndex, uint32_t& clusterIndex) const { getClusterReference(clinfo, nCluster, sectorIndex, rowIndex, clusterIndex, mClustersReference); } template - static inline const o2::tpc::ClusterNative& getCluster(T& clinfo, int nCluster, - const o2::tpc::ClusterNativeAccess& clusters, uint8_t& sectorIndex, uint8_t& rowIndex, const ClusRef& ref) + GPUd() static inline const o2::tpc::ClusterNative& getCluster(T& clinfo, int nCluster, + const o2::tpc::ClusterNativeAccess& clusters, uint8_t& sectorIndex, uint8_t& rowIndex, const ClusRef& ref) { uint32_t clusterIndex; getClusterReference(clinfo, nCluster, sectorIndex, rowIndex, clusterIndex, ref); @@ -106,22 +107,22 @@ class TrackTPC : public o2::track::TrackParCov } template - inline const o2::tpc::ClusterNative& getCluster(T& clinfo, int nCluster, - const o2::tpc::ClusterNativeAccess& clusters, uint8_t& sectorIndex, uint8_t& rowIndex) const + GPUd() inline const o2::tpc::ClusterNative& getCluster(T& clinfo, int nCluster, + const o2::tpc::ClusterNativeAccess& clusters, uint8_t& sectorIndex, uint8_t& rowIndex) const { return getCluster(clinfo, nCluster, clusters, sectorIndex, rowIndex, mClustersReference); } template - inline const o2::tpc::ClusterNative& getCluster(T& clinfo, int nCluster, - const o2::tpc::ClusterNativeAccess& clusters) const + GPUd() inline const o2::tpc::ClusterNative& getCluster(T& clinfo, int nCluster, + const o2::tpc::ClusterNativeAccess& clusters) const { uint8_t sectorIndex, rowIndex; return (getCluster(clinfo, nCluster, clusters, sectorIndex, rowIndex)); } - const dEdxInfo& getdEdx() const { return mdEdx; } - void setdEdx(const dEdxInfo& v) { mdEdx = v; } + GPUd() const dEdxInfo& getdEdx() const { return mdEdx; } + GPUd() void setdEdx(const dEdxInfo& v) { mdEdx = v; } private: float mTime0 = 0.f; ///< Reference Z of the track assumed for the vertex, scaled with pseudo diff --git a/DataFormats/common/include/CommonDataFormat/RangeReference.h b/DataFormats/common/include/CommonDataFormat/RangeReference.h index 1b2e77b229867..ae230bf324b4f 100644 --- a/DataFormats/common/include/CommonDataFormat/RangeReference.h +++ b/DataFormats/common/include/CommonDataFormat/RangeReference.h @@ -16,6 +16,7 @@ #define ALICEO2_RANGEREFERENCE_H #include "GPUCommonRtypes.h" +#include "GPUCommonDef.h" namespace o2 { @@ -27,22 +28,22 @@ template class RangeReference { public: - RangeReference(FirstEntry ent, NElem n) { set(ent, n); } - RangeReference(const RangeReference& src) = default; - RangeReference() = default; - ~RangeReference() = default; - void set(FirstEntry ent, NElem n) + GPUd() RangeReference(FirstEntry ent, NElem n) { set(ent, n); } + GPUdDefault() RangeReference(const RangeReference& src) = default; + GPUdDefault() RangeReference() = default; + GPUdDefault() ~RangeReference() = default; + GPUd() void set(FirstEntry ent, NElem n) { mFirstEntry = ent; mEntries = n; } - void clear() { set(0, 0); } - FirstEntry getFirstEntry() const { return mFirstEntry; } - NElem getEntries() const { return mEntries; } - void setFirstEntry(FirstEntry ent) { mFirstEntry = ent; } - void setEntries(NElem n) { mEntries = n; } - void changeEntriesBy(NElem inc) { mEntries += inc; } - bool operator==(const RangeReference& other) const + GPUd() void clear() { set(0, 0); } + GPUd() FirstEntry getFirstEntry() const { return mFirstEntry; } + GPUd() NElem getEntries() const { return mEntries; } + GPUd() void setFirstEntry(FirstEntry ent) { mFirstEntry = ent; } + GPUd() void setEntries(NElem n) { mEntries = n; } + GPUd() void changeEntriesBy(NElem inc) { mEntries += inc; } + GPUd() bool operator==(const RangeReference& other) const { return mFirstEntry == other.mFirstEntry && mEntries == other.mEntries; } @@ -58,34 +59,34 @@ class RangeReference template class RangeRefComp { - using Base = std::uint32_t; + using Base = unsigned int; private: static constexpr int NBitsTotal = sizeof(Base) * 8; static constexpr Base MaskN = ((0x1 << NBitsN) - 1); static constexpr Base MaskR = (~Base(0)) & (~MaskN); Base mData = 0; ///< packed 1st entry reference + N entries - void sanityCheck() + GPUd() void sanityCheck() { static_assert(NBitsN < NBitsTotal, "NBitsN too large"); } public: - RangeRefComp(int ent, int n) { set(ent, n); } - RangeRefComp() = default; - RangeRefComp(const RangeRefComp& src) = default; - void set(int ent, int n) + GPUd() RangeRefComp(int ent, int n) { set(ent, n); } + GPUdDefault() RangeRefComp() = default; + GPUdDefault() RangeRefComp(const RangeRefComp& src) = default; + GPUd() void set(int ent, int n) { mData = (Base(ent) << NBitsN) + (Base(n) & MaskN); } - static constexpr Base getMaxFirstEntry() { return MaskR >> NBitsN; } - static constexpr Base getMaxEntries() { return MaskN; } - int getFirstEntry() const { return mData >> NBitsN; } - int getEntries() const { return mData & ((0x1 << NBitsN) - 1); } - void setFirstEntry(int ent) { mData = (Base(ent) << NBitsN) | (mData & MaskN); } - void setEntries(int n) { mData = (mData & MaskR) | (Base(n) & MaskN); } - void changeEntriesBy(int inc) { setEntries(getEntries() + inc); } - bool operator==(const RangeRefComp& other) const + GPUd() static constexpr Base getMaxFirstEntry() { return MaskR >> NBitsN; } + GPUd() static constexpr Base getMaxEntries() { return MaskN; } + GPUd() int getFirstEntry() const { return mData >> NBitsN; } + GPUd() int getEntries() const { return mData & ((0x1 << NBitsN) - 1); } + GPUd() void setFirstEntry(int ent) { mData = (Base(ent) << NBitsN) | (mData & MaskN); } + GPUd() void setEntries(int n) { mData = (mData & MaskR) | (Base(n) & MaskN); } + GPUd() void changeEntriesBy(int inc) { setEntries(getEntries() + inc); } + GPUd() bool operator==(const RangeRefComp& other) const { return mData == other.mData; }