forked from cms-patatrack/pixeltrack-standalone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContextState.h
61 lines (49 loc) · 1.68 KB
/
ContextState.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
58
59
60
61
#ifndef HeterogeneousCore_CUDACore_ContextState_h
#define HeterogeneousCore_CUDACore_ContextState_h
#include "CUDACore/SharedStreamPtr.h"
#include <memory>
namespace cms {
namespace cuda {
/**
* The purpose of this class is to deliver the device and CUDA stream
* information from ExternalWork's acquire() to producer() via a
* member/StreamCache variable.
*/
class ContextState {
public:
ContextState() = default;
~ContextState() = default;
ContextState(const ContextState&) = delete;
ContextState& operator=(const ContextState&) = delete;
ContextState(ContextState&&) = delete;
ContextState& operator=(ContextState&& other) = delete;
private:
friend class ScopedContextAcquire;
friend class ScopedContextProduce;
friend class ScopedContextTask;
void set(int device, SharedStreamPtr stream) {
throwIfStream();
device_ = device;
stream_ = std::move(stream);
}
int device() const { return device_; }
const SharedStreamPtr& streamPtr() const {
throwIfNoStream();
return stream_;
}
SharedStreamPtr releaseStreamPtr() {
throwIfNoStream();
// This function needs to effectively reset stream_ (i.e. stream_
// must be empty after this function). This behavior ensures that
// the SharedStreamPtr is not hold for inadvertedly long (i.e. to
// the next event), and is checked at run time.
return std::move(stream_);
}
void throwIfStream() const;
void throwIfNoStream() const;
SharedStreamPtr stream_;
int device_;
};
} // namespace cuda
} // namespace cms
#endif