已合并
【PR】feat: sync develop to master 20260708 #1235
zhanj创建于 7月8日
【PR】feat: sync develop to master 20260708 #1235
已合并
共 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 ge | 39 | } // 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 | ||
| 48 | std::unique_ptr<AutofuseBackendSpec> GetAutofuseBackendSpec(); | 49 | std::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 optimize | 57 | } // namespace optimize |
| 57 | 58 | ||
| @@ -14,7 +14,9 @@ | |||
| 14 | namespace optimize { | 14 | namespace optimize { |
| 15 | std::unique_ptr<BackendSpec> BackendSpec::GetInstance() { | 15 | std::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 optimize | 22 | } // namespace optimize |
| @@ -22,6 +22,7 @@ namespace optimize { | |||
| 22 | struct PlatformConfig { | 22 | struct 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 | ||
| 27 | class BasePlatform { | 28 | class 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 optimize | 55 | } // namespace optimize |
| 50 | 56 | ||
| @@ -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 | 14 | ||
| 15 | 15 | ||
| 16 | + | ||
| 16 | 17 | ||
| 17 | 18 | ||
| 18 | 19 | ||
| 19 | namespace optimize { | 20 | namespace optimize { |
| 20 | -using PlatformCreator = std::unique_ptr<BasePlatform> (*)(); | 21 | +using PlatformCreator = std::function<std::unique_ptr<BasePlatform>()>; |
| 21 | 22 | ||
| 22 | class PlatformFactory { | 23 | class PlatformFactory { |
| 23 | public: | 24 | public: |
| @@ -39,13 +40,14 @@ class PlatformFactory { | |||
| 39 | template <typename T> | 40 | template <typename T> |
| 40 | class PlatformRegistrar { | 41 | class 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 | ||
| 45 | template <typename T> | 46 | template <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 optimize | 52 | } // namespace optimize |
| 51 | 53 | ||
| @@ -22,8 +22,9 @@ | |||
| 22 | namespace optimize { | 22 | namespace optimize { |
| 23 | constexpr size_t kMaxVecQueNum = 4UL; | 23 | constexpr 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 | ||
| 29 | af::Status PlatformV1::PartitionSubFunctions([[maybe_unused]] af::AscGraph &impl_graph) { | 30 | af::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 | - | ||
| 76 | Status PlatformV1::GenerateTasks(ascir::ImplGraph &optimize_graph, const OptimizerOptions &options, | 74 | Status 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 optimize | 99 | } // namespace optimize |
| @@ -16,21 +16,17 @@ | |||
| 16 | namespace optimize { | 16 | namespace optimize { |
| 17 | class PlatformV1 : public BasePlatform { | 17 | class 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 optimize | 31 | } // namespace optimize |
| 36 | 32 | ||
| @@ -5,6 +5,7 @@ file(GLOB_RECURSE OPTIMIZE_TEST_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp") | |||
| 5 | add_executable(optimize_st | 5 | add_executable(optimize_st |
| 6 | test.cpp | 6 | 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.cpp | 9 | ${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 | ||
| 67 | add_test(NAME optimize_st COMMAND optimize_st --gtest_output=xml:${CMAKE_INSTALL_PREFIX}/report/st/optimize_st.xml) | 68 | add_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 | 42 | ||
| 43 | 43 | ||
| 44 | 44 | ||
| 45 | + | ||
| 45 | 46 | ||
| 46 | using namespace std; | 47 | using namespace std; |
| 47 | using namespace af; | 48 | using 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 | + | ||
| 3641 | TEST_F(OptimizerSt, ReduceNeedAlignment) { | 3651 | TEST_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 | ||
| 4077 | TEST_F(OptimizerSt, TestConcatBackwardFusionGraph_OptimizeSuccess) { | 4094 | TEST_F(OptimizerSt, TestConcatBackwardFusionGraph_OptimizeSuccess) { |
| @@ -6,6 +6,7 @@ list(FILTER OPTIMIZE_TEST_FILES EXCLUDE REGEX "autofuse_backend_stub.cpp") | |||
| 6 | add_executable(optimize_ut | 6 | add_executable(optimize_ut |
| 7 | test.cpp | 7 | test.cpp |
| 8 | ${OPTIMIZE_TEST_FILES} | 8 | ${OPTIMIZE_TEST_FILES} |
| 9 | + ${CODE_ROOT_DIR}/common/autofuse_backend_spec_api.cpp | ||
| 9 | ) | 10 | ) |
| 10 | 11 | ||
| 11 | target_include_directories(optimize_ut PRIVATE | 12 | target_include_directories(optimize_ut PRIVATE |
| @@ -42,6 +42,7 @@ | |||
| 42 | 42 | ||
| 43 | 43 | ||
| 44 | 44 | ||
| 45 | + | ||
| 45 | 46 | ||
| 46 | using namespace af; | 47 | using namespace af; |
| 47 | using namespace af::ops; | 48 | using 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 | + | ||
| 7219 | TEST_F(TestOptimizer, BackendSpec) { | 7251 | TEST_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 | ||
| 7225 | TEST_F(TestOptimizer, BrcCacheReuseOtherMem) { | 7277 | TEST_F(TestOptimizer, BrcCacheReuseOtherMem) { |
| @@ -44,6 +44,7 @@ | |||
| 44 | 44 | ||
| 45 | 45 | ||
| 46 | 46 | ||
| 47 | + | ||
| 47 | 48 | ||
| 48 | using namespace std; | 49 | using namespace std; |
| 49 | using namespace ge; | 50 | using 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 | + | ||
| 111 | namespace optimize { | 131 | namespace optimize { |
| 112 | TEST_F(OptimizerStV2, ElewiseAndBrcCanMerge) { | 132 | TEST_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 | ||
| 1092 | TEST_F(OptimizerStV2, ConcatTailDim_SplitConcat_LargeRowNum) { | 1126 | TEST_F(OptimizerStV2, ConcatTailDim_SplitConcat_LargeRowNum) { |
| @@ -47,6 +47,7 @@ | |||
| 47 | 47 | ||
| 48 | 48 | ||
| 49 | 49 | ||
| 50 | + | ||
| 50 | 51 | ||
| 51 | 52 | ||
| 52 | 53 | ||
| @@ -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 | + | ||
| 106 | TEST_F(TestOptimizerV2, NotRemovePad) { | 129 | TEST_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 | ||
| 3180 | TEST_F(TestOptimizerV2, TestNddmaReAlignVectorizedStrides) { | 3217 | TEST_F(TestOptimizerV2, TestNddmaReAlignVectorizedStrides) { |
| @@ -26,9 +26,10 @@ | |||
| 26 | namespace optimize { | 26 | namespace optimize { |
| 27 | constexpr size_t kMaxVecQueNum = 14UL; | 27 | constexpr 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 | ||
| 34 | af::Status PlatformV2::PartitionSubFunctions(af::AscGraph &impl_graph) { | 35 | af::Status PlatformV2::PartitionSubFunctions(af::AscGraph &impl_graph) { |
| @@ -78,6 +79,7 @@ std::unique_ptr<BackendSpec> PlatformV2::GetBackendSpec() const { | |||
| 78 | // 256*1024是UB size | 79 | // 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 | - | ||
| 107 | std::set<std::string> PlatformV2::BroadcastTypes() const { | 105 | std::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 optimize | 114 | } // namespace optimize |
| @@ -16,7 +16,7 @@ | |||
| 16 | namespace optimize { | 16 | namespace optimize { |
| 17 | class PlatformV2 : public BasePlatform { | 17 | class 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 optimize | 30 | } // namespace optimize |
| 35 | 31 | ||
| @@ -58,7 +58,7 @@ fi | |||
| 58 | autofuse_python_dir="${WHL_INSTALL_DIR_PATH}/autofuse" | 58 | autofuse_python_dir="${WHL_INSTALL_DIR_PATH}/autofuse" |
| 59 | if [ -d "${autofuse_python_dir}" ]; then | 59 | if [ -d "${autofuse_python_dir}" ]; then |
| 60 | python3 -m compileall -q "${autofuse_python_dir}" 2>/dev/null || true | 60 | python3 -m compileall -q "${autofuse_python_dir}" 2>/dev/null || true |
| 61 | - chmod -R 550 "${autofuse_python_dir}/__pycache__" 2>/dev/null || true | 61 | + chmod -R 555 "${autofuse_python_dir}/__pycache__" 2>/dev/null || true |
| 62 | fi | 62 | fi |
| 63 | 63 | ||
| 64 | chmod_recur "${sourcedir}/python" 750 dir | 64 | chmod_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 | fi | 125 | fi |
| 126 | else | 126 | 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 1 | 128 | exit 1 |
| 129 | fi | 129 | fi |
| 130 | } | 130 | } |
| @@ -347,7 +347,7 @@ custom_install() { | |||
| 347 | if [ "${pylocal}" = "y" ]; then | 347 | 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 | else | 349 | 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 | fi | 351 | fi |
| 352 | 352 | ||
| 353 | if [ "x$stage" = "xinstall" ]; then | 353 | if [ "x$stage" = "xinstall" ]; then |
| @@ -369,7 +369,7 @@ custom_install() { | |||
| 369 | if [ -d "${autofuse_python_dir}" ]; then | 369 | 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 || true | 371 | python3 -m compileall -q "${autofuse_python_dir}" 2>/dev/null || true |
| 372 | - chmod -R 550 "${autofuse_python_dir}/__pycache__" 2>/dev/null || true | 372 | + chmod -R 555 "${autofuse_python_dir}/__pycache__" 2>/dev/null || true |
🟡 Medium Priority 与 建议:与 custom_postinst.sh 的建议相同:将权限改回 ![]() ![]() | |||
| 373 | log "INFO" "autofuse python scripts pre-compiled." | 373 | log "INFO" "autofuse python scripts pre-compiled." |
| 374 | fi | 374 | fi |
| 375 | 375 | ||


🟡 Medium Priority
两个 shell 脚本中对
__pycache__目录的权限从550(r-xr-x---,仅 owner 和 group 可读/可执行)改为555(r-xr-xr-x,所有用户可读/可执行)。__pycache__目录包含 Python 编译后的.pyc字节码文件,可以通过反编译工具还原出近似源码。而同一安装脚本中对 Python 源码目录的权限控制为750(chmod_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 无权限),与源码目录的权限模型一致。若确实需要放宽权限,请确认无安全风险并添加注释说明原因。