已合并
【PR】feat: sync develop to master 20260708 #1235
zhanj创建于 7月8日
【PR】feat: sync develop to master 20260708 #1235
已合并
zhanj创建于 7月8日
develop合入到master
19 个文件变更+182-39
@@ -33,6 +33,7 @@ std::unique_ptr<AutofuseBackendSpec> GetAutofuseBackendSpec() {
33 spec->max_input_nums_after_fuse = backend_spec->max_input_nums_after_fuse;33 spec->max_input_nums_after_fuse = backend_spec->max_input_nums_after_fuse;
34 spec->transpose_mode = backend_spec->transpose_mode;34 spec->transpose_mode = backend_spec->transpose_mode;
35 spec->enable_matmul_lowering_to_matmul = backend_spec->enable_matmul_lowering_to_matmul;35 spec->enable_matmul_lowering_to_matmul = backend_spec->enable_matmul_lowering_to_matmul;
36+ spec->is_default_enabled = backend_spec->is_default_enabled;
36 return spec;37 return spec;
37}38}
38} // namespace ge39} // namespace ge
@@ -43,6 +43,7 @@ struct AutofuseBackendSpec {
43 uint32_t max_input_nums_after_fuse = 8U;43 uint32_t max_input_nums_after_fuse = 8U;
44 uint32_t transpose_mode = static_cast<uint32_t>(AutofuseTransposeMode::TRANSPOSE_MODE_NORMAL);44 uint32_t transpose_mode = static_cast<uint32_t>(AutofuseTransposeMode::TRANSPOSE_MODE_NORMAL);
45 bool enable_matmul_lowering_to_matmul = false;45 bool enable_matmul_lowering_to_matmul = false;
46+ bool is_default_enabled = false;
46};47};
47 48 
48std::unique_ptr<AutofuseBackendSpec> GetAutofuseBackendSpec();49std::unique_ptr<AutofuseBackendSpec> GetAutofuseBackendSpec();
@@ -52,6 +52,7 @@ struct BackendSpec {
52 uint32_t max_group_num_per_compile_unit = 5;52 uint32_t max_group_num_per_compile_unit = 5;
53 PgoSpec pgo_spec;53 PgoSpec pgo_spec;
54 bool enable_matmul_lowering_to_matmul; // 限制A2A3 不能lowering出matmul,不限制matmul lowering成别的ascir类型54 bool enable_matmul_lowering_to_matmul; // 限制A2A3 不能lowering出matmul,不限制matmul lowering成别的ascir类型
55+ bool is_default_enabled;
55};56};
56} // namespace optimize57} // namespace optimize
57 58 
@@ -14,7 +14,9 @@
14namespace optimize {14namespace optimize {
15std::unique_ptr<BackendSpec> BackendSpec::GetInstance() {15std::unique_ptr<BackendSpec> BackendSpec::GetInstance() {
16 const auto platform = PlatformFactory::GetInstance().GetPlatform();16 const auto platform = PlatformFactory::GetInstance().GetPlatform();
17- GE_ASSERT_NOTNULL(platform);17+ if (platform == nullptr) {
18+ return nullptr;
19+ }
18 return platform->GetBackendSpec();20 return platform->GetBackendSpec();
19}21}
20} // namespace optimize22} // namespace optimize
@@ -22,6 +22,7 @@ namespace optimize {
22struct PlatformConfig {22struct PlatformConfig {
23 size_t max_que_num = 4U;23 size_t max_que_num = 4U;
24 bool is_support_compat_mode = false;24 bool is_support_compat_mode = false;
25+ bool is_default_enabled = false;
25};26};
26 27 
27class BasePlatform {28class BasePlatform {
@@ -39,12 +40,17 @@ class BasePlatform {
39 // 获取平台相关规格40 // 获取平台相关规格
40 virtual std::unique_ptr<BackendSpec> GetBackendSpec() const = 0;41 virtual std::unique_ptr<BackendSpec> GetBackendSpec() const = 0;
41 42 
42- virtual const PlatformConfig &GetPlatformConfig() const = 0;43+ const PlatformConfig &GetPlatformConfig() const {
44+ return config_;
45+ }
43 46 
44 virtual Status GenerateTasks(::ascir::ImplGraph &optimize_graph, const OptimizerOptions &options,47 virtual Status GenerateTasks(::ascir::ImplGraph &optimize_graph, const OptimizerOptions &options,
45 std::vector<ScheduleTask> &tasks) const = 0;48 std::vector<ScheduleTask> &tasks) const = 0;
46 49 
47 virtual std::set<std::string> BroadcastTypes() const = 0;50 virtual std::set<std::string> BroadcastTypes() const = 0;
51+ 
52+ protected:
53+ PlatformConfig config_;
48};54};
49} // namespace optimize55} // namespace optimize
50#endif // OPTIMIZE_PLATFORM_BASE_PLATFORM_H56#endif // OPTIMIZE_PLATFORM_BASE_PLATFORM_H
@@ -37,7 +37,7 @@ BasePlatform *PlatformFactory::GetPlatform() {
37 return platform_name_to_instances_[platform_name].get();37 return platform_name_to_instances_[platform_name].get();
38 }38 }
39 39 
40- GELOGE(af::FAILED, "Can't find platform %s", platform_name.c_str());40+ GELOGW("Can't find platform %s", platform_name.c_str());
41 return nullptr;41 return nullptr;
42}42}
43 43 
@@ -13,11 +13,12 @@
13 13 
14#include <string>14#include <string>
15#include <memory>15#include <memory>
16+#include <functional>
16#include <unordered_map>17#include <unordered_map>
17#include "base_platform.h"18#include "base_platform.h"
18 19 
19namespace optimize {20namespace optimize {
20-using PlatformCreator = std::unique_ptr<BasePlatform> (*)();21+using PlatformCreator = std::function<std::unique_ptr<BasePlatform>()>;
21 22 
22class PlatformFactory {23class PlatformFactory {
23 public:24 public:
@@ -39,13 +40,14 @@ class PlatformFactory {
39template <typename T>40template <typename T>
40class PlatformRegistrar {41class PlatformRegistrar {
41 public:42 public:
42- explicit PlatformRegistrar(const std::string &platform_name);43+ PlatformRegistrar(const std::string &platform_name, bool is_default_enabled);
43};44};
44 45 
45template <typename T>46template <typename T>
46-PlatformRegistrar<T>::PlatformRegistrar(const std::string &platform_name) {47+PlatformRegistrar<T>::PlatformRegistrar(const std::string &platform_name, bool is_default_enabled) {
47 PlatformFactory::GetInstance().RegisterPlatform(48 PlatformFactory::GetInstance().RegisterPlatform(
48- platform_name, []() -> std::unique_ptr<BasePlatform> { return std::make_unique<T>(); });49+ platform_name,
50+ [is_default_enabled]() -> std::unique_ptr<BasePlatform> { return std::make_unique<T>(is_default_enabled); });
49}51}
50} // namespace optimize52} // namespace optimize
51 53 
@@ -22,8 +22,9 @@
22namespace optimize {22namespace optimize {
23constexpr size_t kMaxVecQueNum = 4UL;23constexpr size_t kMaxVecQueNum = 4UL;
24 24 
25-PlatformV1::PlatformV1() {25+PlatformV1::PlatformV1(bool is_default_enabled) {
26 config_.max_que_num = kMaxVecQueNum;26 config_.max_que_num = kMaxVecQueNum;
27+ config_.is_default_enabled = is_default_enabled;
27}28}
28 29 
29af::Status PlatformV1::PartitionSubFunctions([[maybe_unused]] af::AscGraph &impl_graph) {30af::Status PlatformV1::PartitionSubFunctions([[maybe_unused]] af::AscGraph &impl_graph) {
@@ -66,13 +67,10 @@ std::unique_ptr<BackendSpec> PlatformV1::GetBackendSpec() const {
66 ret->transpose_mode = static_cast<uint32_t>(TransposeMode::TRANSPOSE_MODE_NORMAL);67 ret->transpose_mode = static_cast<uint32_t>(TransposeMode::TRANSPOSE_MODE_NORMAL);
67 ret->set_local_memory_size = 0;68 ret->set_local_memory_size = 0;
68 ret->pgo_spec = {true};69 ret->pgo_spec = {true};
70+ ret->is_default_enabled = config_.is_default_enabled;
69 return ret;71 return ret;
70}72}
71 73 
72-const PlatformConfig &PlatformV1::GetPlatformConfig() const {
73- return config_;
74-}
75- 
76Status PlatformV1::GenerateTasks(ascir::ImplGraph &optimize_graph, const OptimizerOptions &options,74Status PlatformV1::GenerateTasks(ascir::ImplGraph &optimize_graph, const OptimizerOptions &options,
77 std::vector<ScheduleTask> &tasks) const {75 std::vector<ScheduleTask> &tasks) const {
78 GE_CHK_STATUS_RET(SplitFusionCaseGenerator().GeneratorTask(optimize_graph, tasks, options),76 GE_CHK_STATUS_RET(SplitFusionCaseGenerator().GeneratorTask(optimize_graph, tasks, options),
@@ -94,8 +92,8 @@ std::set<std::string> PlatformV1::BroadcastTypes() const {
94 return {af::ascir_op::Broadcast::Type};92 return {af::ascir_op::Broadcast::Type};
95}93}
96 94 
97-#define REGISTER_PLATFORM_V1(platform_name, suffix) \95+#define REGISTER_PLATFORM_V1(platform_name, suffix, is_default_enabled) \
98- static PlatformRegistrar<PlatformV1> registrar_##suffix(platform_name)96+ static PlatformRegistrar<PlatformV1> registrar_##suffix(platform_name, is_default_enabled)
99 97 
100-REGISTER_PLATFORM_V1("2201", v1);98+REGISTER_PLATFORM_V1("2201", v1, false);
101} // namespace optimize99} // namespace optimize
@@ -16,21 +16,17 @@
16namespace optimize {16namespace optimize {
17class PlatformV1 : public BasePlatform {17class PlatformV1 : public BasePlatform {
18 public:18 public:
19- PlatformV1();19+ explicit PlatformV1(bool is_default_enabled);
20 ~PlatformV1() override = default;20 ~PlatformV1() override = default;
21 af::Status PartitionSubFunctions(af::AscGraph &impl_graph) override;21 af::Status PartitionSubFunctions(af::AscGraph &impl_graph) override;
22 std::unique_ptr<BaseAlignmentStrategy> GetAlignmentStrategy() override;22 std::unique_ptr<BaseAlignmentStrategy> GetAlignmentStrategy() override;
23 unique_ptr<BasePassRunner> GetPassRunner() override;23 unique_ptr<BasePassRunner> GetPassRunner() override;
24 std::unique_ptr<BaseTemplateGenerator> GetTemplateGenerator() override;24 std::unique_ptr<BaseTemplateGenerator> GetTemplateGenerator() override;
25 std::unique_ptr<BackendSpec> GetBackendSpec() const override;25 std::unique_ptr<BackendSpec> GetBackendSpec() const override;
26- const PlatformConfig &GetPlatformConfig() const override;
27 26 
28 Status GenerateTasks(::ascir::ImplGraph &optimize_graph, const OptimizerOptions &options,27 Status GenerateTasks(::ascir::ImplGraph &optimize_graph, const OptimizerOptions &options,
29 std::vector<ScheduleTask> &tasks) const override;28 std::vector<ScheduleTask> &tasks) const override;
30 std::set<std::string> BroadcastTypes() const override;29 std::set<std::string> BroadcastTypes() const override;
31- 
32- private:
33- PlatformConfig config_;
34};30};
35} // namespace optimize31} // namespace optimize
36#endif // OPTIMIZE_PLATFORM_V1_PLATFORM_V1_H32#endif // OPTIMIZE_PLATFORM_V1_PLATFORM_V1_H
@@ -5,6 +5,7 @@ file(GLOB_RECURSE OPTIMIZE_TEST_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
5add_executable(optimize_st5add_executable(optimize_st
6 test.cpp6 test.cpp
7 ${OPTIMIZE_TEST_FILES}7 ${OPTIMIZE_TEST_FILES}
8+ ${CODE_ROOT_DIR}/common/autofuse_backend_spec_api.cpp
8 ${CODE_ROOT_DIR}/tests/framework/easy_asc_graph/asc_graph_builder.cpp9 ${CODE_ROOT_DIR}/tests/framework/easy_asc_graph/asc_graph_builder.cpp
9)10)
10 11 
@@ -65,4 +66,4 @@ target_link_libraries(optimize_st ${ASCGEN_COMMON_LINK_OPTION}
65)66)
66 67 
67add_test(NAME optimize_st COMMAND optimize_st --gtest_output=xml:${CMAKE_INSTALL_PREFIX}/report/st/optimize_st.xml)68add_test(NAME optimize_st COMMAND optimize_st --gtest_output=xml:${CMAKE_INSTALL_PREFIX}/report/st/optimize_st.xml)
68-set_tests_properties(optimize_st PROPERTIES LABELS "st;optimize_st")69+set_tests_properties(optimize_st PROPERTIES LABELS "st;optimize_st")
@@ -42,6 +42,7 @@
42#include "codegen.h"42#include "codegen.h"
43#include "ascgraph_info_complete.h"43#include "ascgraph_info_complete.h"
44#include "asc_graph_builder.h"44#include "asc_graph_builder.h"
45+#include "common/autofuse_backend_spec_api.h"
45 46 
46using namespace std;47using namespace std;
47using namespace af;48using namespace af;
@@ -3638,6 +3639,15 @@ TEST_F(OptimizerSt, platform_reg_test) {
3638 EXPECT_EQ(platform_v1->PartitionSubFunctions(graph), af::SUCCESS);3639 EXPECT_EQ(platform_v1->PartitionSubFunctions(graph), af::SUCCESS);
3639}3640}
3640 3641 
3642+TEST_F(OptimizerSt, platform_config_test) {
3643+ auto platform_v1 = optimize::PlatformFactory::GetInstance().GetPlatform();
3644+ ASSERT_NE(platform_v1, nullptr);
3645+ const auto &config = platform_v1->GetPlatformConfig();
3646+ EXPECT_FALSE(config.is_default_enabled);
3647+ EXPECT_FALSE(config.is_support_compat_mode);
3648+ EXPECT_EQ(config.max_que_num, 4UL);
3649+}
3650+ 
3641TEST_F(OptimizerSt, ReduceNeedAlignment) {3651TEST_F(OptimizerSt, ReduceNeedAlignment) {
3642 const Expression s0 = af::Symbol(7);3652 const Expression s0 = af::Symbol(7);
3643 const Expression s1 = af::Symbol(8);3653 const Expression s1 = af::Symbol(8);
@@ -4072,6 +4082,13 @@ TEST_F(OptimizerSt, BackendSpec) {
4072 auto spec = optimize::BackendSpec::GetInstance();4082 auto spec = optimize::BackendSpec::GetInstance();
4073 ASSERT_TRUE(spec != nullptr);4083 ASSERT_TRUE(spec != nullptr);
4074 ASSERT_EQ(spec->concat_max_input_num, 63);4084 ASSERT_EQ(spec->concat_max_input_num, 63);
4085+ ASSERT_FALSE(spec->is_default_enabled);
4086+}
4087+ 
4088+TEST_F(OptimizerSt, AutofuseBackendSpecTest) {
4089+ auto spec = ge::GetAutofuseBackendSpec();
4090+ ASSERT_NE(spec, nullptr);
4091+ EXPECT_FALSE(spec->is_default_enabled);
4075}4092}
4076 4093 
4077TEST_F(OptimizerSt, TestConcatBackwardFusionGraph_OptimizeSuccess) {4094TEST_F(OptimizerSt, TestConcatBackwardFusionGraph_OptimizeSuccess) {
@@ -6,6 +6,7 @@ list(FILTER OPTIMIZE_TEST_FILES EXCLUDE REGEX "autofuse_backend_stub.cpp")
6add_executable(optimize_ut6add_executable(optimize_ut
7 test.cpp7 test.cpp
8 ${OPTIMIZE_TEST_FILES}8 ${OPTIMIZE_TEST_FILES}
9+ ${CODE_ROOT_DIR}/common/autofuse_backend_spec_api.cpp
9)10)
10 11 
11target_include_directories(optimize_ut PRIVATE12target_include_directories(optimize_ut PRIVATE
@@ -42,6 +42,7 @@
42#include "asc_graph_builder.h"42#include "asc_graph_builder.h"
43#include "codegen.h"43#include "codegen.h"
44#include "optimize/graph_pass/pass_utils.h"44#include "optimize/graph_pass/pass_utils.h"
45+#include "common/autofuse_backend_spec_api.h"
45 46 
46using namespace af;47using namespace af;
47using namespace af::ops;48using namespace af::ops;
@@ -7216,10 +7217,61 @@ TEST_F(TestOptimizer, platform_reg_test) {
7216 EXPECT_EQ(platform_fake, nullptr);7217 EXPECT_EQ(platform_fake, nullptr);
7217}7218}
7218 7219 
7220+TEST_F(TestOptimizer, platform_config_test) {
7221+ // "2201" -> PlatformV1, is_default_enabled = false
7222+ std::string platform_str;
7223+ ge::PlatformContext::GetInstance().GetCurrentPlatformString(platform_str);
7224+ EXPECT_EQ(platform_str, "2201");
7225+ auto platform_v1 = optimize::PlatformFactory::GetInstance().GetPlatform();
7226+ ASSERT_NE(platform_v1, nullptr);
7227+ const auto &config_v1 = platform_v1->GetPlatformConfig();
7228+ EXPECT_FALSE(config_v1.is_default_enabled);
7229+ EXPECT_FALSE(config_v1.is_support_compat_mode);
7230+ EXPECT_EQ(config_v1.max_que_num, 4UL);
7231+ 
7232+ // "3510" -> PlatformV2, is_default_enabled = true
7233+ ge::PlatformContext::GetInstance().SetPlatform("3510");
7234+ auto platform_3510 = optimize::PlatformFactory::GetInstance().GetPlatform();
7235+ ASSERT_NE(platform_3510, nullptr);
7236+ const auto &config_3510 = platform_3510->GetPlatformConfig();
7237+ EXPECT_TRUE(config_3510.is_default_enabled);
7238+ EXPECT_TRUE(config_3510.is_support_compat_mode);
7239+ EXPECT_EQ(config_3510.max_que_num, 14UL);
7240+ 
7241+ // "5102" -> PlatformV2, is_default_enabled = false
7242+ ge::PlatformContext::GetInstance().SetPlatform("5102");
7243+ auto platform_5102 = optimize::PlatformFactory::GetInstance().GetPlatform();
7244+ ASSERT_NE(platform_5102, nullptr);
7245+ const auto &config_5102 = platform_5102->GetPlatformConfig();
7246+ EXPECT_FALSE(config_5102.is_default_enabled);
7247+ EXPECT_TRUE(config_5102.is_support_compat_mode);
7248+ EXPECT_EQ(config_5102.max_que_num, 14UL);
7249+}
7250+ 
7219TEST_F(TestOptimizer, BackendSpec) {7251TEST_F(TestOptimizer, BackendSpec) {
7220 auto spec = optimize::BackendSpec::GetInstance();7252 auto spec = optimize::BackendSpec::GetInstance();
7221 ASSERT_TRUE(spec != nullptr);7253 ASSERT_TRUE(spec != nullptr);
7222 ASSERT_EQ(spec->concat_max_input_num, 63);7254 ASSERT_EQ(spec->concat_max_input_num, 63);
7255+ ASSERT_FALSE(spec->is_default_enabled);
7256+}
7257+ 
7258+TEST_F(TestOptimizer, AutofuseBackendSpecTest) {
7259+ // "2201" -> is_default_enabled = false
7260+ auto spec_2201 = ge::GetAutofuseBackendSpec();
7261+ ASSERT_NE(spec_2201, nullptr);
7262+ EXPECT_FALSE(spec_2201->is_default_enabled);
7263+ 
7264+ // "3510" -> is_default_enabled = true
7265+ ge::PlatformContext::GetInstance().SetPlatform("3510");
7266+ auto spec_3510 = ge::GetAutofuseBackendSpec();
7267+ ASSERT_NE(spec_3510, nullptr);
7268+ EXPECT_TRUE(spec_3510->is_default_enabled);
7269+ 
7270+ // "5102" -> is_default_enabled = false
7271+ ge::PlatformContext::GetInstance().SetPlatform("5102");
7272+ auto spec_5102 = ge::GetAutofuseBackendSpec();
7273+ ASSERT_NE(spec_5102, nullptr);
7274+ EXPECT_FALSE(spec_5102->is_default_enabled);
7223}7275}
7224 7276 
7225TEST_F(TestOptimizer, BrcCacheReuseOtherMem) {7277TEST_F(TestOptimizer, BrcCacheReuseOtherMem) {
@@ -44,6 +44,7 @@
44#include "codegen.h"44#include "codegen.h"
45#include "ascgraph_info_complete.h"45#include "ascgraph_info_complete.h"
46#include "asc_graph_builder.h"46#include "asc_graph_builder.h"
47+#include "common/autofuse_backend_spec_api.h"
47 48 
48using namespace std;49using namespace std;
49using namespace ge;50using namespace ge;
@@ -108,6 +109,25 @@ class OptimizerStV2 : public ::testing::Test {
108 }109 }
109};110};
110 111 
112+TEST_F(OptimizerStV2, platform_config_test) {
113+ // "3510" -> PlatformV2, is_default_enabled = true
114+ const auto platform_3510 = optimize::PlatformFactory::GetInstance().GetPlatform();
115+ ASSERT_NE(platform_3510, nullptr);
116+ const auto &config_3510 = platform_3510->GetPlatformConfig();
117+ EXPECT_TRUE(config_3510.is_default_enabled);
118+ EXPECT_TRUE(config_3510.is_support_compat_mode);
119+ EXPECT_EQ(config_3510.max_que_num, 14UL);
120+ 
121+ // "5102" -> PlatformV2, is_default_enabled = false
122+ ge::PlatformContext::GetInstance().SetPlatform("5102");
123+ const auto platform_5102 = optimize::PlatformFactory::GetInstance().GetPlatform();
124+ ASSERT_NE(platform_5102, nullptr);
125+ const auto &config_5102 = platform_5102->GetPlatformConfig();
126+ EXPECT_FALSE(config_5102.is_default_enabled);
127+ EXPECT_TRUE(config_5102.is_support_compat_mode);
128+ EXPECT_EQ(config_5102.max_que_num, 14UL);
129+}
130+ 
111namespace optimize {131namespace optimize {
112TEST_F(OptimizerStV2, ElewiseAndBrcCanMerge) {132TEST_F(OptimizerStV2, ElewiseAndBrcCanMerge) {
113 af::AscGraph graph1("graph1");133 af::AscGraph graph1("graph1");
@@ -1087,6 +1107,20 @@ TEST_F(OptimizerStV2, BackendSpec) {
1087 auto spec = ::optimize::BackendSpec::GetInstance();1107 auto spec = ::optimize::BackendSpec::GetInstance();
1088 ASSERT_TRUE(spec != nullptr);1108 ASSERT_TRUE(spec != nullptr);
1089 ASSERT_EQ(spec->concat_max_input_num, 512);1109 ASSERT_EQ(spec->concat_max_input_num, 512);
1110+ ASSERT_TRUE(spec->is_default_enabled);
1111+}
1112+ 
1113+TEST_F(OptimizerStV2, AutofuseBackendSpecTest) {
1114+ // "3510" -> is_default_enabled = true
1115+ auto spec_3510 = ge::GetAutofuseBackendSpec();
1116+ ASSERT_NE(spec_3510, nullptr);
1117+ EXPECT_TRUE(spec_3510->is_default_enabled);
1118+ 
1119+ // "5102" -> is_default_enabled = false
1120+ ge::PlatformContext::GetInstance().SetPlatform("5102");
1121+ auto spec_5102 = ge::GetAutofuseBackendSpec();
1122+ ASSERT_NE(spec_5102, nullptr);
1123+ EXPECT_FALSE(spec_5102->is_default_enabled);
1090}1124}
1091 1125 
1092TEST_F(OptimizerStV2, ConcatTailDim_SplitConcat_LargeRowNum) {1126TEST_F(OptimizerStV2, ConcatTailDim_SplitConcat_LargeRowNum) {
@@ -47,6 +47,7 @@
47#include "base/att_const_values.h"47#include "base/att_const_values.h"
48#include "graph_pass/pow_equiv_substitution_pass.h"48#include "graph_pass/pow_equiv_substitution_pass.h"
49#include "template/nddma_template.h"49#include "template/nddma_template.h"
50+#include "common/autofuse_backend_spec_api.h"
50#define protected public51#define protected public
51#include "un_alignment_strategy.h"52#include "un_alignment_strategy.h"
52#undef protected53#undef protected
@@ -103,6 +104,28 @@ TEST_F(TestOptimizerV2, platform_reg_test) {
103 EXPECT_NE(platform_v2->GetTemplateGenerator(), nullptr);104 EXPECT_NE(platform_v2->GetTemplateGenerator(), nullptr);
104}105}
105 106 
107+TEST_F(TestOptimizerV2, platform_config_test) {
108+ // "3510" -> PlatformV2, is_default_enabled = true
109+ std::string platform_str;
110+ ge::PlatformContext::GetInstance().GetCurrentPlatformString(platform_str);
111+ EXPECT_EQ(platform_str, "3510");
112+ const auto platform_3510 = optimize::PlatformFactory::GetInstance().GetPlatform();
113+ ASSERT_NE(platform_3510, nullptr);
114+ const auto &config_3510 = platform_3510->GetPlatformConfig();
115+ EXPECT_TRUE(config_3510.is_default_enabled);
116+ EXPECT_TRUE(config_3510.is_support_compat_mode);
117+ EXPECT_EQ(config_3510.max_que_num, 14UL);
118+ 
119+ // "5102" -> PlatformV2, is_default_enabled = false
120+ ge::PlatformContext::GetInstance().SetPlatform("5102");
121+ const auto platform_5102 = optimize::PlatformFactory::GetInstance().GetPlatform();
122+ ASSERT_NE(platform_5102, nullptr);
123+ const auto &config_5102 = platform_5102->GetPlatformConfig();
124+ EXPECT_FALSE(config_5102.is_default_enabled);
125+ EXPECT_TRUE(config_5102.is_support_compat_mode);
126+ EXPECT_EQ(config_5102.max_que_num, 14UL);
127+}
128+ 
106TEST_F(TestOptimizerV2, NotRemovePad) {129TEST_F(TestOptimizerV2, NotRemovePad) {
107 af::AscGraph graph("Autoschedule_autoschedule_removepad_broadcast");130 af::AscGraph graph("Autoschedule_autoschedule_removepad_broadcast");
108 auto s0 = graph.CreateSizeVar(2);131 auto s0 = graph.CreateSizeVar(2);
@@ -3175,6 +3198,20 @@ TEST_F(TestOptimizerV2, BackendSpec) {
3175 auto spec = optimize::BackendSpec::GetInstance();3198 auto spec = optimize::BackendSpec::GetInstance();
3176 ASSERT_TRUE(spec != nullptr);3199 ASSERT_TRUE(spec != nullptr);
3177 ASSERT_EQ(spec->concat_max_input_num, 512);3200 ASSERT_EQ(spec->concat_max_input_num, 512);
3201+ ASSERT_TRUE(spec->is_default_enabled);
3202+}
3203+ 
3204+TEST_F(TestOptimizerV2, AutofuseBackendSpecTest) {
3205+ // "3510" -> is_default_enabled = true
3206+ auto spec_3510 = ge::GetAutofuseBackendSpec();
3207+ ASSERT_NE(spec_3510, nullptr);
3208+ EXPECT_TRUE(spec_3510->is_default_enabled);
3209+ 
3210+ // "5102" -> is_default_enabled = false
3211+ ge::PlatformContext::GetInstance().SetPlatform("5102");
3212+ auto spec_5102 = ge::GetAutofuseBackendSpec();
3213+ ASSERT_NE(spec_5102, nullptr);
3214+ EXPECT_FALSE(spec_5102->is_default_enabled);
3178}3215}
3179 3216 
3180TEST_F(TestOptimizerV2, TestNddmaReAlignVectorizedStrides) {3217TEST_F(TestOptimizerV2, TestNddmaReAlignVectorizedStrides) {
@@ -26,9 +26,10 @@
26namespace optimize {26namespace optimize {
27constexpr size_t kMaxVecQueNum = 14UL;27constexpr size_t kMaxVecQueNum = 14UL;
28 28 
29-PlatformV2::PlatformV2() {29+PlatformV2::PlatformV2(bool is_default_enabled) {
30 config_.max_que_num = kMaxVecQueNum;30 config_.max_que_num = kMaxVecQueNum;
31 config_.is_support_compat_mode = true;31 config_.is_support_compat_mode = true;
32+ config_.is_default_enabled = is_default_enabled;
32}33}
33 34 
34af::Status PlatformV2::PartitionSubFunctions(af::AscGraph &impl_graph) {35af::Status PlatformV2::PartitionSubFunctions(af::AscGraph &impl_graph) {
@@ -78,6 +79,7 @@ std::unique_ptr<BackendSpec> PlatformV2::GetBackendSpec() const {
78 // 256*1024是UB size79 // 256*1024是UB size
79 ret->set_local_memory_size = 248 * 1024 - 8 * 1024 - 32 * 1024;80 ret->set_local_memory_size = 248 * 1024 - 8 * 1024 - 32 * 1024;
80 ret->pgo_spec = {false};81 ret->pgo_spec = {false};
82+ ret->is_default_enabled = config_.is_default_enabled;
81 return ret;83 return ret;
82}84}
83 85 
@@ -100,17 +102,13 @@ Status PlatformV2::GenerateTasks(ascir::ImplGraph &optimize_graph, const Optimiz
100 return af::SUCCESS;102 return af::SUCCESS;
101}103}
102 104 
103-const PlatformConfig &PlatformV2::GetPlatformConfig() const {
104- return config_;
105-}
106- 
107std::set<std::string> PlatformV2::BroadcastTypes() const {105std::set<std::string> PlatformV2::BroadcastTypes() const {
108 return {af::ascir_op::Broadcast::Type, af::ascir_op::Nddma::Type};106 return {af::ascir_op::Broadcast::Type, af::ascir_op::Nddma::Type};
109}107}
110 108 
111-#define REGISTER_PLATFORM_V2(platform_name, suffix) \109+#define REGISTER_PLATFORM_V2(platform_name, suffix, is_default_enabled) \
112- static PlatformRegistrar<PlatformV2> registrar_##suffix(platform_name)110+ static PlatformRegistrar<PlatformV2> registrar_##suffix(platform_name, is_default_enabled)
113 111 
114-REGISTER_PLATFORM_V2("3510", v2);112+REGISTER_PLATFORM_V2("3510", v2, true);
115-REGISTER_PLATFORM_V2("5102", V2_1);113+REGISTER_PLATFORM_V2("5102", V2_1, false);
116} // namespace optimize114} // namespace optimize
@@ -16,7 +16,7 @@
16namespace optimize {16namespace optimize {
17class PlatformV2 : public BasePlatform {17class PlatformV2 : public BasePlatform {
18 public:18 public:
19- PlatformV2();19+ explicit PlatformV2(bool is_default_enabled);
20 ~PlatformV2() override = default;20 ~PlatformV2() override = default;
21 af::Status PartitionSubFunctions(af::AscGraph &impl_graph) override;21 af::Status PartitionSubFunctions(af::AscGraph &impl_graph) override;
22 std::unique_ptr<BaseAlignmentStrategy> GetAlignmentStrategy() override;22 std::unique_ptr<BaseAlignmentStrategy> GetAlignmentStrategy() override;
@@ -25,11 +25,7 @@ class PlatformV2 : public BasePlatform {
25 std::unique_ptr<BackendSpec> GetBackendSpec() const override;25 std::unique_ptr<BackendSpec> GetBackendSpec() const override;
26 Status GenerateTasks(ascir::ImplGraph &optimize_graph, const OptimizerOptions &options,26 Status GenerateTasks(ascir::ImplGraph &optimize_graph, const OptimizerOptions &options,
27 std::vector<ScheduleTask> &tasks) const override;27 std::vector<ScheduleTask> &tasks) const override;
28- const PlatformConfig &GetPlatformConfig() const override;
29 std::set<std::string> BroadcastTypes() const override;28 std::set<std::string> BroadcastTypes() const override;
30- 
31- private:
32- PlatformConfig config_;
33};29};
34} // namespace optimize30} // namespace optimize
35#endif // OPTIMIZE_PLATFORM_V1_PLATFORM_V2_H31#endif // OPTIMIZE_PLATFORM_V1_PLATFORM_V2_H
@@ -58,7 +58,7 @@ fi
58autofuse_python_dir="${WHL_INSTALL_DIR_PATH}/autofuse"58autofuse_python_dir="${WHL_INSTALL_DIR_PATH}/autofuse"
59if [ -d "${autofuse_python_dir}" ]; then59if [ -d "${autofuse_python_dir}" ]; then
60 python3 -m compileall -q "${autofuse_python_dir}" 2>/dev/null || true60 python3 -m compileall -q "${autofuse_python_dir}" 2>/dev/null || true
61- chmod -R 550 "${autofuse_python_dir}/__pycache__" 2>/dev/null || true61+ chmod -R 555 "${autofuse_python_dir}/__pycache__" 2>/dev/null || true
atomgit-bot
atomgit-botatomgit-bot7月8日

🟡 Medium Priority

两个 shell 脚本中对 __pycache__ 目录的权限从 550r-xr-x---,仅 owner 和 group 可读/可执行)改为 555r-xr-xr-x,所有用户可读/可执行)。

__pycache__ 目录包含 Python 编译后的 .pyc 字节码文件,可以通过反编译工具还原出近似源码。而同一安装脚本中对 Python 源码目录的权限控制为 750chmod_recur "${sourcedir}/python" 750 dir),即仅 owner+group 可访问。此变更使 .pyc 字节码的访问权限比源码目录更宽松,在多用户系统中,未授权的 "other" 用户可读取并反编译这些字节码,从而绕过源码目录的权限限制。

影响范围:custom_postinst.sh 第 61 行(rpm/deb 安装后脚本)和 graph_autofusion_custom_install.sh 第 372 行(自定义安装脚本)。

建议:建议保持与源码目录一致的权限策略。若 __pycache__ 需要可执行权限以支持 Python import 机制,可将权限设为 550(owner+group 可读可执行,other 无权限),与源码目录的权限模型一致。若确实需要放宽权限,请确认无安全风险并添加注释说明原因。

likedislike
62fi62fi
63 63 
64chmod_recur "${sourcedir}/python" 750 dir64chmod_recur "${sourcedir}/python" 750 dir
@@ -124,7 +124,7 @@ graph_autofusion_install_package() {
124 log "INFO" "install ${_package} successfully!"124 log "INFO" "install ${_package} successfully!"
125 fi125 fi
126 else126 else
127- log "ERROR" "ERR_NO:0x0080;ERR_DES:install ${_package} faied, can not find the matched package for this platform."127+ log "ERROR" "ERR_NO:0x0080;ERR_DES:install ${_package} failed, can not find the matched package for this platform."
128 exit 1128 exit 1
129 fi129 fi
130}130}
@@ -347,7 +347,7 @@ custom_install() {
347 if [ "${pylocal}" = "y" ]; then347 if [ "${pylocal}" = "y" ]; then
348 log "INFO" "please make sure PYTHONPATH include ${WHL_INSTALL_DIR_PATH}."348 log "INFO" "please make sure PYTHONPATH include ${WHL_INSTALL_DIR_PATH}."
349 else349 else
350- log "INFO" "The package te is already installed in python default path. It is recommended to install it using the '--pylocal' parameter, install the package graph_autofusion in the ${WHL_INSTALL_DIR_PATH}."350+ log "INFO" "The package graph_autofusion is already installed in python default path. It is recommended to install it using the '--pylocal' parameter, install the package graph_autofusion in the ${WHL_INSTALL_DIR_PATH}."
351 fi351 fi
352 352 
353 if [ "x$stage" = "xinstall" ]; then353 if [ "x$stage" = "xinstall" ]; then
@@ -369,7 +369,7 @@ custom_install() {
369 if [ -d "${autofuse_python_dir}" ]; then369 if [ -d "${autofuse_python_dir}" ]; then
370 log "INFO" "pre-compiling autofuse python scripts..."370 log "INFO" "pre-compiling autofuse python scripts..."
371 python3 -m compileall -q "${autofuse_python_dir}" 2>/dev/null || true371 python3 -m compileall -q "${autofuse_python_dir}" 2>/dev/null || true
372- chmod -R 550 "${autofuse_python_dir}/__pycache__" 2>/dev/null || true372+ chmod -R 555 "${autofuse_python_dir}/__pycache__" 2>/dev/null || true
atomgit-bot
atomgit-botatomgit-bot7月8日

🟡 Medium Priority

custom_postinst.sh:61 相同的问题:chmod -R 550 改为 chmod -R 555,使 __pycache__ 目录及其中 .pyc 字节码文件对 "other" 用户变为可读可执行。安装脚本中对源码目录的权限管理(chmod_recur 使用 750/550)限制 other 用户访问,但此变更使编译后的字节码绕过该限制。

建议:与 custom_postinst.sh 的建议相同:将权限改回 550 以保持与源码目录权限策略一致。

likedislike
373 log "INFO" "autofuse python scripts pre-compiled."373 log "INFO" "autofuse python scripts pre-compiled."
374 fi374 fi
375 375