• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2020-2022 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_DATA_DUMP_E_2_E_DUMP_H_
18 #define MINDSPORE_MINDSPORE_CCSRC_DEBUG_DATA_DUMP_E_2_E_DUMP_H_
19 
20 #include <dirent.h>
21 #include <map>
22 #include <memory>
23 #include <string>
24 #include <vector>
25 
26 #include "include/backend/kernel_graph.h"
27 #include "include/backend/device_address.h"
28 #include "include/backend/debug/data_dump/dump_json_parser.h"
29 #include "include/backend/debug/data_dump/dump_utils.h"
30 #ifdef ENABLE_DEBUGGER
31 #include "include/backend/debug/debugger/debugger.h"
32 #endif
33 #include "include/backend/visible.h"
34 
35 #ifndef ENABLE_DEBUGGER
36 class Debugger;
37 #endif
38 namespace mindspore {
39 class BACKEND_EXPORT E2eDump {
40  public:
41   E2eDump() = default;
42   ~E2eDump() = default;
43   static void UpdateIterMindRTDump();
44 
45   static void UpdateIterOldRTDump(const session::KernelGraph *graph);
46 
47   static void DumpRunIter(const KernelGraphPtr &graph_ptr, uint32_t rank_id = 0);
48 
49   static void DumpData(const session::KernelGraph *graph, uint32_t rank_id, const Debugger *debugger = nullptr);
50 
51   static void DumpConstantData(const session::KernelGraph *graph, const std::string &cst_dump_path,
52                                const Debugger *debugger = nullptr);
53 
54   static void DumpConstantData(const session::KernelGraph *graph, uint32_t rank_id, const Debugger *debugger = nullptr);
55 
56   static void DumpParametersData(uint32_t rank_id, const Debugger *debugger);
57 
58   static bool DumpSingleNodeData(const CNodePtr &node, uint32_t graph_id, uint32_t rank_id,
59                                  const Debugger *debugger = nullptr);
60 
61   // Dump data when task error.
62   static void DumpInputImpl(const CNodePtr &node, bool trans_flag, const std::string &dump_path,
63                             std::string *kernel_name, const Debugger *debugger);
64 
65   static void DumpOutputImpl(const CNodePtr &node, bool trans_flag, const std::string &dump_path,
66                              std::string *kernel_name, const Debugger *debugger);
67   // Dump input/output data without additional check, used for exception case only
68   static void DumpInputData(const CNodePtr &node, bool trans_flag, const std::string &dump_path,
69                             std::string *kernel_name);
70   static void DumpOutputData(const CNodePtr &node, bool trans_flag, const std::string &dump_path,
71                              std::string *kernel_name);
72 
73   static bool IsDeviceTargetGPU();
74 
75   static bool IsDeviceTargetAscend();
76 
77   static bool IsMindRTKernelByKernel();
78 
79  private:
80   static void DumpOutput(const session::KernelGraph *graph, const std::string &dump_path, const Debugger *debugger);
81 
82   static void DumpOutputSingleNode(const CNodePtr &node, const std::string &dump_path, const Debugger *debugger);
83 
84   static void DumpInput(const session::KernelGraph *graph, const std::string &dump_path, const Debugger *debugger);
85 
86   static void DumpInputSingleNode(const CNodePtr &node, const std::string &dump_path, const Debugger *debugger);
87 
88   static void DumpParameters(const session::KernelGraph *graph, const std::string &dump_path, const Debugger *debugger);
89 
90   static void DumpArgsSingleNode(const CNodePtr &node, const std::string &dump_path, const Debugger *debugger);
91 
92   static void DumpMemFromTensorLoaderToFile(const Debugger *debugger, const std::string &file_path,
93                                             const std::string &original_kernel_name, size_t slot);
94 
95   static void DumpSingleAnfNode(const AnfNodePtr &anf_node, const size_t output_index, const std::string &dump_path,
96                                 bool trans_flag, const Debugger *debugger);
97 
98   static void DumpSingleParameterNode(const AnfNodePtr &anf_node, const std::string &dump_path, bool trans_flag,
99                                       const Debugger *debugger);
100 
101   inline static unsigned int starting_graph_id = INT32_MAX;
102 };
103 }  // namespace mindspore
104 #endif  // MINDSPORE_MINDSPORE_CCSRC_DEBUG_DATA_DUMP_E_2_E_DUMP_UTIL_H_
105