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.

debug_services.h 26 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  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_CCSRC_DEBUG_DEBUG_SERVICES_H_
  17. #define MINDSPORE_CCSRC_DEBUG_DEBUG_SERVICES_H_
  18. #ifndef OFFLINE_DBG_MODE
  19. #define ONLINE_DBG_MODE
  20. #endif
  21. #ifdef OFFLINE_DBG_MODE
  22. #include "base/float16.h"
  23. #endif
  24. #include <math.h>
  25. #include <vector>
  26. #include <future>
  27. #include <string>
  28. #include <memory>
  29. #include <tuple>
  30. #include <unordered_map>
  31. #include <set>
  32. #include <mutex>
  33. #include <map>
  34. #include <limits>
  35. #include <sstream>
  36. #include <utility>
  37. #include "debug/tensor_load.h"
  38. #include "debug/tensor_data.h"
  39. namespace mindspore {
  40. class DebugServices {
  41. public:
  42. DebugServices();
  43. DebugServices(const DebugServices &other);
  44. DebugServices &operator=(const DebugServices &other);
  45. ~DebugServices() = default;
  46. enum File_ATTR_MATCH { START_POS = 0, END_POS = 1, STR_POS = 2 };
  47. enum CONDITION_TYPE {
  48. HAS_NAN,
  49. HAS_INF,
  50. IS_OVERFLOW,
  51. MAX_GT,
  52. MAX_LT,
  53. MIN_GT,
  54. MIN_LT,
  55. MAX_MIN_GT,
  56. MAX_MIN_LT,
  57. MEAN_GT,
  58. MEAN_LT,
  59. SD_GT,
  60. SD_LT,
  61. GENERAL_OVERFLOW,
  62. INIT,
  63. TOO_LARGE,
  64. TOO_SMALL,
  65. ALL_ZERO,
  66. CHANGE_TOO_LARGE,
  67. CHANGE_TOO_SMALL,
  68. NOT_CHANGED,
  69. RANGE
  70. };
  71. struct condition_t {
  72. CONDITION_TYPE type;
  73. float parameter = 0;
  74. };
  75. struct parameter_t {
  76. std::string name;
  77. bool disabled;
  78. double_t value;
  79. bool hit;
  80. double_t actual_value;
  81. void Evaluate(double_t actualValue, std::string inequality_type) {
  82. if (std::isnan(actualValue)) {
  83. return;
  84. }
  85. actual_value = actualValue;
  86. // if cannot extract inequality type from watchpoint
  87. // try extract from parameter name
  88. if (inequality_type.empty()) {
  89. auto pos = name.find_last_of('_');
  90. if (pos != std::string::npos) {
  91. inequality_type = name.substr(pos + 1);
  92. }
  93. }
  94. std::map<std::string, bool> condition_check{{"gt", actual_value > value},
  95. {"lt", actual_value < value},
  96. {"ge", actual_value >= value},
  97. {"le", actual_value <= value}};
  98. hit = condition_check[inequality_type];
  99. }
  100. };
  101. struct MappedFiles {
  102. MappedFiles(std::vector<std::string> bin_files, std::map<std::string, std::vector<std::string>> npy_files)
  103. : bin_files(bin_files), npy_files(npy_files) {}
  104. MappedFiles() = default;
  105. std::vector<std::string> bin_files;
  106. // key is op_name and value is the vector of matched npy files to that op name.
  107. std::map<std::string, std::vector<std::string>> npy_files;
  108. };
  109. struct DumpFileAttr {
  110. std::string file_path;
  111. // name_to_match is the op_name extracted from file name.
  112. std::string name_to_match;
  113. std::string time_stamp;
  114. uint64_t slot = 0;
  115. bool is_output{false};
  116. };
  117. struct ProtoDump {
  118. bool operator==(ProtoDump obj) {
  119. return (origin_node_name == obj.origin_node_name && dump_name == obj.dump_name && is_output == obj.is_output);
  120. }
  121. // name_to_match is the op_name between first and second dot in file_name
  122. std::string origin_node_name;
  123. std::string dump_name;
  124. bool is_output{false};
  125. };
  126. typedef std::vector<std::vector<int>> partitioned_numbers;
  127. typedef std::vector<std::vector<std::string>> partitioned_names;
  128. typedef std::vector<std::vector<std::vector<parameter_t>>> partitioned_parameters;
  129. typedef std::vector<std::vector<int32_t>> partitioned_error_code;
  130. typedef std::vector<std::vector<unsigned int>> partitioned_id;
  131. typedef std::set<std::string> NPYFilePool;
  132. typedef std::map<std::string, std::vector<std::tuple<std::string, std::string>>> DirMap;
  133. // key is dump dir path and value is vector of bin files and map of npy files.
  134. typedef std::map<std::string, DebugServices::MappedFiles> DumpFileMap;
  135. typedef std::map<std::string, std::vector<DebugServices::DumpFileAttr>> ProcessedNPYFiles;
  136. // bool shows if preprocess was successful, and DumpFileMap is preprocessed file result
  137. typedef std::tuple<bool, DumpFileMap> AsyncPreProcessResult;
  138. struct watchpoint_t {
  139. unsigned int id;
  140. condition_t condition;
  141. std::vector<std::tuple<std::string, bool>> check_node_list;
  142. std::vector<std::tuple<std::string, std::vector<uint32_t>>> check_node_device_list;
  143. std::vector<std::tuple<std::string, std::vector<uint32_t>>> check_node_graph_list;
  144. std::vector<parameter_t> parameter_list;
  145. size_t location = 0;
  146. std::string FindQualifiedTensorName(const std::string &tensor_name, unsigned const int &tensor_device_id,
  147. unsigned const int &tensor_root_graph_id) const {
  148. size_t indx = 0;
  149. for (auto check_node : check_node_list) {
  150. std::string w_name = std::get<0>(check_node);
  151. bool w_type = std::get<1>(check_node);
  152. auto found = w_name.find_last_of('/');
  153. bool check_tensor_name = found != std::string::npos && w_name.substr(found + 1) == tensor_name;
  154. bool check_node_name =
  155. (w_type && (tensor_name == w_name || w_name == "*")) || (!w_type && tensor_name == w_name);
  156. if (check_tensor_name || check_node_name) {
  157. // online debugger only support single card
  158. if (check_node_device_list.empty()) {
  159. return w_name;
  160. }
  161. auto device_vec = std::get<1>(check_node_device_list[indx]);
  162. auto root_graph_vec = std::get<1>(check_node_graph_list[indx]);
  163. auto iter1 = std::find(device_vec.begin(), device_vec.end(), tensor_device_id);
  164. auto iter2 = std::find(root_graph_vec.begin(), root_graph_vec.end(), tensor_root_graph_id);
  165. if (iter1 != device_vec.end() && iter2 != root_graph_vec.end()) {
  166. return w_name;
  167. }
  168. }
  169. indx++;
  170. }
  171. return {};
  172. }
  173. bool is_gt_wp() const {
  174. return condition.type == MAX_GT || condition.type == MIN_GT || condition.type == MEAN_GT ||
  175. condition.type == SD_GT || condition.type == MAX_MIN_GT;
  176. }
  177. bool is_lt_wp() const {
  178. return condition.type == MAX_LT || condition.type == MIN_LT || condition.type == MEAN_LT ||
  179. condition.type == SD_LT || condition.type == MAX_MIN_LT;
  180. }
  181. // mean or sd related condition set
  182. bool mean_sd_enabled() const {
  183. return condition.type == MEAN_LT || condition.type == MEAN_GT || condition.type == SD_LT ||
  184. condition.type == SD_GT || (condition.type == TOO_LARGE && !parameter_list[3].disabled) ||
  185. (condition.type == TOO_SMALL && !parameter_list[3].disabled);
  186. }
  187. bool abs_mean_enabled() const {
  188. return (condition.type == TOO_LARGE && !parameter_list[0].disabled) ||
  189. (condition.type == TOO_SMALL && !parameter_list[0].disabled);
  190. }
  191. bool tensor_update_ratio_mean_enabled() const {
  192. return condition.type == CHANGE_TOO_LARGE || condition.type == CHANGE_TOO_SMALL;
  193. }
  194. bool allclose_enabled() const { return condition.type == NOT_CHANGED; }
  195. bool range_enabled() const {
  196. return condition.type == RANGE && (!parameter_list[0].disabled || !parameter_list[1].disabled);
  197. }
  198. bool change_condition() const {
  199. return condition.type == CHANGE_TOO_LARGE || condition.type == CHANGE_TOO_SMALL || condition.type == NOT_CHANGED;
  200. }
  201. };
  202. struct TensorBase {
  203. TensorBase(uint64_t data_size, int dtype, const std::vector<int64_t> &shape)
  204. : data_size(data_size), dtype(dtype), shape(shape) {}
  205. TensorBase() = default;
  206. uint64_t data_size = 0;
  207. int dtype = 0;
  208. std::vector<int64_t> shape;
  209. };
  210. struct TensorStat {
  211. TensorStat(uint64_t data_size, int dtype, const std::vector<int64_t> &shape, bool is_bool, double max_value,
  212. double min_value, double avg_value, uint64_t count, uint64_t neg_zero_count, uint64_t pos_zero_count,
  213. uint64_t nan_count, uint64_t neg_inf_count, uint64_t pos_inf_count, uint64_t zero_count)
  214. : data_size(data_size),
  215. dtype(dtype),
  216. shape(shape),
  217. is_bool(is_bool),
  218. max_value(max_value),
  219. min_value(min_value),
  220. avg_value(avg_value),
  221. count(count),
  222. neg_zero_count(neg_zero_count),
  223. pos_zero_count(pos_zero_count),
  224. nan_count(nan_count),
  225. neg_inf_count(neg_inf_count),
  226. pos_inf_count(pos_inf_count),
  227. zero_count(zero_count) {}
  228. TensorStat() = default;
  229. uint64_t data_size = 0;
  230. int dtype = 0;
  231. std::vector<int64_t> shape;
  232. bool is_bool = false;
  233. double max_value = std::numeric_limits<double>::lowest();
  234. double min_value = std::numeric_limits<double>::max();
  235. double avg_value = 0.0;
  236. uint64_t count = 0;
  237. uint64_t neg_zero_count = 0;
  238. uint64_t pos_zero_count = 0;
  239. uint64_t nan_count = 0;
  240. uint64_t neg_inf_count = 0;
  241. uint64_t pos_inf_count = 0;
  242. uint64_t zero_count = 0;
  243. };
  244. static TensorStat GetTensorStatistics(const std::shared_ptr<TensorData> &tensor);
  245. void AddWatchpoint(
  246. int id, int watch_condition, float parameter, const std::vector<std::tuple<std::string, bool>> &check_node_list,
  247. const std::vector<parameter_t> &parameter_list,
  248. const std::vector<std::tuple<std::string, std::vector<uint32_t>>> *check_node_device_list = nullptr,
  249. const std::vector<std::tuple<std::string, std::vector<uint32_t>>> *check_node_graph_list = nullptr);
  250. void RemoveWatchpoint(unsigned int id);
  251. #ifdef OFFLINE_DBG_MODE
  252. void CheckOutofMemoryandNoValue(
  253. const bool no_mem_to_read, const bool error_on_no_value, const std::vector<watchpoint_t> watchpoints_to_check,
  254. const int chunk_id, partitioned_names *const chunk_names, partitioned_names *const chunk_slots,
  255. partitioned_numbers *const chunk_conditions, partitioned_id *const chunk_watchpoint_id,
  256. partitioned_parameters *const chunk_parameters, partitioned_error_code *const chunk_error_codes,
  257. partitioned_numbers *const chunk_exec_orders, partitioned_names *const chunk_time_stamp,
  258. partitioned_id *const chunk_device_id, partitioned_id *const chunk_root_graph_id,
  259. std::vector<unsigned int> *const device_id, std::vector<unsigned int> *const root_graph_id, const int exec_order,
  260. const std::string time_stamp, const std::string &qualified_tensor_name, const std::string &tensor_slot,
  261. const unsigned int device_id_val, const unsigned int root_graph_id_val,
  262. const std::vector<parameter_t> &parameter_list);
  263. #endif
  264. const void *PreparePrevTensor(uint64_t *prev_num_elements, const std::string &tensor_name);
  265. void CheckHistoryErrorCode(int *error_code, bool history_not_found);
  266. void CheckWatchpointsForTensor(partitioned_names *chunk_names, partitioned_names *chunk_slots,
  267. partitioned_numbers *chunk_conditions, partitioned_id *const chunk_watchpoint_id,
  268. partitioned_parameters *chunk_parameters, partitioned_error_code *chunk_error_codes,
  269. const std::vector<std::string> &op_overflows,
  270. ProcessedNPYFiles *const processed_npy_files, partitioned_numbers *chunk_exec_orders,
  271. std::vector<std::shared_ptr<TensorData>> *tensor_list, int begin, int end,
  272. int chunk_id, const bool init_dbg_suspend, const bool step_end, const bool recheck,
  273. partitioned_id *chunk_device_id, partitioned_id *chunk_root_graph_id,
  274. std::vector<uint64_t> *chunk_tensor_byte_size, partitioned_names *chunk_time_stamp,
  275. std::vector<unsigned int> *device_id, std::vector<unsigned int> *root_graph_id,
  276. bool error_on_no_value = false);
  277. void AddOpOverflowOpNames(const std::string &overflow_bin_path, std::vector<std::string> *op_names);
  278. void CheckWatchpoints(std::vector<std::string> *name, std::vector<std::string> *slot, std::vector<int> *condition,
  279. std::vector<unsigned int> *const watchpoint_id,
  280. std::vector<std::vector<parameter_t>> *parameters, std::vector<int32_t> *error_code,
  281. const std::vector<std::string> &op_overflows, ProcessedNPYFiles *const processed_npy_files,
  282. std::vector<std::shared_ptr<TensorData>> *tensor_list, bool init_dbg_suspend,
  283. const bool step_end, const bool recheck, std::vector<unsigned int> *device_id = nullptr,
  284. std::vector<unsigned int> *root_graph_id = nullptr, bool error_on_no_value = false);
  285. void SortWatchpointsInfo(std::vector<std::future<void>> *tensor_future_vec, std::vector<int> *exec_order,
  286. std::vector<std::string> *time_stamps, uint64_t *tensor_list_byte_size,
  287. std::vector<std::string> *name, std::vector<std::string> *slot, std::vector<int> *condition,
  288. std::vector<unsigned int> *const watchpoint_id,
  289. std::vector<std::vector<parameter_t>> *parameters, std::vector<int32_t> *error_codes,
  290. partitioned_names *chunk_names, partitioned_names *chunk_slots,
  291. partitioned_numbers *chunk_conditions, partitioned_id *chunk_watchpoint_id,
  292. partitioned_parameters *chunk_parameters, partitioned_error_code *chunk_error_codes,
  293. partitioned_numbers *chunk_exec_orders, partitioned_names *chunk_time_stamp,
  294. std::vector<uint64_t> *chunk_tensor_byte_size, partitioned_id *chunk_device_id,
  295. partitioned_id *chunk_root_graph_id, std::vector<unsigned int> *device_id,
  296. std::vector<unsigned int> *root_graph_id);
  297. #ifdef OFFLINE_DBG_MODE
  298. void SetTensorToNotInUse(const std::shared_ptr<TensorData> &tensor, const void *previous_tensor_ptr);
  299. #endif
  300. void AddWatchPointsToCheck(bool init_dbg_suspend, bool step_end, bool recheck,
  301. const std::shared_ptr<TensorData> &tensor, bool *previous_iter_tensor_needed,
  302. std::string *qualified_tensor_name, std::vector<watchpoint_t> *watchpoints_to_check);
  303. void SetCheckWatchpointsResult(const int chunk_id, partitioned_names *chunk_names, partitioned_names *chunk_slots,
  304. partitioned_numbers *chunk_conditions, partitioned_id *chunk_watchpoint_id,
  305. partitioned_parameters *chunk_parameters, partitioned_error_code *chunk_error_codes,
  306. partitioned_numbers *chunk_exec_orders, partitioned_names *chunk_time_stamp,
  307. partitioned_id *chunk_device_id, partitioned_id *chunk_root_graph_id,
  308. std::vector<unsigned int> *device_id, std::vector<unsigned int> *root_graph_id,
  309. const int exec_order, const std::string time_stamp,
  310. const std::string &qualified_tensor_name, const std::string &tensor_slot,
  311. const watchpoint_t &wp, const unsigned int device_id_val,
  312. const unsigned int root_graph_id_val, const std::vector<parameter_t> &parameter_list,
  313. const int32_t error_code);
  314. #ifdef OFFLINE_DBG_MODE
  315. void AddToTensorData(const std::string &backend_name, const std::string &time_stamp, const std::size_t slot,
  316. const unsigned int iteration, const unsigned int device_id, const unsigned int root_graph_id,
  317. const bool is_output, const std::size_t data_size, const std::string &type_name,
  318. const std::vector<int64_t> &shape, std::vector<char> *buffer,
  319. std::vector<std::shared_ptr<TensorData>> *const result_list);
  320. void SetPrefixToCheck(std::string *const prefix_dump_file_name, std::string *const slot_string_to_check,
  321. std::string *const dump_style_kernel_name, size_t slot, bool is_output);
  322. void ReadDumpedTensor(std::vector<std::string> backend_name, std::vector<size_t> slot,
  323. std::vector<unsigned int> device_id, std::vector<unsigned int> iteration,
  324. std::vector<unsigned int> root_graph_id, const std::vector<bool> &is_output,
  325. ProcessedNPYFiles *const processed_npy_files,
  326. std::vector<std::shared_ptr<TensorData>> *const result_list, bool *no_mem_to_read = nullptr);
  327. void ProcessTensorDataSync(const std::vector<ProtoDump> &proto_to_dump, const std::string &specific_dump_dir,
  328. ProcessedNPYFiles processed_npy_files, unsigned int iteration, unsigned int device_id,
  329. unsigned int root_graph_id, std::vector<std::shared_ptr<TensorData>> *const tensor_list,
  330. bool error_on_no_value = false);
  331. void ReadFileAndAddToTensor(const bool found, const std::vector<std::string> &matched_paths,
  332. const std::vector<std::string> &matched_time_stamps, const std::string &backend_name,
  333. const unsigned int device_id, const unsigned int root_graph_id, bool is_output,
  334. size_t slot, bool *no_mem_to_read, unsigned int iteration,
  335. std::vector<std::shared_ptr<TensorData>> *result_list);
  336. void ReadDumpedTensorSync(const std::string &prefix_dump_file_name, const std::string &specific_dump_dir,
  337. const std::string &backend_name, size_t slot, unsigned int device_id,
  338. unsigned int iteration, unsigned int root_graph_id, const bool &is_output,
  339. std::vector<std::shared_ptr<TensorData>> *result_list, bool *no_mem_to_read);
  340. void ReadDumpedTensorUtils(const std::string &specific_dump_dir, const std::string &prefix_dump_to_check,
  341. const std::string &backend_name, size_t slot, unsigned int device_id,
  342. unsigned int iteration, unsigned int root_graph_id, bool is_output,
  343. const ProcessedNPYFiles &processed_npy_files,
  344. std::vector<std::shared_ptr<TensorData>> *result_list, bool *no_mem_to_read);
  345. std::vector<std::shared_ptr<TensorData>> ReadNeededDumpedTensors(unsigned int iteration,
  346. ProcessedNPYFiles *const processed_npy_files,
  347. bool error_on_no_value = false);
  348. const void *GetPrevTensor(const std::shared_ptr<TensorData> &tensor, bool previous_iter_tensor_needed,
  349. uint64_t *prev_num_elements, bool *history_not_found);
  350. void ReadTensorFromNpy(const std::string &tensor_name, const std::string &file_name, std::string *const tensor_type,
  351. std::size_t *const size, std::vector<int64_t> *const shape,
  352. std::vector<char> **const data_buffer, bool *no_mem_to_read);
  353. AsyncPreProcessResult PreProcessDumpDirAsync(const std::string &specific_dump_dir);
  354. DebugServices::NPYFilePool PreProcessDumpDirSync(const std::string &specific_dump_dir);
  355. ProcessedNPYFiles ProcessNPYFilePool(const NPYFilePool &npy_file_pool);
  356. void ConvertToHostFormat(const DirMap &dir_to_files_map, NPYFilePool *const result_list);
  357. void ProcessConvertToHostFormat(const std::vector<std::string> &files_after_convert_in_dir,
  358. const std::string &dump_key, NPYFilePool *const result_list);
  359. void ConvertReadTensors(std::vector<std::string> backend_name, std::vector<size_t> slot,
  360. std::vector<unsigned int> device_id, std::vector<unsigned int> iteration,
  361. std::vector<unsigned int> root_graph_id, NPYFilePool *const result_list);
  362. void ConvertWatchPointNodes(const DumpFileMap &dump_dir_mapped_files, const std::vector<ProtoDump> &proto_dump,
  363. const std::string &specific_dump_dir, NPYFilePool *const result_list);
  364. void ProcessConvertList(const DumpFileMap &dump_dir_mapped_files, const std::string &prefix_dump_file_name,
  365. const std::string &specific_dump_dir, DirMap *dir_to_files_map,
  366. NPYFilePool *const result_list);
  367. void GetTensorDataInfoAsync(const std::vector<ProtoDump> &proto_dump, const std::string &specific_dump_dir,
  368. uint32_t iteration, uint32_t device_id, uint32_t root_graph_id,
  369. const ProcessedNPYFiles &processed_async_files,
  370. std::vector<std::shared_ptr<TensorData>> *const tensor_list);
  371. void SetGraphsHistory();
  372. std::vector<uint32_t> GetDumpRankIdList();
  373. void CheckDumpGraphIdList(std::vector<uint32_t> rank_id_list);
  374. void ReadGraphsHistory(uint32_t rank_id, uint32_t root_graph_id);
  375. std::map<std::tuple<uint32_t, uint32_t>, std::vector<std::tuple<std::string, bool>>> GetAllWpNodes();
  376. void ReadGraphRunIter(std::string file_path, std::tuple<uint32_t, uint32_t> rank_and_graph);
  377. std::string IterationString(unsigned int iteration);
  378. #endif
  379. void ReadNodesTensors(const std::vector<std::string> &name, std::vector<std::string> *ret_name,
  380. std::vector<const char *> *data_ptr, std::vector<ssize_t> *data_size,
  381. std::vector<unsigned int> *dtype, std::vector<std::vector<int64_t>> *const shape);
  382. void SearchNodesTensors(const std::vector<std::string> &name,
  383. std::vector<std::tuple<std::string, std::shared_ptr<TensorData>>> *result_list);
  384. #ifdef ONLINE_DBG_MODE
  385. bool IsWatchPoint(const std::string &kernel_name, const CNodePtr &kernel = nullptr) const;
  386. bool IsWatchPointNodeInput(const std::string &w_name, const CNodePtr &kernel) const;
  387. bool CompareCurrentRootGraph(uint32_t id);
  388. #endif
  389. std::vector<std::shared_ptr<TensorData>> GetTensor() const;
  390. std::shared_ptr<TensorData> GetTensor(const std::string &tensor_name) const;
  391. void AddAnalyzedTensorToCache(const bool recheck, const unsigned int id, const std::string &tensor_name);
  392. void EmptyCurrentTensor();
  393. #ifdef ONLINE_DBG_MODE
  394. bool DumpTensorToFile(const std::string &tensor_name, bool trans_flag, const std::string &filepath,
  395. const std::string &host_fmt, const std::vector<int64_t> &host_shape, TypeId host_type,
  396. TypeId device_type, const std::string &addr_format, size_t slot) const;
  397. #endif
  398. bool LoadNewTensor(const std::shared_ptr<TensorData> &tensor, bool keep_prev);
  399. uint32_t GetPrevIteration(const std::shared_ptr<TensorData> &tensor);
  400. void ResetLoadedTensors();
  401. #ifdef ONLINE_DBG_MODE
  402. std::vector<std::shared_ptr<TensorData>> GetNodeTensor(const CNodePtr &kernel);
  403. #endif
  404. // Find if any operation overflow happened on a particular node name
  405. bool CheckOpOverflow(std::string node_name_to_find, unsigned int device_id = 0, unsigned int root_graph_id = 0,
  406. unsigned int iteration = 0);
  407. std::string RemoveKernelGraphPrefix(std::string node_name_to_find);
  408. bool GetTaskIdStreamId(std::string file_name, std::string overflow_file_prefix, uint64_t *task_id,
  409. uint64_t *stream_id);
  410. bool GetAttrsFromFilename(const std::string &file_name, std::string *const node_name, uint64_t *task_id,
  411. uint64_t *stream_id);
  412. std::string RealPath(const std::string &input_path);
  413. uint64_t BytestoUInt64(const std::vector<char> &buffer);
  414. bool TensorExistsInCurrent(const std::string &tensor_name);
  415. void MoveTensorCurrentToPrev(const std::string &tensor_name);
  416. void AppendToCacheEvictQueue(const std::string &tensor_name);
  417. void SetNetName(std::string net_name);
  418. std::string GetNetName();
  419. void SetDumpDir(std::string dump_dir);
  420. std::string GetDumpDir();
  421. void SetSyncMode(bool is_sync_mode);
  422. bool GetSyncMode();
  423. void SetMemLimit(uint64_t max_mem_size);
  424. void CheckWatchpointProgress(size_t tensor_list_size);
  425. size_t GetProcessedTensorCount() { return tensor_processed_count_; }
  426. private:
  427. std::mutex lock_;
  428. std::mutex wp_lock_;
  429. std::mutex overflow_wp_lock_;
  430. // to keep track of watchpoints that have been checked already for a tensor in current step
  431. std::unordered_map<std::string, std::set<int32_t>> wp_id_cache_;
  432. std::unordered_map<unsigned int, watchpoint_t> watchpoint_table_;
  433. // key is the iteration path, value is vector of op_names which have overflowed
  434. std::unordered_map<std::string, std::vector<std::string>> overflow_ops_;
  435. std::string net_name_;
  436. std::string dump_dir_;
  437. // DumpFileMap for each specific dump dir (including rank, graph_id and iteration)
  438. DumpFileMap dump_dir_mapped_files_;
  439. // store history of graphs that have been run (rank_id, graph_id)
  440. std::map<std::tuple<uint32_t, uint32_t>, std::vector<uint32_t>> graphs_run_history_;
  441. bool is_sync_mode_{false};
  442. // processed tensors in checkwatchpoint function
  443. std::atomic<size_t> tensor_processed_count_{0};
  444. bool wp_progress_enabled_{false};
  445. std::unique_ptr<std::thread> wp_progress_thread_;
  446. std::shared_ptr<TensorLoader> tensor_loader_;
  447. };
  448. } // namespace mindspore
  449. #endif // MINDSPORE_CCSRC_DEBUG_DEBUG_SERVICES_H_