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 (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 
ConfigurationDescriptions.h
BeamSpotPOD.h
edm::StreamID
Definition: StreamID.h:30
cms::cuda::ScopedContextProduce
Definition: ScopedContext.h:149
fwrapper::cs
unique_ptr< ClusterSequence > cs
Definition: fastjetfortran_madfks.cc:47
edm::EDGetTokenT< reco::BeamSpot >
edm::EDPutTokenT
Definition: EDPutToken.h:33
BeamSpotToCUDA::BeamSpotToCUDA
BeamSpotToCUDA(const edm::ParameterSet &iConfig)
Definition: BeamSpotToCUDA.cc:65
cms::cuda::host::noncached::unique_ptr
std::unique_ptr< T, impl::HostDeleter > unique_ptr
Definition: host_noncached_unique_ptr.h:23
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89285
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
BeamSpotToCUDA
Definition: BeamSpotToCUDA.cc:43
BeamSpotToCUDA::bsGetToken_
const edm::EDGetTokenT< reco::BeamSpot > bsGetToken_
Definition: BeamSpotToCUDA.cc:61
BeamSpotCUDA
Definition: BeamSpotCUDA.h:9
BeamSpotToCUDA::produce
void produce(edm::StreamID streamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const override
Definition: BeamSpotToCUDA.cc:75
host_noncached_unique_ptr.h
BeamSpotToCUDA::beginStream
std::unique_ptr< BeamSpotHost > beginStream(edm::StreamID) const override
Definition: BeamSpotToCUDA.cc:50
MakerMacros.h
cms::cuda::bs
bs
Definition: HistoContainer.h:127
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
BeamSpot.h
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
Service.h
reco::BeamSpot
Definition: BeamSpot.h:21
BeamSpotToCUDA::~BeamSpotToCUDA
~BeamSpotToCUDA() override=default
ParameterSetDescription.h
edm::global::EDProducer
Definition: EDProducer.h:32
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
BeamSpotCUDA.h
edm::Service
Definition: Service.h:30
iEvent
int iEvent
Definition: GenABIO.cc:224
copyAsync.h
edm::EventSetup
Definition: EventSetup.h:58
CUDAService.h
Product.h
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
BeamSpotPOD
Definition: BeamSpotPOD.h:11
ScopedContext.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
BeamSpotToCUDA::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: BeamSpotToCUDA.cc:69
ParameterSet.h
EDProducer.h
edm::Event
Definition: Event.h:73
BeamSpotToCUDA::bsPutToken_
const edm::EDPutTokenT< cms::cuda::Product< BeamSpotCUDA > > bsPutToken_
Definition: BeamSpotToCUDA.cc:62
edm::InputTag
Definition: InputTag.h:15
cms::cuda::copyAsync
void copyAsync(device::unique_ptr< T > &dst, const host::unique_ptr< T > &src, cudaStream_t stream)
Definition: copyAsync.h:20