CMS 3D CMS Logo

BeamSpotToCUDA.cc
Go to the documentation of this file.
1 #include <cuda_runtime.h>
2 
18 
19 namespace {
20 
21  class BeamSpotHost {
22  public:
23  BeamSpotHost() : data_h_{cms::cuda::make_host_noncached_unique<BeamSpotPOD>(cudaHostAllocWriteCombined)} {}
24 
25  BeamSpotHost(BeamSpotHost const&) = delete;
26  BeamSpotHost(BeamSpotHost&&) = default;
27 
28  BeamSpotHost& operator=(BeamSpotHost const&) = delete;
29  BeamSpotHost& operator=(BeamSpotHost&&) = default;
30 
31  BeamSpotPOD* data() { return data_h_.get(); }
32  BeamSpotPOD const* data() const { return data_h_.get(); }
33 
35  cms::cuda::host::noncached::unique_ptr<BeamSpotPOD> const& ptr() const { return data_h_; }
36 
37  private:
39  };
40 
41 } // namespace
42 
43 class BeamSpotToCUDA : public edm::global::EDProducer<edm::StreamCache<BeamSpotHost>> {
44 public:
45  explicit BeamSpotToCUDA(const edm::ParameterSet& iConfig);
46  ~BeamSpotToCUDA() override = default;
47 
48  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
49 
50  std::unique_ptr<BeamSpotHost> beginStream(edm::StreamID) const override {
52  if (cuda and cuda->enabled()) {
53  return std::make_unique<BeamSpotHost>();
54  } else {
55  return nullptr;
56  }
57  }
58  void produce(edm::StreamID streamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const override;
59 
60 private:
63 };
64 
66  : bsGetToken_{consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("src"))},
67  bsPutToken_{produces<cms::cuda::Product<BeamSpotCUDA>>()} {}
68 
71  desc.add<edm::InputTag>("src", edm::InputTag("offlineBeamSpot"));
72  descriptions.add("offlineBeamSpotToCUDA", desc);
73 }
74 
76  cms::cuda::ScopedContextProduce ctx{streamID};
77 
78  const reco::BeamSpot& bs = iEvent.get(bsGetToken_);
79 
80  auto& bsHost = streamCache(streamID)->ptr();
81 
82  bsHost->x = bs.x0();
83  bsHost->y = bs.y0();
84  bsHost->z = bs.z0();
85 
86  bsHost->sigmaZ = bs.sigmaZ();
87  bsHost->beamWidthX = bs.BeamWidthX();
88  bsHost->beamWidthY = bs.BeamWidthY();
89  bsHost->dxdz = bs.dxdz();
90  bsHost->dydz = bs.dydz();
91  bsHost->emittanceX = bs.emittanceX();
92  bsHost->emittanceY = bs.emittanceY();
93  bsHost->betaStar = bs.betaStar();
94 
95  BeamSpotCUDA bsDevice(ctx.stream());
96  cms::cuda::copyAsync(bsDevice.ptr(), bsHost, ctx.stream());
97 
98  ctx.emplace(iEvent, bsPutToken_, std::move(bsDevice));
99 }
100 
const edm::EDGetTokenT< reco::BeamSpot > bsGetToken_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
~BeamSpotToCUDA() override=default
std::unique_ptr< T, impl::HostDeleter > unique_ptr
int iEvent
Definition: GenABIO.cc:224
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void copyAsync(device::unique_ptr< T > &dst, const host::unique_ptr< T > &src, cudaStream_t stream)
Definition: copyAsync.h:20
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::unique_ptr< BeamSpotHost > beginStream(edm::StreamID) const override
void add(std::string const &label, ParameterSetDescription const &psetDescription)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
const edm::EDPutTokenT< cms::cuda::Product< BeamSpotCUDA > > bsPutToken_
BeamSpotToCUDA(const edm::ParameterSet &iConfig)
void produce(edm::StreamID streamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const override
def move(src, dest)
Definition: eostools.py:511