[INFO] Initializing environment for https://gitcode.com/pre-commit/pre-commit-hooks. [WARNING] repo `https://gitcode.com/pre-commit/pre-commit-hooks` uses deprecated stage names (commit, push) which will be removed in a future version. Hint: often `pre-commit autoupdate --repo https://gitcode.com/pre-commit/pre-commit-hooks` will fix this. if it does not -- consider reporting an issue to that repo. [INFO] Initializing environment for https://gitcode.com/pre-commit-clang/mirrors-clang-format. [INFO] Initializing environment for https://gitcode.com/gh_mirrors/ru/ruff-pre-commit. [INFO] Initializing environment for https://gitcode.com/gh_mirrors/co/codespell. [INFO] Installing environment for https://gitcode.com/pre-commit/pre-commit-hooks. [INFO] Once installed this environment will be reused. [INFO] This may take a few minutes... [INFO] Installing environment for https://gitcode.com/pre-commit-clang/mirrors-clang-format. [INFO] Once installed this environment will be reused. [INFO] This may take a few minutes... [INFO] Installing environment for https://gitcode.com/gh_mirrors/ru/ruff-pre-commit. [INFO] Once installed this environment will be reused. [INFO] This may take a few minutes... [INFO] Installing environment for https://gitcode.com/gh_mirrors/co/codespell. [INFO] Once installed this environment will be reused. [INFO] This may take a few minutes... trim trailing whitespace.................................................Passed fix end of files.........................................................Passed check yaml...........................................(no files to check)Skipped check for added large files..............................................Passed check for merge conflicts................................................Passed detect private key.......................................................Passed check json...........................................(no files to check)Skipped clang-format.........................................(no files to check)Skipped ruff check...............................................................Passed ruff format..............................................................Failed - hook id: ruff-format - files were modified by this hook 1 file reformatted codespell................................................................Passed All changes made by hooks: diff --git a/scripts/kernel/binary_script/gen_output_json.py b/scripts/kernel/binary_script/gen_output_json.py index 8341007..d4746fa 100644 --- a/scripts/kernel/binary_script/gen_output_json.py +++ b/scripts/kernel/binary_script/gen_output_json.py @@ -13,6 +13,7 @@ """ gen_output_json.py """ + import argparse import copy import json @@ -24,49 +25,59 @@ from binary_util.util import wr_json from binary_util.util import generate_op_static_key DATA_TYPE_DICT = { - 'float32': 0, - 'float16': 1, - 'int8': 2, - 'int32': 3, - 'uint8': 4, - 'int16': 6, - 'uint16': 7, - 'uint32': 8, - 'int64': 9, - 'uint64': 10, - 'double': 11, - 'float64': 11, - 'bool': 12, - 'complex64': 16, - 'complex128': 17, - 'qint8': 18, - 'qint16': 19, - 'qint32': 20, - 'quint8': 21, - 'quint16': 22, - 'resource': 23, - 'dual': 25, - 'variant': 26, - 'bf16': 27, - 'bfloat16': 27, - 'int4': 29, - 'uint1': 30, - 'int2': 31, - 'uint2': 32 + "float32": 0, + "float16": 1, + "int8": 2, + "int32": 3, + "uint8": 4, + "int16": 6, + "uint16": 7, + "uint32": 8, + "int64": 9, + "uint64": 10, + "double": 11, + "float64": 11, + "bool": 12, + "complex64": 16, + "complex128": 17, + "qint8": 18, + "qint16": 19, + "qint32": 20, + "quint8": 21, + "quint16": 22, + "resource": 23, + "dual": 25, + "variant": 26, + "bf16": 27, + "bfloat16": 27, + "int4": 29, + "uint1": 30, + "int2": 31, + "uint2": 32, } BFLOAT16_SUPPORT_MAP = { "All": ["ascend950", "ascend910b", "ascend910_93", "ascend310b"], "Conv2DBackpropFilter": ["ascend910b", "ascend910_93", "ascend950"], "Conv3DBackpropFilter": ["ascend910b", "ascend910_93", "ascend950"], - "MatMul": ["ascend910b", "ascend910_93", "ascend950"] + "MatMul": ["ascend910b", "ascend910_93", "ascend950"], } OPS_REUSE_BINARY = ["Conv2DBackpropFilter", "Conv3DBackpropFilter"] ReuseBinary = [ # Note: Only define one reuse rule Per number in this list. - {"opp": "SplitV", "new_dtype": "int64", "reuse_dtype": "int32", - "input_args": [2], # the input argument which need replace - "output_args": [], # the output argument which need replace - "support_map": ["ascend950", "ascend910_93", "ascend910b", "ascend910", "ascend310p"]} + { + "opp": "SplitV", + "new_dtype": "int64", + "reuse_dtype": "int32", + "input_args": [2], # the input argument which need replace + "output_args": [], # the output argument which need replace + "support_map": [ + "ascend950", + "ascend910_93", + "ascend910b", + "ascend910", + "ascend310p", + ], + } ] @@ -80,18 +91,24 @@ def generate_operator_json_content(input_json, kernel_output, json_content): op_type = binary_json.get("op_type") for item in binary_json.get("op_list"): opc_json_file_name = item.get("bin_filename") - expect_outputs = [f"{kernel_output}{opc_json_file_name}.json", - f"{kernel_output}{opc_json_file_name}_deterministic.json"] - opc_json_outputs = list(filter(lambda fname: os.path.isfile(fname), expect_outputs)) + expect_outputs = [ + f"{kernel_output}{opc_json_file_name}.json", + f"{kernel_output}{opc_json_file_name}_deterministic.json", + ] + opc_json_outputs = list( + filter(lambda fname: os.path.isfile(fname), expect_outputs) + ) if len(opc_json_outputs) == 0: print(f"[ERROR]the kernel {opc_json_file_name} not generate output json") print(f"[ERROR]the kernel {opc_json_file_name} is {item}") - print(f"ERROR REASON: opc_json_file_name:{kernel_output}{opc_json_file_name}.json generation failed") + print( + f"ERROR REASON: opc_json_file_name:{kernel_output}{opc_json_file_name}.json generation failed" + ) message = ( - "For more detail: please set env:\n" - "export ASCEND_GLOBAL_LOG_LEVEL=0\n" - "export ASCEND_SLOG_PRINT_TO_STDOUT=1\n" - "and run again, then check kernel log in build/binary/${soc_version}/bin/build_logs\n" + "For more detail: please set env:\n" + "export ASCEND_GLOBAL_LOG_LEVEL=0\n" + "export ASCEND_SLOG_PRINT_TO_STDOUT=1\n" + "and run again, then check kernel log in build/binary/${soc_version}/bin/build_logs\n" ) print(message) failed_json_file_name = opc_json_file_name + "_failed" @@ -108,13 +125,25 @@ def generate_operator_json_content(input_json, kernel_output, json_content): one_binary_case_info["binInfo"] = {"jsonFilePath": json_file_path} json_content.get("binList").append(one_binary_case_info) platform_name = json_file_path.split("/")[0] - if ("MatMulV2" in opc_json_file_name - and platform_name in BFLOAT16_SUPPORT_MAP.get("MatMul", BFLOAT16_SUPPORT_MAP.get("All"))): - bf16_reuse_fp16(one_binary_case_info, json_content, input_num=2, output_num=1) - elif (op_type in OPS_REUSE_BINARY - and platform_name in BFLOAT16_SUPPORT_MAP.get(op_type, BFLOAT16_SUPPORT_MAP.get("All"))): - bf16_reuse_fp16(one_binary_case_info, json_content, input_num=3, output_num=1) - binary_dtype_reuse(platform_name, op_type, one_binary_case_info, json_content) + if ( + "MatMulV2" in opc_json_file_name + and platform_name + in BFLOAT16_SUPPORT_MAP.get("MatMul", BFLOAT16_SUPPORT_MAP.get("All")) + ): + bf16_reuse_fp16( + one_binary_case_info, json_content, input_num=2, output_num=1 + ) + elif ( + op_type in OPS_REUSE_BINARY + and platform_name + in BFLOAT16_SUPPORT_MAP.get(op_type, BFLOAT16_SUPPORT_MAP.get("All")) + ): + bf16_reuse_fp16( + one_binary_case_info, json_content, input_num=3, output_num=1 + ) + binary_dtype_reuse( + platform_name, op_type, one_binary_case_info, json_content + ) def bf16_reuse_fp16(src_info, new_info, input_num, output_num): @@ -152,12 +181,16 @@ def binary_dtype_reuse(platform_name, op_type, src_info, new_info) -> None: args_list = args_keys.split("/") args_offset = len(args_list) - _get_offset(args_list) _, f_idx = args_list[args_offset + index].split(",") - args_list[args_offset + index] = f"{DATA_TYPE_DICT[dtype_new]}" + "," + f"{f_idx}" - new_keys.append('/'.join(args_list)) + args_list[args_offset + index] = ( + f"{DATA_TYPE_DICT[dtype_new]}" + "," + f"{f_idx}" + ) + new_keys.append("/".join(args_list)) return new_keys for reuse_info in ReuseBinary: - if reuse_info.get("opp") != op_type or platform_name not in reuse_info.get("support_map"): + if reuse_info.get("opp") != op_type or platform_name not in reuse_info.get( + "support_map" + ): continue new_dtype = reuse_info.get("new_dtype") reuse_dtype = reuse_info.get("reuse_dtype") @@ -169,7 +202,9 @@ def binary_dtype_reuse(platform_name, op_type, src_info, new_info) -> None: for index in input_args: if src_info["inputs"][index]["dtype"] == reuse_dtype: ori_keys = new_support_info.get("simplifiedKey") - new_support_info.update({"simplifiedKey": _update_simplified_key(ori_keys, new_dtype)}) + new_support_info.update( + {"simplifiedKey": _update_simplified_key(ori_keys, new_dtype)} + ) new_support_info["inputs"][index]["dtype"] = new_dtype need_insert_json_block = True for index in output_args: @@ -213,15 +248,11 @@ def main(binary_file, kernel_output, output_json, number): def parse_args(argv): """Command line parameter parsing""" parser = argparse.ArgumentParser() - parser.add_argument('argv', nargs='+') - parser.add_argument('-n', - '--dtype-num', - nargs='?', - type=int, - default=0) + parser.add_argument("argv", nargs="+") + parser.add_argument("-n", "--dtype-num", nargs="?", type=int, default=0) return parser.parse_args(argv) -if __name__ == '__main__': +if __name__ == "__main__": args = parse_args(sys.argv) main(args.argv[1], args.argv[2], args.argv[3], args.dtype_num)