Browse Source

!1644 Modify data index when input is invalid.

From: @zhao_zhixuan
Reviewed-by: @xchu42
Signed-off-by:
tags/v1.3.0
mindspore-ci-bot Gitee 3 years ago
parent
commit
04ac7dbd39
2 changed files with 43 additions and 0 deletions
  1. +41
    -0
      ge/graph/manager/graph_manager.cc
  2. +2
    -0
      ge/graph/manager/graph_manager.h

+ 41
- 0
ge/graph/manager/graph_manager.cc View File

@@ -466,6 +466,46 @@ Status GraphManager::SetStagesOptions(uint32_t graph_id, const GraphManagerOptio
return SUCCESS;
}

Status GraphManager::ModifyDataIndex(const Graph &graph, const std::map<std::string, std::string> &graph_option) {
vector<OpDescPtr> data_desc;
set<int64_t> 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<int64_t>(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);
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;
}
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<std::string, std::string> &options,
const OmgContext &omg_context) {
@@ -499,6 +539,7 @@ Status GraphManager::AddGraph(const GraphId &graph_id, const Graph &graph,
GELOGE(FAILED, "AddGraph failed.");
return FAILED;
}
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);


+ 2
- 0
ge/graph/manager/graph_manager.h View File

@@ -427,6 +427,8 @@ class GraphManager {

void SetSessionGraphId(ComputeGraphPtr compute_graph, uint32_t graph_id);

Status ModifyDataIndex(const Graph &graph, const std::map<std::string, std::string> &graph_option);

static Status CheckGraphAdded(const GraphId &graph_id, const Graph &graph);

std::atomic_bool thread_run_flag_;


Loading…
Cancel
Save