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 AddNOp : public XlaOpKernel {
     23  public:
     24   explicit AddNOp(OpKernelConstruction* ctx) : XlaOpKernel(ctx) {}
     25 
     26   void Compile(XlaOpKernelContext* ctx) override {
     27     if (!ctx->ValidateInputsAreSameShape(this)) return;
     28 
     29     OP_REQUIRES(ctx, ctx->num_inputs() >= 1,
     30                 errors::InvalidArgument("AddN requires at least one argument"));
     31 
     32     xla::ComputationDataHandle sum = ctx->Input(0);
     33     for (int i = 1; i < ctx->num_inputs(); ++i) {
     34       sum = ctx->builder()->Add(sum, ctx->Input(i));
     35     }
     36 
     37     ctx->SetOutput(0, sum);
     38   }
     39 
     40  private:
     41   TF_DISALLOW_COPY_AND_ASSIGN(AddNOp);
     42 };
     43 
     44 REGISTER_XLA_OP(Name("AddN"), AddNOp);
     45 
     46 }  // namespace
     47 }  // namespace tensorflow
     48