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