Home | History | Annotate | Download | only in kernels
      1 /* Copyright 2017 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 #include "tensorflow/compiler/tf2xla/xla_op_kernel.h"
     17 #include "tensorflow/compiler/tf2xla/xla_op_registry.h"
     18 
     19 namespace tensorflow {
     20 namespace {
     21 
     22 class IdentityOp : public XlaOpKernel {
     23  public:
     24   explicit IdentityOp(OpKernelConstruction* context) : XlaOpKernel(context) {}
     25 
     26   void Compile(XlaOpKernelContext* ctx) override {
     27     for (int i = 0; i < ctx->num_inputs(); ++i) {
     28       ctx->SetOutput(i, ctx->Input(i));
     29     }
     30   }
     31 
     32  private:
     33   TF_DISALLOW_COPY_AND_ASSIGN(IdentityOp);
     34 };
     35 
     36 // XLA_* devices also register a "real" Identity operator so we suppress the
     37 // dummy operator using CompilationOnly().
     38 REGISTER_XLA_OP(Name("Identity").CompilationOnly(), IdentityOp);
     39 
     40 REGISTER_XLA_OP(Name("IdentityN").CompilationOnly(), IdentityOp);
     41 REGISTER_XLA_OP(Name("PreventGradient"), IdentityOp);
     42 REGISTER_XLA_OP(Name("StopGradient"), IdentityOp);
     43 REGISTER_XLA_OP(Name("Snapshot"), IdentityOp);
     44 
     45 }  // namespace
     46 }  // namespace tensorflow
     47