From c21ca96511887552b2a857af4d4a5076fb319066 Mon Sep 17 00:00:00 2001 From: zhangxiaokun Date: Fri, 19 Feb 2021 15:29:22 +0800 Subject: [PATCH 1/3] Fix No NetOutput Model Logic --- ge/graph/load/model_manager/davinci_model.cc | 13 +++++++------ ge/graph/load/model_manager/davinci_model.h | 1 + 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/ge/graph/load/model_manager/davinci_model.cc b/ge/graph/load/model_manager/davinci_model.cc index 9954ceaf..1899af37 100755 --- a/ge/graph/load/model_manager/davinci_model.cc +++ b/ge/graph/load/model_manager/davinci_model.cc @@ -1095,6 +1095,7 @@ Status DavinciModel::InitNetOutput(const ComputeGraphPtr &graph, const NodePtr & GELOGI("Init NetOutput node: %s.", op_desc->GetName().c_str()); output_op_list.push_back(op_desc); + has_output_node_ = true; if (known_node_) { return SUCCESS; } @@ -2422,7 +2423,7 @@ void DavinciModel::SetProfileTime(ModelProcStage stage, int64_t endTime) { /// @author /// Status DavinciModel::CopyOutputData(uint32_t data_id, OutputData &output_data, rtMemcpyKind_t kind) { - if (output_addrs_list_.empty()) { + if (!has_output_node_) { Status ret = SyncVarData(); return ret; } @@ -2582,7 +2583,7 @@ Status DavinciModel::ReturnResult(uint32_t data_id, const bool rslt_flg, const b return INTERNAL_ERROR; } - if (output_addrs_list_.empty()) { + if (!has_output_node_) { GELOGW("Output tensor list is empty, model id: %u", model_id_); GE_CHK_STATUS(listener_->OnComputeDone(model_id_, data_id, INTERNAL_ERROR, outputs), "OnComputeDone failed."); return INTERNAL_ERROR; @@ -2735,10 +2736,10 @@ void *DavinciModel::Run(DavinciModel *model) { model->SetProfileTime(MODEL_AFTER_PROC_START)); GE_TIMESTAMP_START(ReturnResult3); // copy output data from device to host - GE_IF_BOOL_EXEC(!model->output_addrs_list_.empty(), - (void)model->ReturnResult(current_data.index, rslt_flg, false, data_wrapper->GetOutput())) + GE_IF_BOOL_EXEC(model->has_output_node_, + (void)model->ReturnResult(current_data.index, rslt_flg, false, data_wrapper->GetOutput())); // copy output data from device to host for variable graph - GE_IF_BOOL_EXEC(model->output_addrs_list_.empty(), (void)model->ReturnNoOutput(current_data.index)); + GE_IF_BOOL_EXEC(!model->has_output_node_, (void)model->ReturnNoOutput(current_data.index)); GE_IF_BOOL_EXEC(model->is_first_execute_, GE_TIMESTAMP_EVENT_END(ReturnResult3, "GraphExcute::CopyDataFromDeviceToHost")); GE_IF_BOOL_EXEC(ProfilingManager::Instance().ProfilingModelExecuteOn(), @@ -2890,7 +2891,7 @@ Status DavinciModel::CreateKnownZeroCopyMap(const vector &inputs, const GELOGI("input %zu, v addr %p, r addr %p, p addr %p", i, addr_list[kDataIndex], addr, inputs[i]); } - if (output_addrs_list_.empty()) { + if (!has_output_node_) { GELOGW("output op num in graph is %zu", output_addrs_list_.size()); return SUCCESS; } diff --git a/ge/graph/load/model_manager/davinci_model.h b/ge/graph/load/model_manager/davinci_model.h index 31cc9939..5bc3a68e 100755 --- a/ge/graph/load/model_manager/davinci_model.h +++ b/ge/graph/load/model_manager/davinci_model.h @@ -1042,6 +1042,7 @@ class DavinciModel { // For super kernel. SuperKernelTaskInfo skt_info_; + bool has_output_node_ = false; bool is_dynamic_aipp_ = false; vector dynamic_output_shape_info_; From dd9099f6614b396c3aafc2e914193a74176648b1 Mon Sep 17 00:00:00 2001 From: zhangxiaokun Date: Fri, 19 Feb 2021 16:21:47 +0800 Subject: [PATCH 2/3] Add unit test for no NetOutput --- ge/graph/load/model_manager/davinci_model.cc | 3 +-- .../ut/ge/graph/load/davinci_model_unittest.cc | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/ge/graph/load/model_manager/davinci_model.cc b/ge/graph/load/model_manager/davinci_model.cc index 1899af37..e921aefe 100755 --- a/ge/graph/load/model_manager/davinci_model.cc +++ b/ge/graph/load/model_manager/davinci_model.cc @@ -2424,8 +2424,7 @@ void DavinciModel::SetProfileTime(ModelProcStage stage, int64_t endTime) { /// Status DavinciModel::CopyOutputData(uint32_t data_id, OutputData &output_data, rtMemcpyKind_t kind) { if (!has_output_node_) { - Status ret = SyncVarData(); - return ret; + return SyncVarData(); } output_data.index = data_id; diff --git a/tests/ut/ge/graph/load/davinci_model_unittest.cc b/tests/ut/ge/graph/load/davinci_model_unittest.cc index c90a4997..f10068aa 100644 --- a/tests/ut/ge/graph/load/davinci_model_unittest.cc +++ b/tests/ut/ge/graph/load/davinci_model_unittest.cc @@ -27,6 +27,16 @@ using namespace std; namespace ge { extern OpDescPtr CreateOpDesc(string name, string type); +class DModelListener : public ModelListener { + public: + DModelListener(){}; + uint32_t OnComputeDone(uint32_t model_id, uint32_t data_index, uint32_t result, vector &outputs) { + return 0; + } +}; + +shared_ptr g_local_call_back(new DModelListener()); + class UtestDavinciModel : public testing::Test { protected: void SetUp() {} @@ -309,7 +319,7 @@ TEST_F(UtestDavinciModel, init_unknown) { } TEST_F(UtestDavinciModel, Init_variable_op) { - DavinciModel model(0, nullptr); + DavinciModel model(0, g_local_call_back); model.ge_model_ = make_shared(); model.runtime_param_.mem_base = (uint8_t *)0x08000000; model.runtime_param_.mem_size = 5120000; @@ -337,6 +347,12 @@ TEST_F(UtestDavinciModel, Init_variable_op) { EXPECT_EQ(model.ReturnNoOutput(1), PARAM_INVALID); EXPECT_EQ(model.SyncVarData(), SUCCESS); + + OutputData output_data; + EXPECT_FALSE(model.has_output_node_); + EXPECT_EQ(model.CopyOutputData(1, output_data, RT_MEMCPY_DEVICE_TO_HOST), SUCCESS); + + EXPECT_EQ(model.ReturnResult(1, false, true, &output_data), INTERNAL_ERROR); } TEST_F(UtestDavinciModel, InitRealSizeAndShapeInfo_succ1) { From 75bcf24692072918d51963f02d29502cce70c951 Mon Sep 17 00:00:00 2001 From: zhangxiaokun Date: Fri, 19 Feb 2021 16:31:29 +0800 Subject: [PATCH 3/3] Add unit test for no NetOutput --- tests/ut/ge/graph/load/davinci_model_unittest.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ut/ge/graph/load/davinci_model_unittest.cc b/tests/ut/ge/graph/load/davinci_model_unittest.cc index f10068aa..b8a963e3 100644 --- a/tests/ut/ge/graph/load/davinci_model_unittest.cc +++ b/tests/ut/ge/graph/load/davinci_model_unittest.cc @@ -345,7 +345,7 @@ TEST_F(UtestDavinciModel, Init_variable_op) { EXPECT_EQ(model.InitNodes(graph), SUCCESS); - EXPECT_EQ(model.ReturnNoOutput(1), PARAM_INVALID); + EXPECT_EQ(model.ReturnNoOutput(1), SUCCESS); EXPECT_EQ(model.SyncVarData(), SUCCESS); OutputData output_data;