CMS 3D CMS Logo

ContextState.h
Go to the documentation of this file.
1 #ifndef HeterogeneousCore_CUDACore_ContextState_h
2 #define HeterogeneousCore_CUDACore_ContextState_h
3 
5 
6 #include <memory>
7 
8 namespace cms {
9  namespace cuda {
15  class ContextState {
16  public:
17  ContextState() = default;
18  ~ContextState() = default;
19 
20  ContextState(const ContextState&) = delete;
21  ContextState& operator=(const ContextState&) = delete;
22  ContextState(ContextState&&) = delete;
24 
25  private:
26  friend class ScopedContextAcquire;
27  friend class ScopedContextProduce;
28  friend class ScopedContextTask;
29 
30  void set(int device, SharedStreamPtr stream) {
31  throwIfStream();
32  device_ = device;
34  }
35 
36  int device() const { return device_; }
37 
38  const SharedStreamPtr& streamPtr() const {
40  return stream_;
41  }
42 
45  // This function needs to effectively reset stream_ (i.e. stream_
46  // must be empty after this function). This behavior ensures that
47  // the SharedStreamPtr is not hold for inadvertedly long (i.e. to
48  // the next event), and is checked at run time.
49  return std::move(stream_);
50  }
51 
52  void throwIfStream() const;
53  void throwIfNoStream() const;
54 
56  int device_;
57  };
58  } // namespace cuda
59 } // namespace cms
60 
61 #endif
void throwIfNoStream() const
Definition: ContextState.cc:11
SharedStreamPtr stream_
Definition: ContextState.h:55
std::shared_ptr< std::remove_pointer_t< cudaStream_t > > SharedStreamPtr
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream
const SharedStreamPtr & streamPtr() const
Definition: ContextState.h:38
void throwIfStream() const
Definition: ContextState.cc:5
Namespace of DDCMS conversion namespace.
SharedStreamPtr releaseStreamPtr()
Definition: ContextState.h:43
ContextState & operator=(const ContextState &)=delete
def move(src, dest)
Definition: eostools.py:511