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_manager.h 1.8 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**
  2. * Copyright 2019 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_DEVICE_ASCEND_PROFILING_PROFILING_MANAGER_H_
  17. #define MINDSPORE_CCSRC_DEVICE_ASCEND_PROFILING_PROFILING_MANAGER_H_
  18. #include <map>
  19. #include <cstring>
  20. #include <string>
  21. #include <memory>
  22. #include <nlohmann/json.hpp>
  23. #include "utils/contract.h"
  24. #include "utils/context/ms_context.h"
  25. using std::map;
  26. using std::string;
  27. namespace mindspore {
  28. namespace device {
  29. namespace ascend {
  30. class ProfilingEngineImpl;
  31. class ProfilingManager {
  32. public:
  33. static ProfilingManager &GetInstance();
  34. uint64_t GetJobId() const;
  35. bool ReportProfilingData(const map<uint32_t, string> &op_taskId_map) const;
  36. bool StartupProfiling(uint32_t device_id);
  37. bool StopProfiling();
  38. inline bool IsProfiling() const {
  39. auto context = MsContext::GetInstance();
  40. MS_EXCEPTION_IF_NULL(context);
  41. return context->enable_profiling();
  42. }
  43. protected:
  44. ProfilingManager();
  45. ~ProfilingManager() { prof_handle_ = nullptr; }
  46. private:
  47. bool ProfStartUp(NotNull<nlohmann::json *> json);
  48. std::shared_ptr<ProfilingEngineImpl> engine_0_;
  49. uint32_t device_id_;
  50. void *prof_handle_;
  51. };
  52. } // namespace ascend
  53. } // namespace device
  54. } // namespace mindspore
  55. #endif // MINDSPORE_CCSRC_DEVICE_ASCEND_PROFILING_PROFILING_MANAGER_H_