CMS 3D CMS Logo

PixelTrackSoAFromCUDA.cc
Go to the documentation of this file.
1 #include <cuda_runtime.h>
2 
18 
19 // Switch on to enable checks and printout for found tracks
20 // #define PIXEL_DEBUG_PRODUCE
21 
22 class PixelTrackSoAFromCUDA : public edm::stream::EDProducer<edm::ExternalWork> {
23 public:
24  explicit PixelTrackSoAFromCUDA(const edm::ParameterSet& iConfig);
25  ~PixelTrackSoAFromCUDA() override = default;
26 
27  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
28 
29 private:
30  void acquire(edm::Event const& iEvent,
31  edm::EventSetup const& iSetup,
32  edm::WaitingTaskWithArenaHolder waitingTaskHolder) override;
33  void produce(edm::Event& iEvent, edm::EventSetup const& iSetup) override;
34 
37 
39 };
40 
42  : tokenCUDA_(consumes<cms::cuda::Product<PixelTrackHeterogeneous>>(iConfig.getParameter<edm::InputTag>("src"))),
43  tokenSOA_(produces<PixelTrackHeterogeneous>()) {}
44 
47 
48  desc.add<edm::InputTag>("src", edm::InputTag("pixelTracksCUDA"));
49  descriptions.add("pixelTracksSoA", desc);
50 }
51 
53  edm::EventSetup const& iSetup,
54  edm::WaitingTaskWithArenaHolder waitingTaskHolder) {
55  cms::cuda::Product<PixelTrackHeterogeneous> const& inputDataWrapped = iEvent.get(tokenCUDA_);
56  cms::cuda::ScopedContextAcquire ctx{inputDataWrapped, std::move(waitingTaskHolder)};
57  auto const& inputData = ctx.get(inputDataWrapped);
58 
59  soa_ = inputData.toHostAsync(ctx.stream());
60 }
61 
63  // check that the fixed-size SoA does not overflow
64  auto const& tsoa = *soa_;
65  auto maxTracks = tsoa.stride();
66  auto nTracks = tsoa.nTracks();
68  if (nTracks == maxTracks - 1) {
69  edm::LogWarning("PixelTracks") << "Unsorted reconstructed pixel tracks truncated to " << maxTracks - 1
70  << " candidates";
71  }
72 
73 #ifdef PIXEL_DEBUG_PRODUCE
74  std::cout << "size of SoA " << sizeof(tsoa) << " stride " << maxTracks << std::endl;
75  std::cout << "found " << nTracks << " tracks in cpu SoA at " << &tsoa << std::endl;
76 
77  int32_t nt = 0;
78  for (int32_t it = 0; it < maxTracks; ++it) {
79  auto nHits = tsoa.nHits(it);
80  assert(nHits == int(tsoa.hitIndices.size(it)));
81  if (nHits == 0)
82  break; // this is a guard: maybe we need to move to nTracks...
83  nt++;
84  }
85  assert(nTracks == nt);
86 #endif
87 
88  // DO NOT make a copy (actually TWO....)
89  iEvent.emplace(tokenSOA_, std::move(soa_));
90 
91  assert(!soa_);
92 }
93 
~PixelTrackSoAFromCUDA() override=default
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void acquire(edm::Event const &iEvent, edm::EventSetup const &iSetup, edm::WaitingTaskWithArenaHolder waitingTaskHolder) override
edm::EDPutTokenT< PixelTrackHeterogeneous > tokenSOA_
void produce(edm::Event &iEvent, edm::EventSetup const &iSetup) override
PixelTrackSoAFromCUDA(const edm::ParameterSet &iConfig)
cms::cuda::host::unique_ptr< pixelTrack::TrackSoA > soa_
assert(be >=bs)
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
int nt
Definition: AMPTWrapper.h:42
Namespace of DDCMS conversion namespace.
edm::EDGetTokenT< cms::cuda::Product< PixelTrackHeterogeneous > > tokenCUDA_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
caConstants::TupleMultiplicity const CAHitNtupletGeneratorKernelsGPU::HitToTuple const cms::cuda::AtomicPairCounter GPUCACell const *__restrict__ uint32_t const *__restrict__ gpuPixelDoublets::CellNeighborsVector const gpuPixelDoublets::CellTracksVector const GPUCACell::OuterHitOfCell const int32_t nHits
maxTracks
Definition: DMR_cfg.py:159
HLT enums.
std::unique_ptr< T, impl::HostDeleter > unique_ptr
Log< level::Warning, false > LogWarning
def move(src, dest)
Definition: eostools.py:511