CMS 3D CMS Logo

EventCache.h
Go to the documentation of this file.
1 #ifndef HeterogeneousCore_CUDAUtilities_EventCache_h
2 #define HeterogeneousCore_CUDAUtilities_EventCache_h
3 
4 #include <vector>
5 
6 #include <cuda_runtime.h>
7 
10 
11 class CUDAService;
12 
13 namespace cms {
14  namespace cuda {
15  class EventCache {
16  public:
17  using BareEvent = SharedEventPtr::element_type;
18 
19  EventCache();
20 
21  // Gets a (cached) CUDA event for the current device. The event
22  // will be returned to the cache by the shared_ptr destructor. The
23  // returned event is guaranteed to be in the state where all
24  // captured work has completed, i.e. cudaEventQuery() == cudaSuccess.
25  //
26  // This function is thread safe
27  SharedEventPtr get();
28 
29  private:
30  friend class ::CUDAService;
31 
32  // thread safe
33  SharedEventPtr makeOrGet(int dev);
34 
35  // not thread safe, intended to be called only from CUDAService destructor
36  void clear();
37 
38  class Deleter {
39  public:
40  Deleter() = default;
41  Deleter(int d) : device_{d} {}
42  void operator()(cudaEvent_t event) const;
43 
44  private:
45  int device_ = -1;
46  };
47 
48  std::vector<edm::ReusableObjectHolder<BareEvent, Deleter>> cache_;
49  };
50 
51  // Gets the global instance of a EventCache
52  // This function is thread safe
54  } // namespace cuda
55 } // namespace cms
56 
57 #endif
SharedEventPtr makeOrGet(int dev)
Definition: EventCache.cc:45
std::shared_ptr< std::remove_pointer_t< cudaEvent_t > > SharedEventPtr
std::vector< edm::ReusableObjectHolder< BareEvent, Deleter > > cache_
Definition: EventCache.h:48
d
Definition: ztail.py:151
Namespace of DDCMS conversion namespace.
void operator()(cudaEvent_t event) const
Definition: EventCache.cc:10
EventCache & getEventCache()
Definition: EventCache.cc:66
SharedEventPtr::element_type BareEvent
Definition: EventCache.h:17
Definition: event.py:1