[TF:XLA] Register a real implementation of ControlTrigger on XLA devices.
authorPeter Hawkins <phawkins@google.com>
Wed, 23 May 2018 18:31:36 +0000 (11:31 -0700)
committerTensorFlower Gardener <gardener@tensorflow.org>
Wed, 23 May 2018 18:33:57 +0000 (11:33 -0700)
PiperOrigin-RevId: 197759239

tensorflow/compiler/jit/xla_device_ops.h
tensorflow/compiler/tests/xla_device_test.py
tensorflow/compiler/tf2xla/kernels/no_op.cc

index 9c00a06..59822a1 100644 (file)
@@ -73,7 +73,9 @@ class XlaDeviceDummyOp : public OpKernel {
                                                                                \
   REGISTER_KERNEL_BUILDER(                                                     \
       Name("VarHandleOp").Device(DEVICE).HostMemory("resource"),               \
-      ResourceHandleOp<Var>);
+      ResourceHandleOp<Var>);                                                  \
+  REGISTER_KERNEL_BUILDER(Name("ControlTrigger").Device(DEVICE),               \
+                          ControlTriggerOp);
 
 }  // namespace tensorflow
 
index b707bd0..f0b010f 100644 (file)
@@ -23,6 +23,7 @@ import numpy as np
 from tensorflow.compiler.tests.xla_test import XLATestCase
 from tensorflow.python.framework import ops
 from tensorflow.python.ops import array_ops
+from tensorflow.python.ops import gen_control_flow_ops
 from tensorflow.python.platform import test
 
 
@@ -46,6 +47,12 @@ class XlaDeviceTest(XLATestCase):
           result = sess.run(z, {x: inputs})
         self.assertAllCloseAccordingToType(result, inputs + inputs)
 
+  def testControlTrigger(self):
+    with self.test_session() as sess:
+      with self.test_scope():
+        x = gen_control_flow_ops.control_trigger()
+      sess.run(x)
+
 
 if __name__ == "__main__":
   test.main()
index 8c8a9bb..65ab9da 100644 (file)
@@ -24,8 +24,7 @@ namespace tensorflow {
 REGISTER_XLA_OP(Name("NoOp").CompilationOnly(), NoOp);
 
 // We register ControlTrigger as a no-op. This is correct since nodes seen
-// by the XLA compiler are never dead. This may need rethinking when we add
-// support for conditionals to XLA.
-REGISTER_XLA_OP(Name("ControlTrigger"), NoOp);
+// by the XLA compiler are never dead.
+REGISTER_XLA_OP(Name("ControlTrigger").CompilationOnly(), NoOp);
 
 }  // namespace tensorflow