Browse Source

!1664 fwkacllib support inference when ge lib is not inited

From: @lichun30
Reviewed-by: @xchu42,@ji_chen
Signed-off-by: @ji_chen
tags/v1.3.0
mindspore-ci-bot Gitee 3 years ago
parent
commit
7a8e2a79a5
5 changed files with 63 additions and 3 deletions
  1. +0
    -3
      ge/hybrid/node_executor/aicore/aicore_node_executor.cc
  2. +13
    -0
      ge/hybrid/node_executor/aicore/aicore_task_compiler.cc
  3. +1
    -0
      ge/hybrid/node_executor/aicore/aicore_task_compiler.h
  4. +1
    -0
      tests/ut/ge/CMakeLists.txt
  5. +48
    -0
      tests/ut/ge/hybrid/node_executor/aicore/aicore_task_compiler_unittest.cc

+ 0
- 3
ge/hybrid/node_executor/aicore/aicore_node_executor.cc View File

@@ -41,9 +41,6 @@ AiCoreNodeTask::AiCoreNodeTask(std::vector<std::unique_ptr<AiCoreOpTask>> &&task

Status AiCoreNodeExecutor::Initialize() {
compiler_ = TaskCompilerFactory::GetInstance().GetTaskCompiler();
if (compiler_ != nullptr) {
GE_CHK_STATUS_RET(compiler_->Initialize(), "[Init][TaskCompiler] failed.");
}
return SUCCESS;
}



+ 13
- 0
ge/hybrid/node_executor/aicore/aicore_task_compiler.cc View File

@@ -31,6 +31,11 @@ REGISTER_TASK_COMPILER(AiCoreTaskCompiler);
std::mutex AiCoreTaskCompiler::mu_;

Status AiCoreTaskCompiler::Initialize() {
std::lock_guard<std::mutex> 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<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);
GELOGI("AiCoreTaskCompiler(%s) CompileOp Start.", node->GetName().c_str());



+ 1
- 0
ge/hybrid/node_executor/aicore/aicore_task_compiler.h View File

@@ -34,6 +34,7 @@ class AiCoreTaskCompiler : public TaskCompiler {
Status DoCompileOp(const NodePtr &node) const;
Status DoGenerateTask(const Node &node, std::vector<domi::TaskDef> &tasks);
OpsKernelInfoStorePtr aic_kernel_store_;
bool is_initialized_ = false;
static std::mutex mu_;
};
} // namespace hybrid


+ 1
- 0
tests/ut/ge/CMakeLists.txt View File

@@ -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


+ 48
- 0
tests/ut/ge/hybrid/node_executor/aicore/aicore_task_compiler_unittest.cc View File

@@ -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


Loading…
Cancel
Save