From 3074cd4ee5252fb7724f46166df12716d0b42756 Mon Sep 17 00:00:00 2001 From: lichun Date: Wed, 19 May 2021 10:24:11 +0800 Subject: [PATCH 1/2] fwkacllib support inference when ge lib is not inited --- .../aicore/aicore_node_executor.cc | 3 -- .../aicore/aicore_task_compiler.cc | 13 +++++ .../aicore/aicore_task_compiler.h | 2 + tests/ut/ge/CMakeLists.txt | 1 + .../aicore/aicore_task_compiler_unittest.cc | 48 +++++++++++++++++++ 5 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 tests/ut/ge/hybrid/node_executor/aicore/aicore_task_compiler_unittest.cc diff --git a/ge/hybrid/node_executor/aicore/aicore_node_executor.cc b/ge/hybrid/node_executor/aicore/aicore_node_executor.cc index 29ae831c..7ebb9e39 100755 --- a/ge/hybrid/node_executor/aicore/aicore_node_executor.cc +++ b/ge/hybrid/node_executor/aicore/aicore_node_executor.cc @@ -41,9 +41,6 @@ AiCoreNodeTask::AiCoreNodeTask(std::vector> &&task Status AiCoreNodeExecutor::Initialize() { compiler_ = TaskCompilerFactory::GetInstance().GetTaskCompiler(); - if (compiler_ != nullptr) { - GE_CHK_STATUS_RET(compiler_->Initialize(), "[Init][TaskCompiler] failed."); - } return SUCCESS; } diff --git a/ge/hybrid/node_executor/aicore/aicore_task_compiler.cc b/ge/hybrid/node_executor/aicore/aicore_task_compiler.cc index 742b3ca2..0cdea5d5 100755 --- a/ge/hybrid/node_executor/aicore/aicore_task_compiler.cc +++ b/ge/hybrid/node_executor/aicore/aicore_task_compiler.cc @@ -31,6 +31,11 @@ REGISTER_TASK_COMPILER(AiCoreTaskCompiler); std::mutex AiCoreTaskCompiler::mu_; Status AiCoreTaskCompiler::Initialize() { + std::lock_guard lk(mu_); + if (is_initialized_) { + return SUCCESS; + } + auto ge_lib = GELib::GetInstance(); GE_CHECK_NOTNULL(ge_lib); if (!ge_lib->InitFlag()) { @@ -41,6 +46,7 @@ Status AiCoreTaskCompiler::Initialize() { auto &kernel_manager = ge_lib->OpsKernelManagerObj(); aic_kernel_store_ = kernel_manager.GetOpsKernelInfoStore("AIcoreEngine"); GE_CHECK_NOTNULL(aic_kernel_store_); + is_initialized_ = true; return SUCCESS; } @@ -57,6 +63,13 @@ Status AiCoreTaskCompiler::DoCompileOp(const NodePtr &node) const { } Status AiCoreTaskCompiler::CompileOp(const NodePtr &node, std::vector &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); GELOGI("AiCoreTaskCompiler(%s) CompileOp Start.", node->GetName().c_str()); diff --git a/ge/hybrid/node_executor/aicore/aicore_task_compiler.h b/ge/hybrid/node_executor/aicore/aicore_task_compiler.h index b6dfd82b..cc733e99 100755 --- a/ge/hybrid/node_executor/aicore/aicore_task_compiler.h +++ b/ge/hybrid/node_executor/aicore/aicore_task_compiler.h @@ -18,6 +18,7 @@ #define GE_HYBRID_KERNEL_AICORE_TASK_COMPILER_H_ #include +#include #include "opskernel_manager/ops_kernel_manager.h" #include "aicore_node_executor.h" @@ -34,6 +35,7 @@ class AiCoreTaskCompiler : public TaskCompiler { Status DoCompileOp(const NodePtr &node) const; Status DoGenerateTask(const Node &node, std::vector &tasks); OpsKernelInfoStorePtr aic_kernel_store_; + std::atomic_bool is_initialized_{false}; static std::mutex mu_; }; } // namespace hybrid diff --git a/tests/ut/ge/CMakeLists.txt b/tests/ut/ge/CMakeLists.txt index 96da50d1..3f272023 100755 --- a/tests/ut/ge/CMakeLists.txt +++ b/tests/ut/ge/CMakeLists.txt @@ -829,6 +829,7 @@ set(HYBRID_TEST_FILES "hybrid/model/hybrid_model_builder_unittest.cc" "hybrid/node_executor/rts/rts_node_task_unittest.cc" "hybrid/executor/hybrid_model_async_executor_unittest.cc" + "hybrid/node_executor/aicore/aicore_task_compiler_unittest.cc" ) set(OTHERS_TEST_FILES diff --git a/tests/ut/ge/hybrid/node_executor/aicore/aicore_task_compiler_unittest.cc b/tests/ut/ge/hybrid/node_executor/aicore/aicore_task_compiler_unittest.cc new file mode 100644 index 00000000..3371cd5c --- /dev/null +++ b/tests/ut/ge/hybrid/node_executor/aicore/aicore_task_compiler_unittest.cc @@ -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 +#include +#include + +#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(); + std::vector 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 + From 2083a8e059de8ddfbf6d19bdd6ed398f2463c723 Mon Sep 17 00:00:00 2001 From: lichun Date: Wed, 19 May 2021 11:30:16 +0800 Subject: [PATCH 2/2] fwkacllib support inference when ge lib is not inited --- ge/hybrid/node_executor/aicore/aicore_task_compiler.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ge/hybrid/node_executor/aicore/aicore_task_compiler.h b/ge/hybrid/node_executor/aicore/aicore_task_compiler.h index cc733e99..4cb4dc58 100755 --- a/ge/hybrid/node_executor/aicore/aicore_task_compiler.h +++ b/ge/hybrid/node_executor/aicore/aicore_task_compiler.h @@ -18,7 +18,6 @@ #define GE_HYBRID_KERNEL_AICORE_TASK_COMPILER_H_ #include -#include #include "opskernel_manager/ops_kernel_manager.h" #include "aicore_node_executor.h" @@ -35,7 +34,7 @@ class AiCoreTaskCompiler : public TaskCompiler { Status DoCompileOp(const NodePtr &node) const; Status DoGenerateTask(const Node &node, std::vector &tasks); OpsKernelInfoStorePtr aic_kernel_store_; - std::atomic_bool is_initialized_{false}; + bool is_initialized_ = false; static std::mutex mu_; }; } // namespace hybrid