!49611 [MS]{Lite][Task] add auto install for ascend custom op

Merge pull request !49611 from 刘力力/feature_custom_install_merge
This commit is contained in:
i-robot 2023-03-02 12:01:46 +00:00 committed by Gitee
commit f47095ef91
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
8 changed files with 107 additions and 3 deletions

View File

@ -44,6 +44,7 @@ struct AclModelOptionCfg {
std::string profiling_path;
std::string dump_path;
std::string dump_model_name;
std::string custom_opp_path;
};
constexpr auto kOutputShapes = "outputs_shape";

View File

@ -0,0 +1,63 @@
/**
* Copyright 2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "tools/converter/adapter/acl/src/acl_custom_opp_installer.h"
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include "src/common/log_util.h"
namespace mindspore {
namespace opt {
constexpr size_t kOutBufSize = 1024;
bool AclCustomOppInstaller::InstallCustomOpp(const std::string &custom_opp_path, const std::string &cann_opp_path) {
MS_LOG(INFO) << "AclCustomOppInstaller::InstallCustomOpp: Install opp from " << custom_opp_path << " to "
<< cann_opp_path;
if (!custom_opp_path.empty()) {
// if set the custom_opp_path, install the custom opp to cann opp library
if (!cann_opp_path.empty()) {
// if set the cann_opp_path, set the ASCEND_OPP_PATH env to cann_opp_path for targe dir
if (setenv("ASCEND_OPP_PATH", cann_opp_path.c_str(), 1) != 0) {
MS_LOG(ERROR) << "AclCustomOppInstaller::InstallCustomOpp: Set ASCEND_OPP_PATH env failed";
return false;
}
}
// call the install.sh script to install custom opp
FILE *fp;
std::string install_path = custom_opp_path + "/install.sh";
std::string cmd = "bash " + install_path;
if ((fp = popen(cmd.c_str(), "r")) == NULL) {
MS_LOG(ERROR) << "AclCustomOppInstaller::InstallCustomOpp: Install Custom Opp failed";
return false;
} else {
char buf_ps[kOutBufSize];
while (fgets(buf_ps, kOutBufSize, fp) != NULL) {
printf("%s\n", buf_ps);
}
}
pclose(fp);
}
return true;
}
} // namespace opt
} // namespace mindspore

View File

@ -0,0 +1,30 @@
/**
* Copyright 2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_ACL_SRC_ACL_CUSTOM_OPP_INSTALLER_H_
#define MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_ACL_SRC_ACL_CUSTOM_OPP_INSTALLER_H_
#include <string>
namespace mindspore {
namespace opt {
class AclCustomOppInstaller {
public:
static bool InstallCustomOpp(const std::string &custom_opp_path, const std::string &cann_opp_path);
};
} // namespace opt
} // namespace mindspore
#endif // MINDSPORE_LITE_TOOLS_CONVERTER_ADAPTER_ACL_SRC_ACL_CUSTOM_OPP_INSTALLER_H_

View File

@ -51,6 +51,7 @@
#include "tools/converter/quantizer/full_quant_quantizer.h"
#include "tools/converter/quantizer/insert_quant_node_manager.h"
#include "tools/converter/parser/unify_format.h"
#include "tools/converter/adapter/acl/src/acl_custom_opp_installer.h"
namespace mindspore {
namespace opt {
@ -869,6 +870,11 @@ bool AclPassImpl::Run(const FuncGraphPtr &func_graph) {
auto manager = Manage(func_graph, true);
MS_CHECK_TRUE_MSG(manager != nullptr, false, "manager is nullptr.");
if (!user_options_cfg_.custom_opp_path.empty()) {
// if set custom_opp_path config, first install custom ops to cann
AclCustomOppInstaller::InstallCustomOpp(user_options_cfg_.custom_opp_path, "");
}
if (PreProcGraph(func_graph) != lite::RET_OK) {
MS_LOG(ERROR) << "Pre proc graph failed.";
return false;

View File

@ -83,6 +83,7 @@ STATUS AclOptionParamParser::ParseCommon(const AclOptionCfgString &acl_option_st
acl_option_cfg->insert_op_config_file_path = acl_option_string.insert_op_config_file_path;
acl_option_cfg->dynamic_image_size = acl_option_string.dynamic_image_size;
acl_option_cfg->aoe_mode = acl_option_string.aoe_mode;
acl_option_cfg->custom_opp_path = acl_option_string.custom_opp_path;
return RET_OK;
}

View File

@ -36,6 +36,7 @@ constexpr auto kRegistry = "registry";
constexpr auto kAclOptionParam = "acl_option_cfg_param";
constexpr auto kMicroParam = "micro_param";
constexpr auto kCpuOptionParam = "cpu_option_cfg_param";
constexpr auto kCustomOppPath = "custom_opp_path";
} // namespace
using ShapeVector = std::vector<int64_t>;
const int kBatchDim = 0;
@ -450,7 +451,8 @@ int ConfigFileParser::ParseAclOptionCfgString(const std::map<std::string, std::m
{"buffer_optimize", acl_option_cfg_string_.buffer_optimize},
{"insert_op_config_file_path", acl_option_cfg_string_.insert_op_config_file_path},
{"dynamic_image_size", acl_option_cfg_string_.dynamic_image_size},
{"aoe_mode", acl_option_cfg_string_.aoe_mode}};
{"aoe_mode", acl_option_cfg_string_.aoe_mode},
{"custom_opp_path", acl_option_cfg_string_.custom_opp_path}};
return SetMapData(map, parse_map, kAclOptionParam);
}
return RET_OK;

View File

@ -88,6 +88,7 @@ struct AclOptionCfgString {
std::string insert_op_config_file_path;
std::string dynamic_image_size;
std::string aoe_mode;
std::string custom_opp_path;
};
struct MicroParamString {

View File

@ -2,9 +2,9 @@
vendor_name=mslite
targetdir=/usr/local/Ascend/opp
sourcedir=$PWD/packages
script_dir=$(cd "$(dirname ${BASH_SOURCE[0]})"; pwd)
sourcedir=${script_dir}/packages
vendordir=vendors/$vendor_name
QUIET="y"
for i in "$@"