Browse Source

!1584 fix AddGraph and AddGraphWithCopy

From: @HW_KK
Reviewed-by: @wqtshg,@youui
Signed-off-by: @youui
tags/v1.3.0
mindspore-ci-bot Gitee 3 years ago
parent
commit
c788a63811
2 changed files with 39 additions and 1 deletions
  1. +8
    -1
      ge/graph/manager/graph_manager.cc
  2. +31
    -0
      tests/ut/ge/graph/manager/graph_manager_unittest.cc

+ 8
- 1
ge/graph/manager/graph_manager.cc View File

@@ -492,9 +492,12 @@ Status GraphManager::AddGraph(const GraphId &graph_id, const Graph &graph,
}
// Do add graph
SetAddGraphCondition(graph_id, kStartAdd);
if (CheckGraphAdded(graph_id, graph) != SUCCESS) {
GELOGE(FAILED, "AddGraph failed.");
return FAILED;
}
auto compute_graph = GraphUtils::GetComputeGraph(graph);
GE_CHECK_NOTNULL(compute_graph);
compute_graph->SetGraphID(graph_id);
(void)AttrUtils::SetBool(*compute_graph, ATTR_NAME_GRAPH_HAS_BEEN_ADDED, true);
SetSessionGraphId(compute_graph, graph_id);

@@ -552,6 +555,10 @@ Status GraphManager::CheckGraphAdded(const GraphId &graph_id, const Graph &graph
Status GraphManager::AddGraphWithCopy(const GraphId &graph_id, const Graph &graph,
const std::map<std::string, std::string> &options,
const OmgContext &omg_context) {
if (HasGraphNode(graph_id)) {
GELOGE(GE_GRAPH_GRAPH_ALREADY_EXIST, "[GraphManager] graph exists, graph_id = %u", graph_id);
return GE_GRAPH_GRAPH_ALREADY_EXIST;
}
if (CheckGraphAdded(graph_id, graph) != SUCCESS) {
GELOGE(FAILED, "AddGraphWithCopy failed.");
return FAILED;


+ 31
- 0
tests/ut/ge/graph/manager/graph_manager_unittest.cc View File

@@ -206,6 +206,37 @@ TEST_F(UtestGraphManagerTest, test_add_graph_3) {
EXPECT_EQ(status2, ge::SUCCESS);
}

TEST_F(UtestGraphManagerTest, test_add_graph_4) {
GraphId graph_id = 1;
GraphManager graph_manager;
// create graph
Graph graph("test_graph");
CreateGraph(graph);
auto compute_graph = GraphUtils::GetComputeGraph(graph);
(void)AttrUtils::SetBool(*compute_graph, ATTR_NAME_GRAPH_HAS_BEEN_ADDED, true);

std::map<std::string, std::string> options;
OmgContext context;
Status status = graph_manager.AddGraph(graph_id, graph, options, context);
EXPECT_NE(status, ge::SUCCESS);
}

TEST_F(UtestGraphManagerTest, test_add_graph_with_copy_1) {
GraphId graph_id = 1;
GraphManager graph_manager;
// create graph
Graph graph("test_graph");
CreateGraph(graph);
GraphNodePtr graph_node = MakeShared<GraphNode>(graph_id);
graph_manager.graph_map_.insert({1, graph_node});

std::map<std::string, std::string> options;
OmgContext context;
Status status = graph_manager.AddGraphWithCopy(graph_id, graph, options, context);
EXPECT_NE(status, ge::SUCCESS);
}

TEST_F(UtestGraphManagerTest, test_remove_graph_1) {
GraphId graph_id = 1;
GraphManager graph_manager;


Loading…
Cancel
Save