• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2020 Huawei Technologies Co., Ltd
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef MINDSPORE_MINDSPORE_CCSRC_DEBUG_DUMP_JSON_PARSER_H_
18 #define MINDSPORE_MINDSPORE_CCSRC_DEBUG_DUMP_JSON_PARSER_H_
19 
20 #include <string>
21 #include <map>
22 #include <set>
23 #include <mutex>
24 #include <vector>
25 #include "nlohmann/json.hpp"
26 #include "utils/ms_utils.h"
27 #include "backend/session/kernel_graph.h"
28 namespace mindspore {
29 class DumpJsonParser {
30  public:
GetInstance()31   static DumpJsonParser &GetInstance() {
32     static DumpJsonParser instance;
33     return instance;
34   }
35 
36   void Parse();
37   static bool DumpToFile(const std::string &filename, const void *data, size_t len, const ShapeVector &shape,
38                          TypeId type);
39   void CopyDumpJsonToDir(uint32_t rank_id);
40   void CopyHcclJsonToDir(uint32_t rank_id);
41   void CopyMSCfgJsonToDir(uint32_t rank_id);
42   bool NeedDump(const std::string &op_full_name) const;
43   void MatchKernel(const std::string &kernel_name);
44   void PrintUnusedKernel();
45   bool IsDumpIter(uint32_t iteration) const;
46   bool DumpAllIter();
47 
async_dump_enabled()48   bool async_dump_enabled() const { return async_dump_enabled_; }
e2e_dump_enabled()49   bool e2e_dump_enabled() const { return e2e_dump_enabled_; }
dump_mode()50   uint32_t dump_mode() const { return dump_mode_; }
path()51   std::string path() const { return path_; }
iteration_string()52   std::string iteration_string() const { return iteration_; }
net_name()53   std::string net_name() const { return net_name_; }
op_debug_mode()54   uint32_t op_debug_mode() const { return op_debug_mode_; }
trans_flag()55   bool trans_flag() const { return trans_flag_; }
cur_dump_iter()56   uint32_t cur_dump_iter() const { return cur_dump_iter_; }
UpdateDumpIter()57   void UpdateDumpIter() { ++cur_dump_iter_; }
58   bool GetIterDumpFlag() const;
59   bool InputNeedDump() const;
60   bool OutputNeedDump() const;
61   std::string GetOpOverflowBinPath(uint32_t graph_id) const;
62   void UpdateNeedDumpKernels(const session::KernelGraph &kernel_graph);
63 
ClearGraph()64   void ClearGraph() { graphs_.clear(); }
SaveGraph(session::KernelGraph * graph)65   void SaveGraph(session::KernelGraph *graph) { (void)graphs_.emplace_back(graph); }
graphs()66   const std::vector<session::KernelGraph *> &graphs() const { return graphs_; }
67 
68  private:
69   DumpJsonParser() = default;
70   ~DumpJsonParser() = default;
71   DISABLE_COPY_AND_ASSIGN(DumpJsonParser)
72 
73   std::mutex lock_;
74   bool async_dump_enabled_{false};
75   bool e2e_dump_enabled_{false};
76   uint32_t dump_mode_{0};
77   std::string path_;
78   std::string net_name_;
79   std::string iteration_;
80   uint32_t input_output_{0};
81   std::map<std::string, uint32_t> kernels_;
82   std::set<uint32_t> support_devices_;
83   uint32_t op_debug_mode_{0};
84   bool trans_flag_{false};
85   uint32_t cur_dump_iter_{0};
86   bool already_parsed_{false};
87 
88   // Save graphs for dump.
89   std::vector<session::KernelGraph *> graphs_;
90 
91   void ParseCommonDumpSetting(const nlohmann::json &content);
92   void ParseE2eDumpSetting(const nlohmann::json &content);
93   bool IsDumpEnabled();
94 
95   auto CheckJsonKeyExist(const nlohmann::json &content, const std::string &key);
96 
97   void ParseDumpMode(const nlohmann::json &content);
98   void ParseDumpPath(const nlohmann::json &content);
99   void ParseNetName(const nlohmann::json &content);
100   void ParseIteration(const nlohmann::json &content);
101   void ParseInputOutput(const nlohmann::json &content);
102   void ParseKernels(const nlohmann::json &content);
103   void ParseSupportDevice(const nlohmann::json &content);
104   bool ParseEnable(const nlohmann::json &content);
105   void ParseOpDebugMode(const nlohmann::json &content);
106 
107   void JudgeDumpEnabled();
108   void JsonConfigToString();
109 };
110 }  // namespace mindspore
111 #endif  // MINDSPORE_MINDSPORE_CCSRC_DEBUG_DUMP_JSON_PARSER_H_
112