aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/core/framework/tensor_shape.h
diff options
context:
space:
mode:
authorGravatar A. Unique TensorFlower <nobody@tensorflow.org>2016-05-04 08:14:06 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2016-05-04 09:21:36 -0700
commitf7a662e595f1631c12d15173344ee0f50d2cd9f8 (patch)
treeab87e6527dadcc2b7b9367ce70c62052bc343cd5 /tensorflow/core/framework/tensor_shape.h
parenta1bc10f9e28cd3d33e91bfaedd8199e4590f2893 (diff)
Reduce overhead of ExecutorState::ProcessOutputs:
- Cache result of LogMemory::IsEnabled. - Init Tensor for logging only if logging is enabled. - Add move constructor to Tensor and use it in ProcessOutputs. Also added benchmark for copy vs move in tensor_test.cc Change: 121487202
Diffstat (limited to 'tensorflow/core/framework/tensor_shape.h')
-rw-r--r--tensorflow/core/framework/tensor_shape.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/tensorflow/core/framework/tensor_shape.h b/tensorflow/core/framework/tensor_shape.h
index 84947e308a..7cc8223016 100644
--- a/tensorflow/core/framework/tensor_shape.h
+++ b/tensorflow/core/framework/tensor_shape.h
@@ -54,6 +54,13 @@ class TensorShape {
TensorShape(const TensorShape& b);
void operator=(const TensorShape& b);
+ /// Move the specified shape. After moving, <b> is safe for destruction and
+ // can be reassigned into, but its dimensions and number of elements can be
+ // nonsensical (e.g., negative dimension sizes, or number of elements not
+ // properly recomputed).
+ TensorShape(TensorShape&& b);
+ void operator=(TensorShape&& b);
+
/// Returns `true` iff `proto` is a valid tensor shape.
static bool IsValid(const TensorShapeProto& proto);
@@ -308,6 +315,15 @@ inline TensorShape::TensorShape(const TensorShape& b) {
}
}
+inline TensorShape::TensorShape(TensorShape&& b) {
+ num_elements_ = b.num_elements_;
+ memcpy(buf(), b.buf(), sizeof(u_.buf));
+ // memcpy above Implicitly does:
+ // set_ndims_byte(b.ndims_byte());
+ // set_tag(b.tag());
+ b.set_tag(REP16); // other shape no longer owns out-of-line data, if any.
+}
+
inline TensorShape::~TensorShape() {
if (tag() == REP_OUT_OF_LINE) {
DestructorOutOfLine();
@@ -326,6 +342,18 @@ inline void TensorShape::operator=(const TensorShape& b) {
}
}
+inline void TensorShape::operator=(TensorShape&& b) {
+ if (tag() == REP_OUT_OF_LINE) {
+ DestructorOutOfLine();
+ }
+ num_elements_ = b.num_elements_;
+ memcpy(buf(), b.buf(), sizeof(u_.buf));
+ // memcpy above Implicitly does:
+ // set_ndims_byte(b.ndims_byte());
+ // set_tag(b.tag());
+ b.set_tag(REP16); // other shape no longer owns out-of-line data, if any.
+}
+
} // namespace tensorflow
#endif // TENSORFLOW_CORE_FRAMEWORK_TENSOR_SHAPE_H_