CMS 3D CMS Logo

StreamCache.h
Go to the documentation of this file.
1 #ifndef HeterogeneousCore_CUDAUtilities_StreamCache_h
2 #define HeterogeneousCore_CUDAUtilities_StreamCache_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 StreamCache {
16  public:
17  using BareStream = SharedStreamPtr::element_type;
18 
19  StreamCache();
20 
21  // Gets a (cached) CUDA stream for the current device. The stream
22  // will be returned to the cache by the shared_ptr destructor.
23  // This function is thread safe
25 
26  private:
27  friend class ::CUDAService;
28  // not thread safe, intended to be called only from CUDAService destructor
29  void clear();
30 
31  class Deleter {
32  public:
33  Deleter() = default;
34  Deleter(int d) : device_{d} {}
35  void operator()(cudaStream_t stream) const;
36 
37  private:
38  int device_ = -1;
39  };
40 
41  std::vector<edm::ReusableObjectHolder<BareStream, Deleter>> cache_;
42  };
43 
44  // Gets the global instance of a StreamCache
45  // This function is thread safe
47  } // namespace cuda
48 } // namespace cms
49 
50 #endif
cms::cuda::StreamCache::BareStream
SharedStreamPtr::element_type BareStream
Definition: StreamCache.h:17
cms::cuda::StreamCache::Deleter::Deleter
Deleter(int d)
Definition: StreamCache.h:34
cms::cuda::stream
cudaStream_t stream
Definition: HistoContainer.h:57
cms::cuda::SharedStreamPtr
std::shared_ptr< std::remove_pointer_t< cudaStream_t > > SharedStreamPtr
Definition: SharedStreamPtr.h:14
cms::cuda::StreamCache::clear
void clear()
Definition: StreamCache.cc:29
ReusableObjectHolder.h
prod1Switch_cff.cuda
cuda
Definition: prod1Switch_cff.py:11
cms::cuda::StreamCache::StreamCache
StreamCache()
Definition: StreamCache.cc:18
cms::cuda::getStreamCache
StreamCache & getStreamCache()
Definition: StreamCache.cc:39
cms::cuda::StreamCache::cache_
std::vector< edm::ReusableObjectHolder< BareStream, Deleter > > cache_
Definition: StreamCache.h:41
SharedStreamPtr.h
cms::cuda::StreamCache::get
SharedStreamPtr get()
Definition: StreamCache.cc:20
cms::cuda::StreamCache::Deleter::operator()
void operator()(cudaStream_t stream) const
Definition: StreamCache.cc:9
cms::cuda::StreamCache::Deleter::device_
int device_
Definition: StreamCache.h:38
cms::cuda::StreamCache::Deleter
Definition: StreamCache.h:31
cms::cuda::StreamCache
Definition: StreamCache.h:15
ztail.d
d
Definition: ztail.py:151
CUDAService
Definition: CUDAService.h:15
cms
Namespace of DDCMS conversion namespace.
Definition: ProducerAnalyzer.cc:21
cms::cuda::StreamCache::Deleter::Deleter
Deleter()=default