1 /* Copyright 2015 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 #ifndef TENSORFLOW_CORE_KERNELS_CONTROL_FLOW_OPS_H_ 17 #define TENSORFLOW_CORE_KERNELS_CONTROL_FLOW_OPS_H_ 18 19 #include "tensorflow/core/framework/op_kernel.h" 20 21 namespace tensorflow { 22 23 // A ControlTriggerOp is similar to a NoOp. However, it always treats the input 24 // control edges as Live edges. Its primary use so far is in the scheduling of 25 // recvs, where we add ControlTrigger nodes and use them to trigger recvs. We 26 // allow ControlTrigger nodes to be enabled by dead nodes. 27 class ControlTriggerOp : public OpKernel { 28 public: ControlTriggerOp(OpKernelConstruction * context)29 explicit ControlTriggerOp(OpKernelConstruction* context) 30 : OpKernel(context) {} Compute(OpKernelContext * context)31 void Compute(OpKernelContext* context) override {} IsExpensive()32 bool IsExpensive() override { return false; } 33 }; 34 35 // A switch op has two inputs and two outputs. It forwards the value of 36 // Input:0 to the output specified by input:1. Input:1 is a boolean tensor. 37 // Input:0 is forwarded to output:0 if input:1 is false, otherwise to 38 // output:1. 39 class SwitchOp : public OpKernel { 40 public: SwitchOp(OpKernelConstruction * context)41 explicit SwitchOp(OpKernelConstruction* context) : OpKernel(context) {} 42 void Compute(OpKernelContext* context) override; IsExpensive()43 bool IsExpensive() override { return false; } ~SwitchOp()44 ~SwitchOp() override {} 45 46 TF_DISALLOW_COPY_AND_ASSIGN(SwitchOp); 47 }; 48 49 // A merge op has n inputs and two outputs. It forwards the value of the 50 // first input that becomes available to its first output, and the 51 // index of the first input to its second output. 52 class MergeOp : public OpKernel { 53 public: 54 explicit MergeOp(OpKernelConstruction* context); 55 void Compute(OpKernelContext* context) override; IsExpensive()56 bool IsExpensive() override { return false; } ~MergeOp()57 ~MergeOp() override {} 58 59 TF_DISALLOW_COPY_AND_ASSIGN(MergeOp); 60 }; 61 62 // An enter op has one input and one output. It creates or finds 63 // the child frame that is uniquely identified by the frame_name, 64 // and makes its input available to the child frame. 65 class EnterOp : public OpKernel { 66 public: EnterOp(OpKernelConstruction * context)67 explicit EnterOp(OpKernelConstruction* context) : OpKernel(context) {} 68 void Compute(OpKernelContext* context) override; IsExpensive()69 bool IsExpensive() override { return false; } ~EnterOp()70 ~EnterOp() override {} 71 72 TF_DISALLOW_COPY_AND_ASSIGN(EnterOp); 73 }; 74 75 // An exit op has one input and one output. It exits the current 76 // frame to its parent frame, and makes its input available to the 77 // parent frame. 78 class ExitOp : public OpKernel { 79 public: ExitOp(OpKernelConstruction * context)80 explicit ExitOp(OpKernelConstruction* context) : OpKernel(context) {} 81 void Compute(OpKernelContext* context) override; IsExpensive()82 bool IsExpensive() override { return false; } ~ExitOp()83 ~ExitOp() override {} 84 85 TF_DISALLOW_COPY_AND_ASSIGN(ExitOp); 86 }; 87 88 // A next_iteration op has one input and one output. It makes its input 89 // available to the next iteration. 90 class NextIterationOp : public OpKernel { 91 public: NextIterationOp(OpKernelConstruction * context)92 explicit NextIterationOp(OpKernelConstruction* context) : OpKernel(context) {} 93 void Compute(OpKernelContext* context) override; IsExpensive()94 bool IsExpensive() override { return false; } ~NextIterationOp()95 ~NextIterationOp() override {} 96 97 TF_DISALLOW_COPY_AND_ASSIGN(NextIterationOp); 98 }; 99 100 // A LoopCond op has one input and one output. The input is a boolean 101 // scalar representing the taken branches of the "pivot" Switch that 102 // determines loop termination. As a contract, any high-level front-end 103 // should always use port '0' of the "pivot" switches for loop exit. 104 class LoopCondOp : public OpKernel { 105 public: 106 explicit LoopCondOp(OpKernelConstruction* context); 107 ~LoopCondOp() override; 108 109 void Compute(OpKernelContext* context) override; 110 111 bool IsExpensive() override; 112 113 TF_DISALLOW_COPY_AND_ASSIGN(LoopCondOp); 114 }; 115 116 } // namespace tensorflow 117 118 #endif // TENSORFLOW_CORE_KERNELS_CONTROL_FLOW_OPS_H_ 119