已合并
【feat】: JIT 调度与切图解耦,开启自动融合时整图jit执行 #4566
chengyutao3创建于 8月26日
【feat】: JIT 调度与切图解耦,开启自动融合时整图jit执行 #4566
已合并
chengyutao3创建于 8月26日
共 19 个文件变更+492-188
@@ -1262,13 +1262,13 @@ Status Session::SetGraphConstMemoryBase(uint32_t graph_id, const void *const mem
1262 "correctly executed before setting the graph const memory base"}));1262 "correctly executed before setting the graph const memory base"}));
1263 return FAILED;1263 return FAILED;
1264 }1264 }
1265- if (EnableSliceSchedule()) {1265+ if (EnableAutoFuse()) {
1266 GELOGE(UNSUPPORTED,1266 GELOGE(UNSUPPORTED,
1267- "[Construct][Session]SetGraphConstMemoryBase does not support the slice scheduler currently, "1267+ "[Construct][Session]SetGraphConstMemoryBase does not support the JIT executor currently, "
1268 "session_id:%" PRIu64 ", graph_id:%u, memory:%p, size:%zu",1268 "session_id:%" PRIu64 ", graph_id:%u, memory:%p, size:%zu",
1269 sessionId_, graph_id, memory, size);1269 sessionId_, graph_id, memory, size);
1270 REPORT_INNER_ERR_MSG("E19999",1270 REPORT_INNER_ERR_MSG("E19999",
1271- "SetGraphConstMemoryBase does not support the slice scheduler currently, session_id:%" PRIu641271+ "SetGraphConstMemoryBase does not support the JIT executor currently, session_id:%" PRIu64
1272 ", graph_id:%u, memory:%p, size:%zu",1272 ", graph_id:%u, memory:%p, size:%zu",
1273 sessionId_, graph_id, memory, size);1273 sessionId_, graph_id, memory, size);
1274 return UNSUPPORTED;1274 return UNSUPPORTED;
@@ -1306,16 +1306,15 @@ Status Session::UpdateGraphFeatureMemoryBase(uint32_t graph_id, const void *cons
1306 "correctly executed before updating the graph feature memory base"}));1306 "correctly executed before updating the graph feature memory base"}));
1307 return FAILED;1307 return FAILED;
1308 }1308 }
1309- if (EnableSliceSchedule()) {1309+ if (EnableAutoFuse()) {
1310 GELOGE(UNSUPPORTED,1310 GELOGE(UNSUPPORTED,
1311- "[Construct][Session]UpdateGraphFeatureMemoryBase does not support the slice scheduler currently, "1311+ "[Construct][Session]UpdateGraphFeatureMemoryBase does not support the JIT executor currently, "
1312 "session_id:%" PRIu64 ", graph_id:%u, memory:%p, size:%zu",1312 "session_id:%" PRIu64 ", graph_id:%u, memory:%p, size:%zu",
1313 sessionId_, graph_id, memory, size);1313 sessionId_, graph_id, memory, size);
1314- REPORT_INNER_ERR_MSG(1314+ REPORT_INNER_ERR_MSG("E19999",
1315- "E19999",1315+ "UpdateGraphFeatureMemoryBase does not support the JIT executor currently, session_id:%" PRIu64
1316- "UpdateGraphFeatureMemoryBase does not support the slice scheduler currently, session_id:%" PRIu641316+ ", graph_id:%u, memory:%p, size:%zu",
1317- ", graph_id:%u, memory:%p, size:%zu",1317+ sessionId_, graph_id, memory, size);
1318- sessionId_, graph_id, memory, size);
1319 return UNSUPPORTED;1318 return UNSUPPORTED;
1320 }1319 }
1321 const auto inner_session = g_session_manager->GetSession(sessionId_);1320 const auto inner_session = g_session_manager->GetSession(sessionId_);
@@ -1356,14 +1355,14 @@ Status Session::SetGraphFixedFeatureMemoryBaseWithType(uint32_t graph_id, Memory
1356 "correctly executed before setting the graph fixed feature memory base with type"}));1355 "correctly executed before setting the graph fixed feature memory base with type"}));
1357 return FAILED;1356 return FAILED;
1358 }1357 }
1359- if (EnableSliceSchedule()) {1358+ if (EnableAutoFuse()) {
1360 GELOGE(UNSUPPORTED,1359 GELOGE(UNSUPPORTED,
1361- "[Construct][Session]SetGraphFixedFeatureMemoryBaseWithType does not support the slice scheduler currently, "1360+ "[Construct][Session]SetGraphFixedFeatureMemoryBaseWithType does not support the JIT executor currently, "
1362 "session_id:%" PRIu64 ", graph_id:%u, type:%d, memory:%p, size:%zu",1361 "session_id:%" PRIu64 ", graph_id:%u, type:%d, memory:%p, size:%zu",
1363 sessionId_, graph_id, type, memory, size);1362 sessionId_, graph_id, type, memory, size);
1364 REPORT_INNER_ERR_MSG(1363 REPORT_INNER_ERR_MSG(
1365 "E19999",1364 "E19999",
1366- "SetGraphFixedFeatureMemoryBaseWithType does not support the slice scheduler currently, session_id:%" PRIu641365+ "SetGraphFixedFeatureMemoryBaseWithType does not support the JIT executor currently, session_id:%" PRIu64
1367 ", graph_id:%u, memory:%p, size:%zu",1366 ", graph_id:%u, memory:%p, size:%zu",
1368 sessionId_, graph_id, memory, size);1367 sessionId_, graph_id, memory, size);
1369 return UNSUPPORTED;1368 return UNSUPPORTED;
@@ -1403,14 +1402,14 @@ Status Session::UpdateGraphRefreshableFeatureMemoryBase(uint32_t graph_id, const
1403 "correctly executed before updating the graph refreshable feature memory base"}));1402 "correctly executed before updating the graph refreshable feature memory base"}));
1404 return FAILED;1403 return FAILED;
1405 }1404 }
1406- if (EnableSliceSchedule()) {1405+ if (EnableAutoFuse()) {
1407 GELOGE(UNSUPPORTED,1406 GELOGE(UNSUPPORTED,
1408- "[Construct][Session]UpdateGraphRefreshableFeatureMemoryBase does not support the slice scheduler "1407+ "[Construct][Session]UpdateGraphRefreshableFeatureMemoryBase does not support the JIT executor "
1409 "currently, session_id:%" PRIu64 ", graph_id:%u, memory:%p, size:%zu",1408 "currently, session_id:%" PRIu64 ", graph_id:%u, memory:%p, size:%zu",
1410 sessionId_, graph_id, memory, size);1409 sessionId_, graph_id, memory, size);
1411 REPORT_INNER_ERR_MSG(1410 REPORT_INNER_ERR_MSG(
1412 "E19999",1411 "E19999",
1413- "UpdateGraphRefreshableFeatureMemoryBase does not support the slice scheduler currently, session_id:%" PRIu641412+ "UpdateGraphRefreshableFeatureMemoryBase does not support the JIT executor currently, session_id:%" PRIu64
1414 ", graph_id:%u, memory:%p, size:%zu",1413 ", graph_id:%u, memory:%p, size:%zu",
1415 sessionId_, graph_id, memory, size);1414 sessionId_, graph_id, memory, size);
1416 return UNSUPPORTED;1415 return UNSUPPORTED;
@@ -697,7 +697,7 @@ Status GeSession::RunGraph(uint32_t graph_id, const std::vector<gert::Tensor> &i
697 auto ret = CheckRunGraphMode(cur_mode, graph_id, RunGraphMode::kRunGraph);697 auto ret = CheckRunGraphMode(cur_mode, graph_id, RunGraphMode::kRunGraph);
698 GE_CHK_BOOL_RET_STATUS(ret == SUCCESS, ret, "Run graph failed, error code:%u, session_id:%lu, graph_id:%u.", ret,698 GE_CHK_BOOL_RET_STATUS(ret == SUCCESS, ret, "Run graph failed, error code:%u, session_id:%lu, graph_id:%u.", ret,
699 GetSessionId(), graph_id);699 GetSessionId(), graph_id);
700- if (!impl_->GetLoadFlag(graph_id)) {700+ if (!EnableAutoFuse() && !impl_->GetLoadFlag(graph_id)) {
701 GELOGI("Graph is not loaded, start to load graph, session_id:%lu, graph_id:%u", GetSessionId(), graph_id);701 GELOGI("Graph is not loaded, start to load graph, session_id:%lu, graph_id:%u", GetSessionId(), graph_id);
702 ret = LoadGraph(graph_id, {}, nullptr);702 ret = LoadGraph(graph_id, {}, nullptr);
703 GE_CHK_BOOL_RET_STATUS(ret == SUCCESS, ret, "Run graph failed, error code:%u, session_id:%lu, graph_id:%u.", ret,703 GE_CHK_BOOL_RET_STATUS(ret == SUCCESS, ret, "Run graph failed, error code:%u, session_id:%lu, graph_id:%u.", ret,
@@ -988,14 +988,13 @@ Status GeSession::SetGraphConstMemoryBase(uint32_t graph_id, const void *const m
988 return FAILED;988 return FAILED;
989 }989 }
990 GE_CHK_BOOL_RET_STATUS(impl_ != nullptr, FAILED, "GeSession construction incomplete (null impl pointer)");990 GE_CHK_BOOL_RET_STATUS(impl_ != nullptr, FAILED, "GeSession construction incomplete (null impl pointer)");
991- if (EnableSliceSchedule()) {991+ if (EnableAutoFuse()) {
992- GELOGE(992+ GELOGE(UNSUPPORTED,
993- UNSUPPORTED,993+ "[Construct][GeSession]SetGraphConstMemoryBase does not support the JIT executor currently, session_id:%lu, "
994- "[Construct][GeSession]SetGraphConstMemoryBase does not support the slice scheduler currently, session_id:%lu, "994+ "graph_id:%u, memory:%p, size:%zu",
995- "graph_id:%u, memory:%p, size:%zu",995+ GetSessionId(), graph_id, memory, size);
996- GetSessionId(), graph_id, memory, size);
997 REPORT_INNER_ERR_MSG("E19999",996 REPORT_INNER_ERR_MSG("E19999",
998- "SetGraphConstMemoryBase does not support the slice scheduler currently, session_id:%lu, "997+ "SetGraphConstMemoryBase does not support the JIT executor currently, session_id:%lu, "
999 "graph_id:%u, memory:%p, size:%zu",998 "graph_id:%u, memory:%p, size:%zu",
1000 GetSessionId(), graph_id, memory, size);999 GetSessionId(), graph_id, memory, size);
1001 return UNSUPPORTED;1000 return UNSUPPORTED;
@@ -1019,14 +1018,14 @@ Status GeSession::UpdateGraphFeatureMemoryBase(uint32_t graph_id, const void *co
1019 return FAILED;1018 return FAILED;
1020 }1019 }
1021 GE_CHK_BOOL_RET_STATUS(impl_ != nullptr, FAILED, "GeSession construction incomplete (null impl pointer)");1020 GE_CHK_BOOL_RET_STATUS(impl_ != nullptr, FAILED, "GeSession construction incomplete (null impl pointer)");
1022- if (EnableSliceSchedule()) {1021+ if (EnableAutoFuse()) {
1023 GELOGE(UNSUPPORTED,1022 GELOGE(UNSUPPORTED,
1024- "[Construct][GeSession]UpdateGraphFeatureMemoryBase does not support the slice scheduler currently, "1023+ "[Construct][GeSession]UpdateGraphFeatureMemoryBase does not support the JIT executor currently, "
1025 "session_id:%lu, "1024 "session_id:%lu, "
1026 "graph_id:%u, memory:%p, size:%zu",1025 "graph_id:%u, memory:%p, size:%zu",
1027 GetSessionId(), graph_id, memory, size);1026 GetSessionId(), graph_id, memory, size);
1028 REPORT_INNER_ERR_MSG("E19999",1027 REPORT_INNER_ERR_MSG("E19999",
1029- "UpdateGraphFeatureMemoryBase does not support the slice scheduler currently, session_id:%lu, "1028+ "UpdateGraphFeatureMemoryBase does not support the JIT executor currently, session_id:%lu, "
1030 "graph_id:%u, memory:%p, size:%zu",1029 "graph_id:%u, memory:%p, size:%zu",
1031 GetSessionId(), graph_id, memory, size);1030 GetSessionId(), graph_id, memory, size);
1032 return UNSUPPORTED;1031 return UNSUPPORTED;
@@ -1051,15 +1050,14 @@ Status GeSession::SetGraphFixedFeatureMemoryBaseWithType(uint32_t graph_id, Memo
1051 return FAILED;1050 return FAILED;
1052 }1051 }
1053 GE_CHK_BOOL_RET_STATUS(impl_ != nullptr, FAILED, "GeSession construction incomplete (null impl pointer)");1052 GE_CHK_BOOL_RET_STATUS(impl_ != nullptr, FAILED, "GeSession construction incomplete (null impl pointer)");
1054- if (EnableSliceSchedule()) {1053+ if (EnableAutoFuse()) {
1055- GELOGE(1054+ GELOGE(UNSUPPORTED,
1056- UNSUPPORTED,1055+ "[Construct][GeSession]SetGraphFixedFeatureMemoryBaseWithType does not support the JIT executor currently, "
1057- "[Construct][GeSession]SetGraphFixedFeatureMemoryBaseWithType does not support the slice scheduler currently, "1056+ "session_id:%lu, graph_id:%u, type:%d, memory:%p, size:%zu",
1058- "session_id:%lu, graph_id:%u, type:%d, memory:%p, size:%zu",1057+ GetSessionId(), graph_id, type, memory, size);
1059- GetSessionId(), graph_id, type, memory, size);
1060 REPORT_INNER_ERR_MSG(1058 REPORT_INNER_ERR_MSG(
1061 "E19999",1059 "E19999",
1062- "SetGraphFixedFeatureMemoryBaseWithType does not support the slice scheduler currently, session_id:%lu, "1060+ "SetGraphFixedFeatureMemoryBaseWithType does not support the JIT executor currently, session_id:%lu, "
1063 "graph_id:%u, memory:%p, size:%zu",1061 "graph_id:%u, memory:%p, size:%zu",
1064 GetSessionId(), graph_id, memory, size);1062 GetSessionId(), graph_id, memory, size);
1065 return UNSUPPORTED;1063 return UNSUPPORTED;
@@ -1085,15 +1083,14 @@ Status GeSession::UpdateGraphRefreshableFeatureMemoryBase(uint32_t graph_id, con
1085 return FAILED;1083 return FAILED;
1086 }1084 }
1087 GE_CHK_BOOL_RET_STATUS(impl_ != nullptr, FAILED, "GeSession construction incomplete (null impl pointer)");1085 GE_CHK_BOOL_RET_STATUS(impl_ != nullptr, FAILED, "GeSession construction incomplete (null impl pointer)");
1088- if (EnableSliceSchedule()) {1086+ if (EnableAutoFuse()) {
1089- GELOGE(1087+ GELOGE(UNSUPPORTED,
1090- UNSUPPORTED,1088+ "[Construct][GeSession]UpdateGraphRefreshableFeatureMemoryBase does not support the JIT executor currently, "
1091- "[Construct][GeSession]UpdateGraphRefreshableFeatureMemoryBase does not support the slice scheduler currently, "1089+ "session_id:%lu, graph_id:%u, memory:%p, size:%zu",
1092- "session_id:%lu, graph_id:%u, memory:%p, size:%zu",1090+ GetSessionId(), graph_id, memory, size);
1093- GetSessionId(), graph_id, memory, size);
1094 REPORT_INNER_ERR_MSG(1091 REPORT_INNER_ERR_MSG(
1095 "E19999",1092 "E19999",
1096- "UpdateGraphRefreshableFeatureMemoryBase does not support the slice scheduler currently, session_id:%lu, "1093+ "UpdateGraphRefreshableFeatureMemoryBase does not support the JIT executor currently, session_id:%lu, "
1097 "graph_id:%u, memory:%p, size:%zu",1094 "graph_id:%u, memory:%p, size:%zu",
1098 GetSessionId(), graph_id, memory, size);1095 GetSessionId(), graph_id, memory, size);
1099 return UNSUPPORTED;1096 return UNSUPPORTED;
@@ -15,6 +15,7 @@
15#include "common/memory/tensor_trans_utils.h"15#include "common/memory/tensor_trans_utils.h"
16#include "graph/utils/tensor_adapter.h"16#include "graph/utils/tensor_adapter.h"
17#include "graph/utils/type_utils.h"17#include "graph/utils/type_utils.h"
18+#include "api/aclgrph/option_utils.h"
18 19 
19namespace ge {20namespace ge {
20namespace {21namespace {
@@ -106,17 +107,32 @@ Status ExecutionOrder::NextPoint(const ExecutionPoint &ep, const std::vector<GeT
106 107 
107Status ExecutionOrder::AddNewSlice(const ComputeGraphPtr &graph, const std::vector<GeTensor> &inputs,108Status ExecutionOrder::AddNewSlice(const ComputeGraphPtr &graph, const std::vector<GeTensor> &inputs,
108 ExecutionPoint *&new_ep) {109 ExecutionPoint *&new_ep) {
109- std::vector<NodePtr> infered_nodes;
110- GE_ASSERT_SUCCESS(JitInferUtils::InferSymbolForGraph(graph, inputs, infered_nodes));
111 PartionResult partition_result;110 PartionResult partition_result;
112- if (!infered_nodes.empty()) {111+ std::string dump_name;
113- GE_ASSERT_SUCCESS(BinaryPartitioner::Partition(graph, infered_nodes, partition_result));112+ if (user_graph_.slice_supported) {
113+ std::vector<NodePtr> infered_nodes;
114+ GE_ASSERT_SUCCESS(JitInferUtils::InferSymbolForGraph(graph, inputs, infered_nodes));
115+ if (!infered_nodes.empty()) {
116+ GE_ASSERT_SUCCESS(BinaryPartitioner::Partition(graph, infered_nodes, partition_result));
117+ GELOGI("graph[%s] partitioned, sliced_graph has %zu nodes.", partition_result.sliced_graph->GetName().c_str(),
118+ partition_result.sliced_graph->GetDirectNodesSize());
119+ } else {
120+ partition_result.sliced_graph = graph;
121+ GELOGI("graph[%s] all nodes inferred, no partition needed.", graph->GetName().c_str());
122+ }
123+ dump_name = "SlicedGraph_";
114 } else {124 } else {
115 partition_result.sliced_graph = graph;125 partition_result.sliced_graph = graph;
126+ partition_result.remaining_graph = nullptr;
127+ // 整图模式下原始图末端仍是 FrameworkOp/_RetVal,尚未创建 NetOutput,
128+ // 复用传统编译 NetOutputPass 的同一套逻辑提前补出 NetOutput,确保 output_size 能被正确校正
129+ GE_ASSERT_SUCCESS(graph->CreateOrUpdateNetoutput());
130+ GELOGI("graph[%s] whole-graph mode, no slicing.", graph->GetName().c_str());
131+ dump_name = "WholeGraph_";
116 }132 }
117 GE_ASSERT_NOTNULL(partition_result.sliced_graph);133 GE_ASSERT_NOTNULL(partition_result.sliced_graph);
118 GE_ASSERT_SUCCESS(SetOutputSizeIfNeed(partition_result.sliced_graph));134 GE_ASSERT_SUCCESS(SetOutputSizeIfNeed(partition_result.sliced_graph));
119- GE_DUMP(partition_result.sliced_graph, "SlicedGraph_" + std::to_string(slice_graphs_.size()));135+ GE_DUMP(partition_result.sliced_graph, dump_name + std::to_string(slice_graphs_.size()));
120 // use vector index as ep id136 // use vector index as ep id
121 const auto &ep_options = SelectEpOption(partition_result);137 const auto &ep_options = SelectEpOption(partition_result);
122 slice_graphs_.emplace_back(MakeUnique<ExecutionPoint>(slice_graphs_.size(), partition_result.sliced_graph,138 slice_graphs_.emplace_back(MakeUnique<ExecutionPoint>(slice_graphs_.size(), partition_result.sliced_graph,
@@ -22,6 +22,7 @@ struct UserGraph {
22 uint32_t user_graph_id;22 uint32_t user_graph_id;
23 ComputeGraphPtr compute_graph;23 ComputeGraphPtr compute_graph;
24 std::map<std::string, std::string> graph_options;24 std::map<std::string, std::string> graph_options;
25+ bool slice_supported = false;
25};26};
26/**27/**
27 * 该类用于确定一张UserGraph中的切图结果28 * 该类用于确定一张UserGraph中的切图结果
@@ -11,6 +11,7 @@
11#include "user_graph_ctrl.h"11#include "user_graph_ctrl.h"
12#include "common/memory/tensor_trans_utils.h"12#include "common/memory/tensor_trans_utils.h"
13#include "graph/utils/graph_utils_ex.h"13#include "graph/utils/graph_utils_ex.h"
14+#include "graph/utils/tensor_adapter.h"
14#include "ge_context.h"15#include "ge_context.h"
15#include "formats/utils/formats_trans_utils.h"16#include "formats/utils/formats_trans_utils.h"
16 17 
@@ -111,11 +112,79 @@ Status UserGraphControl::Finalize() {
111 }112 }
112 }113 }
113 StopQueue();114 StopQueue();
115+ if (whole_graph_added_) {
116+ (void)graph_manager_.RemoveGraph(whole_graph_instance_id_);
117+ whole_graph_added_ = false;
118+ }
114 GE_ASSERT_SUCCESS(jit_executor_pool_.Finalize());119 GE_ASSERT_SUCCESS(jit_executor_pool_.Finalize());
115 GE_ASSERT_SUCCESS(cmc_.SaveCache(order_));120 GE_ASSERT_SUCCESS(cmc_.SaveCache(order_));
116 return SUCCESS;121 return SUCCESS;
117}122}
118 123 
124+Status UserGraphControl::EnsureWholeGraphAdded() {
125+ if (whole_graph_added_) {
126+ return SUCCESS;
127+ }
128+ whole_graph_instance_id_ = compile_context_.GenNewGraphId();
129+ const auto graph = GraphUtilsEx::CreateGraphFromComputeGraph(compute_graph_);
130+ GE_ASSERT_SUCCESS(graph_manager_.AddGraph(whole_graph_instance_id_, graph, order_.GetUserGraph().graph_options,
131+ domi::GetContext()));
132+ whole_graph_added_ = true;
133+ return SUCCESS;
134+}
135+ 
136+Status UserGraphControl::EnsureWholeGraphCompiled(const std::vector<gert::Tensor> &inputs, uint64_t session_id) {
137+ GE_ASSERT_SUCCESS(EnsureWholeGraphAdded());
138+ if (whole_graph_compiled_ || graph_manager_.GetBuildFlag(whole_graph_instance_id_)) {
139+ whole_graph_compiled_ = true;
140+ return SUCCESS;
141+ }
142+ 
143+ std::vector<ge::Tensor> compile_inputs;
144+ GE_ASSERT_SUCCESS(TensorTransUtils::GertTensors2Tensors(inputs, compile_inputs));
145+ GE_ASSERT_SUCCESS(graph_manager_.CompileGraph(whole_graph_instance_id_, session_id, compile_inputs));
146+ whole_graph_compiled_ = true;
147+ return SUCCESS;
148+}
149+ 
150+Status UserGraphControl::EnsureWholeGraphLoaded(const std::map<AscendString, AscendString> &options, void *stream) {
151+ GE_ASSERT_SUCCESS(EnsureWholeGraphAdded());
152+ if (whole_graph_loaded_ || graph_manager_.GetLoadFlag(whole_graph_instance_id_)) {
153+ whole_graph_loaded_ = true;
154+ return SUCCESS;
155+ }
156+ GE_ASSERT_SUCCESS(graph_manager_.LoadGraph(whole_graph_instance_id_, options, stream));
157+ whole_graph_loaded_ = true;
158+ return SUCCESS;
159+}
160+ 
161+Status UserGraphControl::RunGraph(const std::vector<ge::Tensor> &inputs, std::vector<ge::Tensor> &outputs,
162+ uint64_t session_id) {
163+ GE_ASSERT_SUCCESS(EnsureWholeGraphAdded());
164+ return graph_manager_.RunGraph(whole_graph_instance_id_, inputs, outputs, session_id);
165+}
166+ 
167+Status UserGraphControl::RunGraph(const std::vector<gert::Tensor> &inputs, std::vector<gert::Tensor> &outputs,
168+ uint64_t session_id) {
169+ GE_ASSERT_SUCCESS(EnsureWholeGraphCompiled(inputs, session_id));
170+ GE_ASSERT_SUCCESS(EnsureWholeGraphLoaded(GetLoadOptions(), nullptr));
171+ return graph_manager_.RunGraph(whole_graph_instance_id_, inputs, outputs);
172+}
173+ 
174+Status UserGraphControl::RunGraphWithStreamAsync(void *stream, const std::vector<GeTensor> &inputs,
175+ std::vector<GeTensor> &outputs, uint64_t session_id) {
176+ GE_ASSERT_SUCCESS(EnsureWholeGraphAdded());
177+ return graph_manager_.RunGraphWithStreamAsync(whole_graph_instance_id_, stream, session_id, inputs, outputs);
178+}
179+ 
180+RunGraphMode UserGraphControl::GetRunGraphMode() const {
181+ return run_graph_mode_;
182+}
183+ 
184+void UserGraphControl::SetRunGraphMode(const RunGraphMode &mode) {
185+ run_graph_mode_ = mode;
186+}
187+ 
119Status UserGraphControl::AddGraphInstance() {188Status UserGraphControl::AddGraphInstance() {
120 auto jit_executor = JitExecutor::Create(graph_manager_, executions_, order_, compile_context_, cmc_, compile_mutex_);189 auto jit_executor = JitExecutor::Create(graph_manager_, executions_, order_, compile_context_, cmc_, compile_mutex_);
121 JIT_CTRL_ASSERT_NOTNULL(jit_executor, "[UserGraph:%u]Failed to create jit executor instance.", user_graph_id_);190 JIT_CTRL_ASSERT_NOTNULL(jit_executor, "[UserGraph:%u]Failed to create jit executor instance.", user_graph_id_);
@@ -230,11 +299,11 @@ CompiledGraphSummaryPtr UserGraphControl::GetCompiledGraphSummary() {
230}299}
231 300 
232Status UserGraphControl::LoadGraph(const std::map<AscendString, AscendString> &options, void *stream) {301Status UserGraphControl::LoadGraph(const std::map<AscendString, AscendString> &options, void *stream) {
302+ SetLoadOptions(options);
233 bool is_unknown_input_shape{false};303 bool is_unknown_input_shape{false};
234 const auto &inputs = order_.GetInputTensors(is_unknown_input_shape);304 const auto &inputs = order_.GetInputTensors(is_unknown_input_shape);
235 if (is_unknown_input_shape) {305 if (is_unknown_input_shape) {
236 GELOGI("CompileGraph dynamic graph %u skip.", user_graph_id_);306 GELOGI("CompileGraph dynamic graph %u skip.", user_graph_id_);
237- SetLoadOptions(options);
238 return SUCCESS;307 return SUCCESS;
239 }308 }
240 auto load_task = MakeUnique<UserGraphExecution>(user_graph_id_, inputs, nullptr, INVALID_SESSION_ID);309 auto load_task = MakeUnique<UserGraphExecution>(user_graph_id_, inputs, nullptr, INVALID_SESSION_ID);
@@ -22,6 +22,7 @@
22 22 
23#include "compile_context.h"23#include "compile_context.h"
24#include "exe_points/execution_order.h"24#include "exe_points/execution_order.h"
25+#include "api/aclgrph/option_utils.h"
25#include "cache/compiled_model_cache.h"26#include "cache/compiled_model_cache.h"
26#include "jit_executor.h"27#include "jit_executor.h"
27#include "common/thread_pool/thread_pool.h"28#include "common/thread_pool/thread_pool.h"
@@ -50,7 +51,9 @@ class UserGraphControl {
50 UserGraphControl(uint32_t user_graph_id, const ComputeGraphPtr &graph, CompileContext &compile_context,51 UserGraphControl(uint32_t user_graph_id, const ComputeGraphPtr &graph, CompileContext &compile_context,
51 GraphManager &graph_manager, const std::map<std::string, std::string> &graph_options)52 GraphManager &graph_manager, const std::map<std::string, std::string> &graph_options)
52 : user_graph_id_(user_graph_id),53 : user_graph_id_(user_graph_id),
53- order_(UserGraph({user_graph_id, graph, graph_options})),54+ compute_graph_(graph),
55+ order_(UserGraph({user_graph_id, graph, graph_options,
56+ EnableSliceSchedule() && IsGraphSupportSliceSchedule(graph, graph_options)})),
54 compile_context_(compile_context),57 compile_context_(compile_context),
55 graph_manager_(graph_manager),58 graph_manager_(graph_manager),
56 jit_exe_thread_pool_("jit_exe", kDefaultJitExeThreadPoolSize, true),59 jit_exe_thread_pool_("jit_exe", kDefaultJitExeThreadPoolSize, true),
@@ -71,6 +74,12 @@ class UserGraphControl {
71 74 
72 Status AddGraphInstance();75 Status AddGraphInstance();
73 void RunGraphAsync(std::unique_ptr<UserGraphExecution> &task);76 void RunGraphAsync(std::unique_ptr<UserGraphExecution> &task);
77+ Status RunGraph(const std::vector<ge::Tensor> &inputs, std::vector<ge::Tensor> &outputs, uint64_t session_id);
78+ Status RunGraph(const std::vector<gert::Tensor> &inputs, std::vector<gert::Tensor> &outputs, uint64_t session_id);
79+ Status RunGraphWithStreamAsync(void *stream, const std::vector<GeTensor> &inputs, std::vector<GeTensor> &outputs,
80+ uint64_t session_id);
81+ RunGraphMode GetRunGraphMode() const;
82+ void SetRunGraphMode(const RunGraphMode &mode);
74 Status ExecuteGraphWithStreamAsync(std::unique_ptr<UserGraphExecution> task);83 Status ExecuteGraphWithStreamAsync(std::unique_ptr<UserGraphExecution> task);
75 Status CompileGraph(uint64_t session_id);84 Status CompileGraph(uint64_t session_id);
76 CompiledGraphSummaryPtr GetCompiledGraphSummary();85 CompiledGraphSummaryPtr GetCompiledGraphSummary();
@@ -86,8 +95,12 @@ class UserGraphControl {
86 void ExecuteUserGraph();95 void ExecuteUserGraph();
87 void SetLoadOptions(const std::map<AscendString, AscendString> &load_options);96 void SetLoadOptions(const std::map<AscendString, AscendString> &load_options);
88 Status CompileCompleteGraph(uint64_t session_id);97 Status CompileCompleteGraph(uint64_t session_id);
98+ Status EnsureWholeGraphAdded();
99+ Status EnsureWholeGraphCompiled(const std::vector<gert::Tensor> &inputs, uint64_t session_id);
100+ Status EnsureWholeGraphLoaded(const std::map<AscendString, AscendString> &options, void *stream);
89 101 
90 uint32_t user_graph_id_;102 uint32_t user_graph_id_;
103+ ComputeGraphPtr compute_graph_;
91 ExecutionOrder order_;104 ExecutionOrder order_;
92 CompileContext &compile_context_;105 CompileContext &compile_context_;
93 GraphManager &graph_manager_;106 GraphManager &graph_manager_;
@@ -112,6 +125,11 @@ class UserGraphControl {
112 // set true only when Session::CompileGraph is called125 // set true only when Session::CompileGraph is called
113 // only set or check in ge_api.cc126 // only set or check in ge_api.cc
114 bool compiled_flag_{false};127 bool compiled_flag_{false};
128+ uint32_t whole_graph_instance_id_{0U};
129+ bool whole_graph_added_{false};
130+ bool whole_graph_compiled_{false};
131+ bool whole_graph_loaded_{false};
132+ RunGraphMode run_graph_mode_{RunGraphMode::kRunGraphModeEnd};
115};133};
116} // namespace ge134} // namespace ge
117 135 
@@ -15,29 +15,13 @@
15#include "api/aclgrph/option_utils.h"15#include "api/aclgrph/option_utils.h"
16 16 
17namespace ge {17namespace ge {
18-bool UserGraphsManager::ShouldUseSliceSchedule(uint32_t user_graph_id) const {
19- if (!EnableSliceSchedule()) {
20- return false;
21- }
22- std::lock_guard<std::mutex> locker(user_graph_ctrl_mutex_);
23- return slice_schedule_unsupported_set_.find(user_graph_id) == slice_schedule_unsupported_set_.end();
24-}
25- 
26Status UserGraphsManager::AddGraph(uint32_t user_graph_id, const Graph &graph,18Status UserGraphsManager::AddGraph(uint32_t user_graph_id, const Graph &graph,
27 const std::map<std::string, std::string> &options) {19 const std::map<std::string, std::string> &options) {
28- if (!EnableSliceSchedule()) {20+ if (!EnableAutoFuse()) {
29 return graph_manager_.AddGraph(user_graph_id, graph, options, domi::GetContext());21 return graph_manager_.AddGraph(user_graph_id, graph, options, domi::GetContext());
30 }22 }
31 auto compute_graph = GraphUtilsEx::GetComputeGraph(graph);23 auto compute_graph = GraphUtilsEx::GetComputeGraph(graph);
32 GE_ASSERT_NOTNULL(compute_graph);24 GE_ASSERT_NOTNULL(compute_graph);
33- const bool slice_supported = IsGraphSupportSliceSchedule(compute_graph, options);
34- if (!slice_supported) {
35- std::lock_guard<std::mutex> locker(user_graph_ctrl_mutex_);
36- slice_schedule_unsupported_set_.insert(user_graph_id);
37- GELOGI("Graph[%u] does not support slice schedule, fallback to traditional mode.", user_graph_id);
38- return graph_manager_.AddGraph(user_graph_id, graph, options, domi::GetContext());
39- }
40- 
41 SetLocalOmgContext(domi::GetContext());25 SetLocalOmgContext(domi::GetContext());
42 GetThreadLocalContext().SetGraphOption(options);26 GetThreadLocalContext().SetGraphOption(options);
43 std::lock_guard<std::mutex> locker(user_graph_ctrl_mutex_);27 std::lock_guard<std::mutex> locker(user_graph_ctrl_mutex_);
@@ -56,7 +40,7 @@ Status UserGraphsManager::AddGraph(uint32_t user_graph_id, const Graph &graph,
56 40 
57Status UserGraphsManager::BuildGraph(uint32_t user_graph_id, const std::vector<GeTensor> &inputs,41Status UserGraphsManager::BuildGraph(uint32_t user_graph_id, const std::vector<GeTensor> &inputs,
58 uint64_t session_id) const {42 uint64_t session_id) const {
59- if (!ShouldUseSliceSchedule(user_graph_id)) {43+ if (!EnableAutoFuse()) {
60 GeRootModelPtr ge_root_model;44 GeRootModelPtr ge_root_model;
61 return graph_manager_.BuildGraph(user_graph_id, inputs, ge_root_model, session_id, true);45 return graph_manager_.BuildGraph(user_graph_id, inputs, ge_root_model, session_id, true);
62 }46 }
@@ -67,7 +51,7 @@ Status UserGraphsManager::BuildGraph(uint32_t user_graph_id, const std::vector<G
67 51 
68Status UserGraphsManager::RunGraphAsync(uint32_t user_graph_id, std::vector<gert::Tensor> &&inputs, uint64_t session_id,52Status UserGraphsManager::RunGraphAsync(uint32_t user_graph_id, std::vector<gert::Tensor> &&inputs, uint64_t session_id,
69 const RunAsyncCallbackV2 &callback) {53 const RunAsyncCallbackV2 &callback) {
70- if (!ShouldUseSliceSchedule(user_graph_id)) {54+ if (!EnableAutoFuse()) {
71 return graph_manager_.RunGraphAsync(user_graph_id, std::move(inputs), session_id, callback);55 return graph_manager_.RunGraphAsync(user_graph_id, std::move(inputs), session_id, callback);
72 }56 }
73 UserGraphControl *user_graph_control = nullptr;57 UserGraphControl *user_graph_control = nullptr;
@@ -85,6 +69,34 @@ Status UserGraphsManager::RunGraphAsync(uint32_t user_graph_id, std::vector<gert
85 return SUCCESS;69 return SUCCESS;
86}70}
87 71 
72+Status UserGraphsManager::RunGraph(uint32_t user_graph_id, const std::vector<ge::Tensor> &inputs,
73+ std::vector<ge::Tensor> &outputs, uint64_t session_id) {
74+ if (!EnableAutoFuse()) {
75+ return graph_manager_.RunGraph(user_graph_id, inputs, outputs, session_id);
76+ }
77+ UserGraphControl *user_graph_control = GetUserGraphControl(user_graph_id);
78+ return user_graph_control->RunGraph(inputs, outputs, session_id);
79+}
80+ 
81+Status UserGraphsManager::RunGraph(uint32_t user_graph_id, const std::vector<gert::Tensor> &inputs,
82+ std::vector<gert::Tensor> &outputs, uint64_t session_id) {
83+ if (!EnableAutoFuse()) {
84+ return graph_manager_.RunGraph(user_graph_id, inputs, outputs);
85+ }
86+ UserGraphControl *user_graph_control = GetUserGraphControl(user_graph_id);
87+ return user_graph_control->RunGraph(inputs, outputs, session_id);
88+}
89+ 
90+Status UserGraphsManager::RunGraphWithStreamAsync(uint32_t user_graph_id, void *stream,
91+ const std::vector<GeTensor> &inputs, std::vector<GeTensor> &outputs,
92+ uint64_t session_id) {
93+ if (!EnableAutoFuse()) {
94+ return graph_manager_.RunGraphWithStreamAsync(user_graph_id, stream, session_id, inputs, outputs);
95+ }
96+ UserGraphControl *user_graph_control = GetUserGraphControl(user_graph_id);
97+ return user_graph_control->RunGraphWithStreamAsync(stream, inputs, outputs, session_id);
98+}
99+ 
88UserGraphControl *UserGraphsManager::GetUserGraphControl(uint32_t user_graph_id) {100UserGraphControl *UserGraphsManager::GetUserGraphControl(uint32_t user_graph_id) {
89 std::lock_guard<std::mutex> locker(user_graph_ctrl_mutex_);101 std::lock_guard<std::mutex> locker(user_graph_ctrl_mutex_);
90 UserGraphControl *user_graph_control = nullptr;102 UserGraphControl *user_graph_control = nullptr;
@@ -95,7 +107,7 @@ UserGraphControl *UserGraphsManager::GetUserGraphControl(uint32_t user_graph_id)
95}107}
96 108 
97Status UserGraphsManager::CompileGraph(uint32_t user_graph_id, uint64_t session_id, const vector<ge::Tensor> &inputs) {109Status UserGraphsManager::CompileGraph(uint32_t user_graph_id, uint64_t session_id, const vector<ge::Tensor> &inputs) {
98- if (!ShouldUseSliceSchedule(user_graph_id)) {110+ if (!EnableAutoFuse()) {
99 return graph_manager_.CompileGraph(user_graph_id, session_id, inputs);111 return graph_manager_.CompileGraph(user_graph_id, session_id, inputs);
100 }112 }
101 UserGraphControl *user_graph_control = GetUserGraphControl(user_graph_id);113 UserGraphControl *user_graph_control = GetUserGraphControl(user_graph_id);
@@ -105,7 +117,7 @@ Status UserGraphsManager::CompileGraph(uint32_t user_graph_id, uint64_t session_
105}117}
106 118 
107Status UserGraphsManager::GetCompiledGraphSummary(uint32_t user_graph_id, CompiledGraphSummaryPtr &summary) {119Status UserGraphsManager::GetCompiledGraphSummary(uint32_t user_graph_id, CompiledGraphSummaryPtr &summary) {
108- if (!ShouldUseSliceSchedule(user_graph_id)) {120+ if (!EnableAutoFuse()) {
109 return graph_manager_.GetCompiledGraphSummary(user_graph_id, summary);121 return graph_manager_.GetCompiledGraphSummary(user_graph_id, summary);
110 }122 }
111 UserGraphControl *user_graph_control = GetUserGraphControl(user_graph_id);123 UserGraphControl *user_graph_control = GetUserGraphControl(user_graph_id);
@@ -116,7 +128,7 @@ Status UserGraphsManager::GetCompiledGraphSummary(uint32_t user_graph_id, Compil
116 128 
117Status UserGraphsManager::LoadGraph(const uint32_t user_graph_id, const std::map<AscendString, AscendString> &options,129Status UserGraphsManager::LoadGraph(const uint32_t user_graph_id, const std::map<AscendString, AscendString> &options,
118 void *stream) {130 void *stream) {
119- if (!ShouldUseSliceSchedule(user_graph_id)) {131+ if (!EnableAutoFuse()) {
120 return graph_manager_.LoadGraph(user_graph_id, options, stream);132 return graph_manager_.LoadGraph(user_graph_id, options, stream);
121 }133 }
122 UserGraphControl *user_graph_control = GetUserGraphControl(user_graph_id);134 UserGraphControl *user_graph_control = GetUserGraphControl(user_graph_id);
@@ -128,7 +140,7 @@ Status UserGraphsManager::LoadGraph(const uint32_t user_graph_id, const std::map
128Status UserGraphsManager::ExecuteGraphWithStreamAsync(uint32_t user_graph_id, void *stream,140Status UserGraphsManager::ExecuteGraphWithStreamAsync(uint32_t user_graph_id, void *stream,
129 const std::vector<gert::Tensor> &inputs,141 const std::vector<gert::Tensor> &inputs,
130 std::vector<gert::Tensor> &outputs, uint64_t session_id) {142 std::vector<gert::Tensor> &outputs, uint64_t session_id) {
131- if (!ShouldUseSliceSchedule(user_graph_id)) {143+ if (!EnableAutoFuse()) {
132 return graph_manager_.ExecuteGraphWithStreamAsync(user_graph_id, stream, inputs, outputs);144 return graph_manager_.ExecuteGraphWithStreamAsync(user_graph_id, stream, inputs, outputs);
133 }145 }
134 UserGraphControl *user_graph_control = GetUserGraphControl(user_graph_id);146 UserGraphControl *user_graph_control = GetUserGraphControl(user_graph_id);
@@ -146,14 +158,12 @@ Status UserGraphsManager::ExecuteGraphWithStreamAsync(uint32_t user_graph_id, vo
146Status UserGraphsManager::Finalize() {158Status UserGraphsManager::Finalize() {
147 std::lock_guard<std::mutex> locker(user_graph_ctrl_mutex_);159 std::lock_guard<std::mutex> locker(user_graph_ctrl_mutex_);
148 ids_to_user_graph_ctrl_.clear();160 ids_to_user_graph_ctrl_.clear();
149- slice_schedule_unsupported_set_.clear();
150 return SUCCESS;161 return SUCCESS;
151}162}
152 163 
153Status UserGraphsManager::RemoveGraph(uint32_t user_graph_id) {164Status UserGraphsManager::RemoveGraph(uint32_t user_graph_id) {
154- if (!ShouldUseSliceSchedule(user_graph_id)) {165+ if (!EnableAutoFuse()) {
155 std::lock_guard<std::mutex> locker(user_graph_ctrl_mutex_);166 std::lock_guard<std::mutex> locker(user_graph_ctrl_mutex_);
156- slice_schedule_unsupported_set_.erase(user_graph_id);
157 return graph_manager_.RemoveGraph(user_graph_id);167 return graph_manager_.RemoveGraph(user_graph_id);
158 }168 }
159 std::lock_guard<std::mutex> locker(user_graph_ctrl_mutex_);169 std::lock_guard<std::mutex> locker(user_graph_ctrl_mutex_);
@@ -169,7 +179,7 @@ Status UserGraphsManager::RemoveGraph(uint32_t user_graph_id) {
169}179}
170 180 
171bool UserGraphsManager::IsGraphNeedRebuild(uint32_t user_graph_id) {181bool UserGraphsManager::IsGraphNeedRebuild(uint32_t user_graph_id) {
172- if (!ShouldUseSliceSchedule(user_graph_id)) {182+ if (!EnableAutoFuse()) {
173 return graph_manager_.IsGraphNeedRebuild(user_graph_id);183 return graph_manager_.IsGraphNeedRebuild(user_graph_id);
174 }184 }
175 std::lock_guard<std::mutex> locker(user_graph_ctrl_mutex_);185 std::lock_guard<std::mutex> locker(user_graph_ctrl_mutex_);
@@ -183,7 +193,7 @@ bool UserGraphsManager::IsGraphNeedRebuild(uint32_t user_graph_id) {
183}193}
184 194 
185Status UserGraphsManager::GetCompiledFlag(uint32_t user_graph_id, bool &flag) {195Status UserGraphsManager::GetCompiledFlag(uint32_t user_graph_id, bool &flag) {
186- if (!ShouldUseSliceSchedule(user_graph_id)) {196+ if (!EnableAutoFuse()) {
187 return graph_manager_.GetCompiledFlag(user_graph_id, flag);197 return graph_manager_.GetCompiledFlag(user_graph_id, flag);
188 }198 }
189 const UserGraphControl *user_graph_control = GetUserGraphControl(user_graph_id);199 const UserGraphControl *user_graph_control = GetUserGraphControl(user_graph_id);
@@ -197,7 +207,7 @@ Status UserGraphsManager::DumpDebugJSONPrint(uint32_t user_graph_id, uint32_t fl
197}207}
198 208 
199Status UserGraphsManager::SetCompiledFlag(uint32_t user_graph_id, bool flag) {209Status UserGraphsManager::SetCompiledFlag(uint32_t user_graph_id, bool flag) {
200- if (!ShouldUseSliceSchedule(user_graph_id)) {210+ if (!EnableAutoFuse()) {
201 return graph_manager_.SetCompiledFlag(user_graph_id, flag);211 return graph_manager_.SetCompiledFlag(user_graph_id, flag);
202 }212 }
203 UserGraphControl *user_graph_control = GetUserGraphControl(user_graph_id);213 UserGraphControl *user_graph_control = GetUserGraphControl(user_graph_id);
@@ -211,4 +221,22 @@ Status UserGraphsManager::GetOmeContextByGraphId(const GraphId &graph_id, OmeCon
211 return SUCCESS;221 return SUCCESS;
212}222}
213 223 
224+Status UserGraphsManager::GetRunGraphMode(uint32_t user_graph_id, RunGraphMode &mode) {
225+ if (!EnableAutoFuse()) {
226+ return graph_manager_.GetRunGraphMode(user_graph_id, mode);
227+ }
228+ UserGraphControl *user_graph_control = GetUserGraphControl(user_graph_id);
229+ mode = user_graph_control->GetRunGraphMode();
230+ return SUCCESS;
231+}
232+ 
233+Status UserGraphsManager::SetRunGraphMode(uint32_t user_graph_id, const RunGraphMode &mode) {
234+ if (!EnableAutoFuse()) {
235+ return graph_manager_.SetRunGraphMode(user_graph_id, mode);
236+ }
237+ UserGraphControl *user_graph_control = GetUserGraphControl(user_graph_id);
238+ user_graph_control->SetRunGraphMode(mode);
239+ return SUCCESS;
240+}
241+ 
214} // namespace ge242} // namespace ge
@@ -12,7 +12,6 @@
12#define USER_GRAPHS_MANAGER_H12#define USER_GRAPHS_MANAGER_H
13#include <cstdint>13#include <cstdint>
14#include <map>14#include <map>
15-#include <set>
16 15 
17#include "graph/graph.h"16#include "graph/graph.h"
18#include "exe_graph/runtime/runtime_tensor.h"17#include "exe_graph/runtime/runtime_tensor.h"
@@ -29,6 +28,12 @@ class UserGraphsManager {
29 Status BuildGraph(uint32_t user_graph_id, const std::vector<GeTensor> &inputs, uint64_t session_id) const;28 Status BuildGraph(uint32_t user_graph_id, const std::vector<GeTensor> &inputs, uint64_t session_id) const;
30 Status RunGraphAsync(uint32_t user_graph_id, std::vector<gert::Tensor> &&inputs, uint64_t session_id,29 Status RunGraphAsync(uint32_t user_graph_id, std::vector<gert::Tensor> &&inputs, uint64_t session_id,
31 const RunAsyncCallbackV2 &callback);30 const RunAsyncCallbackV2 &callback);
31+ Status RunGraph(uint32_t user_graph_id, const std::vector<ge::Tensor> &inputs, std::vector<ge::Tensor> &outputs,
32+ uint64_t session_id);
33+ Status RunGraph(uint32_t user_graph_id, const std::vector<gert::Tensor> &inputs, std::vector<gert::Tensor> &outputs,
34+ uint64_t session_id);
35+ Status RunGraphWithStreamAsync(uint32_t user_graph_id, void *stream, const std::vector<GeTensor> &inputs,
36+ std::vector<GeTensor> &outputs, uint64_t session_id);
32 Status RemoveGraph(uint32_t user_graph_id);37 Status RemoveGraph(uint32_t user_graph_id);
33 bool IsGraphNeedRebuild(uint32_t user_graph_id);38 bool IsGraphNeedRebuild(uint32_t user_graph_id);
34 Status GetCompiledFlag(uint32_t user_graph_id, bool &flag);39 Status GetCompiledFlag(uint32_t user_graph_id, bool &flag);
@@ -41,10 +46,11 @@ class UserGraphsManager {
41 Status ExecuteGraphWithStreamAsync(uint32_t user_graph_id, void *stream, const std::vector<gert::Tensor> &inputs,46 Status ExecuteGraphWithStreamAsync(uint32_t user_graph_id, void *stream, const std::vector<gert::Tensor> &inputs,
42 std::vector<gert::Tensor> &outputs, uint64_t session_id);47 std::vector<gert::Tensor> &outputs, uint64_t session_id);
43 Status GetOmeContextByGraphId(const GraphId &graph_id, OmeContext &ome_context) const;48 Status GetOmeContextByGraphId(const GraphId &graph_id, OmeContext &ome_context) const;
49+ Status GetRunGraphMode(uint32_t user_graph_id, RunGraphMode &mode);
50+ Status SetRunGraphMode(uint32_t user_graph_id, const RunGraphMode &mode);
44 51 
45 private:52 private:
46 UserGraphControl *GetUserGraphControl(uint32_t user_graph_id);53 UserGraphControl *GetUserGraphControl(uint32_t user_graph_id);
47- bool ShouldUseSliceSchedule(uint32_t user_graph_id) const;
48 54 
49 private:55 private:
50 CompileContext compile_context_;56 CompileContext compile_context_;
@@ -52,7 +58,6 @@ class UserGraphsManager {
52 58 
53 mutable std::mutex user_graph_ctrl_mutex_;59 mutable std::mutex user_graph_ctrl_mutex_;
54 std::map<uint32_t, std::unique_ptr<UserGraphControl>> ids_to_user_graph_ctrl_;60 std::map<uint32_t, std::unique_ptr<UserGraphControl>> ids_to_user_graph_ctrl_;
55- std::set<uint32_t> slice_schedule_unsupported_set_; // 黑名单:不支持 slice schedule 的 graph_id
56};61};
57using UserGraphsManagerPtr = std::shared_ptr<UserGraphsManager>;62using UserGraphsManagerPtr = std::shared_ptr<UserGraphsManager>;
58} // namespace ge63} // namespace ge
@@ -398,7 +398,8 @@ Status InnerSession::RunGraph(uint32_t graph_id, const std::vector<Tensor> &inpu
398 GELOGI("[InnerSession:%" PRIu64 "] Run graph on session, graph_id=%u.", session_id_, graph_id);398 GELOGI("[InnerSession:%" PRIu64 "] Run graph on session, graph_id=%u.", session_id_, graph_id);
399 if (std::unique_lock<std::mutex> lock{mutex_, std::try_to_lock}) {399 if (std::unique_lock<std::mutex> lock{mutex_, std::try_to_lock}) {
400 UpdateGlobalSessionContext();400 UpdateGlobalSessionContext();
401- return graph_manager_.RunGraph(graph_id, inputs, outputs, GetSessionId());401+ GE_ASSERT_NOTNULL(user_graphs_manager_);
402+ return user_graphs_manager_->RunGraph(graph_id, inputs, outputs, GetSessionId());
402 } else {403 } else {
403 GELOGE(GE_SESS_ALREADY_RUNNING, "[Run][Graph]failed, InnerSession:%" PRIu64 ", graph_id=%u.", session_id_,404 GELOGE(GE_SESS_ALREADY_RUNNING, "[Run][Graph]failed, InnerSession:%" PRIu64 ", graph_id=%u.", session_id_,
404 graph_id);405 graph_id);
@@ -414,7 +415,8 @@ Status InnerSession::RunGraph(uint32_t graph_id, const std::vector<gert::Tensor>
414 GELOGI("[InnerSession:%" PRIu64 "] Run graph on session, graph_id=%u.", session_id_, graph_id);415 GELOGI("[InnerSession:%" PRIu64 "] Run graph on session, graph_id=%u.", session_id_, graph_id);
415 if (std::unique_lock<std::mutex> lock{mutex_, std::try_to_lock}) {416 if (std::unique_lock<std::mutex> lock{mutex_, std::try_to_lock}) {
416 UpdateGlobalSessionContext();417 UpdateGlobalSessionContext();
417- return graph_manager_.RunGraph(graph_id, inputs, outputs);418+ GE_ASSERT_NOTNULL(user_graphs_manager_);
419+ return user_graphs_manager_->RunGraph(graph_id, inputs, outputs, GetSessionId());
418 } else {420 } else {
419 GELOGE(GE_SESS_ALREADY_RUNNING, "[Run][Graph]failed, InnerSession:%" PRIu64 ", graph_id=%u.", session_id_,421 GELOGE(GE_SESS_ALREADY_RUNNING, "[Run][Graph]failed, InnerSession:%" PRIu64 ", graph_id=%u.", session_id_,
420 graph_id);422 graph_id);
@@ -475,7 +477,9 @@ Status InnerSession::RunGraphWithStreamAsync(uint32_t graph_id, aclrtStream stre
475 for (auto &item : outputs) {477 for (auto &item : outputs) {
476 ge_outputs.emplace_back(TensorAdapter::AsGeTensorShared(item));478 ge_outputs.emplace_back(TensorAdapter::AsGeTensorShared(item));
477 }479 }
478- const Status res = graph_manager_.RunGraphWithStreamAsync(graph_id, stream, session_id_, ge_inputs, ge_outputs);480+ GE_ASSERT_NOTNULL(user_graphs_manager_);
481+ const Status res =
482+ user_graphs_manager_->RunGraphWithStreamAsync(graph_id, stream, ge_inputs, ge_outputs, session_id_);
479 if (res != SUCCESS) {483 if (res != SUCCESS) {
480 GELOGE(res,484 GELOGE(res,
481 "[Run][GraphWithStreamAsync]failed,"485 "[Run][GraphWithStreamAsync]failed,"
@@ -916,11 +920,13 @@ void InnerSession::SetDFlowSession(const std::shared_ptr<DFlowSessionImpl> &dflo
916}920}
917 921 
918Status InnerSession::GetRunGraphMode(uint32_t graph_id, RunGraphMode &mode) const {922Status InnerSession::GetRunGraphMode(uint32_t graph_id, RunGraphMode &mode) const {
919- return graph_manager_.GetRunGraphMode(graph_id, mode);923+ GE_ASSERT_NOTNULL(user_graphs_manager_);
924+ return user_graphs_manager_->GetRunGraphMode(graph_id, mode);
920}925}
921 926 
922Status InnerSession::SetRunGraphMode(uint32_t graph_id, const RunGraphMode &mode) {927Status InnerSession::SetRunGraphMode(uint32_t graph_id, const RunGraphMode &mode) {
923- return graph_manager_.SetRunGraphMode(graph_id, mode);928+ GE_ASSERT_NOTNULL(user_graphs_manager_);
929+ return user_graphs_manager_->SetRunGraphMode(graph_id, mode);
924}930}
925 931 
926Status InnerSession::GetCompiledModel(uint32_t graph_id, ModelBufferData &model_buffer) {932Status InnerSession::GetCompiledModel(uint32_t graph_id, ModelBufferData &model_buffer) {
@@ -1988,6 +1988,12 @@ Status CheckOptimizationOptionValid(const std::map<std::string, std::string> &op
1988 }1988 }
1989 return SUCCESS;1989 return SUCCESS;
1990}1990}
1991+ 
1992+bool EnableAutoFuse() {
1993+ static const bool kEnableAutoFuse = (ge::GetAutofuseFlagValue(kAutoFuseEnableOption) == "true");
1994+ return kEnableAutoFuse;
1995+}
1996+ 
1991bool EnableSliceSchedule() {1997bool EnableSliceSchedule() {
1992 static const bool kSliceSheduleEnable = ((ge::GetAutofuseFlagValue(kAutoFuseEnableOption) == "true") &&1998 static const bool kSliceSheduleEnable = ((ge::GetAutofuseFlagValue(kAutoFuseEnableOption) == "true") &&
1993 (ge::GetAutofuseFlagValue(kSliceScheduleOption) == "true"));1999 (ge::GetAutofuseFlagValue(kSliceScheduleOption) == "true"));
@@ -165,6 +165,7 @@ bool ParseSingleShapeRange(std::string &shape_range, std::vector<std::pair<int64
165std::string SupportedHostEnvCpuList(std::unordered_set<std::string> &supported_os_cpu);165std::string SupportedHostEnvCpuList(std::unordered_set<std::string> &supported_os_cpu);
166std::string SupportedHostEnvOsList(166std::string SupportedHostEnvOsList(
167 std::unordered_map<std::string, std::unordered_set<std::string>> &opp_supported_os_cpu);167 std::unordered_map<std::string, std::unordered_set<std::string>> &opp_supported_os_cpu);
168+bool EnableAutoFuse();
168bool EnableSliceSchedule();169bool EnableSliceSchedule();
169bool IsGraphSupportSliceSchedule(const ComputeGraphPtr &graph, const std::map<std::string, std::string> &options);170bool IsGraphSupportSliceSchedule(const ComputeGraphPtr &graph, const std::map<std::string, std::string> &options);
170} // namespace ge171} // namespace ge
@@ -3159,7 +3159,7 @@ ge::ComputeGraphPtr ShareGraph::BuildStaticTwoReduceNodeGraph() {
3159 3159 
3160 auto data1 = graph->FindNode("data1");3160 auto data1 = graph->FindNode("data1");
3161 AttrUtils::SetInt(data1->GetOpDesc(), "index", 0);3161 AttrUtils::SetInt(data1->GetOpDesc(), "index", 0);
3162- SetNoStorage(data1->GetOpDesc(), ge::FORMAT_ND, DT_FLOAT, {2, 2, 2});3162+ SetNoStorage(data1->GetOpDesc(), ge::FORMAT_ND, DT_FLOAT, {2, 2, 16});
3163 data1->GetOpDesc()->MutableAllInputName() = {{"x", 0}};3163 data1->GetOpDesc()->MutableAllInputName() = {{"x", 0}};
3164 data1->GetOpDesc()->MutableAllOutputName() = {{"y", 0}};3164 data1->GetOpDesc()->MutableAllOutputName() = {{"y", 0}};
3165 3165 
@@ -28,6 +28,7 @@ target_include_directories(autofuse_test PRIVATE
28 ${AIR_CODE_DIR}28 ${AIR_CODE_DIR}
29 ${AIR_CODE_DIR}/base/29 ${AIR_CODE_DIR}/base/
30 ${AIR_CODE_DIR}/compiler/30 ${AIR_CODE_DIR}/compiler/
31+ ${AIR_CODE_DIR}/api/session
31 ${AIR_CODE_DIR}/tests/depends/32 ${AIR_CODE_DIR}/tests/depends/
32 ${AIR_CODE_DIR}/inc33 ${AIR_CODE_DIR}/inc
33 ${AIR_CODE_DIR}/inc/framework/34 ${AIR_CODE_DIR}/inc/framework/
@@ -28,11 +28,42 @@
28#include "tests/framework/ge_runtime_stub/include/common/summary_checker.h"28#include "tests/framework/ge_runtime_stub/include/common/summary_checker.h"
29#include "faker/space_registry_faker.h"29#include "faker/space_registry_faker.h"
30#include "depends/runtime/src/runtime_stub.h"30#include "depends/runtime/src/runtime_stub.h"
31+#include "session/session_manager.h"
32+#include "session/inner_session.h"
33+#include "jit_execution/user_graphs_manager.h"
34+#include "jit_execution/user_graph_ctrl.h"
35+#include "jit_execution/exe_points/execution_order.h"
36+#include "jit_execution/exe_points/execution_point.h"
37+#include "jit_execution/exe_points/guarded_execution_point.h"
31 38 
32using namespace std;39using namespace std;
33using namespace testing;40using namespace testing;
34using namespace ge::autofuse;41using namespace ge::autofuse;
35 42 
43+ge::SessionManager *GetSessionManager();
44+ 
45+namespace {
46+ComputeGraphPtr GetJitCompiledGraph(const ge::Session &session, uint32_t graph_id) {
47+ const auto inner_session = GetSessionManager()->GetSession(session.GetSessionId());
48+ if (inner_session == nullptr) {
49+ return nullptr;
50+ }
51+ auto *user_graph_ctrl = inner_session->user_graphs_manager_->GetUserGraphControl(graph_id);
52+ if (user_graph_ctrl == nullptr) {
53+ return nullptr;
54+ }
55+ auto *ep = user_graph_ctrl->order_.GetFirstPoint();
56+ if (ep == nullptr) {
57+ return nullptr;
58+ }
59+ auto &geps = ep->models_.GetCache();
60+ if (geps.empty()) {
61+ return nullptr;
62+ }
63+ return geps.front()->GetGraph();
64+}
65+} // namespace
66+ 
36namespace ge {67namespace ge {
37using af::AscGraphUtils;68using af::AscGraphUtils;
38 69 
@@ -138,10 +169,8 @@ TEST_F(TestCanfusePass, test_canfuse_ele_and_ele_horizontal_fusion_1) {
138 Session session(options);169 Session session(options);
139 auto ret = session.AddGraph(1, *graph, options);170 auto ret = session.AddGraph(1, *graph, options);
140 EXPECT_EQ(ret, SUCCESS);171 EXPECT_EQ(ret, SUCCESS);
141- InputTensorInfo input{0, {2, 2, 2, 2}, nullptr, 0};172+ // 通过 CompileGraph 触发真实编译,融合结果在 GEP 编译副本上
142- std::vector<InputTensorInfo> inputs{input};173+ EXPECT_EQ(session.CompileGraph(1), SUCCESS);
143- // 当前测试框架还不支持 BuildGraph 接口端到端编译、加载, 仅测试编译流程
144- EXPECT_EQ(session.BuildGraph(1, inputs), SUCCESS);
145 174 
146 CHECK_GRAPH(AutofuseOptimize_Exit) {175 CHECK_GRAPH(AutofuseOptimize_Exit) {
147 std::map<std::string, size_t> node_types_to_count0;176 std::map<std::string, size_t> node_types_to_count0;
@@ -151,7 +180,9 @@ TEST_F(TestCanfusePass, test_canfuse_ele_and_ele_horizontal_fusion_1) {
151 std::string str = gert::SummaryChecker(graph).StrictDirectNodeTypes(node_types_to_count0);180 std::string str = gert::SummaryChecker(graph).StrictDirectNodeTypes(node_types_to_count0);
152 EXPECT_EQ(str, "success");181 EXPECT_EQ(str, "success");
153 };182 };
154- auto asc_bc = compute_graph->FindFirstNodeMatchType("AscBackend");183+ auto compiled_graph = GetJitCompiledGraph(session, 1);
184+ ASSERT_NE(compiled_graph, nullptr);
185+ auto asc_bc = compiled_graph->FindFirstNodeMatchType("AscBackend");
155 ASSERT_NE(asc_bc, nullptr);186 ASSERT_NE(asc_bc, nullptr);
156 auto attr = asc_bc->GetOpDesc()->GetAttrsGroup<AutoFuseAttrs>();187 auto attr = asc_bc->GetOpDesc()->GetAttrsGroup<AutoFuseAttrs>();
157 const auto &fused_graph = AscGraphUtils::GetComputeGraph(*attr->GetAscGraph());188 const auto &fused_graph = AscGraphUtils::GetComputeGraph(*attr->GetAscGraph());
@@ -196,11 +227,9 @@ TEST_F(TestCanfusePass, test_canfuse_ele_and_ele_horizontal_fusion_2) {
196 Session session(options);227 Session session(options);
197 auto ret = session.AddGraph(1, *graph, options);228 auto ret = session.AddGraph(1, *graph, options);
198 EXPECT_EQ(ret, SUCCESS);229 EXPECT_EQ(ret, SUCCESS);
199- InputTensorInfo input{0, {2, 2, 2, 2}, nullptr, 0};230+ // 通过 CompileGraph 触发真实编译,融合结果在 GEP 编译副本上
200- std::vector<InputTensorInfo> inputs{input};231+ session.CompileGraph(1);
201- // 当前测试框架还不支持 BuildGraph 接口端到端编译、加载, 仅测试编译流程232+ EXPECT_EQ(session.CompileGraph(1), SUCCESS);
202- session.BuildGraph(1, inputs);
203- EXPECT_EQ(session.BuildGraph(1, inputs), SUCCESS);
204 233 
205 CHECK_GRAPH(AutofuseOptimize_Exit) {234 CHECK_GRAPH(AutofuseOptimize_Exit) {
206 std::map<std::string, size_t> node_types_to_count0;235 std::map<std::string, size_t> node_types_to_count0;
@@ -211,7 +240,9 @@ TEST_F(TestCanfusePass, test_canfuse_ele_and_ele_horizontal_fusion_2) {
211 EXPECT_EQ(str, "success");240 EXPECT_EQ(str, "success");
212 };241 };
213 242 
214- auto asc_bc = compute_graph->FindFirstNodeMatchType("AscBackend");243+ auto compiled_graph = GetJitCompiledGraph(session, 1);
244+ ASSERT_NE(compiled_graph, nullptr);
245+ auto asc_bc = compiled_graph->FindFirstNodeMatchType("AscBackend");
215 ASSERT_NE(asc_bc, nullptr);246 ASSERT_NE(asc_bc, nullptr);
216 auto attr = asc_bc->GetOpDesc()->GetAttrsGroup<AutoFuseAttrs>();247 auto attr = asc_bc->GetOpDesc()->GetAttrsGroup<AutoFuseAttrs>();
217 ASSERT_NE(attr, nullptr);248 ASSERT_NE(attr, nullptr);
@@ -254,11 +285,8 @@ TEST_F(TestCanfusePass, test_canfuse_ele_and_bro_horizontal_fusion) {
254 Session session(options);285 Session session(options);
255 auto ret = session.AddGraph(1, *graph, options);286 auto ret = session.AddGraph(1, *graph, options);
256 EXPECT_EQ(ret, SUCCESS);287 EXPECT_EQ(ret, SUCCESS);
257- InputTensorInfo input1{0, {2, 2, 2}, nullptr, 0};288+ // 通过 CompileGraph 触发真实编译,融合结果在 GEP 编译副本上
258- InputTensorInfo input2{0, {2, 2}, nullptr, 0};289+ EXPECT_EQ(session.CompileGraph(1), SUCCESS);
259- std::vector<InputTensorInfo> inputs{input1, input2};
260- // 当前测试框架还不支持 BuildGraph 接口端到端编译、加载, 仅测试编译流程
261- EXPECT_EQ(session.BuildGraph(1, inputs), SUCCESS);
262 290 
263 CHECK_GRAPH(AutofuseOptimize_Exit) {291 CHECK_GRAPH(AutofuseOptimize_Exit) {
264 std::map<std::string, size_t> node_types_to_count0;292 std::map<std::string, size_t> node_types_to_count0;
@@ -268,7 +296,9 @@ TEST_F(TestCanfusePass, test_canfuse_ele_and_bro_horizontal_fusion) {
268 std::string str = gert::SummaryChecker(graph).StrictDirectNodeTypes(node_types_to_count0);296 std::string str = gert::SummaryChecker(graph).StrictDirectNodeTypes(node_types_to_count0);
269 EXPECT_EQ(str, "success");297 EXPECT_EQ(str, "success");
270 };298 };
271- auto asc_bc = compute_graph->FindFirstNodeMatchType("AscBackend");299+ auto compiled_graph = GetJitCompiledGraph(session, 1);
300+ ASSERT_NE(compiled_graph, nullptr);
301+ auto asc_bc = compiled_graph->FindFirstNodeMatchType("AscBackend");
272 ASSERT_NE(asc_bc, nullptr);302 ASSERT_NE(asc_bc, nullptr);
273 auto attr = asc_bc->GetOpDesc()->GetAttrsGroup<AutoFuseAttrs>();303 auto attr = asc_bc->GetOpDesc()->GetAttrsGroup<AutoFuseAttrs>();
274 304 
@@ -311,12 +341,8 @@ TEST_F(TestCanfusePass, test_canfuse_ele_and_bro_horizontal_fusion_2) {
311 Session session(options);341 Session session(options);
312 auto ret = session.AddGraph(1, *graph, options);342 auto ret = session.AddGraph(1, *graph, options);
313 EXPECT_EQ(ret, SUCCESS);343 EXPECT_EQ(ret, SUCCESS);
314- InputTensorInfo input1{0, {2, 2}, nullptr, 0};344+ // 通过 CompileGraph 触发真实编译,融合结果在 GEP 编译副本上
315- InputTensorInfo input2{0, {2, 2, 2}, nullptr, 0};345+ EXPECT_EQ(session.CompileGraph(1), SUCCESS);
316- InputTensorInfo input3{0, {2, 2, 2, 2}, nullptr, 0};
317- std::vector<InputTensorInfo> inputs{input1, input2, input3};
318- // 当前测试框架还不支持 BuildGraph 接口端到端编译、加载, 仅测试编译流程
319- EXPECT_EQ(session.BuildGraph(1, inputs), SUCCESS);
320 346 
321 CHECK_GRAPH(AutofuseOptimize_Exit) {347 CHECK_GRAPH(AutofuseOptimize_Exit) {
322 std::map<std::string, size_t> node_types_to_count0;348 std::map<std::string, size_t> node_types_to_count0;
@@ -327,7 +353,9 @@ TEST_F(TestCanfusePass, test_canfuse_ele_and_bro_horizontal_fusion_2) {
327 EXPECT_EQ(str, "success");353 EXPECT_EQ(str, "success");
328 };354 };
329 355 
330- auto asc_bc = compute_graph->FindFirstNodeMatchType("AscBackend");356+ auto compiled_graph = GetJitCompiledGraph(session, 1);
357+ ASSERT_NE(compiled_graph, nullptr);
358+ auto asc_bc = compiled_graph->FindFirstNodeMatchType("AscBackend");
331 ASSERT_NE(asc_bc, nullptr);359 ASSERT_NE(asc_bc, nullptr);
332 auto attr = asc_bc->GetOpDesc()->GetAttrsGroup<AutoFuseAttrs>();360 auto attr = asc_bc->GetOpDesc()->GetAttrsGroup<AutoFuseAttrs>();
333 ASSERT_NE(attr, nullptr);361 ASSERT_NE(attr, nullptr);
@@ -429,12 +457,8 @@ TEST_F(TestCanfusePass, test_canfuse_bro_and_bro_horizontal_fusion) {
429 Session session(options);457 Session session(options);
430 auto ret = session.AddGraph(1, *graph, options);458 auto ret = session.AddGraph(1, *graph, options);
431 EXPECT_EQ(ret, SUCCESS);459 EXPECT_EQ(ret, SUCCESS);
432- InputTensorInfo input1{0, {2, 2}, nullptr, 0};460+ // 通过 CompileGraph 触发真实编译,融合结果在 GEP 编译副本上
433- InputTensorInfo input2{0, {2, 2, 2}, nullptr, 0};461+ EXPECT_EQ(session.CompileGraph(1), SUCCESS);
434- InputTensorInfo input3{0, {2, 2, 2}, nullptr, 0};
435- std::vector<InputTensorInfo> inputs{input1, input2, input3};
436- // 当前测试框架还不支持 BuildGraph 接口端到端编译、加载, 仅测试编译流程
437- EXPECT_EQ(session.BuildGraph(1, inputs), SUCCESS);
438 462 
439 CHECK_GRAPH(AutofuseOptimize_Exit) {463 CHECK_GRAPH(AutofuseOptimize_Exit) {
440 std::map<std::string, size_t> node_types_to_count0;464 std::map<std::string, size_t> node_types_to_count0;
@@ -446,7 +470,9 @@ TEST_F(TestCanfusePass, test_canfuse_bro_and_bro_horizontal_fusion) {
446 EXPECT_NE(str, "success"); // 恢复线上阻塞,临时修改470 EXPECT_NE(str, "success"); // 恢复线上阻塞,临时修改
447 };471 };
448 472 
449- auto asc_bc = compute_graph->FindFirstNodeMatchType("AscBackend");473+ auto compiled_graph = GetJitCompiledGraph(session, 1);
474+ ASSERT_NE(compiled_graph, nullptr);
475+ auto asc_bc = compiled_graph->FindFirstNodeMatchType("AscBackend");
450 ASSERT_NE(asc_bc, nullptr);476 ASSERT_NE(asc_bc, nullptr);
451 auto attr = asc_bc->GetOpDesc()->GetAttrsGroup<AutoFuseAttrs>();477 auto attr = asc_bc->GetOpDesc()->GetAttrsGroup<AutoFuseAttrs>();
452 ASSERT_NE(attr, nullptr);478 ASSERT_NE(attr, nullptr);
@@ -490,11 +516,8 @@ TEST_F(TestCanfusePass, test_canfuse_bro_and_red_horizontal_fusion_1) {
490 Session session(options);516 Session session(options);
491 auto ret = session.AddGraph(1, *graph, options);517 auto ret = session.AddGraph(1, *graph, options);
492 EXPECT_EQ(ret, SUCCESS);518 EXPECT_EQ(ret, SUCCESS);
493- InputTensorInfo input1{0, {2, 2}, nullptr, 0};519+ // 通过 CompileGraph 触发真实编译,融合结果在 GEP 编译副本上
494- InputTensorInfo input2{0, {2}, nullptr, 0};520+ EXPECT_EQ(session.CompileGraph(1), SUCCESS);
495- std::vector<InputTensorInfo> inputs{input1, input2};
496- // 当前测试框架还不支持 BuildGraph 接口端到端编译、加载, 仅测试编译流程
497- EXPECT_EQ(session.BuildGraph(1, inputs), SUCCESS);
498 521 
499 CHECK_GRAPH(AutofuseOptimize_Exit) {522 CHECK_GRAPH(AutofuseOptimize_Exit) {
500 std::map<std::string, size_t> node_types_to_count0;523 std::map<std::string, size_t> node_types_to_count0;
@@ -507,7 +530,9 @@ TEST_F(TestCanfusePass, test_canfuse_bro_and_red_horizontal_fusion_1) {
507 // EXPECT_EQ(str, "success"); // 恢复线上阻塞,临时修改530 // EXPECT_EQ(str, "success"); // 恢复线上阻塞,临时修改
508 };531 };
509 532 
510- auto asc_bc = compute_graph->FindFirstNodeMatchType("AscBackend");533+ auto compiled_graph = GetJitCompiledGraph(session, 1);
534+ ASSERT_NE(compiled_graph, nullptr);
535+ auto asc_bc = compiled_graph->FindFirstNodeMatchType("AscBackend");
511 ASSERT_NE(asc_bc, nullptr);536 ASSERT_NE(asc_bc, nullptr);
512 auto attr = asc_bc->GetOpDesc()->GetAttrsGroup<AutoFuseAttrs>();537 auto attr = asc_bc->GetOpDesc()->GetAttrsGroup<AutoFuseAttrs>();
513 ASSERT_NE(attr, nullptr);538 ASSERT_NE(attr, nullptr);
@@ -609,10 +634,8 @@ TEST_F(TestCanfusePass, test_canfuse_red_and_red_vertical_fusion_1) {
609 Session session(options);634 Session session(options);
610 auto ret = session.AddGraph(1, *graph, options);635 auto ret = session.AddGraph(1, *graph, options);
611 EXPECT_EQ(ret, SUCCESS);636 EXPECT_EQ(ret, SUCCESS);
612- InputTensorInfo input1{0, {2, 2, 16}, nullptr, 0};637+ // 通过 CompileGraph 触发真实编译,融合结果在 GEP 编译副本上
613- std::vector<InputTensorInfo> inputs{input1};638+ session.CompileGraph(1);
614- // 当前测试框架还不支持 BuildGraph 接口端到端编译、加载, 仅测试编译流程
615- session.BuildGraph(1, inputs);
616 639 
617 // lifting AscBackend中单节点还原为原节点640 // lifting AscBackend中单节点还原为原节点
618 CHECK_GRAPH(AutofuseOptimize_Exit) {641 CHECK_GRAPH(AutofuseOptimize_Exit) {
@@ -651,11 +674,8 @@ TEST_F(TestCanfusePass, test_canfuse_red_and_bro_vertical_fusion) {
651 Session session(options);674 Session session(options);
652 auto ret = session.AddGraph(1, *graph, options);675 auto ret = session.AddGraph(1, *graph, options);
653 EXPECT_EQ(ret, SUCCESS);676 EXPECT_EQ(ret, SUCCESS);
654- InputTensorInfo input1{0, {2, 2, 2}, nullptr, 0};677+ // 通过 CompileGraph 触发真实编译,融合结果在 GEP 编译副本上
655- InputTensorInfo input2{0, {2, 2, 2}, nullptr, 0};678+ EXPECT_EQ(session.CompileGraph(1), SUCCESS);
656- std::vector<InputTensorInfo> inputs{input1, input2};
657- // 当前测试框架还不支持 BuildGraph 接口端到端编译、加载, 仅测试编译流程
658- EXPECT_EQ(session.BuildGraph(1, inputs), SUCCESS);
659 679 
660 CHECK_GRAPH(AutofuseOptimize_Exit) {680 CHECK_GRAPH(AutofuseOptimize_Exit) {
661 std::map<std::string, size_t> node_types_to_count0;681 std::map<std::string, size_t> node_types_to_count0;
@@ -668,7 +688,9 @@ TEST_F(TestCanfusePass, test_canfuse_red_and_bro_vertical_fusion) {
668 // EXPECT_EQ(str, "success"); // 恢复线上阻塞,临时修改688 // EXPECT_EQ(str, "success"); // 恢复线上阻塞,临时修改
669 };689 };
670 690 
671- auto fused_asc_bc = compute_graph->FindFirstNodeMatchType("AscBackend");691+ auto compiled_graph = GetJitCompiledGraph(session, 1);
692+ ASSERT_NE(compiled_graph, nullptr);
693+ auto fused_asc_bc = compiled_graph->FindFirstNodeMatchType("AscBackend");
672 ASSERT_NE(fused_asc_bc, nullptr);694 ASSERT_NE(fused_asc_bc, nullptr);
673 auto attr = fused_asc_bc->GetOpDesc()->GetAttrsGroup<AutoFuseAttrs>();695 auto attr = fused_asc_bc->GetOpDesc()->GetAttrsGroup<AutoFuseAttrs>();
674 ASSERT_NE(attr, nullptr);696 ASSERT_NE(attr, nullptr);
@@ -712,10 +734,8 @@ TEST_F(TestCanfusePass, test_canfuse_red_and_ele_vertical_fusion) {
712 Session session(options);734 Session session(options);
713 auto ret = session.AddGraph(1, *graph, options);735 auto ret = session.AddGraph(1, *graph, options);
714 EXPECT_EQ(ret, SUCCESS);736 EXPECT_EQ(ret, SUCCESS);
715- InputTensorInfo input1{0, {2, 2, 16}, nullptr, 0};737+ // 通过 CompileGraph 触发真实编译,融合结果在 GEP 编译副本上
716- std::vector<InputTensorInfo> inputs{input1};738+ EXPECT_EQ(session.CompileGraph(1), SUCCESS);
717- // 当前测试框架还不支持 BuildGraph 接口端到端编译、加载, 仅测试编译流程
718- EXPECT_EQ(session.BuildGraph(1, inputs), SUCCESS);
719 739 
720 CHECK_GRAPH(AutofuseOptimize_Exit) {740 CHECK_GRAPH(AutofuseOptimize_Exit) {
721 std::map<std::string, size_t> node_types_to_count0;741 std::map<std::string, size_t> node_types_to_count0;
@@ -727,7 +747,9 @@ TEST_F(TestCanfusePass, test_canfuse_red_and_ele_vertical_fusion) {
727 EXPECT_EQ(str, "success");747 EXPECT_EQ(str, "success");
728 };748 };
729 749 
730- auto fused_asc_bc = compute_graph->FindFirstNodeMatchType("AscBackend");750+ auto compiled_graph = GetJitCompiledGraph(session, 1);
751+ ASSERT_NE(compiled_graph, nullptr);
752+ auto fused_asc_bc = compiled_graph->FindFirstNodeMatchType("AscBackend");
731 ASSERT_NE(fused_asc_bc, nullptr);753 ASSERT_NE(fused_asc_bc, nullptr);
732 auto attr = fused_asc_bc->GetOpDesc()->GetAttrsGroup<AutoFuseAttrs>();754 auto attr = fused_asc_bc->GetOpDesc()->GetAttrsGroup<AutoFuseAttrs>();
733 ASSERT_NE(attr, nullptr);755 ASSERT_NE(attr, nullptr);
@@ -771,10 +793,8 @@ TEST_F(TestCanfusePass, test_canfuse_ele_and_ele_vertical_fusion) {
771 Session session(options);793 Session session(options);
772 auto ret = session.AddGraph(1, *graph, options);794 auto ret = session.AddGraph(1, *graph, options);
773 EXPECT_EQ(ret, SUCCESS);795 EXPECT_EQ(ret, SUCCESS);
774- InputTensorInfo input1{0, {2, 2, 2}, nullptr, 0};796+ // 通过 CompileGraph 触发真实编译,融合结果在 GEP 编译副本上
775- std::vector<InputTensorInfo> inputs{input1};797+ EXPECT_EQ(session.CompileGraph(1), SUCCESS);
776- // 当前测试框架还不支持 BuildGraph 接口端到端编译、加载, 仅测试编译流程
777- EXPECT_EQ(session.BuildGraph(1, inputs), SUCCESS);
778 CHECK_GRAPH(AutofuseOptimize_Exit) {798 CHECK_GRAPH(AutofuseOptimize_Exit) {
779 std::map<std::string, size_t> node_types_to_count0;799 std::map<std::string, size_t> node_types_to_count0;
780 node_types_to_count0.emplace("Data", 1);800 node_types_to_count0.emplace("Data", 1);
@@ -784,7 +804,9 @@ TEST_F(TestCanfusePass, test_canfuse_ele_and_ele_vertical_fusion) {
784 EXPECT_EQ(str, "success");804 EXPECT_EQ(str, "success");
785 };805 };
786 806 
787- auto fused_asc_bc = compute_graph->FindFirstNodeMatchType("AscBackend");807+ auto compiled_graph = GetJitCompiledGraph(session, 1);
808+ ASSERT_NE(compiled_graph, nullptr);
809+ auto fused_asc_bc = compiled_graph->FindFirstNodeMatchType("AscBackend");
788 ASSERT_NE(fused_asc_bc, nullptr);810 ASSERT_NE(fused_asc_bc, nullptr);
789 auto attr = fused_asc_bc->GetOpDesc()->GetAttrsGroup<AutoFuseAttrs>();811 auto attr = fused_asc_bc->GetOpDesc()->GetAttrsGroup<AutoFuseAttrs>();
790 ASSERT_NE(attr, nullptr);812 ASSERT_NE(attr, nullptr);
@@ -830,11 +852,8 @@ TEST_F(TestCanfusePass, test_canfuse_ele_and_bro_vertical_fusion) {
830 Session session(options);852 Session session(options);
831 auto ret = session.AddGraph(1, *graph, options);853 auto ret = session.AddGraph(1, *graph, options);
832 EXPECT_EQ(ret, SUCCESS);854 EXPECT_EQ(ret, SUCCESS);
833- InputTensorInfo input1{0, {2, 2, 2}, nullptr, 0};855+ // 通过 CompileGraph 触发真实编译,融合结果在 GEP 编译副本上
834- InputTensorInfo input2{0, {2, 2, 2, 2}, nullptr, 0};856+ EXPECT_EQ(session.CompileGraph(1), SUCCESS);
835- std::vector<InputTensorInfo> inputs{input1, input2};
836- // 当前测试框架还不支持 BuildGraph 接口端到端编译、加载, 仅测试编译流程
837- EXPECT_EQ(session.BuildGraph(1, inputs), SUCCESS);
838 857 
839 CHECK_GRAPH(AutofuseOptimize_Exit) {858 CHECK_GRAPH(AutofuseOptimize_Exit) {
840 std::map<std::string, size_t> node_types_to_count0;859 std::map<std::string, size_t> node_types_to_count0;
@@ -845,7 +864,9 @@ TEST_F(TestCanfusePass, test_canfuse_ele_and_bro_vertical_fusion) {
845 EXPECT_EQ(str, "success");864 EXPECT_EQ(str, "success");
846 };865 };
847 866 
848- auto fused_asc_bc = compute_graph->FindFirstNodeMatchType("AscBackend");867+ auto compiled_graph = GetJitCompiledGraph(session, 1);
868+ ASSERT_NE(compiled_graph, nullptr);
869+ auto fused_asc_bc = compiled_graph->FindFirstNodeMatchType("AscBackend");
849 ASSERT_NE(fused_asc_bc, nullptr);870 ASSERT_NE(fused_asc_bc, nullptr);
850 auto attr = fused_asc_bc->GetOpDesc()->GetAttrsGroup<AutoFuseAttrs>();871 auto attr = fused_asc_bc->GetOpDesc()->GetAttrsGroup<AutoFuseAttrs>();
851 ASSERT_NE(attr, nullptr);872 ASSERT_NE(attr, nullptr);
@@ -893,11 +914,9 @@ TEST_F(TestCanfusePass, test_canfuse_ele_and_red_vertical_fusion) {
893 Session session(options);914 Session session(options);
894 auto ret = session.AddGraph(1, *graph, options);915 auto ret = session.AddGraph(1, *graph, options);
895 EXPECT_EQ(ret, SUCCESS);916 EXPECT_EQ(ret, SUCCESS);
896- InputTensorInfo input1{0, {2, 2, 16}, nullptr, 0};
897- std::vector<InputTensorInfo> inputs{input1};
898 DUMP_GRAPH_WHEN("AutofuseOptimize_Exit");917 DUMP_GRAPH_WHEN("AutofuseOptimize_Exit");
899- // 当前测试框架还不支持 BuildGraph 接口端到端编译、加载, 仅测试编译流程918+ // 通过 CompileGraph 触发真实编译,融合结果在 GEP 编译副本上
900- EXPECT_EQ(session.BuildGraph(1, inputs), SUCCESS);919+ EXPECT_EQ(session.CompileGraph(1), SUCCESS);
901 920 
902 CHECK_GRAPH(AutofuseOptimize_Exit) {921 CHECK_GRAPH(AutofuseOptimize_Exit) {
903 std::map<std::string, size_t> node_types_to_count0;922 std::map<std::string, size_t> node_types_to_count0;
@@ -909,7 +928,9 @@ TEST_F(TestCanfusePass, test_canfuse_ele_and_red_vertical_fusion) {
909 EXPECT_EQ(str, "success");928 EXPECT_EQ(str, "success");
910 };929 };
911 930 
912- auto fused_asc_bc = compute_graph->FindFirstNodeMatchType("AscBackend");931+ auto compiled_graph = GetJitCompiledGraph(session, 1);
932+ ASSERT_NE(compiled_graph, nullptr);
933+ auto fused_asc_bc = compiled_graph->FindFirstNodeMatchType("AscBackend");
913 ASSERT_NE(fused_asc_bc, nullptr);934 ASSERT_NE(fused_asc_bc, nullptr);
914 auto attr = fused_asc_bc->GetOpDesc()->GetAttrsGroup<AutoFuseAttrs>();935 auto attr = fused_asc_bc->GetOpDesc()->GetAttrsGroup<AutoFuseAttrs>();
915 ASSERT_NE(attr, nullptr);936 ASSERT_NE(attr, nullptr);
@@ -954,12 +975,9 @@ TEST_F(TestCanfusePass, test_canfuse_bro_and_ele_vertical_fusion) {
954 Session session(options);975 Session session(options);
955 auto ret = session.AddGraph(1, *graph, options);976 auto ret = session.AddGraph(1, *graph, options);
956 EXPECT_EQ(ret, SUCCESS);977 EXPECT_EQ(ret, SUCCESS);
957- InputTensorInfo input1{0, {2, 2, 2}, nullptr, 0};
958- InputTensorInfo input2{0, {2, 2, 2, 2}, nullptr, 0};
959- std::vector<InputTensorInfo> inputs{input1, input2};
960 DUMP_GRAPH_WHEN("AutofuseOptimize_Exit");978 DUMP_GRAPH_WHEN("AutofuseOptimize_Exit");
961- // 当前测试框架还不支持 BuildGraph 接口端到端编译、加载, 仅测试编译流程979+ // 通过 CompileGraph 触发真实编译,融合结果在 GEP 编译副本上
962- EXPECT_EQ(session.BuildGraph(1, inputs), SUCCESS);980+ EXPECT_EQ(session.CompileGraph(1), SUCCESS);
963 981 
964 CHECK_GRAPH(AutofuseOptimize_Exit) {982 CHECK_GRAPH(AutofuseOptimize_Exit) {
965 std::map<std::string, size_t> node_types_to_count0;983 std::map<std::string, size_t> node_types_to_count0;
@@ -970,7 +988,9 @@ TEST_F(TestCanfusePass, test_canfuse_bro_and_ele_vertical_fusion) {
970 EXPECT_EQ(str, "success");988 EXPECT_EQ(str, "success");
971 };989 };
972 990 
973- auto fused_asc_bc = compute_graph->FindFirstNodeMatchType("AscBackend");991+ auto compiled_graph = GetJitCompiledGraph(session, 1);
992+ ASSERT_NE(compiled_graph, nullptr);
993+ auto fused_asc_bc = compiled_graph->FindFirstNodeMatchType("AscBackend");
974 ASSERT_NE(fused_asc_bc, nullptr);994 ASSERT_NE(fused_asc_bc, nullptr);
975 auto attr = fused_asc_bc->GetOpDesc()->GetAttrsGroup<AutoFuseAttrs>();995 auto attr = fused_asc_bc->GetOpDesc()->GetAttrsGroup<AutoFuseAttrs>();
976 996 
@@ -1018,12 +1038,9 @@ TEST_F(TestCanfusePass, test_canfuse_bro_and_red_vertical_fusion) {
1018 Session session(options);1038 Session session(options);
1019 auto ret = session.AddGraph(1, *graph, options);1039 auto ret = session.AddGraph(1, *graph, options);
1020 EXPECT_EQ(ret, SUCCESS);1040 EXPECT_EQ(ret, SUCCESS);
1021- InputTensorInfo input1{0, {16, 16, 16}, nullptr, 0};
1022- InputTensorInfo input2{0, {16, 16, 16, 16}, nullptr, 0};
1023- std::vector<InputTensorInfo> inputs{input1, input2};
1024 DUMP_GRAPH_WHEN("AutofuseOptimize_Exit");1041 DUMP_GRAPH_WHEN("AutofuseOptimize_Exit");
1025- // 当前测试框架还不支持 BuildGraph 接口端到端编译、加载, 仅测试编译流程1042+ // 通过 CompileGraph 触发真实编译,融合结果在 GEP 编译副本上
1026- EXPECT_EQ(session.BuildGraph(1, inputs), SUCCESS);1043+ EXPECT_EQ(session.CompileGraph(1), SUCCESS);
1027 1044 
1028 CHECK_GRAPH(AutofuseOptimize_Exit) {1045 CHECK_GRAPH(AutofuseOptimize_Exit) {
1029 std::map<std::string, size_t> node_types_to_count0;1046 std::map<std::string, size_t> node_types_to_count0;
@@ -1035,7 +1052,9 @@ TEST_F(TestCanfusePass, test_canfuse_bro_and_red_vertical_fusion) {
1035 EXPECT_EQ(str, "success");1052 EXPECT_EQ(str, "success");
1036 };1053 };
1037 1054 
1038- auto fused_asc_bc = compute_graph->FindFirstNodeMatchType("AscBackend");1055+ auto compiled_graph = GetJitCompiledGraph(session, 1);
1056+ ASSERT_NE(compiled_graph, nullptr);
1057+ auto fused_asc_bc = compiled_graph->FindFirstNodeMatchType("AscBackend");
1039 ASSERT_NE(fused_asc_bc, nullptr);1058 ASSERT_NE(fused_asc_bc, nullptr);
1040 auto attr = fused_asc_bc->GetOpDesc()->GetAttrsGroup<AutoFuseAttrs>();1059 auto attr = fused_asc_bc->GetOpDesc()->GetAttrsGroup<AutoFuseAttrs>();
1041 1060 
@@ -1082,13 +1101,9 @@ TEST_F(TestCanfusePass, test_canfuse_bro_and_bro_vertical_fusion) {
1082 Session session(options);1101 Session session(options);
1083 auto ret = session.AddGraph(1, *graph, options);1102 auto ret = session.AddGraph(1, *graph, options);
1084 EXPECT_EQ(ret, SUCCESS);1103 EXPECT_EQ(ret, SUCCESS);
1085- InputTensorInfo input1{0, {2, 2}, nullptr, 0};
1086- InputTensorInfo input2{0, {2, 2, 2}, nullptr, 0};
1087- InputTensorInfo input3{0, {2, 2, 2, 2}, nullptr, 0};
1088- std::vector<InputTensorInfo> inputs{input1, input2, input3};
1089 DUMP_GRAPH_WHEN("AutofuseOptimize_Exit");1104 DUMP_GRAPH_WHEN("AutofuseOptimize_Exit");
1090- // 当前测试框架还不支持 BuildGraph 接口端到端编译、加载, 仅测试编译流程1105+ // 通过 CompileGraph 触发真实编译,融合结果在 GEP 编译副本上
1091- EXPECT_EQ(session.BuildGraph(1, inputs), SUCCESS);1106+ EXPECT_EQ(session.CompileGraph(1), SUCCESS);
1092 1107 
1093 CHECK_GRAPH(AutofuseOptimize_Exit) {1108 CHECK_GRAPH(AutofuseOptimize_Exit) {
1094 std::map<std::string, size_t> node_types_to_count0;1109 std::map<std::string, size_t> node_types_to_count0;
@@ -1099,7 +1114,9 @@ TEST_F(TestCanfusePass, test_canfuse_bro_and_bro_vertical_fusion) {
1099 EXPECT_EQ(str, "success");1114 EXPECT_EQ(str, "success");
1100 };1115 };
1101 1116 
1102- auto fused_asc_bc = compute_graph->FindFirstNodeMatchType("AscBackend");1117+ auto compiled_graph = GetJitCompiledGraph(session, 1);
1118+ ASSERT_NE(compiled_graph, nullptr);
1119+ auto fused_asc_bc = compiled_graph->FindFirstNodeMatchType("AscBackend");
1103 ASSERT_NE(fused_asc_bc, nullptr);1120 ASSERT_NE(fused_asc_bc, nullptr);
1104 auto attr = fused_asc_bc->GetOpDesc()->GetAttrsGroup<AutoFuseAttrs>();1121 auto attr = fused_asc_bc->GetOpDesc()->GetAttrsGroup<AutoFuseAttrs>();
1105 ASSERT_NE(attr, nullptr);1122 ASSERT_NE(attr, nullptr);
@@ -1145,10 +1162,8 @@ TEST_F(TestCanfusePass, test_canfuse_red_and_red_vertical_fusion_2) {
1145 Session session(options);1162 Session session(options);
1146 auto ret = session.AddGraph(1, *graph, options);1163 auto ret = session.AddGraph(1, *graph, options);
1147 EXPECT_EQ(ret, SUCCESS);1164 EXPECT_EQ(ret, SUCCESS);
1148- InputTensorInfo input1{0, {16, 16, 16}, nullptr, 0};1165+ // 通过 CompileGraph 触发真实编译,融合结果在 GEP 编译副本上
1149- std::vector<InputTensorInfo> inputs{input1};1166+ EXPECT_EQ(session.CompileGraph(1), SUCCESS);
1150- // 当前测试框架还不支持 BuildGraph 接口端到端编译、加载, 仅测试编译流程
1151- EXPECT_EQ(session.BuildGraph(1, inputs), SUCCESS);
1152 1167 
1153 CHECK_GRAPH(AutofuseOptimize_Exit) {1168 CHECK_GRAPH(AutofuseOptimize_Exit) {
1154 std::map<std::string, size_t> node_types_to_count0;1169 std::map<std::string, size_t> node_types_to_count0;
@@ -1160,7 +1175,9 @@ TEST_F(TestCanfusePass, test_canfuse_red_and_red_vertical_fusion_2) {
1160 EXPECT_EQ(str, "success");1175 EXPECT_EQ(str, "success");
1161 };1176 };
1162 1177 
1163- auto fused_asc_bc = compute_graph->FindFirstNodeMatchType("AscBackend");1178+ auto compiled_graph = GetJitCompiledGraph(session, 1);
1179+ ASSERT_NE(compiled_graph, nullptr);
1180+ auto fused_asc_bc = compiled_graph->FindFirstNodeMatchType("AscBackend");
1164 ASSERT_NE(fused_asc_bc, nullptr);1181 ASSERT_NE(fused_asc_bc, nullptr);
1165 auto attr = fused_asc_bc->GetOpDesc()->GetAttrsGroup<AutoFuseAttrs>();1182 auto attr = fused_asc_bc->GetOpDesc()->GetAttrsGroup<AutoFuseAttrs>();
1166 ASSERT_NE(attr, nullptr);1183 ASSERT_NE(attr, nullptr);
@@ -57,7 +57,7 @@ TEST_F(ExecutionOrderUT, no_slice_tests) {
57 57 
58 compute_graph->SetOutputSize(2); // make a wrong output size58 compute_graph->SetOutputSize(2); // make a wrong output size
59 59 
60- UserGraph user_graph{0, compute_graph};60+ UserGraph user_graph{0, compute_graph, {}, true};
61 ExecutionOrder eo(user_graph);61 ExecutionOrder eo(user_graph);
62 62 
63 std::vector<GeTensor> input_tensors(1);63 std::vector<GeTensor> input_tensors(1);
@@ -390,7 +390,7 @@ TEST_F(JitExecutorUT, run_success_when_input_graph_contain_one_reshape_node) {
390 uint32_t user_graph_id = 0u;390 uint32_t user_graph_id = 0u;
391 auto graph = JitShareGraph::OneReshapeNode();391 auto graph = JitShareGraph::OneReshapeNode();
392 auto compute_graph = GraphUtilsEx::GetComputeGraph(*graph.get());392 auto compute_graph = GraphUtilsEx::GetComputeGraph(*graph.get());
393- ExecutionOrder order({user_graph_id, compute_graph});393+ ExecutionOrder order({user_graph_id, compute_graph, {}, true});
394 CompileContext compile_context(graph_manager);394 CompileContext compile_context(graph_manager);
395 CompiledModelCache cmc(user_graph_id, compile_context, graph_manager);395 CompiledModelCache cmc(user_graph_id, compile_context, graph_manager);
396 std::mutex tmp_mutex;396 std::mutex tmp_mutex;
@@ -483,7 +483,7 @@ TEST_F(JitExecutorUT, run_success_when_input_graph_contain_one_reshape_node_with
483 uint32_t user_graph_id = 0u;483 uint32_t user_graph_id = 0u;
484 auto graph = JitShareGraph::OneReshapeNodeWithHostInput();484 auto graph = JitShareGraph::OneReshapeNodeWithHostInput();
485 auto compute_graph = GraphUtilsEx::GetComputeGraph(*graph.get());485 auto compute_graph = GraphUtilsEx::GetComputeGraph(*graph.get());
486- ExecutionOrder order({user_graph_id, compute_graph});486+ ExecutionOrder order({user_graph_id, compute_graph, {}, true});
487 CompileContext compile_context(graph_manager);487 CompileContext compile_context(graph_manager);
488 CompiledModelCache cmc(user_graph_id, compile_context, graph_manager);488 CompiledModelCache cmc(user_graph_id, compile_context, graph_manager);
489 std::mutex tmp_mutex;489 std::mutex tmp_mutex;
@@ -545,7 +545,7 @@ TEST_F(JitExecutorUT, run_success_when_input_graph_contain_one_reshape_two_relu_
545 uint32_t user_graph_id = 0u;545 uint32_t user_graph_id = 0u;
546 auto graph = JitShareGraph::OneReshapeNodeTwoRelu();546 auto graph = JitShareGraph::OneReshapeNodeTwoRelu();
547 auto compute_graph = GraphUtilsEx::GetComputeGraph(*graph.get());547 auto compute_graph = GraphUtilsEx::GetComputeGraph(*graph.get());
548- ExecutionOrder order({user_graph_id, compute_graph});548+ ExecutionOrder order({user_graph_id, compute_graph, {}, true});
549 CompileContext compile_context(graph_manager);549 CompileContext compile_context(graph_manager);
550 CompiledModelCache cmc(user_graph_id, compile_context, graph_manager);550 CompiledModelCache cmc(user_graph_id, compile_context, graph_manager);
551 std::mutex tmp_mutex;551 std::mutex tmp_mutex;
@@ -606,7 +606,7 @@ TEST_F(JitExecutorUT, run_success_when_input_graph_contain_two_reshape_node) {
606 uint32_t user_graph_id = 0u;606 uint32_t user_graph_id = 0u;
607 auto graph = JitShareGraph::TwoReshapeNodeTwoRelu();607 auto graph = JitShareGraph::TwoReshapeNodeTwoRelu();
608 auto compute_graph = GraphUtilsEx::GetComputeGraph(*graph.get());608 auto compute_graph = GraphUtilsEx::GetComputeGraph(*graph.get());
609- ExecutionOrder order({user_graph_id, compute_graph});609+ ExecutionOrder order({user_graph_id, compute_graph, {}, true});
610 CompileContext compile_context(graph_manager);610 CompileContext compile_context(graph_manager);
611 CompiledModelCache cmc(user_graph_id, compile_context, graph_manager);611 CompiledModelCache cmc(user_graph_id, compile_context, graph_manager);
612 std::mutex tmp_mutex;612 std::mutex tmp_mutex;
@@ -662,7 +662,7 @@ TEST_F(JitExecutorUT, run_success_when_input_graph_contain_two_reshape_one_const
662 uint32_t user_graph_id = 0u;662 uint32_t user_graph_id = 0u;
663 auto graph = JitShareGraph::OneConstTwoReshapeNodeTwoRelu();663 auto graph = JitShareGraph::OneConstTwoReshapeNodeTwoRelu();
664 auto compute_graph = GraphUtilsEx::GetComputeGraph(*graph.get());664 auto compute_graph = GraphUtilsEx::GetComputeGraph(*graph.get());
665- ExecutionOrder order({user_graph_id, compute_graph});665+ ExecutionOrder order({user_graph_id, compute_graph, {}, true});
666 CompileContext compile_context(graph_manager);666 CompileContext compile_context(graph_manager);
667 CompiledModelCache cmc(user_graph_id, compile_context, graph_manager);667 CompiledModelCache cmc(user_graph_id, compile_context, graph_manager);
668 std::mutex tmp_mutex;668 std::mutex tmp_mutex;
@@ -160,6 +160,97 @@ TEST_F(UserGraphControlUT, GetSetCompiledFlag_Success) {
160 EXPECT_EQ(graph_manager.Finalize(), SUCCESS);160 EXPECT_EQ(graph_manager.Finalize(), SUCCESS);
161}161}
162 162 
163+TEST_F(UserGraphControlUT, GetSetRunGraphMode_Success) {
164+ ModelExecutor model_executor;
165+ model_executor.Initialize({}, 0);
166+ GraphManager graph_manager;
167+ EXPECT_EQ(graph_manager.Initialize({}, &model_executor), SUCCESS);
168+ auto graph = JitShareGraph::AllNormalNodes();
169+ auto compute_graph = GraphUtilsEx::GetComputeGraph(*graph.get());
170+ CompileContext compile_context(graph_manager);
171+ auto ctrl = MakeUnique<UserGraphControl>(0U, compute_graph, compile_context, graph_manager,
172+ std::map<std::string, std::string>{});
173+ 
174+ EXPECT_EQ(ctrl->GetRunGraphMode(), RunGraphMode::kRunGraphModeEnd);
175+ ctrl->SetRunGraphMode(RunGraphMode::kRunGraph);
176+ EXPECT_EQ(ctrl->GetRunGraphMode(), RunGraphMode::kRunGraph);
177+ ctrl->SetRunGraphMode(RunGraphMode::kRunGraphWithStreamAsync);
178+ EXPECT_EQ(ctrl->GetRunGraphMode(), RunGraphMode::kRunGraphWithStreamAsync);
179+ 
180+ EXPECT_EQ(ctrl->Finalize(), SUCCESS);
181+ EXPECT_EQ(graph_manager.Finalize(), SUCCESS);
182+}
183+ 
184+TEST_F(UserGraphControlUT, RunGraph_StaticShape_Success) {
185+ ModelExecutor model_executor;
186+ model_executor.Initialize({}, 0);
187+ GraphManager graph_manager;
188+ EXPECT_EQ(graph_manager.Initialize({}, &model_executor), SUCCESS);
189+ auto graph = JitShareGraph::AllNormalNodesStaticShape();
190+ auto compute_graph = GraphUtilsEx::GetComputeGraph(*graph.get());
191+ CompileContext compile_context(graph_manager);
192+ auto ctrl = MakeUnique<UserGraphControl>(0U, compute_graph, compile_context, graph_manager,
193+ std::map<std::string, std::string>{});
194+ 
195+ std::vector<gert::Tensor> inputs(1U);
196+ TensorCheckUtils::ConstructGertTensor(inputs[0], {2, 3, 3, 2}, DT_FLOAT, FORMAT_NCHW);
197+ std::vector<gert::Tensor> outputs;
198+ EXPECT_EQ(ctrl->RunGraph(inputs, outputs, 0U), SUCCESS);
199+ EXPECT_FALSE(outputs.empty());
200+ 
201+ EXPECT_EQ(ctrl->Finalize(), SUCCESS);
202+ EXPECT_EQ(graph_manager.Finalize(), SUCCESS);
203+}
204+ 
205+TEST_F(UserGraphControlUT, RunGraph_GeTensor_StaticShape_Success) {
206+ ModelExecutor model_executor;
207+ model_executor.Initialize({}, 0);
208+ GraphManager graph_manager;
209+ EXPECT_EQ(graph_manager.Initialize({}, &model_executor), SUCCESS);
210+ auto graph = JitShareGraph::AllNormalNodesStaticShape();
211+ auto compute_graph = GraphUtilsEx::GetComputeGraph(*graph.get());
212+ CompileContext compile_context(graph_manager);
213+ auto ctrl = MakeUnique<UserGraphControl>(0U, compute_graph, compile_context, graph_manager,
214+ std::map<std::string, std::string>{});
215+ 
216+ TensorDesc tensor_desc(Shape({2, 3, 3, 2}), FORMAT_NCHW, DT_FLOAT);
217+ std::vector<float> input_data(2U * 3U * 3U * 2U, 0.0F);
218+ GeTensorDesc ge_tensor_desc = TensorAdapter::TensorDesc2GeTensorDesc(tensor_desc);
219+ GeTensor ge_input(ge_tensor_desc, reinterpret_cast<uint8_t *>(input_data.data()), input_data.size() * sizeof(float));
220+ std::vector<ge::Tensor> inputs{TensorAdapter::AsTensor(ge_input)};
221+ std::vector<ge::Tensor> outputs;
222+ EXPECT_EQ(ctrl->RunGraph(inputs, outputs, 0U), SUCCESS);
223+ EXPECT_FALSE(outputs.empty());
224+ 
225+ EXPECT_EQ(ctrl->Finalize(), SUCCESS);
226+ EXPECT_EQ(graph_manager.Finalize(), SUCCESS);
227+}
228+ 
229+TEST_F(UserGraphControlUT, RunGraphWithStreamAsync_GeTensor_Success) {
230+ ModelExecutor model_executor;
231+ model_executor.Initialize({}, 0);
232+ GraphManager graph_manager;
233+ EXPECT_EQ(graph_manager.Initialize({}, &model_executor), SUCCESS);
234+ auto graph = JitShareGraph::AllNormalNodesStaticShape();
235+ auto compute_graph = GraphUtilsEx::GetComputeGraph(*graph.get());
236+ CompileContext compile_context(graph_manager);
237+ auto ctrl = MakeUnique<UserGraphControl>(0U, compute_graph, compile_context, graph_manager,
238+ std::map<std::string, std::string>{});
239+ 
240+ GeTensorDesc tensor_desc(GeShape({2, 3, 3, 2}), FORMAT_NCHW, DT_FLOAT);
241+ std::vector<float> input_data(2U * 3U * 3U * 2U, 0.0F);
242+ std::vector<GeTensor> inputs{
243+ GeTensor(tensor_desc, reinterpret_cast<uint8_t *>(input_data.data()), input_data.size() * sizeof(float))};
244+ std::vector<float> output_data(2U * 3U * 3U * 2U, 0.0F);
245+ std::vector<GeTensor> outputs{
246+ GeTensor(tensor_desc, reinterpret_cast<uint8_t *>(output_data.data()), output_data.size() * sizeof(float))};
247+ EXPECT_EQ(ctrl->RunGraphWithStreamAsync(nullptr, inputs, outputs, 0U), SUCCESS);
248+ EXPECT_FALSE(outputs.empty());
249+ 
250+ EXPECT_EQ(ctrl->Finalize(), SUCCESS);
251+ EXPECT_EQ(graph_manager.Finalize(), SUCCESS);
252+}
253+ 
163TEST_F(UserGraphControlUT, AddGraphInstance_MultiThread_Success) {254TEST_F(UserGraphControlUT, AddGraphInstance_MultiThread_Success) {
164 ModelExecutor model_executor;255 ModelExecutor model_executor;
165 model_executor.Initialize({}, 0);256 model_executor.Initialize({}, 0);
@@ -144,6 +144,32 @@ TEST_F(UserGraphsManagerlUT, GetSetCompiledFlag_Failed) {
144 EXPECT_EQ(graph_manager.Finalize(), SUCCESS);144 EXPECT_EQ(graph_manager.Finalize(), SUCCESS);
145}145}
146 146 
147+TEST_F(UserGraphsManagerlUT, GetSetRunGraphMode_AutoFuse_Success) {
148+ mmSetEnv("AUTOFUSE_FLAGS", "--enable_autofuse=true", 1);
149+ ModelExecutor model_executor;
150+ model_executor.Initialize({}, 0);
151+ GraphManager graph_manager;
152+ EXPECT_EQ(graph_manager.Initialize({}, &model_executor), SUCCESS);
153+ UserGraphsManager user_graph_manager(graph_manager);
154+ 
155+ const uint32_t user_graph_id = 0U;
156+ auto graph = JitShareGraph::AllNormalNodesStaticShape();
157+ EXPECT_EQ(user_graph_manager.AddGraph(user_graph_id, *graph, {}), SUCCESS);
158+ 
159+ RunGraphMode mode = RunGraphMode::kRunGraph;
160+ EXPECT_EQ(user_graph_manager.GetRunGraphMode(user_graph_id, mode), SUCCESS);
161+ EXPECT_EQ(mode, RunGraphMode::kRunGraphModeEnd);
162+ 
163+ EXPECT_EQ(user_graph_manager.SetRunGraphMode(user_graph_id, RunGraphMode::kRunGraph), SUCCESS);
164+ EXPECT_EQ(user_graph_manager.GetRunGraphMode(user_graph_id, mode), SUCCESS);
165+ EXPECT_EQ(mode, RunGraphMode::kRunGraph);
166+ 
167+ EXPECT_EQ(user_graph_manager.RemoveGraph(user_graph_id), SUCCESS);
168+ EXPECT_EQ(user_graph_manager.Finalize(), SUCCESS);
169+ EXPECT_EQ(graph_manager.Finalize(), SUCCESS);
170+ unsetenv("AUTOFUSE_FLAGS");
171+}
172+ 
147TEST_F(UserGraphsManagerlUT, RunGraphAsync_Success) {173TEST_F(UserGraphsManagerlUT, RunGraphAsync_Success) {
148 ModelExecutor model_executor;174 ModelExecutor model_executor;
149 model_executor.Initialize({}, 0);175 model_executor.Initialize({}, 0);
@@ -702,10 +728,10 @@ TEST_F(UserGraphsManagerlUT, set_memory_skip_by_slice_scheduler_enable) {
702 EXPECT_EQ(UNSUPPORTED, session.UpdateGraphRefreshableFeatureMemoryBase(graph_id, nullptr, 0));728 EXPECT_EQ(UNSUPPORTED, session.UpdateGraphRefreshableFeatureMemoryBase(graph_id, nullptr, 0));
703 729 
704 std::vector<std::string> expect_log_list = {730 std::vector<std::string> expect_log_list = {
705- "SetGraphConstMemoryBase does not support the slice scheduler currently",731+ "SetGraphConstMemoryBase does not support the JIT executor currently",
706- "UpdateGraphFeatureMemoryBase does not support the slice scheduler currently",732+ "UpdateGraphFeatureMemoryBase does not support the JIT executor currently",
707- "SetGraphFixedFeatureMemoryBaseWithType does not support the slice scheduler currently",733+ "SetGraphFixedFeatureMemoryBaseWithType does not support the JIT executor currently",
708- "UpdateGraphRefreshableFeatureMemoryBase does not support the slice scheduler currently"};734+ "UpdateGraphRefreshableFeatureMemoryBase does not support the JIT executor currently"};
709 for (auto &it : expect_log_list) {735 for (auto &it : expect_log_list) {
710 EXPECT_NE(gert_stub_.GetSlogStub().FindLog(-1, it.c_str()), -1);736 EXPECT_NE(gert_stub_.GetSlogStub().FindLog(-1, it.c_str()), -1);
711 }737 }
@@ -54,6 +54,7 @@
54#include "easy_graph/builder/graph_dsl.h"54#include "easy_graph/builder/graph_dsl.h"
55#include "ge_graph_dsl/graph_dsl.h"55#include "ge_graph_dsl/graph_dsl.h"
56#include "graph_metadef/depends/checker/tensor_check_utils.h"56#include "graph_metadef/depends/checker/tensor_check_utils.h"
57+#include "api/aclgrph/option_utils.h"
57using namespace std;58using namespace std;
58 59 
59static bool g_fail_nothrow_new = false;60static bool g_fail_nothrow_new = false;
@@ -82,7 +83,28 @@ __attribute__((no_sanitize("address"))) void *operator new[](std::size_t size, c
82 83 
83namespace ge {84namespace ge {
84using Json = nlohmann::json;85using Json = nlohmann::json;
86+ 
87+bool g_enable_auto_fuse_stub = false;
88+ 
89+bool EnableAutoFuse() {
90+ return g_enable_auto_fuse_stub && GetAutofuseFlagValue(kAutoFuseEnableOption) == "true";
91+}
92+ 
85namespace {93namespace {
94+class AutoFuseStubGuard {
95+ public:
96+ AutoFuseStubGuard() : old_value_(g_enable_auto_fuse_stub) {
97+ g_enable_auto_fuse_stub = true;
98+ }
99+ 
100+ ~AutoFuseStubGuard() {
101+ g_enable_auto_fuse_stub = old_value_;
102+ }
103+ 
104+ private:
105+ bool old_value_;
106+};
107+ 
86class EnvValueGuard {108class EnvValueGuard {
87 public:109 public:
88 explicit EnvValueGuard(const char *name) : name_(name) {110 explicit EnvValueGuard(const char *name) : name_(name) {
@@ -2537,6 +2559,7 @@ TEST_F(UtestGeApiV2, AreOptionsEqual_DifferentOptions) {
2537}2559}
2538 2560 
2539TEST_F(UtestGeApiV2, SliceSchedule_UnsupportedPaths) {2561TEST_F(UtestGeApiV2, SliceSchedule_UnsupportedPaths) {
2562+ AutoFuseStubGuard auto_fuse_stub_guard;
2540 EnvValueGuard guard("AUTOFUSE_FLAGS");2563 EnvValueGuard guard("AUTOFUSE_FLAGS");
2541 setenv("AUTOFUSE_FLAGS", "--enable_autofuse=true;--experimental_enable_jit_executor_v2=true", 1);2564 setenv("AUTOFUSE_FLAGS", "--enable_autofuse=true;--experimental_enable_jit_executor_v2=true", 1);
2542 2565