!21963 fix a profiling bug to improve performance

Merge pull request !21963 from lvchangquan/master
This commit is contained in:
i-robot 2021-08-24 03:31:24 +00:00 committed by Gitee
commit d2a42f131f
2 changed files with 12 additions and 1 deletions

View File

@ -22,10 +22,20 @@
#include <string> #include <string>
#include "utils/profile.h" #include "utils/profile.h"
#include "utils/utils.h" #include "utils/utils.h"
#include "utils/ms_context.h"
namespace mindspore { namespace mindspore {
namespace device { namespace device {
PynativeProfiler::PynativeProfiler() {
auto ms_context = MsContext::GetInstance();
MS_EXCEPTION_IF_NULL(ms_context);
enable_profiler_flag = ms_context->get_param<bool>(MS_CTX_ENABLE_PROFILING);
}
void PynativeProfiler::SingleOpProfilingData() { void PynativeProfiler::SingleOpProfilingData() {
if (!enable_profiler_flag) {
return;
}
static std::ofstream of("pynative_forward_profiling_data.csv"); static std::ofstream of("pynative_forward_profiling_data.csv");
of.setf(std::ios::fixed, std::ios::floatfield); of.setf(std::ios::fixed, std::ios::floatfield);
if (real_run_op_index_ == 1) { if (real_run_op_index_ == 1) {

View File

@ -41,10 +41,11 @@ class PynativeProfiler {
void SingleOpProfilingData(); void SingleOpProfilingData();
private: private:
PynativeProfiler() = default; PynativeProfiler();
~PynativeProfiler() = default; ~PynativeProfiler() = default;
PynativeProfiler(const PynativeProfiler &) = delete; PynativeProfiler(const PynativeProfiler &) = delete;
PynativeProfiler &operator=(const PynativeProfiler &) = delete; PynativeProfiler &operator=(const PynativeProfiler &) = delete;
bool enable_profiler_flag = false;
int real_run_op_index_ = 0; int real_run_op_index_ = 0;
std::string real_run_op_name_; std::string real_run_op_name_;
std::pair<double, double> real_run_op_start_time_end_time_; std::pair<double, double> real_run_op_start_time_end_time_;