From 00d7a2147b339755d89d816c8b5228cd429012da Mon Sep 17 00:00:00 2001 From: CLAY-panjw <1330286576@qq.com> Date: Wed, 12 Oct 2022 16:44:13 +0800 Subject: [PATCH] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E5=8F=82=E6=95=B0aoe=5Fconfi?= =?UTF-8?q?g=5Ffile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tf_adapter/interface_spec/api_npu_config.pyh | 2 +- .../npu_bridge/estimator/npu/npu_config.py | 4 +++- .../npu_bridge/estimator/npu/npu_estimator.py | 2 ++ .../npu_bridge/estimator/npu/npu_plugin.py | 4 +++- tf_adapter/util/npu_attrs.cc | 17 +++++++++++++++++ tf_adapter_2.x/npu_device/core/npu_wrapper.cpp | 1 + .../python/npu_device/configs/aoe_config.py | 1 + 7 files changed, 28 insertions(+), 3 deletions(-) diff --git a/tf_adapter/interface_spec/api_npu_config.pyh b/tf_adapter/interface_spec/api_npu_config.pyh index 521ec8da0..1f9298a35 100644 --- a/tf_adapter/interface_spec/api_npu_config.pyh +++ b/tf_adapter/interface_spec/api_npu_config.pyh @@ -18,7 +18,7 @@ class NPURunConfig(run_config_lib.RunConfig): distribute_config=None, modify_mixlist=None, op_precision_mode=None, device_type="default_device_type", soc_config=None, hccl_timeout=None, op_wait_timeout=None, op_execute_timeout=None, HCCL_algorithm=None, customize_dtypes=None, op_debug_config=None, memory_config=None, experimental_config=None, - jit_compile=True, topo_sorting_mode=None): + jit_compile=True, topo_sorting_mode=None, aoe_config_file=None): class ProfilingConfig(): def __init__(self, enable_profiling=False, profiling_options=None): diff --git a/tf_adapter/python/npu_bridge/estimator/npu/npu_config.py b/tf_adapter/python/npu_bridge/estimator/npu/npu_config.py index 5781a3136..d776970db 100644 --- a/tf_adapter/python/npu_bridge/estimator/npu/npu_config.py +++ b/tf_adapter/python/npu_bridge/estimator/npu/npu_config.py @@ -101,7 +101,8 @@ class NPURunConfig(run_config_lib.RunConfig): memory_config=None, experimental_config=None, jit_compile=True, - topo_sorting_mode=None + topo_sorting_mode=None, + aoe_config_file=None ): """ Constructs a NPUConfig. @@ -242,6 +243,7 @@ class NPURunConfig(run_config_lib.RunConfig): self._experimental_config = self._get_experimental_config(experimental_config) self._jit_compile = jit_compile self.topo_sorting_mode = topo_sorting_mode + self.aoe_config_file = aoe_config_file super(NPURunConfig, self).__init__( diff --git a/tf_adapter/python/npu_bridge/estimator/npu/npu_estimator.py b/tf_adapter/python/npu_bridge/estimator/npu/npu_estimator.py index b1bb1cc51..444da8406 100644 --- a/tf_adapter/python/npu_bridge/estimator/npu/npu_estimator.py +++ b/tf_adapter/python/npu_bridge/estimator/npu/npu_estimator.py @@ -676,6 +676,8 @@ class NPUEstimator(estimator_lib.Estimator): custom_op.parameter_map["work_path"].s = tf.compat.as_bytes("./") if config._distribute_config is not None: custom_op.parameter_map["distribute_config"].s = tf.compat.as_bytes(config._distribute_config) + if config.aoe_config_file is not None: + custom_op.parameter_map["aoe_config_file"].s = tf.compat.as_bytes(config.aoe_config_file) def __load_graph_optimizers(self, config): """ diff --git a/tf_adapter/python/npu_bridge/estimator/npu/npu_plugin.py b/tf_adapter/python/npu_bridge/estimator/npu/npu_plugin.py index 932cbcdb0..b01a092f7 100644 --- a/tf_adapter/python/npu_bridge/estimator/npu/npu_plugin.py +++ b/tf_adapter/python/npu_bridge/estimator/npu/npu_plugin.py @@ -72,7 +72,8 @@ def npu_resource_init(graph_run_mode=1, op_compiler_cache_dir=None, debug_dir=None, hcom_multi_mode=False, - distribute_config=None): + distribute_config=None, + aoe_config_file=None): """Initialize NPU resource""" util.check_nonnegative_integer(graph_run_mode, "graph_run_mode") check_graph_run_mode(graph_run_mode) @@ -123,6 +124,7 @@ def npu_resource_init(graph_run_mode=1, util.check_bool_type(hcom_multi_mode, "hcom_multi_mode") hcom_multi_mode = util.convert_bool_to_int(hcom_multi_mode) init["ge.hcomMultiMode"] = str(hcom_multi_mode) + init["ge.aoe_config_file"] = str(aoe_config_file) init_options = tf_adapter.map_string_string(init) tf_adapter.PluginInit(init_options) diff --git a/tf_adapter/util/npu_attrs.cc b/tf_adapter/util/npu_attrs.cc index 25d177fbc..d14ab4cbd 100644 --- a/tf_adapter/util/npu_attrs.cc +++ b/tf_adapter/util/npu_attrs.cc @@ -556,6 +556,7 @@ std::map NpuAttrs::GetInitOptions(const OpKernelConstr std::string logical_device_cluster_deploy_mode = "LB"; std::string logical_device_id; std::string dump_data = "tensor"; + std::string aoe_config_file; if (ctx != nullptr && ctx->GetAttr("_NpuOptimizer", &npuOptimizer) == Status::OK()) { (void) ctx->GetAttr("_precision_mode", &precision_mode); @@ -589,6 +590,7 @@ std::map NpuAttrs::GetInitOptions(const OpKernelConstr (void) ctx->GetAttr("_logical_device_cluster_deploy_mode", &logical_device_cluster_deploy_mode); (void) ctx->GetAttr("_logical_device_id", &logical_device_id); (void) ctx->GetAttr("_dump_data", &dump_data); + (void) ctx->GetAttr("_aoe_config_file", &aoe_config_file); } if (precision_mode.empty()) { @@ -633,6 +635,8 @@ std::map NpuAttrs::GetInitOptions(const OpKernelConstr init_options_["ge.exec.logicalDeviceId"] = logical_device_id; init_options_["dump_data"] = dump_data; init_options_["ge.exec.dumpData"] = dump_data; + init_options_["aoe_config_file"] = aoe_config_file; + init_options_["ge.aoe_config_file"] = aoe_config_file; return init_options_; } @@ -997,6 +1001,7 @@ std::map NpuAttrs::GetAllAttrOptions(const AttrSlice & std::string jit_compile = "1"; std::string topo_sorting_mode; std::string resource_config_path; + std::string aoe_config_file; auto NpuOptimizer_value = attrs.Find("_NpuOptimizer"); auto enable_data_pre_proc_value = attrs.Find("_enable_data_pre_proc"); @@ -1070,6 +1075,7 @@ std::map NpuAttrs::GetAllAttrOptions(const AttrSlice & auto jit_compile_value = attrs.Find("_jit_compile"); auto topo_sorting_mode_value = attrs.Find("_topo_sorting_mode"); auto resource_config_path_value = attrs.Find("_resource_config_path"); + auto aoe_config_file_value = attrs.Find("_aoe_config_file"); if (NpuOptimizer_value != nullptr) { do_npu_optimizer = "1"; @@ -1313,6 +1319,9 @@ std::map NpuAttrs::GetAllAttrOptions(const AttrSlice & if (dump_layer_value != nullptr) { dump_layer = dump_layer_value->s(); } + if (aoe_config_file_value != nullptr) { + aoe_config_file = aoe_config_file_value->s(); + } } all_options["variable_format_optimize"] = variable_format_optimize; @@ -1397,6 +1406,8 @@ std::map NpuAttrs::GetAllAttrOptions(const AttrSlice & all_options["topo_sorting_mode"] = topo_sorting_mode; all_options["ge.topoSortingMode"] = topo_sorting_mode; all_options["resource_config_path"] = resource_config_path; + all_options["ge.aoe_config_file"] = aoe_config_file; + all_options["aoe_config_file"] = aoe_config_file; return all_options; } @@ -1491,6 +1502,7 @@ Status NpuAttrs::SetNpuOptimizerAttr(const GraphOptimizationPassOptions &options std::string logical_device_cluster_deploy_mode = "LB"; std::string logical_device_id; bool jit_compile = true; + std::string aoe_config_file; const RewriterConfig &rewrite_options = options.session_options->config.graph_options().rewrite_options(); @@ -1867,6 +1879,9 @@ Status NpuAttrs::SetNpuOptimizerAttr(const GraphOptimizationPassOptions &options if (params.count("dump_layer") > 0) { dump_layer = params.at("dump_layer").s(); } + if (params.count("aoe_config_file") > 0) { + aoe_config_file = params.at("aoe_config_file").s(); + } } } @@ -1978,6 +1993,8 @@ Status NpuAttrs::SetNpuOptimizerAttr(const GraphOptimizationPassOptions &options init_options_["ge.exec.logicalDeviceId"] = logical_device_id; init_options_["dump_data"] = dump_data; init_options_["ge.exec.dumpData"] = dump_data; + init_options_["aoe_config_file"] = aoe_config_file; + init_options_["ge.aoe_config_file"] = aoe_config_file; pass_options["do_npu_optimizer"] = std::to_string(static_cast(do_npu_optimizer)); pass_options["enable_data_pre_proc"] = std::to_string(static_cast(enable_dp)); diff --git a/tf_adapter_2.x/npu_device/core/npu_wrapper.cpp b/tf_adapter_2.x/npu_device/core/npu_wrapper.cpp index 19e3819cc..187e60d5a 100644 --- a/tf_adapter_2.x/npu_device/core/npu_wrapper.cpp +++ b/tf_adapter_2.x/npu_device/core/npu_wrapper.cpp @@ -107,6 +107,7 @@ const std::map kConfigurableOptions = { {"customize_dtypes", "ge.customizeDtypes"}, {"dump_data", "ge.exec.dumpData"}, {"dump_layer", "ge.exec.dumpLayer"}, + {"aoe_config_file", "ge.aoe_config_file"}, // private options {"_distribute.rank_id", ge::OPTION_EXEC_RANK_ID}, {"_distribute.rank_table", ge::OPTION_EXEC_RANK_TABLE_FILE}, diff --git a/tf_adapter_2.x/python/npu_device/configs/aoe_config.py b/tf_adapter_2.x/python/npu_device/configs/aoe_config.py index 6115cbb95..cba7a4e52 100644 --- a/tf_adapter_2.x/python/npu_device/configs/aoe_config.py +++ b/tf_adapter_2.x/python/npu_device/configs/aoe_config.py @@ -23,5 +23,6 @@ class NpuAoeConfig(NpuBaseConfig): def __init__(self): self.aoe_mode = OptionValue(None, ["1", "2", "4"]) self.work_path = OptionValue("./", None) + self.aoe_config_file = OptionValue(None, None) super(NpuAoeConfig, self).__init__() \ No newline at end of file -- Gitee