已合并
fix: v1补充注册 Unsupported ASCIR 算子及占位 codegen #1767
wei_shi创建于 21 天前
fix: v1补充注册 Unsupported ASCIR 算子及占位 codegen #1767
已合并
共 5 个文件变更+93-0
| @@ -41,6 +41,15 @@ namespace af { | |||
| 41 | namespace ascir { | 41 | namespace ascir { |
| 42 | EXPORT_GENERATOR() | 42 | EXPORT_GENERATOR() |
| 43 | 43 | ||
| 44 | +class AscIrAttStub : public af::ascir::AscIrAtt { | ||
| 45 | + void *GetApiPerf() const override { | ||
| 46 | + return nullptr; | ||
| 47 | + } | ||
| 48 | + void *GetAscendCApiPerfTable() const override { | ||
| 49 | + return nullptr; | ||
| 50 | + } | ||
| 51 | +}; | ||
| 52 | + | ||
| 44 | const std::vector<std::string> v1_soc_versions{"2201"}; | 53 | const std::vector<std::string> v1_soc_versions{"2201"}; |
| 45 | 54 | ||
| 46 | REG_ASC_IR(Data) | 55 | REG_ASC_IR(Data) |
| @@ -930,5 +939,15 @@ REG_ASC_IR(Conv2DOffsetBias) | |||
| 930 | 939 | ||
| 931 | REG_ASC_IR(Split).Input("x", "T").DynamicOutput("y", "T").Attr<int64_t>("index").Attr<int64_t>( | 940 | REG_ASC_IR(Split).Input("x", "T").DynamicOutput("y", "T").Attr<int64_t>("index").Attr<int64_t>( |
| 932 | "gid"); // global_id, SplitOp的全局编号 | 941 | "gid"); // global_id, SplitOp的全局编号 |
| 942 | + | ||
| 943 | +REG_ASC_IR(Unsupported) | ||
| 944 | + .Inputs({}) | ||
| 945 | + .Output("y", "T") | ||
| 946 | + .StartNode() | ||
| 947 | + .Attr<std::string>("error_msg") | ||
| 948 | + .ComputeType(ComputeType::kComputeInvalid) | ||
| 949 | + .Impl(v1_soc_versions, {af::ascir::AscIrImplCreator<af::ascir::AscIrAttStub>(), | ||
| 950 | + af::ascir::AscIrImplCreator<af::ascir::UnsupportedAscIrCodegenImpl>(), | ||
| 951 | + {{"T", TensorType{DT_FLOAT}}}}); | ||
| 933 | } // namespace ascir | 952 | } // namespace ascir |
| 934 | } // namespace af | 953 | } // namespace af |
| @@ -2103,6 +2103,16 @@ class Conv2DAscIrCodegenImpl : public AscIrCodegen { | |||
| 2103 | return true; | 2103 | return true; |
| 2104 | } | 2104 | } |
| 2105 | }; | 2105 | }; |
| 2106 | + | ||
| 2107 | +class UnsupportedAscIrCodegenImpl : public AscIrCodegen { | ||
| 2108 | + public: | ||
| 2109 | + std::string GetApiCallName() const override { | ||
| 2110 | + return ""; | ||
| 2111 | + } | ||
| 2112 | + std::string GetApiName() const override { | ||
| 2113 | + return "Unsupported"; | ||
| 2114 | + } | ||
| 2115 | +}; | ||
| 2106 | } // namespace ascir | 2116 | } // namespace ascir |
| 2107 | } // namespace af | 2117 | } // namespace af |
| 2108 | 2118 | ||
| @@ -24,6 +24,7 @@ add_executable(test_ascir_st | |||
| 24 | reg_func/test_reg_func_gather.cpp | 24 | reg_func/test_reg_func_gather.cpp |
| 25 | reg_func/test_reg_func_erf.cpp | 25 | reg_func/test_reg_func_erf.cpp |
| 26 | reg_func/test_reg_func_axpy.cpp | 26 | reg_func/test_reg_func_axpy.cpp |
| 27 | + reg_func/test_reg_func_unsupported.cpp | ||
| 27 | reg_func_v2/test_reg_func_sin_v2.cpp | 28 | reg_func_v2/test_reg_func_sin_v2.cpp |
| 28 | code_dumper/code_dumper_unittest.cc | 29 | code_dumper/code_dumper_unittest.cc |
| 29 | ) | 30 | ) |
| @@ -0,0 +1,37 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | + * CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | + * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | + */ | ||
| 7 | + | ||
| 8 | + | ||
| 9 | + | ||
| 10 | + | ||
| 11 | + | ||
| 12 | +namespace af { | ||
| 13 | +TEST(UnsupportedAscIrRegistration, HasExpectedDefinitionAndImplementations) { | ||
| 14 | + const auto ®istry = ascir::AscirRegistry::GetInstance().GetAll(); | ||
| 15 | + const auto iter = registry.find("Unsupported"); | ||
| 16 | + ASSERT_NE(iter, registry.end()); | ||
| 17 | + | ||
| 18 | + auto definition = iter->second; | ||
| 19 | + EXPECT_TRUE(definition.GetInputDefs().empty()); | ||
| 20 | + ASSERT_EQ(definition.GetOutputDefs().size(), 1U); | ||
| 21 | + EXPECT_EQ(definition.GetOutputDefs()[0].first, "y"); | ||
| 22 | + EXPECT_TRUE(definition.IsStartNode()); | ||
| 23 | + ASSERT_EQ(definition.GetAttrDefs().size(), 1U); | ||
| 24 | + EXPECT_EQ(definition.GetAttrDefs()[0].name, "error_msg"); | ||
| 25 | + EXPECT_EQ(definition.GetComputeType(), ComputeType::kComputeInvalid); | ||
| 26 | + | ||
| 27 | + auto codegen = definition.GetAscIrCodegenImpl("2201"); | ||
| 28 | + ASSERT_NE(codegen, nullptr); | ||
| 29 | + EXPECT_TRUE(codegen->GetApiCallName().empty()); | ||
| 30 | + EXPECT_EQ(codegen->GetApiName(), "Unsupported"); | ||
| 31 | + | ||
| 32 | + auto att = definition.GetAscIrAttImpl("2201"); | ||
| 33 | + ASSERT_NE(att, nullptr); | ||
| 34 | + EXPECT_EQ(att->GetApiPerf(), nullptr); | ||
| 35 | + EXPECT_EQ(att->GetAscendCApiPerfTable(), nullptr); | ||
| 36 | +} | ||
| 37 | +} // namespace af | ||
| @@ -12,6 +12,7 @@ | |||
| 12 | 12 | ||
| 13 | 13 | ||
| 14 | 14 | ||
| 15 | + | ||
| 15 | 16 | ||
| 16 | 17 | ||
| 17 | 18 | ||
| @@ -29,6 +30,31 @@ class AscendGraphDumpUT : public testing::Test { | |||
| 29 | }; | 30 | }; |
| 30 | 31 | ||
| 31 | namespace af { | 32 | namespace af { |
| 33 | +TEST(UnsupportedAscIrRegistration, HasExpectedDefinitionAndImplementations) { | ||
| 34 | + const auto ®istry = ascir::AscirRegistry::GetInstance().GetAll(); | ||
| 35 | + const auto iter = registry.find("Unsupported"); | ||
| 36 | + ASSERT_NE(iter, registry.end()); | ||
| 37 | + | ||
| 38 | + auto definition = iter->second; | ||
| 39 | + EXPECT_TRUE(definition.GetInputDefs().empty()); | ||
| 40 | + ASSERT_EQ(definition.GetOutputDefs().size(), 1U); | ||
| 41 | + EXPECT_EQ(definition.GetOutputDefs()[0].first, "y"); | ||
| 42 | + EXPECT_TRUE(definition.IsStartNode()); | ||
| 43 | + ASSERT_EQ(definition.GetAttrDefs().size(), 1U); | ||
| 44 | + EXPECT_EQ(definition.GetAttrDefs()[0].name, "error_msg"); | ||
| 45 | + EXPECT_EQ(definition.GetComputeType(), ComputeType::kComputeInvalid); | ||
| 46 | + | ||
| 47 | + auto codegen = definition.GetAscIrCodegenImpl("2201"); | ||
| 48 | + ASSERT_NE(codegen, nullptr); | ||
| 49 | + EXPECT_TRUE(codegen->GetApiCallName().empty()); | ||
| 50 | + EXPECT_EQ(codegen->GetApiName(), "Unsupported"); | ||
| 51 | + | ||
| 52 | + auto att = definition.GetAscIrAttImpl("2201"); | ||
| 53 | + ASSERT_NE(att, nullptr); | ||
| 54 | + EXPECT_EQ(att->GetApiPerf(), nullptr); | ||
| 55 | + EXPECT_EQ(att->GetAscendCApiPerfTable(), nullptr); | ||
| 56 | +} | ||
| 57 | + | ||
| 32 | TEST_F(AscendGraphDumpUT, test_dump_when_env_not_set) { | 58 | TEST_F(AscendGraphDumpUT, test_dump_when_env_not_set) { |
| 33 | AscGraph graph("test"); | 59 | AscGraph graph("test"); |
| 34 | ::ascir::utils::DumpGraph(graph, "empty_stage0"); | 60 | ::ascir::utils::DumpGraph(graph, "empty_stage0"); |