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 // Helper methods for XLA Gather Ops.
17 
18 #ifndef TENSORFLOW_COMPILER_TF2XLA_KERNELS_GATHER_OP_HELPERS_H_
19 #define TENSORFLOW_COMPILER_TF2XLA_KERNELS_GATHER_OP_HELPERS_H_
20 
21 #include "tensorflow/compiler/tf2xla/xla_op_kernel.h"
22 #include "tensorflow/compiler/xla/client/client_library.h"
23 #include "tensorflow/compiler/xla/client/xla_builder.h"
24 #include "tensorflow/core/framework/op_kernel.h"
25 #include "tensorflow/core/util/bcast.h"
26 
27 namespace tensorflow {
28 
29 // Adds to builder an XLA computation that performs a gather on input (of
30 // shape input_shape) keyed on indices (of shape indices_shape).
31 //
32 // index_type must be must be DT_INT32 or DT_INT64.
33 // If `indices_are_nd` is true, the last dimension of `indices` are treated as
34 // a multidimensional index values. Otherwise, `indices` is treated as a tensor
35 // of scalar indices.
36 Status XlaGather(const xla::XlaOp& input, const TensorShape& input_shape,
37                  const xla::XlaOp& indices, const TensorShape& indices_shape,
38                  int64 axis, bool indices_are_nd, DataType dtype,
39                  DataType index_type, xla::XlaBuilder* builder,
40                  xla::XlaOp* gather_output);
41 
42 // The implementation of Gather and ResourceGather through XLA. Uses `input` as
43 // the input instead of context->input(0) in order to allow ResourceGather to
44 // handle obtaining the data from the ResourceVariable.
45 Status XlaGatherWithBatchDimsOpImpl(XlaOpKernelContext* context,
46                                     const xla::XlaOp input,
47                                     const TensorShape& input_shape,
48                                     int batch_dims, xla::XlaOp* gather_output);
49 }  // namespace tensorflow
50 
51 #endif  // TENSORFLOW_COMPILER_TF2XLA_KERNELS_GATHER_OP_HELPERS_H_
52