aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/core/common_runtime
diff options
context:
space:
mode:
authorGravatar Peter Hawkins <phawkins@google.com>2018-10-04 08:08:22 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-10-04 08:12:38 -0700
commit7b56d4ff7679ed59e3ea799054c5dcefd0600ab0 (patch)
tree65e44b2071e1031a709143434944dcac5f601c98 /tensorflow/core/common_runtime
parent82ea80b979768c7fe1daa4b50cf054e5a0968f31 (diff)
[TF] Fail fast if there is no CPU kernel during constant tensor evaluation.
Avoids LOG(ERROR) spam when the Executor is unable to find a CPU kernel. PiperOrigin-RevId: 215738481
Diffstat (limited to 'tensorflow/core/common_runtime')
-rw-r--r--tensorflow/core/common_runtime/eval_const_tensor.cc18
1 files changed, 18 insertions, 0 deletions
diff --git a/tensorflow/core/common_runtime/eval_const_tensor.cc b/tensorflow/core/common_runtime/eval_const_tensor.cc
index c1542f1f57..87749da7af 100644
--- a/tensorflow/core/common_runtime/eval_const_tensor.cc
+++ b/tensorflow/core/common_runtime/eval_const_tensor.cc
@@ -113,6 +113,13 @@ Status TryToInferTensorOutputFromInputShapes(const Edge& edge,
return Status::OK();
}
+// Returns true if 'node' has a registered CPU kernel.
+bool HasCpuKernel(const Node& node) {
+ return FindKernelDef(DeviceType(DEVICE_CPU), node.def(), /*def=*/nullptr,
+ /*kernel_class_name=*/nullptr)
+ .ok();
+}
+
// Extracts the subgraph ending at 'target_node' that is statically computable
// and inserts into 'out_graph'. If statically computable, 'is_constant_graph'
// will be set to true.
@@ -136,6 +143,12 @@ Status ExtractConstantSubgraph(
return Status::OK();
}
+ // Since constant-folding runs on the CPU, do not attempt to constant-fold
+ // operators that have no CPU kernel.
+ if (!HasCpuKernel(target_node)) {
+ return Status::OK();
+ }
+
// TODO(skyewm): should more of the filtering applied in input nodes below be
// applied to target_node here?
@@ -201,6 +214,11 @@ Status ExtractConstantSubgraph(
return Status::OK();
}
+ if (!HasCpuKernel(*current_node)) {
+ *is_constant_graph = false;
+ return Status::OK();
+ }
+
// If there is nothing more to recurse down, see if
// the generator node is a constant.
if (current_node->num_inputs() == 0) {