profiler.op_analyse() verify the parameters.

This commit is contained in:
liuchuting 2022-05-07 18:10:45 +08:00
parent 009bf45528
commit 96587bd71e
3 changed files with 31 additions and 8 deletions

View File

@ -432,7 +432,7 @@ class GpuFrameWorkParser:
framework_file_path = validate_and_normalize_path(framework_file_path)
with open(framework_file_path, 'r') as f_obj:
framework_info = f_obj.readlines()
for line_info in framework_info[1:]:
for line_info in framework_info:
line_info = line_info.strip(' ').strip('\n').split(';')
input_shape = ':'.join(line_info[2:]).split(':')[1::2]
# line_info[0]: op_type, line_info[1]: op_name, line_info[2]: input_shape;
@ -500,7 +500,22 @@ class GpuFrameWorkParser:
def get_device_target_filename(self):
"""Get device target filename."""
for file_name in os.listdir(self._output_path):
gpu_framework_file = f'gpu_framework_{self._dev_id}.txt'
cpu_framework_file = f'cpu_framework_{self._dev_id}.txt'
gpu_op_detail_file = f'gpu_op_detail_info_{self._dev_id}.csv'
cpu_op_detail_file = f'cpu_op_detail_info_{self._dev_id}.csv'
all_file = os.listdir(self._output_path)
if not all_file:
logger.error(f'No profiler file is found in the path <%s>. '
f'Check whether the profiler path is correct.' % self._output_path)
if gpu_op_detail_file in all_file and gpu_framework_file not in all_file:
logger.error(f'The output file <%s> is not found.' % gpu_framework_file)
if cpu_op_detail_file in all_file and cpu_framework_file not in all_file:
logger.error(f'The output file <%s> is not found.' % cpu_framework_file)
if gpu_op_detail_file not in all_file and cpu_op_detail_file not in all_file:
logger.error(f'The profiling data of this card which device_id is equal to {self._dev_id} does not exist.'
f' Check whether device_id is correct.')
for file_name in all_file:
if file_name.endswith(f'detail_info_{self._dev_id}.csv'):
self.detail_info_dir.append(file_name)
if file_name.endswith(f'framework_{self._dev_id}.txt'):

View File

@ -158,18 +158,21 @@ class Profiler:
if self.start_profile:
self.start()
def op_analyse(self, op_name, **kwargs):
def op_analyse(self, op_name, device_id=None):
"""
Profiler users can use this interface to obtain operator performance data.
Args:
op_name (str, list): The primitive operator name.
device_id (int): ID of the target device, operator performance data of a specified card is analyzed using
the device_id parameter. Default: 0.
device_id (int): ID of the target device, users can use device_id parameter to specify which card operator
performance data to parse, Default: 0.
Raises:
TypeError: If the op_name parameter type is incorrect,
Profiler cannot parse the generated operator performance data.
TypeError: If the device_id parameter type is incorrect,
Profiler cannot parse the generated operator performance data.
RunTimeError: If MindSpore runs on Ascend, this interface cannot be used.
Supported Platforms:
``GPU`` ``CPU``
@ -196,8 +199,11 @@ class Profiler:
... profiler = Profiler(output_path="my_profiler_path")
... profiler.op_analyse(op_name="Conv2D")
"""
device_id = kwargs.pop("device_id", None)
if self._device_target == 'ascend':
raise RuntimeError("The Interface 'Profiler.op_analyse()' is not supported on Ascend currently.")
if device_id and not isinstance(device_id, int):
raise TypeError(f"For 'Profiler.op_analyse()', the parameter device_id must be int, "
f"but got type {type(device_id)}")
self._dev_id = self._dev_id if device_id is None else device_id
if self._dev_id is None:
self._dev_id = 0

View File

@ -187,6 +187,7 @@ class TestProfiler:
model.train(1, ds_train, dataset_sink_mode=True)
profiler.analyse()
profiler.op_analyse(op_name="Conv2D")
def _check_gpu_profiling_file(self):
op_detail_file = self.profiler_path + f'gpu_op_detail_info_{self.device_id}.csv'
@ -195,9 +196,10 @@ class TestProfiler:
timeline_file = self.profiler_path + f'gpu_timeline_display_{self.device_id}.json'
getnext_file = self.profiler_path + f'minddata_getnext_profiling_{self.device_id}.txt'
pipeline_file = self.profiler_path + f'minddata_pipeline_raw_{self.device_id}.csv'
framework_file = self.profiler_path + f'gpu_framework_{self.device_id}.txt'
gpu_profiler_files = (op_detail_file, op_type_file, activity_file,
timeline_file, getnext_file, pipeline_file)
timeline_file, getnext_file, pipeline_file, framework_file)
for file in gpu_profiler_files:
assert os.path.isfile(file)