• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_RUNTIME_DEVICE_ASCEND_PROFILING_PROFILING_MANAGER_H_
17 #define MINDSPORE_CCSRC_RUNTIME_DEVICE_ASCEND_PROFILING_PROFILING_MANAGER_H_
18 
19 #include <map>
20 #include <cstring>
21 #include <string>
22 #include <memory>
23 #include <nlohmann/json.hpp>
24 #include "utils/contract.h"
25 #include "utils/ms_context.h"
26 #include "toolchain/prof_callback.h"
27 #include "toolchain/prof_acl_api.h"
28 #include "toolchain/slog.h"
29 #include "runtime/base.h"
30 #include "profiler/device/profiling.h"
31 
32 using std::map;
33 using std::string;
34 
35 namespace mindspore {
36 namespace device {
37 namespace ascend {
38 struct MsprofCallback {
39   MsprofCtrlCallback msprofCtrlCallback;
40   MsprofSetDeviceCallback msprofSetDeviceCallback;
41   MsprofReporterCallback msprofReporterCallback;
42 };
43 
44 enum ProfCommandHandleType {
45   kProfCommandhandleInit = 0,
46   kProfCommandhandleStart,
47   kProfCommandhandleStop,
48   kProfCommandhandleFinalize,
49   kProfCommandhandleModelSubscribe,
50   kProfCommandhandleModelUnsubscribe
51 };
52 
53 class ProfilingManager {
54  public:
55   static ProfilingManager &GetInstance();
56   uint64_t GetJobId() const;
57   bool ProfRegisterCtrlCallback() const;
58   bool StartupProfiling(uint32_t device_id);
59   bool StopProfiling() const;
60 
IsProfiling()61   inline bool IsProfiling() const {
62     auto profiler_manager = profiler::ProfilerManager::GetInstance();
63     MS_EXCEPTION_IF_NULL(profiler_manager);
64     return profiler_manager->GetProfilingEnableFlag();
65   }
66   Status PluginInit() const;
67   void PluginUnInit() const;
68   Status CallMsprofReport(NotNull<ReporterData *> reporter_data) const;
GetMsprofCallback()69   const struct MsprofCallback &GetMsprofCallback() { return prof_cb_; }
SetMsprofCtrlCallback(MsprofCtrlCallback func)70   void SetMsprofCtrlCallback(MsprofCtrlCallback func) { prof_cb_.msprofCtrlCallback = func; }
SetMsprofReporterCallback(MsprofReporterCallback func)71   void SetMsprofReporterCallback(MsprofReporterCallback func) { prof_cb_.msprofReporterCallback = func; }
SetMsprofSetDeviceCallback(MsprofSetDeviceCallback func)72   void SetMsprofSetDeviceCallback(MsprofSetDeviceCallback func) { prof_cb_.msprofSetDeviceCallback = func; }
73   Status GetProfConf(NotNull<MsprofGeOptions *> prof);
SetHcclEnabledBefProfilingEnabled()74   void SetHcclEnabledBefProfilingEnabled() { hccl_enabled_bef_profiling_enabled_ = true; }
75 
76  protected:
77   ProfilingManager();
~ProfilingManager()78   ~ProfilingManager() {}
79 
80  private:
81   bool ProfStartUp(NotNull<MsprofGeOptions *> prof_conf) const;
82   uint32_t device_id_;
83   MsprofCallback prof_cb_;
84   bool hccl_enabled_bef_profiling_enabled_;
85   bool has_started_;
86 };
87 
88 Status ProfCommandHandle(ProfCommandHandleType type);
89 rtError_t CtrlCallbackHandle(uint32_t rt_type, void *data, uint32_t /*len*/);
90 Status ProfCtrlSwitchHandle(void *data);
91 }  // namespace ascend
92 }  // namespace device
93 }  // namespace mindspore
94 
95 #endif  // MINDSPORE_CCSRC_RUNTIME_DEVICE_ASCEND_PROFILING_PROFILING_MANAGER_H_
96