CMS 3D CMS Logo

StreamCache.cc
Go to the documentation of this file.
7 
8 namespace cms::cuda {
9  void StreamCache::Deleter::operator()(cudaStream_t stream) const {
10  if (device_ != -1) {
11  ScopedSetDevice deviceGuard{device_};
12  cudaCheck(cudaStreamDestroy(stream));
13  }
14  }
15 
16  // StreamCache should be constructed by the first call to
17  // getStreamCache() only if we have CUDA devices present
19 
21  const auto dev = currentDevice();
22  return cache_[dev].makeOrGet([dev]() {
23  cudaStream_t stream;
24  cudaCheck(cudaStreamCreateWithFlags(&stream, cudaStreamNonBlocking));
25  return std::unique_ptr<BareStream, Deleter>(stream, Deleter{dev});
26  });
27  }
28 
30  // Reset the contents of the caches, but leave an
31  // edm::ReusableObjectHolder alive for each device. This is needed
32  // mostly for the unit tests, where the function-static
33  // StreamCache lives through multiple tests (and go through
34  // multiple shutdowns of the framework).
35  cache_.clear();
36  cache_.resize(deviceCount());
37  }
38 
40  // the public interface is thread safe
42  return cache;
43  }
44 } // namespace cms::cuda
int deviceCount()
Definition: deviceCount.h:10
std::shared_ptr< std::remove_pointer_t< cudaStream_t > > SharedStreamPtr
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream
SharedStreamPtr get()
Definition: StreamCache.cc:20
#define CMS_THREAD_SAFE
StreamCache & getStreamCache()
Definition: StreamCache.cc:39
def cache(function)
Definition: utilities.py:3
std::vector< edm::ReusableObjectHolder< BareStream, Deleter > > cache_
Definition: StreamCache.h:41
#define cudaCheck(ARG,...)
Definition: cudaCheck.h:69
void operator()(cudaStream_t stream) const
Definition: StreamCache.cc:9
int currentDevice()
Definition: currentDevice.h:10