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.1 kB

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