CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 (cs->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_
double z0() const
z coordinate
Definition: BeamSpot.h:65
~BeamSpotToCUDA() override=default
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
unique_ptr< ClusterSequence > cs
std::unique_ptr< T, impl::HostDeleter > unique_ptr
double emittanceX() const
additional information
Definition: BeamSpot.h:129
double betaStar() const
Definition: BeamSpot.h:131
double dydz() const
dydz slope
Definition: BeamSpot.h:80
int iEvent
Definition: GenABIO.cc:224
double emittanceY() const
Definition: BeamSpot.h:130
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
bool enabled() const
Definition: CUDAService.h:22
def move
Definition: eostools.py:511
void copyAsync(device::unique_ptr< T > &dst, const host::unique_ptr< T > &src, cudaStream_t stream)
Definition: copyAsync.h:20
bool get(ProductID const &oid, Handle< PROD > &result) const
Definition: Event.h:346
double BeamWidthX() const
beam width X
Definition: BeamSpot.h:82
ParameterDescriptionBase * add(U const &iLabel, T const &value)
double dxdz() const
dxdz slope
Definition: BeamSpot.h:78
std::unique_ptr< BeamSpotHost > beginStream(edm::StreamID) const override
double sigmaZ() const
sigma z
Definition: BeamSpot.h:76
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
double BeamWidthY() const
beam width Y
Definition: BeamSpot.h:84
void add(std::string const &label, ParameterSetDescription const &psetDescription)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
double y0() const
y coordinate
Definition: BeamSpot.h:63
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
double x0() const
x coordinate
Definition: BeamSpot.h:61