From ac62f5d2ce90ae4a00f5f285a000ea95e9cf2ab1 Mon Sep 17 00:00:00 2001 From: lichun Date: Wed, 12 May 2021 17:24:03 +0800 Subject: [PATCH] support fwk offline inference when ge_lib is not initialized --- tests/ut/ge/CMakeLists.txt | 1 + .../aicore/aicore_task_compiler_unittest.cc | 55 ++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 tests/ut/ge/hybrid/node_executor/aicore/aicore_task_compiler_unittest.cc diff --git a/tests/ut/ge/CMakeLists.txt b/tests/ut/ge/CMakeLists.txt index 7cdec968..16e30c94 100755 --- a/tests/ut/ge/CMakeLists.txt +++ b/tests/ut/ge/CMakeLists.txt @@ -828,6 +828,7 @@ set(HYBRID_TEST_FILES "hybrid/executor/worker/execution_engine_unittest.cc" "hybrid/model/hybrid_model_builder_unittest.cc" "hybrid/node_executor/rts/rts_node_task_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..a33b3675 --- /dev/null +++ b/tests/ut/ge/hybrid/node_executor/aicore/aicore_task_compiler_unittest.cc @@ -0,0 +1,55 @@ +/** + * 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" + +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) { + AicoreTaskCompiler aicore_task_compiler; + NodePtr node = nullptr; + std::vector tasks{}; + ASSERT_EQ(aicore_task_compiler.Initialize(), FAILED); // cause: ge lib is nullptr + ASSERT_EQ(aicore_task_compiler.CompileOp(node, tasks), FAILED); // cause: aicore task compiler init failed. + + std::shared_ptr ge_lib_ptr = MakeShared(); + ge_lib_ptr->init_flag_ = true; + OpsKernelManager OpsKernelManagerObj; + OpsKernelInfoStorePtr ops_kernel_info_store = MakeShared(new OpsKernelInfoStore()); + OpsKernelManagerObj.ops_kernel_store_.insert("AIcoreEngine", ops_kernel_info_store); + ASSERT_EQ(aicore_task_compiler.CompileOp(node, tasks), FAILED); // cause: node is nullptr + ASSERT_EQ(aicore_task_compiler.is_initialized_, true); // though CompileOp failed since node is nullptr, + // but aicore_task_compiler init success. +} +} // namespace ge +