Home | History | Annotate | Download | only in kernels
      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_KERNELS_CONTROL_FLOW_OPS_H_
     17 #define TENSORFLOW_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:
     29   explicit ControlTriggerOp(OpKernelConstruction* context)
     30       : OpKernel(context) {}
     31   void Compute(OpKernelContext* context) override {}
     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:
     41   explicit SwitchOp(OpKernelConstruction* context) : OpKernel(context) {}
     42   void Compute(OpKernelContext* context) override;
     43   bool IsExpensive() override { return false; }
     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;
     56   bool IsExpensive() override { return false; }
     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:
     67   explicit EnterOp(OpKernelConstruction* context) : OpKernel(context) {}
     68   void Compute(OpKernelContext* context) override;
     69   bool IsExpensive() override { return false; }
     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:
     80   explicit ExitOp(OpKernelConstruction* context) : OpKernel(context) {}
     81   void Compute(OpKernelContext* context) override;
     82   bool IsExpensive() override { return false; }
     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:
     92   explicit NextIterationOp(OpKernelConstruction* context) : OpKernel(context) {}
     93   void Compute(OpKernelContext* context) override;
     94   bool IsExpensive() override { return false; }
     95   ~NextIterationOp() override {}
     96 
     97   TF_DISALLOW_COPY_AND_ASSIGN(NextIterationOp);
     98 };
     99 
    100 }  // namespace tensorflow
    101 
    102 #endif  // TENSORFLOW_KERNELS_CONTROL_FLOW_OPS_H_
    103