diff options
author | A. Unique TensorFlower <gardener@tensorflow.org> | 2017-01-20 13:29:02 -0800 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2017-01-20 13:50:05 -0800 |
commit | 3ecafa37a2c6cd3a95fc568b00c43a9b87649300 (patch) | |
tree | c07035e84b2442b889a02242318ee74417c0a340 /tensorflow/stream_executor/stream_executor_pimpl.h | |
parent | bb71ec089658fb8a91423a7cf7195e5c900c2c98 (diff) |
Add default ScopedDeviceMemory ctor in StreamExecutor
Change: 145120921
Diffstat (limited to 'tensorflow/stream_executor/stream_executor_pimpl.h')
-rw-r--r-- | tensorflow/stream_executor/stream_executor_pimpl.h | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/tensorflow/stream_executor/stream_executor_pimpl.h b/tensorflow/stream_executor/stream_executor_pimpl.h index a5da0e047e..29ba63af05 100644 --- a/tensorflow/stream_executor/stream_executor_pimpl.h +++ b/tensorflow/stream_executor/stream_executor_pimpl.h @@ -673,6 +673,10 @@ inline port::StatusOr<DeviceMemory<T>> StreamExecutor::GetSymbol( } template <typename ElemT> +ScopedDeviceMemory<ElemT>::ScopedDeviceMemory() + : wrapped_(DeviceMemoryBase()), parent_(nullptr) {} + +template <typename ElemT> ScopedDeviceMemory<ElemT>::ScopedDeviceMemory(StreamExecutor *parent, DeviceMemoryBase value) : wrapped_(value), parent_(parent) {} @@ -692,18 +696,26 @@ ScopedDeviceMemory<ElemT>::ScopedDeviceMemory( template <typename ElemT> ScopedDeviceMemory<ElemT>::~ScopedDeviceMemory() { + if (wrapped_ == nullptr) return; + DCHECK(parent_ != nullptr); parent_->Deallocate(&wrapped_); } template <typename ElemT> void ScopedDeviceMemory<ElemT>::Reset(DeviceMemory<ElemT> updated) { - parent_->Deallocate(&wrapped_); + if (wrapped_ != nullptr) { + DCHECK(parent_ != nullptr); + parent_->Deallocate(&wrapped_); + } wrapped_ = updated; } template <typename ElemT> void ScopedDeviceMemory<ElemT>::Reset(std::nullptr_t) { - parent_->Deallocate(&wrapped_); + if (wrapped_ != nullptr) { + DCHECK(parent_ != nullptr); + parent_->Deallocate(&wrapped_); + } wrapped_ = DeviceMemory<ElemT>{}; } |