aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/stream_executor/stream_executor_pimpl.h
diff options
context:
space:
mode:
authorGravatar A. Unique TensorFlower <gardener@tensorflow.org>2017-01-20 13:29:02 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2017-01-20 13:50:05 -0800
commit3ecafa37a2c6cd3a95fc568b00c43a9b87649300 (patch)
treec07035e84b2442b889a02242318ee74417c0a340 /tensorflow/stream_executor/stream_executor_pimpl.h
parentbb71ec089658fb8a91423a7cf7195e5c900c2c98 (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.h16
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>{};
}