From 3edb04d9070d0fa4680a717c0ade4b206089d056 Mon Sep 17 00:00:00 2001 From: wjm Date: Sun, 7 Feb 2021 20:34:16 +0800 Subject: [PATCH 1/8] provide interface for atc --- ge/common/helper/model_helper.cc | 97 +++++++++++++++++++++++++++++++ ge/graph/optimize/common/params.h | 2 +- ge/init/gelib.cc | 20 +++++++ inc/framework/omg/ge_init.h | 39 +++++++++++++ inc/framework/omg/model_tool.h | 33 +++++++++++ 5 files changed, 190 insertions(+), 1 deletion(-) create mode 100644 inc/framework/omg/ge_init.h create mode 100644 inc/framework/omg/model_tool.h diff --git a/ge/common/helper/model_helper.cc b/ge/common/helper/model_helper.cc index 37cb53bc..33570db7 100644 --- a/ge/common/helper/model_helper.cc +++ b/ge/common/helper/model_helper.cc @@ -21,6 +21,7 @@ #include "framework/common/debug/log.h" #include "framework/common/util.h" #include "framework/common/debug/ge_log.h" +#include "framework/omg/model_tool.h" #include "framework/omg/version.h" #include "graph/debug/ge_attr_define.h" #include "graph/load/model_manager/davinci_model_parser.h" @@ -892,4 +893,100 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelHelper::GetModelNam GE_CHK_BOOL_EXEC_WARN(!model_name.empty(), return FAILED, "Get model_name failed, check params --output"); return SUCCESS; } + +FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelTool::GetModelInfoFromOm(const char *model_file, + ge::proto::ModelDef &model_def) { + GE_CHECK_NOTNULL(model_file); + ge::ModelData model; + int32_t priority = 0; + + // Load model from file + Status ret = ModelParserBase::LoadFromFile(model_file, "", priority, model); + if (ret != SUCCESS) { + GELOGE(ret, "LoadFromFile failed."); + return ret; + } + std::function callback = [&]() { + if (model.model_data != nullptr) { + delete[] reinterpret_cast(model.model_data); + model.model_data = nullptr; + } + }; + + uint8_t *model_data = nullptr; + uint32_t model_len = 0; + // Parse the contents of the file to get the modeldef object + ret = ModelParserBase::ParseModelContent(model, model_data, model_len); + if (ret != SUCCESS) { + ErrorManager::GetInstance().ATCReportErrMessage("E10003", + {"parameter", "value", "reason"}, + {"om", model_file, "invalid om file"}); + GELOGE(ACL_ERROR_GE_PARAM_INVALID, + "ParseModelContent failed because of invalid om file. Please check --om param."); + return ret; + } + + OmFileLoadHelper omFileLoadHelper; + ret = omFileLoadHelper.Init(model_data, model_len); + if (ret != ge::GRAPH_SUCCESS) { + ErrorManager::GetInstance().ATCReportErrMessage("E19021", {"reason"}, {"Om file init failed"}); + GELOGE(ge::FAILED, "Om file init failed."); + return ret; + } + + ModelPartition ir_part; + ret = omFileLoadHelper.GetModelPartition(MODEL_DEF, ir_part); + if (ret != ge::GRAPH_SUCCESS) { + ErrorManager::GetInstance().ATCReportErrMessage("E19021", {"reason"}, {"Get model part failed"}); + GELOGE(ge::FAILED, "Get model part failed."); + return ret; + } + + bool flag = ReadProtoFromArray(ir_part.data, ir_part.size, &model_def); + if (flag) { + ret = INTERNAL_ERROR; + ErrorManager::GetInstance().ATCReportErrMessage("E19021", {"reason"}, {"ReadProtoFromArray failed"}); + GELOGE(ret, "ReadProtoFromArray failed."); + return ret; + } + return ret; +} + +FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelTool::GetModelInfoFromPbtxt(const char *model_file, + ge::proto::ModelDef &model_def) { + GE_CHECK_NOTNULL(model_file); + ge::ModelData model; + int32_t priority = 0; + // Load model from file + Status ret = ModelParserBase::LoadFromFile(model_file, "", priority, model); + auto free_model_data = [](void **ptr) -> void { + if (ptr != nullptr && *ptr != nullptr) { + delete[] reinterpret_cast(*ptr); + *ptr = nullptr; + } + }; + if (ret != SUCCESS) { + free_model_data(&model.model_data); + GELOGE(ret, "LoadFromFile failed."); + return ret; + } + + try { + bool flag = google::protobuf::TextFormat::ParseFromString(reinterpret_cast(model.model_data), &model_def); + if (!flag) { + free_model_data(&model.model_data); + ErrorManager::GetInstance().ATCReportErrMessage("E19021", {"reason"}, {"ParseFromString failed"}); + GELOGE(FAILED, "ParseFromString failed."); + return FAILED; + } + free_model_data(&model.model_data); + return SUCCESS; + } catch (google::protobuf::FatalException &e) { + free_model_data(&model.model_data); + ErrorManager::GetInstance().ATCReportErrMessage("E19021", {"reason"}, {"ParseFromString failed, exception message[" + + std::string(e.what()) + "]"}); + GELOGE(FAILED, "ParseFromString failed. exception message : %s", e.what()); + return FAILED; + } +} } // namespace ge diff --git a/ge/graph/optimize/common/params.h b/ge/graph/optimize/common/params.h index c174a4d1..d5b66b8f 100644 --- a/ge/graph/optimize/common/params.h +++ b/ge/graph/optimize/common/params.h @@ -55,7 +55,7 @@ class Params : public Singleton { Params() : target_("MINI") {} string target_; - uint8_t target_8bit_ = 0; + uint8_t target_8bit_ = TARGET_TYPE_MINI_8BIT; }; } // namespace ge diff --git a/ge/init/gelib.cc b/ge/init/gelib.cc index d44568cc..c5a96db0 100755 --- a/ge/init/gelib.cc +++ b/ge/init/gelib.cc @@ -31,6 +31,7 @@ #include "framework/common/debug/ge_log.h" #include "framework/common/debug/log.h" #include "framework/common/util.h" +#include "framework/omg/ge_init.h" #include "analyzer/analyzer.h" #include "ge/ge_api_types.h" #include "ge_local_engine/engine/host_cpu_engine.h" @@ -531,4 +532,23 @@ void GELib::RollbackInit() { HostMemManager::Instance().Finalize(); VarManagerPool::Instance().Destory(); } + +Status GEInit::Initialize(const map &options) { + Status ret = SUCCESS; + std::shared_ptr instance_ptr = ge::GELib::GetInstance(); + if (instance_ptr == nullptr || !instance_ptr->InitFlag()) { + ret = GELib::Initialize(options); + } + return ret; +} + +Status GEInit::Finalize() { + Status ret = GELib::GetInstance()->Finalize(); + return ret; +} + +string GEInit::GetPath() { + std::string path = GELib::GetPath(); + return path; +} } // namespace ge diff --git a/inc/framework/omg/ge_init.h b/inc/framework/omg/ge_init.h new file mode 100644 index 00000000..f82055d1 --- /dev/null +++ b/inc/framework/omg/ge_init.h @@ -0,0 +1,39 @@ +/** + * Copyright 2020 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 INC_FRAMEWORK_OMG_GE_INIT_H_ +#define INC_FRAMEWORK_OMG_GE_INIT_H_ +#include +#include +#include "common/ge_inner_error_codes.h" + +using std::string; +using std::map; + +namespace ge { +class GE_FUNC_VISIBILITY GEInit { + public: + // GE Environment Initialize, return Status: SUCCESS,FAILED + static Status Initialize(const map &options); + + static string GetPath(); + + // GE Environment Finalize, return Status: SUCCESS,FAILED + static Status Finalize(); +}; +} // namespace ge + +#endif // INIT_H_ diff --git a/inc/framework/omg/model_tool.h b/inc/framework/omg/model_tool.h new file mode 100644 index 00000000..afc8dad1 --- /dev/null +++ b/inc/framework/omg/model_tool.h @@ -0,0 +1,33 @@ +/** + * Copyright 2019-2020 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 INC_FRAMEWORK_OMG_MODEL_TOOL_H_ +#define INC_FRAMEWORK_OMG_MODEL_TOOL_H_ + +#include +#include + +#include "framework/common/debug/ge_log.h" +#include "proto/ge_ir.pb.h" +namespace ge { +class GE_FUNC_VISIBILITY ModelTool { + public: + static Status GetModelInfoFromOm(const char *model_file, ge::proto::ModelDef &model_def); + + static Status GetModelInfoFromPbtxt(const char *model_file, ge::proto::ModelDef &model_def); +}; +} // namespace ge +#endif // INC_FRAMEWORK_OMG_MODEL_TOOL_H_ From c8c9f461af64bfd8161832035d18388d37246a49 Mon Sep 17 00:00:00 2001 From: wjm Date: Tue, 9 Feb 2021 11:01:21 +0800 Subject: [PATCH 2/8] update submodule --- parser | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parser b/parser index 81eb1792..a33f8001 160000 --- a/parser +++ b/parser @@ -1 +1 @@ -Subproject commit 81eb1792fbbca4b569b391fd31d7dd7281e3c228 +Subproject commit a33f8001d1996160fca54aa571eee6bb1e13142b From 9b439be58a0869ef9f122a82a72381539b3644e4 Mon Sep 17 00:00:00 2001 From: wjm Date: Tue, 9 Feb 2021 11:24:47 +0800 Subject: [PATCH 3/8] fix --- ge/common/helper/model_helper.cc | 96 ------------------------------- ge/graph/optimize/common/params.h | 2 +- ge/init/gelib.cc | 19 ------ inc/framework/omg/ge_init.h | 39 ------------- inc/framework/omg/model_tool.h | 33 ----------- 5 files changed, 1 insertion(+), 188 deletions(-) delete mode 100644 inc/framework/omg/ge_init.h delete mode 100644 inc/framework/omg/model_tool.h diff --git a/ge/common/helper/model_helper.cc b/ge/common/helper/model_helper.cc index 33570db7..81e543c7 100644 --- a/ge/common/helper/model_helper.cc +++ b/ge/common/helper/model_helper.cc @@ -893,100 +893,4 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelHelper::GetModelNam GE_CHK_BOOL_EXEC_WARN(!model_name.empty(), return FAILED, "Get model_name failed, check params --output"); return SUCCESS; } - -FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelTool::GetModelInfoFromOm(const char *model_file, - ge::proto::ModelDef &model_def) { - GE_CHECK_NOTNULL(model_file); - ge::ModelData model; - int32_t priority = 0; - - // Load model from file - Status ret = ModelParserBase::LoadFromFile(model_file, "", priority, model); - if (ret != SUCCESS) { - GELOGE(ret, "LoadFromFile failed."); - return ret; - } - std::function callback = [&]() { - if (model.model_data != nullptr) { - delete[] reinterpret_cast(model.model_data); - model.model_data = nullptr; - } - }; - - uint8_t *model_data = nullptr; - uint32_t model_len = 0; - // Parse the contents of the file to get the modeldef object - ret = ModelParserBase::ParseModelContent(model, model_data, model_len); - if (ret != SUCCESS) { - ErrorManager::GetInstance().ATCReportErrMessage("E10003", - {"parameter", "value", "reason"}, - {"om", model_file, "invalid om file"}); - GELOGE(ACL_ERROR_GE_PARAM_INVALID, - "ParseModelContent failed because of invalid om file. Please check --om param."); - return ret; - } - - OmFileLoadHelper omFileLoadHelper; - ret = omFileLoadHelper.Init(model_data, model_len); - if (ret != ge::GRAPH_SUCCESS) { - ErrorManager::GetInstance().ATCReportErrMessage("E19021", {"reason"}, {"Om file init failed"}); - GELOGE(ge::FAILED, "Om file init failed."); - return ret; - } - - ModelPartition ir_part; - ret = omFileLoadHelper.GetModelPartition(MODEL_DEF, ir_part); - if (ret != ge::GRAPH_SUCCESS) { - ErrorManager::GetInstance().ATCReportErrMessage("E19021", {"reason"}, {"Get model part failed"}); - GELOGE(ge::FAILED, "Get model part failed."); - return ret; - } - - bool flag = ReadProtoFromArray(ir_part.data, ir_part.size, &model_def); - if (flag) { - ret = INTERNAL_ERROR; - ErrorManager::GetInstance().ATCReportErrMessage("E19021", {"reason"}, {"ReadProtoFromArray failed"}); - GELOGE(ret, "ReadProtoFromArray failed."); - return ret; - } - return ret; -} - -FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelTool::GetModelInfoFromPbtxt(const char *model_file, - ge::proto::ModelDef &model_def) { - GE_CHECK_NOTNULL(model_file); - ge::ModelData model; - int32_t priority = 0; - // Load model from file - Status ret = ModelParserBase::LoadFromFile(model_file, "", priority, model); - auto free_model_data = [](void **ptr) -> void { - if (ptr != nullptr && *ptr != nullptr) { - delete[] reinterpret_cast(*ptr); - *ptr = nullptr; - } - }; - if (ret != SUCCESS) { - free_model_data(&model.model_data); - GELOGE(ret, "LoadFromFile failed."); - return ret; - } - - try { - bool flag = google::protobuf::TextFormat::ParseFromString(reinterpret_cast(model.model_data), &model_def); - if (!flag) { - free_model_data(&model.model_data); - ErrorManager::GetInstance().ATCReportErrMessage("E19021", {"reason"}, {"ParseFromString failed"}); - GELOGE(FAILED, "ParseFromString failed."); - return FAILED; - } - free_model_data(&model.model_data); - return SUCCESS; - } catch (google::protobuf::FatalException &e) { - free_model_data(&model.model_data); - ErrorManager::GetInstance().ATCReportErrMessage("E19021", {"reason"}, {"ParseFromString failed, exception message[" - + std::string(e.what()) + "]"}); - GELOGE(FAILED, "ParseFromString failed. exception message : %s", e.what()); - return FAILED; - } -} } // namespace ge diff --git a/ge/graph/optimize/common/params.h b/ge/graph/optimize/common/params.h index d5b66b8f..c174a4d1 100644 --- a/ge/graph/optimize/common/params.h +++ b/ge/graph/optimize/common/params.h @@ -55,7 +55,7 @@ class Params : public Singleton { Params() : target_("MINI") {} string target_; - uint8_t target_8bit_ = TARGET_TYPE_MINI_8BIT; + uint8_t target_8bit_ = 0; }; } // namespace ge diff --git a/ge/init/gelib.cc b/ge/init/gelib.cc index c5a96db0..6032a002 100755 --- a/ge/init/gelib.cc +++ b/ge/init/gelib.cc @@ -532,23 +532,4 @@ void GELib::RollbackInit() { HostMemManager::Instance().Finalize(); VarManagerPool::Instance().Destory(); } - -Status GEInit::Initialize(const map &options) { - Status ret = SUCCESS; - std::shared_ptr instance_ptr = ge::GELib::GetInstance(); - if (instance_ptr == nullptr || !instance_ptr->InitFlag()) { - ret = GELib::Initialize(options); - } - return ret; -} - -Status GEInit::Finalize() { - Status ret = GELib::GetInstance()->Finalize(); - return ret; -} - -string GEInit::GetPath() { - std::string path = GELib::GetPath(); - return path; -} } // namespace ge diff --git a/inc/framework/omg/ge_init.h b/inc/framework/omg/ge_init.h deleted file mode 100644 index f82055d1..00000000 --- a/inc/framework/omg/ge_init.h +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Copyright 2020 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 INC_FRAMEWORK_OMG_GE_INIT_H_ -#define INC_FRAMEWORK_OMG_GE_INIT_H_ -#include -#include -#include "common/ge_inner_error_codes.h" - -using std::string; -using std::map; - -namespace ge { -class GE_FUNC_VISIBILITY GEInit { - public: - // GE Environment Initialize, return Status: SUCCESS,FAILED - static Status Initialize(const map &options); - - static string GetPath(); - - // GE Environment Finalize, return Status: SUCCESS,FAILED - static Status Finalize(); -}; -} // namespace ge - -#endif // INIT_H_ diff --git a/inc/framework/omg/model_tool.h b/inc/framework/omg/model_tool.h deleted file mode 100644 index afc8dad1..00000000 --- a/inc/framework/omg/model_tool.h +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Copyright 2019-2020 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 INC_FRAMEWORK_OMG_MODEL_TOOL_H_ -#define INC_FRAMEWORK_OMG_MODEL_TOOL_H_ - -#include -#include - -#include "framework/common/debug/ge_log.h" -#include "proto/ge_ir.pb.h" -namespace ge { -class GE_FUNC_VISIBILITY ModelTool { - public: - static Status GetModelInfoFromOm(const char *model_file, ge::proto::ModelDef &model_def); - - static Status GetModelInfoFromPbtxt(const char *model_file, ge::proto::ModelDef &model_def); -}; -} // namespace ge -#endif // INC_FRAMEWORK_OMG_MODEL_TOOL_H_ From 99d0c872a09d2028dc355b7ebeca05022722b918 Mon Sep 17 00:00:00 2001 From: wjm Date: Tue, 9 Feb 2021 11:26:47 +0800 Subject: [PATCH 4/8] fix --- ge/common/helper/model_helper.cc | 1 - ge/init/gelib.cc | 1 - 2 files changed, 2 deletions(-) diff --git a/ge/common/helper/model_helper.cc b/ge/common/helper/model_helper.cc index 81e543c7..37cb53bc 100644 --- a/ge/common/helper/model_helper.cc +++ b/ge/common/helper/model_helper.cc @@ -21,7 +21,6 @@ #include "framework/common/debug/log.h" #include "framework/common/util.h" #include "framework/common/debug/ge_log.h" -#include "framework/omg/model_tool.h" #include "framework/omg/version.h" #include "graph/debug/ge_attr_define.h" #include "graph/load/model_manager/davinci_model_parser.h" diff --git a/ge/init/gelib.cc b/ge/init/gelib.cc index 6032a002..d44568cc 100755 --- a/ge/init/gelib.cc +++ b/ge/init/gelib.cc @@ -31,7 +31,6 @@ #include "framework/common/debug/ge_log.h" #include "framework/common/debug/log.h" #include "framework/common/util.h" -#include "framework/omg/ge_init.h" #include "analyzer/analyzer.h" #include "ge/ge_api_types.h" #include "ge_local_engine/engine/host_cpu_engine.h" From b4818668876c2ad91e70552dc4d810b0f5877ce3 Mon Sep 17 00:00:00 2001 From: wjm Date: Tue, 9 Feb 2021 16:14:05 +0800 Subject: [PATCH 5/8] fix ut --- tests/ut/ge/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ut/ge/CMakeLists.txt b/tests/ut/ge/CMakeLists.txt index 7c49c0a7..c3b1eca8 100755 --- a/tests/ut/ge/CMakeLists.txt +++ b/tests/ut/ge/CMakeLists.txt @@ -49,13 +49,13 @@ include_directories(${GE_CODE_DIR}/metadef) include_directories(${GE_CODE_DIR}/metadef/graph) include_directories(${GE_CODE_DIR}/inc/external) include_directories(${GE_CODE_DIR}/metadef/inc/external) -include_directories(${GE_CODE_DIR}/parser) -include_directories(${GE_CODE_DIR}/parser/parser) include_directories(${GE_CODE_DIR}/metadef/inc/external/graph) include_directories(${GE_CODE_DIR}/metadef/inc/graph) include_directories(${GE_CODE_DIR}/inc/framework) include_directories(${GE_CODE_DIR}/metadef/inc/common) include_directories(${GE_CODE_DIR}/metadef/third_party) +include_directories(${GE_CODE_DIR}/parser) +include_directories(${GE_CODE_DIR}/parser/parser) include_directories(${GE_CODE_DIR}/third_party/fwkacllib/inc) include_directories(${GE_CODE_DIR}/third_party/fwkacllib/inc/cce) include_directories(${GE_CODE_DIR}/third_party/fwkacllib/inc/ops) From c47a4668a584ded11680d8500a0f991fa663040a Mon Sep 17 00:00:00 2001 From: wjm Date: Tue, 9 Feb 2021 16:17:52 +0800 Subject: [PATCH 6/8] update --- parser | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parser b/parser index a33f8001..30908fb8 160000 --- a/parser +++ b/parser @@ -1 +1 @@ -Subproject commit a33f8001d1996160fca54aa571eee6bb1e13142b +Subproject commit 30908fb820690d58d4f1b2cca4762b915ef00f4b From 7257fc53bdd3d6b7ffcf8d9c51292873ef6c9f97 Mon Sep 17 00:00:00 2001 From: wjm Date: Tue, 9 Feb 2021 17:17:47 +0800 Subject: [PATCH 7/8] update metadef --- metadef | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadef b/metadef index 7a4a8575..40e2d5c9 160000 --- a/metadef +++ b/metadef @@ -1 +1 @@ -Subproject commit 7a4a857590baaf80ce2d907c910b85163c91a011 +Subproject commit 40e2d5c974eda1d1f5716b18fc776dede7da4370 From d14c243e0508463ffbbd8ac248cce2b50a1b9751 Mon Sep 17 00:00:00 2001 From: wjm Date: Tue, 9 Feb 2021 17:29:41 +0800 Subject: [PATCH 8/8] update parser --- parser | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parser b/parser index 30908fb8..3c534dc8 160000 --- a/parser +++ b/parser @@ -1 +1 @@ -Subproject commit 30908fb820690d58d4f1b2cca4762b915ef00f4b +Subproject commit 3c534dc831eeedd13ad86d9c2b52879f345403e0