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
cms::cuda
Definition: Product.h:14
StreamCache.h
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
deviceCount.h
cms::cuda::ScopedSetDevice
Definition: ScopedSetDevice.h:10
CMS_THREAD_SAFE
#define CMS_THREAD_SAFE
Definition: thread_safety_macros.h:4
utilities.cache
def cache(function)
Definition: utilities.py:3
cms::cuda::currentDevice
int currentDevice()
Definition: currentDevice.h:10
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
thread_safety_macros.h
cms::cuda::deviceCount
int deviceCount()
Definition: deviceCount.h:10
cms::cuda::StreamCache::get
SharedStreamPtr get()
Definition: StreamCache.cc:20
cudaCheck.h
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
cudaCheck
#define cudaCheck(ARG,...)
Definition: cudaCheck.h:62
currentDevice.h
cms::cuda::StreamCache
Definition: StreamCache.h:15
ScopedSetDevice.h