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