• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2018 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_JIT_SHAPE_INFERENCE_H_
17 #define TENSORFLOW_COMPILER_JIT_SHAPE_INFERENCE_H_
18 
19 #include <map>
20 #include <vector>
21 
22 #include "tensorflow/compiler/xla/statusor.h"
23 #include "tensorflow/core/common_runtime/optimization_registry.h"
24 #include "tensorflow/core/common_runtime/shape_refiner.h"
25 #include "tensorflow/core/lib/core/status.h"
26 
27 namespace tensorflow {
28 
29 struct InferredShape {
30   // Shape of the argument tensor.
31   PartialTensorShape shape;
32 
33   // If the argument is a resource variable, the type and shape of the
34   // variable's value.
35   DataType handle_type = DT_INVALID;
36   PartialTensorShape handle_shape;
37 };
38 typedef std::unordered_map<string, std::vector<InferredShape>> GraphShapeInfo;
39 
40 // Infer shapes for all Tensors in a graph, and save them in a map.  The vector
41 // for a Node contains the information about each of its outputs.
42 // TODO(phawkins): this code does not infer accurate shapes for cyclic graphs.
43 Status InferShapes(Graph* graph, const std::map<int, InferredShape>& arg_shapes,
44                    const tensorflow::FunctionLibraryDefinition* fnlib_def,
45                    GraphShapeInfo* shape_info);
46 
47 // Merges two InferredShapes. Return an error if the two shapes cannot be
48 // merged.
49 xla::StatusOr<InferredShape> MergeInferredShapes(const InferredShape& a,
50                                                  const InferredShape& b);
51 
52 }  // namespace tensorflow
53 
54 #endif  // TENSORFLOW_COMPILER_JIT_SHAPE_INFERENCE_H_
55