File indexing completed on 2025-05-30 02:10:01
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
0029 void set(int device, SharedStreamPtr stream) {
0030 throwIfStream();
0031 device_ = device;
0032 stream_ = std::move(stream);
0033 }
0034
0035 int device() const { return device_; }
0036
0037 const SharedStreamPtr& streamPtr() const {
0038 throwIfNoStream();
0039 return stream_;
0040 }
0041
0042 SharedStreamPtr releaseStreamPtr() {
0043 throwIfNoStream();
0044
0045
0046
0047
0048 return std::move(stream_);
0049 }
0050
0051 void throwIfStream() const;
0052 void throwIfNoStream() const;
0053
0054 SharedStreamPtr stream_;
0055 int device_;
0056 };
0057 }
0058 }
0059
0060 #endif