forked from cms-patatrack/pixeltrack-standalone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStreamCache.h
50 lines (37 loc) · 1.2 KB
/
StreamCache.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#ifndef HeterogeneousCore_CUDAUtilities_StreamCache_h
#define HeterogeneousCore_CUDAUtilities_StreamCache_h
#include <vector>
#include <cuda_runtime.h>
#include "Framework/ReusableObjectHolder.h"
#include "CUDACore/SharedStreamPtr.h"
class CUDAService;
namespace cms {
namespace cuda {
class StreamCache {
public:
using BareStream = SharedStreamPtr::element_type;
StreamCache();
// Gets a (cached) CUDA stream for the current device. The stream
// will be returned to the cache by the shared_ptr destructor.
// This function is thread safe
SharedStreamPtr get();
private:
friend class ::CUDAService;
// not thread safe, intended to be called only from CUDAService destructor
void clear();
class Deleter {
public:
Deleter() = default;
Deleter(int d) : device_{d} {}
void operator()(cudaStream_t stream) const;
private:
int device_ = -1;
};
std::vector<edm::ReusableObjectHolder<BareStream, Deleter>> cache_;
};
// Gets the global instance of a StreamCache
// This function is thread safe
StreamCache& getStreamCache();
} // namespace cuda
} // namespace cms
#endif