• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2019 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_COMPILER_TF2XLA_KERNELS_TENSOR_LIST_UTILS_H_
17 #define TENSORFLOW_COMPILER_TF2XLA_KERNELS_TENSOR_LIST_UTILS_H_
18 
19 // TensorList utilities.
20 //
21 // Tensor lists are represented as tuple consisting of a pre-allocated buffer
22 // consisting of the tensors (and where dim 0 is the list index), along with a
23 // scalar telling us the next index to push a value at.
24 
25 #include "tensorflow/compiler/tf2xla/xla_op_kernel.h"
26 #include "tensorflow/compiler/xla/client/xla_builder.h"
27 #include "tensorflow/core/framework/tensor_shape.h"
28 
29 namespace tensorflow {
30 
31 // Whether the input expression at `index` corresponds to a TensorList.
32 bool IsTensorListInput(XlaOpKernelContext* ctx, int index);
33 
34 // Builds a TensorList from its constituents, `buffer` and `push_index`.
35 Status BuildTensorList(const xla::XlaOp& buffer, const xla::XlaOp& push_index,
36                        xla::XlaOp* output_list);
37 
38 // Returns the buffer for the TensorList.
39 Status GetTensorListBuffer(const xla::XlaOp& op, xla::XlaOp* buffer);
40 
41 // Returns the push_index for the TensorList.
42 Status GetTensorListPushIndex(const xla::XlaOp& op, xla::XlaOp* push_index);
43 
44 // Returns the shape of the TensorList buffer.
45 Status GetTensorListBufferShape(const xla::XlaOp& op,
46                                 TensorShape* buffer_shape);
47 
48 // Inputs the TensorList shape and returns the buffer shape.
49 Status GetTensorListBufferShape(const xla::Shape& list_shape,
50                                 TensorShape* buffer_shape);
51 
52 // Returns whether the TensorList has been initialized.
53 //
54 // A TensorList is considered initialized if its element_shape is completely
55 // known.
56 Status IsTensorListInitialized(const xla::XlaOp& op, bool* is_initialized);
57 
58 // Inputs an uninitialized list and a buffer_shape and returns an initialized
59 // list. The initialized list uses the dtype and push index of the uninitialized
60 // list and is filled with zeros.
61 Status InitializeTensorList(const xla::XlaOp& uninitialized_list,
62                             const TensorShape& buffer_shape,
63                             xla::XlaOp* output_list);
64 
65 }  // namespace tensorflow
66 
67 #endif  // TENSORFLOW_COMPILER_TF2XLA_KERNELS_TENSOR_LIST_UTILS_H_
68