CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
TestCUDAProducerGPUEWTask Class Reference
Inheritance diagram for TestCUDAProducerGPUEWTask:
edm::stream::EDProducer< edm::ExternalWork >

Public Member Functions

void acquire (edm::Event const &iEvent, edm::EventSetup const &iSetup, edm::WaitingTaskWithArenaHolder waitingTaskHolder) override
 
void produce (edm::Event &iEvent, const edm::EventSetup &iSetup) override
 
 TestCUDAProducerGPUEWTask (edm::ParameterSet const &iConfig)
 
 ~TestCUDAProducerGPUEWTask () override=default
 
- Public Member Functions inherited from edm::stream::EDProducer< edm::ExternalWork >
 EDProducer ()=default
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndRuns () const final
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 

Private Member Functions

void addSimpleWork (edm::EventNumber_t eventID, edm::StreamID streamID, cms::cuda::ScopedContextTask &ctx)
 

Private Attributes

cms::cuda::ContextState ctxState_
 
cms::cuda::device::unique_ptr< float[]> devicePtr_
 
const edm::EDPutTokenT< cms::cuda::Product< cms::cudatest::Thing > > dstToken_
 
TestCUDAProducerGPUKernel gpuAlgo_
 
cms::cuda::host::noncached::unique_ptr< float > hostData_
 
const std::string label_
 
const edm::EDGetTokenT< cms::cuda::Product< cms::cudatest::Thing > > srcToken_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer< edm::ExternalWork >
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 

Detailed Description

Definition at line 24 of file TestCUDAProducerGPUEWTask.cc.

Constructor & Destructor Documentation

◆ TestCUDAProducerGPUEWTask()

TestCUDAProducerGPUEWTask::TestCUDAProducerGPUEWTask ( edm::ParameterSet const &  iConfig)
explicit

Definition at line 48 of file TestCUDAProducerGPUEWTask.cc.

49  : label_{iConfig.getParameter<std::string>("@module_label")},
50  srcToken_{consumes<cms::cuda::Product<cms::cudatest::Thing>>(iConfig.getParameter<edm::InputTag>("src"))},
51  dstToken_{produces<cms::cuda::Product<cms::cudatest::Thing>>()} {
53  if (cs->enabled()) {
54  hostData_ = cms::cuda::make_host_noncached_unique<float>();
55  }
56 }

References edm::ParameterSet::getParameter(), and AlCaHLTBitMon_QueryRunRegistry::string.

◆ ~TestCUDAProducerGPUEWTask()

TestCUDAProducerGPUEWTask::~TestCUDAProducerGPUEWTask ( )
overridedefault

Member Function Documentation

◆ acquire()

void TestCUDAProducerGPUEWTask::acquire ( edm::Event const &  iEvent,
edm::EventSetup const &  iSetup,
edm::WaitingTaskWithArenaHolder  waitingTaskHolder 
)
override

Definition at line 71 of file TestCUDAProducerGPUEWTask.cc.

73  {
74  edm::LogVerbatim("TestCUDAProducerGPUEWTask") << label_ << " TestCUDAProducerGPUEWTask::acquire begin event "
75  << iEvent.id().event() << " stream " << iEvent.streamID();
76 
77  auto const& in = iEvent.get(srcToken_);
78  cms::cuda::ScopedContextAcquire ctx{in, waitingTaskHolder, ctxState_};
79 
80  cms::cudatest::Thing const& input = ctx.get(in);
81 
82  devicePtr_ = gpuAlgo_.runAlgo(label_, input.get(), ctx.stream());
83  // Mimick the need to transfer some of the GPU data back to CPU to
84  // be used for something within this module, or to be put in the
85  // event.
86  cudaCheck(
87  cudaMemcpyAsync(hostData_.get(), devicePtr_.get() + 10, sizeof(float), cudaMemcpyDeviceToHost, ctx.stream()));
88  // Push a task to run addSimpleWork() after the asynchronous work
89  // (and acquire()) has finished instead of produce()
90  ctx.pushNextTask([iev = iEvent.id().event(), istr = iEvent.streamID(), this](cms::cuda::ScopedContextTask ctx) {
91  addSimpleWork(iev, istr, ctx);
92  });
93 
94  edm::LogVerbatim("TestCUDAProducerGPUEWTask") << label_ << " TestCUDAProducerGPUEWTask::acquire end event "
95  << iEvent.id().event() << " stream " << iEvent.streamID();
96 }

References addSimpleWork(), ctxState_, cudaCheck, devicePtr_, dqmMemoryStats::float, gpuAlgo_, hostData_, iEvent, recoMuon::in, input, label_, TestCUDAProducerGPUKernel::runAlgo(), and srcToken_.

◆ addSimpleWork()

void TestCUDAProducerGPUEWTask::addSimpleWork ( edm::EventNumber_t  eventID,
edm::StreamID  streamID,
cms::cuda::ScopedContextTask ctx 
)
private

Definition at line 98 of file TestCUDAProducerGPUEWTask.cc.

100  {
101  if (*hostData_ < 13) {
102  edm::LogVerbatim("TestCUDAProducerGPUEWTask")
103  << label_ << " TestCUDAProducerGPUEWTask::addSimpleWork begin event " << eventID << " stream " << streamID
104  << " 10th element " << *hostData_ << " not satisfied, queueing more work";
105  cudaCheck(
106  cudaMemcpyAsync(hostData_.get(), devicePtr_.get() + 10, sizeof(float), cudaMemcpyDeviceToHost, ctx.stream()));
107 
108  ctx.pushNextTask(
109  [eventID, streamID, this](cms::cuda::ScopedContextTask ctx) { addSimpleWork(eventID, streamID, ctx); });
110  gpuAlgo_.runSimpleAlgo(devicePtr_.get(), ctx.stream());
111  edm::LogVerbatim("TestCUDAProducerGPUEWTask")
112  << label_ << " TestCUDAProducerGPUEWTask::addSimpleWork end event " << eventID << " stream " << streamID;
113  } else {
114  edm::LogVerbatim("TestCUDAProducerGPUEWTask")
115  << label_ << " TestCUDAProducerGPUEWTask::addSimpleWork event " << eventID << " stream " << streamID
116  << " 10th element " << *hostData_ << " not queueing more work";
117  }
118 }

References cudaCheck, devicePtr_, dqmMemoryStats::float, gpuAlgo_, hostData_, label_, cms::cuda::ScopedContextTask::pushNextTask(), TestCUDAProducerGPUKernel::runSimpleAlgo(), and cms::cuda::impl::ScopedContextBase::stream().

Referenced by acquire().

◆ fillDescriptions()

void TestCUDAProducerGPUEWTask::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 58 of file TestCUDAProducerGPUEWTask.cc.

58  {
60  desc.add<edm::InputTag>("src", edm::InputTag());
61  descriptions.addWithDefaultLabel(desc);
62  descriptions.setComment(
63  "This EDProducer is part of the TestCUDAProducer* family. It models a GPU algorithm this is not the first "
64  "algorithm in the chain of the GPU EDProducers, and that transfers some data from GPU to CPU multiple times "
65  "alternating the transfers and kernel executions (e.g. to decide which kernel to run next based on a value from "
66  "GPU). A synchronization between GPU and CPU is needed after each transfer. The synchronizations are implemented "
67  "with the ExternalWork extension and explicit TBB tasks within the module. Produces "
68  "cms::cuda::Product<cms::cudatest::Thing>.");
69 }

References edm::ParameterSetDescription::add(), edm::ConfigurationDescriptions::addWithDefaultLabel(), HLT_2018_cff::InputTag, and edm::ConfigurationDescriptions::setComment().

◆ produce()

void TestCUDAProducerGPUEWTask::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
override

Definition at line 120 of file TestCUDAProducerGPUEWTask.cc.

120  {
121  edm::LogVerbatim("TestCUDAProducerGPUEWTask")
122  << label_ << " TestCUDAProducerGPUEWTask::produce begin event " << iEvent.id().event() << " stream "
123  << iEvent.streamID() << " 10th element " << *hostData_;
124  if (*hostData_ != 13) {
125  throw cms::Exception("Assert") << "Expecting 10th element to be 13, got " << *hostData_;
126  }
127 
129 
130  ctx.emplace(iEvent, dstToken_, std::move(devicePtr_));
131 
132  edm::LogVerbatim("TestCUDAProducerGPUEWTask") << label_ << " TestCUDAProducerGPUEWTask::produce end event "
133  << iEvent.id().event() << " stream " << iEvent.streamID();
134 }

References ctxState_, devicePtr_, dstToken_, Exception, hostData_, iEvent, label_, and eostools::move().

Member Data Documentation

◆ ctxState_

cms::cuda::ContextState TestCUDAProducerGPUEWTask::ctxState_
private

Definition at line 43 of file TestCUDAProducerGPUEWTask.cc.

Referenced by acquire(), and produce().

◆ devicePtr_

cms::cuda::device::unique_ptr<float[]> TestCUDAProducerGPUEWTask::devicePtr_
private

Definition at line 44 of file TestCUDAProducerGPUEWTask.cc.

Referenced by acquire(), addSimpleWork(), and produce().

◆ dstToken_

const edm::EDPutTokenT<cms::cuda::Product<cms::cudatest::Thing> > TestCUDAProducerGPUEWTask::dstToken_
private

Definition at line 41 of file TestCUDAProducerGPUEWTask.cc.

Referenced by produce().

◆ gpuAlgo_

TestCUDAProducerGPUKernel TestCUDAProducerGPUEWTask::gpuAlgo_
private

Definition at line 42 of file TestCUDAProducerGPUEWTask.cc.

Referenced by acquire(), and addSimpleWork().

◆ hostData_

cms::cuda::host::noncached::unique_ptr<float> TestCUDAProducerGPUEWTask::hostData_
private

Definition at line 45 of file TestCUDAProducerGPUEWTask.cc.

Referenced by acquire(), addSimpleWork(), and produce().

◆ label_

const std::string TestCUDAProducerGPUEWTask::label_
private

◆ srcToken_

const edm::EDGetTokenT<cms::cuda::Product<cms::cudatest::Thing> > TestCUDAProducerGPUEWTask::srcToken_
private

Definition at line 40 of file TestCUDAProducerGPUEWTask.cc.

Referenced by acquire().

edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
input
static const std::string input
Definition: EdmProvDump.cc:48
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
TestCUDAProducerGPUKernel::runAlgo
cms::cuda::device::unique_ptr< float[]> runAlgo(const std::string &label, cudaStream_t stream) const
Definition: TestCUDAProducerGPUKernel.h:27
TestCUDAProducerGPUEWTask::devicePtr_
cms::cuda::device::unique_ptr< float[]> devicePtr_
Definition: TestCUDAProducerGPUEWTask.cc:44
cms::cuda::ScopedContextProduce
Definition: ScopedContext.h:149
fwrapper::cs
unique_ptr< ClusterSequence > cs
Definition: fastjetfortran_madfks.cc:45
TestCUDAProducerGPUEWTask::label_
const std::string label_
Definition: TestCUDAProducerGPUEWTask.cc:39
cms::cuda::ScopedContextTask::pushNextTask
void pushNextTask(F &&f)
Definition: ScopedContext.h:203
cms::cuda::impl::ScopedContextBase::stream
cudaStream_t stream() const
Definition: ScopedContext.h:34
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
TestCUDAProducerGPUEWTask::ctxState_
cms::cuda::ContextState ctxState_
Definition: TestCUDAProducerGPUEWTask.cc:43
TestCUDAProducerGPUEWTask::addSimpleWork
void addSimpleWork(edm::EventNumber_t eventID, edm::StreamID streamID, cms::cuda::ScopedContextTask &ctx)
Definition: TestCUDAProducerGPUEWTask.cc:98
TestCUDAProducerGPUEWTask::hostData_
cms::cuda::host::noncached::unique_ptr< float > hostData_
Definition: TestCUDAProducerGPUEWTask.cc:45
TestCUDAProducerGPUEWTask::dstToken_
const edm::EDPutTokenT< cms::cuda::Product< cms::cudatest::Thing > > dstToken_
Definition: TestCUDAProducerGPUEWTask.cc:41
TestCUDAProducerGPUEWTask::srcToken_
const edm::EDGetTokenT< cms::cuda::Product< cms::cudatest::Thing > > srcToken_
Definition: TestCUDAProducerGPUEWTask.cc:40
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
TestCUDAProducerGPUKernel::runSimpleAlgo
void runSimpleAlgo(float *d_data, cudaStream_t stream) const
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ConfigurationDescriptions::setComment
void setComment(std::string const &value)
Definition: ConfigurationDescriptions.cc:48
recoMuon::in
Definition: RecoMuonEnumerators.h:6
cms::cudatest::Thing
Definition: Thing.h:8
edm::Service
Definition: Service.h:30
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::LogVerbatim
Definition: MessageLogger.h:297
TestCUDAProducerGPUEWTask::gpuAlgo_
TestCUDAProducerGPUKernel gpuAlgo_
Definition: TestCUDAProducerGPUEWTask.cc:42
cms::cuda::ScopedContextAcquire
Definition: ScopedContext.h:101
eostools.move
def move(src, dest)
Definition: eostools.py:511
cudaCheck
#define cudaCheck(ARG,...)
Definition: cudaCheck.h:62
cms::cuda::ScopedContextTask
Definition: ScopedContext.h:192
Exception
Definition: hltDiff.cc:246
edm::InputTag
Definition: InputTag.h:15
edm::ConfigurationDescriptions::addWithDefaultLabel
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:87