forked from mindspore-Ecosystem/mindspore
!28821 Adapt to the old data format of aicpu
Merge pull request !28821 from zangqx/zangqx_5
This commit is contained in:
commit
15bd3af3e3
|
@ -144,7 +144,10 @@ class DataPreProcessParser:
|
||||||
|
|
||||||
with open(self._source_file_name, 'rb') as ai_cpu_data:
|
with open(self._source_file_name, 'rb') as ai_cpu_data:
|
||||||
content = ai_cpu_data.read()
|
content = ai_cpu_data.read()
|
||||||
ai_cpu_total_time_summary, result_list = self.parser_binary_file(content)
|
if content[0:2].hex().upper() == "5A5A":
|
||||||
|
ai_cpu_total_time_summary, result_list = self.parser_binary_file(content)
|
||||||
|
else:
|
||||||
|
ai_cpu_total_time_summary, result_list = self.parser_txt_file(content)
|
||||||
|
|
||||||
os.chmod(self._source_file_name, stat.S_IREAD)
|
os.chmod(self._source_file_name, stat.S_IREAD)
|
||||||
|
|
||||||
|
@ -188,6 +191,39 @@ class DataPreProcessParser:
|
||||||
|
|
||||||
return ai_cpu_total_time_summary, result_list
|
return ai_cpu_total_time_summary, result_list
|
||||||
|
|
||||||
|
def parser_txt_file(self, content):
|
||||||
|
"""Parse txt format file."""
|
||||||
|
ai_cpu_str = str(content.replace(b'\n\x00', b' ___ ').replace(b'\x00', b' ___ '))[2:-1]
|
||||||
|
ai_cpu_lines = ai_cpu_str.split(" ___ ")
|
||||||
|
result_list = list()
|
||||||
|
ai_cpu_total_time_summary = 0
|
||||||
|
# Node serial number.
|
||||||
|
serial_number = 1
|
||||||
|
for i in range(len(ai_cpu_lines) - 1):
|
||||||
|
node_line = ai_cpu_lines[i]
|
||||||
|
thread_line = ai_cpu_lines[i + 1]
|
||||||
|
if "Node" in node_line and "Thread" in thread_line:
|
||||||
|
# Get the node data from node_line
|
||||||
|
result = self._get_kernel_result(
|
||||||
|
serial_number,
|
||||||
|
node_line.split(','),
|
||||||
|
thread_line.split(',')
|
||||||
|
)
|
||||||
|
|
||||||
|
if result is None:
|
||||||
|
continue
|
||||||
|
|
||||||
|
result_list.append(result)
|
||||||
|
# Calculate the total time.
|
||||||
|
total_time = result[2]
|
||||||
|
ai_cpu_total_time_summary += total_time
|
||||||
|
# Increase node serial number.
|
||||||
|
serial_number += 1
|
||||||
|
elif "Node" in node_line and "Thread" not in thread_line:
|
||||||
|
node_type_name = node_line.split(',')[0].split(':')[-1]
|
||||||
|
logger.warning("The node type:%s cannot find thread data", node_type_name)
|
||||||
|
return ai_cpu_total_time_summary, result_list
|
||||||
|
|
||||||
def query_aicpu_data(self):
|
def query_aicpu_data(self):
|
||||||
"""
|
"""
|
||||||
Get execution time of AI CPU operator.
|
Get execution time of AI CPU operator.
|
||||||
|
|
Binary file not shown.
|
@ -0,0 +1,5 @@
|
||||||
|
serial_number node_type_name total_time(ms) dispatch_time(ms) execution_time(ms) run_start run_end
|
||||||
|
1 InitData 1.567 0.1 0.129 2298200409.0 2298200538.0
|
||||||
|
2 GetNext 0.989 0.087 0.048 2302769932.0 2302769980.0
|
||||||
|
3 TruncatedNormal 1.566 0.105 0.129 4098200409.0 4098200538.0
|
||||||
|
AI CPU Total Time(ms): 4.122000
|
|
@ -24,6 +24,15 @@ class TestAicpuParser:
|
||||||
"""Test the class of Aicpu Parser."""
|
"""Test the class of Aicpu Parser."""
|
||||||
def setup_class(self):
|
def setup_class(self):
|
||||||
"""Initialization before test case execution."""
|
"""Initialization before test case execution."""
|
||||||
|
|
||||||
|
|
||||||
|
def teardown_method(self) -> None:
|
||||||
|
"""Clear output file."""
|
||||||
|
if os.path.exists(self.output_path):
|
||||||
|
shutil.rmtree(self.output_path)
|
||||||
|
|
||||||
|
def test_aicpu_parser_binary(self):
|
||||||
|
"""Test the class of aicpu binary data Parser."""
|
||||||
self.profiling_dir = os.path.realpath(os.path.join(os.path.dirname(__file__),
|
self.profiling_dir = os.path.realpath(os.path.join(os.path.dirname(__file__),
|
||||||
'../../../data/profiler_data/'
|
'../../../data/profiler_data/'
|
||||||
'JOB_AICPU/data'))
|
'JOB_AICPU/data'))
|
||||||
|
@ -40,13 +49,6 @@ class TestAicpuParser:
|
||||||
"DropoutGenMask-op280"
|
"DropoutGenMask-op280"
|
||||||
}
|
}
|
||||||
|
|
||||||
def teardown_method(self) -> None:
|
|
||||||
"""Clear output file."""
|
|
||||||
if os.path.exists(self.output_path):
|
|
||||||
shutil.rmtree(self.output_path)
|
|
||||||
|
|
||||||
def test_aicpu_parser(self):
|
|
||||||
"""Test the class of Aicpu Parser."""
|
|
||||||
data = DataPreProcessParser(self.profiling_dir, self.output_file, self.op_task_dict)
|
data = DataPreProcessParser(self.profiling_dir, self.output_file, self.op_task_dict)
|
||||||
data.execute()
|
data.execute()
|
||||||
with open(self.expect_file, 'r') as fp:
|
with open(self.expect_file, 'r') as fp:
|
||||||
|
@ -54,3 +56,23 @@ class TestAicpuParser:
|
||||||
with open(self.output_file, 'r') as fp:
|
with open(self.output_file, 'r') as fp:
|
||||||
result = fp.read()
|
result = fp.read()
|
||||||
assert expect_result == result
|
assert expect_result == result
|
||||||
|
|
||||||
|
def test_aicpu_parser_txt(self):
|
||||||
|
"""Test the class of aicpu txt data Parser."""
|
||||||
|
self.profiling_dir = os.path.realpath(os.path.join(os.path.dirname(__file__),
|
||||||
|
'../../../data/profiler_data/'
|
||||||
|
'JOB_AICPU/data_txt'))
|
||||||
|
self.expect_dir = os.path.realpath(os.path.join(os.path.dirname(__file__),
|
||||||
|
'../../../data/profiler_data/'
|
||||||
|
'JOB_AICPU/expect_txt'))
|
||||||
|
self.output_path = tempfile.mkdtemp(prefix='output_data_preprocess_aicpu_')
|
||||||
|
self.output_file = os.path.join(self.output_path, 'output_data_preprocess_aicpu_0.txt')
|
||||||
|
self.expect_file = os.path.join(self.expect_dir, 'output_data_preprocess_aicpu_0.txt')
|
||||||
|
|
||||||
|
data = DataPreProcessParser(self.profiling_dir, self.output_file, None)
|
||||||
|
data.execute()
|
||||||
|
with open(self.expect_file, 'r') as fp:
|
||||||
|
expect_result = fp.read()
|
||||||
|
with open(self.output_file, 'r') as fp:
|
||||||
|
result = fp.read()
|
||||||
|
assert expect_result == result
|
||||||
|
|
Loading…
Reference in New Issue