1 /** 2 * Copyright 2020-2021 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 <stdlib.h> 22 #include <map> 23 #include <string> 24 25 #include "backend/session/kernel_graph.h" 26 #include "runtime/device/device_address.h" 27 #include "debug/data_dump/dump_json_parser.h" 28 #include "debug/data_dump/dump_utils.h" 29 30 #ifndef ENABLE_DEBUGGER 31 class Debugger; 32 #endif 33 namespace mindspore { 34 class E2eDump { 35 public: 36 E2eDump() = default; 37 ~E2eDump() = default; 38 static void DumpSetup(const session::KernelGraph *graph); 39 40 static void UpdateIterGPUDump(); 41 42 static void DumpData(const session::KernelGraph *graph, uint32_t rank_id, const Debugger *debugger = nullptr); 43 44 static bool DumpParametersAndConstData(const session::KernelGraph *graph, uint32_t rank_id, const Debugger *debugger); 45 46 static bool DumpSingleNodeData(const CNodePtr &node, uint32_t graph_id, uint32_t rank_id, 47 const Debugger *debugger = nullptr); 48 49 static bool isDatasetGraph(const session::KernelGraph *graph); 50 51 // Dump data when task error. 52 static void DumpInputImpl(const CNodePtr &node, bool trans_flag, const std::string &dump_path, 53 std::string *kernel_name, const Debugger *debugger); 54 55 static void DumpOutputImpl(const CNodePtr &node, bool trans_flag, const std::string &dump_path, 56 std::string *kernel_name, const Debugger *debugger); 57 58 static bool DumpDirExists(const std::string &dump_path); 59 60 private: 61 static void DumpOutput(const session::KernelGraph *graph, const std::string &dump_path, const Debugger *debugger); 62 63 static void DumpOutputSingleNode(const CNodePtr &node, const std::string &dump_path, const Debugger *debugger); 64 65 static void DumpInput(const session::KernelGraph *graph, const std::string &dump_path, const Debugger *debugger); 66 67 static void DumpInputSingleNode(const CNodePtr &node, const std::string &dump_path, const Debugger *debugger); 68 69 static void DumpParametersAndConst(const session::KernelGraph *graph, const std::string &dump_path, 70 const Debugger *debugger); 71 72 static void DumpGPUMemToFile(const std::string &file_path, const std::string &original_kernel_name, 73 const device::DeviceAddress &addr, const ShapeVector &int_shapes, 74 const TypeId &host_type, const TypeId &device_type, bool trans_flag, size_t slot, 75 const Debugger *debugger); 76 static bool IsDeviceTargetGPU(); 77 static void DumpSingleAnfNode(const AnfNodePtr &anf_node, const size_t output_index, const std::string &dump_path, 78 bool trans_flag, std::map<std::string, size_t> *const_map, const Debugger *debugger); 79 80 static void UpdateIterDumpSetup(const session::KernelGraph *graph, bool sink_mode); 81 82 inline static unsigned int starting_graph_id = INT32_MAX; 83 }; 84 } // namespace mindspore 85 #endif // MINDSPORE_MINDSPORE_CCSRC_DEBUG_DATA_DUMP_E_2_E_DUMP_UTIL_H_ 86