| @@ -1077,7 +1077,12 @@ Status HybridModelBuilder::InitWeights() { | |||
| Status HybridModelBuilder::LoadTasks() { | |||
| GE_CHK_STATUS_RET(CheckAicpuOpList(), "Check Aicpu op failed."); | |||
| std::map<int64_t, NodeItem *> ordered_node_items; | |||
| for (auto &it : hybrid_model_.node_items_) { | |||
| auto &node_item = it.second; | |||
| ordered_node_items.emplace(node_item->node_id, node_item.get()); | |||
| } | |||
| for (auto &it : ordered_node_items) { | |||
| auto &node_item = it.second; | |||
| auto &node_ptr = node_item->node; | |||
| if (node_item->node_type == NETOUTPUT) { | |||
| @@ -95,13 +95,6 @@ Status KnownNodeTask::UpdateArgs(TaskContext &context) { | |||
| Status KnownNodeTask::Init(TaskContext &context) { | |||
| // allocate output mem | |||
| GE_CHK_STATUS_RET(context.AllocateOutputs(), "known node task allocate output failed."); | |||
| // init davinicmodel | |||
| if (!load_flag_) { | |||
| davinci_model_->InitRuntimeParams(); | |||
| GE_CHK_STATUS_RET(davinci_model_->InitVariableMem(), "init variable mem failed."); | |||
| } | |||
| // allocate mem base | |||
| void *buffer = nullptr; | |||
| if (davinci_model_->TotalMemSize() != 0) { | |||
| @@ -129,23 +122,31 @@ Status KnownNodeTask::Init(TaskContext &context) { | |||
| void *global_step = context.GetExecutionContext()->global_step; | |||
| davinci_model_->SetKnownShapeGlobalStep(global_step); | |||
| } | |||
| int32_t device_id = 0; | |||
| rtError_t rt_ret = rtGetDevice(&device_id); | |||
| if (rt_ret != RT_ERROR_NONE || device_id < 0) { | |||
| GELOGE(rt_ret, "Call rtGetDevice failed, ret = 0x%X, device_id = %d.", rt_ret, device_id); | |||
| return RT_ERROR_TO_GE_STATUS(rt_ret); | |||
| } | |||
| davinci_model_->SetDeviceId(device_id); | |||
| GE_CHK_STATUS_RET(davinci_model_->Init(), "KnownNodeExecutor::InitDavinciModel failed."); | |||
| load_flag_ = true; | |||
| } else { | |||
| GE_CHK_STATUS_RET(ModelManager::GetInstance()->DestroyAicpuKernel(davinci_model_->GetSessionId(), | |||
| davinci_model_->Id(), davinci_model_->SubModelId()), "KnownNodeTask::Init destroy aicpu kernel failed."); | |||
| } | |||
| GE_CHK_STATUS_RET(ModelManager::GetInstance()->DestroyAicpuKernel(davinci_model_->GetSessionId(), | |||
| davinci_model_->Id(), davinci_model_->SubModelId()), | |||
| "KnownNodeTask::Init destroy aicpu kernel failed."); | |||
| GELOGI("[%s] KnownNodeExecutor::Init success.", context.GetNodeName()); | |||
| return SUCCESS; | |||
| } | |||
| Status KnownNodeTask::InitDavinciModel() { | |||
| GELOGD("[Init][Model] start"); | |||
| davinci_model_->InitRuntimeParams(); | |||
| GE_CHK_STATUS_RET(davinci_model_->InitVariableMem(), "init variable mem failed"); | |||
| int32_t device_id = 0; | |||
| GE_CHK_RT_RET(rtGetDevice(&device_id)); | |||
| davinci_model_->SetDeviceId(static_cast<uint32_t>(device_id)); | |||
| GE_CHK_STATUS_RET(DoInitDavinciModel(), "[Init][Model] Failed to init davinci model."); | |||
| GELOGD("[Init][Model] success"); | |||
| return SUCCESS; | |||
| } | |||
| Status KnownNodeTask::DoInitDavinciModel() { | |||
| return davinci_model_->Init(); | |||
| } | |||
| Status KnownNodeExecutor::PrepareTask(NodeTask &task, TaskContext &context) const { | |||
| GELOGD("[%s] KnownNodeExecutor::PrepareTask in.", context.GetNodeName()); | |||
| RECORD_EXECUTION_EVENT(context.GetExecutionContext(), context.GetNodeName(), "[KnownNodeExecutorPrepareTask] Start"); | |||
| @@ -182,9 +183,11 @@ Status KnownNodeExecutor::LoadTask(const HybridModel &model, const NodePtr &node | |||
| GE_CHK_STATUS_RET(davinci_model->Assign(ge_model), "KnownNodeExecutor::LoadTask davincimodel assign failed."); | |||
| task = MakeShared<KnownNodeTask>(davinci_model); | |||
| GE_CHECK_NOTNULL(task); | |||
| auto known_node_task = MakeShared<KnownNodeTask>(davinci_model); | |||
| GE_CHECK_NOTNULL(known_node_task); | |||
| GE_CHK_STATUS_RET_NOLOG(known_node_task->InitDavinciModel()); | |||
| GELOGI("[%s] KnownNodeExecutor::LoadTask success.", node->GetName().c_str()); | |||
| task = std::move(known_node_task); | |||
| return SUCCESS; | |||
| } | |||
| @@ -31,11 +31,15 @@ class KnownNodeTask : public NodeTask { | |||
| : davinci_model_(davinci_model) | |||
| {} | |||
| ~KnownNodeTask() {} | |||
| ~KnownNodeTask() = default; | |||
| Status UpdateArgs(TaskContext &context) override; | |||
| Status ExecuteAsync(TaskContext &context, std::function<void()> done_callback) override; | |||
| Status Init(TaskContext &context) override; | |||
| Status InitDavinciModel(); | |||
| protected: | |||
| virtual Status DoInitDavinciModel(); | |||
| private: | |||
| std::shared_ptr<DavinciModel> davinci_model_ = nullptr; | |||
| bool load_flag_ = false; | |||
| @@ -47,8 +51,6 @@ class KnownNodeExecutor : public NodeExecutor { | |||
| Status PrepareTask(NodeTask &task, TaskContext &context) const; | |||
| Status ExecuteTask(NodeTask &task, TaskContext &context, const std::function<void()> &callback) const; | |||
| ~KnownNodeExecutor() {} | |||
| private: | |||
| std::shared_ptr<DavinciModel> davinci_model_ = nullptr; | |||
| }; | |||
| } // namespace hybrid | |||
| } // namespace ge | |||
| @@ -795,6 +795,7 @@ set(PROFILING_MNG_TEST_FILES | |||
| set(HYBRID_TEST_FILES | |||
| "hybrid/ge_hybrid_unittest.cc" | |||
| "hybrid/known_node_executor_unittest.cc" | |||
| ) | |||
| set(OTHERS_TEST_FILES | |||
| @@ -51,7 +51,9 @@ class UtestGeHybrid : public testing::Test { | |||
| protected: | |||
| void SetUp() {} | |||
| void TearDown() {} | |||
| void TearDown() { | |||
| NpuMemoryAllocator::allocators_.clear(); | |||
| } | |||
| }; | |||
| static ge::OpDescPtr CreateOpDesc(string name = "", string type = "") { | |||
| @@ -0,0 +1,62 @@ | |||
| /** | |||
| * 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); | |||
| 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); | |||
| } | |||