You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

e2e_dump.h 5.5 kB

4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. #ifndef MINDSPORE_MINDSPORE_CCSRC_DEBUG_DATA_DUMP_E_2_E_DUMP_H_
  17. #define MINDSPORE_MINDSPORE_CCSRC_DEBUG_DATA_DUMP_E_2_E_DUMP_H_
  18. #include <dirent.h>
  19. #include <map>
  20. #include <string>
  21. #include <vector>
  22. #include "backend/common/session/kernel_graph.h"
  23. #include "runtime/device/device_address.h"
  24. #include "debug/data_dump/dump_json_parser.h"
  25. #include "debug/data_dump/dump_utils.h"
  26. #ifdef ENABLE_D
  27. #include "proto/dump_data.pb.h"
  28. #endif
  29. using mindspore::kernel::KernelLaunchInfo;
  30. #ifndef ENABLE_DEBUGGER
  31. class Debugger;
  32. #endif
  33. namespace mindspore {
  34. struct dump_data_t {
  35. std::string dump_file_path;
  36. char *data_ptr;
  37. mindspore::TypeId data_type;
  38. std::string format;
  39. ShapeVector device_shape;
  40. ShapeVector host_shape;
  41. size_t data_size;
  42. int32_t sub_format;
  43. std::string in_out_str;
  44. uint32_t slot;
  45. };
  46. class E2eDump {
  47. public:
  48. E2eDump() = default;
  49. ~E2eDump() = default;
  50. static void UpdateIterMindRTDump();
  51. static void UpdateIterOldRTDump(const session::KernelGraph *graph);
  52. static void DumpRunIter(const KernelGraphPtr &graph_ptr, uint32_t rank_id = 0);
  53. static void DumpData(const session::KernelGraph *graph, uint32_t rank_id, const Debugger *debugger = nullptr);
  54. static void DumpConstantData(const session::KernelGraph *graph, const std::string &cst_dump_path,
  55. const Debugger *debugger = nullptr);
  56. static void DumpConstantData(const session::KernelGraph *graph, uint32_t rank_id, const Debugger *debugger = nullptr);
  57. static void DumpParametersData(uint32_t rank_id, const Debugger *debugger);
  58. static bool DumpSingleNodeData(const CNodePtr &node, uint32_t graph_id, uint32_t rank_id,
  59. const Debugger *debugger = nullptr, const KernelLaunchInfo *launch_info = nullptr);
  60. // Dump data when task error.
  61. static void DumpInputImpl(const CNodePtr &node, bool trans_flag, const std::string &dump_path,
  62. std::string *kernel_name, const Debugger *debugger,
  63. const KernelLaunchInfo *launch_info = nullptr);
  64. static void DumpOutputImpl(const CNodePtr &node, bool trans_flag, const std::string &dump_path,
  65. std::string *kernel_name, const Debugger *debugger);
  66. // Dump input/output data without additional check, used for exception case only
  67. static void DumpInputData(const CNodePtr &node, bool trans_flag, const std::string &dump_path,
  68. std::string *kernel_name);
  69. static void DumpOutputData(const CNodePtr &node, bool trans_flag, const std::string &dump_path,
  70. std::string *kernel_name);
  71. #ifdef ENABLE_D
  72. static void DumpTensorToFile(const std::string &dump_path, const debugger::dump::DumpData &dump_data, char *data_ptr);
  73. static void DumpOpDebugToFile(const std::string &dump_path, const debugger::dump::DumpData &dump_data,
  74. char *data_ptr);
  75. #endif
  76. private:
  77. static void DumpOutput(const session::KernelGraph *graph, const std::string &dump_path, const Debugger *debugger);
  78. static void DumpOutputSingleNode(const CNodePtr &node, const std::string &dump_path, const Debugger *debugger);
  79. static void DumpInput(const session::KernelGraph *graph, const std::string &dump_path, const Debugger *debugger);
  80. static void DumpInputSingleNode(const CNodePtr &node, const std::string &dump_path, const Debugger *debugger,
  81. const KernelLaunchInfo *launch_info = nullptr);
  82. static void DumpParameters(const session::KernelGraph *graph, const std::string &dump_path, const Debugger *debugger);
  83. static void DumpGPUMemToFile(const std::string &file_path, const std::string &original_kernel_name,
  84. const device::DeviceAddress &addr, const ShapeVector &int_shapes,
  85. const TypeId &host_type, const TypeId &device_type, bool trans_flag, size_t slot,
  86. const Debugger *debugger);
  87. static bool IsDeviceTargetGPU();
  88. static void DumpSingleAnfNode(const AnfNodePtr &anf_node, const size_t output_index, const std::string &dump_path,
  89. bool trans_flag, const Debugger *debugger);
  90. static void DumpSingleParameterNode(const AnfNodePtr &anf_node, const std::string &dump_path, bool trans_flag,
  91. const Debugger *debugger);
  92. #ifdef ENABLE_D
  93. static nlohmann::json ParseOverflowInfo(char *data_ptr);
  94. static bool ConvertFormatForTensorAndDump(const dump_data_t &dump_tensor_info);
  95. static void ConvertFormatForTensors(const std::vector<dump_data_t> &dump_tensor_vec, uint32_t start_idx,
  96. uint32_t end_idx);
  97. #endif
  98. inline static unsigned int starting_graph_id = INT32_MAX;
  99. };
  100. } // namespace mindspore
  101. #endif // MINDSPORE_MINDSPORE_CCSRC_DEBUG_DATA_DUMP_E_2_E_DUMP_UTIL_H_