aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/core/framework/tensor.cc
diff options
context:
space:
mode:
Diffstat (limited to 'tensorflow/core/framework/tensor.cc')
-rw-r--r--tensorflow/core/framework/tensor.cc13
1 files changed, 7 insertions, 6 deletions
diff --git a/tensorflow/core/framework/tensor.cc b/tensorflow/core/framework/tensor.cc
index 7b85ff9c36..de15d82269 100644
--- a/tensorflow/core/framework/tensor.cc
+++ b/tensorflow/core/framework/tensor.cc
@@ -416,7 +416,8 @@ Tensor::Tensor(DataType type, const TensorShape& shape, TensorBuffer* buf)
}
bool Tensor::IsInitialized() const {
- return buf_ != nullptr && buf_->data() != nullptr;
+ return (buf_ != nullptr && buf_->data() != nullptr) ||
+ shape_.num_elements() == 0;
}
void Tensor::CheckType(DataType expected_dtype) const {
@@ -507,7 +508,7 @@ Tensor::Tensor(Allocator* a, DataType type, const TensorShape& shape)
if (shape_.num_elements() > 0 || a->ShouldAllocateEmptyTensors()) {
CASES(type, buf_ = new Buffer<T>(a, shape.num_elements()));
}
- if (IsInitialized() && LogMemory::IsEnabled()) {
+ if (buf_ != nullptr && buf_->data() != nullptr && LogMemory::IsEnabled()) {
LogMemory::RecordTensorAllocation("Unknown", LogMemory::UNKNOWN_STEP_ID,
*this);
}
@@ -521,8 +522,8 @@ Tensor::Tensor(Allocator* a, DataType type, const TensorShape& shape,
if (shape_.num_elements() > 0 || a->ShouldAllocateEmptyTensors()) {
CASES(type, buf_ = new Buffer<T>(a, shape.num_elements(), allocation_attr));
}
- if (!allocation_attr.allocation_will_be_logged && IsInitialized() &&
- LogMemory::IsEnabled()) {
+ if (!allocation_attr.allocation_will_be_logged && buf_ != nullptr &&
+ buf_->data() != nullptr && LogMemory::IsEnabled()) {
LogMemory::RecordTensorAllocation("Unknown (with attributes)",
LogMemory::UNKNOWN_STEP_ID, *this);
}
@@ -617,7 +618,7 @@ bool Tensor::FromProto(Allocator* a, const TensorProto& proto) {
buf_ = p;
// TODO(misard) add tracking of which kernels and steps are calling
// FromProto.
- if (IsInitialized() && LogMemory::IsEnabled()) {
+ if (buf_ != nullptr && buf_->data() != nullptr && LogMemory::IsEnabled()) {
LogMemory::RecordTensorAllocation("Unknown (from Proto)",
LogMemory::UNKNOWN_STEP_ID, *this);
}
@@ -765,7 +766,7 @@ string Tensor::DebugString() const {
void Tensor::FillDescription(TensorDescription* description) const {
description->set_dtype(dtype());
shape().AsProto(description->mutable_shape());
- if (IsInitialized()) {
+ if (buf_ != nullptr && buf_->data() != nullptr) {
buf_->FillAllocationDescription(
description->mutable_allocation_description());
}