| @@ -917,6 +917,15 @@ Status GeGenerator::Impl::BuildModel(const Graph &graph, const vector<GeTensor> | |||||
| static std::atomic<uint64_t> atomic_session_id(0); | static std::atomic<uint64_t> atomic_session_id(0); | ||||
| auto session_id = atomic_session_id.fetch_add(1); | auto session_id = atomic_session_id.fetch_add(1); | ||||
| // This is a temporary add for graph with variable | |||||
| auto version = static_cast<int32_t>(SessionVersion::ClOUD_VERSION); | |||||
| const int DEFAULT_DEVICE_ID = 0; | |||||
| const int DEFAULT_JOB_ID= 0; | |||||
| ret = VarManager::Instance(session_id)->Init(version, session_id, DEFAULT_DEVICE_ID, DEFAULT_JOB_ID); | |||||
| GELOGI("Start init var instance, session_id %lu", session_id); | |||||
| if (ret != SUCCESS) { | |||||
| GELOGE(ret, "Failed init var instance, session_id %lu", session_id); | |||||
| } | |||||
| if (is_singleop_unregistered_) { | if (is_singleop_unregistered_) { | ||||
| ret = graph_manager_.BuildGraphForUnregisteredOp(graph_id, inputs, ge_root_model, session_id); | ret = graph_manager_.BuildGraphForUnregisteredOp(graph_id, inputs, ge_root_model, session_id); | ||||
| } else { | } else { | ||||
| @@ -359,7 +359,10 @@ Status GraphManager::AddGraph(const GraphId &graph_id, const Graph &graph, | |||||
| std::shared_ptr<Graph> graph_ptr = MakeShared<ge::Graph>(graph); | std::shared_ptr<Graph> graph_ptr = MakeShared<ge::Graph>(graph); | ||||
| GE_IF_BOOL_EXEC(graph_ptr == nullptr, GELOGE(FAILED, "GraphPtr make shared failed"); | GE_IF_BOOL_EXEC(graph_ptr == nullptr, GELOGE(FAILED, "GraphPtr make shared failed"); | ||||
| return FAILED); | return FAILED); | ||||
| // update option about tuning graph | |||||
| ParseOption(options, BUILD_MODE, options_.build_mode); | |||||
| ParseOption(options, BUILD_STEP, options_.build_step); | |||||
| ParseOption(options, TUNING_PATH, options_.tuning_path); | |||||
| graph_node->SetGraph(graph_ptr); | graph_node->SetGraph(graph_ptr); | ||||
| graph_node->SetOptions(options); | graph_node->SetOptions(options); | ||||
| AddGraphNode(graph_id, graph_node); | AddGraphNode(graph_id, graph_node); | ||||
| @@ -433,6 +436,10 @@ Status GraphManager::AddGraphWithCopy(const GraphId &graph_id, const Graph &grap | |||||
| GELOGE(FAILED, "GraphPtr make shared failed"); | GELOGE(FAILED, "GraphPtr make shared failed"); | ||||
| return FAILED; | return FAILED; | ||||
| } | } | ||||
| // update option about tuning graph | |||||
| ParseOption(options, BUILD_MODE, options_.build_mode); | |||||
| ParseOption(options, BUILD_STEP, options_.build_step); | |||||
| ParseOption(options, TUNING_PATH, options_.tuning_path); | |||||
| graph_node->SetGraph(graph_ptr); | graph_node->SetGraph(graph_ptr); | ||||
| graph_node->SetOptions(options); | graph_node->SetOptions(options); | ||||
| @@ -1466,6 +1473,10 @@ Status GraphManager::ParseOptions(const std::map<std::string, std::string> &opti | |||||
| GE_IF_BOOL_EXEC(ret != SUCCESS, | GE_IF_BOOL_EXEC(ret != SUCCESS, | ||||
| GELOGE(GE_GRAPH_OPTIONS_INVALID, "Key:ge.compressFlag value is invalid, must be 0 or 1."); | GELOGE(GE_GRAPH_OPTIONS_INVALID, "Key:ge.compressFlag value is invalid, must be 0 or 1."); | ||||
| return GE_GRAPH_OPTIONS_INVALID); | return GE_GRAPH_OPTIONS_INVALID); | ||||
| // Set Build model and step | |||||
| ParseOption(options, BUILD_MODE, options_.build_mode); | |||||
| ParseOption(options, BUILD_STEP, options_.build_step); | |||||
| ParseOption(options, BUILD_STEP, options_.tuning_path); | |||||
| // ge.graphType. | // ge.graphType. | ||||
| options_.run_graph_flag = true; | options_.run_graph_flag = true; | ||||
| @@ -1514,10 +1525,6 @@ Status GraphManager::ParseOptions(const std::map<std::string, std::string> &opti | |||||
| GELOGD("Dynamic dims params: input shape is %s, dynamic dims is %s, dynamic node type is %d", | GELOGD("Dynamic dims params: input shape is %s, dynamic dims is %s, dynamic node type is %d", | ||||
| options_.input_shape.c_str(), options_.dynamic_dims.c_str(), options_.dynamic_node_type); | options_.input_shape.c_str(), options_.dynamic_dims.c_str(), options_.dynamic_node_type); | ||||
| // Set Build model and step | |||||
| ParseOption(options, BUILD_MODE, options_.build_mode); | |||||
| ParseOption(options, BUILD_STEP, options_.build_step); | |||||
| return SUCCESS; | return SUCCESS; | ||||
| } | } | ||||
| @@ -1549,6 +1556,7 @@ void GraphManager::ParseOption(const std::map<std::string, std::string> &options | |||||
| std::string &option) { | std::string &option) { | ||||
| auto iter = options.find(key); | auto iter = options.find(key); | ||||
| if (iter != options.end()) { | if (iter != options.end()) { | ||||
| GELOGD("Set option %s from value %s to value%s", key.c_str(), option.c_str(), iter->second.c_str()); | |||||
| option = iter->second; | option = iter->second; | ||||
| } | } | ||||
| } | } | ||||
| @@ -3132,6 +3140,21 @@ Status GraphManager::ConvertGraphToFile(ComputeGraphPtr &compute_graph, GraphPar | |||||
| non_tuning_subgraphs.push_back(sub_graph_tmp); | non_tuning_subgraphs.push_back(sub_graph_tmp); | ||||
| } | } | ||||
| } | } | ||||
| // for function graphs to tune | |||||
| for (auto &function_graph : compute_graph->GetAllSubgraphs()) { | |||||
| auto subgraph_list = sub_graph_map[function_graph]; | |||||
| for (const auto &sub_graph_info_ptr : subgraph_list) { | |||||
| GE_CHECK_NOTNULL(sub_graph_info_ptr); | |||||
| ComputeGraphPtr sub_graph_tmp = sub_graph_info_ptr->GetSubGraph(); | |||||
| // need to tuning | |||||
| if (sub_graph_info_ptr->GetEngineName() == kVectorEngine || | |||||
| sub_graph_info_ptr->GetEngineName() == kAIcoreEngine) { | |||||
| tuning_subgraphs.push_back(sub_graph_tmp); | |||||
| } else { | |||||
| non_tuning_subgraphs.push_back(sub_graph_tmp); | |||||
| } | |||||
| } | |||||
| } | |||||
| return TuningUtils::ConvertGraphToFile(tuning_subgraphs, non_tuning_subgraphs, exe_flag, path); | return TuningUtils::ConvertGraphToFile(tuning_subgraphs, non_tuning_subgraphs, exe_flag, path); | ||||
| } | } | ||||
| @@ -249,6 +249,7 @@ struct GraphManagerOptions { | |||||
| std::string save_original_model; | std::string save_original_model; | ||||
| std::string build_mode; | std::string build_mode; | ||||
| std::string build_step; | std::string build_step; | ||||
| std::string tuning_path; | |||||
| std::string input_shape; | std::string input_shape; | ||||
| std::string dynamic_dims; | std::string dynamic_dims; | ||||
| int32_t dynamic_node_type = -1; | int32_t dynamic_node_type = -1; | ||||
| @@ -275,7 +276,8 @@ struct GraphManagerOptions { | |||||
| is_single_op(false), | is_single_op(false), | ||||
| save_original_model("false"), | save_original_model("false"), | ||||
| build_mode(""), | build_mode(""), | ||||
| build_step("") {} | |||||
| build_step(""), | |||||
| tuning_path(""){} | |||||
| }; | }; | ||||
| } // namespace ge | } // namespace ge | ||||
| @@ -347,14 +347,18 @@ ge::Status VarManager::Init(const uint32_t &version, const uint64_t &session_id, | |||||
| const uint64_t &job_id) { | const uint64_t &job_id) { | ||||
| std::lock_guard<std::recursive_mutex> lock(mutex_); | std::lock_guard<std::recursive_mutex> lock(mutex_); | ||||
| GELOGI("VarManager::Init, session id = %lu.", session_id); | GELOGI("VarManager::Init, session id = %lu.", session_id); | ||||
| version_ = version; | |||||
| device_id_ = device_id; | |||||
| session_id_ = session_id; | |||||
| job_id_ = job_id; | |||||
| var_resource_ = std::unique_ptr<VarResource>(new (std::nothrow) VarResource(session_id_)); | |||||
| if (var_resource_ == nullptr) { | if (var_resource_ == nullptr) { | ||||
| GELOGW("VarManager has not been init."); | |||||
| return ge::INTERNAL_ERROR; | |||||
| version_ = version; | |||||
| device_id_ = device_id; | |||||
| session_id_ = session_id; | |||||
| job_id_ = job_id; | |||||
| var_resource_ = std::unique_ptr<VarResource>(new (std::nothrow) VarResource(session_id_)); | |||||
| if (var_resource_ == nullptr) { | |||||
| GELOGW("VarManager init failed session id = %lu.", session_id); | |||||
| return ge::INTERNAL_ERROR; | |||||
| } | |||||
| } else { | |||||
| GELOGW("VarManager::has been inited, session id = %lu.", session_id); | |||||
| } | } | ||||
| return SUCCESS; | return SUCCESS; | ||||
| } | } | ||||
| @@ -1304,7 +1304,8 @@ Status GraphPrepare::UpdateInput(const std::vector<GeTensor> &user_input, | |||||
| auto format = desc.GetFormat(); | auto format = desc.GetFormat(); | ||||
| auto origin_format = desc.GetOriginFormat(); | auto origin_format = desc.GetOriginFormat(); | ||||
| // data maybe internal format [FRACTAL_NZ] at singleop process such as GEMM. | // data maybe internal format [FRACTAL_NZ] at singleop process such as GEMM. | ||||
| bool need_check_internal_format = (!IsTansDataOpData(input_node)) && (!options_.is_single_op); | |||||
| auto tune_flag = (options_.build_mode == BUILD_MODE_TUNING) && (options_.build_step == BUILD_STEP_AFTER_BUILDER); | |||||
| bool need_check_internal_format = (!IsTansDataOpData(input_node)) && (!options_.is_single_op) && (!tune_flag); | |||||
| if (need_check_internal_format) { | if (need_check_internal_format) { | ||||
| bool is_internal = TypeUtils::IsInternalFormat(format) || TypeUtils::IsInternalFormat(origin_format); | bool is_internal = TypeUtils::IsInternalFormat(format) || TypeUtils::IsInternalFormat(origin_format); | ||||
| if (is_internal) { | if (is_internal) { | ||||
| @@ -1346,19 +1347,22 @@ Status GraphPrepare::UpdateInput(const std::vector<GeTensor> &user_input, | |||||
| return FAILED; | return FAILED; | ||||
| } | } | ||||
| ge::TensorUtils::SetSize(desc, shape_size); | ge::TensorUtils::SetSize(desc, shape_size); | ||||
| graphStatus graph_ret = op->UpdateInputDesc(0, desc); | |||||
| if (graph_ret != GRAPH_SUCCESS) { | |||||
| GELOGE(graph_ret, "UpdateInputDesc fail, graph_ret:%u", graph_ret); | |||||
| return graph_ret; | |||||
| } | |||||
| // Size will be recalculated in the build stage | |||||
| ge::TensorUtils::SetSize(desc, 0); | |||||
| graph_ret = op->UpdateOutputDesc(0, desc); | |||||
| if (graph_ret != GRAPH_SUCCESS) { | |||||
| GELOGE(graph_ret, "UpdateOutputDesc fail, graph_ret:%u", graph_ret); | |||||
| return graph_ret; | |||||
| if (!tune_flag) { | |||||
| graphStatus graph_ret = op->UpdateInputDesc(0, desc); | |||||
| if (graph_ret != GRAPH_SUCCESS) { | |||||
| GELOGE(graph_ret, "UpdateInputDesc fail, graph_ret:%u", graph_ret); | |||||
| return graph_ret; | |||||
| } | |||||
| // Size will be recalculated in the build stage | |||||
| ge::TensorUtils::SetSize(desc, 0); | |||||
| graph_ret = op->UpdateOutputDesc(0, desc); | |||||
| if (graph_ret != GRAPH_SUCCESS) { | |||||
| GELOGE(graph_ret, "UpdateOutputDesc fail, graph_ret:%u", graph_ret); | |||||
| return graph_ret; | |||||
| } | |||||
| } else { | |||||
| GELOGI("data %s skip update info in tune mode", op->GetName().c_str()); | |||||
| } | } | ||||
| if (!dynamic_shape_range_vec.empty()) { | if (!dynamic_shape_range_vec.empty()) { | ||||
| ret = UpdateDynamicInputShapeRange(index, dynamic_shape_range_vec, op, desc); | ret = UpdateDynamicInputShapeRange(index, dynamic_shape_range_vec, op, desc); | ||||
| GE_CHK_STATUS_RET(ret, "Fail to update dynamic input shape range on %s.", op->GetName().c_str()); | GE_CHK_STATUS_RET(ret, "Fail to update dynamic input shape range on %s.", op->GetName().c_str()); | ||||