@@ -121,14 +121,15 @@ int TimeFrame<nLayers>::loadROFrameData(gsl::span<o2::itsmft::ROFRecord> rofs,
121
121
const itsmft::TopologyDictionary* dict,
122
122
const dataformats::MCTruthContainer<MCCompLabel>* mcLabels)
123
123
{
124
- resetROFrameData ();
124
+ resetROFrameData (rofs. size () );
125
125
126
126
GeometryTGeo* geom = GeometryTGeo::Instance ();
127
127
geom->fillMatrixCache (o2::math_utils::bit2Mask (o2::math_utils::TransformType::T2L, o2::math_utils::TransformType::L2G));
128
128
129
- mNrof = 0 ;
129
+ mNrof = rofs. size () ;
130
130
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];
132
133
for (int clusterId{rof.getFirstEntry ()}; clusterId < rof.getFirstEntry () + rof.getNEntries (); ++clusterId) {
133
134
const auto & c = clusters[clusterId];
134
135
@@ -164,15 +165,13 @@ int TimeFrame<nLayers>::loadROFrameData(gsl::span<o2::itsmft::ROFRecord> rofs,
164
165
addTrackingFrameInfoToLayer (layer, gloXYZ.x (), gloXYZ.y (), gloXYZ.z (), trkXYZ.x (), geom->getSensorRefAlpha (sensorID),
165
166
std::array<float , 2 >{trkXYZ.y (), trkXYZ.z ()},
166
167
std::array<float , 3 >{sigmaY2, sigmaYZ, sigmaZ2});
167
-
168
168
// / Rotate to the global frame
169
169
addClusterToLayer (layer, gloXYZ.x (), gloXYZ.y (), gloXYZ.z (), mUnsortedClusters [layer].size ());
170
170
addClusterExternalIndexToLayer (layer, clusterId);
171
171
}
172
172
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
174
174
}
175
- mNrof ++;
176
175
}
177
176
178
177
for (auto i = 0 ; i < mNTrackletsPerCluster .size (); ++i) {
@@ -188,13 +187,13 @@ int TimeFrame<nLayers>::loadROFrameData(gsl::span<o2::itsmft::ROFRecord> rofs,
188
187
}
189
188
190
189
template <int nLayers>
191
- void TimeFrame<nLayers>::resetROFrameData()
190
+ void TimeFrame<nLayers>::resetROFrameData(size_t nRofs )
192
191
{
193
192
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 ());
196
196
deepVectorClear (mClusterExternalIndices [iLayer], mMemoryPool .get ());
197
- clearResizeBoundedVector (mROFramesClusters [iLayer], 1 , mMemoryPool .get (), 0 );
198
197
199
198
if (iLayer < 2 ) {
200
199
deepVectorClear (mTrackletsIndexROF [iLayer], mMemoryPool .get ());
@@ -298,11 +297,11 @@ void TimeFrame<nLayers>::initialise(const int iteration, const TrackingParameter
298
297
clearResizeBoundedVector (mBogusClusters , trkParam.NLayers , mMemoryPool .get ());
299
298
deepVectorClear (mTrackletClusters );
300
299
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 ));
303
302
mPositionResolution [iLayer] = o2::gpu::CAMath::Sqrt (0 .5f * (trkParam.SystErrorZ2 [iLayer] + trkParam.SystErrorY2 [iLayer]) + trkParam.LayerResolution [iLayer] * trkParam.LayerResolution [iLayer]);
304
303
}
305
- clearResizeBoundedArray (mIndexTables , mNrof * (trkParam.ZBins * trkParam.PhiBins + 1 ), mMemoryPool . get ( ));
304
+ clearResizeBoundedArray (mIndexTables , mNrof * (trkParam.ZBins * trkParam.PhiBins + 1 ), getMaybeExternalHostResource (maxLayers != nLayers ));
306
305
clearResizeBoundedVector (mLines , mNrof , mMemoryPool .get ());
307
306
clearResizeBoundedVector (mTrackletClusters , mNrof , mMemoryPool .get ());
308
307
@@ -586,37 +585,24 @@ void TimeFrame<nLayers>::setMemoryPool(std::shared_ptr<BoundedMemoryResource> po
586
585
{
587
586
mMemoryPool = pool;
588
587
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 )
595
589
{
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 ()});
599
591
};
600
- auto initVectors = [&]<typename T>(std::vector<bounded_vector<T>> & vec )
592
+ auto initContainers = [&]<typename Container>(Container & container, bool useExternal = false )
601
593
{
602
- for (size_t i{ 0 }; i < vec. size (); ++i ) {
603
- initVector (vec[i] );
594
+ for (auto & v : container ) {
595
+ initVector (v, useExternal );
604
596
}
605
597
};
606
-
598
+ // these will only reside on the host for the cpu part
607
599
initVector (mTotVertPerIteration );
608
600
initVector (mPrimaryVertices );
609
601
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 );
620
606
initVector (mROFramesPV );
621
607
initVector (mPrimaryVertices );
622
608
initVector (mRoads );
@@ -628,12 +614,19 @@ void TimeFrame<nLayers>::setMemoryPool(std::shared_ptr<BoundedMemoryResource> po
628
614
initVector (mPValphaX );
629
615
initVector (mBogusClusters );
630
616
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 ());
637
630
}
638
631
639
632
template <int nLayers>
0 commit comments