HeterogeneousCore
CUDAUtilities
src
StreamCache.cc
Go to the documentation of this file.
1
#include "
FWCore/Utilities/interface/thread_safety_macros.h
"
2
#include "
HeterogeneousCore/CUDAUtilities/interface/StreamCache.h
"
3
#include "
HeterogeneousCore/CUDAUtilities/interface/cudaCheck.h
"
4
#include "
HeterogeneousCore/CUDAUtilities/interface/currentDevice.h
"
5
#include "
HeterogeneousCore/CUDAUtilities/interface/deviceCount.h
"
6
#include "
HeterogeneousCore/CUDAUtilities/interface/ScopedSetDevice.h
"
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
18
StreamCache::StreamCache
() :
cache_
(
deviceCount
()) {}
19
20
SharedStreamPtr
StreamCache::get
() {
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
29
void
StreamCache::clear
() {
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
39
StreamCache
&
getStreamCache
() {
40
// the public interface is thread safe
41
CMS_THREAD_SAFE
static
StreamCache
cache
;
42
return
cache
;
43
}
44
}
// namespace cms::cuda
cms::cuda
Definition:
Product.h:14
StreamCache.h
cms::cuda::SharedStreamPtr
std::shared_ptr< std::remove_pointer_t< cudaStream_t > > SharedStreamPtr
Definition:
SharedStreamPtr.h:14
cms::cuda::stream
uint32_t const T *__restrict__ const uint32_t *__restrict__ int32_t int Histo::index_type cudaStream_t stream
Definition:
HistoContainer.h:51
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:69
currentDevice.h
cms::cuda::StreamCache
Definition:
StreamCache.h:15
ScopedSetDevice.h
Generated for CMSSW Reference Manual by
1.8.16