已合并
[bugfix] Read DVM config dynamically #44514
SorryNaCN创建于 25 天前
[bugfix] Read DVM config dynamically #44514
已合并
共 4 个文件变更+14-18
| @@ -15,7 +15,7 @@ from torch_npu.npu._backends import get_soc_version | |||
| 15 | 15 | ||
| 16 | from torch_npu._inductor.npu_compare import check_accuracy_dvm | 16 | from torch_npu._inductor.npu_compare import check_accuracy_dvm |
| 17 | 17 | ||
| 18 | -from .config import bf16_vector_keep_promoted, debug_mode | 18 | +from . import config as dvm_config |
| 19 | 19 | ||
| 20 | 20 | ||
| 21 | bool_ = DataType.bool | 21 | bool_ = DataType.bool |
| @@ -114,7 +114,7 @@ def kernel( | |||
| 114 | 114 | ||
| 115 | def fn(*args, **kwargs): | 115 | def fn(*args, **kwargs): |
| 116 | outputs = kobj(*args) | 116 | outputs = kobj(*args) |
| 117 | - if debug_mode: | 117 | + if dvm_config.debug_mode: |
| 118 | _post_run(args) | 118 | _post_run(args) |
| 119 | return outputs | 119 | return outputs |
| 120 | 120 | ||
| @@ -123,7 +123,7 @@ def kernel( | |||
| 123 | check_accuracy_dvm(kobj, fn._acc_meta, kernel_name, args) | 123 | check_accuracy_dvm(kobj, fn._acc_meta, kernel_name, args) |
| 124 | else: | 124 | else: |
| 125 | kobj.run(*args) | 125 | kobj.run(*args) |
| 126 | - if debug_mode: | 126 | + if dvm_config.debug_mode: |
| 127 | _post_run(args) | 127 | _post_run(args) |
| 128 | 128 | ||
| 129 | fn.run = run | 129 | fn.run = run |
| @@ -182,7 +182,7 @@ def _install_bf16_promote(): | |||
| 182 | 182 | ||
| 183 | new_args = tuple(maybe_cast_arg(a) for a in args) | 183 | new_args = tuple(maybe_cast_arg(a) for a in args) |
| 184 | out = op_fn(self, *new_args) | 184 | out = op_fn(self, *new_args) |
| 185 | - if bf16_vector_keep_promoted and need_cast_back : | 185 | + if dvm_config.bf16_vector_keep_promoted and need_cast_back: |
| 186 | out = self.cast(out, bfloat16) | 186 | out = self.cast(out, bfloat16) |
| 187 | return out | 187 | return out |
| 188 | 188 | ||
| @@ -19,7 +19,7 @@ from torch.fx.passes.utils.fuser_utils import ( | |||
| 19 | erase_nodes, | 19 | erase_nodes, |
| 20 | ) | 20 | ) |
| 21 | 21 | ||
| 22 | -from .config import dump_fx_test | 22 | +from . import config as dvm_config |
| 23 | from .graph_build import DvmCodegenInterpreter, is_fx_dynamic | 23 | from .graph_build import DvmCodegenInterpreter, is_fx_dynamic |
| 24 | from .util import patch_gm_placeholder_strides_from_codegen_args | 24 | from .util import patch_gm_placeholder_strides_from_codegen_args |
| 25 | from .fx_test import generate_dvm_fx_case | 25 | from .fx_test import generate_dvm_fx_case |
| @@ -160,7 +160,7 @@ class _FusedMeta: | |||
| 160 | """ | 160 | """ |
| 161 | Return (codegen_interpreter, python_source_string). | 161 | Return (codegen_interpreter, python_source_string). |
| 162 | """ | 162 | """ |
| 163 | - if dump_fx_test: | 163 | + if dvm_config.dump_fx_test: |
| 164 | generate_dvm_fx_case(self.gm, fusion_type="graph") | 164 | generate_dvm_fx_case(self.gm, fusion_type="graph") |
| 165 | cg = DvmCodegenInterpreter(self.gm, ktype="split") | 165 | cg = DvmCodegenInterpreter(self.gm, ktype="split") |
| 166 | cg.run() | 166 | cg.run() |
| @@ -25,11 +25,7 @@ from torch_npu._inductor.ascend_npu_ir.ascend_npu_ir.npu.utils import ( | |||
| 25 | get_num_call_functions, | 25 | get_num_call_functions, |
| 26 | ) | 26 | ) |
| 27 | 27 | ||
| 28 | -from .config import ( | 28 | +from . import config as dvm_config |
| 29 | - disable_post_reduce_fusion, | ||
| 30 | - dump_fx_test, | ||
| 31 | - enable_matmul_fusion, | ||
| 32 | -) | ||
| 33 | from .decomp import patch_decomp | 29 | from .decomp import patch_decomp |
| 34 | from .fx_test import generate_dvm_fx_case | 30 | from .fx_test import generate_dvm_fx_case |
| 35 | from .graph_build import DvmCodegenInterpreter | 31 | from .graph_build import DvmCodegenInterpreter |
| @@ -194,7 +190,7 @@ class NpuDvmScheduling(NpuMetaScheduling): | |||
| 194 | ) | 190 | ) |
| 195 | else: | 191 | else: |
| 196 | wrapper.add_import_once("from torch_npu._inductor import dvm") | 192 | wrapper.add_import_once("from torch_npu._inductor import dvm") |
| 197 | - if dump_fx_test: | 193 | + if dvm_config.dump_fx_test: |
| 198 | generate_dvm_fx_case(mlir_kernel._gm, fusion_type="mlir") | 194 | generate_dvm_fx_case(mlir_kernel._gm, fusion_type="mlir") |
| 199 | code = mlir_kernel.dvm_codegen.code | 195 | code = mlir_kernel.dvm_codegen.code |
| 200 | code.splice( | 196 | code.splice( |
| @@ -241,7 +237,7 @@ class NpuDvmScheduling(NpuMetaScheduling): | |||
| 241 | return can_fuse_dvm_epilogue(node1, node2) | 237 | return can_fuse_dvm_epilogue(node1, node2) |
| 242 | if isinstance(template2, DvmTemplateBuffer): | 238 | if isinstance(template2, DvmTemplateBuffer): |
| 243 | return False | 239 | return False |
| 244 | - if not disable_post_reduce_fusion: | 240 | + if not dvm_config.disable_post_reduce_fusion: |
| 245 | return super().can_fuse_vertical(node1, node2) | 241 | return super().can_fuse_vertical(node1, node2) |
| 246 | 242 | ||
| 247 | _, (numel1, rnumel1) = node1.group | 243 | _, (numel1, rnumel1) = node1.group |
| @@ -274,7 +270,7 @@ class NpuDvmScheduling(NpuMetaScheduling): | |||
| 274 | template2, DvmTemplateBuffer | 270 | template2, DvmTemplateBuffer |
| 275 | ): | 271 | ): |
| 276 | return False | 272 | return False |
| 277 | - if not disable_post_reduce_fusion: | 273 | + if not dvm_config.disable_post_reduce_fusion: |
| 278 | return super().can_fuse_horizontal(node1, node2) | 274 | return super().can_fuse_horizontal(node1, node2) |
| 279 | return False | 275 | return False |
| 280 | 276 | ||
| @@ -444,7 +440,7 @@ class DvmMlirFusionPatch: | |||
| 444 | patch_decomp() | 440 | patch_decomp() |
| 445 | _patch_lowering_type_checks() | 441 | _patch_lowering_type_checks() |
| 446 | _patch_lowering() | 442 | _patch_lowering() |
| 447 | - if enable_matmul_fusion: | 443 | + if dvm_config.enable_matmul_fusion: |
| 448 | patch_dvm_matmul_template_fusion() | 444 | patch_dvm_matmul_template_fusion() |
| 449 | register_backend_for_device( | 445 | register_backend_for_device( |
| 450 | "npu", NpuDvmScheduling, NpuMlirWrapperCodeGen | 446 | "npu", NpuDvmScheduling, NpuMlirWrapperCodeGen |
| @@ -7,7 +7,7 @@ from typing import Sequence | |||
| 7 | import torch | 7 | import torch |
| 8 | from torch._inductor.virtualized import V | 8 | from torch._inductor.virtualized import V |
| 9 | 9 | ||
| 10 | -from .config import view_fusion_level | 10 | +from . import config as dvm_config |
| 11 | from .op_emitter import load, view_load | 11 | from .op_emitter import load, view_load |
| 12 | 12 | ||
| 13 | 13 | ||
| @@ -49,10 +49,10 @@ def codegen_maybe_view_load( | |||
| 49 | skip_cont=False means the caller must manually materialize a non-contiguous | 49 | skip_cont=False means the caller must manually materialize a non-contiguous |
| 50 | input with .contiguous() before launching the DVM kernel. | 50 | input with .contiguous() before launching the DVM kernel. |
| 51 | """ | 51 | """ |
| 52 | - if view_fusion_level == 0: | 52 | + if dvm_config.view_fusion_level == 0: |
| 53 | return load(shape, dtype), False | 53 | return load(shape, dtype), False |
| 54 | 54 | ||
| 55 | - if view_fusion_level == 2: | 55 | + if dvm_config.view_fusion_level == 2: |
| 56 | return view_load(shape, stride, dtype), True | 56 | return view_load(shape, stride, dtype), True |
| 57 | 57 | ||
| 58 | if is_symbolic: | 58 | if is_symbolic: |