diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc index 236e3e53a1825..ff6880e5504b0 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc +++ b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtuplet.cc @@ -15,6 +15,7 @@ #include "FWCore/Utilities/interface/ESGetToken.h" #include "FWCore/Utilities/interface/InputTag.h" #include "FWCore/Utilities/interface/RunningAverage.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" #include "HeterogeneousCore/AlpakaCore/interface/alpaka/EDGetToken.h" #include "HeterogeneousCore/AlpakaCore/interface/alpaka/EDPutToken.h" #include "HeterogeneousCore/AlpakaCore/interface/alpaka/Event.h" @@ -358,14 +359,44 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { auto const& geometry = runCache()->get(iEvent.queue()); auto const& hits = iEvent.get(tokenHit_); - std::array nHitsV = {{double(hits.nHits())}}; - std::array emptyV; - - uint32_t const maxTuples = maxNumberOfTuples_.evaluate(nHitsV, emptyV); - uint32_t const maxDoublets = maxNumberOfDoublets_.evaluate(nHitsV, emptyV); + /// Don't bother if no hits on BPix1 and no good graph for that + /// (so no staring pair without BPix1 as first layer). + /// TODO: this could be extended to a more general check for + /// no hits on any of the starting layers. + + bool hitsOnBPix1 = hits.offsetBPIX2() > 0; + bool startNoBPix1 = hitsOnBPix1; // one would suffice, two for readability + if (not hitsOnBPix1) { + startNoBPix1 = false; + for (const unsigned int& i : globalCache()->startingPairs_) { + if (globalCache()->pairGraph_[2 * i] > 0) { + startNoBPix1 = true; + break; + } + } + } - iEvent.emplace(tokenTrack_, - deviceAlgo_.makeTuplesAsync(hits, geometry, bf, maxDoublets, maxTuples, iEvent.queue())); + if (startNoBPix1) { + std::array nHitsV = {{double(hits.nHits())}}; + std::array emptyV; + + uint32_t const maxTuples = maxNumberOfTuples_.evaluate(nHitsV, emptyV); + uint32_t const maxDoublets = maxNumberOfDoublets_.evaluate(nHitsV, emptyV); + + iEvent.emplace(tokenTrack_, + deviceAlgo_.makeTuplesAsync(hits, geometry, bf, maxDoublets, maxTuples, iEvent.queue())); + + } else { + edm::LogWarning("CAHitNtupletAlpaka") << "No hit on BPix1 (" << hits.offsetBPIX2() + << ") and all the starting pairs has BPix1 as inner layer.\nIt's useless " + "to run the CA. Returning with 0 tracks!"; + auto& queue = iEvent.queue(); + const auto device = alpaka::getDev(queue); + reco::TracksSoACollection tracks({{0, 0}}, queue); + auto ntracks_d = cms::alpakatools::make_device_view(device, tracks.view().nTracks()); + alpaka::memset(queue, ntracks_d, 0); + iEvent.emplace(tokenTrack_, std::move(tracks)); + } } using CAHitNtupletAlpakaPhase1 = CAHitNtupletAlpaka; diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernels.dev.cc b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernels.dev.cc index 65c02aa783f13..3b07ca6ebe1c2 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernels.dev.cc +++ b/RecoTracker/PixelSeeding/plugins/alpaka/CAHitNtupletGeneratorKernels.dev.cc @@ -57,8 +57,9 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE { #ifdef GPU_DEBUG std::cout << "Allocation for tuple building with: " << std::endl; std::cout << "- nHits = " << nHits << std::endl; - std::cout << "- maxDoublets = " << maxTuples << std::endl; - std::cout << "- maxTracks = " << maxDoublets << std::endl; + std::cout << "- outerHits = " << outerHits << std::endl; + std::cout << "- maxDoublets = " << maxDoublets << std::endl; + std::cout << "- maxTracks = " << maxTuples << std::endl; std::cout << "- nCellsToCells = " << nCellsToCells << std::endl; std::cout << "- nHitsToCells = " << nHitsToCells << std::endl; diff --git a/RecoTracker/PixelSeeding/plugins/alpaka/CAPixelDoubletsAlgos.h b/RecoTracker/PixelSeeding/plugins/alpaka/CAPixelDoubletsAlgos.h index 871212e810b64..ef97d1e6f74c7 100644 --- a/RecoTracker/PixelSeeding/plugins/alpaka/CAPixelDoubletsAlgos.h +++ b/RecoTracker/PixelSeeding/plugins/alpaka/CAPixelDoubletsAlgos.h @@ -420,9 +420,11 @@ namespace ALPAKA_ACCELERATOR_NAMESPACE::caPixelDoublets { } auto ind = alpaka::atomicAdd(acc, nCells, 1u, alpaka::hierarchy::Blocks{}); - if (ind >= maxNumOfDoublets) { + if (ind >= maxNumOfDoublets or ind >= uint32_t(outerHitHisto->capacity())) { #ifdef CA_WARNINGS - printf("Warning!!!! Too many cells (limit = %d)!\n", maxNumOfDoublets); + printf("Warning!!!! Too many cells (maxNumOfDoublets = %d - nHitsToCell = %d)!\n", + maxNumOfDoublets, + outerHitHisto->capacity()); #endif alpaka::atomicSub(acc, nCells, 1u, alpaka::hierarchy::Blocks{}); break;