From 43c5d42354804f3519ba206f2b7614e2e1ce2001 Mon Sep 17 00:00:00 2001 From: zhaozhixuan Date: Thu, 13 May 2021 19:31:26 +0800 Subject: [PATCH 1/6] Modify data index when input is invalid. --- ge/graph/manager/graph_manager.cc | 34 +++++++++++++++++++ ge/graph/manager/graph_manager.h | 2 ++ .../graph/manager/graph_manager_unittest.cc | 20 +++++------ 3 files changed, 46 insertions(+), 10 deletions(-) diff --git a/ge/graph/manager/graph_manager.cc b/ge/graph/manager/graph_manager.cc index 31e5b5ab..6dd9f95d 100755 --- a/ge/graph/manager/graph_manager.cc +++ b/ge/graph/manager/graph_manager.cc @@ -466,6 +466,39 @@ Status GraphManager::SetStagesOptions(uint32_t graph_id, const GraphManagerOptio return SUCCESS; } +Status GraphManager::ModifyDataIndex(const Graph &graph) { + vector data_desc; + set indexes; + auto compute_graph = GraphUtils::GetComputeGraph(graph); + GE_CHECK_NOTNULL(compute_graph); + for (auto &input_node : compute_graph->GetDirectNode()) { + GE_CHECK_NOTNULL(input_node); + auto op = input_node->GetOpDesc(); + GE_CHECK_NOTNULL(op); + if (op->GetType() == DATA) { + int64_t index = 0; + (void) AttrUtils::GetInt(op, ATTR_NAME_INDEX, index); + indexes.insert(index); + data_desc.emplace_back(op); + } + } + if (!indexes.empty()) { + auto first_iter = indexes.begin(); + auto end_iter = indexes.end(); + --end_iter; + auto data_size = static_cast(data_desc.size()); + // The valid index starts with 0 and increases by 1, and num is equal to data_node. + if (indexes.size() != data_desc.size() || *first_iter != 0 || *end_iter != data_size - 1) { + GELOGI("Graph[%s] input data index is invalid, set data index by topo order.", compute_graph->GetName().c_str()); + int64_t index = 0; + for (auto &op : data_desc) { + (void) AttrUtils::SetInt(op, ATTR_NAME_INDEX, index++); + } + } + } + return SUCCESS; +} + Status GraphManager::AddGraph(const GraphId &graph_id, const Graph &graph, const std::map &options, const OmgContext &omg_context) { @@ -499,6 +532,7 @@ Status GraphManager::AddGraph(const GraphId &graph_id, const Graph &graph, GELOGE(FAILED, "AddGraph failed."); return FAILED; } + GE_CHK_STATUS_RET(ModifyDataIndex(graph)); auto compute_graph = GraphUtils::GetComputeGraph(graph); GE_CHECK_NOTNULL(compute_graph); (void)AttrUtils::SetBool(*compute_graph, ATTR_NAME_GRAPH_HAS_BEEN_ADDED, true); diff --git a/ge/graph/manager/graph_manager.h b/ge/graph/manager/graph_manager.h index 36c1143f..1cf60eef 100644 --- a/ge/graph/manager/graph_manager.h +++ b/ge/graph/manager/graph_manager.h @@ -427,6 +427,8 @@ class GraphManager { void SetSessionGraphId(ComputeGraphPtr compute_graph, uint32_t graph_id); + Status ModifyDataIndex(const Graph &graph); + static Status CheckGraphAdded(const GraphId &graph_id, const Graph &graph); std::atomic_bool thread_run_flag_; diff --git a/tests/ut/ge/graph/manager/graph_manager_unittest.cc b/tests/ut/ge/graph/manager/graph_manager_unittest.cc index fafd7168..33b60ac7 100644 --- a/tests/ut/ge/graph/manager/graph_manager_unittest.cc +++ b/tests/ut/ge/graph/manager/graph_manager_unittest.cc @@ -194,16 +194,16 @@ TEST_F(UtestGraphManagerTest, test_add_graph_3) { std::map options; OmgContext context; - std::future fut1 = std::async(std::launch::async, - &GraphManager::AddGraph, &graph_manager, graph_id, graph, options, context); - std::future fut2 = std::async(std::launch::async, - &GraphManager::AddGraph, &graph_manager, graph_id, graph, options, context); - fut1.wait(); - fut2.wait(); - Status status1 = fut1.get(); - Status status2 = fut2.get(); - EXPECT_EQ(status1, ge::SUCCESS); - EXPECT_EQ(status2, ge::SUCCESS); + // std::future fut1 = std::async(std::launch::async, + // &GraphManager::AddGraph, &graph_manager, graph_id, graph, options, context); + // std::future fut2 = std::async(std::launch::async, + // &GraphManager::AddGraph, &graph_manager, graph_id, graph, options, context); + // fut1.wait(); + // fut2.wait(); + // Status status1 = fut1.get(); + // Status status2 = fut2.get(); + // EXPECT_EQ(status1, ge::SUCCESS); + // EXPECT_EQ(status2, ge::SUCCESS); } TEST_F(UtestGraphManagerTest, test_add_graph_4) { From 9ec0b5a3c1ed03d28d430fd4493124eef52d675c Mon Sep 17 00:00:00 2001 From: zhaozhixuan Date: Thu, 13 May 2021 19:31:44 +0800 Subject: [PATCH 2/6] Modify data index when input is invalid. --- .../graph/manager/graph_manager_unittest.cc | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/ut/ge/graph/manager/graph_manager_unittest.cc b/tests/ut/ge/graph/manager/graph_manager_unittest.cc index 33b60ac7..fafd7168 100644 --- a/tests/ut/ge/graph/manager/graph_manager_unittest.cc +++ b/tests/ut/ge/graph/manager/graph_manager_unittest.cc @@ -194,16 +194,16 @@ TEST_F(UtestGraphManagerTest, test_add_graph_3) { std::map options; OmgContext context; - // std::future fut1 = std::async(std::launch::async, - // &GraphManager::AddGraph, &graph_manager, graph_id, graph, options, context); - // std::future fut2 = std::async(std::launch::async, - // &GraphManager::AddGraph, &graph_manager, graph_id, graph, options, context); - // fut1.wait(); - // fut2.wait(); - // Status status1 = fut1.get(); - // Status status2 = fut2.get(); - // EXPECT_EQ(status1, ge::SUCCESS); - // EXPECT_EQ(status2, ge::SUCCESS); + std::future fut1 = std::async(std::launch::async, + &GraphManager::AddGraph, &graph_manager, graph_id, graph, options, context); + std::future fut2 = std::async(std::launch::async, + &GraphManager::AddGraph, &graph_manager, graph_id, graph, options, context); + fut1.wait(); + fut2.wait(); + Status status1 = fut1.get(); + Status status2 = fut2.get(); + EXPECT_EQ(status1, ge::SUCCESS); + EXPECT_EQ(status2, ge::SUCCESS); } TEST_F(UtestGraphManagerTest, test_add_graph_4) { From 74f71027bc304c2ea5952941c41305d5908f9464 Mon Sep 17 00:00:00 2001 From: zhaozhixuan Date: Sat, 15 May 2021 15:15:22 +0800 Subject: [PATCH 3/6] Add shape range check. --- ge/graph/manager/graph_manager.cc | 11 +++++++++-- ge/graph/manager/graph_manager.h | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ge/graph/manager/graph_manager.cc b/ge/graph/manager/graph_manager.cc index 6dd9f95d..ff7e4b3a 100755 --- a/ge/graph/manager/graph_manager.cc +++ b/ge/graph/manager/graph_manager.cc @@ -466,7 +466,7 @@ Status GraphManager::SetStagesOptions(uint32_t graph_id, const GraphManagerOptio return SUCCESS; } -Status GraphManager::ModifyDataIndex(const Graph &graph) { +Status GraphManager::ModifyDataIndex(const Graph &graph, const std::map &graph_option) { vector data_desc; set indexes; auto compute_graph = GraphUtils::GetComputeGraph(graph); @@ -489,6 +489,13 @@ Status GraphManager::ModifyDataIndex(const Graph &graph) { auto data_size = static_cast(data_desc.size()); // The valid index starts with 0 and increases by 1, and num is equal to data_node. if (indexes.size() != data_desc.size() || *first_iter != 0 || *end_iter != data_size - 1) { + auto iter = graph_option.find(OPTION_EXEC_DATA_INPUTS_SHAPE_RANGE); + bool enable_input_shape_range = (iter != graph_option.end()) && (!iter->second.empty()); + if (enable_input_shape_range) { + REPORT_INNER_ERROR("E19999", "Input data index is invalid when data shape range enabled, please check!"); + GELOGE(GRAPH_PARAM_INVALID, "Input data index is invalid when data shape range enabled."); + return GRAPH_PARAM_INVALID; + } GELOGI("Graph[%s] input data index is invalid, set data index by topo order.", compute_graph->GetName().c_str()); int64_t index = 0; for (auto &op : data_desc) { @@ -532,7 +539,7 @@ Status GraphManager::AddGraph(const GraphId &graph_id, const Graph &graph, GELOGE(FAILED, "AddGraph failed."); return FAILED; } - GE_CHK_STATUS_RET(ModifyDataIndex(graph)); + GE_CHK_STATUS_RET(ModifyDataIndex(graph, options)); auto compute_graph = GraphUtils::GetComputeGraph(graph); GE_CHECK_NOTNULL(compute_graph); (void)AttrUtils::SetBool(*compute_graph, ATTR_NAME_GRAPH_HAS_BEEN_ADDED, true); diff --git a/ge/graph/manager/graph_manager.h b/ge/graph/manager/graph_manager.h index 1cf60eef..945a5e5d 100644 --- a/ge/graph/manager/graph_manager.h +++ b/ge/graph/manager/graph_manager.h @@ -427,7 +427,7 @@ class GraphManager { void SetSessionGraphId(ComputeGraphPtr compute_graph, uint32_t graph_id); - Status ModifyDataIndex(const Graph &graph); + Status ModifyDataIndex(const Graph &graph, const std::map &graph_option); static Status CheckGraphAdded(const GraphId &graph_id, const Graph &graph); From 7c34f730986a1ddf05c8832625664ceaed6cfd92 Mon Sep 17 00:00:00 2001 From: zhaozhixuan Date: Sat, 15 May 2021 15:33:51 +0800 Subject: [PATCH 4/6] Add shape range check. --- ge/graph/manager/graph_manager.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ge/graph/manager/graph_manager.cc b/ge/graph/manager/graph_manager.cc index ff7e4b3a..6e8478d8 100755 --- a/ge/graph/manager/graph_manager.cc +++ b/ge/graph/manager/graph_manager.cc @@ -493,7 +493,7 @@ Status GraphManager::ModifyDataIndex(const Graph &graph, const std::mapsecond.empty()); if (enable_input_shape_range) { REPORT_INNER_ERROR("E19999", "Input data index is invalid when data shape range enabled, please check!"); - GELOGE(GRAPH_PARAM_INVALID, "Input data index is invalid when data shape range enabled."); + GELOGE(GRAPH_PARAM_INVALID, "[COMP][AddGraph]Input data index is invalid when data shape range enabled."); return GRAPH_PARAM_INVALID; } GELOGI("Graph[%s] input data index is invalid, set data index by topo order.", compute_graph->GetName().c_str()); From f3e50acb9e724974bb3c8b5f25e38a2692d33aaf Mon Sep 17 00:00:00 2001 From: zhaozhixuan Date: Sat, 15 May 2021 16:16:13 +0800 Subject: [PATCH 5/6] Add shape range check. --- ge/graph/manager/graph_manager.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ge/graph/manager/graph_manager.cc b/ge/graph/manager/graph_manager.cc index 6e8478d8..02a500fe 100755 --- a/ge/graph/manager/graph_manager.cc +++ b/ge/graph/manager/graph_manager.cc @@ -490,8 +490,8 @@ Status GraphManager::ModifyDataIndex(const Graph &graph, const std::mapsecond.empty()); - if (enable_input_shape_range) { + if (iter != graph_option.end()) && (!iter->second.empty()) { + // If data inputs shape range is set, user must set valid data index. REPORT_INNER_ERROR("E19999", "Input data index is invalid when data shape range enabled, please check!"); GELOGE(GRAPH_PARAM_INVALID, "[COMP][AddGraph]Input data index is invalid when data shape range enabled."); return GRAPH_PARAM_INVALID; From 52df3661c70d734ae3a72f8dc295b2987c952ede Mon Sep 17 00:00:00 2001 From: zhaozhixuan Date: Sat, 15 May 2021 16:28:42 +0800 Subject: [PATCH 6/6] Add shape range check. --- ge/graph/manager/graph_manager.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ge/graph/manager/graph_manager.cc b/ge/graph/manager/graph_manager.cc index 02a500fe..241ca0b2 100755 --- a/ge/graph/manager/graph_manager.cc +++ b/ge/graph/manager/graph_manager.cc @@ -490,7 +490,7 @@ Status GraphManager::ModifyDataIndex(const Graph &graph, const std::mapsecond.empty()) { + if (iter != graph_option.end() && !iter->second.empty()) { // If data inputs shape range is set, user must set valid data index. REPORT_INNER_ERROR("E19999", "Input data index is invalid when data shape range enabled, please check!"); GELOGE(GRAPH_PARAM_INVALID, "[COMP][AddGraph]Input data index is invalid when data shape range enabled.");