CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
24  SharedStreamPtr get();
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
void operator()(cudaStream_t stream) const
Definition: StreamCache.cc:9
SharedStreamPtr::element_type BareStream
Definition: StreamCache.h:17
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream
tuple d
Definition: ztail.py:151
std::shared_ptr< std::remove_pointer_t< cudaStream_t >> SharedStreamPtr
StreamCache & getStreamCache()
Definition: StreamCache.cc:39
std::vector< edm::ReusableObjectHolder< BareStream, Deleter > > cache_
Definition: StreamCache.h:41