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 3.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /**
  2. * Copyright 2020 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. #include <math.h>
  19. #include <vector>
  20. #include <string>
  21. #include <memory>
  22. #include <tuple>
  23. #include <unordered_map>
  24. #include <mutex>
  25. #include "debug/tensor_load.h"
  26. #include "debug/tensor_data.h"
  27. #include "ir/dtype.h"
  28. namespace mindspore {
  29. class DebugServices {
  30. public:
  31. DebugServices();
  32. DebugServices(const DebugServices &other);
  33. DebugServices &operator=(const DebugServices &other);
  34. ~DebugServices();
  35. typedef struct condition_no_param {
  36. bool enabled = false;
  37. } condition_no_param_t;
  38. typedef struct condition_with_param {
  39. bool enabled = false;
  40. float parameter = 0;
  41. } condition_with_param_t;
  42. typedef struct conditions {
  43. condition_no_param_t inf;
  44. condition_no_param_t neg_inf;
  45. condition_no_param_t nan;
  46. condition_with_param_t max_below;
  47. condition_with_param_t max_above;
  48. condition_with_param_t min_below;
  49. condition_with_param_t min_above;
  50. condition_with_param_t max_minus_min_below;
  51. condition_with_param_t max_minus_min_above;
  52. condition_with_param_t mean_below;
  53. condition_with_param_t mean_above;
  54. condition_with_param_t std_dev_below;
  55. condition_with_param_t std_dev_above;
  56. } conditions_t;
  57. typedef struct watchpoint {
  58. unsigned int id;
  59. conditions_t conditions;
  60. std::vector<std::tuple<std::string, bool>> check_node_list;
  61. } watchpoint_t;
  62. void AddWatchpoint(unsigned int id, unsigned int watch_condition,
  63. const std::vector<std::tuple<std::string, bool>> &check_node_list);
  64. void RemoveWatchpoint(unsigned int id);
  65. void CheckWatchpoints(std::vector<std::string> *name, std::vector<std::string> *slot, std::vector<char *> *data_ptr,
  66. std::vector<unsigned int> *data_size, std::vector<int> *condition,
  67. std::vector<unsigned int> *wacthpoint_id);
  68. void ReadNodesTensors(std::vector<std::string> name, std::vector<std::string> *ret_name,
  69. std::vector<char *> *data_ptr, std::vector<unsigned int> *data_size,
  70. std::vector<TypePtr> *dtype, std::vector<std::vector<int>> *shape);
  71. bool IsWatchPoint(std::string kernel_name, std::unordered_map<unsigned int, watchpoint_t> watchpoint_table);
  72. TensorLoader *tensor_loader() const;
  73. std::unordered_map<unsigned int, watchpoint_t> GetWatchpointTable();
  74. private:
  75. std::mutex lock_;
  76. std::unordered_map<unsigned int, watchpoint_t> watchpoint_table;
  77. TensorLoader *tensor_loader_;
  78. };
  79. } // namespace mindspore
  80. #endif // MINDSPORE_CCSRC_DEBUG_DEBUG_SERVICES_H_