Merged
feat: 新增 --multi_stream_parallel_mode ATC 开关 #4184
feat: 新增 --multi_stream_parallel_mode ATC 开关 #4184
Merged
sunsummercqcAdd on Jul 29
Total: 11 files changed+309-89
@@ -194,6 +194,8 @@ const char *const kRawCompileOptionsGlobal = "global";
194const char *const kRawCompileOptionsSession = "session";194const char *const kRawCompileOptionsSession = "session";
195const char *const kRawCompileOptionsGraph = "graph";195const char *const kRawCompileOptionsGraph = "graph";
196const char *const kCliOptionPrefix = "--";196const char *const kCliOptionPrefix = "--";
197+const char *const kMultiStreamParallelModeFlag = "multi_stream_parallel_mode";
198+const char *const kMultiStreamParallelModeOption = "--multi_stream_parallel_mode";
197const std::set<std::string> kRawNonReplaceableCliOptions = {"model", "output", "framework", "soc_version"};199const std::set<std::string> kRawNonReplaceableCliOptions = {"model", "output", "framework", "soc_version"};
198 200 
199std::set<std::string> &GetRawAppliedFlagNames() {201std::set<std::string> &GetRawAppliedFlagNames() {
@@ -864,6 +866,19 @@ class GFlagUtils {
864 return SUCCESS;866 return SUCCESS;
865 }867 }
866 868 
869+ static Status CheckMultiStreamParallelModeConflict() {
870+ const auto &user_options = ge::flgs::GetUserOptions();
871+ const bool is_multi_stream_set = (user_options.count(kMultiStreamParallelModeFlag) > 0U) ||
872+ (GetRawAppliedFlagNames().count(kMultiStreamParallelModeFlag) > 0U);
873+ if (is_multi_stream_set && FLAGS_enable_single_stream == "true") {
874+ REPORT_PREDEFINED_ERR_MSG("E10056", std::vector<const char *>({"parameter1", "parameter2"}),
875+ std::vector<const char *>({kMultiStreamParallelModeOption, "--enable_single_stream"}));
876+ GELOGE(FAILED, "Cannot set both %s and --enable_single_stream.", kMultiStreamParallelModeOption);
877+ return FAILED;
878+ }
879+ return SUCCESS;
880+ }
881+ 
867 static Status CheckFlags() {882 static Status CheckFlags() {
868 const bool is_mode_om = ((FLAGS_mode == static_cast<int32_t>(RunMode::GEN_OM_MODEL)) ||883 const bool is_mode_om = ((FLAGS_mode == static_cast<int32_t>(RunMode::GEN_OM_MODEL)) ||
869 (FLAGS_mode == static_cast<int32_t>(RunMode::GEN_EXE_OM_FOR_NANO)) ||884 (FLAGS_mode == static_cast<int32_t>(RunMode::GEN_EXE_OM_FOR_NANO)) ||
@@ -980,6 +995,7 @@ class GFlagUtils {
980 995 
981 GE_CHK_BOOL_EXEC(CheckEnableSingleStreamParamValid(std::string(FLAGS_enable_single_stream)) == SUCCESS,996 GE_CHK_BOOL_EXEC(CheckEnableSingleStreamParamValid(std::string(FLAGS_enable_single_stream)) == SUCCESS,
982 return FAILED, "[Check][EnableSingleStream]failed!");997 return FAILED, "[Check][EnableSingleStream]failed!");
998+ GE_ASSERT_SUCCESS(CheckMultiStreamParallelModeConflict(), "[Check][MultiStreamParallelModeConflict]failed!");
983 999 
984 GE_CHK_BOOL_EXEC(CheckExternalWeightParamValid(std::string(FLAGS_external_weight)) == SUCCESS, return FAILED,1000 GE_CHK_BOOL_EXEC(CheckExternalWeightParamValid(std::string(FLAGS_external_weight)) == SUCCESS, return FAILED,
985 "[Check][ExternalWeight]failed!");1001 "[Check][ExternalWeight]failed!");
@@ -35,6 +35,7 @@ bool ExportCompileStatChecker(const std::string &opt_value, std::string &reason)
35 }35 }
36 return true;36 return true;
37}37}
38+ 
38} // namespace39} // namespace
39REG_OPTION(OO_CONSTANT_FOLDING)40REG_OPTION(OO_CONSTANT_FOLDING)
40 .LEVELS(OoLevel::kO1)41 .LEVELS(OoLevel::kO1)
@@ -82,4 +83,12 @@ REG_OPTION(OPTION_EXPORT_COMPILE_STAT)
82 .HELP(83 .HELP(
83 "The option of configuring statistics of the graph compiler, 0: Not Generate; 1: Generated when the program "84 "The option of configuring statistics of the graph compiler, 0: Not Generate; 1: Generated when the program "
84 "exits(default); 2: Generated when graph compilation complete.");85 "exits(default); 2: Generated when graph compilation complete.");
86+ 
87+REG_OPTION(OPTION_AUTO_MULTISTREAM_PARALLEL_MODE)
88+ .LEVELS(OoLevel::kO3)
89+ .DEFAULT_VALUES({{OoLevel::kO3, ""}})
90+ .VISIBILITY({OoEntryPoint::kSession, OoEntryPoint::kAtc})
91+ .SHOW_NAME(OoEntryPoint::kAtc, "multi_stream_parallel_mode", OoCategory::kModelTuning)
92+ .HELP(
93+ "Auto multi-stream parallel mode: \"\"(default, disabled), cv, LoadBalance:N, MainStream:N (N range [1,64]).");
85} // namespace ge94} // namespace ge
@@ -0,0 +1,70 @@
1+# --multi\_stream\_parallel\_mode
2+ 
3+## 产品支持情况
4+ 
5+<!-- npu="950" id6 -->
6+- Ascend 950PR/Ascend 950DT:支持
7+<!-- end id6 -->
8+<!-- npu="A3" id5 -->
9+- Atlas A3 训练系列产品/Atlas A3 推理系列产品:支持
10+<!-- end id5 -->
11+<!-- npu="910b" id4 -->
12+- Atlas A2 训练系列产品/Atlas A2 推理系列产品:支持
13+<!-- end id4 -->
14+<!-- npu="310b" id3 -->
15+- Atlas 200I/500 A2 推理产品:不支持
16+<!-- end id3 -->
17+<!-- npu="310p" id2 -->
18+- Atlas 推理系列产品:支持
19+<!-- end id2 -->
20+<!-- npu="910" id1 -->
21+- Atlas 训练系列产品:支持
22+<!-- end id1 -->
23+ 
24+<!-- npu="IPV350" id7 -->
25+- IPV350:不支持
26+<!-- end id7 -->
27+ 
28+## 功能说明
29+ 
30+**调试功能扩展参数,暂不支持应用于生产环境,后续版本会作为正式功能更新发布。**
31+ 
32+该参数适用于静态/动态shape图场景,开发者可通过配置此参数控制多流并行模式的自动分配策略,以提升图执行性能。
33+ 
34+其中,流(Stream)用于维护异步操作的执行顺序,同一条流内的任务严格按序执行,不同流之间的任务可以并行执行。开启自动多流并行后,GE在编译期将计算图转换为MiniDAG,结合节点依赖关系和设备资源执行分流策略,将无依赖的算子分配到不同流上并行执行,并将新的stream_id写回计算图。
35+ 
36+## 关联参数
37+ 
38+该参数与[--enable\_single\_stream](--enable_single_stream.md)互斥,不可同时设置。若同时设置,编译会报错并终止。
39+ 
40+动态shape场景下,需先通过环境变量ENABLE\_DYNAMIC\_SHAPE\_MULTI\_STREAM使能动态shape多流后,此参数才用于选择多流并行算法,不能单独开启动态shape多流。关于环境变量详细说明请参见[《环境变量参考》](https://hiascend.com/document/redirect/CannCommunityEnvRef)。
41+ 
42+## 参数取值
43+ 
44+**参数值:**
45+ 
46+- cv:开启Cube算子与Vector算子的并行执行功能。
47+- LoadBalance:N:负载均衡算法,将所有算子均匀分布在N条流上执行。N为最大流数量,正整数,取值范围\[1,64\]。若N取值超过了实际可用核数,性能可能会降低。
48+- MainStream:N:主流算法,串行算子分布在主流上执行,其他可并行算子分布在其他流上执行。N为最大流数量,正整数,取值范围\[1,64\]。若N取值超过了实际可用核数,性能可能会降低。
49+- 空字符串(默认值):不启用任何多流并行优化。
50+ 
51+**参数值约束:**
52+ 
53+- 该参数仅在O3优化级别下生效。
54+- N为最大流数量,取值范围为\[1,64\],超出范围会导致编译失败。
55+ 
56+## 推荐配置及收益
57+ 
58+无。
59+ 
60+## 示例
61+ 
62+```bash
63+atc --multi_stream_parallel_mode=LoadBalance:8 ...
64+```
65+ 
66+## 使用约束
67+ 
68+- 该参数仅限于推荐类型网络使用。
69+- 动态shape多流下使用此功能需要先通过ENABLE\_DYNAMIC\_SHAPE\_MULTI\_STREAM使能动态shape多流,再配置此参数。
70+- 该参数与[--enable\_single\_stream](--enable_single_stream.md)互斥。
@@ -57,6 +57,7 @@
57 - [--hccl\_sub\_comm\_config](--hccl_sub_comm_config.md)57 - [--hccl\_sub\_comm\_config](--hccl_sub_comm_config.md)
58 - [--h2d\_overlapped\_with\_compute](--h2d_overlapped_with_compute.md)58 - [--h2d\_overlapped\_with\_compute](--h2d_overlapped_with_compute.md)
59 - [--mdl\_bank\_path](--mdl_bank_path.md)59 - [--mdl\_bank\_path](--mdl_bank_path.md)
60+ - [--multi\_stream\_parallel\_mode](--multi_stream_parallel_mode.md)
60 - [--oo\_constant\_folding](--oo_constant_folding.md)61 - [--oo\_constant\_folding](--oo_constant_folding.md)
61 - [--oo\_dead\_code\_elimination](--oo_dead_code_elimination.md)62 - [--oo\_dead\_code\_elimination](--oo_dead_code_elimination.md)
62 - [--oo\_level](--oo_level.md)63 - [--oo\_level](--oo_level.md)
@@ -25,6 +25,7 @@
25#include <debug/ge_attr_define.h>25#include <debug/ge_attr_define.h>
26#include "graph/ge_local_context.h"26#include "graph/ge_local_context.h"
27#include "graph/ge_context.h"27#include "graph/ge_context.h"
28+#include "register/optimization_option_registry.h"
28#include "register/custom_pass_helper.h"29#include "register/custom_pass_helper.h"
29#include "register/custom_pass_context_impl.h"30#include "register/custom_pass_context_impl.h"
30#include "graph/build/stream/dag_adapter.h"31#include "graph/build/stream/dag_adapter.h"
@@ -35,6 +36,13 @@
35namespace ge {36namespace ge {
36 37 
37namespace {38namespace {
39+void SetGraphOptionForTest(const std::map<std::string, std::string> &options) {
40+ ge::GetThreadLocalContext().SetGraphOption(options);
41+ ASSERT_EQ(ge::GetThreadLocalContext().GetOo().Initialize(ge::GetThreadLocalContext().GetAllOptions(),
42+ ge::OptionRegistry::GetInstance().GetRegisteredOptTable()),
43+ ge::GRAPH_SUCCESS);
44+}
45+ 
38graphStatus CallFromGEGraph(const ConstGraphPtr &ge_graph, std::shared_ptr<minidag::DAGGraph> &dag) {46graphStatus CallFromGEGraph(const ConstGraphPtr &ge_graph, std::shared_ptr<minidag::DAGGraph> &dag) {
39 bool has_profiled_node_cost = false;47 bool has_profiled_node_cost = false;
40 return DAGAdapter::FromGEGraph(ge_graph, dag, has_profiled_node_cost);48 return DAGAdapter::FromGEGraph(ge_graph, dag, has_profiled_node_cost);
@@ -42,7 +50,7 @@ graphStatus CallFromGEGraph(const ConstGraphPtr &ge_graph, std::shared_ptr<minid
42 50 
43struct GraphOptionGuard {51struct GraphOptionGuard {
44 ~GraphOptionGuard() {52 ~GraphOptionGuard() {
45- ge::GetThreadLocalContext().SetGraphOption({});53+ SetGraphOptionForTest({});
46 }54 }
47};55};
48 56 
@@ -51,7 +59,7 @@ struct ProfilingPathGuard {
51 ~ProfilingPathGuard() {59 ~ProfilingPathGuard() {
52 unsetenv("MINIDAG_PROFILING_PATH");60 unsetenv("MINIDAG_PROFILING_PATH");
53 std::remove(path_);61 std::remove(path_);
54- ge::GetThreadLocalContext().SetGraphOption({});62+ SetGraphOptionForTest({});
55 }63 }
56 const char *path_;64 const char *path_;
57};65};
@@ -108,11 +116,11 @@ class MiniDAGStreamPassTest : public testing::Test {
108 }116 }
109 117 
110 void SetUp() override {118 void SetUp() override {
111- GetThreadLocalContext().SetGraphOption({});119+ SetGraphOptionForTest({});
112 }120 }
113 121 
114 void TearDown() override {122 void TearDown() override {
115- GetThreadLocalContext().SetGraphOption({});123+ SetGraphOptionForTest({});
116 }124 }
117};125};
118 126 
@@ -126,7 +134,7 @@ class MiniDAGStreamPassTest : public testing::Test {
126TEST_F(MiniDAGStreamPassTest, Enable_WithLoadBalanceMode) {134TEST_F(MiniDAGStreamPassTest, Enable_WithLoadBalanceMode) {
127 std::map<std::string, std::string> options;135 std::map<std::string, std::string> options;
128 options["ge.autoMultistreamParallelMode"] = "LoadBalance:8";136 options["ge.autoMultistreamParallelMode"] = "LoadBalance:8";
129- GetThreadLocalContext().SetGraphOption(options);137+ SetGraphOptionForTest(options);
130 138 
131 auto compute_graph = gert::ShareGraph::BuildTwoAddNodeKnownShapeGraph();139 auto compute_graph = gert::ShareGraph::BuildTwoAddNodeKnownShapeGraph();
132 ASSERT_NE(compute_graph, nullptr);140 ASSERT_NE(compute_graph, nullptr);
@@ -165,7 +173,7 @@ TEST_F(MiniDAGStreamPassTest, Enable_WithLoadBalanceMode) {
165TEST_F(MiniDAGStreamPassTest, Fail_WithOtherValue) {173TEST_F(MiniDAGStreamPassTest, Fail_WithOtherValue) {
166 std::map<std::string, std::string> options;174 std::map<std::string, std::string> options;
167 options["ge.autoMultistreamParallelMode"] = "other_value";175 options["ge.autoMultistreamParallelMode"] = "other_value";
168- GetThreadLocalContext().SetGraphOption(options);176+ SetGraphOptionForTest(options);
169 177 
170 auto compute_graph = gert::ShareGraph::BuildTwoAddNodeKnownShapeGraph();178 auto compute_graph = gert::ShareGraph::BuildTwoAddNodeKnownShapeGraph();
171 ASSERT_NE(compute_graph, nullptr);179 ASSERT_NE(compute_graph, nullptr);
@@ -210,7 +218,7 @@ TEST_F(MiniDAGStreamPassTest, Skip_WithoutOption) {
210TEST_F(MiniDAGStreamPassTest, EndToEnd_DAGNodeProperties) {218TEST_F(MiniDAGStreamPassTest, EndToEnd_DAGNodeProperties) {
211 std::map<std::string, std::string> options;219 std::map<std::string, std::string> options;
212 options["ge.autoMultistreamParallelMode"] = "LoadBalance:8";220 options["ge.autoMultistreamParallelMode"] = "LoadBalance:8";
213- GetThreadLocalContext().SetGraphOption(options);221+ SetGraphOptionForTest(options);
214 222 
215 auto compute_graph = gert::ShareGraph::BuildStaticAbsReluExpAddNodeGraph();223 auto compute_graph = gert::ShareGraph::BuildStaticAbsReluExpAddNodeGraph();
216 ASSERT_NE(compute_graph, nullptr);224 ASSERT_NE(compute_graph, nullptr);
@@ -244,7 +252,7 @@ TEST_F(MiniDAGStreamPassTest, EndToEnd_DAGNodeProperties) {
244TEST_F(MiniDAGStreamPassTest, EndToEnd_DAGEdgeProperties) {252TEST_F(MiniDAGStreamPassTest, EndToEnd_DAGEdgeProperties) {
245 std::map<std::string, std::string> options;253 std::map<std::string, std::string> options;
246 options["ge.autoMultistreamParallelMode"] = "LoadBalance:8";254 options["ge.autoMultistreamParallelMode"] = "LoadBalance:8";
247- GetThreadLocalContext().SetGraphOption(options);255+ SetGraphOptionForTest(options);
248 256 
249 auto compute_graph = gert::ShareGraph::BuildTwoAddNodeKnownShapeGraph();257 auto compute_graph = gert::ShareGraph::BuildTwoAddNodeKnownShapeGraph();
250 ASSERT_NE(compute_graph, nullptr);258 ASSERT_NE(compute_graph, nullptr);
@@ -276,7 +284,7 @@ TEST_F(MiniDAGStreamPassTest, EndToEnd_DAGEdgeProperties) {
276TEST_F(MiniDAGStreamPassTest, EndToEnd_DAGNodeEdgeRelations) {284TEST_F(MiniDAGStreamPassTest, EndToEnd_DAGNodeEdgeRelations) {
277 std::map<std::string, std::string> options;285 std::map<std::string, std::string> options;
278 options["ge.autoMultistreamParallelMode"] = "LoadBalance:8";286 options["ge.autoMultistreamParallelMode"] = "LoadBalance:8";
279- GetThreadLocalContext().SetGraphOption(options);287+ SetGraphOptionForTest(options);
280 288 
281 auto compute_graph = gert::ShareGraph::BuildStaticAbsReluExpAddNodeGraph();289 auto compute_graph = gert::ShareGraph::BuildStaticAbsReluExpAddNodeGraph();
282 ASSERT_NE(compute_graph, nullptr);290 ASSERT_NE(compute_graph, nullptr);
@@ -311,7 +319,7 @@ TEST_F(MiniDAGStreamPassTest, EndToEnd_DAGNodeEdgeRelations) {
311TEST_F(MiniDAGStreamPassTest, EndToEnd_DAGNodeCostProperties) {319TEST_F(MiniDAGStreamPassTest, EndToEnd_DAGNodeCostProperties) {
312 std::map<std::string, std::string> options;320 std::map<std::string, std::string> options;
313 options["ge.autoMultistreamParallelMode"] = "LoadBalance:8";321 options["ge.autoMultistreamParallelMode"] = "LoadBalance:8";
314- GetThreadLocalContext().SetGraphOption(options);322+ SetGraphOptionForTest(options);
315 323 
316 auto compute_graph = gert::ShareGraph::BuildTwoAddNodeKnownShapeGraph();324 auto compute_graph = gert::ShareGraph::BuildTwoAddNodeKnownShapeGraph();
317 ASSERT_NE(compute_graph, nullptr);325 ASSERT_NE(compute_graph, nullptr);
@@ -360,7 +368,7 @@ TEST_F(MiniDAGStreamPassTest, EndToEnd_DAGNodeCostProperties) {
360TEST_F(MiniDAGStreamPassTest, EndToEnd_CompleteGraphStructure) {368TEST_F(MiniDAGStreamPassTest, EndToEnd_CompleteGraphStructure) {
361 std::map<std::string, std::string> options;369 std::map<std::string, std::string> options;
362 options["ge.autoMultistreamParallelMode"] = "LoadBalance:8";370 options["ge.autoMultistreamParallelMode"] = "LoadBalance:8";
363- GetThreadLocalContext().SetGraphOption(options);371+ SetGraphOptionForTest(options);
364 372 
365 auto compute_graph = gert::ShareGraph::BuildStaticAbsReluExpAddNodeGraph();373 auto compute_graph = gert::ShareGraph::BuildStaticAbsReluExpAddNodeGraph();
366 ASSERT_NE(compute_graph, nullptr);374 ASSERT_NE(compute_graph, nullptr);
@@ -393,7 +401,7 @@ TEST_F(MiniDAGStreamPassTest, EndToEnd_CompleteGraphStructure) {
393TEST_F(MiniDAGStreamPassTest, EndToEnd_RefreshStreamIdsToGE) {401TEST_F(MiniDAGStreamPassTest, EndToEnd_RefreshStreamIdsToGE) {
394 std::map<std::string, std::string> options;402 std::map<std::string, std::string> options;
395 options["ge.autoMultistreamParallelMode"] = "LoadBalance:8";403 options["ge.autoMultistreamParallelMode"] = "LoadBalance:8";
396- GetThreadLocalContext().SetGraphOption(options);404+ SetGraphOptionForTest(options);
397 405 
398 auto compute_graph = gert::ShareGraph::BuildTwoAddNodeKnownShapeGraph();406 auto compute_graph = gert::ShareGraph::BuildTwoAddNodeKnownShapeGraph();
399 ASSERT_NE(compute_graph, nullptr);407 ASSERT_NE(compute_graph, nullptr);
@@ -424,7 +432,7 @@ TEST_F(MiniDAGStreamPassTest, EndToEnd_RefreshStreamIdsToGE) {
424TEST_F(MiniDAGStreamPassTest, DirectCall_Success) {432TEST_F(MiniDAGStreamPassTest, DirectCall_Success) {
425 std::map<std::string, std::string> options;433 std::map<std::string, std::string> options;
426 options["ge.autoMultistreamParallelMode"] = "LoadBalance:8";434 options["ge.autoMultistreamParallelMode"] = "LoadBalance:8";
427- GetThreadLocalContext().SetGraphOption(options);435+ SetGraphOptionForTest(options);
428 436 
429 auto compute_graph = gert::ShareGraph::BuildTwoAddNodeKnownShapeGraph();437 auto compute_graph = gert::ShareGraph::BuildTwoAddNodeKnownShapeGraph();
430 ASSERT_NE(compute_graph, nullptr);438 ASSERT_NE(compute_graph, nullptr);
@@ -452,7 +460,7 @@ TEST_F(MiniDAGStreamPassTest, DirectCall_NullGraph) {
452TEST_F(MiniDAGStreamPassTest, DirectCall_WithStreamContext) {460TEST_F(MiniDAGStreamPassTest, DirectCall_WithStreamContext) {
453 std::map<std::string, std::string> options;461 std::map<std::string, std::string> options;
454 options["ge.autoMultistreamParallelMode"] = "LoadBalance:8";462 options["ge.autoMultistreamParallelMode"] = "LoadBalance:8";
455- GetThreadLocalContext().SetGraphOption(options);463+ SetGraphOptionForTest(options);
456 464 
457 auto compute_graph = gert::ShareGraph::BuildStaticAbsReluExpAddNodeGraph();465 auto compute_graph = gert::ShareGraph::BuildStaticAbsReluExpAddNodeGraph();
458 ASSERT_NE(compute_graph, nullptr);466 ASSERT_NE(compute_graph, nullptr);
@@ -474,7 +482,7 @@ TEST_F(MiniDAGStreamPassTest, DirectCall_WithStreamContext) {
474TEST_F(MiniDAGStreamPassTest, DirectCall_DataNetOutputOnly) {482TEST_F(MiniDAGStreamPassTest, DirectCall_DataNetOutputOnly) {
475 std::map<std::string, std::string> options;483 std::map<std::string, std::string> options;
476 options["ge.autoMultistreamParallelMode"] = "LoadBalance:8";484 options["ge.autoMultistreamParallelMode"] = "LoadBalance:8";
477- GetThreadLocalContext().SetGraphOption(options);485+ SetGraphOptionForTest(options);
478 486 
479 auto graph = std::make_shared<ge::Graph>("data_netoutput_only");487 auto graph = std::make_shared<ge::Graph>("data_netoutput_only");
480 ge::Operator data1_op("data1", "Data");488 ge::Operator data1_op("data1", "Data");
@@ -497,7 +505,7 @@ TEST_F(MiniDAGStreamPassTest, DirectCall_DataNetOutputOnly) {
497TEST_F(MiniDAGStreamPassTest, Adapter_ControlEdgeConversion) {505TEST_F(MiniDAGStreamPassTest, Adapter_ControlEdgeConversion) {
498 std::map<std::string, std::string> options;506 std::map<std::string, std::string> options;
499 options["ge.autoMultistreamParallelMode"] = "LoadBalance:8";507 options["ge.autoMultistreamParallelMode"] = "LoadBalance:8";
500- GetThreadLocalContext().SetGraphOption(options);508+ SetGraphOptionForTest(options);
501 509 
502 auto graph = std::make_shared<ge::Graph>("control_edge_test");510 auto graph = std::make_shared<ge::Graph>("control_edge_test");
503 ge::Operator data1_op("data1", "Data");511 ge::Operator data1_op("data1", "Data");
@@ -534,7 +542,7 @@ TEST_F(MiniDAGStreamPassTest, Adapter_ControlEdgeConversion) {
534TEST_F(MiniDAGStreamPassTest, Adapter_ControlEdgeNodeRelation) {542TEST_F(MiniDAGStreamPassTest, Adapter_ControlEdgeNodeRelation) {
535 std::map<std::string, std::string> options;543 std::map<std::string, std::string> options;
536 options["ge.autoMultistreamParallelMode"] = "LoadBalance:8";544 options["ge.autoMultistreamParallelMode"] = "LoadBalance:8";
537- GetThreadLocalContext().SetGraphOption(options);545+ SetGraphOptionForTest(options);
538 546 
539 auto graph = std::make_shared<ge::Graph>("control_edge_relation");547 auto graph = std::make_shared<ge::Graph>("control_edge_relation");
540 ge::Operator data1_op("data1", "Data");548 ge::Operator data1_op("data1", "Data");
@@ -576,7 +584,7 @@ TEST_F(MiniDAGStreamPassTest, Adapter_ControlEdgeNodeRelation) {
576TEST_F(MiniDAGStreamPassTest, RunPass_InvalidEmptyAlgoName) {584TEST_F(MiniDAGStreamPassTest, RunPass_InvalidEmptyAlgoName) {
577 std::map<std::string, std::string> options;585 std::map<std::string, std::string> options;
578 options["ge.autoMultistreamParallelMode"] = ":812";586 options["ge.autoMultistreamParallelMode"] = ":812";
579- ge::GetThreadLocalContext().SetGraphOption(options);587+ SetGraphOptionForTest(options);
580 588 
581 auto compute_graph = gert::ShareGraph::BuildStaticAbsReluExpAddNodeGraph();589 auto compute_graph = gert::ShareGraph::BuildStaticAbsReluExpAddNodeGraph();
582 ASSERT_NE(compute_graph, nullptr);590 ASSERT_NE(compute_graph, nullptr);
@@ -588,7 +596,7 @@ TEST_F(MiniDAGStreamPassTest, RunPass_InvalidEmptyAlgoName) {
588 auto ret = RunMiniDAGStreamPass(graph, context);596 auto ret = RunMiniDAGStreamPass(graph, context);
589 EXPECT_EQ(ret, ge::FAILED);597 EXPECT_EQ(ret, ge::FAILED);
590 598 
591- ge::GetThreadLocalContext().SetGraphOption({});599+ SetGraphOptionForTest({});
592}600}
593 601 
594/**602/**
@@ -597,7 +605,7 @@ TEST_F(MiniDAGStreamPassTest, RunPass_InvalidEmptyAlgoName) {
597TEST_F(MiniDAGStreamPassTest, RunPass_InvalidUnknownAlgoName) {605TEST_F(MiniDAGStreamPassTest, RunPass_InvalidUnknownAlgoName) {
598 std::map<std::string, std::string> options;606 std::map<std::string, std::string> options;
599 options["ge.autoMultistreamParallelMode"] = "UnknownAlgoABC:8";607 options["ge.autoMultistreamParallelMode"] = "UnknownAlgoABC:8";
600- ge::GetThreadLocalContext().SetGraphOption(options);608+ SetGraphOptionForTest(options);
601 609 
602 auto compute_graph = gert::ShareGraph::BuildStaticAbsReluExpAddNodeGraph();610 auto compute_graph = gert::ShareGraph::BuildStaticAbsReluExpAddNodeGraph();
603 ASSERT_NE(compute_graph, nullptr);611 ASSERT_NE(compute_graph, nullptr);
@@ -609,7 +617,7 @@ TEST_F(MiniDAGStreamPassTest, RunPass_InvalidUnknownAlgoName) {
609 auto ret = RunMiniDAGStreamPass(graph, context);617 auto ret = RunMiniDAGStreamPass(graph, context);
610 EXPECT_EQ(ret, ge::FAILED);618 EXPECT_EQ(ret, ge::FAILED);
611 619 
612- ge::GetThreadLocalContext().SetGraphOption({});620+ SetGraphOptionForTest({});
613}621}
614 622 
615/**623/**
@@ -623,7 +631,7 @@ TEST_F(MiniDAGStreamPassTest, RunPass_ProfileHitUsesWeightedLoadBalance) {
623 631 
624 std::map<std::string, std::string> options;632 std::map<std::string, std::string> options;
625 options["ge.autoMultistreamParallelMode"] = "LoadBalance:8";633 options["ge.autoMultistreamParallelMode"] = "LoadBalance:8";
626- ge::GetThreadLocalContext().SetGraphOption(options);634+ SetGraphOptionForTest(options);
627 635 
628 auto compute_graph = gert::ShareGraph::BuildTwoAddNodeKnownShapeGraph();636 auto compute_graph = gert::ShareGraph::BuildTwoAddNodeKnownShapeGraph();
629 ASSERT_NE(compute_graph, nullptr);637 ASSERT_NE(compute_graph, nullptr);
@@ -649,7 +657,7 @@ TEST_F(MiniDAGStreamPassTest, RunPass_WithWeightedLoadBalanceMode) {
649 GraphOptionGuard guard;657 GraphOptionGuard guard;
650 std::map<std::string, std::string> options;658 std::map<std::string, std::string> options;
651 options["ge.autoMultistreamParallelMode"] = "WeightedLoadBalance:8";659 options["ge.autoMultistreamParallelMode"] = "WeightedLoadBalance:8";
652- ge::GetThreadLocalContext().SetGraphOption(options);660+ SetGraphOptionForTest(options);
653 661 
654 auto compute_graph = gert::ShareGraph::BuildTwoAddNodeKnownShapeGraph();662 auto compute_graph = gert::ShareGraph::BuildTwoAddNodeKnownShapeGraph();
655 ASSERT_NE(compute_graph, nullptr);663 ASSERT_NE(compute_graph, nullptr);
@@ -670,7 +678,7 @@ TEST_F(MiniDAGStreamPassTest, RunPass_WithWeightedLoadBalanceModeOnComplexGraph)
670 GraphOptionGuard guard;678 GraphOptionGuard guard;
671 std::map<std::string, std::string> options;679 std::map<std::string, std::string> options;
672 options["ge.autoMultistreamParallelMode"] = "WeightedLoadBalance:4";680 options["ge.autoMultistreamParallelMode"] = "WeightedLoadBalance:4";
673- ge::GetThreadLocalContext().SetGraphOption(options);681+ SetGraphOptionForTest(options);
674 682 
675 auto compute_graph = gert::ShareGraph::BuildStaticAbsReluExpAddNodeGraph();683 auto compute_graph = gert::ShareGraph::BuildStaticAbsReluExpAddNodeGraph();
676 ASSERT_NE(compute_graph, nullptr);684 ASSERT_NE(compute_graph, nullptr);
@@ -695,7 +703,7 @@ TEST_F(MiniDAGStreamPassTest, RunPass_ProfileMultiNodeHitUsesWeightedLoadBalance
695 703 
696 std::map<std::string, std::string> options;704 std::map<std::string, std::string> options;
697 options["ge.autoMultistreamParallelMode"] = "LoadBalance:4";705 options["ge.autoMultistreamParallelMode"] = "LoadBalance:4";
698- ge::GetThreadLocalContext().SetGraphOption(options);706+ SetGraphOptionForTest(options);
699 707 
700 auto compute_graph = gert::ShareGraph::BuildStaticAbsReluExpAddNodeGraph();708 auto compute_graph = gert::ShareGraph::BuildStaticAbsReluExpAddNodeGraph();
701 ASSERT_NE(compute_graph, nullptr);709 ASSERT_NE(compute_graph, nullptr);
@@ -2797,6 +2797,30 @@ TEST_F(AtcCommonSTest, GeFlags_raw_ge_options_unsupported_failed) {
2797 ReInitGe();2797 ReInitGe();
2798}2798}
2799 2799 
2800+TEST_F(AtcCommonSTest, GeFlags_raw_multi_stream_parallel_mode_conflicts_with_enable_single_stream) {
2801+ const auto raw_path = WriteRawOptionsJson("raw_ge_options_multi_stream_parallel_mode.json", R"({
2802+ "compile options": {
2803+ "graph": {
2804+ "ge.autoMultistreamParallelMode": "LoadBalance:8"
2805+ }
2806+ }
2807+ })");
2808+ testing::internal::CaptureStdout();
2809+ testing::internal::CaptureStderr();
2810+ const int32_t ret =
2811+ RunAtcWithRawOptions("raw_ge_options_multi_stream_parallel_mode", raw_path, {"--enable_single_stream=true"});
2812+ const auto output = testing::internal::GetCapturedStdout() + testing::internal::GetCapturedStderr();
2813+ EXPECT_NE(ret, 0);
2814+ EXPECT_NE(output.find("Cannot configure both parameters --multi_stream_parallel_mode and --enable_single_stream "
2815+ "simultaneously."),
2816+ std::string::npos)
2817+ << output;
2818+ EXPECT_NE(output.find("--multi_stream_parallel_mode"), std::string::npos) << output;
2819+ EXPECT_NE(output.find("--enable_single_stream"), std::string::npos) << output;
2820+ (void)remove(raw_path.c_str());
2821+ ReInitGe();
2822+}
2823+ 
2800TEST_F(AtcCommonSTest, GeFlags_raw_ge_options_without_compile_options_failed) {2824TEST_F(AtcCommonSTest, GeFlags_raw_ge_options_without_compile_options_failed) {
2801 const auto raw_path = WriteRawOptionsJson("raw_ge_options_without_compile_options.json", R"({2825 const auto raw_path = WriteRawOptionsJson("raw_ge_options_without_compile_options.json", R"({
2802 "execute options": {2826 "execute options": {
@@ -24,16 +24,33 @@
24#include "register/custom_pass_context_impl.h"24#include "register/custom_pass_context_impl.h"
25#include "graph/ge_context.h"25#include "graph/ge_context.h"
26#include "graph/ge_local_context.h"26#include "graph/ge_local_context.h"
27+#include "register/optimization_option_registry.h"
27 28 
28namespace minidag {29namespace minidag {
29 30 
30namespace {31namespace {
32+void SetGraphOptionForTest(const std::map<std::string, std::string> &options) {
33+ ge::GetThreadLocalContext().SetGraphOption(options);
34+ ASSERT_EQ(ge::GetThreadLocalContext().GetOo().Initialize(ge::GetThreadLocalContext().GetAllOptions(),
35+ ge::OptionRegistry::GetInstance().GetRegisteredOptTable()),
36+ ge::GRAPH_SUCCESS);
37+}
38+ 
31struct GraphOptionGuard {39struct GraphOptionGuard {
32 ~GraphOptionGuard() {40 ~GraphOptionGuard() {
33- ge::GetThreadLocalContext().SetGraphOption({});41+ SetGraphOptionForTest({});
34 }42 }
35};43};
36 44 
45+ge::Status RunMiniDAGStreamPassForTest(const ge::ConstGraphPtr &graph, ge::StreamPassContext &context) {
46+ const auto ret = ge::GetThreadLocalContext().GetOo().Initialize(
47+ ge::GetThreadLocalContext().GetAllOptions(), ge::OptionRegistry::GetInstance().GetRegisteredOptTable());
48+ if (ret != ge::GRAPH_SUCCESS) {
49+ return ret;
50+ }
51+ return ge::RunMiniDAGStreamPass(graph, context);
52+}
53+ 
37class ProfilingFileGuard {54class ProfilingFileGuard {
38 public:55 public:
39 ProfilingFileGuard() = default;56 ProfilingFileGuard() = default;
@@ -26,6 +26,7 @@
26#include "graph/utils/graph_utils.h"26#include "graph/utils/graph_utils.h"
27#include "api/gelib/gelib.h"27#include "api/gelib/gelib.h"
28#include "depends/mmpa/src/mmpa_stub.h"28#include "depends/mmpa/src/mmpa_stub.h"
29+#include "register/optimization_option_registry.h"
29 30 
30namespace ge {31namespace ge {
31class MockMmpaForGeInit : public MmpaStubApiGe {32class MockMmpaForGeInit : public MmpaStubApiGe {
@@ -44,6 +45,8 @@ class UtestDynamicStreamAllocator : public testing::Test {
44 }45 }
45 46 
46 void TearDown() {47 void TearDown() {
48+ GetThreadLocalContext().SetGraphOption({});
49+ RefreshOptimizationOptions();
47 FinalizeGeLib();50 FinalizeGeLib();
48 }51 }
49 52 
@@ -292,12 +295,20 @@ class UtestDynamicStreamAllocator : public testing::Test {
292 std::map<std::string, std::string> options;295 std::map<std::string, std::string> options;
293 options["ge.autoMultistreamParallelMode"] = mode;296 options["ge.autoMultistreamParallelMode"] = mode;
294 GetThreadLocalContext().SetGraphOption(options);297 GetThreadLocalContext().SetGraphOption(options);
298+ RefreshOptimizationOptions();
295 }299 }
296 300 
297 void ClearAutoMultistreamMode() {301 void ClearAutoMultistreamMode() {
298 std::map<std::string, std::string> options;302 std::map<std::string, std::string> options;
299 options["ge.autoMultistreamParallelMode"] = "";303 options["ge.autoMultistreamParallelMode"] = "";
300 GetThreadLocalContext().SetGraphOption(options);304 GetThreadLocalContext().SetGraphOption(options);
305+ RefreshOptimizationOptions();
306+ }
307+ 
308+ void RefreshOptimizationOptions() {
309+ ASSERT_EQ(GetThreadLocalContext().GetOo().Initialize(GetThreadLocalContext().GetAllOptions(),
310+ OptionRegistry::GetInstance().GetRegisteredOptTable()),
311+ GRAPH_SUCCESS);
301 }312 }
302 313 
303 Graph2SubGraphInfoList CreateSubgraphMap(const ComputeGraphPtr &graph,314 Graph2SubGraphInfoList CreateSubgraphMap(const ComputeGraphPtr &graph,
@@ -2015,6 +2015,9 @@ TEST(UtestIrBuild, bundle_save_flow_model_invalid_buffer) {
2015}2015}
2016 2016 
2017TEST(UtestIrBuild, ir_build_oo_init) {2017TEST(UtestIrBuild, ir_build_oo_init) {
2018+ const auto global_options_backup = GetMutableGlobalOptions();
2019+ GE_MAKE_GUARD(restore_global_options,
2020+ [global_options_backup]() { GetMutableGlobalOptions() = global_options_backup; });
2018 const auto opp_path = ConstructOppEnv();2021 const auto opp_path = ConstructOppEnv();
2019 Graph graph_1 = BuildIrGraph1();2022 Graph graph_1 = BuildIrGraph1();
2020 ModelBufferData model_1;2023 ModelBufferData model_1;
@@ -341,4 +341,30 @@ TEST_F(AtcRawOptionsUTest, MergeRawGeOptionsSkipsCliHandledAndExplicitOptions) {
341 MergeRawGeOptions({{kRawUtCheckerOption, "raw"}}, options);341 MergeRawGeOptions({{kRawUtCheckerOption, "raw"}}, options);
342 EXPECT_EQ(options[kRawUtCheckerOption], "raw");342 EXPECT_EQ(options[kRawUtCheckerOption], "raw");
343}343}
344+ 
345+TEST_F(AtcRawOptionsUTest, MultiStreamParallelModeRegistered) {
346+ const auto *info = OptionRegistry::GetInstance().FindOptInfo("ge.autoMultistreamParallelMode");
347+ ASSERT_NE(info, nullptr) << "ge.autoMultistreamParallelMode should be registered in OptionRegistry";
348+ EXPECT_TRUE(OoInfoUtils::IsBitSet(info->visibility, static_cast<uint32_t>(OoEntryPoint::kAtc)))
349+ << "autoMultistreamParallelMode should be visible in ATC entry point";
350+ EXPECT_TRUE(OoInfoUtils::IsBitSet(info->levels, static_cast<uint32_t>(OoLevel::kO3)))
351+ << "autoMultistreamParallelMode should belong to O3 level";
352+ EXPECT_EQ(info->default_values.count(OoLevel::kO3), 1U);
353+ EXPECT_EQ(info->default_values.at(OoLevel::kO3), "");
354+}
355+ 
356+TEST_F(AtcRawOptionsUTest, MultiStreamParallelModeConflictDetectionPattern) {
357+ flgs::GetUserOptions()["multi_stream_parallel_mode"] = "LoadBalance:8";
358+ GetRawAppliedFlagNames().insert("multi_stream_parallel_mode");
359+ const auto &user_opts = flgs::GetUserOptions();
360+ const bool is_set_by_cli = (user_opts.count("multi_stream_parallel_mode") > 0U);
361+ const bool is_set_by_raw = (GetRawAppliedFlagNames().count("multi_stream_parallel_mode") > 0U);
362+ EXPECT_TRUE(is_set_by_cli) << "GetUserOptions() should contain multi_stream_parallel_mode after setting";
363+ EXPECT_TRUE(is_set_by_raw) << "GetRawAppliedFlagNames() should contain multi_stream_parallel_mode after setting";
364+ 
365+ flgs::GetUserOptions().clear();
366+ GetRawAppliedFlagNames().clear();
367+ EXPECT_EQ(flgs::GetUserOptions().count("multi_stream_parallel_mode"), 0U);
368+ EXPECT_EQ(GetRawAppliedFlagNames().count("multi_stream_parallel_mode"), 0U);
369+}
344} // namespace ge370} // namespace ge
@@ -191,6 +191,33 @@ static std::string ConstructOppEnv() {
191}191}
192} // namespace192} // namespace
193 193 
194+TEST_F(UtestMain, MainImplTest_multi_stream_parallel_mode_conflicts_with_enable_single_stream) {
195+ std::string model_arg = AtcFileFactory::Generatefile1("--model=", "add.pb");
196+ std::string output_arg = AtcFileFactory::Generatefile1("--output=", "tmp");
197+ char *argv[] = {"atc",
198+ "--mode=0",
199+ "--framework=3",
200+ const_cast<char *>(model_arg.c_str()),
201+ const_cast<char *>(output_arg.c_str()),
202+ "--soc_version=Ascend310",
203+ "--input_format=NCHW",
204+ "--cal_conf=",
205+ "--multi_stream_parallel_mode=LoadBalance:8",
206+ "--enable_single_stream=true"};
207+ testing::internal::CaptureStdout();
208+ testing::internal::CaptureStderr();
209+ const int32_t ret = main_impl(sizeof(argv) / sizeof(argv[0]), argv);
210+ const auto output = testing::internal::GetCapturedStdout() + testing::internal::GetCapturedStderr();
211+ EXPECT_NE(ret, 0);
212+ EXPECT_NE(output.find("Cannot configure both parameters --multi_stream_parallel_mode and --enable_single_stream "
213+ "simultaneously."),
214+ std::string::npos)
215+ << output;
216+ EXPECT_NE(output.find("--multi_stream_parallel_mode"), std::string::npos) << output;
217+ EXPECT_NE(output.find("--enable_single_stream"), std::string::npos) << output;
218+ AtcFileFactory::RemoveFile(AtcFileFactory::Generatefile1("", "tmp.om").c_str());
219+}
220+ 
194TEST_F(UtestMain, MainImplTest_socversion_and_mode_fail01) {221TEST_F(UtestMain, MainImplTest_socversion_and_mode_fail01) {
195 std::string om_arg = AtcFileFactory::Generatefile1("--model=", "add.pb");222 std::string om_arg = AtcFileFactory::Generatefile1("--model=", "add.pb");
196 std::string output_arg = AtcFileFactory::Generatefile1("--output=", "tmp");223 std::string output_arg = AtcFileFactory::Generatefile1("--output=", "tmp");