From: @lichun30 Reviewed-by: @xchu42,@ji_chen Signed-off-by: @ji_chentags/v1.3.0
| @@ -41,9 +41,6 @@ AiCoreNodeTask::AiCoreNodeTask(std::vector<std::unique_ptr<AiCoreOpTask>> &&task | |||||
| Status AiCoreNodeExecutor::Initialize() { | Status AiCoreNodeExecutor::Initialize() { | ||||
| compiler_ = TaskCompilerFactory::GetInstance().GetTaskCompiler(); | compiler_ = TaskCompilerFactory::GetInstance().GetTaskCompiler(); | ||||
| if (compiler_ != nullptr) { | |||||
| GE_CHK_STATUS_RET(compiler_->Initialize(), "[Init][TaskCompiler] failed."); | |||||
| } | |||||
| return SUCCESS; | return SUCCESS; | ||||
| } | } | ||||
| @@ -31,6 +31,11 @@ REGISTER_TASK_COMPILER(AiCoreTaskCompiler); | |||||
| std::mutex AiCoreTaskCompiler::mu_; | std::mutex AiCoreTaskCompiler::mu_; | ||||
| Status AiCoreTaskCompiler::Initialize() { | Status AiCoreTaskCompiler::Initialize() { | ||||
| std::lock_guard<std::mutex> lk(mu_); | |||||
| if (is_initialized_) { | |||||
| return SUCCESS; | |||||
| } | |||||
| auto ge_lib = GELib::GetInstance(); | auto ge_lib = GELib::GetInstance(); | ||||
| GE_CHECK_NOTNULL(ge_lib); | GE_CHECK_NOTNULL(ge_lib); | ||||
| if (!ge_lib->InitFlag()) { | if (!ge_lib->InitFlag()) { | ||||
| @@ -41,6 +46,7 @@ Status AiCoreTaskCompiler::Initialize() { | |||||
| auto &kernel_manager = ge_lib->OpsKernelManagerObj(); | auto &kernel_manager = ge_lib->OpsKernelManagerObj(); | ||||
| aic_kernel_store_ = kernel_manager.GetOpsKernelInfoStore("AIcoreEngine"); | aic_kernel_store_ = kernel_manager.GetOpsKernelInfoStore("AIcoreEngine"); | ||||
| GE_CHECK_NOTNULL(aic_kernel_store_); | GE_CHECK_NOTNULL(aic_kernel_store_); | ||||
| is_initialized_ = true; | |||||
| return SUCCESS; | return SUCCESS; | ||||
| } | } | ||||
| @@ -57,6 +63,13 @@ Status AiCoreTaskCompiler::DoCompileOp(const NodePtr &node) const { | |||||
| } | } | ||||
| Status AiCoreTaskCompiler::CompileOp(const NodePtr &node, std::vector<domi::TaskDef> &tasks) { | Status AiCoreTaskCompiler::CompileOp(const NodePtr &node, std::vector<domi::TaskDef> &tasks) { | ||||
| Status ret = Initialize(); | |||||
| if (ret != SUCCESS) { | |||||
| GELOGE(FAILED, "[Check][State][%s] Offline inference not support online compile.", node->GetName().c_str()); | |||||
| REPORT_INNER_ERROR("E19999", "[%s] Offline inference not support online compile.", node->GetName().c_str()); | |||||
| return ret; | |||||
| } | |||||
| GE_CHECK_NOTNULL(node); | GE_CHECK_NOTNULL(node); | ||||
| GELOGI("AiCoreTaskCompiler(%s) CompileOp Start.", node->GetName().c_str()); | GELOGI("AiCoreTaskCompiler(%s) CompileOp Start.", node->GetName().c_str()); | ||||
| @@ -34,6 +34,7 @@ class AiCoreTaskCompiler : public TaskCompiler { | |||||
| Status DoCompileOp(const NodePtr &node) const; | Status DoCompileOp(const NodePtr &node) const; | ||||
| Status DoGenerateTask(const Node &node, std::vector<domi::TaskDef> &tasks); | Status DoGenerateTask(const Node &node, std::vector<domi::TaskDef> &tasks); | ||||
| OpsKernelInfoStorePtr aic_kernel_store_; | OpsKernelInfoStorePtr aic_kernel_store_; | ||||
| bool is_initialized_ = false; | |||||
| static std::mutex mu_; | static std::mutex mu_; | ||||
| }; | }; | ||||
| } // namespace hybrid | } // namespace hybrid | ||||
| @@ -829,6 +829,7 @@ set(HYBRID_TEST_FILES | |||||
| "hybrid/model/hybrid_model_builder_unittest.cc" | "hybrid/model/hybrid_model_builder_unittest.cc" | ||||
| "hybrid/node_executor/rts/rts_node_task_unittest.cc" | "hybrid/node_executor/rts/rts_node_task_unittest.cc" | ||||
| "hybrid/executor/hybrid_model_async_executor_unittest.cc" | "hybrid/executor/hybrid_model_async_executor_unittest.cc" | ||||
| "hybrid/node_executor/aicore/aicore_task_compiler_unittest.cc" | |||||
| ) | ) | ||||
| set(OTHERS_TEST_FILES | set(OTHERS_TEST_FILES | ||||
| @@ -0,0 +1,48 @@ | |||||
| /** | |||||
| * Copyright 2021-2021 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 <gtest/gtest.h> | |||||
| #include <gmock/gmock.h> | |||||
| #include <vector> | |||||
| #define private public | |||||
| #define protected public | |||||
| #include "init/gelib.h" | |||||
| #include "hybrid/node_executor/aicore/aicore_task_compiler.h" | |||||
| #undef private | |||||
| #undef protected | |||||
| using namespace std; | |||||
| using namespace testing; | |||||
| namespace ge { | |||||
| using namespace hybrid; | |||||
| class UtestAiCoreTaskCompiler : public testing::Test { | |||||
| protected: | |||||
| void SetUp() {} | |||||
| void TearDown() {} | |||||
| }; | |||||
| TEST_F(UtestAiCoreTaskCompiler, test_aicore_task_compiler_init) { | |||||
| ge::hybrid::AiCoreTaskCompiler aicore_task_compiler; | |||||
| NodePtr node = MakeShared<Node>(); | |||||
| std::vector<domi::TaskDef> tasks{}; | |||||
| EXPECT_EQ(aicore_task_compiler.Initialize(), ge::PARAM_INVALID); // cause: ge lib is nullptr | |||||
| EXPECT_EQ(aicore_task_compiler.CompileOp(node, tasks), ge::PARAM_INVALID); // cause: aicore task compiler init failed. | |||||
| } | |||||
| } // namespace ge | |||||