From 8017c247c84c4c80fa11744b1b913aec3ee88f3e Mon Sep 17 00:00:00 2001 From: Derek Murray Date: Wed, 21 Feb 2018 14:46:29 -0800 Subject: [PATCH] Mark the `SerializeSparseOp` kernel as inexpensive. Since this op only performs a constant amount of work, and typically executes in a few microseconds, it should be profitable to execute this op inline, rather than scheduling it on a remote thread. PiperOrigin-RevId: 186522885 --- tensorflow/core/kernels/serialize_sparse_op.cc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tensorflow/core/kernels/serialize_sparse_op.cc b/tensorflow/core/kernels/serialize_sparse_op.cc index 799c574..64e0a68 100644 --- a/tensorflow/core/kernels/serialize_sparse_op.cc +++ b/tensorflow/core/kernels/serialize_sparse_op.cc @@ -44,6 +44,8 @@ class SerializeSparseOp : public OpKernel { explicit SerializeSparseOp(OpKernelConstruction* context) : OpKernel(context) {} + bool IsExpensive() override; + Status Initialize(Tensor* result); Status Serialize(const Tensor& input, T* result); @@ -82,6 +84,21 @@ class SerializeSparseOp : public OpKernel { } }; +// NOTE(mrry): We specialize the IsExpensive() method differently for +// the string and variant cases, because (i) the string version +// actually performs memory copies as part of its serialization (and +// is hence potentially expensive), and (ii) the variant version +// performs O(1) shallow copies (and hence is much cheaper than +// dispatching to another thread would be). +template <> +bool SerializeSparseOp::IsExpensive() { + return true; +} +template <> +bool SerializeSparseOp::IsExpensive() { + return false; +} + template <> Status SerializeSparseOp::Initialize(Tensor* result) { *result = Tensor(DT_STRING, TensorShape({3})); -- 2.7.4