File indexing completed on 2024-04-06 12:15:43
0001 #ifndef HeterogeneousCore_CUDACore_ContextState_h
0002 #define HeterogeneousCore_CUDACore_ContextState_h
0003
0004 #include "HeterogeneousCore/CUDAUtilities/interface/SharedStreamPtr.h"
0005
0006 #include <memory>
0007
0008 namespace cms {
0009 namespace cuda {
0010
0011
0012
0013
0014
0015 class ContextState {
0016 public:
0017 ContextState() = default;
0018 ~ContextState() = default;
0019
0020 ContextState(const ContextState&) = delete;
0021 ContextState& operator=(const ContextState&) = delete;
0022 ContextState(ContextState&&) = delete;
0023 ContextState& operator=(ContextState&& other) = delete;
0024
0025 private:
0026 friend class ScopedContextAcquire;
0027 friend class ScopedContextProduce;
0028 friend class ScopedContextTask;
0029
0030 void set(int device, SharedStreamPtr stream) {
0031 throwIfStream();
0032 device_ = device;
0033 stream_ = std::move(stream);
0034 }
0035
0036 int device() const { return device_; }
0037
0038 const SharedStreamPtr& streamPtr() const {
0039 throwIfNoStream();
0040 return stream_;
0041 }
0042
0043 SharedStreamPtr releaseStreamPtr() {
0044 throwIfNoStream();
0045
0046
0047
0048
0049 return std::move(stream_);
0050 }
0051
0052 void throwIfStream() const;
0053 void throwIfNoStream() const;
0054
0055 SharedStreamPtr stream_;
0056 int device_;
0057 };
0058 }
0059 }
0060
0061 #endif