| @@ -146,10 +146,14 @@ Status KnownNodeTask::InitDavinciModel() { | |||||
| int32_t device_id = 0; | int32_t device_id = 0; | ||||
| GE_CHK_RT_RET(rtGetDevice(&device_id)); | GE_CHK_RT_RET(rtGetDevice(&device_id)); | ||||
| davinci_model_->SetDeviceId(static_cast<uint32_t>(device_id)); | davinci_model_->SetDeviceId(static_cast<uint32_t>(device_id)); | ||||
| GE_CHK_STATUS_RET(davinci_model_->Init(), "[Init][Model] Failed to init davinci model."); | |||||
| GE_CHK_STATUS_RET(DoInitDavinciModel(), "[Init][Model] Failed to init davinci model."); | |||||
| return SUCCESS; | return SUCCESS; | ||||
| } | } | ||||
| Status KnownNodeTask::DoInitDavinciModel() { | |||||
| return davinci_model_->Init(); | |||||
| } | |||||
| Status KnownNodeExecutor::PrepareTask(NodeTask &task, TaskContext &context) const { | Status KnownNodeExecutor::PrepareTask(NodeTask &task, TaskContext &context) const { | ||||
| GELOGD("[%s] KnownNodeExecutor::PrepareTask in.", context.GetNodeName()); | GELOGD("[%s] KnownNodeExecutor::PrepareTask in.", context.GetNodeName()); | ||||
| RECORD_EXECUTION_EVENT(context.GetExecutionContext(), context.GetNodeName(), "[KnownNodeExecutorPrepareTask] Start"); | RECORD_EXECUTION_EVENT(context.GetExecutionContext(), context.GetNodeName(), "[KnownNodeExecutorPrepareTask] Start"); | ||||
| @@ -37,6 +37,9 @@ class KnownNodeTask : public NodeTask { | |||||
| Status ExecuteAsync(TaskContext &context, std::function<void()> done_callback) override; | Status ExecuteAsync(TaskContext &context, std::function<void()> done_callback) override; | ||||
| Status Init(TaskContext &context) override; | Status Init(TaskContext &context) override; | ||||
| Status InitDavinciModel(); | Status InitDavinciModel(); | ||||
| protected: | |||||
| virtual Status DoInitDavinciModel(); | |||||
| private: | private: | ||||
| std::shared_ptr<DavinciModel> davinci_model_ = nullptr; | std::shared_ptr<DavinciModel> davinci_model_ = nullptr; | ||||
| bool load_flag_ = false; | bool load_flag_ = false; | ||||
| @@ -793,6 +793,7 @@ set(PROFILING_MNG_TEST_FILES | |||||
| set(HYBRID_TEST_FILES | set(HYBRID_TEST_FILES | ||||
| "hybrid/ge_hybrid_unittest.cc" | "hybrid/ge_hybrid_unittest.cc" | ||||
| "hybrid/known_node_executor_unittest.cc" | |||||
| ) | ) | ||||
| set(OTHERS_TEST_FILES | set(OTHERS_TEST_FILES | ||||
| @@ -0,0 +1,65 @@ | |||||
| /** | |||||
| * Copyright 2019-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> | |||||
| #include <memory> | |||||
| #define protected public | |||||
| #define private public | |||||
| #include "hybrid/node_executor/compiledsubgraph/known_node_executor.h" | |||||
| #undef private | |||||
| #undef protected | |||||
| #include "graph/manager/graph_mem_allocator.h" | |||||
| using namespace std; | |||||
| using namespace testing; | |||||
| using namespace ge; | |||||
| using namespace hybrid; | |||||
| class UnknownNodeExecutorTest : public testing::Test { | |||||
| protected: | |||||
| void SetUp() {} | |||||
| void TearDown() {} | |||||
| }; | |||||
| namespace { | |||||
| class KnownNodeTaskMock : public KnownNodeTask { | |||||
| public: | |||||
| KnownNodeTaskMock(std::shared_ptr<DavinciModel> davinci_model): KnownNodeTask(davinci_model) {}; | |||||
| ~KnownNodeTaskMock() override = default; | |||||
| MOCK_METHOD0(DoInitDavinciModel, Status()); | |||||
| }; | |||||
| } | |||||
| TEST_F(UnknownNodeExecutorTest, test_init_davinci_model) { | |||||
| auto davinci_model = std::make_shared<DavinciModel>(0, nullptr); | |||||
| davinci_model->SetDeviceId(0); | |||||
| davinci_model->SetKnownNode(true); | |||||
| MemManager::Instance().Initialize(std::vector<rtMemType_t>({RT_MEMORY_HBM})); | |||||
| auto ge_model = make_shared<GeModel>(); | |||||
| AttrUtils::SetInt(ge_model, ATTR_MODEL_VAR_SIZE, 0); | |||||
| AttrUtils::SetInt(ge_model, ATTR_MODEL_MEMORY_SIZE, 1024); | |||||
| davinci_model->Assign(ge_model); | |||||
| KnownNodeTaskMock mock(davinci_model); | |||||
| EXPECT_CALL(mock, DoInitDavinciModel).WillOnce(::testing::Return(SUCCESS)); | |||||
| ASSERT_EQ(mock.InitDavinciModel(), SUCCESS); | |||||
| MemManager::Instance().Finalize(); | |||||
| } | |||||