• 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_DEADNESS_ANALYSIS_H_
17 #define TENSORFLOW_COMPILER_JIT_DEADNESS_ANALYSIS_H_
18 
19 #include "tensorflow/core/graph/graph.h"
20 
21 namespace tensorflow {
22 
23 // This analyzes a TensorFlow graph to identify nodes which may have partially
24 // dead inputs (i.e. these nodes may have some dead inputs and some alive
25 // inputs).
26 //
27 // For example, the ADD node in the following graph
28 //
29 //      V0  PRED0    V1  PRED1
30 //       |    |       |    |
31 //       v    v       v    v
32 //       SWITCH       SWITCH
33 //          |            |
34 //          +---+   + ---+
35 //              |   |
36 //              v   v
37 //               ADD
38 //
39 // can have its inputs independently dead or alive based on the runtime values
40 // of PRED0 and PRED1.
41 //
42 // It is tempting to call this a liveness analysis but I avoided that because
43 // "liveness" already has other connotations.
44 class DeadnessAnalysis {
45  public:
46   // Returns true if `node` may have some live inputs and some dead inputs.
47   //
48   // This is a conservatively correct routine -- if it returns false then `node`
49   // is guaranteed to not have inputs with mismatching liveness, but not the
50   // converse.
51   //
52   // REQUIRES: node is not a Merge operation.
53   virtual bool HasInputsWithMismatchingDeadness(const Node& node) = 0;
54 
55   // Prints out the internal state of this instance.  For debugging purposes
56   // only.
57   virtual void Print() const = 0;
58   virtual ~DeadnessAnalysis();
59 
60   // Run the deadness analysis over `graph` and returns an error or a populated
61   // instance of DeadnessAnalysis in `result`.
62   static Status Run(const Graph& graph,
63                     std::unique_ptr<DeadnessAnalysis>* result);
64 };
65 
66 }  // namespace tensorflow
67 
68 #endif  // TENSORFLOW_COMPILER_JIT_DEADNESS_ANALYSIS_H_
69