• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 #ifndef MINDSPORE_CCSRC_PIPELINE_PYNATIVE_PYNATIVE_PROFILING_H_
18 #define MINDSPORE_CCSRC_PIPELINE_PYNATIVE_PYNATIVE_PROFILING_H_
19 
20 #include <memory>
21 #include <string>
22 #include <vector>
23 #include <utility>
24 #include <unordered_map>
25 
26 namespace mindspore {
27 class PynativeProfiler {
28  public:
29   PynativeProfiler(const PynativeProfiler &) = delete;
30   PynativeProfiler &operator=(const PynativeProfiler &) = delete;
31   static void SetEnableProfilingFlag();
32   static void Reset();
33   static void SetDeviceOpNameAndLaunchTimePoint(
34     const std::pair<std::string, std::pair<double, double>> &name_start_end);
35   static void SetDeviceOpNameAndLaunchCostTime(const std::pair<std::string, double> &name_time);
36   static void ExportDeviceInfoToFile();
37   static void ExportDeviceInfoToScreen();
38   static void SetStageTimePoint(const std::string &stage_name, const std::string &flag);
39   static double SetStageTimePointWithReturn(const std::string &stage_name, const std::string &flag);
40   static void SetStageStatTime(const std::string &stage_name, double cost_time);
41   static void ExportStageTimePointToFile();
42   static void ExportStageTimePointToScreen();
43   static void ExportStageStatTimeToFile();
44   static void ExportStageStatTimeToScreen();
45 
46  private:
47   PynativeProfiler() = default;
48   ~PynativeProfiler() = default;
49   inline static bool enable_profiler_flag_ = false;
50   inline static std::vector<std::pair<std::string, std::pair<std::string, double>>> stage_time_point_vec_;
51   inline static std::vector<std::pair<std::string, double>> stage_stat_time_vec_;
52   inline static std::vector<std::pair<std::string, std::pair<double, double>>> op_name_launch_time_point_vec_;
53   inline static std::vector<std::pair<std::string, double>> op_name_launch_time_vec_;
54 };
55 }  // namespace mindspore
56 
57 #endif  // MINDSPORE_CCSRC_PIPELINE_PYNATIVE_PYNATIVE_PROFILING_H_
58