Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clamp the number of pixel tracks to the capacity of the SoA [12.4.x] #38884

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -60,10 +60,17 @@ void PixelTrackSoAFromCUDA::acquire(edm::Event const& iEvent,
}

void PixelTrackSoAFromCUDA::produce(edm::Event& iEvent, edm::EventSetup const& iSetup) {
#ifdef PIXEL_DEBUG_PRODUCE
// check that the fixed-size SoA does not overflow
auto const& tsoa = *soa_;
auto maxTracks = tsoa.stride();
auto nTracks = tsoa.nTracks();
assert(nTracks < maxTracks);
if (nTracks == maxTracks - 1) {
edm::LogWarning("PixelTracks") << "Unsorted reconstructed pixel tracks truncated to " << maxTracks - 1
<< " candidates";
}

#ifdef PIXEL_DEBUG_PRODUCE
std::cout << "size of SoA " << sizeof(tsoa) << " stride " << maxTracks << std::endl;
std::cout << "found " << nTracks << " tracks in cpu SoA at " << &tsoa << std::endl;

Expand All @@ -79,7 +86,7 @@ void PixelTrackSoAFromCUDA::produce(edm::Event& iEvent, edm::EventSetup const& i
#endif

// DO NOT make a copy (actually TWO....)
iEvent.emplace(tokenSOA_, PixelTrackHeterogeneous(std::move(soa_)));
iEvent.emplace(tokenSOA_, std::move(soa_));

assert(!soa_);
}
Expand Down
Expand Up @@ -562,7 +562,8 @@ __global__ void kernel_fillHitDetIndices(HitContainer const *__restrict__ tuples
__global__ void kernel_fillNLayers(TkSoA *__restrict__ ptracks, cms::cuda::AtomicPairCounter *apc) {
auto &tracks = *ptracks;
auto first = blockIdx.x * blockDim.x + threadIdx.x;
auto ntracks = apc->get().m;
// clamp the number of tracks to the capacity of the SoA
auto ntracks = std::min<int>(apc->get().m, tracks.stride() - 1);
if (0 == first)
tracks.setNTracks(ntracks);
for (int idx = first, nt = ntracks; idx < nt; idx += gridDim.x * blockDim.x) {
Expand Down
Expand Up @@ -247,5 +247,15 @@ PixelTrackHeterogeneous CAHitNtupletGeneratorOnGPU::makeTuples(TrackingRecHit2DC
std::cout << "finished building pixel tracks on CPU" << std::endl;
#endif

// check that the fixed-size SoA does not overflow
auto const& tsoa = *soa;
auto maxTracks = tsoa.stride();
auto nTracks = tsoa.nTracks();
assert(nTracks < maxTracks);
if (nTracks == maxTracks - 1) {
edm::LogWarning("PixelTracks") << "Unsorted reconstructed pixel tracks truncated to " << maxTracks - 1
<< " candidates";
}

return tracks;
}