Fix offline dbg shows null for fusion nodes using async dump data

This commit is contained in:
TinaMengtingZhang 2021-11-25 17:26:14 -05:00
parent 6c20f55a51
commit 6a65e02740
1 changed files with 2 additions and 85 deletions

View File

@ -17,15 +17,11 @@ Module to provide conversion capabalities from .timestamp async dump files to .n
It's an internal module for debugger backend but not exposed to users.
"""
import os
import glob
import stat
import sys
from pathlib import Path
from importlib import import_module
from collections import namedtuple
import numpy as np
class ConvertToolLoader:
"""
@ -119,7 +115,7 @@ def parse_args(file_list, output_path):
args_dict = dict()
args_dict['dump_version'] = '2.0'
args_dict['format'] = 'NCHW'
args_dict['output_file_type'] = 'npy'
args_dict['output_file_type'] = 'msnpy'
args_dict['dump_path'] = output_path
args_dict['output_path'] = output_path
args_dict['file_list'] = file_list
@ -170,50 +166,13 @@ class AsyncDumpConverter:
convert.check_arguments_valid()
# 2. convert format for dump data
ret_code = self.handle_multi_process(convert, self.files_to_convert)
self._rename_generated_npy_files()
if ret_code != self.convert_tool.compare_none_error:
if os.path.exists(self.failed_file_path):
self.convert_failed_tensors()
self.convert_tool.log.print_info_log('An error has occurred while converting format.')
finally:
# clean up sys.path no matter conversion is successful or not to avoid pollution
self.convert_tool.reset_system_path()
self.convert_tool.log.print_info_log('Finish to convert async dump files.')
def convert_failed_tensors(self):
"""
Convert the failed tensor recorded in the failed txt file.
"""
self.convert_tool.log.print_info_log(
'Start to convert failed tensors recorded in ' + self.failed_file_path + '.')
with open(self.failed_file_path) as failed_lines:
for failed_line in failed_lines:
try:
failed_line_list = failed_line.rstrip().split(',')
self.convert_one_failed_tensor(failed_line_list)
except (ValueError, OSError, AttributeError, self.convert_tool.compare_exception) as err:
self.convert_tool.log.print_error_log(
'Failed to convert ' + failed_line + ' to Host format: ' + str(err))
def convert_one_failed_tensor(self, failed_tensor):
"""
Convert failed operator one by one.
"""
if len(failed_tensor) <= 1:
raise ValueError(
"Invalid tensor info in convert_failed_file_list.txt")
file_path = failed_tensor[0]
type_index = failed_tensor[1:]
op_data = self.convert_tool.utils.parse_dump_file(
file_path, self.args.dump_version)
for type_index_item in type_index:
tensor_type, index = type_index_item.split(':')
index = int(index)
tensor = getattr(op_data, tensor_type)[index]
dump_data_array = self.convert_tool.utils.deserialize_dump_data_to_array(tensor)
array = dump_data_array.reshape(tensor.shape.dim)
out_path = self._generate_path(file_path, tensor_type, index, tensor.format)
self._save_tensor_to_npy_file(out_path, array)
def handle_multi_process(self, convert_obj, files):
"""
Convert async format files to npy in a multithreaded manner.
@ -281,45 +240,3 @@ class AsyncDumpConverter:
if ret_bf != self.convert_tool.compare_none_error:
return_code = ret_bf
return return_code
@staticmethod
def _save_tensor_to_npy_file(out_path, dump_data_array):
"""
Save tensor file into npy format.
"""
np.save(out_path, dump_data_array)
os.chmod(out_path, stat.S_IRUSR)
def _generate_path(self, file_path, tensor_type, idx, tensor_format):
"""
Generate path and filename to the target npy files
"""
file_name = os.path.basename(file_path)
name_splits = file_name.split('.')
name_splits[1] = name_splits[1].split('_')[-1]
file_name_no_scope = '.'.join(name_splits)
out_file_name = "%s.%s.%d.%s.npy" % (
file_name_no_scope,
tensor_type,
idx,
self.convert_tool.common.get_format_string(tensor_format)
)
return os.path.join(self.output_path, out_file_name)
def _rename_generated_npy_files(self):
"""
In order to follow dump naming convention, rename npy files generated by CANN conversion tool.
"""
target_file_list = []
for in_file in self.files_to_convert:
target_file_list.extend(glob.glob(in_file + "*.npy"))
for target_file in target_file_list:
old_filename = os.path.basename(target_file)
name_splits = old_filename.split('.')
name_splits[1] = name_splits[1].split('_')[-1]
name_splits[-2] = self.args.format
new_file_name = '.'.join(name_splits)
out_path = os.path.join(self.output_path, new_file_name)
os.rename(target_file, out_path)
os.chmod(out_path, stat.S_IRUSR)
self.convert_tool.log.print_info_log("Rename file " + target_file + " to " + out_path)