From 1c3e6c74d1eb63ebef2257c3eb7f3ee05ddd88d2 Mon Sep 17 00:00:00 2001 From: Eugene Brevdo Date: Tue, 18 Apr 2017 15:40:56 -0800 Subject: [TF] Optimization of tf.tile: Skip allocation if multiples is all ones. Change: 153528509 --- tensorflow/core/kernels/tile_ops.cc | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tensorflow/core/kernels/tile_ops.cc') diff --git a/tensorflow/core/kernels/tile_ops.cc b/tensorflow/core/kernels/tile_ops.cc index 9822b021eb..06f20cd9ec 100644 --- a/tensorflow/core/kernels/tile_ops.cc +++ b/tensorflow/core/kernels/tile_ops.cc @@ -124,6 +124,10 @@ class TileOp : public OpKernel { multiples_array[i])); output_shape.AddDim(input.dim_size(i) * multiples_array[i]); } + if (output_shape == input.shape()) { + context->set_output(0, input); + return; + } Tensor* result = nullptr; OP_REQUIRES_OK(context, context->allocate_output(0, output_shape, &result)); @@ -315,6 +319,10 @@ class TileGradientOp : public OpKernel { output_shape.AddDim(input.dim_size(i) / multiples_array[i]); input_dim_size_vec.push_back(input.dim_size(i)); } + if (output_shape == input.shape()) { + context->set_output(0, input); + return; + } Tensor* result = nullptr; OP_REQUIRES_OK(context, context->allocate_output(0, output_shape, &result)); -- cgit v1.2.3