@@ -121,14 +121,15 @@ int TimeFrame<nLayers>::loadROFrameData(gsl::span<o2::itsmft::ROFRecord> rofs,
121121 const itsmft::TopologyDictionary* dict,
122122 const dataformats::MCTruthContainer<MCCompLabel>* mcLabels)
123123{
124- resetROFrameData ();
124+ resetROFrameData (rofs. size () );
125125
126126 GeometryTGeo* geom = GeometryTGeo::Instance ();
127127 geom->fillMatrixCache (o2::math_utils::bit2Mask (o2::math_utils::TransformType::T2L, o2::math_utils::TransformType::L2G));
128128
129- mNrof = 0 ;
129+ mNrof = rofs. size () ;
130130 clearResizeBoundedVector (mClusterSize , clusters.size (), mMemoryPool .get ());
131- for (auto & rof : rofs) {
131+ for (size_t iRof{0 }; iRof < rofs.size (); ++iRof) {
132+ const auto & rof = rofs[iRof];
132133 for (int clusterId{rof.getFirstEntry ()}; clusterId < rof.getFirstEntry () + rof.getNEntries (); ++clusterId) {
133134 const auto & c = clusters[clusterId];
134135
@@ -164,15 +165,13 @@ int TimeFrame<nLayers>::loadROFrameData(gsl::span<o2::itsmft::ROFRecord> rofs,
164165 addTrackingFrameInfoToLayer (layer, gloXYZ.x (), gloXYZ.y (), gloXYZ.z (), trkXYZ.x (), geom->getSensorRefAlpha (sensorID),
165166 std::array<float , 2 >{trkXYZ.y (), trkXYZ.z ()},
166167 std::array<float , 3 >{sigmaY2, sigmaYZ, sigmaZ2});
167-
168168 // / Rotate to the global frame
169169 addClusterToLayer (layer, gloXYZ.x (), gloXYZ.y (), gloXYZ.z (), mUnsortedClusters [layer].size ());
170170 addClusterExternalIndexToLayer (layer, clusterId);
171171 }
172172 for (unsigned int iL{0 }; iL < mUnsortedClusters .size (); ++iL) {
173- mROFramesClusters [iL]. push_back ( mUnsortedClusters [iL].size ());
173+ mROFramesClusters [iL][iRof + 1 ] = mUnsortedClusters [iL].size (); // effectively calculating and exclusive sum
174174 }
175- mNrof ++;
176175 }
177176
178177 for (auto i = 0 ; i < mNTrackletsPerCluster .size (); ++i) {
@@ -188,13 +187,13 @@ int TimeFrame<nLayers>::loadROFrameData(gsl::span<o2::itsmft::ROFRecord> rofs,
188187}
189188
190189template <int nLayers>
191- void TimeFrame<nLayers>::resetROFrameData()
190+ void TimeFrame<nLayers>::resetROFrameData(size_t nRofs )
192191{
193192 for (int iLayer{0 }; iLayer < nLayers; ++iLayer) {
194- deepVectorClear (mUnsortedClusters [iLayer], mMemoryPool .get ());
195- deepVectorClear (mTrackingFrameInfo [iLayer], mMemoryPool .get ());
193+ deepVectorClear (mUnsortedClusters [iLayer], getMaybeExternalHostResource ());
194+ deepVectorClear (mTrackingFrameInfo [iLayer], getMaybeExternalHostResource ());
195+ clearResizeBoundedVector (mROFramesClusters [iLayer], nRofs + 1 , getMaybeExternalHostResource ());
196196 deepVectorClear (mClusterExternalIndices [iLayer], mMemoryPool .get ());
197- clearResizeBoundedVector (mROFramesClusters [iLayer], 1 , mMemoryPool .get (), 0 );
198197
199198 if (iLayer < 2 ) {
200199 deepVectorClear (mTrackletsIndexROF [iLayer], mMemoryPool .get ());
@@ -298,11 +297,11 @@ void TimeFrame<nLayers>::initialise(const int iteration, const TrackingParameter
298297 clearResizeBoundedVector (mBogusClusters , trkParam.NLayers , mMemoryPool .get ());
299298 deepVectorClear (mTrackletClusters );
300299 for (unsigned int iLayer{0 }; iLayer < std::min ((int )mClusters .size (), maxLayers); ++iLayer) {
301- clearResizeBoundedVector (mClusters [iLayer], mUnsortedClusters [iLayer].size (), mMemoryPool . get ( ));
302- clearResizeBoundedVector (mUsedClusters [iLayer], mUnsortedClusters [iLayer].size (), mMemoryPool . get ( ));
300+ clearResizeBoundedVector (mClusters [iLayer], mUnsortedClusters [iLayer].size (), getMaybeExternalHostResource (maxLayers != nLayers ));
301+ clearResizeBoundedVector (mUsedClusters [iLayer], mUnsortedClusters [iLayer].size (), getMaybeExternalHostResource (maxLayers != nLayers ));
303302 mPositionResolution [iLayer] = o2::gpu::CAMath::Sqrt (0 .5f * (trkParam.SystErrorZ2 [iLayer] + trkParam.SystErrorY2 [iLayer]) + trkParam.LayerResolution [iLayer] * trkParam.LayerResolution [iLayer]);
304303 }
305- clearResizeBoundedArray (mIndexTables , mNrof * (trkParam.ZBins * trkParam.PhiBins + 1 ), mMemoryPool . get ( ));
304+ clearResizeBoundedArray (mIndexTables , mNrof * (trkParam.ZBins * trkParam.PhiBins + 1 ), getMaybeExternalHostResource (maxLayers != nLayers ));
306305 clearResizeBoundedVector (mLines , mNrof , mMemoryPool .get ());
307306 clearResizeBoundedVector (mTrackletClusters , mNrof , mMemoryPool .get ());
308307
@@ -586,37 +585,24 @@ void TimeFrame<nLayers>::setMemoryPool(std::shared_ptr<BoundedMemoryResource> po
586585{
587586 mMemoryPool = pool;
588587
589- auto initVector = [&]<typename T>(bounded_vector<T> & vec)
590- {
591- bounded_vector<T> tmp (std::pmr::polymorphic_allocator<T>{mMemoryPool .get ()});
592- vec.swap (tmp);
593- };
594- auto initArrays = [&]<typename T, size_t S>(std::array<bounded_vector<T>, S> & arr)
588+ auto initVector = [&]<typename T>(bounded_vector<T> & vec, bool useExternal = false )
595589 {
596- for (size_t i{0 }; i < S; ++i) {
597- initVector (arr[i]);
598- }
590+ vec = bounded_vector<T>(std::pmr::polymorphic_allocator<T>{(useExternal) ? mExtMemoryPool .get () : mMemoryPool .get ()});
599591 };
600- auto initVectors = [&]<typename T>(std::vector<bounded_vector<T>> & vec )
592+ auto initContainers = [&]<typename Container>(Container & container, bool useExternal = false )
601593 {
602- for (size_t i{ 0 }; i < vec. size (); ++i ) {
603- initVector (vec[i] );
594+ for (auto & v : container ) {
595+ initVector (v, useExternal );
604596 }
605597 };
606-
598+ // these will only reside on the host for the cpu part
607599 initVector (mTotVertPerIteration );
608600 initVector (mPrimaryVertices );
609601 initVector (mROFramesPV );
610- initArrays (mClusters );
611- initArrays (mTrackingFrameInfo );
612- initArrays (mClusterExternalIndices );
613- initArrays (mROFramesClusters );
614- initArrays (mNTrackletsPerCluster );
615- initArrays (mNTrackletsPerClusterSum );
616- initArrays (mNClustersPerROF );
617- initArrays (mIndexTables );
618- initArrays (mUsedClusters );
619- initArrays (mUnsortedClusters );
602+ initContainers (mClusterExternalIndices );
603+ initContainers (mNTrackletsPerCluster );
604+ initContainers (mNTrackletsPerClusterSum );
605+ initContainers (mNClustersPerROF );
620606 initVector (mROFramesPV );
621607 initVector (mPrimaryVertices );
622608 initVector (mRoads );
@@ -628,12 +614,19 @@ void TimeFrame<nLayers>::setMemoryPool(std::shared_ptr<BoundedMemoryResource> po
628614 initVector (mPValphaX );
629615 initVector (mBogusClusters );
630616 initVector (mVerticesContributorLabels );
631- initArrays (mTrackletsIndexROF );
632- initVectors (mTracks );
633- initVectors (mTracklets );
634- initVectors (mCells );
635- initVectors (mCellsNeighbours );
636- initVectors (mCellsLookupTable );
617+ initContainers (mTrackletsIndexROF );
618+ initContainers (mTracks );
619+ initContainers (mTracklets );
620+ initContainers (mCells );
621+ initContainers (mCellsNeighbours );
622+ initContainers (mCellsLookupTable );
623+ // these will use possibly an externally provided allocator
624+ initContainers (mClusters , hasExternalHostAllocator ());
625+ initContainers (mUsedClusters , hasExternalHostAllocator ());
626+ initContainers (mUnsortedClusters , hasExternalHostAllocator ());
627+ initContainers (mIndexTables , hasExternalHostAllocator ());
628+ initContainers (mTrackingFrameInfo , hasExternalHostAllocator ());
629+ initContainers (mROFramesClusters , hasExternalHostAllocator ());
637630}
638631
639632template <int nLayers>
0 commit comments