Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:49:26

0001 #ifndef HeterogeneousCore_CUDAUtilities_EventCache_h
0002 #define HeterogeneousCore_CUDAUtilities_EventCache_h
0003 
0004 #include <vector>
0005 
0006 #include <cuda_runtime.h>
0007 
0008 #include "FWCore/Utilities/interface/ReusableObjectHolder.h"
0009 #include "HeterogeneousCore/CUDAUtilities/interface/SharedEventPtr.h"
0010 
0011 class CUDAService;
0012 
0013 namespace cms {
0014   namespace cuda {
0015     class EventCache {
0016     public:
0017       using BareEvent = SharedEventPtr::element_type;
0018 
0019       EventCache();
0020 
0021       // Gets a (cached) CUDA event for the current device. The event
0022       // will be returned to the cache by the shared_ptr destructor. The
0023       // returned event is guaranteed to be in the state where all
0024       // captured work has completed, i.e. cudaEventQuery() == cudaSuccess.
0025       //
0026       // This function is thread safe
0027       SharedEventPtr get();
0028 
0029     private:
0030       friend class ::CUDAService;
0031 
0032       // thread safe
0033       SharedEventPtr makeOrGet(int dev);
0034 
0035       // not thread safe, intended to be called only from CUDAService destructor
0036       void clear();
0037 
0038       class Deleter {
0039       public:
0040         Deleter() = default;
0041         Deleter(int d) : device_{d} {}
0042         void operator()(cudaEvent_t event) const;
0043 
0044       private:
0045         int device_ = -1;
0046       };
0047 
0048       std::vector<edm::ReusableObjectHolder<BareEvent, Deleter>> cache_;
0049     };
0050 
0051     // Gets the global instance of a EventCache
0052     // This function is thread safe
0053     EventCache& getEventCache();
0054   }  // namespace cuda
0055 }  // namespace cms
0056 
0057 #endif