forked from cms-patatrack/pixeltrack-standalone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EventCache.h
57 lines (42 loc) · 1.4 KB
/
EventCache.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
51
52
53
54
55
56
57
#ifndef HeterogeneousCore_CUDAUtilities_EventCache_h
#define HeterogeneousCore_CUDAUtilities_EventCache_h
#include <vector>
#include <cuda_runtime.h>
#include "Framework/ReusableObjectHolder.h"
#include "CUDACore/SharedEventPtr.h"
class CUDAService;
namespace cms {
namespace cuda {
class EventCache {
public:
using BareEvent = SharedEventPtr::element_type;
EventCache();
// Gets a (cached) CUDA event for the current device. The event
// will be returned to the cache by the shared_ptr destructor. The
// returned event is guaranteed to be in the state where all
// captured work has completed, i.e. cudaEventQuery() == cudaSuccess.
//
// This function is thread safe
SharedEventPtr get();
private:
friend class ::CUDAService;
// thread safe
SharedEventPtr makeOrGet(int dev);
// 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()(cudaEvent_t event) const;
private:
int device_ = -1;
};
std::vector<edm::ReusableObjectHolder<BareEvent, Deleter>> cache_;
};
// Gets the global instance of a EventCache
// This function is thread safe
EventCache& getEventCache();
} // namespace cuda
} // namespace cms
#endif