已合并
Specify kernel compilation #577
zhanglong99创建于 2月25日
Specify kernel compilation #577
已合并
共 13 个文件变更+296-57
| @@ -42,6 +42,7 @@ class BinParamBuilder(opdesc_parser.OpDesc): | |||
| 42 | self.tiling_keys = set() | 42 | self.tiling_keys = set() |
| 43 | self.op_debug_config = '' | 43 | self.op_debug_config = '' |
| 44 | self.op_super_config = [] | 44 | self.op_super_config = [] |
| 45 | + self.kernel_template_input = '' | ||
| 45 | 46 | ||
| 46 | def set_soc_version(self: any, soc: str): | 47 | def set_soc_version(self: any, soc: str): |
| 47 | self.soc = soc | 48 | self.soc = soc |
| @@ -52,6 +53,10 @@ class BinParamBuilder(opdesc_parser.OpDesc): | |||
| 52 | def set_tiling_key(self: any, tiling_key_info: Set): | 53 | def set_tiling_key(self: any, tiling_key_info: Set): |
| 53 | if tiling_key_info: | 54 | if tiling_key_info: |
| 54 | self.tiling_keys.update(tiling_key_info) | 55 | self.tiling_keys.update(tiling_key_info) |
| 56 | + | ||
| 57 | + def set_kernel_template_input(self: any, kernel_template_input_info: str): | ||
| 58 | + if kernel_template_input_info: | ||
| 59 | + self.kernel_template_input = kernel_template_input_info | ||
| 55 | 60 | ||
| 56 | def set_op_debug_config(self: any, op_debug_config: str): | 61 | def set_op_debug_config(self: any, op_debug_config: str): |
| 57 | if op_debug_config: | 62 | if op_debug_config: |
| @@ -481,6 +486,10 @@ grep -q \"None of the given tiling keys are in the supported list\"; then\n" | |||
| 481 | op_super_config_str = ' '.join([str(_key) for _key in list(self.op_super_config)]) | 486 | op_super_config_str = ' '.join([str(_key) for _key in list(self.op_super_config)]) |
| 482 | build_cmd_var += f' {op_super_config_str}' | 487 | build_cmd_var += f' {op_super_config_str}' |
| 483 | 488 | ||
| 489 | + if self.kernel_template_input: | ||
| 490 | + kernel_template_input_str = self.kernel_template_input | ||
| 491 | + build_cmd_var += f' --kernel-template-input={kernel_template_input_str}' | ||
| 492 | + | ||
| 484 | build_cmd_var += ")\n" | 493 | build_cmd_var += ")\n" |
| 485 | build_cmd_var += "\n" | 494 | build_cmd_var += "\n" |
| 486 | 495 | ||
| @@ -524,11 +533,12 @@ def parse_op_debug_config(opc_config_file: str, soc: str) -> Dict: | |||
| 524 | op_debug_config = defaultdict(set) | 533 | op_debug_config = defaultdict(set) |
| 525 | kernel_json_file = defaultdict(dict) | 534 | kernel_json_file = defaultdict(dict) |
| 526 | input_param_file = defaultdict(dict) | 535 | input_param_file = defaultdict(dict) |
| 536 | + kernel_template_input_info = defaultdict(dict) | ||
| 527 | if not opc_config_file: | 537 | if not opc_config_file: |
| 528 | - return tiling_key_info, op_debug_config, kernel_json_file, input_param_file | 538 | + return tiling_key_info, op_debug_config, kernel_json_file, input_param_file, kernel_template_input_info |
| 529 | 539 | ||
| 530 | if not os.path.exists(opc_config_file): | 540 | if not os.path.exists(opc_config_file): |
| 531 | - return tiling_key_info, op_debug_config, kernel_json_file, input_param_file | 541 | + return tiling_key_info, op_debug_config, kernel_json_file, input_param_file, kernel_template_input_info |
| 532 | 542 | ||
| 533 | with open(opc_config_file, 'r') as file: | 543 | with open(opc_config_file, 'r') as file: |
| 534 | contents = file.readlines() | 544 | contents = file.readlines() |
| @@ -582,7 +592,15 @@ def parse_op_debug_config(opc_config_file: str, soc: str) -> Dict: | |||
| 582 | else: | 592 | else: |
| 583 | json_file = "" | 593 | json_file = "" |
| 584 | input_param_file[op_type] = json_file | 594 | input_param_file[op_type] = json_file |
| 585 | - return tiling_key_info, op_debug_config, kernel_json_file, input_param_file | 595 | + if "--kernel-template-input" in options: |
| 596 | + first_index = options.find('=') | ||
| 597 | + if first_index != -1: | ||
| 598 | + kernel_template_input = options[first_index + 1:] | ||
| 599 | + else: | ||
| 600 | + kernel_template_input = "" | ||
| 601 | + kernel_template_input_info[op_type] = kernel_template_input | ||
| 602 | + | ||
| 603 | + return tiling_key_info, op_debug_config, kernel_json_file, input_param_file, kernel_template_input_info | ||
| 586 | 604 | ||
| 587 | 605 | ||
| 588 | def gen_option_config(debug_config, super_config, op_debug_config): | 606 | def gen_option_config(debug_config, super_config, op_debug_config): |
| @@ -607,7 +625,8 @@ def gen_bin_param_file(cfgfile: str, out_dir: str, soc: str, | |||
| 607 | debug_config = defaultdict(set) | 625 | debug_config = defaultdict(set) |
| 608 | super_config = defaultdict(set) | 626 | super_config = defaultdict(set) |
| 609 | op_descs = opdesc_parser.get_op_desc(cfgfile, [], [], BinParamBuilder, ops) | 627 | op_descs = opdesc_parser.get_op_desc(cfgfile, [], [], BinParamBuilder, ops) |
| 610 | - tiling_key_info, op_debug_config, kernel_json_file, input_param_file = parse_op_debug_config(opc_config_file, soc) | 628 | + tiling_key_info, op_debug_config, kernel_json_file, \ |
| 629 | + input_param_file, kernel_template_input_info = parse_op_debug_config(opc_config_file, soc) | ||
| 611 | gen_option_config(debug_config, super_config, op_debug_config) | 630 | gen_option_config(debug_config, super_config, op_debug_config) |
| 612 | 631 | ||
| 613 | auto_gen_path_dir = os.path.dirname(cfgfile) | 632 | auto_gen_path_dir = os.path.dirname(cfgfile) |
| @@ -631,6 +650,10 @@ def gen_bin_param_file(cfgfile: str, out_dir: str, soc: str, | |||
| 631 | op_desc.json_file = kernel_json_file[op_desc.op_type] | 650 | op_desc.json_file = kernel_json_file[op_desc.op_type] |
| 632 | if all_soc_key in kernel_json_file: | 651 | if all_soc_key in kernel_json_file: |
| 633 | op_desc.json_file = kernel_json_file[all_soc_key] | 652 | op_desc.json_file = kernel_json_file[all_soc_key] |
| 653 | + if all_soc_key in kernel_template_input_info: | ||
| 654 | + op_desc.set_kernel_template_input(kernel_template_input_info[all_soc_key]) | ||
| 655 | + if op_desc.op_type in kernel_template_input_info: | ||
| 656 | + op_desc.set_kernel_template_input(kernel_template_input_info[op_desc.op_type]) | ||
| 634 | 657 | ||
| 635 | key_params = "" | 658 | key_params = "" |
| 636 | if op_desc.op_type in input_param_file: | 659 | if op_desc.op_type in input_param_file: |
| @@ -135,7 +135,7 @@ class CompileKernel: | |||
| 135 | ascendc_bin_param_build.gen_bin_param_file( | 135 | ascendc_bin_param_build.gen_bin_param_file( |
| 136 | self.op_cfg_ini, bin_param_path, self.op_soc_ver, opc_config_file, [self.op_type] | 136 | self.op_cfg_ini, bin_param_path, self.op_soc_ver, opc_config_file, [self.op_type] |
| 137 | ) | 137 | ) |
| 138 | - tiling_key_info, op_debug_config, kernel_json_file, _ = ( | 138 | + tiling_key_info, op_debug_config, kernel_json_file, _, kernel_template_input_info = ( |
| 139 | ascendc_bin_param_build.parse_op_debug_config( | 139 | ascendc_bin_param_build.parse_op_debug_config( |
| 140 | opc_config_file, | 140 | opc_config_file, |
| 141 | self.op_soc_ver | 141 | self.op_soc_ver |
| @@ -39,6 +39,7 @@ def gen_compile_options(compile_options_file: str, op_type: str, \ | |||
| 39 | opc_kernel_config = [] | 39 | opc_kernel_config = [] |
| 40 | opc_tiling_keys = "" | 40 | opc_tiling_keys = "" |
| 41 | input_param_file = "" | 41 | input_param_file = "" |
| 42 | + opc_template_kernel_str = "" | ||
| 42 | for opts in compile_options: | 43 | for opts in compile_options: |
| 43 | if "oom" in opts: | 44 | if "oom" in opts: |
| 44 | if opts == "--oom": | 45 | if opts == "--oom": |
| @@ -59,6 +60,13 @@ def gen_compile_options(compile_options_file: str, op_type: str, \ | |||
| 59 | keys = opts.strip().split('=')[1].split(',') | 60 | keys = opts.strip().split('=')[1].split(',') |
| 60 | keys_str = ";".join([key for key in keys]) | 61 | keys_str = ";".join([key for key in keys]) |
| 61 | opc_tiling_keys = keys_str | 62 | opc_tiling_keys = keys_str |
| 63 | + elif "--kernel-template-input" in opts: | ||
| 64 | + if "=" not in opts: | ||
| 65 | + raise RuntimeError('Invalid --kernel-template-input option format!') | ||
| 66 | + input_value = opts.split("=", 1) | ||
| 67 | + if not input_value[1]: | ||
| 68 | + raise RuntimeError('No value given for --kernel-template-input option!') | ||
| 69 | + opc_template_kernel_str = input_value[1] | ||
| 62 | else: | 70 | else: |
| 63 | compile_opt.append(opts) | 71 | compile_opt.append(opts) |
| 64 | if len(compile_opt) > 0: | 72 | if len(compile_opt) > 0: |
| @@ -71,6 +79,10 @@ def gen_compile_options(compile_options_file: str, op_type: str, \ | |||
| 71 | if opc_config_str != "": | 79 | if opc_config_str != "": |
| 72 | opc_config_str += "@" | 80 | opc_config_str += "@" |
| 73 | opc_config_str += "--tiling_key=" + opc_tiling_keys | 81 | opc_config_str += "--tiling_key=" + opc_tiling_keys |
| 82 | + if len(opc_template_kernel_str) > 0: | ||
| 83 | + if opc_config_str != "": | ||
| 84 | + opc_config_str += "@" | ||
| 85 | + opc_config_str += "--kernel-template-input=" + opc_template_kernel_str | ||
| 74 | if opc_kernel_config: | 86 | if opc_kernel_config: |
| 75 | if opc_config_str != "": | 87 | if opc_config_str != "": |
| 76 | opc_config_str += "@" | 88 | opc_config_str += "@" |
| @@ -32,6 +32,7 @@ from asc_op_compile_base.common.platform import set_current_compile_soc_info, ge | |||
| 32 | from asc_op_compile_base.common import register | 32 | from asc_op_compile_base.common import register |
| 33 | from asc_op_compile_base.common import buildcfg | 33 | from asc_op_compile_base.common import buildcfg |
| 34 | from asc_op_compile_base.asc_op_compiler.global_storage import global_var_storage | 34 | from asc_op_compile_base.asc_op_compiler.global_storage import global_var_storage |
| 35 | +from asc_op_compile_base.common.context import get_context | ||
| 35 | 36 | ||
| 36 | def SetCurrentSocInfo(soc: str): | 37 | def SetCurrentSocInfo(soc: str): |
| 37 | set_current_compile_soc_info(soc) | 38 | set_current_compile_soc_info(soc) |
| @@ -3854,6 +3855,7 @@ Contents of section | |||
| 3854 | '-DHIGH_PERFORMANCE=1', '-DDETERMINISTIC_MODE=1'] | 3855 | '-DHIGH_PERFORMANCE=1', '-DDETERMINISTIC_MODE=1'] |
| 3855 | op_compile_option = '{}' | 3856 | op_compile_option = '{}' |
| 3856 | 3857 | ||
| 3858 | + | ||
| 3857 | with asc_op_compile_base.common.context.op_context.OpContext(): | 3859 | with asc_op_compile_base.common.context.op_context.OpContext(): |
| 3858 | with buildcfg.build_config(): | 3860 | with buildcfg.build_config(): |
| 3859 | compile_op(cce_file, origin_func_name, op_info, compile_options, code_channel, op_compile_option) | 3861 | compile_op(cce_file, origin_func_name, op_info, compile_options, code_channel, op_compile_option) |
| @@ -4304,9 +4306,11 @@ void add_custom(); | |||
| 4304 | file.write(context) | 4306 | file.write(context) |
| 4305 | 4307 | ||
| 4306 | with mock.patch.object(KernelInfoInfer, 'get_tiling_key_corresponding_struct', return_value={}): | 4308 | with mock.patch.object(KernelInfoInfer, 'get_tiling_key_corresponding_struct', return_value={}): |
| 4307 | - kernel_info = KernelInfoInfer.infer_info_from_ifile(None, src_file, src_file, src_file, "add_custom") | 4309 | + with asc_op_compile_base.common.context.op_context.OpContext(): |
| 4308 | - self.assertEqual(kernel_info.tiling_key_kernel_type["17435146"], KernelMetaType.KERNEL_TYPE_MIX_AIC_1_2) | 4310 | + with mock.patch.object(asc_op_compile_base.common.context.get_context(), 'get_addition', return_value = ''): |
| 4309 | - self.assertEqual(kernel_info.no_set_kernel_type, False) | 4311 | + kernel_info = KernelInfoInfer.infer_info_from_ifile(None, src_file, src_file, src_file, "add_custom") |
| 4312 | + self.assertEqual(kernel_info.tiling_key_kernel_type["17435146"], KernelMetaType.KERNEL_TYPE_MIX_AIC_1_2) | ||
| 4313 | + self.assertEqual(kernel_info.no_set_kernel_type, False) | ||
| 4310 | 4314 | ||
| 4311 | with open(src_file, "w") as file: | 4315 | with open(src_file, "w") as file: |
| 4312 | context = """ | 4316 | context = """ |
| @@ -4317,8 +4321,10 @@ void add_custom(); | |||
| 4317 | file.write(context) | 4321 | file.write(context) |
| 4318 | 4322 | ||
| 4319 | with mock.patch.object(KernelInfoInfer, 'get_tiling_key_corresponding_struct', return_value={}): | 4323 | with mock.patch.object(KernelInfoInfer, 'get_tiling_key_corresponding_struct', return_value={}): |
| 4320 | - kernel_info = KernelInfoInfer.infer_info_from_ifile(None, src_file, src_file, src_file, "add_custom") | 4324 | + with asc_op_compile_base.common.context.op_context.OpContext(): |
| 4321 | - self.assertEqual(kernel_info.no_set_kernel_type, True) | 4325 | + with mock.patch.object(asc_op_compile_base.common.context.get_context(), 'get_addition', return_value = ''): |
| 4326 | + kernel_info = KernelInfoInfer.infer_info_from_ifile(None, src_file, src_file, src_file, "add_custom") | ||
| 4327 | + self.assertEqual(kernel_info.no_set_kernel_type, True) | ||
| 4322 | 4328 | ||
| 4323 | with open(src_file, "w") as file: | 4329 | with open(src_file, "w") as file: |
| 4324 | context = """ | 4330 | context = """ |
| @@ -4329,10 +4335,12 @@ void add_custom(); | |||
| 4329 | file.write(context) | 4335 | file.write(context) |
| 4330 | 4336 | ||
| 4331 | with mock.patch.object(KernelInfoInfer, 'get_tiling_key_corresponding_struct', return_value={}): | 4337 | with mock.patch.object(KernelInfoInfer, 'get_tiling_key_corresponding_struct', return_value={}): |
| 4332 | - try: | 4338 | + with asc_op_compile_base.common.context.op_context.OpContext(): |
| 4333 | - KernelInfoInfer.infer_info_from_ifile(None, src_file, src_file, src_file, "add_custom") | 4339 | + with mock.patch.object(asc_op_compile_base.common.context.get_context(), 'get_addition', return_value = ''): |
| 4334 | - except Exception as e: | 4340 | + try: |
| 4335 | - assert str(e) == "must provide default kernel type", f"msg is :{e}" | 4341 | + KernelInfoInfer.infer_info_from_ifile(None, src_file, src_file, src_file, "add_custom") |
| 4342 | + except Exception as e: | ||
| 4343 | + assert str(e) == "must provide default kernel type", f"msg is :{e}" | ||
| 4336 | 4344 | ||
| 4337 | 4345 | ||
| 4338 | def test_infer_info_from_ifile_key_none_type_exists(self): | 4346 | def test_infer_info_from_ifile_key_none_type_exists(self): |
| @@ -12,6 +12,7 @@ | |||
| 12 | import os | 12 | import os |
| 13 | import sys | 13 | import sys |
| 14 | import unittest | 14 | import unittest |
| 15 | +from unittest import mock | ||
| 15 | 16 | ||
| 16 | THIS_FILE_NAME = __file__ | 17 | THIS_FILE_NAME = __file__ |
| 17 | FILE_PATH = os.path.dirname(os.path.realpath(THIS_FILE_NAME)) | 18 | FILE_PATH = os.path.dirname(os.path.realpath(THIS_FILE_NAME)) |
| @@ -20,6 +21,7 @@ API_ROOT_PATH = os.path.join(TOP_PATH, "build/adapter_ut") | |||
| 20 | FRAMEWORK_PATH = os.path.join(TOP_PATH, "tools/build/") | 21 | FRAMEWORK_PATH = os.path.join(TOP_PATH, "tools/build/") |
| 21 | sys.path.insert(0, FRAMEWORK_PATH) | 22 | sys.path.insert(0, FRAMEWORK_PATH) |
| 22 | 23 | ||
| 24 | +import asc_op_compile_base | ||
| 23 | from asc_op_compile_base.asc_op_compiler.template_tiling import * | 25 | from asc_op_compile_base.asc_op_compiler.template_tiling import * |
| 24 | 26 | ||
| 25 | 27 | ||
| @@ -35,9 +37,11 @@ class TestCompileOp(unittest.TestCase): | |||
| 35 | def test_template_tiling(self): | 37 | def test_template_tiling(self): |
| 36 | declare_param_str = "@@structFlashAttentionScore@@ =@@ASCENDC_TPL_ARGS_DECL_FlashAttentionScore@@ = {@@ASCENDC_TPL_DTYPE_DECL_X@@ = { 10, 30, 20},@@ASCENDC_TPL_FORMAT_DECL_Y@@ = {15, 25},@@ASCENDC_TPL_UINT_DECL_Z@@ = {8, 2, 2, 0, 2, 3, 4, 5, 6},@@ASCENDC_TPL_BOOL_DECL_S@@ = {0, 1}, };" | 38 | declare_param_str = "@@structFlashAttentionScore@@ =@@ASCENDC_TPL_ARGS_DECL_FlashAttentionScore@@ = {@@ASCENDC_TPL_DTYPE_DECL_X@@ = { 10, 30, 20},@@ASCENDC_TPL_FORMAT_DECL_Y@@ = {15, 25},@@ASCENDC_TPL_UINT_DECL_Z@@ = {8, 2, 2, 0, 2, 3, 4, 5, 6},@@ASCENDC_TPL_BOOL_DECL_S@@ = {0, 1}, };" |
| 37 | select_param_str = "@@ASCENDC_TPL_LISTS@@ = {@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 10, 30},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15},@@ASCENDC_TPL_UINT_SEL_Z@@ = {1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1}},@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 20},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15, 25},@@ASCENDC_TPL_UINT_SEL_Z@@ = { 1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1}}, };" | 39 | select_param_str = "@@ASCENDC_TPL_LISTS@@ = {@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 10, 30},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15},@@ASCENDC_TPL_UINT_SEL_Z@@ = {1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1}},@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 20},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15, 25},@@ASCENDC_TPL_UINT_SEL_Z@@ = { 1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1}}, };" |
| 38 | - extract_template_tiling_info(declare_param_str, select_param_str) | 40 | + with asc_op_compile_base.common.context.op_context.OpContext(): |
| 39 | - result = decode_tiling() | 41 | + with mock.patch.object(asc_op_compile_base.common.context.get_context(), 'get_addition', return_value = ''): |
| 40 | - self.assertEqual(result.get(17176852).get("paramArgs"), ['20', '25', '6', '1']) | 42 | + extract_template_tiling_info(declare_param_str, select_param_str) |
| 43 | + result = decode_tiling() | ||
| 44 | + self.assertEqual(result.get(17176852).get("paramArgs"), ['20', '25', '6', '1']) | ||
| 41 | 45 | ||
| 42 | def test_template_tiling_err_tpl(self): | 46 | def test_template_tiling_err_tpl(self): |
| 43 | declare_param_str = "@@structFlashAttentionScore@@ =@@ASCENDC_TPL_ARGS_DECL_FlashAttentionScore@@ = {@@ASCENDC_TPL_DTYPE_DECL_X@@ = { 10, 30, 20},@@ASCENDC_TPL_FORMAT_DECL_Y@@ = {15, 25},@@ASCENDC_TPL_UINT_DECL_Z@@ = {8, 2, 2, 0, 2, 3, 4, 5, 6},@@ASCENDC_TPL_BOOL_DECL_S@@ = {0, 1}, };" | 47 | declare_param_str = "@@structFlashAttentionScore@@ =@@ASCENDC_TPL_ARGS_DECL_FlashAttentionScore@@ = {@@ASCENDC_TPL_DTYPE_DECL_X@@ = { 10, 30, 20},@@ASCENDC_TPL_FORMAT_DECL_Y@@ = {15, 25},@@ASCENDC_TPL_UINT_DECL_Z@@ = {8, 2, 2, 0, 2, 3, 4, 5, 6},@@ASCENDC_TPL_BOOL_DECL_S@@ = {0, 1}, };" |
| @@ -56,26 +60,29 @@ class TestCompileOp(unittest.TestCase): | |||
| 56 | def test_template_tiling_null(self): | 60 | def test_template_tiling_null(self): |
| 57 | declare_param_str = "@@structFlashAttentionScore@@ =@@ASCENDC_TPL_ARGS_DECL_FlashAttentionScore@@ = {@@ASCENDC_TPL_DTYPE_DECL_X@@ = { 10, 30, 20},@@ASCENDC_TPL_FORMAT_DECL_Y@@ = {15, 25},@@ASCENDC_TPL_UINT_DECL_Z@@ = {8, 2, 2, 0, 2, 3, 4, 5, 6},@@ASCENDC_TPL_BOOL_DECL_S@@ = {0, 1}, };" | 61 | declare_param_str = "@@structFlashAttentionScore@@ =@@ASCENDC_TPL_ARGS_DECL_FlashAttentionScore@@ = {@@ASCENDC_TPL_DTYPE_DECL_X@@ = { 10, 30, 20},@@ASCENDC_TPL_FORMAT_DECL_Y@@ = {15, 25},@@ASCENDC_TPL_UINT_DECL_Z@@ = {8, 2, 2, 0, 2, 3, 4, 5, 6},@@ASCENDC_TPL_BOOL_DECL_S@@ = {0, 1}, };" |
| 58 | select_param_str = "@@ASCENDC_TPL_LISTS@@ = {@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 10, 30},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15},@@ASCENDC_TPL_UINT_SEL_Z@@ = {1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1}},@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 20},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15, 25},@@ASCENDC_TPL_UINT_SEL_Z@@ = { 1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1}}, };" | 62 | select_param_str = "@@ASCENDC_TPL_LISTS@@ = {@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 10, 30},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15},@@ASCENDC_TPL_UINT_SEL_Z@@ = {1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1}},@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 20},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15, 25},@@ASCENDC_TPL_UINT_SEL_Z@@ = { 1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1}}, };" |
| 59 | - | 63 | + with asc_op_compile_base.common.context.op_context.OpContext(): |
| 60 | - extract_template_tiling_info(declare_param_str, select_param_str) | 64 | + with mock.patch.object(asc_op_compile_base.common.context.get_context(), 'get_addition', return_value = ''): |
| 61 | - result = decode_tiling() | 65 | + extract_template_tiling_info(declare_param_str, select_param_str) |
| 62 | - self.assertIsNone(result.get(17176851112)) | 66 | + result = decode_tiling() |
| 67 | + self.assertIsNone(result.get(17176851112)) | ||
| 63 | 68 | ||
| 64 | def test_template_tiling_single(self): | 69 | def test_template_tiling_single(self): |
| 65 | declare_param_str = "@@structFlashAttentionScore@@ =@@ASCENDC_TPL_ARGS_DECL_FlashAttentionScore@@ = {@@ASCENDC_TPL_DTYPE_DECL_X@@ = { 10, 30, 20},@@ASCENDC_TPL_FORMAT_DECL_Y@@ = {15, 25},@@ASCENDC_TPL_UINT_DECL_Z@@ = {8, 2, 2, 0, 2, 3, 4, 5, 6},@@ASCENDC_TPL_BOOL_DECL_S@@ = {0, 1}, };" | 70 | declare_param_str = "@@structFlashAttentionScore@@ =@@ASCENDC_TPL_ARGS_DECL_FlashAttentionScore@@ = {@@ASCENDC_TPL_DTYPE_DECL_X@@ = { 10, 30, 20},@@ASCENDC_TPL_FORMAT_DECL_Y@@ = {15, 25},@@ASCENDC_TPL_UINT_DECL_Z@@ = {8, 2, 2, 0, 2, 3, 4, 5, 6},@@ASCENDC_TPL_BOOL_DECL_S@@ = {0, 1}, };" |
| 66 | select_param_str = "@@ASCENDC_TPL_LISTS@@ = {@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 10, 30},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15},@@ASCENDC_TPL_UINT_SEL_Z@@ = {1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1}},@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 20},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15, 25},@@ASCENDC_TPL_UINT_SEL_Z@@ = { 1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1}}, };" | 71 | select_param_str = "@@ASCENDC_TPL_LISTS@@ = {@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 10, 30},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15},@@ASCENDC_TPL_UINT_SEL_Z@@ = {1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1}},@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 20},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15, 25},@@ASCENDC_TPL_UINT_SEL_Z@@ = { 1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1}}, };" |
| 67 | - | 72 | + with asc_op_compile_base.common.context.op_context.OpContext(): |
| 68 | - extract_template_tiling_info(declare_param_str, select_param_str) | 73 | + with mock.patch.object(asc_op_compile_base.common.context.get_context(), 'get_addition', return_value = ''): |
| 69 | - result = decode_tiling(17176852) | 74 | + extract_template_tiling_info(declare_param_str, select_param_str) |
| 70 | - self.assertEqual(result.get(17176852).get("paramArgs"), ['20', '25', '6', '1']) | 75 | + result = decode_tiling(17176852) |
| 76 | + self.assertEqual(result.get(17176852).get("paramArgs"), ['20', '25', '6', '1']) | ||
| 71 | 77 | ||
| 72 | def test_template_tiling_single_null(self): | 78 | def test_template_tiling_single_null(self): |
| 73 | declare_param_str = "@@structFlashAttentionScore@@ =@@ASCENDC_TPL_ARGS_DECL_FlashAttentionScore@@ = {@@ASCENDC_TPL_DTYPE_DECL_X@@ = { 10, 30, 20},@@ASCENDC_TPL_FORMAT_DECL_Y@@ = {15, 25},@@ASCENDC_TPL_UINT_DECL_Z@@ = {8, 2, 2, 0, 2, 3, 4, 5, 6},@@ASCENDC_TPL_BOOL_DECL_S@@ = {0, 1}, };" | 79 | declare_param_str = "@@structFlashAttentionScore@@ =@@ASCENDC_TPL_ARGS_DECL_FlashAttentionScore@@ = {@@ASCENDC_TPL_DTYPE_DECL_X@@ = { 10, 30, 20},@@ASCENDC_TPL_FORMAT_DECL_Y@@ = {15, 25},@@ASCENDC_TPL_UINT_DECL_Z@@ = {8, 2, 2, 0, 2, 3, 4, 5, 6},@@ASCENDC_TPL_BOOL_DECL_S@@ = {0, 1}, };" |
| 74 | select_param_str = "@@ASCENDC_TPL_LISTS@@ = {@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 10, 30},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15},@@ASCENDC_TPL_UINT_SEL_Z@@ = {1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1}},@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 20},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15, 25},@@ASCENDC_TPL_UINT_SEL_Z@@ = { 1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1}}, };" | 80 | select_param_str = "@@ASCENDC_TPL_LISTS@@ = {@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 10, 30},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15},@@ASCENDC_TPL_UINT_SEL_Z@@ = {1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1}},@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 20},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15, 25},@@ASCENDC_TPL_UINT_SEL_Z@@ = { 1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1}}, };" |
| 75 | - | 81 | + with asc_op_compile_base.common.context.op_context.OpContext(): |
| 76 | - extract_template_tiling_info(declare_param_str, select_param_str) | 82 | + with mock.patch.object(asc_op_compile_base.common.context.get_context(), 'get_addition', return_value = ''): |
| 77 | - result = decode_tiling(17176851112) | 83 | + extract_template_tiling_info(declare_param_str, select_param_str) |
| 78 | - self.assertIsNone(result.get(17176851112)) | 84 | + result = decode_tiling(17176851112) |
| 85 | + self.assertIsNone(result.get(17176851112)) | ||
| 79 | 86 | ||
| 80 | def test_template_tiling_ui_range(self): | 87 | def test_template_tiling_ui_range(self): |
| 81 | declare_param_str = "@@structFlashAttentionScore@@ =@@ASCENDC_TPL_ARGS_DECL_FlashAttentionScore@@ = {@@ASCENDC_TPL_DTYPE_DECL_X@@ = { 10, 30, 20},@@ASCENDC_TPL_FORMAT_DECL_Y@@ = {15, 25},@@ASCENDC_TPL_UINT_DECL_Z@@ = {8, 2, 20, 0, 2, 3, 4, 5, 6},@@ASCENDC_TPL_BOOL_DECL_S@@ = {0, 1}, };" | 88 | declare_param_str = "@@structFlashAttentionScore@@ =@@ASCENDC_TPL_ARGS_DECL_FlashAttentionScore@@ = {@@ASCENDC_TPL_DTYPE_DECL_X@@ = { 10, 30, 20},@@ASCENDC_TPL_FORMAT_DECL_Y@@ = {15, 25},@@ASCENDC_TPL_UINT_DECL_Z@@ = {8, 2, 20, 0, 2, 3, 4, 5, 6},@@ASCENDC_TPL_BOOL_DECL_S@@ = {0, 1}, };" |
| @@ -87,18 +94,22 @@ class TestCompileOp(unittest.TestCase): | |||
| 87 | def test_template_tiling_duplicated(self): | 94 | def test_template_tiling_duplicated(self): |
| 88 | declare_param_str = "@@structFlashAttentionScore@@ =@@ASCENDC_TPL_ARGS_DECL_FlashAttentionScore@@ = {@@ASCENDC_TPL_DTYPE_DECL_X@@ = { 10, 30, 20},@@ASCENDC_TPL_FORMAT_DECL_Y@@ = {15, 25},@@ASCENDC_TPL_UINT_DECL_Z@@ = {8, 2, 2, 0, 2, 3, 4, 3, 6},@@ASCENDC_TPL_BOOL_DECL_S@@ = {0, 1}, };" | 95 | declare_param_str = "@@structFlashAttentionScore@@ =@@ASCENDC_TPL_ARGS_DECL_FlashAttentionScore@@ = {@@ASCENDC_TPL_DTYPE_DECL_X@@ = { 10, 30, 20},@@ASCENDC_TPL_FORMAT_DECL_Y@@ = {15, 25},@@ASCENDC_TPL_UINT_DECL_Z@@ = {8, 2, 2, 0, 2, 3, 4, 3, 6},@@ASCENDC_TPL_BOOL_DECL_S@@ = {0, 1}, };" |
| 89 | select_param_str = "@@ASCENDC_TPL_LISTS@@ = {@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 10, 30},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15},@@ASCENDC_TPL_UINT_SEL_Z@@ = {1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1}},@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 20},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15, 25},@@ASCENDC_TPL_UINT_SEL_Z@@ = { 1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1}}, };" | 96 | select_param_str = "@@ASCENDC_TPL_LISTS@@ = {@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 10, 30},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15},@@ASCENDC_TPL_UINT_SEL_Z@@ = {1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1}},@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 20},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15, 25},@@ASCENDC_TPL_UINT_SEL_Z@@ = { 1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1}}, };" |
| 90 | - with self.assertRaises(RuntimeError) as e: | 97 | + with asc_op_compile_base.common.context.op_context.OpContext(): |
| 91 | - extract_template_tiling_info(declare_param_str, select_param_str) | 98 | + with mock.patch.object(asc_op_compile_base.common.context.get_context(), 'get_addition', return_value = ''): |
| 92 | - self.assertEqual(e.exception.args, ('There is duplicated number in ASCENDC_TPL_DECL_UINT Z! Duplicated List: [0, 1, 2, 3, 4, 3, 6].',)) | 99 | + with self.assertRaises(RuntimeError) as e: |
| 100 | + extract_template_tiling_info(declare_param_str, select_param_str) | ||
| 101 | + self.assertEqual(e.exception.args, ('There is duplicated number in ASCENDC_TPL_DECL_UINT Z! Duplicated List: [0, 1, 2, 3, 4, 3, 6].',)) | ||
| 93 | 102 | ||
| 94 | declare_param_str = "@@structFlashAttentionScore@@ =@@ASCENDC_TPL_ARGS_DECL_FlashAttentionScore@@ = {@@ASCENDC_TPL_DTYPE_DECL_X@@ = { 10, 30, 20},@@ASCENDC_TPL_FORMAT_DECL_Y@@ = {15, 25},@@ASCENDC_TPL_UINT_DECL_Z@@ = {8, 2, 2, 0, 2, 3, 4, 5, 6},@@ASCENDC_TPL_BOOL_DECL_S@@ = {0, 1}, };" | 103 | declare_param_str = "@@structFlashAttentionScore@@ =@@ASCENDC_TPL_ARGS_DECL_FlashAttentionScore@@ = {@@ASCENDC_TPL_DTYPE_DECL_X@@ = { 10, 30, 20},@@ASCENDC_TPL_FORMAT_DECL_Y@@ = {15, 25},@@ASCENDC_TPL_UINT_DECL_Z@@ = {8, 2, 2, 0, 2, 3, 4, 5, 6},@@ASCENDC_TPL_BOOL_DECL_S@@ = {0, 1}, };" |
| 95 | select_param_str = \ | 104 | select_param_str = \ |
| 96 | "@@ASCENDC_TPL_LISTS@@ = {@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 10, 30},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15},@@ASCENDC_TPL_UINT_SEL_Z@@ = {1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1}},"\ | 105 | "@@ASCENDC_TPL_LISTS@@ = {@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 10, 30},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15},@@ASCENDC_TPL_UINT_SEL_Z@@ = {1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1}},"\ |
| 97 | "@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 10, 30},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15},@@ASCENDC_TPL_UINT_SEL_Z@@ = {1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1}}, };" | 106 | "@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 10, 30},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15},@@ASCENDC_TPL_UINT_SEL_Z@@ = {1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1}}, };" |
| 98 | - with self.assertRaises(RuntimeError) as e: | 107 | + with asc_op_compile_base.common.context.op_context.OpContext(): |
| 99 | - extract_template_tiling_info(declare_param_str, select_param_str) | 108 | + with mock.patch.object(asc_op_compile_base.common.context.get_context(), 'get_addition', return_value = ''): |
| 100 | - result = decode_tiling() | 109 | + with self.assertRaises(RuntimeError) as e: |
| 101 | - self.assertEqual(e.exception.args, ("ASCENDC_TPL_SELECT has duplicated definitions!",)) | 110 | + extract_template_tiling_info(declare_param_str, select_param_str) |
| 111 | + result = decode_tiling() | ||
| 112 | + self.assertEqual(e.exception.args, ("ASCENDC_TPL_SELECT has duplicated definitions!",)) | ||
| 102 | 113 | ||
| 103 | def test_template_tiling_name(self): | 114 | def test_template_tiling_name(self): |
| 104 | declare_param_str = "@@structFlashAttentionScore@@ =@@ASCENDC_TPL_ARGS_DECL_FlashAttentionScore@@ = {@@ASCENDC_TPL_DTYPE_DECL_X@@ = { 10, 30, 20},@@ASCENDC_TPL_FORMAT_DECL_Y@@ = {15, 25},@@ASCENDC_TPL_UINT_DECL_Z@@ = {8, 2, 2, 0, 2, 3, 4, 5, 6},@@ASCENDC_TPL_BOOL_DECL_S@@ = {0, 1}, };" | 115 | declare_param_str = "@@structFlashAttentionScore@@ =@@ASCENDC_TPL_ARGS_DECL_FlashAttentionScore@@ = {@@ASCENDC_TPL_DTYPE_DECL_X@@ = { 10, 30, 20},@@ASCENDC_TPL_FORMAT_DECL_Y@@ = {15, 25},@@ASCENDC_TPL_UINT_DECL_Z@@ = {8, 2, 2, 0, 2, 3, 4, 5, 6},@@ASCENDC_TPL_BOOL_DECL_S@@ = {0, 1}, };" |
| @@ -157,33 +168,39 @@ class TestCompileOp(unittest.TestCase): | |||
| 157 | def test_template_tiling_struct(self): | 168 | def test_template_tiling_struct(self): |
| 158 | declare_param_str = "@@structFlashAttentionScore@@ =@@ASCENDC_TPL_ARGS_DECL_FlashAttentionScore@@ = {@@ASCENDC_TPL_DTYPE_DECL_X@@ = { 10, 30, 20},@@ASCENDC_TPL_FORMAT_DECL_Y@@ = {15, 25},@@ASCENDC_TPL_UINT_DECL_Z@@ = {8, 2, 2, 0, 2, 3, 4, 5, 6},@@ASCENDC_TPL_BOOL_DECL_S@@ = {0, 1}, };" | 169 | declare_param_str = "@@structFlashAttentionScore@@ =@@ASCENDC_TPL_ARGS_DECL_FlashAttentionScore@@ = {@@ASCENDC_TPL_DTYPE_DECL_X@@ = { 10, 30, 20},@@ASCENDC_TPL_FORMAT_DECL_Y@@ = {15, 25},@@ASCENDC_TPL_UINT_DECL_Z@@ = {8, 2, 2, 0, 2, 3, 4, 5, 6},@@ASCENDC_TPL_BOOL_DECL_S@@ = {0, 1}, };" |
| 159 | select_param_str = "@@ASCENDC_TPL_LISTS@@ = {@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 10, 30},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15},@@ASCENDC_TPL_UINT_SEL_Z@@ = {1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1}},@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 20},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15, 25},@@ASCENDC_TPL_UINT_SEL_Z@@ = { 1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1},@@ASCENDC_TPL_TILING_STRUCT_SEL_tilingDataStruct@@ = {}},};" | 170 | select_param_str = "@@ASCENDC_TPL_LISTS@@ = {@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 10, 30},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15},@@ASCENDC_TPL_UINT_SEL_Z@@ = {1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1}},@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 20},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15, 25},@@ASCENDC_TPL_UINT_SEL_Z@@ = { 1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1},@@ASCENDC_TPL_TILING_STRUCT_SEL_tilingDataStruct@@ = {}},};" |
| 160 | - extract_template_tiling_info(declare_param_str, select_param_str) | 171 | + with asc_op_compile_base.common.context.op_context.OpContext(): |
| 161 | - result = decode_tiling() | 172 | + with mock.patch.object(asc_op_compile_base.common.context.get_context(), 'get_addition', return_value = ''): |
| 162 | - self.assertEqual(result.get(17176852).get("paramArgs"), ['20', '25', '6', '1']) | 173 | + extract_template_tiling_info(declare_param_str, select_param_str) |
| 174 | + result = decode_tiling() | ||
| 175 | + self.assertEqual(result.get(17176852).get("paramArgs"), ['20', '25', '6', '1']) | ||
| 163 | 176 | ||
| 164 | def test_template_tiling_kernel(self): | 177 | def test_template_tiling_kernel(self): |
| 165 | declare_param_str = "@@ASCENDC_TPL_ARGS_DECL_AddTemplateCustom@@ = {@@ASCENDC_TPL_DTYPE_DECL_D_T_X@@ = {10, 20},@@ASCENDC_TPL_DTYPE_DECL_D_T_Y@@ = {10, 20},@@ASCENDC_TPL_DTYPE_DECL_D_T_Z@@ = {10, 20},@@ASCENDC_TPL_UINT_DECL_TILE_NUM@@ = {8, 2, 2, 0, 2, 3, 5, 10, 12, 13, 9, 8},@@ASCENDC_TPL_BOOL_DECL_IS_SPLIT@@ = {0, 1},};" | 178 | declare_param_str = "@@ASCENDC_TPL_ARGS_DECL_AddTemplateCustom@@ = {@@ASCENDC_TPL_DTYPE_DECL_D_T_X@@ = {10, 20},@@ASCENDC_TPL_DTYPE_DECL_D_T_Y@@ = {10, 20},@@ASCENDC_TPL_DTYPE_DECL_D_T_Z@@ = {10, 20},@@ASCENDC_TPL_UINT_DECL_TILE_NUM@@ = {8, 2, 2, 0, 2, 3, 5, 10, 12, 13, 9, 8},@@ASCENDC_TPL_BOOL_DECL_IS_SPLIT@@ = {0, 1},};" |
| 166 | select_param_str = "@@ASCENDC_TPL_LISTS@@ = {@@{@@ASCENDC_TPL_KERNEL_TYPE_SEL@@ = {2}, @@ASCENDC_TPL_DTYPE_SEL_D_T_X@@ = {10}, @@ASCENDC_TPL_DTYPE_SEL_D_T_Y@@ = {10}, @@ASCENDC_TPL_DTYPE_SEL_D_T_Z@@ = {10}, @@ASCENDC_TPL_UINT_SEL_TILE_NUM@@ = {1, 1, 8}, @@ASCENDC_TPL_BOOL_SEL_IS_SPLIT@@ = {0, 1},}, @@{@@ASCENDC_TPL_KERNEL_TYPE_SEL@@ = {0}, @@ASCENDC_TPL_DTYPE_SEL_D_T_X@@ = {20}, @@ASCENDC_TPL_DTYPE_SEL_D_T_Y@@ = {20}, @@ASCENDC_TPL_DTYPE_SEL_D_T_Z@@ = {20}, @@ASCENDC_TPL_UINT_SEL_TILE_NUM@@ = {1, 1, 8}, @@ASCENDC_TPL_BOOL_SEL_IS_SPLIT@@ = {0, 1},},};" | 179 | select_param_str = "@@ASCENDC_TPL_LISTS@@ = {@@{@@ASCENDC_TPL_KERNEL_TYPE_SEL@@ = {2}, @@ASCENDC_TPL_DTYPE_SEL_D_T_X@@ = {10}, @@ASCENDC_TPL_DTYPE_SEL_D_T_Y@@ = {10}, @@ASCENDC_TPL_DTYPE_SEL_D_T_Z@@ = {10}, @@ASCENDC_TPL_UINT_SEL_TILE_NUM@@ = {1, 1, 8}, @@ASCENDC_TPL_BOOL_SEL_IS_SPLIT@@ = {0, 1},}, @@{@@ASCENDC_TPL_KERNEL_TYPE_SEL@@ = {0}, @@ASCENDC_TPL_DTYPE_SEL_D_T_X@@ = {20}, @@ASCENDC_TPL_DTYPE_SEL_D_T_Y@@ = {20}, @@ASCENDC_TPL_DTYPE_SEL_D_T_Z@@ = {20}, @@ASCENDC_TPL_UINT_SEL_TILE_NUM@@ = {1, 1, 8}, @@ASCENDC_TPL_BOOL_SEL_IS_SPLIT@@ = {0, 1},},};" |
| 167 | - extract_template_tiling_info(declare_param_str, select_param_str) | 180 | + with asc_op_compile_base.common.context.op_context.OpContext(): |
| 168 | - result = decode_tiling() | 181 | + with mock.patch.object(asc_op_compile_base.common.context.get_context(), 'get_addition', return_value = ''): |
| 169 | - self.assertEqual(result.get(17435146).get("paramArgs"), ['10', '10', '10', '1', '0']) | 182 | + extract_template_tiling_info(declare_param_str, select_param_str) |
| 170 | - self.assertEqual(result.get(17435146).get("kernelType"), 2) | 183 | + result = decode_tiling() |
| 184 | + self.assertEqual(result.get(17435146).get("paramArgs"), ['10', '10', '10', '1', '0']) | ||
| 185 | + self.assertEqual(result.get(17435146).get("kernelType"), 2) | ||
| 171 | 186 | ||
| 172 | def test_template_tiling_deterministic(self): | 187 | def test_template_tiling_deterministic(self): |
| 173 | declare_param_str = "@@structFlashAttentionScore@@ =@@ASCENDC_TPL_ARGS_DECL_FlashAttentionScore@@ = {@@ASCENDC_TPL_DTYPE_DECL_X@@ = { 10, 30, 20},@@ASCENDC_TPL_FORMAT_DECL_Y@@ = {15, 25},@@ASCENDC_TPL_UINT_DECL_Z@@ = {8, 2, 2, 0, 2, 3, 4, 5, 6},@@ASCENDC_TPL_BOOL_DECL_S@@ = {0, 1}, };" | 188 | declare_param_str = "@@structFlashAttentionScore@@ =@@ASCENDC_TPL_ARGS_DECL_FlashAttentionScore@@ = {@@ASCENDC_TPL_DTYPE_DECL_X@@ = { 10, 30, 20},@@ASCENDC_TPL_FORMAT_DECL_Y@@ = {15, 25},@@ASCENDC_TPL_UINT_DECL_Z@@ = {8, 2, 2, 0, 2, 3, 4, 5, 6},@@ASCENDC_TPL_BOOL_DECL_S@@ = {0, 1}, };" |
| 174 | select_param_str = "@@ASCENDC_TPL_LISTS@@ = {@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 10, 30},@@ASCENDC_TPL_DETERMINISTIC_SEL@@ = {false},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15},@@ASCENDC_TPL_UINT_SEL_Z@@ = {1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1}},@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 20},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15, 25},@@ASCENDC_TPL_UINT_SEL_Z@@ = { 1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1},@@ASCENDC_TPL_TILING_STRUCT_SEL_tilingDataStruct@@ = {}},};" | 189 | select_param_str = "@@ASCENDC_TPL_LISTS@@ = {@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 10, 30},@@ASCENDC_TPL_DETERMINISTIC_SEL@@ = {false},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15},@@ASCENDC_TPL_UINT_SEL_Z@@ = {1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1}},@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 20},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15, 25},@@ASCENDC_TPL_UINT_SEL_Z@@ = { 1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1},@@ASCENDC_TPL_TILING_STRUCT_SEL_tilingDataStruct@@ = {}},};" |
| 175 | - extract_template_tiling_info(declare_param_str, select_param_str) | 190 | + with asc_op_compile_base.common.context.op_context.OpContext(): |
| 176 | - result = decode_tiling() | 191 | + with mock.patch.object(asc_op_compile_base.common.context.get_context(), 'get_addition', return_value = ''): |
| 177 | - self.assertEqual(result.get(17176852).get("paramArgs"), ['20', '25', '6', '1']) | 192 | + extract_template_tiling_info(declare_param_str, select_param_str) |
| 178 | - select_param_str = "@@ASCENDC_TPL_LISTS@@ = {@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 10, 30},@@ASCENDC_TPL_DETERMINISTIC_SEL@@ = {0},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15},@@ASCENDC_TPL_UINT_SEL_Z@@ = {1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1}},@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 20},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15, 25},@@ASCENDC_TPL_UINT_SEL_Z@@ = { 1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1},@@ASCENDC_TPL_TILING_STRUCT_SEL_tilingDataStruct@@ = {}},};" | 193 | + result = decode_tiling() |
| 179 | - extract_template_tiling_info(declare_param_str, select_param_str) | 194 | + self.assertEqual(result.get(17176852).get("paramArgs"), ['20', '25', '6', '1']) |
| 180 | - select_param_str = "@@ASCENDC_TPL_LISTS@@ = {@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 10, 30},@@ASCENDC_TPL_DETERMINISTIC_SEL@@ = {1},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15},@@ASCENDC_TPL_UINT_SEL_Z@@ = {1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1}},@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 20},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15, 25},@@ASCENDC_TPL_UINT_SEL_Z@@ = { 1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1},@@ASCENDC_TPL_TILING_STRUCT_SEL_tilingDataStruct@@ = {}},};" | 195 | + select_param_str = "@@ASCENDC_TPL_LISTS@@ = {@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 10, 30},@@ASCENDC_TPL_DETERMINISTIC_SEL@@ = {0},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15},@@ASCENDC_TPL_UINT_SEL_Z@@ = {1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1}},@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 20},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15, 25},@@ASCENDC_TPL_UINT_SEL_Z@@ = { 1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1},@@ASCENDC_TPL_TILING_STRUCT_SEL_tilingDataStruct@@ = {}},};" |
| 181 | - extract_template_tiling_info(declare_param_str, select_param_str) | 196 | + extract_template_tiling_info(declare_param_str, select_param_str) |
| 182 | - select_param_str = "@@ASCENDC_TPL_LISTS@@ = {@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 10, 30},@@ASCENDC_TPL_DETERMINISTIC_SEL@@ = {3},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15},@@ASCENDC_TPL_UINT_SEL_Z@@ = {1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1}},@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 20},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15, 25},@@ASCENDC_TPL_UINT_SEL_Z@@ = { 1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1},@@ASCENDC_TPL_TILING_STRUCT_SEL_tilingDataStruct@@ = {}},};" | 197 | + select_param_str = "@@ASCENDC_TPL_LISTS@@ = {@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 10, 30},@@ASCENDC_TPL_DETERMINISTIC_SEL@@ = {1},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15},@@ASCENDC_TPL_UINT_SEL_Z@@ = {1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1}},@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 20},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15, 25},@@ASCENDC_TPL_UINT_SEL_Z@@ = { 1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1},@@ASCENDC_TPL_TILING_STRUCT_SEL_tilingDataStruct@@ = {}},};" |
| 183 | - with self.assertRaises(RuntimeError) as e: | 198 | + extract_template_tiling_info(declare_param_str, select_param_str) |
| 184 | - extract_template_tiling_info(declare_param_str, select_param_str) | 199 | + select_param_str = "@@ASCENDC_TPL_LISTS@@ = {@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 10, 30},@@ASCENDC_TPL_DETERMINISTIC_SEL@@ = {3},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15},@@ASCENDC_TPL_UINT_SEL_Z@@ = {1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1}},@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 20},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15, 25},@@ASCENDC_TPL_UINT_SEL_Z@@ = { 1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1},@@ASCENDC_TPL_TILING_STRUCT_SEL_tilingDataStruct@@ = {}},};" |
| 185 | - select_param_str = "@@ASCENDC_TPL_LISTS@@ = {@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 10, 30},@@ASCENDC_TPL_DETERMINISTIC_SEL@@ = {0, 1},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15},@@ASCENDC_TPL_UINT_SEL_Z@@ = {1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1}},@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 20},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15, 25},@@ASCENDC_TPL_UINT_SEL_Z@@ = { 1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1},@@ASCENDC_TPL_TILING_STRUCT_SEL_tilingDataStruct@@ = {}},};" | 200 | + with self.assertRaises(RuntimeError) as e: |
| 186 | - with self.assertRaises(RuntimeError) as e: | 201 | + extract_template_tiling_info(declare_param_str, select_param_str) |
| 187 | - extract_template_tiling_info(declare_param_str, select_param_str) | 202 | + select_param_str = "@@ASCENDC_TPL_LISTS@@ = {@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 10, 30},@@ASCENDC_TPL_DETERMINISTIC_SEL@@ = {0, 1},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15},@@ASCENDC_TPL_UINT_SEL_Z@@ = {1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1}},@@{@@ASCENDC_TPL_DTYPE_SEL_X@@ = { 20},@@ASCENDC_TPL_FORMAT_SEL_Y@@ = { 15, 25},@@ASCENDC_TPL_UINT_SEL_Z@@ = { 1, 4, 6},@@ASCENDC_TPL_BOOL_SEL_S@@ = {0, 1},@@ASCENDC_TPL_TILING_STRUCT_SEL_tilingDataStruct@@ = {}},};" |
| 203 | + with self.assertRaises(RuntimeError) as e: | ||
| 204 | + extract_template_tiling_info(declare_param_str, select_param_str) | ||
| 188 | if __name__ == "__main__": | 205 | if __name__ == "__main__": |
| 189 | unittest.main() | 206 | unittest.main() |
| @@ -469,6 +469,8 @@ REGISTER_TILING_DEFAULT') | |||
| 469 | extract_template_tiling_info(declare_param_str, select_param_str) | 469 | extract_template_tiling_info(declare_param_str, select_param_str) |
| 470 | decode_tiling_result = decode_tiling() | 470 | decode_tiling_result = decode_tiling() |
| 471 | tiling_key_list = [str(k) for k in decode_tiling_result.keys()] | 471 | tiling_key_list = [str(k) for k in decode_tiling_result.keys()] |
| 472 | + if len(tiling_key_list) == 0: | ||
| 473 | + raise Exception(f'no match kernel template input!') | ||
| 472 | # ==================== All SEL checks | 474 | # ==================== All SEL checks |
| 473 | tiling_key_list, decode_tiling_result = tpl_tilingkey_kernel_type_check( | 475 | tiling_key_list, decode_tiling_result = tpl_tilingkey_kernel_type_check( |
| 474 | tiling_key_list, decode_tiling_result, tiling_key_kernel_type | 476 | tiling_key_list, decode_tiling_result, tiling_key_kernel_type |
| @@ -15,6 +15,7 @@ import re | |||
| 15 | from enum import Enum, auto | 15 | from enum import Enum, auto |
| 16 | from dataclasses import dataclass | 16 | from dataclasses import dataclass |
| 17 | from typing import List, Any | 17 | from typing import List, Any |
| 18 | +from tbe.common.context import get_context | ||
| 18 | from .log_utils import AscendCLogLevel | 19 | from .log_utils import AscendCLogLevel |
| 19 | from .ascendc_common_utility import CommonUtility | 20 | from .ascendc_common_utility import CommonUtility |
| 20 | from .get_op_tiling import OpInfo | 21 | from .get_op_tiling import OpInfo |
| @@ -58,6 +59,41 @@ ASCENDC_COMPILE_DATATYPE_MAP = { | |||
| 58 | "DT_MAX": ["unknown", ASCENDC_TPL_DATATYPE_MAX], | 59 | "DT_MAX": ["unknown", ASCENDC_TPL_DATATYPE_MAX], |
| 59 | } | 60 | } |
| 60 | ASCENDC_COMPILE_DATATYPE_REVERT_MAP = {v[-1]: v[0] for v in ASCENDC_COMPILE_DATATYPE_MAP.values()} | 61 | ASCENDC_COMPILE_DATATYPE_REVERT_MAP = {v[-1]: v[0] for v in ASCENDC_COMPILE_DATATYPE_MAP.values()} |
| 62 | +ASCENDC_KERNEL_TEMPLATE_INPUT_DATATYPE_MAP = { | ||
| 63 | + "float": 0, | ||
| 64 | + "half": 1, | ||
| 65 | + "int8_t": 2, | ||
| 66 | + "int32_t": 3, | ||
| 67 | + "uint8_t": 4, | ||
| 68 | + "int16_t": 6, | ||
| 69 | + "uint16_t": 7, | ||
| 70 | + "uint32_t": 8, | ||
| 71 | + "int64_t": 9, | ||
| 72 | + "uint64_t": 10, | ||
| 73 | + "double": 11, | ||
| 74 | + "bool": 12, | ||
| 75 | + "complex64": 16, | ||
| 76 | + "bfloat16_t": 27, | ||
| 77 | + "int4b_t": 29, | ||
| 78 | + "hifloat8_t": 34, | ||
| 79 | + "fp8_e5m2_t": 35, | ||
| 80 | + "fp8_e4m3fn_t": 36, | ||
| 81 | + "fp4x2_e2m1_t": 40, | ||
| 82 | + "fp4x2_e1m2_t": 41 | ||
| 83 | +} | ||
| 84 | +ASCENDC_KERNEL_TEMPLATE_INPUT_KERNEL_TYPE_MAP = { | ||
| 85 | + "ASCENDC_TPL_AIV_ONLY": 0, | ||
| 86 | + "ASCENDC_TPL_AIC_ONLY": 1, | ||
| 87 | + "ASCENDC_TPL_MIX_AIV_1_0": 4, | ||
| 88 | + "ASCENDC_TPL_MIX_AIC_1_0": 5, | ||
| 89 | + "ASCENDC_TPL_MIX_AIC_1_1": 6, | ||
| 90 | + "ASCENDC_TPL_MIX_AIC_1_2": 7, | ||
| 91 | + "ASCENDC_TPL_AICORE": 8, | ||
| 92 | + "ASCENDC_TPL_VECTORCORE": 9, | ||
| 93 | + "ASCENDC_TPL_MIX_AICORE": 10, | ||
| 94 | + "ASCENDC_TPL_MIX_VECTOR_CORE": 11, | ||
| 95 | + "ASCENDC_TPL_MAX": 12 | ||
| 96 | +} | ||
| 61 | ASCENDC_TPL_DATAFORMAT_MAX = 55 | 97 | ASCENDC_TPL_DATAFORMAT_MAX = 55 |
| 62 | ASCENDC_COMPILE_DATAFORMAT_MAP = { | 98 | ASCENDC_COMPILE_DATAFORMAT_MAP = { |
| 63 | "FORMAT_NCHW": ["NCHW", 0], | 99 | "FORMAT_NCHW": ["NCHW", 0], |
| @@ -494,6 +530,7 @@ def extract_template_tiling_params(tiling_param_list: List[str], bit_map: dict = | |||
| 494 | GROUP_ID = 0 | 530 | GROUP_ID = 0 |
| 495 | ID_LIST = [] | 531 | ID_LIST = [] |
| 496 | group_map = {} | 532 | group_map = {} |
| 533 | +kernel_compile_dict = {} | ||
| 497 | 534 | ||
| 498 | 535 | ||
| 499 | def get_concated_tiling_key(template_param_list: List[TilingTemplateParams], \ | 536 | def get_concated_tiling_key(template_param_list: List[TilingTemplateParams], \ |
| @@ -501,6 +538,7 @@ def get_concated_tiling_key(template_param_list: List[TilingTemplateParams], \ | |||
| 501 | global ID_LIST | 538 | global ID_LIST |
| 502 | global GROUP_ID | 539 | global GROUP_ID |
| 503 | global group_map | 540 | global group_map |
| 541 | + global kernel_compile_dict | ||
| 504 | result = dict() | 542 | result = dict() |
| 505 | if index == len(template_param_list): | 543 | if index == len(template_param_list): |
| 506 | data.update({"paramArgs": tiling_args}) | 544 | data.update({"paramArgs": tiling_args}) |
| @@ -519,6 +557,9 @@ def get_concated_tiling_key(template_param_list: List[TilingTemplateParams], \ | |||
| 519 | return result | 557 | return result |
| 520 | template_param = template_param_list[index] | 558 | template_param = template_param_list[index] |
| 521 | for val in template_param.values: | 559 | for val in template_param.values: |
| 560 | + if kernel_compile_dict and template_param.name in kernel_compile_dict \ | ||
| 561 | + and str(val) not in kernel_compile_dict[template_param.name]: | ||
| 562 | + continue | ||
| 522 | if template_param.param_type == TilingParamType.TPL_TILING_STRUCT: | 563 | if template_param.param_type == TilingParamType.TPL_TILING_STRUCT: |
| 523 | data["tilingStruct"] = template_param.name | 564 | data["tilingStruct"] = template_param.name |
| 524 | encode_ = "" | 565 | encode_ = "" |
| @@ -597,7 +638,47 @@ def extract_decl_param_options(op_info: OpInfo, option_name="dtype"): | |||
| 597 | return decl_input_options + decl_output_options, deck_select_indexes | 638 | return decl_input_options + decl_output_options, deck_select_indexes |
| 598 | 639 | ||
| 599 | 640 | ||
| 641 | +def check_kernel_template_input(kernel_compile_dict_input: dict): | ||
| 642 | + tiling_map_dict = {item.name: item for item in TILING_DECLARE_MAP} | ||
| 643 | + for key, values in kernel_compile_dict_input.items(): | ||
| 644 | + if key not in tiling_map_dict: | ||
| 645 | + raise RuntimeError('kernel-template-input key {} is invalid!'.format(key)) | ||
| 646 | + valid_values = tiling_map_dict[key].values | ||
| 647 | + valid_values_str = set(str(v) for v in valid_values) | ||
| 648 | + for value in values: | ||
| 649 | + if value not in valid_values_str: | ||
| 650 | + raise RuntimeError('kernel-template-input key: {} value: {} is invalid!'.format(key, value)) | ||
| 651 | + | ||
| 652 | + | ||
| 600 | def decode_tiling(tiling_key: int = None) -> dict: | 653 | def decode_tiling(tiling_key: int = None) -> dict: |
| 654 | + global kernel_compile_dict | ||
| 655 | + kernel_template_input = get_context().get_addition("kernel-template-input") | ||
| 656 | + if kernel_template_input and "=" not in kernel_template_input: | ||
| 657 | + raise RuntimeError('Invalid kernel-template-input format! Please use key value pairs!') | ||
| 658 | + if kernel_template_input: | ||
| 659 | + if kernel_template_input.startswith("'") and kernel_template_input.endswith("'"): | ||
| 660 | + kernel_template_input = kernel_template_input[1:-1] | ||
| 661 | + pairs = kernel_template_input.split(';') | ||
| 662 | + for pair in pairs: | ||
| 663 | + if pair.count("=") > 1: | ||
| 664 | + raise RuntimeError('kernel-template-input value has invalid format!') | ||
| 665 | + if '=' in pair: | ||
| 666 | + key, value = pair.split('=', 1) | ||
| 667 | + value_list = value.split(',') | ||
| 668 | + format_value_list = [] | ||
| 669 | + for v in value_list: | ||
| 670 | + if v in ASCENDC_KERNEL_TEMPLATE_INPUT_DATATYPE_MAP.keys(): | ||
| 671 | + format_value_list.append(str(ASCENDC_KERNEL_TEMPLATE_INPUT_DATATYPE_MAP[v])) | ||
| 672 | + elif v == 'false': | ||
| 673 | + format_value_list.append('0') | ||
| 674 | + elif v == 'true': | ||
| 675 | + format_value_list.append('1') | ||
| 676 | + elif v in ASCENDC_KERNEL_TEMPLATE_INPUT_KERNEL_TYPE_MAP.keys(): | ||
| 677 | + format_value_list.append(str(ASCENDC_KERNEL_TEMPLATE_INPUT_KERNEL_TYPE_MAP[v])) | ||
| 678 | + else: | ||
| 679 | + format_value_list.append(v) | ||
| 680 | + kernel_compile_dict[key] = format_value_list | ||
X | |||
| 681 | + check_kernel_template_input(kernel_compile_dict) | ||
| 601 | encode_book = dict() | 682 | encode_book = dict() |
| 602 | for param in TILING_DECLARE_MAP: | 683 | for param in TILING_DECLARE_MAP: |
| 603 | encode_book[param.name] = param.get_encodes() | 684 | encode_book[param.name] = param.get_encodes() |
| @@ -469,6 +469,8 @@ REGISTER_TILING_DEFAULT') | |||
| 469 | extract_template_tiling_info(declare_param_str, select_param_str) | 469 | extract_template_tiling_info(declare_param_str, select_param_str) |
| 470 | decode_tiling_result = decode_tiling() | 470 | decode_tiling_result = decode_tiling() |
| 471 | tiling_key_list = [str(k) for k in decode_tiling_result.keys()] | 471 | tiling_key_list = [str(k) for k in decode_tiling_result.keys()] |
| 472 | + if len(tiling_key_list) == 0: | ||
| 473 | + raise Exception(f'no match kernel template input!') | ||
| 472 | # ==================== All SEL checks | 474 | # ==================== All SEL checks |
| 473 | tiling_key_list, decode_tiling_result = tpl_tilingkey_kernel_type_check( | 475 | tiling_key_list, decode_tiling_result = tpl_tilingkey_kernel_type_check( |
| 474 | tiling_key_list, decode_tiling_result, tiling_key_kernel_type | 476 | tiling_key_list, decode_tiling_result, tiling_key_kernel_type |
| @@ -16,6 +16,7 @@ from enum import Enum, auto | |||
| 16 | from dataclasses import dataclass | 16 | from dataclasses import dataclass |
| 17 | from typing import List, Any | 17 | from typing import List, Any |
| 18 | from asc_op_compile_base.common.utils.log_utils import AscendCLogLevel | 18 | from asc_op_compile_base.common.utils.log_utils import AscendCLogLevel |
| 19 | +from asc_op_compile_base.common.context import get_context | ||
| 19 | from .ascendc_common_utility import CommonUtility | 20 | from .ascendc_common_utility import CommonUtility |
| 20 | from .get_op_tiling import OpInfo | 21 | from .get_op_tiling import OpInfo |
| 21 | 22 | ||
| @@ -58,6 +59,41 @@ ASCENDC_COMPILE_DATATYPE_MAP = { | |||
| 58 | "DT_MAX": ["unknown", ASCENDC_TPL_DATATYPE_MAX], | 59 | "DT_MAX": ["unknown", ASCENDC_TPL_DATATYPE_MAX], |
| 59 | } | 60 | } |
| 60 | ASCENDC_COMPILE_DATATYPE_REVERT_MAP = {v[-1]: v[0] for v in ASCENDC_COMPILE_DATATYPE_MAP.values()} | 61 | ASCENDC_COMPILE_DATATYPE_REVERT_MAP = {v[-1]: v[0] for v in ASCENDC_COMPILE_DATATYPE_MAP.values()} |
| 62 | +ASCENDC_KERNEL_TEMPLATE_INPUT_DATATYPE_MAP = { | ||
C 这些值double check下 ![]() ![]() | |||
| 63 | + "float": 0, | ||
| 64 | + "half": 1, | ||
| 65 | + "int8_t": 2, | ||
| 66 | + "int32_t": 3, | ||
| 67 | + "uint8_t": 4, | ||
| 68 | + "int16_t": 6, | ||
| 69 | + "uint16_t": 7, | ||
| 70 | + "uint32_t": 8, | ||
| 71 | + "int64_t": 9, | ||
| 72 | + "uint64_t": 10, | ||
| 73 | + "double": 11, | ||
| 74 | + "bool": 12, | ||
| 75 | + "complex64": 16, | ||
| 76 | + "bfloat16_t": 27, | ||
| 77 | + "int4b_t": 29, | ||
| 78 | + "hifloat8_t": 34, | ||
| 79 | + "fp8_e5m2_t": 35, | ||
| 80 | + "fp8_e4m3fn_t": 36, | ||
| 81 | + "fp4x2_e2m1_t": 40, | ||
| 82 | + "fp4x2_e1m2_t": 41 | ||
| 83 | +} | ||
| 84 | +ASCENDC_KERNEL_TEMPLATE_INPUT_KERNEL_TYPE_MAP = { | ||
| 85 | + "ASCENDC_TPL_AIV_ONLY": 0, | ||
| 86 | + "ASCENDC_TPL_AIC_ONLY": 1, | ||
| 87 | + "ASCENDC_TPL_MIX_AIV_1_0": 4, | ||
| 88 | + "ASCENDC_TPL_MIX_AIC_1_0": 5, | ||
| 89 | + "ASCENDC_TPL_MIX_AIC_1_1": 6, | ||
| 90 | + "ASCENDC_TPL_MIX_AIC_1_2": 7, | ||
| 91 | + "ASCENDC_TPL_AICORE": 8, | ||
| 92 | + "ASCENDC_TPL_VECTORCORE": 9, | ||
| 93 | + "ASCENDC_TPL_MIX_AICORE": 10, | ||
| 94 | + "ASCENDC_TPL_MIX_VECTOR_CORE": 11, | ||
| 95 | + "ASCENDC_TPL_MAX": 12 | ||
| 96 | +} | ||
| 61 | ASCENDC_TPL_DATAFORMAT_MAX = 55 | 97 | ASCENDC_TPL_DATAFORMAT_MAX = 55 |
| 62 | ASCENDC_COMPILE_DATAFORMAT_MAP = { | 98 | ASCENDC_COMPILE_DATAFORMAT_MAP = { |
| 63 | "FORMAT_NCHW": ["NCHW", 0], | 99 | "FORMAT_NCHW": ["NCHW", 0], |
| @@ -494,6 +530,7 @@ def extract_template_tiling_params(tiling_param_list: List[str], bit_map: dict = | |||
| 494 | GROUP_ID = 0 | 530 | GROUP_ID = 0 |
| 495 | ID_LIST = [] | 531 | ID_LIST = [] |
| 496 | group_map = {} | 532 | group_map = {} |
| 533 | +kernel_compile_dict = {} | ||
| 497 | 534 | ||
| 498 | 535 | ||
| 499 | def get_concated_tiling_key(template_param_list: List[TilingTemplateParams], \ | 536 | def get_concated_tiling_key(template_param_list: List[TilingTemplateParams], \ |
| @@ -501,6 +538,7 @@ def get_concated_tiling_key(template_param_list: List[TilingTemplateParams], \ | |||
| 501 | global ID_LIST | 538 | global ID_LIST |
| 502 | global GROUP_ID | 539 | global GROUP_ID |
| 503 | global group_map | 540 | global group_map |
| 541 | + global kernel_compile_dict | ||
| 504 | result = dict() | 542 | result = dict() |
| 505 | if index == len(template_param_list): | 543 | if index == len(template_param_list): |
| 506 | data.update({"paramArgs": tiling_args}) | 544 | data.update({"paramArgs": tiling_args}) |
| @@ -519,6 +557,9 @@ def get_concated_tiling_key(template_param_list: List[TilingTemplateParams], \ | |||
| 519 | return result | 557 | return result |
| 520 | template_param = template_param_list[index] | 558 | template_param = template_param_list[index] |
| 521 | for val in template_param.values: | 559 | for val in template_param.values: |
| 560 | + if kernel_compile_dict and template_param.name in kernel_compile_dict \ | ||
| 561 | + and str(val) not in kernel_compile_dict[template_param.name]: | ||
| 562 | + continue | ||
| 522 | if template_param.param_type == TilingParamType.TPL_TILING_STRUCT: | 563 | if template_param.param_type == TilingParamType.TPL_TILING_STRUCT: |
| 523 | data["tilingStruct"] = template_param.name | 564 | data["tilingStruct"] = template_param.name |
| 524 | encode_ = "" | 565 | encode_ = "" |
| @@ -597,7 +638,47 @@ def extract_decl_param_options(op_info: OpInfo, option_name="dtype"): | |||
| 597 | return decl_input_options + decl_output_options, deck_select_indexes | 638 | return decl_input_options + decl_output_options, deck_select_indexes |
| 598 | 639 | ||
| 599 | 640 | ||
| 641 | +def check_kernel_template_input(kernel_compile_dict_input: dict): | ||
| 642 | + tiling_map_dict = {item.name: item for item in TILING_DECLARE_MAP} | ||
| 643 | + for key, values in kernel_compile_dict_input.items(): | ||
| 644 | + if key not in tiling_map_dict: | ||
| 645 | + raise RuntimeError('kernel-template-input key {} is invalid!'.format(key)) | ||
| 646 | + valid_values = tiling_map_dict[key].values | ||
| 647 | + valid_values_str = set(str(v) for v in valid_values) | ||
| 648 | + for value in values: | ||
| 649 | + if value not in valid_values_str: | ||
| 650 | + raise RuntimeError('kernel-template-input key: {} value: {} is invalid!'.format(key, value)) | ||
| 651 | + | ||
| 652 | + | ||
| 600 | def decode_tiling(tiling_key: int = None) -> dict: | 653 | def decode_tiling(tiling_key: int = None) -> dict: |
| 654 | + global kernel_compile_dict | ||
| 655 | + kernel_template_input = get_context().get_addition("kernel-template-input") | ||
| 656 | + if kernel_template_input and "=" not in kernel_template_input: | ||
| 657 | + raise RuntimeError('Invalid kernel-template-input format! Please use key value pairs!') | ||
| 658 | + if kernel_template_input: | ||
| 659 | + if kernel_template_input.startswith("'") and kernel_template_input.endswith("'"): | ||
| 660 | + kernel_template_input = kernel_template_input[1:-1] | ||
| 661 | + pairs = kernel_template_input.split(';') | ||
| 662 | + for pair in pairs: | ||
| 663 | + if pair.count("=") > 1: | ||
| 664 | + raise RuntimeError('kernel-template-input value has invalid format!') | ||
| 665 | + if '=' in pair: | ||
| 666 | + key, value = pair.split('=', 1) | ||
| 667 | + value_list = value.split(',') | ||
| 668 | + format_value_list = [] | ||
| 669 | + for v in value_list: | ||
| 670 | + if v in ASCENDC_KERNEL_TEMPLATE_INPUT_DATATYPE_MAP.keys(): | ||
| 671 | + format_value_list.append(str(ASCENDC_KERNEL_TEMPLATE_INPUT_DATATYPE_MAP[v])) | ||
| 672 | + elif v == 'false': | ||
| 673 | + format_value_list.append('0') | ||
| 674 | + elif v == 'true': | ||
| 675 | + format_value_list.append('1') | ||
| 676 | + elif v in ASCENDC_KERNEL_TEMPLATE_INPUT_KERNEL_TYPE_MAP.keys(): | ||
| 677 | + format_value_list.append(str(ASCENDC_KERNEL_TEMPLATE_INPUT_KERNEL_TYPE_MAP[v])) | ||
| 678 | + else: | ||
| 679 | + format_value_list.append(v) | ||
| 680 | + kernel_compile_dict[key] = format_value_list | ||
| 681 | + check_kernel_template_input(kernel_compile_dict) | ||
| 601 | encode_book = dict() | 682 | encode_book = dict() |
| 602 | for param in TILING_DECLARE_MAP: | 683 | for param in TILING_DECLARE_MAP: |
| 603 | encode_book[param.name] = param.get_encodes() | 684 | encode_book[param.name] = param.get_encodes() |
| @@ -100,6 +100,7 @@ class OpcOptions: | |||
| 100 | OPTIONAL_OUTPUT_MODE = "optional_output_mode" | 100 | OPTIONAL_OUTPUT_MODE = "optional_output_mode" |
| 101 | RELOCATABLE_BIN = "op_relocatable_kernel_binary" | 101 | RELOCATABLE_BIN = "op_relocatable_kernel_binary" |
| 102 | SPK_OPT = "op_super_kernel_options" | 102 | SPK_OPT = "op_super_kernel_options" |
| 103 | + KERNEL_TEMPLATE_INPUT = "kernel-template-input" | ||
| 103 | 104 | ||
| 104 | OpcOptionDefaultValueDict = { | 105 | OpcOptionDefaultValueDict = { |
| 105 | OUTPUT : "", | 106 | OUTPUT : "", |
| @@ -194,6 +194,7 @@ class OpcOptionParser: | |||
| 194 | self.__define_option(OpcOptions.TILING_KEY, None, "tiling key list.") | 194 | self.__define_option(OpcOptions.TILING_KEY, None, "tiling key list.") |
| 195 | self.__define_option(OpcOptions.RELOCATABLE_BIN, "False", "op_relocatable_kernel_binary mode.") | 195 | self.__define_option(OpcOptions.RELOCATABLE_BIN, "False", "op_relocatable_kernel_binary mode.") |
| 196 | self.__define_option(OpcOptions.SPK_OPT, "", "SPK sub kernel compile options.") | 196 | self.__define_option(OpcOptions.SPK_OPT, "", "SPK sub kernel compile options.") |
| 197 | + self.__define_option(OpcOptions.KERNEL_TEMPLATE_INPUT, "", "kernel template input.") | ||
| 197 | 198 | ||
| 198 | 199 | ||
| 199 | def usage(): | 200 | def usage(): |
| @@ -265,6 +266,7 @@ class OpcOptionParser: | |||
| 265 | " --op_super_kernel_options Set super kernel options. \n" | 266 | " --op_super_kernel_options Set super kernel options. \n" |
| 266 | " For expl: --op_super_kernel_options=aaa,bbb \n" | 267 | " For expl: --op_super_kernel_options=aaa,bbb \n" |
| 267 | " if not set, use empty str as default. \n" | 268 | " if not set, use empty str as default. \n" |
| 269 | + " --kernel-template-input Set specific kernel compilation. \n" | ||
| 268 | ) | 270 | ) |
| 269 | 271 | ||
| 270 | 272 | ||
| @@ -519,6 +521,11 @@ class OpcOptionParser: | |||
| 519 | logger.warn("Invalid tiling_key list {}.".format(tiling_key_str)) | 521 | logger.warn("Invalid tiling_key list {}.".format(tiling_key_str)) |
| 520 | self.set_option(OpcOptions.TILING_KEY, tiling_key_list) | 522 | self.set_option(OpcOptions.TILING_KEY, tiling_key_list) |
| 521 | logger.info("Save tiling_key list {}.".format(tiling_key_list)) | 523 | logger.info("Save tiling_key list {}.".format(tiling_key_list)) |
| 524 | + | ||
| 525 | + def check_and_save_kernel_template_input(self): | ||
| 526 | + kernel_template_input_str = self.get_option(OpcOptions.KERNEL_TEMPLATE_INPUT) | ||
| 527 | + if kernel_template_input_str is not None: | ||
| 528 | + self.set_option(OpcOptions.KERNEL_TEMPLATE_INPUT, kernel_template_input_str) | ||
| 522 | 529 | ||
| 523 | def check_op_relocatable_cfg(self): | 530 | def check_op_relocatable_cfg(self): |
| 524 | """ | 531 | """ |
| @@ -624,6 +631,7 @@ class OpcOptionParser: | |||
| 624 | 631 | ||
| 625 | self.check_and_save_tiling_key() | 632 | self.check_and_save_tiling_key() |
| 626 | self.check_op_relocatable_cfg() | 633 | self.check_op_relocatable_cfg() |
| 634 | + self.check_and_save_kernel_template_input() | ||
| 627 | return True | 635 | return True |
| 628 | 636 | ||
| 629 | def parse_args(): | 637 | def parse_args(): |
| @@ -37,7 +37,7 @@ compiling_option_keys = [ | |||
| 37 | OpcOptions.DEBUG_DIR, OpcOptions.CORE_TYPE, OpcOptions.GRAPH, OpcOptions.BIN_FILENAME, OpcOptions.AICORE_NUM, | 37 | OpcOptions.DEBUG_DIR, OpcOptions.CORE_TYPE, OpcOptions.GRAPH, OpcOptions.BIN_FILENAME, OpcOptions.AICORE_NUM, |
| 38 | OpcOptions.LOG, OpcOptions.OPTIONAL_INPUT_MODE, | 38 | OpcOptions.LOG, OpcOptions.OPTIONAL_INPUT_MODE, |
| 39 | OpcOptions.OPTIONAL_OUTPUT_MODE, OpcOptions.OP_MODE, OpcOptions.SIMPLE_KEY_MODE, OpcOptions.DYNAMIC_PARAM_MODE, | 39 | OpcOptions.OPTIONAL_OUTPUT_MODE, OpcOptions.OP_MODE, OpcOptions.SIMPLE_KEY_MODE, OpcOptions.DYNAMIC_PARAM_MODE, |
| 40 | - OpcOptions.TILING_KEY, OpcOptions.RELOCATABLE_BIN, OpcOptions.SPK_OPT | 40 | + OpcOptions.TILING_KEY, OpcOptions.RELOCATABLE_BIN, OpcOptions.SPK_OPT, OpcOptions.KERNEL_TEMPLATE_INPUT |
| 41 | ] | 41 | ] |
| 42 | 42 | ||
| 43 | valid_format_match_mode = ["FormatAgnostic", "FormatDefault", "FormatFixed", None] | 43 | valid_format_match_mode = ["FormatAgnostic", "FormatDefault", "FormatFixed", None] |
| @@ -129,6 +129,7 @@ class SingleOpCompile: | |||
| 129 | str(kwargs), str(opt_input_mode), str(opt_output_mode), str(dyn_param_mode), | 129 | str(kwargs), str(opt_input_mode), str(opt_output_mode), str(dyn_param_mode), |
| 130 | str(sub_kernel_option), str(output_path)) | 130 | str(sub_kernel_option), str(output_path)) |
| 131 | tiling_key_list = self.__opc_compile_args.get(OpcOptions.TILING_KEY) | 131 | tiling_key_list = self.__opc_compile_args.get(OpcOptions.TILING_KEY) |
| 132 | + kernel_template_input = self.__opc_compile_args.get(OpcOptions.KERNEL_TEMPLATE_INPUT) | ||
| 132 | if self.__op_info.get(OpcOptions.IS_DYNAMIC) or \ | 133 | if self.__op_info.get(OpcOptions.IS_DYNAMIC) or \ |
| 133 | self.__opc_compile_args.get(OpcOptions.OP_MODE) == OpModeType.DYNAMIC: | 134 | self.__opc_compile_args.get(OpcOptions.OP_MODE) == OpModeType.DYNAMIC: |
| 134 | with op_context.OpContext("dynamic"): | 135 | with op_context.OpContext("dynamic"): |
| @@ -140,6 +141,7 @@ class SingleOpCompile: | |||
| 140 | context.add_addition(OpcOptions.TILING_KEY, tiling_key_list) | 141 | context.add_addition(OpcOptions.TILING_KEY, tiling_key_list) |
| 141 | context.add_addition(OpcOptions.SPK_OPT, sub_kernel_option) | 142 | context.add_addition(OpcOptions.SPK_OPT, sub_kernel_option) |
| 142 | context.add_addition(OpcOptions.OUTPUT, output_path) | 143 | context.add_addition(OpcOptions.OUTPUT, output_path) |
| 144 | + context.add_addition(OpcOptions.KERNEL_TEMPLATE_INPUT, kernel_template_input) | ||
| 143 | op_func(*inputs, *outputs, *new_attrs, self.__op_info.get(OpcOptions.KERNEL_NAME), **kwargs) | 145 | op_func(*inputs, *outputs, *new_attrs, self.__op_info.get(OpcOptions.KERNEL_NAME), **kwargs) |
| 144 | 146 | ||
| 145 | # fetch json file path for build result. | 147 | # fetch json file path for build result. |
| @@ -161,6 +163,7 @@ class SingleOpCompile: | |||
| 161 | context.add_addition(OpcOptions.TILING_KEY, tiling_key_list) | 163 | context.add_addition(OpcOptions.TILING_KEY, tiling_key_list) |
| 162 | context.add_addition(OpcOptions.SPK_OPT, sub_kernel_option) | 164 | context.add_addition(OpcOptions.SPK_OPT, sub_kernel_option) |
| 163 | context.add_addition(OpcOptions.OUTPUT, output_path) | 165 | context.add_addition(OpcOptions.OUTPUT, output_path) |
| 166 | + context.add_addition(OpcOptions.KERNEL_TEMPLATE_INPUT, kernel_template_input) | ||
| 164 | op_func(*inputs, *outputs, *new_attrs, self.__op_info.get(OpcOptions.KERNEL_NAME), **kwargs) | 167 | op_func(*inputs, *outputs, *new_attrs, self.__op_info.get(OpcOptions.KERNEL_NAME), **kwargs) |
| 165 | 168 | ||
| 166 | # fetch json file path for build result. | 169 | # fetch json file path for build result. |
| @@ -180,6 +183,7 @@ class SingleOpCompile: | |||
| 180 | context.add_addition(OpcOptions.TILING_KEY, tiling_key_list) | 183 | context.add_addition(OpcOptions.TILING_KEY, tiling_key_list) |
| 181 | context.add_addition(OpcOptions.SPK_OPT, sub_kernel_option) | 184 | context.add_addition(OpcOptions.SPK_OPT, sub_kernel_option) |
| 182 | context.add_addition(OpcOptions.OUTPUT, output_path) | 185 | context.add_addition(OpcOptions.OUTPUT, output_path) |
| 186 | + context.add_addition(OpcOptions.KERNEL_TEMPLATE_INPUT, kernel_template_input) | ||
| 183 | op_func(*inputs, *outputs, *new_attrs, self.__op_info.get(OpcOptions.KERNEL_NAME), **kwargs) | 187 | op_func(*inputs, *outputs, *new_attrs, self.__op_info.get(OpcOptions.KERNEL_NAME), **kwargs) |
| 184 | 188 | ||
| 185 | # fetch json file path for build result. | 189 | # fetch json file path for build result. |


是否缺少check_kernel_template_input校验,adapter和asc_op_compiler代码都不一致