Skip to content

Commit

Permalink
Reorganize CUDAScopedContext (#355)
Browse files Browse the repository at this point in the history
* Split CUDAScopedContext to *Acquire and *Produce

The motivation is that acquire() and produce() need a different
functionality, and are constructed differently (e.g. acquire version
always needs the edm::WaitingTaskWithArenaHolder). This split should
make it more difficult to make mistakes. It should also make future
evolution, e.g. towards chains of TBB tasks alternating in CPU and GPU
work, easier.

* Rename CUDAContextToken to CUDAContextState, and change semantics

Now CUDAScopedContextAcquire takes it as a parameter to constructor,
and stores the state in its destructor (yielding RAII semantics).

* Document the constructors.
  • Loading branch information
makortel authored and fwyzard committed Dec 29, 2020
1 parent acc8360 commit af2ffa3
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void SiPixelDigiErrorsSoAFromCUDA::fillDescriptions(edm::ConfigurationDescriptio

void SiPixelDigiErrorsSoAFromCUDA::acquire(const edm::Event& iEvent, const edm::EventSetup& iSetup, edm::WaitingTaskWithArenaHolder waitingTaskHolder) {
// Do the transfer in a CUDA stream parallel to the computation CUDA stream
CUDAScopedContext ctx{iEvent.streamID(), std::move(waitingTaskHolder)};
CUDAScopedContextAcquire ctx{iEvent.streamID(), std::move(waitingTaskHolder)};

const auto& gpuDigiErrors = ctx.get(iEvent, digiErrorGetToken_);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void SiPixelDigisSoAFromCUDA::fillDescriptions(edm::ConfigurationDescriptions& d

void SiPixelDigisSoAFromCUDA::acquire(const edm::Event& iEvent, const edm::EventSetup& iSetup, edm::WaitingTaskWithArenaHolder waitingTaskHolder) {
// Do the transfer in a CUDA stream parallel to the computation CUDA stream
CUDAScopedContext ctx{iEvent.streamID(), std::move(waitingTaskHolder)};
CUDAScopedContextAcquire ctx{iEvent.streamID(), std::move(waitingTaskHolder)};

const auto& gpuDigis = ctx.get(iEvent, digiGetToken_);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class SiPixelRawToClusterCUDA: public edm::stream::EDProducer<edm::ExternalWork>
edm::EDPutTokenT<CUDAProduct<SiPixelDigiErrorsCUDA>> digiErrorPutToken_;
edm::EDPutTokenT<CUDAProduct<SiPixelClustersCUDA>> clusterPutToken_;

CUDAContextToken ctxTmp_;
CUDAContextState ctxState_;

edm::ESWatcher<SiPixelFedCablingMapRcd> recordWatcher;

Expand Down Expand Up @@ -118,7 +118,7 @@ void SiPixelRawToClusterCUDA::fillDescriptions(edm::ConfigurationDescriptions& d


void SiPixelRawToClusterCUDA::acquire(const edm::Event& iEvent, const edm::EventSetup& iSetup, edm::WaitingTaskWithArenaHolder waitingTaskHolder) {
CUDAScopedContext ctx{iEvent.streamID(), std::move(waitingTaskHolder)};
CUDAScopedContextAcquire ctx{iEvent.streamID(), std::move(waitingTaskHolder), ctxState_};

edm::ESHandle<SiPixelFedCablingMapGPUWrapper> hgpuMap;
iSetup.get<CkfComponentsRecord>().get(hgpuMap);
Expand Down Expand Up @@ -228,12 +228,10 @@ void SiPixelRawToClusterCUDA::acquire(const edm::Event& iEvent, const edm::Event
useQuality_, includeErrors_,
edm::MessageDrop::instance()->debugEnabled,
ctx.stream());

ctxTmp_ = ctx.toToken();
}

void SiPixelRawToClusterCUDA::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
CUDAScopedContext ctx{std::move(ctxTmp_)};
CUDAScopedContextProduce ctx{ctxState_};

auto tmp = gpuAlgo_.getResults();
ctx.emplace(iEvent, digiPutToken_, std::move(tmp.first));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void SiPixelRecHitCUDA::produce(edm::StreamID streamID, edm::Event& iEvent, cons
edm::Handle<CUDAProduct<SiPixelClustersCUDA>> hclusters;
iEvent.getByToken(token_, hclusters);

CUDAScopedContext ctx{*hclusters};
CUDAScopedContextProduce ctx{*hclusters};
auto const& clusters = ctx.get(*hclusters);

edm::Handle<CUDAProduct<SiPixelDigisCUDA>> hdigis;
Expand Down

0 comments on commit af2ffa3

Please sign in to comment.