CMS 3D CMS Logo

List of all members | Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends
cms::cuda::EventCache Class Reference

#include <EventCache.h>

Classes

class  Deleter
 

Public Types

using BareEvent = SharedEventPtr::element_type
 

Public Member Functions

 EventCache ()
 
SharedEventPtr get ()
 

Private Member Functions

void clear ()
 
SharedEventPtr makeOrGet (int dev)
 

Private Attributes

std::vector< edm::ReusableObjectHolder< BareEvent, Deleter > > cache_
 

Friends

class ::CUDAService
 

Detailed Description

Definition at line 15 of file EventCache.h.

Member Typedef Documentation

◆ BareEvent

using cms::cuda::EventCache::BareEvent = SharedEventPtr::element_type

Definition at line 17 of file EventCache.h.

Constructor & Destructor Documentation

◆ EventCache()

cms::cuda::EventCache::EventCache ( )

Definition at line 19 of file EventCache.cc.

19 : cache_(deviceCount()) {}
int deviceCount()
Definition: deviceCount.h:10
std::vector< edm::ReusableObjectHolder< BareEvent, Deleter > > cache_
Definition: EventCache.h:48

Member Function Documentation

◆ clear()

void cms::cuda::EventCache::clear ( void  )
private

Definition at line 54 of file EventCache.cc.

References cache_, and cms::cuda::deviceCount().

Referenced by CUDAService::CUDAService(), and CUDAService::~CUDAService().

54  {
55  // Reset the contents of the caches, but leave an
56  // edm::ReusableObjectHolder alive for each device. This is needed
57  // mostly for the unit tests, where the function-static
58  // EventCache lives through multiple tests (and go through
59  // multiple shutdowns of the framework).
60  cache_.clear();
61  cache_.resize(deviceCount());
62  }
int deviceCount()
Definition: deviceCount.h:10
std::vector< edm::ReusableObjectHolder< BareEvent, Deleter > > cache_
Definition: EventCache.h:48

◆ get()

SharedEventPtr cms::cuda::EventCache::get ( )

Definition at line 21 of file EventCache.cc.

References cms::cuda::currentDevice(), edmPickEvents::event, cms::cuda::eventWorkHasCompleted(), makeOrGet(), and eostools::move().

Referenced by Options.Options::__getitem__(), betterConfigParser.BetterConfigParser::__updateDict(), submitPVValidationJobs.BetterConfigParser::__updateDict(), rrapi.RRApi::columns(), rrapi.RRApi::count(), rrapi.RRApi::data(), cms::cuda::ESProduct< HcalGainWidthsGPU::Product >::ESProduct(), betterConfigParser.BetterConfigParser::getCompares(), betterConfigParser.BetterConfigParser::getGeneral(), betterConfigParser.BetterConfigParser::getResultingSection(), submitPVValidationJobs.BetterConfigParser::getResultingSection(), rrapi.RRApi::report(), rrapi.RRApi::reports(), rrapi.RRApi::tables(), rrapi.RRApi::tags(), rrapi.RRApi::templates(), and rrapi.RRApi::workspaces().

21  {
22  const auto dev = currentDevice();
23  auto event = makeOrGet(dev);
24  // captured work has completed, or a just-created event
25  if (eventWorkHasCompleted(event.get())) {
26  return event;
27  }
28 
29  // Got an event with incomplete captured work. Try again until we
30  // get a completed (or a just-created) event. Need to keep all
31  // incomplete events until a completed event is found in order to
32  // avoid ping-pong with an incomplete event.
33  std::vector<SharedEventPtr> ptrs{std::move(event)};
34  bool completed;
35  do {
36  event = makeOrGet(dev);
37  completed = eventWorkHasCompleted(event.get());
38  if (not completed) {
39  ptrs.emplace_back(std::move(event));
40  }
41  } while (not completed);
42  return event;
43  }
SharedEventPtr makeOrGet(int dev)
Definition: EventCache.cc:45
def move(src, dest)
Definition: eostools.py:511
bool eventWorkHasCompleted(cudaEvent_t event)
Definition: event.py:1
int currentDevice()
Definition: currentDevice.h:10

◆ makeOrGet()

SharedEventPtr cms::cuda::EventCache::makeOrGet ( int  dev)
private

Definition at line 45 of file EventCache.cc.

References cache_, cudaCheck, and edmPickEvents::event.

Referenced by get().

45  {
46  return cache_[dev].makeOrGet([dev]() {
47  cudaEvent_t event;
48  // it should be a bit faster to ignore timings
49  cudaCheck(cudaEventCreateWithFlags(&event, cudaEventDisableTiming));
50  return std::unique_ptr<BareEvent, Deleter>(event, Deleter{dev});
51  });
52  }
std::vector< edm::ReusableObjectHolder< BareEvent, Deleter > > cache_
Definition: EventCache.h:48
#define cudaCheck(ARG,...)
Definition: cudaCheck.h:69
Definition: event.py:1

Friends And Related Function Documentation

◆ ::CUDAService

friend class ::CUDAService
friend

Definition at line 30 of file EventCache.h.

Member Data Documentation

◆ cache_

std::vector<edm::ReusableObjectHolder<BareEvent, Deleter> > cms::cuda::EventCache::cache_
private

Definition at line 48 of file EventCache.h.

Referenced by clear(), and makeOrGet().