• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2016 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 // Build a flat structure of ops.
17 
18 #ifndef TENSORFLOW_CORE_PROFILER_INTERNAL_TFPROF_OP_H_
19 #define TENSORFLOW_CORE_PROFILER_INTERNAL_TFPROF_OP_H_
20 
21 #include <deque>
22 #include <map>
23 #include <memory>
24 #include <set>
25 #include <string>
26 #include <vector>
27 
28 #include "tensorflow/core/lib/core/errors.h"
29 #include "tensorflow/core/profiler/internal/tfprof_node.h"
30 #include "tensorflow/core/profiler/internal/tfprof_show_multi.h"
31 #include "tensorflow/core/profiler/internal/tfprof_utils.h"
32 #include "tensorflow/core/profiler/tfprof_options.h"
33 #include "tensorflow/core/profiler/tfprof_output.pb.h"
34 
35 namespace tensorflow {
36 namespace tfprof {
37 
38 // Organize tensorflow ops in a graph structure, pointing from output ops
39 // to input ops.
40 class TFOp : public TFMultiShow {
41  public:
TFOp()42   explicit TFOp() : TFMultiShow() {}
~TFOp()43   ~TFOp() override {}
44 
45   void AddNode(TFGraphNode* node) override;
46 
47   void Build() override;
48 
49  private:
50   const ShowMultiNode* ShowInternal(const Options& opts,
51                                     Timeline* timeline) override;
52 
53   int64_t SearchRoot(const std::vector<OpNode*> nodes,
54                      const std::vector<string>& regexes);
55 
ShouldShowIfExtra(const ShowMultiNode * node,const Options & opts,int depth)56   bool ShouldShowIfExtra(const ShowMultiNode* node, const Options& opts,
57                          int depth) const override {
58     const int max_num_graph_nodes = node->node->graph_nodes().size();
59     if (opts.min_occurrence > max_num_graph_nodes) {
60       return false;
61     }
62     return true;
63   }
64 
65   string FormatNode(OpNode* node, OpNode* root, const Options& opts) const;
66   string FormatMemoryNode(int64_t node_total_bytes, int64_t root_total_bytes,
67                           int64_t node_bytes) const;
68 
69   std::unique_ptr<OpNode> root_;
70   std::map<string, std::unique_ptr<OpNode>> cnodes_map_;
71   std::map<string, std::unique_ptr<TFMultiGraphNode>> tfcnodes_map_;
72 };
73 
74 }  // namespace tfprof
75 }  // namespace tensorflow
76 
77 #endif  // TENSORFLOW_CORE_PROFILER_INTERNAL_TFPROF_OP_H_
78