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.

profiling.h 2.2 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * Copyright 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_PROFILER_DEVICE_PROFILING_H
  17. #define MINDSPORE_CCSRC_PROFILER_DEVICE_PROFILING_H
  18. #include <algorithm>
  19. #include <cstdio>
  20. #include <map>
  21. #include <memory>
  22. #include <mutex>
  23. #include <string>
  24. #include <unordered_map>
  25. #include <utility>
  26. #include <vector>
  27. namespace mindspore {
  28. namespace profiler {
  29. struct StartDuration {
  30. uint64_t start_timestamp = 0l;
  31. float duration = 0l;
  32. };
  33. struct OpInfo {
  34. std::string op_name;
  35. float cupti_api_call_time = 0l;
  36. float cupti_activity_time = 0l;
  37. float op_host_cost_time = 0;
  38. int op_kernel_api_count = 0;
  39. int op_kernel_count = 0;
  40. int op_count = 0;
  41. std::vector<StartDuration> start_duration;
  42. void *stream;
  43. uint32_t pid;
  44. };
  45. class Profiler {
  46. public:
  47. Profiler() = default;
  48. virtual ~Profiler() = default;
  49. virtual void Init(const std::string &profileDataPath) = 0;
  50. virtual void Stop() = 0;
  51. virtual void StepProfilingEnable(const bool enable_flag) = 0;
  52. virtual void OpDataProducerEnd() = 0;
  53. bool GetEnableFlag() const { return enable_flag_; }
  54. std::string ProfileDataPath() const { return profile_data_path_; }
  55. protected:
  56. void SetRunTimeData(const std::string &op_name, const float time_elapsed);
  57. void SetRunTimeData(const std::string &op_name, const uint64_t start, const float duration);
  58. uint64_t GetHostMonoTimeStamp();
  59. virtual void SaveProfileData() = 0;
  60. virtual void ClearInst() = 0;
  61. bool enable_flag_ = false;
  62. std::string profile_data_path_;
  63. std::unordered_map<std::string, OpInfo> op_info_map_;
  64. };
  65. } // namespace profiler
  66. } // namespace mindspore
  67. #endif // MINDSPORE_CCSRC_PROFILER_DEVICE_PROFILING_H