@@ -538,9 +538,15 @@ void TrackerTraits<NLayers>::findCellsNeighbours(const int iteration)
538538
539539template <int NLayers>
540540template <typename InputSeed>
541- void TrackerTraits<NLayers>::processNeighbours(int iteration, int iLayer, int iLevel, const bounded_vector<InputSeed>& currentCellSeed, const bounded_vector<int >& currentCellId, bounded_vector<TrackSeedN>& updatedCellSeeds, bounded_vector<int >& updatedCellsIds)
541+ void TrackerTraits<NLayers>::processNeighbours(int iteration, int iLayer, int iLevel, int startLevel, const bounded_vector<InputSeed>& currentCellSeed, const bounded_vector<int >& currentCellId, bounded_vector<TrackSeedN>& updatedCellSeeds, bounded_vector<int >& updatedCellsIds, bounded_vector<TrackSeedN>* terminalOut )
542542{
543543 auto propagator = o2::base::Propagator::Instance ();
544+ const bool terminal = terminalOut != nullptr ;
545+ const float chi2Max = mTrkParams [iteration].MaxChi2NDF * ((startLevel + 2 ) * 2 - 5 );
546+ const auto seedFilter = [chi2Max](const TrackSeedN& seed) {
547+ return seed.getQ2Pt () <= 1 .e3f && seed.getChi2 () <= chi2Max;
548+ };
549+ const size_t terminalBaseOffset = terminal ? terminalOut->size () : 0 ;
544550
545551 mTaskArena ->execute ([&] {
546552 auto forCellNeighbours = [&](auto Tag, int iCell, int offset = 0 ) -> int {
@@ -613,14 +619,26 @@ void TrackerTraits<NLayers>::processNeighbours(int iteration, int iLayer, int iL
613619 seed.setSecondTrackletIndex (neighbourCell.getSecondTrackletIndex ());
614620 }
615621
622+ if (terminal && !seedFilter (seed)) {
623+ continue ;
624+ }
625+
616626 if constexpr (decltype (Tag)::value == PassMode::OnePass::value) {
617- updatedCellSeeds.push_back (seed);
618- updatedCellsIds.push_back (neighbourCellId);
627+ if (terminal) {
628+ terminalOut->push_back (seed);
629+ } else {
630+ updatedCellSeeds.push_back (seed);
631+ updatedCellsIds.push_back (neighbourCellId);
632+ }
619633 } else if constexpr (decltype (Tag)::value == PassMode::TwoPassCount::value) {
620634 ++foundSeeds;
621635 } else if constexpr (decltype (Tag)::value == PassMode::TwoPassInsert::value) {
622- updatedCellSeeds[offset] = seed;
623- updatedCellsIds[offset++] = neighbourCellId;
636+ if (terminal) {
637+ (*terminalOut)[terminalBaseOffset + offset++] = seed;
638+ } else {
639+ updatedCellSeeds[offset] = seed;
640+ updatedCellsIds[offset++] = neighbourCellId;
641+ }
624642 } else {
625643 static_assert (false , " Unknown mode!" );
626644 }
@@ -644,8 +662,12 @@ void TrackerTraits<NLayers>::processNeighbours(int iteration, int iLayer, int iL
644662 if (totalNeighbours == 0 ) {
645663 return ;
646664 }
647- updatedCellSeeds.resize (totalNeighbours);
648- updatedCellsIds.resize (totalNeighbours);
665+ if (terminal) {
666+ terminalOut->resize (terminalBaseOffset + totalNeighbours);
667+ } else {
668+ updatedCellSeeds.resize (totalNeighbours);
669+ updatedCellsIds.resize (totalNeighbours);
670+ }
649671
650672 tbb::parallel_for (0 , nCells, [&](const int iCell) {
651673 int offset = perCellCount[iCell];
@@ -674,10 +696,6 @@ void TrackerTraits<NLayers>::findRoads(const int iteration)
674696 }
675697 for (int startLevel{mTrkParams [iteration].CellsPerRoad ()}; startLevel >= mTrkParams [iteration].CellMinimumLevel (); --startLevel) {
676698
677- auto seedFilter = [&](const auto & seed) {
678- return seed.getQ2Pt () <= 1 .e3 && seed.getChi2 () <= mTrkParams [iteration].MaxChi2NDF * ((startLevel + 2 ) * 2 - 5 );
679- };
680-
681699 bounded_vector<TrackSeedN> trackSeeds (mMemoryPool .get ());
682700 for (int startLayer{mTrkParams [iteration].NeighboursPerRoad ()}; startLayer >= startLevel - 1 ; --startLayer) {
683701 if ((mTrkParams [iteration].StartLayerMask & (1 << (startLayer + 2 ))) == 0 ) {
@@ -687,23 +705,32 @@ void TrackerTraits<NLayers>::findRoads(const int iteration)
687705 bounded_vector<int > lastCellId (mMemoryPool .get ()), updatedCellId (mMemoryPool .get ());
688706 bounded_vector<TrackSeedN> lastCellSeed (mMemoryPool .get ()), updatedCellSeed (mMemoryPool .get ());
689707
690- processNeighbours (iteration, startLayer, startLevel, mTimeFrame ->getCells ()[startLayer], lastCellId, updatedCellSeed, updatedCellId);
708+ // / A call is terminal when the inner loop will not execute another iteration
709+ // / after it. In that case, route the filtered seeds directly into trackSeeds
710+ // / so we never materialize the full unfiltered updatedCellSeed buffer.
711+ const bool firstCallTerminal = (startLayer - 1 ) <= 0 || startLevel <= 2 ;
712+ processNeighbours (iteration, startLayer, startLevel, startLevel,
713+ mTimeFrame ->getCells ()[startLayer], lastCellId,
714+ updatedCellSeed, updatedCellId,
715+ firstCallTerminal ? &trackSeeds : nullptr );
691716
692717 int level = startLevel;
693718 for (int iLayer{startLayer - 1 }; iLayer > 0 && level > 2 ; --iLayer) {
694719 lastCellSeed.swap (updatedCellSeed);
695720 lastCellId.swap (updatedCellId);
696721 deepVectorClear (updatedCellSeed); // / tame the memory peaks
697722 deepVectorClear (updatedCellId); // / tame the memory peaks
698- processNeighbours (iteration, iLayer, --level, lastCellSeed, lastCellId, updatedCellSeed, updatedCellId);
699- }
700- deepVectorClear (lastCellId); // / tame the memory peaks
701- deepVectorClear (lastCellSeed); // / tame the memory peaks
702-
703- if (!updatedCellSeed.empty ()) {
704- trackSeeds.reserve (trackSeeds.size () + std::count_if (updatedCellSeed.begin (), updatedCellSeed.end (), seedFilter));
705- std::copy_if (updatedCellSeed.begin (), updatedCellSeed.end (), std::back_inserter (trackSeeds), seedFilter);
706- }
723+ --level;
724+ const bool thisCallTerminal = (iLayer - 1 ) <= 0 || level <= 2 ;
725+ processNeighbours (iteration, iLayer, level, startLevel,
726+ lastCellSeed, lastCellId,
727+ updatedCellSeed, updatedCellId,
728+ thisCallTerminal ? &trackSeeds : nullptr );
729+ }
730+ deepVectorClear (lastCellId); // / tame the memory peaks
731+ deepVectorClear (lastCellSeed); // / tame the memory peaks
732+ deepVectorClear (updatedCellId); // / terminal call routed to trackSeeds; drop id buffer
733+ deepVectorClear (updatedCellSeed); // / terminal call routed to trackSeeds; drop seed buffer
707734 }
708735
709736 if (trackSeeds.empty ()) {
@@ -952,13 +979,13 @@ void TrackerTraits<NLayers>::setNThreads(int n, std::shared_ptr<tbb::task_arena>
952979}
953980
954981template class TrackerTraits <7 >;
955- template void TrackerTraits<7 >::processNeighbours<CellSeed>(int , int , int , const bounded_vector<CellSeed>&, const bounded_vector<int >&, bounded_vector<TrackSeed<7 >>&, bounded_vector<int >&);
956- template void TrackerTraits<7 >::processNeighbours<TrackSeed<7 >>(int , int , int , const bounded_vector<TrackSeed<7 >>&, const bounded_vector<int >&, bounded_vector<TrackSeed<7 >>&, bounded_vector<int >&);
982+ template void TrackerTraits<7 >::processNeighbours<CellSeed>(int , int , int , int , const bounded_vector<CellSeed>&, const bounded_vector<int >&, bounded_vector<TrackSeed<7 >>&, bounded_vector<int >&, bounded_vector<TrackSeed< 7 >>* );
983+ template void TrackerTraits<7 >::processNeighbours<TrackSeed<7 >>(int , int , int , int , const bounded_vector<TrackSeed<7 >>&, const bounded_vector<int >&, bounded_vector<TrackSeed<7 >>&, bounded_vector<int >&, bounded_vector<TrackSeed< 7 >>* );
957984// ALICE3 upgrade
958985#ifdef ENABLE_UPGRADES
959986template class TrackerTraits <11 >;
960- template void TrackerTraits<11 >::processNeighbours<CellSeed>(int , int , int , const bounded_vector<CellSeed>&, const bounded_vector<int >&, bounded_vector<TrackSeed<11 >>&, bounded_vector<int >&);
961- template void TrackerTraits<11 >::processNeighbours<TrackSeed<11 >>(int , int , int , const bounded_vector<TrackSeed<11 >>&, const bounded_vector<int >&, bounded_vector<TrackSeed<11 >>&, bounded_vector<int >&);
987+ template void TrackerTraits<11 >::processNeighbours<CellSeed>(int , int , int , int , const bounded_vector<CellSeed>&, const bounded_vector<int >&, bounded_vector<TrackSeed<11 >>&, bounded_vector<int >&, bounded_vector<TrackSeed< 11 >>* );
988+ template void TrackerTraits<11 >::processNeighbours<TrackSeed<11 >>(int , int , int , int , const bounded_vector<TrackSeed<11 >>&, const bounded_vector<int >&, bounded_vector<TrackSeed<11 >>&, bounded_vector<int >&, bounded_vector<TrackSeed< 11 >>* );
962989#endif
963990
964991} // namespace o2::its
0 commit comments