forked from huawei/mindspore2022
save om to file when run lite conveter
This commit is contained in:
parent
0b3eca078f
commit
53106f3438
|
|
@ -38,6 +38,8 @@ class AclModelOptions {
|
|||
// return tuple<init_options, build_options>
|
||||
std::tuple<std::map<std::string, std::string>, std::map<std::string, std::string>> GenAclOptions() const;
|
||||
void SetFirstGraph(bool is_first_graph) noexcept { first_graph_flag_ = is_first_graph; }
|
||||
void SetOmFilePath(const std::string &file_path) noexcept { om_file_path_ = file_path; }
|
||||
std::string GetOmFilePath() const { return om_file_path_; }
|
||||
|
||||
private:
|
||||
std::string output_node_; // todo: at convert.cc::BuildGraph(), no atc options
|
||||
|
|
@ -57,6 +59,7 @@ class AclModelOptions {
|
|||
// other options
|
||||
uint32_t device_id_;
|
||||
std::optional<bool> first_graph_flag_;
|
||||
std::string om_file_path_;
|
||||
};
|
||||
} // namespace mindspore
|
||||
|
||||
|
|
|
|||
|
|
@ -128,10 +128,36 @@ Buffer ModelConverter::BuildAirModel(const transform::DfGraphPtr &graph,
|
|||
return Buffer();
|
||||
}
|
||||
|
||||
if (SaveModel(model) != kSuccess) {
|
||||
MS_LOG(ERROR) << "Save model failed.";
|
||||
return Buffer();
|
||||
}
|
||||
|
||||
ge::aclgrphBuildFinalize();
|
||||
return Buffer(model.data.get(), model.length);
|
||||
}
|
||||
|
||||
Status ModelConverter::SaveModel(const ge::ModelBufferData &model) {
|
||||
#ifdef BUILD_LITE
|
||||
std::string file_path;
|
||||
auto option = options_.lock();
|
||||
if (option != nullptr) {
|
||||
file_path = option->GetOmFilePath();
|
||||
}
|
||||
if (file_path.empty()) {
|
||||
MS_LOG(INFO) << "File path is empty, there is no need to save model";
|
||||
return kSuccess;
|
||||
}
|
||||
MS_LOG(INFO) << "Om file path: " << file_path;
|
||||
auto ret = ge::aclgrphSaveModel(file_path, model);
|
||||
if (ret != ge::SUCCESS) {
|
||||
MS_LOG(ERROR) << "Call aclgrphSaveModel fail.";
|
||||
return kMCFailed;
|
||||
}
|
||||
#endif
|
||||
return kSuccess;
|
||||
}
|
||||
|
||||
Buffer ModelConverter::LoadMindIR(const FuncGraphPtr &func_graph) {
|
||||
MultiProcess multi_process;
|
||||
Buffer buffer_ret;
|
||||
|
|
|
|||
|
|
@ -37,6 +37,8 @@ class ModelConverter {
|
|||
|
||||
void set_options(const std::weak_ptr<AclModelOptions> &options) { options_ = options; }
|
||||
|
||||
Status SaveModel(const ge::ModelBufferData &model);
|
||||
|
||||
private:
|
||||
transform::DfGraphPtr ConvertFuncGraphToAIR(const FuncGraphPtr &anf_graph);
|
||||
Buffer BuildAirModel(const transform::DfGraphPtr &graph, const std::map<std::string, std::string> &init_options,
|
||||
|
|
|
|||
|
|
@ -266,12 +266,16 @@ namespace registry {
|
|||
namespace {
|
||||
const auto kFloat32 = DataType::kNumberTypeFloat32;
|
||||
const auto kFloat16 = DataType::kNumberTypeFloat16;
|
||||
const auto kInt32 = DataType::kNumberTypeInt32;
|
||||
const auto kInt8 = DataType::kNumberTypeInt8;
|
||||
const auto kUInt8 = DataType::kNumberTypeUInt8;
|
||||
const auto kBool = DataType::kNumberTypeBool;
|
||||
} // namespace
|
||||
REGISTER_CUSTOM_KERNEL(ASCEND, ACL, kFloat32, ACL, kernel::acl::CustomCreateKernel)
|
||||
REGISTER_CUSTOM_KERNEL(ASCEND, ACL, kFloat16, ACL, kernel::acl::CustomCreateKernel)
|
||||
REGISTER_CUSTOM_KERNEL(ASCEND, ACL, kInt32, ACL, kernel::acl::CustomCreateKernel)
|
||||
REGISTER_CUSTOM_KERNEL(ASCEND, ACL, kInt8, ACL, kernel::acl::CustomCreateKernel)
|
||||
REGISTER_CUSTOM_KERNEL(ASCEND, ACL, kUInt8, ACL, kernel::acl::CustomCreateKernel)
|
||||
REGISTER_CUSTOM_KERNEL(ASCEND, ACL, kBool, ACL, kernel::acl::CustomCreateKernel)
|
||||
} // namespace registry
|
||||
} // namespace mindspore
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ struct AclModelOptionCfg {
|
|||
std::string buffer_optimize;
|
||||
std::string insert_op_config_file_path;
|
||||
std::string dynamic_image_size;
|
||||
std::string om_file_path;
|
||||
};
|
||||
|
||||
constexpr auto kOutputShapes = "outputs_shape";
|
||||
|
|
|
|||
|
|
@ -328,6 +328,7 @@ STATUS AclPassImpl::SetAclModelOptions(const FuncGraphPtr &func_graph) {
|
|||
input_names.push_back(name);
|
||||
}
|
||||
options_->RenameInput(input_names);
|
||||
options_->SetOmFilePath(user_options_cfg_.om_file_path);
|
||||
MS_LOG(INFO) << "Set acl model options success.";
|
||||
return lite::RET_OK;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -273,6 +273,8 @@ int Flags::InitExtendedIntegrationInfo(const lite::ConfigFileParser &config_file
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
void Flags::InitAclDefaultOption() { this->aclModelOptionCfgParam.om_file_path = this->outputFile; }
|
||||
|
||||
int Flags::InitConfigFile() {
|
||||
lite::ConfigFileParser config_file_parser;
|
||||
auto ret = config_file_parser.ParseConfigFile(this->configFile);
|
||||
|
|
@ -421,6 +423,8 @@ int Flags::PreInit(int argc, const char **argv) {
|
|||
return RET_INPUT_PARAM_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
InitAclDefaultOption();
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -73,6 +73,8 @@ class Flags : public virtual mindspore::lite::FlagParser {
|
|||
|
||||
int InitSaveFP16();
|
||||
|
||||
void InitAclDefaultOption();
|
||||
|
||||
int Init(int argc, const char **argv);
|
||||
|
||||
int PreInit(int argc, const char **argv);
|
||||
|
|
|
|||
Loading…
Reference in New Issue