From f8918115bba95d219a9cebe0807c7f1c777aa36f Mon Sep 17 00:00:00 2001 From: gzhcv Date: Tue, 30 Mar 2021 20:34:54 +0800 Subject: [PATCH] Remove the constraint that gpu profiler initialized in specific position --- .../kernel_compiler/gpu/data/dataset_profiling.cc | 10 +++++----- mindspore/profiler/parser/integrator.py | 3 +-- mindspore/profiler/profiling.py | 6 ++---- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/data/dataset_profiling.cc b/mindspore/ccsrc/backend/kernel_compiler/gpu/data/dataset_profiling.cc index eb9124d3dcc..13f2961b21e 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/data/dataset_profiling.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/data/dataset_profiling.cc @@ -22,17 +22,17 @@ #include "utils/log_adapter.h" #include "utils/ms_utils.h" #include "utils/utils.h" +#include "utils/ms_context.h" namespace mindspore { namespace kernel { GetNextProfiling::GetNextProfiling(const std::string &path) : profiling_path_(path) {} void GetNextProfiling::GetDeviceId() { - // If DEVICE_ID is not set,defult value is 0 - device_id_ = common::GetEnv("DEVICE_ID"); - if (device_id_.empty()) { - device_id_ = "0"; - } + auto context_ptr = MsContext::GetInstance(); + MS_EXCEPTION_IF_NULL(context_ptr); + auto device_id = context_ptr->get_param(MS_CTX_DEVICE_ID); + device_id_ = std::to_string(device_id); } void GetNextProfiling::Init() { diff --git a/mindspore/profiler/parser/integrator.py b/mindspore/profiler/parser/integrator.py index 8d9b709862b..3de7d7e65be 100644 --- a/mindspore/profiler/parser/integrator.py +++ b/mindspore/profiler/parser/integrator.py @@ -986,12 +986,11 @@ class CpuTimelineGenerator(GpuTimelineGenerator): """Get timeline data from file.""" timeline_list = self.load_cpu_op_data() factor_ns_to_ms = 1e6 - factor_us_to_ms = 1e3 start_time = 2 duration = 3 for idx, time_item in enumerate(timeline_list): time_item[start_time] = float(time_item[start_time]) / factor_ns_to_ms - time_item[duration] = float(time_item[duration]) / factor_us_to_ms + time_item[duration] = float(time_item[duration]) timeline_list[idx] = time_item return timeline_list diff --git a/mindspore/profiler/profiling.py b/mindspore/profiler/profiling.py index d4b0501a149..06c3b351dd6 100644 --- a/mindspore/profiler/profiling.py +++ b/mindspore/profiler/profiling.py @@ -278,11 +278,9 @@ class Profiler: def _gpu_analyse(self): """Collect and analyse gpu performance data""" - if GlobalComm.WORLD_COMM_GROUP == "nccl_world_group" and self._dev_id != str(get_rank()): + self._dev_id = context.get_context("device_id") + if GlobalComm.WORLD_COMM_GROUP == "nccl_world_group": self._dev_id = str(get_rank()) - logger.error('Please check the Profiler object initialized after mindspore.context.set_auto_parallel_' - 'context() and mindspore.communication.management.init(). Profiler should be initialized' - ' after these code.') self._gpu_profiler.stop() timeline_generator = self._generate_timeline()