已合并
【PR】: autofuse支持extendconv2d #1669
【PR】: autofuse支持extendconv2d #1669
已合并
hemahema创建于 8月6日
23 个文件变更+1410-755
@@ -863,16 +863,15 @@ REG_ASC_IR(Conv2D)
863 .Attr<std::vector<int64_t>>("pads")863 .Attr<std::vector<int64_t>>("pads")
864 .Attr<std::vector<int64_t>>("dilations")864 .Attr<std::vector<int64_t>>("dilations")
865 .Attr<int64_t>("groups")865 .Attr<int64_t>("groups")
866- .Attr<int64_t>("has_relu")
867 .Attr<std::string>("pad_mode")866 .Attr<std::string>("pad_mode")
868 .Attr<std::string>("data_format")867 .Attr<std::string>("data_format")
869 .Attr<int64_t>("offset_x")868 .Attr<int64_t>("offset_x")
870 .Attr<bool>("enable_hf32")869 .Attr<bool>("enable_hf32")
870+ .Attr<int64_t>("fixed_shift_value")
871 .ComputeType(ComputeType::kComputeCube)871 .ComputeType(ComputeType::kComputeCube)
872 .Impl(v1_soc_versions, {af::ascir::AscIrImplCreator<Conv2DAscIrAttImpl>(),872 .Impl(v1_soc_versions, {af::ascir::AscIrImplCreator<Conv2DAscIrAttImpl>(),
873 af::ascir::AscIrImplCreator<af::ascir::Conv2DAscIrCodegenImpl>(),873 af::ascir::AscIrImplCreator<af::ascir::Conv2DAscIrCodegenImpl>(),
874- {{"T1", TensorType{DT_FLOAT16, DT_FLOAT, DT_BF16, DT_HIFLOAT8}},874+ {{"T1", TensorType{DT_FLOAT16}}, {"T2", TensorType{DT_FLOAT16}}}});
875- {"T2", TensorType{DT_FLOAT16, DT_FLOAT, DT_BF16, DT_HIFLOAT8}}}});
876 875 
877REG_ASC_IR(Conv2DBias)876REG_ASC_IR(Conv2DBias)
878 .Input("x", "T1")877 .Input("x", "T1")
@@ -883,16 +882,15 @@ REG_ASC_IR(Conv2DBias)
883 .Attr<std::vector<int64_t>>("pads")882 .Attr<std::vector<int64_t>>("pads")
884 .Attr<std::vector<int64_t>>("dilations")883 .Attr<std::vector<int64_t>>("dilations")
885 .Attr<int64_t>("groups")884 .Attr<int64_t>("groups")
886- .Attr<int64_t>("has_relu")
887 .Attr<std::string>("pad_mode")885 .Attr<std::string>("pad_mode")
888 .Attr<std::string>("data_format")886 .Attr<std::string>("data_format")
889 .Attr<int64_t>("offset_x")887 .Attr<int64_t>("offset_x")
890 .Attr<bool>("enable_hf32")888 .Attr<bool>("enable_hf32")
889+ .Attr<int64_t>("fixed_shift_value")
891 .ComputeType(ComputeType::kComputeCube)890 .ComputeType(ComputeType::kComputeCube)
892 .Impl(v1_soc_versions, {af::ascir::AscIrImplCreator<Conv2DAscIrAttImpl>(),891 .Impl(v1_soc_versions, {af::ascir::AscIrImplCreator<Conv2DAscIrAttImpl>(),
893 af::ascir::AscIrImplCreator<af::ascir::Conv2DAscIrCodegenImpl>(),892 af::ascir::AscIrImplCreator<af::ascir::Conv2DAscIrCodegenImpl>(),
894- {{"T1", TensorType{DT_FLOAT16, DT_FLOAT, DT_BF16, DT_HIFLOAT8}},893+ {{"T1", TensorType{DT_FLOAT16}}, {"T2", TensorType{DT_FLOAT16}}}});
895- {"T2", TensorType{DT_FLOAT16, DT_FLOAT, DT_BF16, DT_HIFLOAT8}}}});
896 894 
897REG_ASC_IR(Conv2DOffset)895REG_ASC_IR(Conv2DOffset)
898 .Input("x", "T1")896 .Input("x", "T1")
@@ -903,17 +901,16 @@ REG_ASC_IR(Conv2DOffset)
903 .Attr<std::vector<int64_t>>("pads")901 .Attr<std::vector<int64_t>>("pads")
904 .Attr<std::vector<int64_t>>("dilations")902 .Attr<std::vector<int64_t>>("dilations")
905 .Attr<int64_t>("groups")903 .Attr<int64_t>("groups")
906- .Attr<int64_t>("has_relu")
907 .Attr<std::string>("pad_mode")904 .Attr<std::string>("pad_mode")
908 .Attr<std::string>("data_format")905 .Attr<std::string>("data_format")
909 .Attr<int64_t>("offset_x")906 .Attr<int64_t>("offset_x")
910 .Attr<bool>("enable_hf32")907 .Attr<bool>("enable_hf32")
908+ .Attr<int64_t>("fixed_shift_value")
911 .ComputeType(ComputeType::kComputeCube)909 .ComputeType(ComputeType::kComputeCube)
912- .Impl(v1_soc_versions, {af::ascir::AscIrImplCreator<Conv2DAscIrAttImpl>(),910+ .Impl(v1_soc_versions,
913- af::ascir::AscIrImplCreator<af::ascir::Conv2DAscIrCodegenImpl>(),911+ {af::ascir::AscIrImplCreator<Conv2DAscIrAttImpl>(),
914- {{"T1", TensorType{DT_FLOAT16, DT_FLOAT, DT_BF16, DT_HIFLOAT8}},912+ af::ascir::AscIrImplCreator<af::ascir::Conv2DAscIrCodegenImpl>(),
915- {"T2", TensorType{DT_FLOAT16, DT_FLOAT, DT_BF16, DT_HIFLOAT8}},913+ {{"T1", TensorType{DT_FLOAT16}}, {"T2", TensorType{DT_FLOAT16}}, {"T3", TensorType{DT_INT8}}}});
916- {"T3", TensorType{DT_INT8}}}});
917 914 
918REG_ASC_IR(Conv2DOffsetBias)915REG_ASC_IR(Conv2DOffsetBias)
919 .Input("x", "T1")916 .Input("x", "T1")
@@ -925,17 +922,105 @@ REG_ASC_IR(Conv2DOffsetBias)
925 .Attr<std::vector<int64_t>>("pads")922 .Attr<std::vector<int64_t>>("pads")
926 .Attr<std::vector<int64_t>>("dilations")923 .Attr<std::vector<int64_t>>("dilations")
927 .Attr<int64_t>("groups")924 .Attr<int64_t>("groups")
928- .Attr<int64_t>("has_relu")
929 .Attr<std::string>("pad_mode")925 .Attr<std::string>("pad_mode")
930 .Attr<std::string>("data_format")926 .Attr<std::string>("data_format")
931 .Attr<int64_t>("offset_x")927 .Attr<int64_t>("offset_x")
932 .Attr<bool>("enable_hf32")928 .Attr<bool>("enable_hf32")
929+ .Attr<int64_t>("fixed_shift_value")
930+ .ComputeType(ComputeType::kComputeCube)
931+ .Impl(v1_soc_versions,
932+ {af::ascir::AscIrImplCreator<Conv2DAscIrAttImpl>(),
933+ af::ascir::AscIrImplCreator<af::ascir::Conv2DAscIrCodegenImpl>(),
934+ {{"T1", TensorType{DT_FLOAT16}}, {"T2", TensorType{DT_FLOAT16}}, {"T3", TensorType{DT_INT8}}}});
935+ 
936+REG_ASC_IR(ExtendConv2D)
937+ .Input("x", "T1")
938+ .Input("filter", "T1")
939+ .Output("y", "T2")
940+ .Attr<std::vector<int64_t>>("strides")
941+ .Attr<std::vector<int64_t>>("pads")
942+ .Attr<std::vector<int64_t>>("dilations")
943+ .Attr<int64_t>("groups")
944+ .Attr<std::string>("pad_mode")
945+ .Attr<std::string>("data_format")
946+ .Attr<int64_t>("offset_x")
947+ .Attr<std::string>("round_mode")
948+ .Attr<bool>("enable_hf32")
949+ .Attr<int64_t>("fixed_shift_value")
950+ .Attr<bool>("enable_relu0")
933 .ComputeType(ComputeType::kComputeCube)951 .ComputeType(ComputeType::kComputeCube)
934 .Impl(v1_soc_versions, {af::ascir::AscIrImplCreator<Conv2DAscIrAttImpl>(),952 .Impl(v1_soc_versions, {af::ascir::AscIrImplCreator<Conv2DAscIrAttImpl>(),
935 af::ascir::AscIrImplCreator<af::ascir::Conv2DAscIrCodegenImpl>(),953 af::ascir::AscIrImplCreator<af::ascir::Conv2DAscIrCodegenImpl>(),
936- {{"T1", TensorType{DT_FLOAT16, DT_FLOAT, DT_BF16, DT_HIFLOAT8}},954+ {{"T1", TensorType{DT_FLOAT16}}, {"T2", TensorType{DT_FLOAT16}}}});
937- {"T2", TensorType{DT_FLOAT16, DT_FLOAT, DT_BF16, DT_HIFLOAT8}},955+ 
938- {"T3", TensorType{DT_INT8}}}});956+REG_ASC_IR(ExtendConv2DBias)
957+ .Input("x", "T1")
958+ .Input("filter", "T1")
959+ .Input("bias", "T2")
960+ .Output("y", "T3")
961+ .Attr<std::vector<int64_t>>("strides")
962+ .Attr<std::vector<int64_t>>("pads")
963+ .Attr<std::vector<int64_t>>("dilations")
964+ .Attr<int64_t>("groups")
965+ .Attr<std::string>("pad_mode")
966+ .Attr<std::string>("data_format")
967+ .Attr<int64_t>("offset_x")
968+ .Attr<std::string>("round_mode")
969+ .Attr<bool>("enable_hf32")
970+ .Attr<int64_t>("fixed_shift_value")
971+ .Attr<bool>("enable_relu0")
972+ .ComputeType(ComputeType::kComputeCube)
973+ .Impl(v1_soc_versions,
974+ {af::ascir::AscIrImplCreator<Conv2DAscIrAttImpl>(),
975+ af::ascir::AscIrImplCreator<af::ascir::Conv2DAscIrCodegenImpl>(),
976+ {{"T1", TensorType{DT_FLOAT16}}, {"T2", TensorType{DT_FLOAT16}}, {"T3", TensorType{DT_FLOAT16}}}});
977+ 
978+REG_ASC_IR(ExtendConv2DScale)
979+ .Input("x", "T1")
980+ .Input("filter", "T1")
981+ .Input("scale0", "T3")
982+ .Output("y", "T2")
983+ .Attr<std::vector<int64_t>>("strides")
984+ .Attr<std::vector<int64_t>>("pads")
985+ .Attr<std::vector<int64_t>>("dilations")
986+ .Attr<int64_t>("groups")
987+ .Attr<std::string>("pad_mode")
988+ .Attr<std::string>("data_format")
989+ .Attr<int64_t>("offset_x")
990+ .Attr<std::string>("round_mode")
991+ .Attr<bool>("enable_hf32")
992+ .Attr<int64_t>("fixed_shift_value")
993+ .Attr<bool>("enable_relu0")
994+ .ComputeType(ComputeType::kComputeCube)
995+ .Impl(v1_soc_versions,
996+ {af::ascir::AscIrImplCreator<Conv2DAscIrAttImpl>(),
997+ af::ascir::AscIrImplCreator<af::ascir::Conv2DAscIrCodegenImpl>(),
998+ {{"T1", TensorType{DT_INT8}}, {"T2", TensorType{DT_FLOAT16}}, {"T3", TensorType{DT_UINT64}}}});
999+ 
1000+REG_ASC_IR(ExtendConv2DBiasScale)
1001+ .Input("x", "T1")
1002+ .Input("filter", "T1")
1003+ .Input("bias", "T2")
1004+ .Input("scale0", "T4")
1005+ .Output("y", "T3")
1006+ .Attr<std::vector<int64_t>>("strides")
1007+ .Attr<std::vector<int64_t>>("pads")
1008+ .Attr<std::vector<int64_t>>("dilations")
1009+ .Attr<int64_t>("groups")
1010+ .Attr<std::string>("pad_mode")
1011+ .Attr<std::string>("data_format")
1012+ .Attr<int64_t>("offset_x")
1013+ .Attr<std::string>("round_mode")
1014+ .Attr<bool>("enable_hf32")
1015+ .Attr<int64_t>("fixed_shift_value")
1016+ .Attr<bool>("enable_relu0")
1017+ .ComputeType(ComputeType::kComputeCube)
1018+ .Impl(v1_soc_versions, {af::ascir::AscIrImplCreator<Conv2DAscIrAttImpl>(),
1019+ af::ascir::AscIrImplCreator<af::ascir::Conv2DAscIrCodegenImpl>(),
1020+ {{"T1", TensorType{DT_INT8}},
1021+ {"T2", TensorType{DT_INT32}},
1022+ {"T3", TensorType{DT_FLOAT16}},
1023+ {"T4", TensorType{DT_UINT64}}}});
939 1024 
940REG_ASC_IR(Split).Input("x", "T").DynamicOutput("y", "T").Attr<int64_t>("index").Attr<int64_t>(1025REG_ASC_IR(Split).Input("x", "T").DynamicOutput("y", "T").Attr<int64_t>("index").Attr<int64_t>(
941 "gid"); // global_id, SplitOp的全局编号1026 "gid"); // global_id, SplitOp的全局编号
@@ -2530,7 +2530,8 @@ std::string Kernel::KernelFuncDeclare(const std::string &graph_name,
2530 if (is_conv2d) {2530 if (is_conv2d) {
2531 ss << "template<int8_t FmapTiling, int8_t WeightTiling, int8_t L1PingPong, int8_t L0PingPong, int8_t "2531 ss << "template<int8_t FmapTiling, int8_t WeightTiling, int8_t L1PingPong, int8_t L0PingPong, int8_t "
2532 "OutputOrder, int8_t IterOrder, int8_t GroupType, int8_t EnableSmallChannel, int8_t WeightUbTrans, int8_t "2532 "OutputOrder, int8_t IterOrder, int8_t GroupType, int8_t EnableSmallChannel, int8_t WeightUbTrans, int8_t "
2533- "FmapCopyMode, int8_t InnerBatch, int8_t DisContinuous > "2533+ "FmapCopyMode, int8_t InnerBatch, int8_t DisContinuous, int8_t BatchOne, int8_t NoPad, int8_t SmallWeight, "
2534+ "int8_t SmallKernel> "
2534 << std::endl;2535 << std::endl;
2535 } else {2536 } else {
2536 if (is_inductor) {2537 if (is_inductor) {
@@ -3297,7 +3298,7 @@ af::Status Kernel::GenCubeCommonTiling(std::stringstream &ss, const bool is_batc
3297 ss << "AscendC::TPipe pipe;" << std::endl;3298 ss << "AscendC::TPipe pipe;" << std::endl;
3298 ss << " conv2d_v2<";3299 ss << " conv2d_v2<";
3299 ss << "FmapTiling, WeightTiling, L1PingPong, L0PingPong, OutputOrder, IterOrder, GroupType, EnableSmallChannel, "3300 ss << "FmapTiling, WeightTiling, L1PingPong, L0PingPong, OutputOrder, IterOrder, GroupType, EnableSmallChannel, "
3300- "WeightUbTrans, FmapCopyMode, InnerBatch, DisContinuous>(";3301+ "WeightUbTrans, FmapCopyMode, InnerBatch, DisContinuous, BatchOne, NoPad, SmallWeight, SmallKernel>(";
3301 } else {3302 } else {
3302 if (is_dynamic) {3303 if (is_dynamic) {
3303 if (is_db) {3304 if (is_db) {
@@ -3333,48 +3334,83 @@ af::Status Kernel::GenCubeCommonTiling(std::stringstream &ss, const bool is_batc
3333 return af::SUCCESS;3334 return af::SUCCESS;
3334}3335}
3335 3336 
3336-std::string Kernel::GenCubeTilingSingleFuncCall(const bool is_batch, const bool is_cv_fuse, bool is_bias,3337+namespace {
3337- bool is_offset_w, bool is_conv2d, bool is_dynamic, bool is_db) const {3338+Status AppendConv2DInputArgs(std::stringstream &ss, const std::vector<Variable> &inputs,
3338- std::stringstream ss;3339+ const CubeTilingOptions &options) {
3339- GE_CHK_STATUS(GenCubeCommonTiling(ss, is_batch, is_conv2d, is_dynamic, is_db), "GenCubeCommonTilingHead failed");3340+ ss << inputs[0].Str() << ", " << inputs[1].Str() << ", ";
3341+ size_t next_input_idx = 2U;
3342+ for (const bool is_present : {options.has_bias, options.has_offset_w, options.has_scale0}) {
3343+ ss << (is_present ? inputs[next_input_idx++].Str() : "nullptr") << ", ";
3344+ }
3345+ return af::SUCCESS;
3346+}
3340 3347 
3341- if (use_list_tensor_) {3348+Status AppendMatMulInputArgs(std::stringstream &ss, const std::vector<Variable> &inputs,
3349+ const CubeTilingOptions &options) {
3350+ if (inputs.size() < (2U + (options.has_bias ? 1U : 0U) + (options.has_offset_w ? 1U : 0U))) {
3351+ // a、b 矩阵同输入时 AscGraph 有两个输入,但 AscBackend 只有一个,需补齐第二个实参。
3352+ ss << inputs[0].Str() << ", ";
3353+ }
3354+ for (const auto &input : inputs) {
3355+ ss << input.Str() << ", ";
3356+ }
3357+ if (!options.has_bias) {
3358+ ss << "nullptr, ";
3359+ }
3360+ if (!options.has_offset_w) {
3361+ ss << "nullptr, ";
3362+ }
3363+ return af::SUCCESS;
3364+}
3365+ 
3366+Status AppendCubeInputArgs(std::stringstream &ss, const std::vector<Variable> &inputs,
3367+ const CubeTilingOptions &options) {
3368+ return options.is_conv2d ? AppendConv2DInputArgs(ss, inputs, options) : AppendMatMulInputArgs(ss, inputs, options);
3369+}
3370+ 
3371+void AppendCubeOutputArgs(std::stringstream &ss, const std::vector<GM_ADDR> &outputs,
3372+ const std::string &empty_output_arg) {
3373+ for (const auto &output : outputs) {
3374+ ss << output.Str() << ", ";
3375+ }
3376+ if (outputs.empty()) {
3377+ ss << empty_output_arg << ", ";
3378+ }
3379+}
3380+ 
3381+CubeTilingOptions GetCubeTilingOptions(const ascir::ImplGraph &impl_graph) {
3382+ CubeTilingOptions options;
3383+ options.is_conv2d = IsConv2DGraphType(impl_graph);
3384+ if (options.is_conv2d) {
3385+ options.has_bias = ascgen_utils::IsConv2DTypeWithBias(impl_graph);
3386+ options.has_offset_w = ascgen_utils::IsConv2DTypeWithOffsetW(impl_graph);
3387+ options.has_scale0 = ascgen_utils::IsConv2DTypeWithScale0(impl_graph);
3388+ } else {
3389+ options.is_batch = ascgen_utils::IsMatMulTypeWithBatch(impl_graph);
3390+ options.has_bias = ascgen_utils::IsMatMulTypeWithBias(impl_graph);
3391+ options.has_offset_w = ascgen_utils::IsMatMulTypeWithOffsetW(impl_graph);
3392+ }
3393+ return options;
3394+}
3395+} // namespace
3396+ 
3397+std::string Kernel::GenCubeTilingSingleFuncCall(const CubeTilingOptions &options) const {
3398+ std::stringstream ss;
3399+ GE_CHK_STATUS(GenCubeCommonTiling(ss, options.is_batch, options.is_conv2d, options.is_dynamic, options.is_db),
3400+ "GenCubeCommonTilingHead failed");
3401+ if (this->use_list_tensor_) {
3342 ss << kInputTensorDescName << ", " << kOutputTensorDescName << ", ";3402 ss << kInputTensorDescName << ", " << kOutputTensorDescName << ", ";
3343 } else {3403 } else {
3344- if (this->inputs.size() < (2U + (is_bias ? 1U : 0U) + (is_offset_w ? 1U : 0U))) {3404+ if (options.is_conv2d) {
3345- ss << this->inputs[0].Str()3405+ GE_ASSERT_TRUE(this->inputs.size() >= 2U, "conv2d inputs num [%u] < 2", this->inputs.size());
3346- << ", "; // a矩阵、b矩阵同输入存在ascgraph的matmul有两个输入,Ascackend只有一个输入,需多加一个
3347- }
3348- for (auto &input : this->inputs) {
3349- ss << input.Str() << ", ";
3350- }
3351- if (!is_bias) { // 无bias场景
3352- ss << "nullptr, ";
3353- }
3354- if (!is_offset_w) { // 无offset_w场景
3355- ss << "nullptr, ";
3356- }
3357- for (auto &output : this->outputs) {
3358- ss << output.Str() << ", ";
3359- }
3360- if (this->outputs.empty()) {
3361- ss << (is_cv_fuse ? "nullptr, " : "output_0, ");
3362 }3406 }
3407+ GE_CHK_STATUS(AppendCubeInputArgs(ss, this->inputs, options), "Append cube input arguments failed");
3408+ AppendCubeOutputArgs(ss, this->outputs, options.is_cv_fuse ? "nullptr" : "output_0");
3363 }3409 }
3364 ss << this->workspace_arg.Str() << ", ";3410 ss << this->workspace_arg.Str() << ", ";
3365 ss << "gm_tiling_data";3411 ss << "gm_tiling_data";
3366- if (is_cv_fuse) {3412+ if (options.is_cv_fuse) {
3367- if (is_dynamic) {3413+ ss << (options.is_dynamic && options.is_db ? ", &CV_FUSION_ADDR_DB" : ", &CV_FUSION_ADDR");
3368- if (is_db) {
3369- ss << ", &CV_FUSION_ADDR_DB";
3370- } else {
3371- ss << ", &CV_FUSION_ADDR";
3372- }
3373- } else {
3374- ss << ", &CV_FUSION_ADDR";
3375- }
3376- } else {
3377- ss << "";
3378 }3414 }
3379 ss << ");" << std::endl;3415 ss << ");" << std::endl;
3380 return ss.str();3416 return ss.str();
@@ -3382,43 +3418,25 @@ std::string Kernel::GenCubeTilingSingleFuncCall(const bool is_batch, const bool
3382 3418 
3383std::string Kernel::GenCubeCommonTilingSingleFuncCall(const ascir::ImplGraph &impl_graph,3419std::string Kernel::GenCubeCommonTilingSingleFuncCall(const ascir::ImplGraph &impl_graph,
3384 const std::string &output_arg_override) const {3420 const std::string &output_arg_override) const {
3385- bool is_batch = false;3421+ const auto options = GetCubeTilingOptions(impl_graph);
3386- bool has_bias = false;
3387- bool has_offset_w = false;
3388- bool is_conv2d = IsConv2DGraphType(impl_graph);
3389- if (is_conv2d) {
3390- has_bias = ascgen_utils::IsConv2DTypeWithBias(impl_graph);
3391- has_offset_w = ascgen_utils::IsConv2DTypeWithOffsetW(impl_graph);
3392- } else {
3393- is_batch = ascgen_utils::IsMatMulTypeWithBatch(impl_graph);
3394- has_bias = ascgen_utils::IsMatMulTypeWithBias(impl_graph);
3395- has_offset_w = ascgen_utils::IsMatMulTypeWithOffsetW(impl_graph);
3396- }
3397 std::stringstream ss;3422 std::stringstream ss;
3398- GE_CHK_STATUS(GenCubeCommonTiling(ss, is_batch, is_conv2d), "GenCubeCommonTilingHead failed");3423+ GE_CHK_STATUS(GenCubeCommonTiling(ss, options.is_batch, options.is_conv2d), "GenCubeCommonTilingHead failed");
3399- if (use_list_tensor_) {3424+ if (this->use_list_tensor_) {
3400 ss << kInputTensorDescName << ", " << kOutputTensorDescName << ", ";3425 ss << kInputTensorDescName << ", " << kOutputTensorDescName << ", ";
3401 } else {3426 } else {
3402- auto min_inputs_num = 1U + (has_bias ? 1U : 0U) + (has_offset_w ? 1U : 0U);3427+ if (options.is_conv2d) {
3403- GE_ASSERT_TRUE(this->inputs.size() >= min_inputs_num, "cube inputs num [%u] < min_inputs_num [%u]",3428+ auto min_inputs_num =
3404- this->inputs.size(), min_inputs_num);3429+ 2U + (options.has_bias ? 1U : 0U) + (options.has_offset_w ? 1U : 0U) + (options.has_scale0 ? 1U : 0U);
3405- // a矩阵、b矩阵同输入存在ascgraph的matmul有两个输入,Ascackend只有一个输入,需多加一个输入再生成kernel函数3430+ GE_ASSERT_TRUE(this->inputs.size() >= min_inputs_num, "conv2d inputs num [%u] < min_inputs_num [%u]",
3406- (this->inputs.size() == min_inputs_num) ? (ss << this->inputs[0].Str() << ", ") : (ss << "");3431+ this->inputs.size(), min_inputs_num);
3407- for (auto &input : this->inputs) {3432+ } else {
3408- ss << input.Str() << ", ";3433+ auto min_inputs_num = 1U + (options.has_bias ? 1U : 0U) + (options.has_offset_w ? 1U : 0U);
3409- }3434+ GE_ASSERT_TRUE(this->inputs.size() >= min_inputs_num, "cube inputs num [%u] < min_inputs_num [%u]",
3410- if (!has_bias) { // 无bias场景3435+ this->inputs.size(), min_inputs_num);
3411- ss << "nullptr, ";
3412- }
3413- if (!has_offset_w) { // 无offset_w场景
3414- ss << "nullptr, ";
3415- }
3416- for (auto &output : this->outputs) {
3417- ss << output.Str() << ", ";
3418- }
3419- if (this->outputs.empty()) {
3420- ss << (output_arg_override.empty() ? this->workspace_arg.Str() : output_arg_override) << ", ";
3421 }3436 }
3437+ GE_CHK_STATUS(AppendCubeInputArgs(ss, this->inputs, options), "Append cube input arguments failed");
3438+ AppendCubeOutputArgs(ss, this->outputs,
3439+ output_arg_override.empty() ? this->workspace_arg.Str() : output_arg_override);
3422 }3440 }
3423 ss << this->workspace_arg.Str();3441 ss << this->workspace_arg.Str();
3424 // cube workspace的位置需要计算 workspace + vector的偏移3442 // cube workspace的位置需要计算 workspace + vector的偏移
@@ -3427,30 +3445,24 @@ std::string Kernel::GenCubeCommonTilingSingleFuncCall(const ascir::ImplGraph &im
3427}3445}
3428 3446 
3429std::string Kernel::GenCubeTilingFuncCall(const ascir::ImplGraph &impl_graph, bool is_dynamic) const {3447std::string Kernel::GenCubeTilingFuncCall(const ascir::ImplGraph &impl_graph, bool is_dynamic) const {
3430- bool is_batch = false;3448+ auto options = GetCubeTilingOptions(impl_graph);
3431- bool is_bias = false;3449+ options.is_dynamic = is_dynamic;
3432- bool is_offset_w = false;
3433- bool is_conv2d = IsConv2DGraphType(impl_graph);
3434- if (is_conv2d) {
3435- is_bias = ascgen_utils::IsConv2DTypeWithBias(impl_graph);
3436- is_offset_w = ascgen_utils::IsConv2DTypeWithOffsetW(impl_graph);
3437- } else {
3438- is_batch = ascgen_utils::IsMatMulTypeWithBatch(impl_graph);
3439- is_bias = ascgen_utils::IsMatMulTypeWithBias(impl_graph);
3440- is_offset_w = ascgen_utils::IsMatMulTypeWithOffsetW(impl_graph);
3441- }
3442 std::stringstream ss;3450 std::stringstream ss;
3443 if (is_dynamic) {3451 if (is_dynamic) {
3452+ options.is_cv_fuse = true;
3444 ss << "if constexpr (UB_MODE == 0) {" << std::endl;3453 ss << "if constexpr (UB_MODE == 0) {" << std::endl;
3445- ss << GenCubeTilingSingleFuncCall(is_batch, true, is_bias, is_offset_w, is_conv2d, true, false);3454+ ss << GenCubeTilingSingleFuncCall(options);
3446 ss << "} else {" << std::endl;3455 ss << "} else {" << std::endl;
3447- ss << GenCubeTilingSingleFuncCall(is_batch, true, is_bias, is_offset_w, is_conv2d, true, true);3456+ options.is_db = true;
3457+ ss << GenCubeTilingSingleFuncCall(options);
3448 ss << "}" << std::endl;3458 ss << "}" << std::endl;
3449 } else {3459 } else {
3450 ss << "#ifdef CV_UB_FUSION" << std::endl;3460 ss << "#ifdef CV_UB_FUSION" << std::endl;
3451- ss << GenCubeTilingSingleFuncCall(is_batch, true, is_bias, is_offset_w, is_conv2d);3461+ options.is_cv_fuse = true;
3462+ ss << GenCubeTilingSingleFuncCall(options);
3452 ss << "#else" << std::endl;3463 ss << "#else" << std::endl;
3453- ss << GenCubeTilingSingleFuncCall(is_batch, false, is_bias, is_offset_w, is_conv2d);3464+ options.is_cv_fuse = false;
3465+ ss << GenCubeTilingSingleFuncCall(options);
3454 ss << "#endif" << std::endl;3466 ss << "#endif" << std::endl;
3455 }3467 }
3456 return ss.str();3468 return ss.str();
@@ -4150,7 +4162,7 @@ class AutoFusionVector {
4150 result << std::endl;4162 result << std::endl;
4151 result << "GET_TILING_DATA_WITH_STRUCT(Conv2DTilingData, tmpTilingData, tmpTilingGM);" << std::endl;4163 result << "GET_TILING_DATA_WITH_STRUCT(Conv2DTilingData, tmpTilingData, tmpTilingGM);" << std::endl;
4152 result << "const int32_t ub_align_value = 32 / sizeof(" << dtype_name << ");" << std::endl;4164 result << "const int32_t ub_align_value = 32 / sizeof(" << dtype_name << ");" << std::endl;
4153- result << "const int32_t basen_align = (tmpTilingData.conv2dApiTiling.hoL0 + ub_align_value - 1) / "4165+ result << "const int32_t basen_align = (tmpTilingData.hoL0 + ub_align_value - 1) / "
X
Xxuyafei8月18日

整体调整了还是说只针对了量化场景

likedislike
hemahema
hemahema
8月19日 评论:
4154 "ub_align_value * ub_align_value;"4166 "ub_align_value * ub_align_value;"
4155 << std::endl;4167 << std::endl;
4156 std::string npu_arch;4168 std::string npu_arch;
@@ -4159,8 +4171,7 @@ class AutoFusionVector {
4159 if (npu_arch == "5102") {4171 if (npu_arch == "5102") {
4160 vec_num = 1;4172 vec_num = 1;
4161 }4173 }
4162- result << "stage_size1 = KernelUtils::Max(tmpTilingData.conv2dApiTiling.nL0 / " << vec_num << ", 16) * basen_align;"4174+ result << "stage_size1 = KernelUtils::Max(tmpTilingData.nL0 / " << vec_num << ", 16) * basen_align;" << std::endl;
4163- << std::endl;
4164 if (is_dynamic && is_inductor) {4175 if (is_dynamic && is_inductor) {
4165 result << "#ifdef INDUCTOR_CONST_TILING_DATA" << std::endl;4176 result << "#ifdef INDUCTOR_CONST_TILING_DATA" << std::endl;
4166 result << "const uint32_t stage_size_name = kConstTilingData.tiling_data.STAGE_SIZE_NAME;" << std::endl;4177 result << "const uint32_t stage_size_name = kConstTilingData.tiling_data.STAGE_SIZE_NAME;" << std::endl;
@@ -381,6 +381,17 @@ struct TilingFuncCall {
381 bool need_sync_all_;381 bool need_sync_all_;
382};382};
383 383 
384+struct CubeTilingOptions {
385+ bool is_batch{false};
386+ bool is_cv_fuse{false};
387+ bool has_bias{false};
388+ bool has_offset_w{false};
389+ bool has_scale0{false};
390+ bool is_conv2d{false};
391+ bool is_dynamic{false};
392+ bool is_db{false};
393+};
394+ 
384class Kernel {395class Kernel {
385 public:396 public:
386 GM_ADDR workspace_arg;397 GM_ADDR workspace_arg;
@@ -418,8 +429,7 @@ class Kernel {
418 const std::string &workspace_tiling_data = "t") const;429 const std::string &workspace_tiling_data = "t") const;
419 std::string GenTilingFuncCall(const std::string &impl_graph_name, const std::string &tiling_data) const;430 std::string GenTilingFuncCall(const std::string &impl_graph_name, const std::string &tiling_data) const;
420 std::string GenCubeTilingFuncCall(const ascir::ImplGraph &impl_graph, bool is_dynamic = false) const;431 std::string GenCubeTilingFuncCall(const ascir::ImplGraph &impl_graph, bool is_dynamic = false) const;
421- std::string GenCubeTilingSingleFuncCall(const bool is_batch, const bool is_cv_fuse, bool is_bias, bool is_offset_w,432+ std::string GenCubeTilingSingleFuncCall(const CubeTilingOptions &options) const;
422- bool is_conv2d, bool is_dynamic = false, bool is_db = false) const;
423 af::Status GenCubeCommonTiling(std::stringstream &ss, const bool is_batch, bool is_conv2d = false,433 af::Status GenCubeCommonTiling(std::stringstream &ss, const bool is_batch, bool is_conv2d = false,
424 bool is_dynamic = false, bool is_db = false) const;434 bool is_dynamic = false, bool is_db = false) const;
425 std::string GenCubeCommonTilingSingleFuncCall(const ascir::ImplGraph &impl_graph,435 std::string GenCubeCommonTilingSingleFuncCall(const ascir::ImplGraph &impl_graph,
@@ -215,6 +215,10 @@ static const std::map<std::string, af::ComputeType> kOpTypeToComputeType = {
215 {Conv2DBias::Type, af::ComputeType::kComputeCube},215 {Conv2DBias::Type, af::ComputeType::kComputeCube},
216 {Conv2DOffset::Type, af::ComputeType::kComputeCube},216 {Conv2DOffset::Type, af::ComputeType::kComputeCube},
217 {Conv2DOffsetBias::Type, af::ComputeType::kComputeCube},217 {Conv2DOffsetBias::Type, af::ComputeType::kComputeCube},
218+ {ExtendConv2D::Type, af::ComputeType::kComputeCube},
219+ {ExtendConv2DBias::Type, af::ComputeType::kComputeCube},
220+ {ExtendConv2DScale::Type, af::ComputeType::kComputeCube},
221+ {ExtendConv2DBiasScale::Type, af::ComputeType::kComputeCube},
218};222};
219 223 
220static const std::map<af::ComputeType, Completer> kComputeTypeToCompleter = {224static const std::map<af::ComputeType, Completer> kComputeTypeToCompleter = {
@@ -837,7 +837,8 @@ bool IsMatMulTypeWithOffsetW(const ascir::ImplGraph &impl_graph) {
837 837 
838bool IsConv2DTypeWithBias(const ascir::ImplGraph &impl_graph) {838bool IsConv2DTypeWithBias(const ascir::ImplGraph &impl_graph) {
839 for (const auto &node : impl_graph.GetAllNodes()) {839 for (const auto &node : impl_graph.GetAllNodes()) {
840- if ((node->GetType() == kConv2DBias) || (node->GetType() == kConv2DOffsetBias)) {840+ if ((node->GetType() == kConv2DBias) || (node->GetType() == kConv2DOffsetBias) ||
841+ (node->GetType() == kExtendConv2DBias) || (node->GetType() == kExtendConv2DBiasScale)) {
841 return true;842 return true;
842 }843 }
843 }844 }
@@ -853,10 +854,22 @@ bool IsConv2DTypeWithOffsetW(const ascir::ImplGraph &impl_graph) {
853 return false;854 return false;
854}855}
855 856 
857+bool IsConv2DTypeWithScale0(const ascir::ImplGraph &impl_graph) {
858+ // scale0 仅出现在 ExtendConv2DScale / ExtendConv2DBiasScale 变体中。
859+ for (const auto &node : impl_graph.GetAllNodes()) {
860+ if ((node->GetType() == kExtendConv2DScale) || (node->GetType() == kExtendConv2DBiasScale)) {
861+ return true;
862+ }
863+ }
864+ return false;
865+}
866+ 
856bool IsConv2DGraphType(const ascir::ImplGraph &impl_graph) {867bool IsConv2DGraphType(const ascir::ImplGraph &impl_graph) {
857 for (const auto &node : impl_graph.GetAllNodes()) {868 for (const auto &node : impl_graph.GetAllNodes()) {
858 if ((node->GetType() == kConv2DOffset) || (node->GetType() == kConv2DOffsetBias) ||869 if ((node->GetType() == kConv2DOffset) || (node->GetType() == kConv2DOffsetBias) ||
859- (node->GetType() == kConv2DBias) || (node->GetType() == kConv2D)) {870+ (node->GetType() == kConv2DBias) || (node->GetType() == kConv2D) || (node->GetType() == kExtendConv2D) ||
871+ (node->GetType() == kExtendConv2DBias) || (node->GetType() == kExtendConv2DScale) ||
872+ (node->GetType() == kExtendConv2DBiasScale)) {
860 return true;873 return true;
861 }874 }
862 }875 }
@@ -957,14 +970,30 @@ af::Status ParseConv2DAttr(const ascir::NodeView &node, Conv2DAttr &conv_attr_da
957 GET_CONV2D_ATTRS(node, Conv2D, conv_attr_data);970 GET_CONV2D_ATTRS(node, Conv2D, conv_attr_data);
958 } else if (node->GetType() == kConv2DBias) {971 } else if (node->GetType() == kConv2DBias) {
959 GET_CONV2D_ATTRS(node, Conv2DBias, conv_attr_data);972 GET_CONV2D_ATTRS(node, Conv2DBias, conv_attr_data);
960- conv_attr_data.is_bias = true;973+ conv_attr_data.has_bias = true;
961 } else if (node->GetType() == kConv2DOffset) {974 } else if (node->GetType() == kConv2DOffset) {
962 GET_CONV2D_ATTRS(node, Conv2DOffset, conv_attr_data);975 GET_CONV2D_ATTRS(node, Conv2DOffset, conv_attr_data);
963- conv_attr_data.is_offset_w = true;976+ conv_attr_data.has_offset_w = true;
964 } else if (node->GetType() == kConv2DOffsetBias) {977 } else if (node->GetType() == kConv2DOffsetBias) {
965 GET_CONV2D_ATTRS(node, Conv2DOffsetBias, conv_attr_data);978 GET_CONV2D_ATTRS(node, Conv2DOffsetBias, conv_attr_data);
966- conv_attr_data.is_bias = true;979+ conv_attr_data.has_bias = true;
967- conv_attr_data.is_offset_w = true;980+ conv_attr_data.has_offset_w = true;
981+ } else if (node->GetType() == kExtendConv2D) {
982+ GET_EXTEND_CONV2D_ATTRS(node, ExtendConv2D, conv_attr_data);
983+ conv_attr_data.is_extend_conv2d = true;
984+ } else if (node->GetType() == kExtendConv2DBias) {
985+ GET_EXTEND_CONV2D_ATTRS(node, ExtendConv2DBias, conv_attr_data);
986+ conv_attr_data.is_extend_conv2d = true;
987+ conv_attr_data.has_bias = true;
988+ } else if (node->GetType() == kExtendConv2DScale) {
989+ GET_EXTEND_CONV2D_ATTRS(node, ExtendConv2DScale, conv_attr_data);
990+ conv_attr_data.is_extend_conv2d = true;
991+ conv_attr_data.has_scale0 = true;
992+ } else if (node->GetType() == kExtendConv2DBiasScale) {
993+ GET_EXTEND_CONV2D_ATTRS(node, ExtendConv2DBiasScale, conv_attr_data);
994+ conv_attr_data.is_extend_conv2d = true;
995+ conv_attr_data.has_bias = true;
996+ conv_attr_data.has_scale0 = true;
968 } else {997 } else {
969 GELOGE(af::FAILED, "can't parse conv2d node attr, type=%s", node->GetType().c_str());998 GELOGE(af::FAILED, "can't parse conv2d node attr, type=%s", node->GetType().c_str());
970 }999 }
@@ -42,6 +42,10 @@ const std::string kConv2D = "Conv2D";
42const std::string kConv2DBias = "Conv2DBias";42const std::string kConv2DBias = "Conv2DBias";
43const std::string kConv2DOffset = "Conv2DOffset";43const std::string kConv2DOffset = "Conv2DOffset";
44const std::string kConv2DOffsetBias = "Conv2DOffsetBias";44const std::string kConv2DOffsetBias = "Conv2DOffsetBias";
45+const std::string kExtendConv2D = "ExtendConv2D";
46+const std::string kExtendConv2DBias = "ExtendConv2DBias";
47+const std::string kExtendConv2DScale = "ExtendConv2DScale";
48+const std::string kExtendConv2DBiasScale = "ExtendConv2DBiasScale";
45 49 
46struct MatMulAttr {50struct MatMulAttr {
47 int64_t transpose_x1{0};51 int64_t transpose_x1{0};
@@ -66,12 +70,18 @@ struct Conv2DAttr {
66 std::vector<int64_t> pads;70 std::vector<int64_t> pads;
67 std::vector<int64_t> dilations;71 std::vector<int64_t> dilations;
68 int64_t groups{1};72 int64_t groups{1};
69- std::string pad_mode{"SPECIFIC"};
70 std::string data_format{"NCHW"};73 std::string data_format{"NCHW"};
71 int64_t offset_x{0};74 int64_t offset_x{0};
75+ std::string round_mode{"rint"}; // ExtendConv2D only
76+ std::string pad_mode{"SPECIFIC"};
72 bool enable_hf32{false};77 bool enable_hf32{false};
73- bool is_bias{false};78+ int64_t fixed_shift_value{0};
74- bool is_offset_w{false};79+ bool enable_relu0{false}; // ExtendConv2D only
80+ // 以下字段非 op proto 属性,供 codegen / host tiling 选择入参布局与算子变体。
81+ bool has_bias{false};
82+ bool has_offset_w{false};
83+ bool has_scale0{false}; // ExtendConv2D only
84+ bool is_extend_conv2d{false};
75 std::string output_dtype;85 std::string output_dtype;
76 std::string input_dtype;86 std::string input_dtype;
77};87};
@@ -104,7 +114,14 @@ struct Conv2DAttr {
104 GE_ASSERT_SUCCESS(conv_attr->GetPad_mode(AttrData.pad_mode)); \114 GE_ASSERT_SUCCESS(conv_attr->GetPad_mode(AttrData.pad_mode)); \
105 GE_ASSERT_SUCCESS(conv_attr->GetData_format(AttrData.data_format)); \115 GE_ASSERT_SUCCESS(conv_attr->GetData_format(AttrData.data_format)); \
106 GE_ASSERT_SUCCESS(conv_attr->GetOffset_x(AttrData.offset_x)); \116 GE_ASSERT_SUCCESS(conv_attr->GetOffset_x(AttrData.offset_x)); \
107- GE_ASSERT_SUCCESS(conv_attr->GetEnable_hf32(AttrData.enable_hf32))117+ GE_ASSERT_SUCCESS(conv_attr->GetEnable_hf32(AttrData.enable_hf32)); \
118+ GE_ASSERT_SUCCESS(conv_attr->GetFixed_shift_value(AttrData.fixed_shift_value))
119+ 
120+// ExtendConv2D 相对 Conv2D 额外携带 round_mode / enable_relu0。
121+#define GET_EXTEND_CONV2D_ATTRS(Node, AttrType, AttrData) \
122+ GET_CONV2D_ATTRS(Node, AttrType, AttrData); \
123+ GE_ASSERT_SUCCESS(conv_attr->GetRound_mode(AttrData.round_mode)); \
124+ GE_ASSERT_SUCCESS(conv_attr->GetEnable_relu0(AttrData.enable_relu0))
108 125 
109struct MergeBrcAxisParams {126struct MergeBrcAxisParams {
110 const std::vector<af::Expression> &repeats;127 const std::vector<af::Expression> &repeats;
@@ -262,6 +279,7 @@ af::Status ParseConv2DAttr(const ascir::NodeView &node, Conv2DAttr &conv_attr_da
262bool IsConv2DGraphType(const ascir::ImplGraph &impl_graph);279bool IsConv2DGraphType(const ascir::ImplGraph &impl_graph);
263bool IsConv2DTypeWithBias(const ascir::ImplGraph &impl_graph);280bool IsConv2DTypeWithBias(const ascir::ImplGraph &impl_graph);
264bool IsConv2DTypeWithOffsetW(const ascir::ImplGraph &impl_graph);281bool IsConv2DTypeWithOffsetW(const ascir::ImplGraph &impl_graph);
282+bool IsConv2DTypeWithScale0(const ascir::ImplGraph &impl_graph);
265af::Status GetCubeInfo(const ascir::FusedScheduledResult &fused_schedule_result, bool &is_batch, bool &is_conv,283af::Status GetCubeInfo(const ascir::FusedScheduledResult &fused_schedule_result, bool &is_batch, bool &is_conv,
266 std::string &input_type, std::string &output_type);284 std::string &input_type, std::string &output_type);
267} // namespace ascgen_utils285} // namespace ascgen_utils
@@ -989,12 +989,17 @@ static bool ProcessConv2DNode(const af::AscNodePtr &node, PyObject *attr_dict) {
989 Py_DECREF(dilations_list);989 Py_DECREF(dilations_list);
990 990 
991 SET_DICT_LONG(attr_dict, "groups", conv_attr_data.groups);991 SET_DICT_LONG(attr_dict, "groups", conv_attr_data.groups);
992+ PyDict_SetItemString(attr_dict, "round_mode", PyUnicode_FromString(conv_attr_data.round_mode.c_str()));
992 PyDict_SetItemString(attr_dict, "pad_mode", PyUnicode_FromString(conv_attr_data.pad_mode.c_str()));993 PyDict_SetItemString(attr_dict, "pad_mode", PyUnicode_FromString(conv_attr_data.pad_mode.c_str()));
993 PyDict_SetItemString(attr_dict, "data_format", PyUnicode_FromString(conv_attr_data.data_format.c_str()));994 PyDict_SetItemString(attr_dict, "data_format", PyUnicode_FromString(conv_attr_data.data_format.c_str()));
994 SET_DICT_LONG(attr_dict, "offset_x", conv_attr_data.offset_x);995 SET_DICT_LONG(attr_dict, "offset_x", conv_attr_data.offset_x);
995 PyDict_SetItemString(attr_dict, "enable_hf32", conv_attr_data.enable_hf32 ? Py_True : Py_False);996 PyDict_SetItemString(attr_dict, "enable_hf32", conv_attr_data.enable_hf32 ? Py_True : Py_False);
996- PyDict_SetItemString(attr_dict, "is_bias", conv_attr_data.is_bias ? Py_True : Py_False);997+ SET_DICT_LONG(attr_dict, "fixed_shift_value", conv_attr_data.fixed_shift_value);
997- PyDict_SetItemString(attr_dict, "is_offset_w", conv_attr_data.is_offset_w ? Py_True : Py_False);998+ PyDict_SetItemString(attr_dict, "enable_relu0", conv_attr_data.enable_relu0 ? Py_True : Py_False);
999+ PyDict_SetItemString(attr_dict, "has_bias", conv_attr_data.has_bias ? Py_True : Py_False);
1000+ PyDict_SetItemString(attr_dict, "has_offset_w", conv_attr_data.has_offset_w ? Py_True : Py_False);
1001+ PyDict_SetItemString(attr_dict, "has_scale0", conv_attr_data.has_scale0 ? Py_True : Py_False);
1002+ PyDict_SetItemString(attr_dict, "is_extend_conv2d", conv_attr_data.is_extend_conv2d ? Py_True : Py_False);
998 PyDict_SetItemString(attr_dict, "output_dtype", PyUnicode_FromString(conv_attr_data.output_dtype.c_str()));1003 PyDict_SetItemString(attr_dict, "output_dtype", PyUnicode_FromString(conv_attr_data.output_dtype.c_str()));
999 PyDict_SetItemString(attr_dict, "input_dtype", PyUnicode_FromString(conv_attr_data.input_dtype.c_str()));1004 PyDict_SetItemString(attr_dict, "input_dtype", PyUnicode_FromString(conv_attr_data.input_dtype.c_str()));
1000 SET_DICT_LONG(attr_dict, "type_size", length);1005 SET_DICT_LONG(attr_dict, "type_size", length);
@@ -96,6 +96,18 @@ ShapeCompileContext = namedtuple(
96 "ShapeCompileContext", ["kernel_name", "temp_dir", "graph_name"]96 "ShapeCompileContext", ["kernel_name", "temp_dir", "graph_name"]
97)97)
98 98 
99+ConvArgsConfig = namedtuple(
100+ "ConvArgsConfig",
101+ [
102+ "input_num",
103+ "data_format",
104+ "has_bias",
105+ "has_scale0",
106+ "is_extend_conv2d",
107+ ],
108+ defaults=[False, False, False],
109+)
110+ 
99 111 
100def get_target_machine(params):112def get_target_machine(params):
101 host_env_cpu = params.get("host_env_cpu", "")113 host_env_cpu = params.get("host_env_cpu", "")
@@ -1621,60 +1633,71 @@ def _build_mm_args(args_list, input_num, mm_attr1, mm_attr2):
1621 return _origin_inputs_, _origin_outputs_, _inputs_1633 return _origin_inputs_, _origin_outputs_, _inputs_
1622 1634 
1623 1635 
1624-def build_conv_args(args_list, input_num, data_format):1636+def fill_conv_origin_input(_origin_inputs_, input_arg, logical_index):
1625- _inputs_ = []1637+ op_msg = "Processing input " + str(logical_index) + ":" + str(input_arg)
1638+ logger.info("CV fusion op, conv input info: %s", op_msg)
1639+ CommonUtility.print_compile_log("", op_msg, AscendCLogLevel.LOG_INFO)
1640+ _origin_inputs_.append(input_arg)
1641+ # 与 CreateConvSubgraphAttr 对齐:x=NCHW,filter=FRACTAL_Z,其余可选输入按 ND。
1642+ _origin_inputs_[-1]["ori_shape"] = _origin_inputs_[-1]["shape"]
1643+ if logical_index == 0:
1644+ _origin_inputs_[-1]["ori_format"] = "NCHW"
1645+ _origin_inputs_[-1]["format"] = "NCHW"
1646+ elif logical_index == 1:
1647+ _origin_inputs_[-1]["ori_format"] = "NCHW"
1648+ _origin_inputs_[-1]["format"] = "FRACTAL_Z"
1649+ else:
1650+ _origin_inputs_[-1]["ori_format"] = "ND"
1651+ _origin_inputs_[-1]["format"] = "ND"
1652+ 
1653+ 
1654+def build_conv_args(args_list, config):
1655+ """构造 Conv2DV2/ExtendConv2D 二次 tiling 入参。
1656+ 
1657+ ExtendConv2D 逻辑槽位固定 10 个:0 x、1 filter2 bias(has_bias)、3 offset_w 恒空、
1658+ 4 scale0(has_scale0)、5-9 恒空。Conv2DV2 仍按已连接输入紧凑排布。
1659+ """
1626 _origin_inputs_ = []1660 _origin_inputs_ = []
1627 _origin_outputs_ = []1661 _origin_outputs_ = []
1662+ input_num = config.input_num
1628 logger.info("CV fusion op, conv input(%s)", input_num)1663 logger.info("CV fusion op, conv input(%s)", input_num)
1629 1664 
1630- format_shape_transfer_map = {1665+ input_args = args_list[:input_num] # input_num是实际输入个数
1631- ("HWCN", "NCHW"): [3, 2, 0, 1],1666+ input_index = 0
1632- ("NCHW", "HWCN"): [2, 3, 1, 0],
1633- ("NHWC", "NCHW"): [0, 3, 1, 2],
1634- ("NCHW", "NHWC"): [0, 2, 3, 1],
1635- }
1636 1667 
1637- def transfer_shape_between_formats(shape, old_format, new_format):1668+ def take_connected(logical_index):
1638- """格式转换时对应的 shape 维度重排,参考 TransferShapeBetweenHwcnNchw"""1669+ nonlocal input_index
1639- if len(shape) != 4:1670+ if input_index >= len(input_args):
1640- return shape1671+ logger.error(
1641- if old_format == new_format:1672+ "CV fusion op, conv input %s missing, input_num=%s, has_bias=%s, has_scale0=%s",
1642- return shape1673+ logical_index,
1643- transfer_key = (old_format.upper(), new_format.upper())1674+ input_num,
1644- if transfer_key in format_shape_transfer_map:1675+ config.has_bias,
1645- indices = format_shape_transfer_map[transfer_key]1676+ config.has_scale0,
1646- return tuple(shape[i] for i in indices)1677+ )
1647- return shape1678+ _origin_inputs_.append(None)
1679+ return
1680+ fill_conv_origin_input(_origin_inputs_, input_args[input_index], logical_index)
1681+ input_index += 1
1648 1682 
1649- # 遍历args中的每个元素1683+ def take_empty(logical_index):
1650- for i, input_arg in enumerate(args_list[:input_num]):1684+ _origin_inputs_.append(None)
1651- if i >= input_num:1685+ logger.info("CV fusion op, conv input %s is nullptr", logical_index)
1652- continue1686+ 
1653- op_msg = "Processing input " + str(i) + ":" + str(input_arg)1687+ if config.is_extend_conv2d:
1654- logger.info("CV fusion op, conv input info: %s", op_msg)1688+ extend_conv2d_logical_input_num = 10
1655- CommonUtility.print_compile_log("", op_msg, AscendCLogLevel.LOG_INFO)1689+ for i in range(extend_conv2d_logical_input_num):
1656- _origin_inputs_.append(input_arg)1690+ if i in (0, 1):
1657- if input_arg is not None:1691+ take_connected(i)
1658- if isinstance(input_arg, (list, tuple)) and len(input_arg) != 0:1692+ elif i == 2:
1659- _inputs_.append(input_arg[0])1693+ take_connected(i) if config.has_bias else take_empty(i)
1694+ elif i == 4:
1695+ take_connected(i) if config.has_scale0 else take_empty(i)
1660 else:1696 else:
1661- _inputs_.append(input_arg)1697+ take_empty(i)
1662- else:1698+ else:
1663- _inputs_.append(input_arg)1699+ for i in range(input_num):
1664- _inputs_[-1]["param_name"] = "input" + str(i)1700+ take_connected(i)
1665- shape = _inputs_[-1]["shape"]
1666- src_format = _inputs_[-1]["format"]
1667- # 如果输入格式与目标格式不匹配,需要进行转换
1668- if src_format.upper() != data_format.upper():
1669- # 根据 format 转换规则重排 shape 维度
1670- new_shape = transfer_shape_between_formats(shape, src_format, data_format)
1671- _inputs_[-1]["shape"] = new_shape
1672- _inputs_[-1]["ori_shape"] = new_shape
1673- else:
1674- _inputs_[-1]["shape"] = shape
1675- _inputs_[-1]["ori_shape"] = shape
1676- _inputs_[-1]["ori_format"] = data_format
1677- _inputs_[-1]["format"] = data_format
1678 1701 
1679 op_msg = "Processing output " + ":" + str(args_list[-2])1702 op_msg = "Processing output " + ":" + str(args_list[-2])
1680 logger.info("CV fusion op, conv output info: %s", op_msg)1703 logger.info("CV fusion op, conv output info: %s", op_msg)
@@ -1682,12 +1705,15 @@ def build_conv_args(args_list, input_num, data_format):
1682 _origin_outputs_.append(args_list[-2])1705 _origin_outputs_.append(args_list[-2])
1683 _origin_outputs_[-1]["param_name"] = "output0"1706 _origin_outputs_[-1]["param_name"] = "output0"
1684 _origin_outputs_[-1]["shape"] = args_list[-2]["shape"]1707 _origin_outputs_[-1]["shape"] = args_list[-2]["shape"]
1685- _origin_outputs_[-1]["dtype"] = _inputs_[-1]["dtype"]1708+ _origin_outputs_[-1]["dtype"] = args_list[-2]["dtype"]
1686 _origin_outputs_[-1]["ori_shape"] = args_list[-2]["shape"]1709 _origin_outputs_[-1]["ori_shape"] = args_list[-2]["shape"]
1687- _origin_outputs_[-1]["ori_format"] = data_format1710+ _origin_outputs_[-1]["ori_format"] = config.data_format
1688- _origin_outputs_[-1]["format"] = data_format1711+ _origin_outputs_[-1]["format"] = config.data_format
1712+ if config.is_extend_conv2d:
1713+ # ExtendConv2D proto 含可选第二输出;tiling 侧按双输出占位,避免输出个数校验失败。
1714+ _origin_outputs_.append(_origin_outputs_[-1])
1689 logger.info("CV fusion op, new conv output info: %s", str(_origin_outputs_[-1]))1715 logger.info("CV fusion op, new conv output info: %s", str(_origin_outputs_[-1]))
1690- return _origin_inputs_, _origin_outputs_, _inputs_1716+ return _origin_inputs_, _origin_outputs_
1691 1717 
1692 1718 
1693def _process_tiling_info(1719def _process_tiling_info(
@@ -1899,7 +1925,19 @@ def template_decider(
1899 1925 
1900 1926 
1901def map_dtype_to_string(dtype):1927def map_dtype_to_string(dtype):
1902- dtype_map = {"bfloat16": "bfloat16_t", "float16": "half", "float32": "float"}1928+ dtype_map = {
1929+ "bfloat16": "bfloat16_t",
1930+ "float16": "half",
1931+ "float32": "float",
1932+ "int8": "int8_t",
1933+ "int16": "int16_t",
1934+ "int32": "int32_t",
1935+ "int64": "int64_t",
1936+ "uint8": "uint8_t",
1937+ "uint16": "uint16_t",
1938+ "uint32": "uint32_t",
1939+ "uint64": "uint64_t",
1940+ }
1903 1941 
1904 return dtype_map.get(dtype.lower(), dtype)1942 return dtype_map.get(dtype.lower(), dtype)
1905 1943 
@@ -2099,13 +2137,14 @@ def create_conv_tiling_data(compile_context, tiling_info, cube_info, cube_attrib
2099 _,2137 _,
2100 _,2138 _,
2101 _,2139 _,
2102- is_bias,2140+ has_bias,
2103- is_offset_w,2141+ has_offset_w,
2142+ has_scale0,
2104 origin_inputs,2143 origin_inputs,
2105 origin_outputs,2144 origin_outputs,
2106- ) = cube_info[:9]2145+ ) = cube_info[:10]
2107 struct_name = "Conv2DTilingData"2146 struct_name = "Conv2DTilingData"
2108- data_prefix = "(*tmpTilingData).conv2dApiTiling"2147+ data_prefix = "(*tmpTilingData)"
2109 2148 
2110 host_tiling_data = f"""2149 host_tiling_data = f"""
2111// conv2d2150// conv2d
@@ -2156,14 +2195,28 @@ GET_TILING_DATA_PTR_WITH_STRUCT({struct_name}, tmpTilingData, tmpTilingGM);
2156 )2195 )
2157 2196 
2158 device_tiling_data = f"""\n#include "arch35/conv2d_v2_tiling_def.h"2197 device_tiling_data = f"""\n#include "arch35/conv2d_v2_tiling_def.h"
2159-#define IS_ENABLE_BIAS {str(is_bias).lower()}2198+#define IS_ENABLE_BIAS {str(has_bias).lower()}
2160-#define IS_ENABLE_OFFSET_W {str(is_offset_w).lower()}2199+#define IS_ENABLE_OFFSET_W {str(has_offset_w).lower()}
2200+#define IS_ENABLE_SCALE0 {str(has_scale0).lower()}
2161#define DTYPE_X1 {map_dtype_to_string(origin_inputs[0]["dtype"])}2201#define DTYPE_X1 {map_dtype_to_string(origin_inputs[0]["dtype"])}
2162#define DTYPE_X2 {map_dtype_to_string(origin_inputs[1]["dtype"])}2202#define DTYPE_X2 {map_dtype_to_string(origin_inputs[1]["dtype"])}
2163#define DTYPE_Y {map_dtype_to_string(origin_outputs[0]["dtype"])}2203#define DTYPE_Y {map_dtype_to_string(origin_outputs[0]["dtype"])}
2164-#define DTYPE_BIAS {map_dtype_to_string(origin_outputs[0]["dtype"])}
2165"""2204"""
2166- 2205+ device_tiling_data += (
2206+ f"""#define DTYPE_BIAS {map_dtype_to_string(origin_inputs[2]["dtype"])}\n"""
2207+ if has_bias
2208+ else "#define DTYPE_BIAS int32_t\n"
2209+ )
2210+ device_tiling_data += (
2211+ f"""#define DTYPE_OFFSET_W {map_dtype_to_string(origin_inputs[3]["dtype"])}\n"""
2212+ if has_offset_w
2213+ else "#define DTYPE_OFFSET_W uint64_t\n"
2214+ )
2215+ device_tiling_data += (
2216+ f"""#define DTYPE_SCALE0 {map_dtype_to_string(origin_inputs[4]["dtype"])}\n"""
2217+ if has_scale0
2218+ else "#define DTYPE_SCALE0 uint64_t\n"
2219+ )
2167 tiling_data_undef = create_conv_tiling_undef_header()2220 tiling_data_undef = create_conv_tiling_undef_header()
2168 tiling_info.file_content += device_tiling_data2221 tiling_info.file_content += device_tiling_data
2169 device_tiling_content = tiling_data_undef2222 device_tiling_content = tiling_data_undef
@@ -2213,62 +2266,82 @@ def ascbc_conv_kernel_tiling_pro(
2213 logger.error("kernel_name=[%s] can't find cube attributes", kernel_name)2266 logger.error("kernel_name=[%s] can't find cube attributes", kernel_name)
2214 return2267 return
2215 2268 
2216- is_bias = cube_attributes.get("is_bias", False)2269+ has_bias = cube_attributes.get("has_bias", False)
2217- is_offset_w = cube_attributes.get("is_offset_w", False)2270+ has_offset_w = cube_attributes.get("has_offset_w", False)
2218- enable_hf32 = cube_attributes.get("enable_hf32", False)2271+ has_scale0 = cube_attributes.get("has_scale0", False)
2219- offset_x = cube_attributes.get("offset_x", 0)2272+ is_extend_conv2d = cube_attributes.get("is_extend_conv2d", False)
2220- groups = cube_attributes.get("groups", 1)2273+ 
2221- pad_mode = cube_attributes.get("pad_mode", "SPECIFIC")
2222- data_format = cube_attributes.get("data_format", "NCHW")
2223 strides = cube_attributes.get("strides", [1, 1])2274 strides = cube_attributes.get("strides", [1, 1])
2224 pads = cube_attributes.get("pads", [0, 0, 0, 0])2275 pads = cube_attributes.get("pads", [0, 0, 0, 0])
2225 dilations = cube_attributes.get("dilations", [1, 1])2276 dilations = cube_attributes.get("dilations", [1, 1])
2277+ groups = cube_attributes.get("groups", 1)
2278+ data_format = cube_attributes.get("data_format", "NCHW")
2279+ offset_x = cube_attributes.get("offset_x", 0)
2280+ round_mode = cube_attributes.get("round_mode", "rint")
2281+ pad_mode = cube_attributes.get("pad_mode", "SPECIFIC")
2282+ enable_hf32 = cube_attributes.get("enable_hf32", False)
2283+ fixed_shift_value = cube_attributes.get("fixed_shift_value", 0)
2284+ enable_relu0 = cube_attributes.get("enable_relu0", False)
2285+ enable_relu1 = cube_attributes.get("enable_relu1", False)
2286+ dual_output = cube_attributes.get("dual_output", False)
2287+ dtype0 = cube_attributes.get("dtype0", -1)
2288+ dtype1 = cube_attributes.get("dtype1", -1)
2226 2289 
2227- conv_attr1 = {"name": "strides", "dtype": "list_int", "value": strides}2290+ op_type = "ExtendConv2D" if is_extend_conv2d else "Conv2DV2"
2228- conv_attr2 = {"name": "pads", "dtype": "list_int", "value": pads}2291+ 
2229- conv_attr3 = {"name": "dilations", "dtype": "list_int", "value": dilations}2292+ # attr 顺序需与对应 op proto 一致:ExtendConv2D pad_mode 前插入 round_mode。
2230- conv_attr4 = {"name": "groups", "dtype": "int", "value": groups}2293+ conv_attr = []
2231- conv_attr5 = {"name": "data_format", "dtype": "str", "value": data_format}2294+ conv_attr.append({"name": "strides", "dtype": "list_int", "value": strides})
2232- conv_attr6 = {"name": "offset_x", "dtype": "int", "value": offset_x}2295+ conv_attr.append({"name": "pads", "dtype": "list_int", "value": pads})
2233- conv_attr7 = {"name": "pad_mode", "dtype": "str", "value": pad_mode}2296+ conv_attr.append({"name": "dilations", "dtype": "list_int", "value": dilations})
2234- conv_attr8 = {"name": "enable_hf32", "dtype": "bool", "value": enable_hf32}2297+ conv_attr.append({"name": "groups", "dtype": "int", "value": groups})
2235- conv_attr9 = {"name": "is_bias", "dtype": "bool", "value": is_bias}2298+ conv_attr.append({"name": "data_format", "dtype": "str", "value": data_format})
2236- conv_attr10 = {"name": "is_offset_w", "dtype": "bool", "value": is_offset_w}2299+ conv_attr.append({"name": "offset_x", "dtype": "int", "value": offset_x})
2300+ if is_extend_conv2d:
2301+ conv_attr.append({"name": "round_mode", "dtype": "str", "value": round_mode})
2302+ conv_attr.append({"name": "pad_mode", "dtype": "str", "value": pad_mode})
2303+ conv_attr.append({"name": "enable_hf32", "dtype": "bool", "value": enable_hf32})
2304+ if is_extend_conv2d:
2305+ conv_attr.append(
2306+ {"name": "enable_relu0", "dtype": "bool", "value": enable_relu0}
2307+ )
2308+ conv_attr.append(
2309+ {"name": "enable_relu1", "dtype": "bool", "value": enable_relu1}
2310+ )
2311+ conv_attr.append({"name": "dual_output", "dtype": "bool", "value": dual_output})
2312+ conv_attr.append({"name": "dtype0", "dtype": "int", "value": dtype0})
2313+ conv_attr.append({"name": "dtype1", "dtype": "int", "value": dtype1})
2237 2314 
2238 conv_input_num = cube_attributes.get("input_num", 0)2315 conv_input_num = cube_attributes.get("input_num", 0)
2239- _origin_inputs_, _origin_outputs_, _inputs_ = build_conv_args(2316+ conv_args_config = ConvArgsConfig(
2240- args_list, input_num=conv_input_num, data_format=data_format2317+ input_num=conv_input_num,
2318+ data_format=data_format,
2319+ has_bias=has_bias,
2320+ has_scale0=has_scale0,
2321+ is_extend_conv2d=is_extend_conv2d,
2241 )2322 )
2323+ _origin_inputs_, _origin_outputs_ = build_conv_args(args_list, conv_args_config)
2242 2324 
2243- attrs = [
2244- conv_attr1,
2245- conv_attr2,
2246- conv_attr3,
2247- conv_attr4,
2248- conv_attr5,
2249- conv_attr6,
2250- conv_attr7,
2251- conv_attr8,
2252- conv_attr9,
2253- conv_attr10,
2254- ]
2255 tiling_info = TilingInfo()2325 tiling_info = TilingInfo()
2256 context = get_context()2326 context = get_context()
2257- _change_param_name_to_name(_inputs_)2327+ non_none_origin_inputs = [item for item in _origin_inputs_ if item is not None]
2258- _change_param_name_to_name(_origin_inputs_)2328+ _change_param_name_to_name(non_none_origin_inputs)
2259 compile_info = context.get_compile_info()2329 compile_info = context.get_compile_info()
2260 tiling_config = {2330 tiling_config = {
2261 "name": "ascendc_op_para_size",2331 "name": "ascendc_op_para_size",
2262 "dtype": "int",2332 "dtype": "int",
2263 "value": 2 * 1024 * 1024,2333 "value": 2 * 1024 * 1024,
2264 }2334 }
2265- attrs.append(tiling_config)2335+ conv_attr.append(tiling_config)
2336+ # fixed_shift_value 为 private attr,需显式追加,保证与 ascendc_op_para_size 的 IR 序一致。
2337+ conv_attr.append(
2338+ {"name": "fixed_shift_value", "dtype": "int", "value": fixed_shift_value}
2339+ )
2266 2340 
2267- op_type = "Conv2DV2"
2268 tiling_data_type = "Conv2DTilingData"2341 tiling_data_type = "Conv2DTilingData"
2269 2342 
2270 run_info = do_op_tiling(2343 run_info = do_op_tiling(
2271- op_type, compile_info, _origin_inputs_, _origin_outputs_, None, None, attrs2344+ op_type, compile_info, _origin_inputs_, _origin_outputs_, None, None, conv_attr
2272 )2345 )
2273 tiling_info.tiling_data = run_info["tiling_data"]2346 tiling_info.tiling_data = run_info["tiling_data"]
2274 tiling_info.tiling_key = run_info["tiling_key"]2347 tiling_info.tiling_key = run_info["tiling_key"]
@@ -2292,8 +2365,9 @@ def ascbc_conv_kernel_tiling_pro(
2292 cube_block_dim,2365 cube_block_dim,
2293 use_cv_common,2366 use_cv_common,
2294 False,2367 False,
2295- is_bias,2368+ has_bias,
2296- is_offset_w,2369+ has_offset_w,
2370+ has_scale0,
2297 _origin_inputs_,2371 _origin_inputs_,
2298 _origin_outputs_,2372 _origin_outputs_,
2299 ]2373 ]
@@ -423,6 +423,19 @@ AscNodePtr AscGraphAddAscirNodeByType(AscGraph &asc_graph, const char *op_type,
423 if (type == ascir_op::Conv2DOffsetBias::Type) {423 if (type == ascir_op::Conv2DOffsetBias::Type) {
424 MAKE_NODE(Conv2DOffsetBias);424 MAKE_NODE(Conv2DOffsetBias);
425 }425 }
426+ // ExtendConv2D 四个 ASCIR 变体:无附加输入 / bias / scale0 / bias+scale0。
427+ if (type == ascir_op::ExtendConv2D::Type) {
428+ MAKE_NODE(ExtendConv2D);
429+ }
430+ if (type == ascir_op::ExtendConv2DBias::Type) {
431+ MAKE_NODE(ExtendConv2DBias);
432+ }
433+ if (type == ascir_op::ExtendConv2DScale::Type) {
434+ MAKE_NODE(ExtendConv2DScale);
435+ }
436+ if (type == ascir_op::ExtendConv2DBiasScale::Type) {
437+ MAKE_NODE(ExtendConv2DBiasScale);
438+ }
426 439 
427#undef MAKE_NODE440#undef MAKE_NODE
428 441 
@@ -166,7 +166,7 @@ add_subdirectory(load_pow_all_input_is_scalar_store_test)
166add_subdirectory(pgo_add_abs_test)166add_subdirectory(pgo_add_abs_test)
167# add_subdirectory(pgo_sub_transpose_abs_test)167# add_subdirectory(pgo_sub_transpose_abs_test)
168add_subdirectory(matmul_elemwise_test)168add_subdirectory(matmul_elemwise_test)
169-# add_subdirectory(conv2d_elemwise_test)169+add_subdirectory(conv2d_elemwise_test)
170# add_subdirectory(argmax_test)170# add_subdirectory(argmax_test)
171add_subdirectory(inductor_topn_test)171add_subdirectory(inductor_topn_test)
172add_subdirectory(inductor_matmul_elemwise_test)172add_subdirectory(inductor_matmul_elemwise_test)
@@ -349,6 +349,85 @@ static void CreateElemwiseGraphWithAddScalar(af::AscGraph &graph, const std::str
349 349 
350} // namespace350} // namespace
351 351 
352+struct ConvGraphAxes {
353+ af::Expression s0;
354+ af::Expression s1;
355+ af::AxisId z0;
356+ af::AxisId z1;
357+};
358+ 
359+struct ConvInputConfig {
360+ int64_t index;
361+ ge::DataType dtype;
362+ bool use_output_shape;
363+};
364+ 
365+ConvGraphAxes CreateConvGraphAxes(af::AscGraph &graph) {
366+ const auto s0 = graph.CreateSizeVar(32);
367+ const auto s1 = graph.CreateSizeVar(32);
368+ return {s0, s1, graph.CreateAxis("z0", s0).id, graph.CreateAxis("z1", s1).id};
369+}
370+ 
371+void ConfigureConvInput(af::ascir_op::Data &data, af::ascir_op::Load &load, const ConvGraphAxes &axes,
372+ const ConvInputConfig &config) {
373+ data.attr.sched.axis = {axes.z0, axes.z1};
374+ data.y.dtype = config.dtype;
375+ *data.y.axis = {axes.z0, axes.z1};
376+ data.attr.api.compute_type = af::ComputeType::kComputeInvalid;
377+ data.ir_attr.SetIndex(config.index);
378+ load.attr.sched.axis = {axes.z0, axes.z1};
379+ load.x = data.y;
380+ load.y.dtype = config.dtype;
381+ *load.y.axis = {axes.z0, axes.z1};
382+ if (config.use_output_shape) {
383+ *data.y.strides = {axes.s1, af::ops::One};
384+ *data.y.repeats = {axes.s0, axes.s1};
385+ *load.y.strides = {axes.s1, af::ops::One};
386+ *load.y.repeats = {axes.s0, axes.s1};
387+ } else {
388+ *data.y.strides = {af::ops::Zero, af::ops::Zero};
389+ *data.y.repeats = {af::ops::One, af::ops::One};
390+ *load.y.strides = {af::ops::Zero, af::ops::Zero};
391+ *load.y.repeats = {af::ops::One, af::ops::One};
392+ }
393+}
394+ 
395+template <typename ConvOp>
396+void ConfigureExtendConv2D(ConvOp &conv2d, const ConvGraphAxes &axes, bool enable_relu0) {
397+ conv2d.attr.sched.axis = {axes.z0, axes.z1};
398+ conv2d.y.dtype = ge::DT_FLOAT16;
399+ *conv2d.y.axis = {axes.z0, axes.z1};
400+ *conv2d.y.repeats = {axes.s0, axes.s1};
401+ *conv2d.y.strides = {axes.s1, af::ops::One};
402+ conv2d.ir_attr.SetStrides({1, 1});
403+ conv2d.ir_attr.SetPads({0, 0, 0, 0});
404+ conv2d.ir_attr.SetDilations({1, 1});
405+ conv2d.ir_attr.SetGroups(1);
406+ conv2d.ir_attr.SetData_format("NCHW");
407+ conv2d.ir_attr.SetOffset_x(0);
408+ conv2d.ir_attr.SetPad_mode("SPECIFIC");
409+ conv2d.ir_attr.SetRound_mode("rint");
410+ conv2d.ir_attr.SetEnable_hf32(false);
411+ conv2d.ir_attr.SetEnable_relu0(enable_relu0);
412+}
413+ 
414+template <typename Tensor>
415+void FinishConvGraph(af::AscGraph &graph, Tensor &conv_output, const ConvGraphAxes &axes) {
416+ af::ascir_op::Store store_op("store");
417+ store_op.attr.sched.axis = {axes.z0, axes.z1};
418+ store_op.x = conv_output;
419+ *store_op.y.axis = {axes.z0, axes.z1};
420+ store_op.y.dtype = ge::DT_FLOAT16;
421+ *store_op.y.strides = {axes.s1, af::ops::One};
422+ *store_op.y.repeats = {axes.s0, axes.s1};
423+ store_op.ir_attr.SetOffset(af::ops::One);
424+ af::ascir_op::Output output_op("output");
425+ output_op.x = store_op.y;
426+ output_op.y.dtype = ge::DT_FLOAT16;
427+ output_op.ir_attr.SetIndex(0);
428+ optimize::AscGraphInfoComplete::CompleteApiInfo(graph);
429+}
430+ 
352void CreateConv2DGraph(af::AscGraph &graph) {431void CreateConv2DGraph(af::AscGraph &graph) {
353 auto s0 = graph.CreateSizeVar(32);432 auto s0 = graph.CreateSizeVar(32);
354 auto s1 = graph.CreateSizeVar(32);433 auto s1 = graph.CreateSizeVar(32);
@@ -405,21 +484,7 @@ void CreateConv2DGraph(af::AscGraph &graph) {
405 conv2d.ir_attr.SetOffset_x(0);484 conv2d.ir_attr.SetOffset_x(0);
406 conv2d.ir_attr.SetPad_mode("SPECIFIC");485 conv2d.ir_attr.SetPad_mode("SPECIFIC");
407 conv2d.ir_attr.SetEnable_hf32(false);486 conv2d.ir_attr.SetEnable_hf32(false);
408- 487+ FinishConvGraph(graph, conv2d.y, {s0, s1, z0.id, z1.id});
409- af::ascir_op::Store store_op("store");
410- store_op.attr.sched.axis = {z0.id, z1.id};
411- store_op.x = conv2d.y;
412- *store_op.y.axis = {z0.id, z1.id};
413- store_op.y.dtype = ge::DT_FLOAT16;
414- *store_op.y.strides = {s1, af::ops::One};
415- *store_op.y.repeats = {s0, s1};
416- store_op.ir_attr.SetOffset(af::ops::One);
417- 
418- af::ascir_op::Output output_op("output");
419- output_op.x = store_op.y;
420- output_op.y.dtype = ge::DT_FLOAT16;
421- output_op.ir_attr.SetIndex(0);
422- optimize::AscGraphInfoComplete::CompleteApiInfo(graph);
423}488}
424 489 
425void CreateConv2DBiasGraph(af::AscGraph &graph) {490void CreateConv2DBiasGraph(af::AscGraph &graph) {
@@ -496,21 +561,7 @@ void CreateConv2DBiasGraph(af::AscGraph &graph) {
496 conv2d_bias.ir_attr.SetOffset_x(0);561 conv2d_bias.ir_attr.SetOffset_x(0);
497 conv2d_bias.ir_attr.SetPad_mode("SPECIFIC");562 conv2d_bias.ir_attr.SetPad_mode("SPECIFIC");
498 conv2d_bias.ir_attr.SetEnable_hf32(false);563 conv2d_bias.ir_attr.SetEnable_hf32(false);
499- 564+ FinishConvGraph(graph, conv2d_bias.y, {s0, s1, z0.id, z1.id});
500- af::ascir_op::Store store_op("store");
501- store_op.attr.sched.axis = {z0.id, z1.id};
502- store_op.x = conv2d_bias.y;
503- *store_op.y.axis = {z0.id, z1.id};
504- store_op.y.dtype = ge::DT_FLOAT16;
505- *store_op.y.strides = {s1, af::ops::One};
506- *store_op.y.repeats = {s0, s1};
507- store_op.ir_attr.SetOffset(af::ops::One);
508- 
509- af::ascir_op::Output output_op("output");
510- output_op.x = store_op.y;
511- output_op.y.dtype = ge::DT_FLOAT16;
512- output_op.ir_attr.SetIndex(0);
513- optimize::AscGraphInfoComplete::CompleteApiInfo(graph);
514}565}
515 566 
516void CreateConv2DOffsetGraph(af::AscGraph &graph) {567void CreateConv2DOffsetGraph(af::AscGraph &graph) {
@@ -587,21 +638,7 @@ void CreateConv2DOffsetGraph(af::AscGraph &graph) {
587 conv2d_offset.ir_attr.SetOffset_x(0);638 conv2d_offset.ir_attr.SetOffset_x(0);
588 conv2d_offset.ir_attr.SetPad_mode("SPECIFIC");639 conv2d_offset.ir_attr.SetPad_mode("SPECIFIC");
589 conv2d_offset.ir_attr.SetEnable_hf32(false);640 conv2d_offset.ir_attr.SetEnable_hf32(false);
590- 641+ FinishConvGraph(graph, conv2d_offset.y, {s0, s1, z0.id, z1.id});
591- af::ascir_op::Store store_op("store");
592- store_op.attr.sched.axis = {z0.id, z1.id};
593- store_op.x = conv2d_offset.y;
594- *store_op.y.axis = {z0.id, z1.id};
595- store_op.y.dtype = ge::DT_FLOAT16;
596- *store_op.y.strides = {s1, af::ops::One};
597- *store_op.y.repeats = {s0, s1};
598- store_op.ir_attr.SetOffset(af::ops::One);
599- 
600- af::ascir_op::Output output_op("output");
601- output_op.x = store_op.y;
602- output_op.y.dtype = ge::DT_FLOAT16;
603- output_op.ir_attr.SetIndex(0);
604- optimize::AscGraphInfoComplete::CompleteApiInfo(graph);
605}642}
606 643 
607void CreateConv2DOffsetBiasGraph(af::AscGraph &graph) {644void CreateConv2DOffsetBiasGraph(af::AscGraph &graph) {
@@ -696,21 +733,7 @@ void CreateConv2DOffsetBiasGraph(af::AscGraph &graph) {
696 conv2d_offset_bias.ir_attr.SetOffset_x(0);733 conv2d_offset_bias.ir_attr.SetOffset_x(0);
697 conv2d_offset_bias.ir_attr.SetPad_mode("SPECIFIC");734 conv2d_offset_bias.ir_attr.SetPad_mode("SPECIFIC");
698 conv2d_offset_bias.ir_attr.SetEnable_hf32(false);735 conv2d_offset_bias.ir_attr.SetEnable_hf32(false);
699- 736+ FinishConvGraph(graph, conv2d_offset_bias.y, {s0, s1, z0.id, z1.id});
700- af::ascir_op::Store store_op("store");
701- store_op.attr.sched.axis = {z0.id, z1.id};
702- store_op.x = conv2d_offset_bias.y;
703- *store_op.y.axis = {z0.id, z1.id};
704- store_op.y.dtype = ge::DT_FLOAT16;
705- *store_op.y.strides = {s1, af::ops::One};
706- *store_op.y.repeats = {s0, s1};
707- store_op.ir_attr.SetOffset(af::ops::One);
708- 
709- af::ascir_op::Output output_op("output");
710- output_op.x = store_op.y;
711- output_op.y.dtype = ge::DT_FLOAT16;
712- output_op.ir_attr.SetIndex(0);
713- optimize::AscGraphInfoComplete::CompleteApiInfo(graph);
714}737}
715 738 
716TEST_F(TestBackendConv2DE2e, Conv2DE2eCodegen) {739TEST_F(TestBackendConv2DE2e, Conv2DE2eCodegen) {
@@ -758,6 +781,38 @@ TEST_F(TestBackendConv2DE2e, Conv2DOffsetE2eCodegen) {
758 EXPECT_EQ(gen_success, true);781 EXPECT_EQ(gen_success, true);
759}782}
760 783 
784+void CreateExtendConv2DGraph(af::AscGraph &graph, bool with_bias_scale = false) {
785+ const auto axes = CreateConvGraphAxes(graph);
786+ af::ascir_op::Data data0("data0", graph);
787+ af::ascir_op::Load load0("load0");
788+ ConfigureConvInput(data0, load0, axes, {0, ge::DT_FLOAT16, true});
789+ af::ascir_op::Data data1("data1", graph);
790+ af::ascir_op::Load load1("load1");
791+ ConfigureConvInput(data1, load1, axes, {1, ge::DT_FLOAT16, false});
792+ if (!with_bias_scale) {
793+ af::ascir_op::ExtendConv2D conv2d("extend_conv2d");
794+ conv2d.x = load0.y;
795+ conv2d.filter = load1.y;
796+ ConfigureExtendConv2D(conv2d, axes, false);
797+ FinishConvGraph(graph, conv2d.y, axes);
798+ return;
799+ }
800+ 
801+ af::ascir_op::Data data2("data2", graph);
802+ af::ascir_op::Load load2("load2");
803+ ConfigureConvInput(data2, load2, axes, {2, ge::DT_FLOAT16, false});
804+ af::ascir_op::Data data3("data3", graph);
805+ af::ascir_op::Load load3("load3");
806+ ConfigureConvInput(data3, load3, axes, {3, ge::DT_UINT64, false});
807+ af::ascir_op::ExtendConv2DBiasScale conv2d("extend_conv2d_bias_scale");
808+ conv2d.x = load0.y;
809+ conv2d.filter = load1.y;
810+ conv2d.bias = load2.y;
811+ conv2d.scale0 = load3.y;
812+ ConfigureExtendConv2D(conv2d, axes, true);
813+ FinishConvGraph(graph, conv2d.y, axes);
814+}
815+ 
761TEST_F(TestBackendConv2DE2e, Conv2DOffsetBiasE2eCodegen) {816TEST_F(TestBackendConv2DE2e, Conv2DOffsetBiasE2eCodegen) {
762 af::AscGraph graph("conv2d_offset_bias_elemwise_pro");817 af::AscGraph graph("conv2d_offset_bias_elemwise_pro");
763 CreateElemwiseGraphWithAddScalar(graph, "1.0");818 CreateElemwiseGraphWithAddScalar(graph, "1.0");
@@ -775,3 +830,25 @@ TEST_F(TestBackendConv2DE2e, Conv2DOffsetBiasE2eCodegen) {
775 830 
776 EXPECT_EQ(gen_success, true);831 EXPECT_EQ(gen_success, true);
777}832}
833+ 
834+TEST_F(TestBackendConv2DE2e, ExtendConv2DE2eCodegen) {
835+ af::AscGraph graph("extend_conv2d_elemwise_pro");
836+ CreateElemwiseGraphWithAbs(graph);
837+ 
838+ af::AscGraph conv2d_graph("extend_conv2d");
839+ CreateExtendConv2DGraph(conv2d_graph);
840+ 
841+ bool gen_success = OptimizeAndGenerateCode(*this, graph, conv2d_graph, "ExtendConv2d_fuse_tiling_func.cpp");
842+ EXPECT_EQ(gen_success, true);
843+}
844+ 
845+TEST_F(TestBackendConv2DE2e, ExtendConv2DBiasScaleE2eCodegen) {
846+ af::AscGraph graph("extend_conv2d_bias_scale_elemwise_pro");
847+ CreateElemwiseGraphWithRelu(graph);
848+ 
849+ af::AscGraph conv2d_graph("extend_conv2d_bias_scale");
850+ CreateExtendConv2DGraph(conv2d_graph, true);
851+ 
852+ bool gen_success = OptimizeAndGenerateCode(*this, graph, conv2d_graph, "ExtendConv2dBiasScale_fuse_tiling_func.cpp");
853+ EXPECT_EQ(gen_success, true);
854+}
@@ -4,6 +4,7 @@ add_executable(codegen_st
4 test.cpp4 test.cpp
5 test_codegen_infershape.cpp5 test_codegen_infershape.cpp
6 test_codegen_graph_check.cpp6 test_codegen_graph_check.cpp
7+ test_codegen_extend_conv2d.cpp
7)8)
8target_compile_definitions(codegen_st PRIVATE9target_compile_definitions(codegen_st PRIVATE
9 CMAKE_BINARY_DIR="${CMAKE_BINARY_DIR}"10 CMAKE_BINARY_DIR="${CMAKE_BINARY_DIR}"
@@ -24,6 +25,8 @@ target_link_libraries(codegen_st PRIVATE
24 aihac_symbolizer_af25 aihac_symbolizer_af
25 json26 json
26 ascendc_api_extend27 ascendc_api_extend
28+ pyautofuse
29+ Python3::Python
27 GTest::gtest)30 GTest::gtest)
28 31 
29add_test(NAME codegen_st COMMAND codegen_st --gtest_output=xml:${CMAKE_INSTALL_PREFIX}/report/st/codegen_st.xml)32add_test(NAME codegen_st COMMAND codegen_st --gtest_output=xml:${CMAKE_INSTALL_PREFIX}/report/st/codegen_st.xml)
@@ -0,0 +1,214 @@
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+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7+ * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8+ * See LICENSE in the root of the software repository for the full text of the License.
9+ */
10+ 
11+#include "gtest/gtest.h"
12+#include "ascendc_ir.h"
13+#include "ascir_ops.h"
14+#include "codegen_kernel.h"
15+#include "common_utils.h"
16+#include "schedule_result.h"
17+#include "common/platform_context.h"
18+#include "pyascir_types.h"
19+ 
20+#include <Python.h>
21+#include <sstream>
22+ 
23+using namespace af;
24+using namespace af::ascir_op;
25+using namespace codegen;
26+using namespace ascgen_utils;
27+ 
28+namespace {
29+template <typename ConvOp>
30+void FillExtendConv2DIrAttr(ConvOp &conv, bool enable_relu0 = false) {
31+ conv.ir_attr.SetStrides({1, 1, 1, 1});
32+ conv.ir_attr.SetPads({0, 0, 0, 0});
33+ conv.ir_attr.SetDilations({1, 1, 1, 1});
34+ conv.ir_attr.SetGroups(1);
35+ conv.ir_attr.SetPad_mode("SPECIFIC");
36+ conv.ir_attr.SetData_format("NCHW");
37+ conv.ir_attr.SetOffset_x(0);
38+ conv.ir_attr.SetEnable_hf32(false);
39+ conv.ir_attr.SetFixed_shift_value(0);
40+ conv.ir_attr.SetRound_mode("rint");
41+ conv.ir_attr.SetEnable_relu0(enable_relu0);
42+ conv.attr.api.compute_type = af::ComputeType::kComputeCube;
43+}
44+ 
45+void PrepareConvKernelInputs(Kernel &kernel, size_t input_num) {
46+ for (size_t i = 0; i < input_num; ++i) {
47+ kernel.inputs.emplace_back(GM_ADDR("input_" + std::to_string(i)));
48+ }
49+ kernel.outputs.emplace_back(GM_ADDR("output_0"));
50+}
51+ 
52+::ascir::FusedScheduledResult MakeCubeScheduledResult() {
53+ ::ascir::FusedScheduledResult fused;
54+ fused.node_idx_to_scheduled_results.resize(1);
55+ fused.node_idx_to_scheduled_results[0].resize(1);
56+ fused.node_idx_to_scheduled_results[0][0].cube_type = ::ascir::CubeTemplateType::kUBFuse;
57+ return fused;
58+}
59+ 
60+bool InitFusedScheduledResultType(PyTypeObject &type) {
61+ if (!Py_IsInitialized()) {
62+ Py_Initialize();
63+ }
64+ if (type.tp_name == nullptr) {
65+ type.tp_name = "FusedScheduledResult";
66+ type.tp_basicsize = sizeof(pyascir::FusedScheduledResult::Object);
67+ type.tp_itemsize = 0;
68+ type.tp_dealloc = pyascir::FusedScheduledResult::Dealloc;
69+ type.tp_flags = Py_TPFLAGS_DEFAULT;
70+ type.tp_new = pyascir::FusedScheduledResult::New;
71+ type.tp_init = pyascir::FusedScheduledResult::Init;
72+ }
73+ return PyType_Ready(&type) == 0;
74+}
75+ 
76+af::AscGraph BuildExtendConv2DAttrGraph() {
77+ af::AscGraph graph("extend_conv2d_pyattr");
78+ Data data0("x", graph);
79+ Data data1("filter", graph);
80+ Load load0("load0");
81+ Load load1("load1");
82+ ExtendConv2D conv("extend_conv2d");
83+ graph.AddNode(load0);
84+ graph.AddNode(load1);
85+ graph.AddNode(conv);
86+ load0.x = data0.y;
87+ load1.x = data1.y;
88+ conv.x = load0.y;
89+ conv.filter = load1.y;
90+ conv.y.dtype = ge::DT_FLOAT16;
91+ FillExtendConv2DIrAttr(conv);
92+ return graph;
93+}
94+ 
95+void AttachCubeImplGraph(pyascir::FusedScheduledResult::Object *self, const af::AscGraph &graph) {
96+ self->fused_schedule_result.node_idx_to_scheduled_results.resize(1);
97+ self->fused_schedule_result.node_idx_to_scheduled_results[0].resize(1);
98+ auto &scheduled = self->fused_schedule_result.node_idx_to_scheduled_results[0][0];
99+ scheduled.cube_type = ::ascir::CubeTemplateType::kUBFuse;
100+ ::ascir::ScheduleGroup group;
101+ group.impl_graphs.push_back(graph);
102+ scheduled.schedule_groups.push_back(group);
103+}
104+ 
105+void ExpectExtendConv2DCubeAttrKeys(PyObject *attrs) {
106+ PyObject *cube_attrs = PyDict_GetItemString(attrs, "cube_attributes");
107+ ASSERT_NE(cube_attrs, nullptr);
108+ PyObject *is_extend = PyDict_GetItemString(cube_attrs, "is_extend_conv2d");
109+ ASSERT_NE(is_extend, nullptr);
110+ EXPECT_EQ(is_extend, Py_True);
111+ PyObject *has_scale0 = PyDict_GetItemString(cube_attrs, "has_scale0");
112+ ASSERT_NE(has_scale0, nullptr);
113+ EXPECT_EQ(has_scale0, Py_False);
114+ PyObject *round_mode = PyDict_GetItemString(cube_attrs, "round_mode");
115+ ASSERT_NE(round_mode, nullptr);
116+ EXPECT_STREQ(PyUnicode_AsUTF8(round_mode), "rint");
117+}
118+} // namespace
119+ 
120+TEST(CodegenExtendConv2D, KernelFuncDeclareContainsNewConv2DTemplateArgs) {
121+ const auto fused = MakeCubeScheduledResult();
122+ const std::string decl = Kernel::KernelFuncDeclare("ExtendConv2DGraph", fused, false, false, true);
123+ EXPECT_NE(decl.find("SmallKernel"), std::string::npos);
124+ EXPECT_NE(decl.find("BatchOne"), std::string::npos);
125+}
126+ 
127+TEST(CodegenExtendConv2D, GenCubeTilingFuncCallPlainExtendConv2D) {
128+ af::AscGraph graph("extend_conv2d");
129+ ExtendConv2D conv("extend_conv2d");
130+ graph.AddNode(conv);
131+ FillExtendConv2DIrAttr(conv);
132+ 
133+ Kernel kernel("extend_conv2d_kernel");
134+ PrepareConvKernelInputs(kernel, 2U);
135+ 
136+ const std::string call = kernel.GenCubeTilingFuncCall(graph);
137+ EXPECT_NE(call.find("conv2d_v2"), std::string::npos);
138+ EXPECT_NE(call.find("SmallKernel"), std::string::npos);
139+ EXPECT_NE(call.find("input_0"), std::string::npos);
140+ EXPECT_NE(call.find("nullptr"), std::string::npos);
141+ 
142+ const std::string common_call = kernel.GenCubeCommonTilingSingleFuncCall(graph);
143+ EXPECT_NE(common_call.find("conv2d_v2"), std::string::npos);
144+ EXPECT_NE(common_call.find("input_0"), std::string::npos);
145+}
146+ 
147+TEST(CodegenExtendConv2D, GetCubeAttributesExportsExtendConv2DFields) {
148+ auto &type = pyascir::FusedScheduledResult::type;
149+ ASSERT_TRUE(InitFusedScheduledResultType(type));
150+ ge::PlatformContext::GetInstance().SetPlatform("2201");
151+ 
152+ const auto graph = BuildExtendConv2DAttrGraph();
153+ PyObject *obj = pyascir::FusedScheduledResult::New(&type, nullptr, nullptr);
154+ ASSERT_NE(obj, nullptr);
155+ auto *self = reinterpret_cast<pyascir::FusedScheduledResult::Object *>(obj);
156+ AttachCubeImplGraph(self, graph);
157+ 
158+ PyObject *attrs = pyascir::FusedScheduledResult::GetCubeAttributes(obj);
159+ ASSERT_NE(attrs, nullptr);
160+ ASSERT_EQ(PyErr_Occurred(), nullptr);
161+ ExpectExtendConv2DCubeAttrKeys(attrs);
162+ 
163+ Py_DECREF(attrs);
164+ pyascir::FusedScheduledResult::Dealloc(obj);
165+}
166+ 
167+TEST(CodegenExtendConv2D, GenCubeTilingFuncCallBiasScaleAndDynamic) {
168+ af::AscGraph graph("extend_conv2d_bias_scale");
169+ ExtendConv2DBiasScale conv("extend_conv2d_bias_scale");
170+ graph.AddNode(conv);
171+ FillExtendConv2DIrAttr(conv, true);
172+ 
173+ EXPECT_TRUE(IsConv2DGraphType(graph));
174+ EXPECT_TRUE(IsConv2DTypeWithBias(graph));
175+ EXPECT_TRUE(IsConv2DTypeWithScale0(graph));
176+ 
177+ Kernel kernel("extend_conv2d_bias_scale_kernel");
178+ PrepareConvKernelInputs(kernel, 4U);
179+ 
180+ const std::string call = kernel.GenCubeTilingFuncCall(graph, true);
181+ EXPECT_NE(call.find("conv2d_v2"), std::string::npos);
182+ EXPECT_NE(call.find("input_2"), std::string::npos);
183+ EXPECT_NE(call.find("input_3"), std::string::npos);
184+ EXPECT_NE(call.find("CV_FUSION_ADDR"), std::string::npos);
185+ 
186+ kernel.outputs.clear();
187+ const std::string common_call = kernel.GenCubeCommonTilingSingleFuncCall(graph, "output_override");
188+ EXPECT_NE(common_call.find("input_2"), std::string::npos);
189+ EXPECT_NE(common_call.find("output_override"), std::string::npos);
190+}
191+ 
192+TEST(CodegenExtendConv2D, GenerateVecFuncOfCVFusionUsesNL0) {
193+ ge::PlatformContext::GetInstance().SetPlatform("2201");
194+ 
195+ af::AscGraph graph("cv_ub_fuse");
196+ Data data0("x", graph);
197+ Load load0("load0");
198+ graph.AddNode(load0);
199+ load0.x = data0.y;
200+ load0.y.dtype = ge::DT_FLOAT16;
201+ 
202+ auto load_node = graph.FindNode("load0");
203+ ASSERT_NE(load_node, nullptr);
204+ load_node->outputs[0].attr.mem.tensor_id = 1;
205+ load_node->outputs[0].attr.dtype = ge::DT_FLOAT16;
206+ 
207+ Kernel kernel("cv_ub_fuse_kernel");
208+ kernel.tpipe.cube_output_tensor_id = 1;
209+ ASSERT_EQ(kernel.tpipe.AddTensor(load_node->outputs[0]), af::SUCCESS);
210+ 
211+ std::stringstream ss;
212+ ASSERT_EQ(kernel.GenerateVecFuncOfCVFusion(ss, true, true), af::SUCCESS);
213+ EXPECT_NE(ss.str().find("tmpTilingData.nL0"), std::string::npos);
214+}
@@ -36,6 +36,7 @@ target_link_libraries(test_common_st ${ASCGEN_COMMON_LINK_OPTION}
36 json36 json
37 mmpa_headers37 mmpa_headers
38 metadef_headers38 metadef_headers
39+ metadef
39 error_manager40 error_manager
40 GTest::gtest41 GTest::gtest
41 GTest::gtest_main42 GTest::gtest_main
@@ -635,4 +635,146 @@ TEST_F(CommonUtilsTest, GetAscIrAttImplNotNullTest) {
635 EXPECT_NE(att_impl, nullptr);635 EXPECT_NE(att_impl, nullptr);
636 EXPECT_EQ((uint64_t)(uintptr_t)(att_impl->GetApiPerf()), 0x123456);636 EXPECT_EQ((uint64_t)(uintptr_t)(att_impl->GetApiPerf()), 0x123456);
637}637}
638+ 
639+template <typename ConvOp>
640+void FillConv2DCommonIrAttr(ConvOp &conv) {
641+ conv.ir_attr.SetStrides({1, 1, 1, 1});
642+ conv.ir_attr.SetPads({0, 0, 0, 0});
643+ conv.ir_attr.SetDilations({1, 1, 1, 1});
644+ conv.ir_attr.SetGroups(1);
645+ conv.ir_attr.SetPad_mode("SPECIFIC");
646+ conv.ir_attr.SetData_format("NCHW");
647+ conv.ir_attr.SetOffset_x(0);
648+ conv.ir_attr.SetEnable_hf32(false);
649+ conv.ir_attr.SetFixed_shift_value(0);
650+ conv.attr.api.compute_type = af::ComputeType::kComputeCube;
651+}
652+ 
653+template <typename ConvOp>
654+void FillExtendConv2DIrAttr(ConvOp &conv, bool enable_relu0 = false) {
655+ FillConv2DCommonIrAttr(conv);
656+ conv.ir_attr.SetRound_mode("rint");
657+ conv.ir_attr.SetEnable_relu0(enable_relu0);
658+}
659+ 
660+TEST_F(CommonUtilsTest, ExtendConv2DGraphTypeAndAttrParse) {
661+ af::AscGraph graph("extend_conv2d_graph");
662+ af::ascir_op::ExtendConv2D conv("extend_conv2d");
663+ graph.AddNode(conv);
664+ FillExtendConv2DIrAttr(conv);
665+ 
666+ EXPECT_TRUE(IsConv2DGraphType(graph));
667+ EXPECT_FALSE(IsConv2DTypeWithBias(graph));
668+ EXPECT_FALSE(IsConv2DTypeWithScale0(graph));
669+ EXPECT_FALSE(IsConv2DTypeWithOffsetW(graph));
670+ 
671+ auto node = graph.FindNode("extend_conv2d");
672+ ASSERT_NE(node, nullptr);
673+ Conv2DAttr attr;
674+ ASSERT_EQ(ParseConv2DAttr(node, attr), af::SUCCESS);
675+ EXPECT_TRUE(attr.is_extend_conv2d);
676+ EXPECT_FALSE(attr.has_bias);
677+ EXPECT_FALSE(attr.has_scale0);
678+ EXPECT_EQ(attr.round_mode, "rint");
679+ EXPECT_EQ(attr.pad_mode, "SPECIFIC");
680+}
681+ 
682+TEST_F(CommonUtilsTest, ExtendConv2DBiasGraphTypeAndAttrParse) {
683+ af::AscGraph graph("extend_conv2d_bias_graph");
684+ af::ascir_op::ExtendConv2DBias conv("extend_conv2d_bias");
685+ graph.AddNode(conv);
686+ FillExtendConv2DIrAttr(conv);
687+ 
688+ EXPECT_TRUE(IsConv2DGraphType(graph));
689+ EXPECT_TRUE(IsConv2DTypeWithBias(graph));
690+ EXPECT_FALSE(IsConv2DTypeWithScale0(graph));
691+ 
692+ auto node = graph.FindNode("extend_conv2d_bias");
693+ ASSERT_NE(node, nullptr);
694+ Conv2DAttr attr;
695+ ASSERT_EQ(ParseConv2DAttr(node, attr), af::SUCCESS);
696+ EXPECT_TRUE(attr.is_extend_conv2d);
697+ EXPECT_TRUE(attr.has_bias);
698+ EXPECT_FALSE(attr.has_scale0);
699+}
700+ 
701+TEST_F(CommonUtilsTest, ExtendConv2DScaleGraphTypeAndAttrParse) {
702+ af::AscGraph graph("extend_conv2d_scale_graph");
703+ af::ascir_op::ExtendConv2DScale conv("extend_conv2d_scale");
704+ graph.AddNode(conv);
705+ FillExtendConv2DIrAttr(conv);
706+ 
707+ EXPECT_TRUE(IsConv2DGraphType(graph));
708+ EXPECT_TRUE(IsConv2DTypeWithScale0(graph));
709+ EXPECT_FALSE(IsConv2DTypeWithBias(graph));
710+ 
711+ auto node = graph.FindNode("extend_conv2d_scale");
712+ ASSERT_NE(node, nullptr);
713+ Conv2DAttr attr;
714+ ASSERT_EQ(ParseConv2DAttr(node, attr), af::SUCCESS);
715+ EXPECT_TRUE(attr.is_extend_conv2d);
716+ EXPECT_TRUE(attr.has_scale0);
717+ EXPECT_FALSE(attr.has_bias);
718+}
719+ 
720+TEST_F(CommonUtilsTest, ExtendConv2DBiasScaleGraphTypeAndAttrParse) {
721+ af::AscGraph graph("extend_conv2d_bias_scale_graph");
722+ af::ascir_op::ExtendConv2DBiasScale conv("extend_conv2d_bias_scale");
723+ graph.AddNode(conv);
724+ FillExtendConv2DIrAttr(conv, true);
725+ 
726+ EXPECT_TRUE(IsConv2DGraphType(graph));
727+ EXPECT_TRUE(IsConv2DTypeWithBias(graph));
728+ EXPECT_TRUE(IsConv2DTypeWithScale0(graph));
729+ 
730+ auto node = graph.FindNode("extend_conv2d_bias_scale");
731+ ASSERT_NE(node, nullptr);
732+ Conv2DAttr attr;
733+ ASSERT_EQ(ParseConv2DAttr(node, attr), af::SUCCESS);
734+ EXPECT_TRUE(attr.is_extend_conv2d);
735+ EXPECT_TRUE(attr.has_bias);
736+ EXPECT_TRUE(attr.has_scale0);
737+ EXPECT_TRUE(attr.enable_relu0);
738+}
739+ 
740+TEST_F(CommonUtilsTest, Conv2DLegacyOptionalInputAttrParse) {
741+ {
742+ af::AscGraph graph("conv2d_bias_graph");
743+ af::ascir_op::Conv2DBias conv("conv2d_bias");
744+ graph.AddNode(conv);
745+ FillConv2DCommonIrAttr(conv);
746+ EXPECT_TRUE(IsConv2DTypeWithBias(graph));
747+ auto node = graph.FindNode("conv2d_bias");
748+ ASSERT_NE(node, nullptr);
749+ Conv2DAttr attr;
750+ ASSERT_EQ(ParseConv2DAttr(node, attr), af::SUCCESS);
751+ EXPECT_TRUE(attr.has_bias);
752+ EXPECT_FALSE(attr.has_offset_w);
753+ }
754+ {
755+ af::AscGraph graph("conv2d_offset_graph");
756+ af::ascir_op::Conv2DOffset conv("conv2d_offset");
757+ graph.AddNode(conv);
758+ FillConv2DCommonIrAttr(conv);
759+ auto node = graph.FindNode("conv2d_offset");
760+ ASSERT_NE(node, nullptr);
761+ Conv2DAttr attr;
762+ ASSERT_EQ(ParseConv2DAttr(node, attr), af::SUCCESS);
763+ EXPECT_TRUE(attr.has_offset_w);
764+ EXPECT_FALSE(attr.has_bias);
765+ }
766+ {
767+ af::AscGraph graph("conv2d_offset_bias_graph");
768+ af::ascir_op::Conv2DOffsetBias conv("conv2d_offset_bias");
769+ graph.AddNode(conv);
770+ FillConv2DCommonIrAttr(conv);
771+ EXPECT_TRUE(IsConv2DTypeWithBias(graph));
772+ auto node = graph.FindNode("conv2d_offset_bias");
773+ ASSERT_NE(node, nullptr);
774+ Conv2DAttr attr;
775+ ASSERT_EQ(ParseConv2DAttr(node, attr), af::SUCCESS);
776+ EXPECT_TRUE(attr.has_bias);
777+ EXPECT_TRUE(attr.has_offset_w);
778+ }
779+}
638} // namespace ascgen_utils780} // namespace ascgen_utils
@@ -9,11 +9,13 @@
9# See LICENSE in the root of the software repository for the full text of the License.9# See LICENSE in the root of the software repository for the full text of the License.
10# -----------------------------------------------------------------------------------------------------------10# -----------------------------------------------------------------------------------------------------------
11 11 
12-import pytest
13import json12import json
14-import time
15import os13import os
16import shutil14import shutil
15+import time
16+from collections import namedtuple
17+ 
18+import pytest
17from autofuse.pyautofuse import ascir, Autofuser, AutofuserOptions, Schedule, CodeGen19from autofuse.pyautofuse import ascir, Autofuser, AutofuserOptions, Schedule, CodeGen
18 20 
19try:21try:
@@ -875,6 +877,28 @@ class TestAutofuseLoadMatMulStoreNew:
875 )877 )
876 878 
877 879 
880+_Fp16Layout = namedtuple("_Fp16Layout", ["axes", "sizes", "strides"])
881+ 
882+ 
883+def _fill_fp16_tensor(node, layout):
884+ node.attr.sched.axis = layout.axes
885+ node.y.dtype = ascir.dtypes.float16
886+ node.y.axis = layout.axes
887+ node.y.size = layout.sizes
888+ node.y.strides = layout.strides
889+ 
890+ 
891+def _make_data_and_load(graph, name, index, layout):
892+ data = ascir.ops.Data(f"data_{name}", graph)
893+ data.attr.ir_attr.index = index
894+ _fill_fp16_tensor(data, layout)
895+ load = ascir.ops.Load(f"load_{name}")
896+ load.attr.ir_attr.offset = ascir.SizeExpr(0)
897+ load.x = data
898+ _fill_fp16_tensor(load, layout)
899+ return load
900+ 
901+ 
878class TestCubeAttributes:902class TestCubeAttributes:
879 @staticmethod903 @staticmethod
880 def construct_graph_with_cube_matmul():904 def construct_graph_with_cube_matmul():
@@ -971,6 +995,37 @@ class TestCubeAttributes:
971 graph.set_axis_map({m: [buf_m], k: [buf_k], n: [buf_n]})995 graph.set_axis_map({m: [buf_m], k: [buf_k], n: [buf_n]})
972 return graph996 return graph
973 997 
998+ @staticmethod
999+ def construct_graph_with_extend_conv2d():
1000+ if not hasattr(ascir.ops, "ExtendConv2D"):
1001+ pytest.skip("ExtendConv2D is not registered in ascir.ops")
1002+ graph = ascir.HintGraph("ExtendConv2DCube")
1003+ s0 = graph.create_size("s0")
1004+ s1 = graph.create_size("s1")
1005+ z0 = graph.create_axis("z0", s0)
1006+ z1 = graph.create_axis("z1", s1)
1007+ layout = _Fp16Layout([z0, z1], [s0, s1], [s1, ascir.SizeExpr(1)])
1008+ 
1009+ load_x = _make_data_and_load(graph, "x", 0, layout)
1010+ load_w = _make_data_and_load(graph, "w", 1, layout)
1011+ 
1012+ conv = ascir.ops.ExtendConv2D("extend_conv2d")
1013+ conv.x = load_x
1014+ conv.filter = load_w
1015+ conv.attr.api.compute_type = "cube"
1016+ _fill_fp16_tensor(conv, layout)
1017+ 
1018+ store = ascir.ops.Store("store")
1019+ store.attr.ir_attr.offset = ascir.SizeExpr(0)
1020+ store.x = conv
1021+ _fill_fp16_tensor(store, layout)
1022+ 
1023+ out = ascir.ops.Output("buf0", graph)
1024+ out.attr.ir_attr.index = 0
1025+ out.x = store
1026+ _fill_fp16_tensor(out, layout)
1027+ return graph
1028+ 
974 def test_cube_attributes_extraction(self):1029 def test_cube_attributes_extraction(self):
975 options = AutofuserOptions()1030 options = AutofuserOptions()
976 fuser = Autofuser(options)1031 fuser = Autofuser(options)
@@ -997,6 +1052,27 @@ class TestCubeAttributes:
997 # assert attr_dict["type_size"] == 2, "type_size should be 2 for float16"1052 # assert attr_dict["type_size"] == 2, "type_size should be 2 for float16"
998 # assert attr_dict["input_num"] == 2, "input_num should be 2"1053 # assert attr_dict["input_num"] == 2, "input_num should be 2"
999 1054 
1055+ def test_extend_conv2d_cube_attributes_extraction(self):
1056+ options = AutofuserOptions()
1057+ fuser = Autofuser(options)
1058+ hint_graph = self.construct_graph_with_extend_conv2d()
1059+ try:
1060+ schedule_results = fuser.schedule(hint_graph)
1061+ cube_attrs = schedule_results.get_cube_attributes()
1062+ except Exception as exc:
1063+ pytest.skip(
1064+ f"ExtendConv2D schedule/get_cube_attributes is not ready: {exc}"
1065+ )
1066+ assert isinstance(cube_attrs, dict)
1067+ if "cube_attributes" not in cube_attrs:
1068+ pytest.skip(
1069+ "schedule result does not carry cube_attributes for ExtendConv2D"
1070+ )
1071+ attr_dict = cube_attrs["cube_attributes"]
1072+ assert attr_dict.get("is_extend_conv2d") is True
1073+ assert "round_mode" in attr_dict
1074+ assert "has_scale0" in attr_dict
1075+ 
1000 1076 
1001class TestAutofuseGatherAbsStore:1077class TestAutofuseGatherAbsStore:
1002 @staticmethod1078 @staticmethod
@@ -789,4 +789,101 @@ TEST(CodegenApiParamReduceTest, BuildReduceSpecificParamsRejectsInvalidInput) {
789 EXPECT_NE(codegen::BuildReduceSpecificParams(input, param), af::SUCCESS);789 EXPECT_NE(codegen::BuildReduceSpecificParams(input, param), af::SUCCESS);
790 EXPECT_FALSE(param.valid);790 EXPECT_FALSE(param.valid);
791}791}
792+ 
793+static void FillExtendConv2DIrAttr(af::ascir_op::ExtendConv2D &conv) {
794+ conv.ir_attr.SetStrides({1, 1, 1, 1});
795+ conv.ir_attr.SetPads({0, 0, 0, 0});
796+ conv.ir_attr.SetDilations({1, 1, 1, 1});
797+ conv.ir_attr.SetGroups(1);
798+ conv.ir_attr.SetPad_mode("SPECIFIC");
799+ conv.ir_attr.SetData_format("NCHW");
800+ conv.ir_attr.SetOffset_x(0);
801+ conv.ir_attr.SetRound_mode("rint");
802+ conv.ir_attr.SetEnable_hf32(false);
803+ conv.ir_attr.SetFixed_shift_value(0);
804+ conv.ir_attr.SetEnable_relu0(false);
805+ conv.attr.api.compute_type = af::ComputeType::kComputeCube;
806+}
807+ 
808+TEST_F(CommonUtilsTest, ExtendConv2DGraphTypeAndAttrParse) {
809+ af::AscGraph graph("extend_conv2d_graph");
810+ af::ascir_op::Data data0("x", graph);
811+ af::ascir_op::Data data1("filter", graph);
812+ af::ascir_op::Load load0("load0");
813+ af::ascir_op::Load load1("load1");
814+ af::ascir_op::ExtendConv2D conv("extend_conv2d");
815+ graph.AddNode(load0);
816+ graph.AddNode(load1);
817+ graph.AddNode(conv);
818+ load0.x = data0.y;
819+ load1.x = data1.y;
820+ conv.x = load0.y;
821+ conv.filter = load1.y;
822+ FillExtendConv2DIrAttr(conv);
823+ 
824+ EXPECT_TRUE(IsConv2DGraphType(graph));
825+ EXPECT_FALSE(IsConv2DTypeWithBias(graph));
826+ EXPECT_FALSE(IsConv2DTypeWithScale0(graph));
827+ EXPECT_FALSE(IsConv2DTypeWithOffsetW(graph));
828+ 
829+ auto node = graph.FindNode("extend_conv2d");
830+ ASSERT_NE(node, nullptr);
831+ Conv2DAttr attr;
832+ ASSERT_EQ(ParseConv2DAttr(node, attr), af::SUCCESS);
833+ EXPECT_TRUE(attr.is_extend_conv2d);
834+ EXPECT_FALSE(attr.has_bias);
835+ EXPECT_FALSE(attr.has_scale0);
836+ EXPECT_EQ(attr.round_mode, "rint");
837+ EXPECT_EQ(attr.pad_mode, "SPECIFIC");
838+ EXPECT_EQ(attr.data_format, "NCHW");
839+}
840+ 
841+TEST_F(CommonUtilsTest, ExtendConv2DBiasScaleGraphType) {
842+ af::AscGraph graph("extend_conv2d_bias_scale_graph");
843+ af::ascir_op::ExtendConv2DBiasScale conv("extend_conv2d_bias_scale");
844+ graph.AddNode(conv);
845+ conv.ir_attr.SetStrides({1, 1, 1, 1});
846+ conv.ir_attr.SetPads({0, 0, 0, 0});
847+ conv.ir_attr.SetDilations({1, 1, 1, 1});
848+ conv.ir_attr.SetGroups(1);
849+ conv.ir_attr.SetPad_mode("SPECIFIC");
850+ conv.ir_attr.SetData_format("NCHW");
851+ conv.ir_attr.SetOffset_x(0);
852+ conv.ir_attr.SetRound_mode("rint");
853+ conv.ir_attr.SetEnable_hf32(false);
854+ conv.ir_attr.SetFixed_shift_value(0);
855+ conv.ir_attr.SetEnable_relu0(true);
856+ conv.attr.api.compute_type = af::ComputeType::kComputeCube;
857+ 
858+ EXPECT_TRUE(IsConv2DGraphType(graph));
859+ EXPECT_TRUE(IsConv2DTypeWithBias(graph));
860+ EXPECT_TRUE(IsConv2DTypeWithScale0(graph));
861+ 
862+ auto node = graph.FindNode("extend_conv2d_bias_scale");
863+ ASSERT_NE(node, nullptr);
864+ Conv2DAttr attr;
865+ ASSERT_EQ(ParseConv2DAttr(node, attr), af::SUCCESS);
866+ EXPECT_TRUE(attr.is_extend_conv2d);
867+ EXPECT_TRUE(attr.has_bias);
868+ EXPECT_TRUE(attr.has_scale0);
869+ EXPECT_TRUE(attr.enable_relu0);
870+}
871+ 
872+TEST_F(CommonUtilsTest, ExtendConv2DScaleGraphType) {
873+ af::AscGraph graph("extend_conv2d_scale_graph");
874+ af::ascir_op::ExtendConv2DScale conv("extend_conv2d_scale");
875+ graph.AddNode(conv);
876+ EXPECT_TRUE(IsConv2DGraphType(graph));
877+ EXPECT_TRUE(IsConv2DTypeWithScale0(graph));
878+ EXPECT_FALSE(IsConv2DTypeWithBias(graph));
879+}
880+ 
881+TEST_F(CommonUtilsTest, ExtendConv2DBiasGraphType) {
882+ af::AscGraph graph("extend_conv2d_bias_graph");
883+ af::ascir_op::ExtendConv2DBias conv("extend_conv2d_bias");
884+ graph.AddNode(conv);
885+ EXPECT_TRUE(IsConv2DGraphType(graph));
886+ EXPECT_TRUE(IsConv2DTypeWithBias(graph));
887+ EXPECT_FALSE(IsConv2DTypeWithScale0(graph));
888+}
792} // namespace ascgen_utils889} // namespace ascgen_utils
@@ -36,7 +36,7 @@ def _build_nchw_conv_args(module, input_shape, input_format):
36 {"shape": input_shape, "format": input_format, "dtype": "float16"},36 {"shape": input_shape, "format": input_format, "dtype": "float16"},
37 {"shape": [1, 64, 224, 224], "format": "NCHW", "dtype": "float16"},37 {"shape": [1, 64, 224, 224], "format": "NCHW", "dtype": "float16"},
38 ]38 ]
39- return module.build_conv_args(args_list, 1, "NCHW")39+ return module.build_conv_args(args_list, module.ConvArgsConfig(1, "NCHW"))
40 40 
41 41 
42class SimpleNamespace(object):42class SimpleNamespace(object):
@@ -209,27 +209,22 @@ class TestBuildConvArgs:
209 input_num = 2 # 只处理前2个作为输入209 input_num = 2 # 只处理前2个作为输入
210 data_format = "NCHW"210 data_format = "NCHW"
211 211 
212- origin_inputs, origin_outputs, inputs = (212+ config = asc_codegen_compile_module.ConvArgsConfig(input_num, data_format)
213- asc_codegen_compile_module.build_conv_args(213+ origin_inputs, origin_outputs = asc_codegen_compile_module.build_conv_args(
214- args_list, input_num, data_format214+ args_list, config
215- )
216 )215 )
217 216 
218 # 验证输入输出数量217 # 验证输入输出数量
219 assert len(origin_inputs) == 2218 assert len(origin_inputs) == 2
220- assert len(inputs) == 2
221 assert len(origin_outputs) == 1219 assert len(origin_outputs) == 1
222 220 
223- # 验证第一个输入(已经是 NCHW,不需要转换)221+ # 验证第一个输入 x 槽位写成 NCHW
224- assert inputs[0]["param_name"] == "input0"222+ assert origin_inputs[0]["format"] == "NCHW"
225- assert inputs[0]["format"] == "NCHW"223+ assert origin_inputs[0]["ori_format"] == "NCHW"
226 224 
227- # 验证第二个输入 HWCN -> NCHW 格式转换225+ # 验证第二个输入 filter 槽位写成 FRACTAL_Z
228- # 转换索引: [3,2,0,1]226+ assert origin_inputs[1]["format"] == "FRACTAL_Z"
229- assert inputs[1]["param_name"] == "input1"227+ assert origin_inputs[1]["ori_format"] == "NCHW"
230- assert inputs[1]["format"] == "NCHW"
231- # shape 会被转换成 tuple,这是正常的
232- assert list(inputs[1]["shape"]) == [64, 3, 7, 7]
233 228 
234 # 验证输出格式(args_list[-2] 是 dummy 元素)229 # 验证输出格式(args_list[-2] 是 dummy 元素)
235 assert origin_outputs[0]["format"] == "NCHW"230 assert origin_outputs[0]["format"] == "NCHW"
@@ -237,26 +232,86 @@ class TestBuildConvArgs:
237 232 
238 @staticmethod233 @staticmethod
239 def test_build_conv_args_nhwc_to_nchw(asc_codegen_compile_module):234 def test_build_conv_args_nhwc_to_nchw(asc_codegen_compile_module):
240- """测试 NHWC -> NCHW 格式转换"""235+ """测试 x 槽位被强制写成 NCHW"""
241- origin_inputs, origin_outputs, inputs = _build_nchw_conv_args(236+ origin_inputs, origin_outputs = _build_nchw_conv_args(
242 asc_codegen_compile_module, [1, 224, 224, 64], "NHWC"237 asc_codegen_compile_module, [1, 224, 224, 64], "NHWC"
243 )238 )
244 239 
245- assert inputs[0]["format"] == "NCHW"240+ assert origin_inputs[0]["format"] == "NCHW"
246- # shape 会被转换成 tuple,使用 list() 转换后比较241+ assert origin_inputs[0]["ori_format"] == "NCHW"
247- assert list(inputs[0]["shape"]) == [1, 64, 224, 224]242+ assert origin_inputs[0]["shape"] == [1, 224, 224, 64]
248- assert inputs[0]["ori_format"] == "NCHW"
249 243 
250 @staticmethod244 @staticmethod
251 def test_build_conv_args_same_format_no_conversion(asc_codegen_compile_module):245 def test_build_conv_args_same_format_no_conversion(asc_codegen_compile_module):
252- """测试格式相同时不转换"""246+ """测试格式相同时 shape 保持原值"""
253- origin_inputs, origin_outputs, inputs = _build_nchw_conv_args(247+ origin_inputs, origin_outputs = _build_nchw_conv_args(
254 asc_codegen_compile_module, [1, 64, 224, 224], "NCHW"248 asc_codegen_compile_module, [1, 64, 224, 224], "NCHW"
255 )249 )
256 250 
257- # 格式相同,shape 不变251+ assert origin_inputs[0]["format"] == "NCHW"
258- assert inputs[0]["format"] == "NCHW"252+ assert origin_inputs[0]["shape"] == [1, 64, 224, 224]
259- assert inputs[0]["shape"] == [1, 64, 224, 224]253+ 
254+ @staticmethod
255+ def test_build_conv_args_extend_conv2d_slots(asc_codegen_compile_module):
256+ """ExtendConv2D 固定 10 个逻辑输入槽,并补第二输出占位"""
257+ args_list = [
258+ {"shape": [1, 64, 56, 56], "format": "NCHW", "dtype": "float16"},
259+ {"shape": [64, 64, 3, 3], "format": "NCHW", "dtype": "float16"},
260+ {"shape": [64], "format": "ND", "dtype": "float16"},
261+ {"shape": [64], "format": "ND", "dtype": "uint64"},
262+ {"shape": [1, 64, 56, 56], "format": "NCHW", "dtype": "float16"},
263+ "extend_conv2d_kernel",
264+ ]
265+ 
266+ config = asc_codegen_compile_module.ConvArgsConfig(
267+ input_num=4,
268+ data_format="NCHW",
269+ has_bias=True,
270+ has_scale0=True,
271+ is_extend_conv2d=True,
272+ )
273+ origin_inputs, origin_outputs = asc_codegen_compile_module.build_conv_args(
274+ args_list, config
275+ )
276+ 
277+ assert len(origin_inputs) == 10
278+ assert origin_inputs[0] is not None
279+ assert origin_inputs[1] is not None
280+ assert origin_inputs[2] is not None
281+ assert origin_inputs[3] is None
282+ assert origin_inputs[4] is not None
283+ assert all(item is None for item in origin_inputs[5:])
284+ assert origin_inputs[0]["format"] == "NCHW"
285+ assert origin_inputs[1]["format"] == "FRACTAL_Z"
286+ assert origin_inputs[2]["format"] == "ND"
287+ assert origin_inputs[4]["format"] == "ND"
288+ assert len(origin_outputs) == 2
289+ assert origin_outputs[0]["param_name"] == "output0"
290+ 
291+ @staticmethod
292+ def test_build_conv_args_extend_conv2d_empty_optional(asc_codegen_compile_module):
293+ """ExtendConv2D 无 bias/scale0 时对应槽位为空"""
294+ args_list = [
295+ {"shape": [1, 64, 56, 56], "format": "NCHW", "dtype": "float16"},
296+ {"shape": [64, 64, 3, 3], "format": "NCHW", "dtype": "float16"},
297+ {"shape": [1, 64, 56, 56], "format": "NCHW", "dtype": "float16"},
298+ "extend_conv2d_kernel",
299+ ]
300+ 
301+ config = asc_codegen_compile_module.ConvArgsConfig(
302+ input_num=2,
303+ data_format="NCHW",
304+ is_extend_conv2d=True,
305+ )
306+ origin_inputs, origin_outputs = asc_codegen_compile_module.build_conv_args(
307+ args_list, config
308+ )
309+ 
310+ assert len(origin_inputs) == 10
311+ assert origin_inputs[0] is not None
312+ assert origin_inputs[1] is not None
313+ assert all(item is None for item in origin_inputs[2:])
314+ assert len(origin_outputs) == 2
260 315 
261 316 
262class TestGetGraphBasicInfo:317class TestGetGraphBasicInfo:
@@ -15,9 +15,6 @@
15using namespace Atcos;15using namespace Atcos;
16using namespace Atcos::Conv;16using namespace Atcos::Conv;
17 17 
18-#define CONV_A_FULL_LOAD_MODE 0U
19-#define A_FULL_LOAD_MODE 0UL
20- 
21using aLayout = Atcos::Conv::layout::NCHW;18using aLayout = Atcos::Conv::layout::NCHW;
22using bLayout = Atcos::Conv::layout::CI1KHKWCOCI0;19using bLayout = Atcos::Conv::layout::CI1KHKWCOCI0;
23using cLayout = Atcos::Conv::layout::NCHW;20using cLayout = Atcos::Conv::layout::NCHW;
@@ -25,23 +22,31 @@ using biasLayout = Atcos::Conv::layout::NCHW;
25 22 
26template <int8_t FmapTiling, int8_t WeightTiling, int8_t L1PingPong, int8_t L0PingPong, int8_t OutputOrder,23template <int8_t FmapTiling, int8_t WeightTiling, int8_t L1PingPong, int8_t L0PingPong, int8_t OutputOrder,
27 int8_t IterOrder, int8_t GroupType, int8_t EnableSmallChannel, int8_t WeightUbTrans, int8_t FmapCopyMode,24 int8_t IterOrder, int8_t GroupType, int8_t EnableSmallChannel, int8_t WeightUbTrans, int8_t FmapCopyMode,
28- int8_t InnerBatch, int8_t DisContinuous>25+ int8_t InnerBatch, int8_t DisContinuous, int8_t BatchOne, int8_t NoPad, int8_t SmallWeight,
26+ int8_t SmallKernel>
29__aicore__ void conv2d_v2(27__aicore__ void conv2d_v2(
30#ifdef CV_UB_FUSION28#ifdef CV_UB_FUSION
31- GM_ADDR aGM, GM_ADDR bGM, GM_ADDR biasGM, GM_ADDR offsetWGM, GM_ADDR cGM, GM_ADDR workspaceGM, GM_ADDR tilingGM,29+ // scaleGM 对齐 ExtendConv2D fixpipe;无 scale0 时由 codegen 传入 nullptr。
32- AutoFusionVector::Params *params30+ GM_ADDR aGM, GM_ADDR bGM, GM_ADDR biasGM, GM_ADDR offsetWGM, GM_ADDR scaleGM, GM_ADDR cGM, GM_ADDR workspaceGM,
31+ GM_ADDR tilingGM, AutoFusionVector::Params *params
33#else32#else
34- GM_ADDR aGM, GM_ADDR bGM, GM_ADDR biasGM, GM_ADDR offsetWGM, GM_ADDR cGM, GM_ADDR workspaceGM, GM_ADDR tilingGM33+ GM_ADDR aGM, GM_ADDR bGM, GM_ADDR biasGM, GM_ADDR offsetWGM, GM_ADDR scaleGM, GM_ADDR cGM, GM_ADDR workspaceGM,
34+ GM_ADDR tilingGM
35#endif35#endif
36) {36) {
37 REGISTER_TILING_DEFAULT(Conv2DTilingData);37 REGISTER_TILING_DEFAULT(Conv2DTilingData);
38 GET_TILING_DATA_WITH_STRUCT(Conv2DTilingData, tilingData, tilingGM);38 GET_TILING_DATA_WITH_STRUCT(Conv2DTilingData, tilingData, tilingGM);
39- Conv2DV2Advanced::ConvActKernel<DTYPE_X1, DTYPE_X2, DTYPE_Y, DTYPE_BIAS, aLayout, bLayout, cLayout, biasLayout,39+ // 新增 BatchOne/NoPad/SmallWeight/SmallKernel 模板维,与 ops-nn ActConvConfig 保持一致。
40- A_FULL_LOAD_MODE>(40+ using ConvConfig =
41+ Conv2DV2Advanced::ActConvConfig<FmapTiling, WeightTiling, L1PingPong, L0PingPong, OutputOrder, IterOrder,
42+ GroupType, EnableSmallChannel, WeightUbTrans, FmapCopyMode, InnerBatch,
43+ DisContinuous, BatchOne, NoPad, SmallWeight, SmallKernel>;
44+ Conv2DV2Advanced::ConvActKernel<tilingData, DTYPE_X1, DTYPE_X2, DTYPE_Y, DTYPE_BIAS, DTYPE_SCALE0, aLayout, bLayout,
45+ cLayout, biasLayout, ConvConfig>(
41#ifdef CV_UB_FUSION46#ifdef CV_UB_FUSION
42- aGM, bGM, biasGM, offsetWGM, cGM, workspaceGM, tilingData, params47+ aGM, bGM, biasGM, offsetWGM, scaleGM, cGM, workspaceGM, params
43#else48#else
44- aGM, bGM, biasGM, offsetWGM, cGM, workspaceGM, tilingData49+ aGM, bGM, biasGM, offsetWGM, scaleGM, cGM, workspaceGM
45#endif50#endif
46 );51 );
47}52}
@@ -8,6 +8,11 @@
8 * See LICENSE in the root of the software repository for the full text of the License.8 * See LICENSE in the root of the software repository for the full text of the License.
9 */9 */
10 10 
11+/* !
12+ * \file conv2d_v2_tilingkey.h
13+ * \brief
14+ */
15+ 
11#ifndef CONV2D_V2_TILINGKEY_H16#ifndef CONV2D_V2_TILINGKEY_H
12#define CONV2D_V2_TILINGKEY_H17#define CONV2D_V2_TILINGKEY_H
13 18 
@@ -15,308 +20,17 @@
15#include "arch35/conv_tilingkey.h"20#include "arch35/conv_tilingkey.h"
16#endif21#endif
17#include "arch35/conv2d_v2_inner_batch_tilingkey.h"22#include "arch35/conv2d_v2_inner_batch_tilingkey.h"
18- 23+#include "arch35/conv2d_v2_input_hwnc_tilingkey.h"
19-#ifndef CONV2D_V2_INPUT_HWNC_TILINGKEY_H
20-#define CONV2D_V2_INPUT_HWNC_TILINGKEY_H
21 24 
22namespace Conv2DV2Key {25namespace Conv2DV2Key {
23using namespace ConvKey;26using namespace ConvKey;
24 27 
25-#if (!defined(ASCENDC_TPL_PRE) && !defined(ASCENDC_TPL_KERNEL)) || \28+#define CONV2D_SCALAR_OPT_SEL(...) \
26- (defined(ORIG_DTYPE_X) && \29+ , ASCENDC_TPL_UINT_SEL(BatchOne, ASCENDC_TPL_UI_LIST, CONV_MULTI_BATCH, CONV_ONE_BATCH), \
27- ((ORIG_DTYPE_X == DT_FLOAT16) || (ORIG_DTYPE_X == DT_BF16) || (ORIG_DTYPE_X == DT_FLOAT)))30+ ASCENDC_TPL_UINT_SEL(NoPad, ASCENDC_TPL_UI_LIST, CONV_HAS_PAD, CONV_NO_PAD), \
28- 31+ ASCENDC_TPL_UINT_SEL(SmallWeight, ASCENDC_TPL_UI_LIST, __VA_ARGS__), \
29-#define CONV2D_COMMON_INPUT_HWNC_TPL_UINT_SEL() \32+ ASCENDC_TPL_UINT_SEL(SmallKernel, ASCENDC_TPL_UI_LIST, CONV_NOT_SMALL_KERNEL, CONV_SMALL_KERNEL, \
30- ASCENDC_TPL_UINT_SEL(EnableSmallChannel, ASCENDC_TPL_UI_LIST, CONV_ENABLE_SMALL_CHANNEL_CLOSE), \33+ CONV_SMALL_KERNEL_FM_PARTLOAD)
31- ASCENDC_TPL_UINT_SEL(WeightUbTrans, ASCENDC_TPL_UI_LIST, CONV_WEIGHT_UB_TRANS_CLOSE), \
32- ASCENDC_TPL_UINT_SEL(FmapCopyMode, ASCENDC_TPL_UI_LIST, CONV_FMAP_LOAD3D_MODE), \
33- ASCENDC_TPL_UINT_SEL(InnerBatch, ASCENDC_TPL_UI_LIST, CONV_INNER_BATCH_SINGLE), \
34- ASCENDC_TPL_UINT_SEL(DisContinuous, ASCENDC_TPL_UI_LIST, CONV_DIS_CONTINUOUS_INPUT_HWNC)
35- 
36-#if (defined(CV_UB_FUSION) || defined(CV_SAFETY_FUSION))
37- 
38-#define CONV2D_INPUT_HWNC_ONLY_MN_FULLLOAD_SEL() \
39- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2), CONV_COMMON_ONLY_MN_FULLLOAD_SEL(), \
40- CONV2D_COMMON_INPUT_HWNC_TPL_UINT_SEL()
41- 
42-#define CONV2D_INPUT_HWNC_NO_FULLLOAD_AL0_OPEN_SEL() \
43- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2), CONV_COMMON_NO_FULLLOAD_AL0_OPEN_SEL(), \
44- CONV2D_COMMON_INPUT_HWNC_TPL_UINT_SEL()
45- 
46-#define CONV2D_INPUT_HWNC_NO_FULLLOAD_BL0_OPEN_SEL() \
47- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2), CONV_COMMON_NO_FULLLOAD_BL0_OPEN_SEL(), \
48- CONV2D_COMMON_INPUT_HWNC_TPL_UINT_SEL()
49- 
50-#define CONV2D_INPUT_HWNC_NO_FULLLOAD_ALL_OPEN_SEL() \
51- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2), CONV_COMMON_NO_FULLLOAD_ALL_OPEN_SEL(), \
52- CONV2D_COMMON_INPUT_HWNC_TPL_UINT_SEL()
53- 
54-#define CONV2D_INPUT_HWNC_ONLY_AL1_FULLLOAD_SEL() \
55- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2), CONV_COMMON_ONLY_AL1_FULLLOAD_SEL(), \
56- CONV2D_COMMON_INPUT_HWNC_TPL_UINT_SEL()
57- 
58-#define CONV2D_INPUT_HWNC_ONLY_BL1_FULLLOAD_SEL() \
59- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2), CONV_COMMON_ONLY_BL1_FULLLOAD_SEL(), \
60- CONV2D_COMMON_INPUT_HWNC_TPL_UINT_SEL()
61- 
62-#define CONV2D_INPUT_HWNC_ABL1_FULLLOAD_M_FIRST_SEL() \
63- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2), CONV_COMMON_ABL1_FULLLOAD_M_FIRST_SEL(), \
64- CONV2D_COMMON_INPUT_HWNC_TPL_UINT_SEL()
65- 
66-#define CONV2D_INPUT_HWNC_ABL1_FULLLOAD_N_FIRST_SEL() \
67- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2), CONV_COMMON_ABL1_FULLLOAD_N_FIRST_SEL(), \
68- CONV2D_COMMON_INPUT_HWNC_TPL_UINT_SEL()
69- 
70-#define CONV2D_COMMON_INNER_BATCH_INPUT_HWNC_SEL() \
71- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2), \
72- ASCENDC_TPL_UINT_SEL(GroupType, ASCENDC_TPL_UI_LIST, CONV_GROUP_TYPE_NORMAL_CONV), \
73- ASCENDC_TPL_UINT_SEL(EnableSmallChannel, ASCENDC_TPL_UI_LIST, CONV_ENABLE_SMALL_CHANNEL_CLOSE), \
74- ASCENDC_TPL_UINT_SEL(WeightUbTrans, ASCENDC_TPL_UI_LIST, CONV_WEIGHT_UB_TRANS_CLOSE), \
75- ASCENDC_TPL_UINT_SEL(FmapCopyMode, ASCENDC_TPL_UI_LIST, CONV_FMAP_LOAD3D_MODE), \
76- ASCENDC_TPL_UINT_SEL(InnerBatch, ASCENDC_TPL_UI_LIST, CONV_INNER_BATCH_KERNEL_1X1_MULTI, \
77- CONV_INNER_BATCH_MULTI), \
78- ASCENDC_TPL_UINT_SEL(DisContinuous, ASCENDC_TPL_UI_LIST, CONV_DIS_CONTINUOUS_INPUT_HWNC)
79- 
80-#define CONV2D_INNER_BATCH_INPUT_HWNC_ONLY_MN_FULLLOAD_SEL() \
81- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2), \
82- ASCENDC_TPL_UINT_SEL(FmapTiling, ASCENDC_TPL_UI_LIST, CONV_FMAP_TILING_ONLY_M_FULLLOAD_AL1_AL0), \
83- ASCENDC_TPL_UINT_SEL(WeightTiling, ASCENDC_TPL_UI_LIST, CONV_WEIGHT_TILING_ONLY_N_FULLLOAD_BL1_BL0), \
84- ASCENDC_TPL_UINT_SEL(L1PingPong, ASCENDC_TPL_UI_LIST, CONV_L1_PINGPONG_ALL_CLOSE, CONV_L1_PINGPONG_AL1_OPEN, \
85- CONV_L1_PINGPONG_BL1_OPEN, CONV_L1_PINGPONG_ALL_OPEN), \
86- ASCENDC_TPL_UINT_SEL(L0PingPong, ASCENDC_TPL_UI_LIST, CONV_L0_PINGPONG_ALL_OPEN), \
87- ASCENDC_TPL_UINT_SEL(OutputOrder, ASCENDC_TPL_UI_LIST, CONV_OUTPUT_ORDER_M_MODE), \
88- ASCENDC_TPL_UINT_SEL(IterOrder, ASCENDC_TPL_UI_LIST, CONV_ITER_ORDER_MITER_FIRST, CONV_ITER_ORDER_NITER_FIRST), \
89- CONV2D_COMMON_INNER_BATCH_INPUT_HWNC_SEL()
90- 
91-#define CONV2D_INNER_BATCH_INPUT_HWNC_NO_FULLLOAD_AL0_OPEN_SEL() \
92- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2), \
93- ASCENDC_TPL_UINT_SEL(FmapTiling, ASCENDC_TPL_UI_LIST, CONV_FMAP_TILING_OTHER), \
94- ASCENDC_TPL_UINT_SEL(WeightTiling, ASCENDC_TPL_UI_LIST, CONV_WEIGHT_TILING_OTHER), \
95- ASCENDC_TPL_UINT_SEL(L1PingPong, ASCENDC_TPL_UI_LIST, CONV_L1_PINGPONG_ALL_CLOSE, CONV_L1_PINGPONG_AL1_OPEN, \
96- CONV_L1_PINGPONG_BL1_OPEN, CONV_L1_PINGPONG_ALL_OPEN), \
97- ASCENDC_TPL_UINT_SEL(L0PingPong, ASCENDC_TPL_UI_LIST, CONV_L0_PINGPONG_AL0_OPEN), \
98- ASCENDC_TPL_UINT_SEL(OutputOrder, ASCENDC_TPL_UI_LIST, CONV_OUTPUT_ORDER_M_MODE), \
99- ASCENDC_TPL_UINT_SEL(IterOrder, ASCENDC_TPL_UI_LIST, CONV_ITER_ORDER_MITER_FIRST), \
100- CONV2D_COMMON_INNER_BATCH_INPUT_HWNC_SEL()
101- 
102-#define CONV2D_INNER_BATCH_INPUT_HWNC_NO_FULLLOAD_BL0_OPEN_SEL() \
103- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2), \
104- ASCENDC_TPL_UINT_SEL(FmapTiling, ASCENDC_TPL_UI_LIST, CONV_FMAP_TILING_OTHER), \
105- ASCENDC_TPL_UINT_SEL(WeightTiling, ASCENDC_TPL_UI_LIST, CONV_WEIGHT_TILING_OTHER), \
106- ASCENDC_TPL_UINT_SEL(L1PingPong, ASCENDC_TPL_UI_LIST, CONV_L1_PINGPONG_ALL_CLOSE, CONV_L1_PINGPONG_AL1_OPEN, \
107- CONV_L1_PINGPONG_BL1_OPEN, CONV_L1_PINGPONG_ALL_OPEN), \
108- ASCENDC_TPL_UINT_SEL(L0PingPong, ASCENDC_TPL_UI_LIST, CONV_L0_PINGPONG_BL0_OPEN), \
109- ASCENDC_TPL_UINT_SEL(OutputOrder, ASCENDC_TPL_UI_LIST, CONV_OUTPUT_ORDER_M_MODE), \
110- ASCENDC_TPL_UINT_SEL(IterOrder, ASCENDC_TPL_UI_LIST, CONV_ITER_ORDER_NITER_FIRST), \
111- CONV2D_COMMON_INNER_BATCH_INPUT_HWNC_SEL()
112- 
113-#define CONV2D_INNER_BATCH_INPUT_HWNC_NO_FULLLOAD_ALL_OPEN_SEL() \
114- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2), \
115- ASCENDC_TPL_UINT_SEL(FmapTiling, ASCENDC_TPL_UI_LIST, CONV_FMAP_TILING_OTHER), \
116- ASCENDC_TPL_UINT_SEL(WeightTiling, ASCENDC_TPL_UI_LIST, CONV_WEIGHT_TILING_OTHER), \
117- ASCENDC_TPL_UINT_SEL(L1PingPong, ASCENDC_TPL_UI_LIST, CONV_L1_PINGPONG_ALL_CLOSE, CONV_L1_PINGPONG_AL1_OPEN, \
118- CONV_L1_PINGPONG_BL1_OPEN, CONV_L1_PINGPONG_ALL_OPEN), \
119- ASCENDC_TPL_UINT_SEL(L0PingPong, ASCENDC_TPL_UI_LIST, CONV_L0_PINGPONG_ALL_OPEN), \
120- ASCENDC_TPL_UINT_SEL(OutputOrder, ASCENDC_TPL_UI_LIST, CONV_OUTPUT_ORDER_M_MODE), \
121- ASCENDC_TPL_UINT_SEL(IterOrder, ASCENDC_TPL_UI_LIST, CONV_ITER_ORDER_MITER_FIRST, CONV_ITER_ORDER_NITER_FIRST), \
122- CONV2D_COMMON_INNER_BATCH_INPUT_HWNC_SEL()
123- 
124-#define CONV2D_INNER_BATCH_INPUT_HWNC_ONLY_AL1_FULLLOAD_SEL() \
125- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2), \
126- ASCENDC_TPL_UINT_SEL(FmapTiling, ASCENDC_TPL_UI_LIST, CONV_FMAP_TILING_FULLLOAD_AL1), \
127- ASCENDC_TPL_UINT_SEL(WeightTiling, ASCENDC_TPL_UI_LIST, CONV_WEIGHT_TILING_OTHER), \
128- ASCENDC_TPL_UINT_SEL(L1PingPong, ASCENDC_TPL_UI_LIST, CONV_L1_PINGPONG_ALL_CLOSE, CONV_L1_PINGPONG_BL1_OPEN), \
129- ASCENDC_TPL_UINT_SEL(L0PingPong, ASCENDC_TPL_UI_LIST, CONV_L0_PINGPONG_BL0_OPEN, CONV_L0_PINGPONG_ALL_OPEN), \
130- ASCENDC_TPL_UINT_SEL(OutputOrder, ASCENDC_TPL_UI_LIST, CONV_OUTPUT_ORDER_M_MODE), \
131- ASCENDC_TPL_UINT_SEL(IterOrder, ASCENDC_TPL_UI_LIST, CONV_ITER_ORDER_NITER_FIRST), \
132- CONV2D_COMMON_INNER_BATCH_INPUT_HWNC_SEL()
133- 
134-#define CONV2D_INNER_BATCH_INPUT_HWNC_ONLY_BL1_FULLLOAD_SEL() \
135- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2), \
136- ASCENDC_TPL_UINT_SEL(FmapTiling, ASCENDC_TPL_UI_LIST, CONV_FMAP_TILING_OTHER), \
137- ASCENDC_TPL_UINT_SEL(WeightTiling, ASCENDC_TPL_UI_LIST, CONV_WEIGHT_TILING_FULLLOAD_BL1), \
138- ASCENDC_TPL_UINT_SEL(L1PingPong, ASCENDC_TPL_UI_LIST, CONV_L1_PINGPONG_ALL_CLOSE, CONV_L1_PINGPONG_AL1_OPEN), \
139- ASCENDC_TPL_UINT_SEL(L0PingPong, ASCENDC_TPL_UI_LIST, CONV_L0_PINGPONG_ALL_CLOSE, CONV_L0_PINGPONG_AL0_OPEN, \
140- CONV_L0_PINGPONG_ALL_OPEN), \
141- ASCENDC_TPL_UINT_SEL(OutputOrder, ASCENDC_TPL_UI_LIST, CONV_OUTPUT_ORDER_M_MODE), \
142- ASCENDC_TPL_UINT_SEL(IterOrder, ASCENDC_TPL_UI_LIST, CONV_ITER_ORDER_MITER_FIRST), \
143- CONV2D_COMMON_INNER_BATCH_INPUT_HWNC_SEL()
144- 
145-#define CONV2D_INNER_BATCH_INPUT_HWNC_ABL1_FULLLOAD_M_FIRST_SEL() \
146- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2), \
147- ASCENDC_TPL_UINT_SEL(FmapTiling, ASCENDC_TPL_UI_LIST, CONV_FMAP_TILING_FULLLOAD_AL1), \
148- ASCENDC_TPL_UINT_SEL(WeightTiling, ASCENDC_TPL_UI_LIST, CONV_WEIGHT_TILING_FULLLOAD_BL1), \
149- ASCENDC_TPL_UINT_SEL(L1PingPong, ASCENDC_TPL_UI_LIST, CONV_L1_PINGPONG_ALL_CLOSE), \
150- ASCENDC_TPL_UINT_SEL(L0PingPong, ASCENDC_TPL_UI_LIST, CONV_L0_PINGPONG_ALL_CLOSE, CONV_L0_PINGPONG_AL0_OPEN, \
151- CONV_L0_PINGPONG_ALL_OPEN), \
152- ASCENDC_TPL_UINT_SEL(OutputOrder, ASCENDC_TPL_UI_LIST, CONV_OUTPUT_ORDER_M_MODE), \
153- ASCENDC_TPL_UINT_SEL(IterOrder, ASCENDC_TPL_UI_LIST, CONV_ITER_ORDER_MITER_FIRST), \
154- CONV2D_COMMON_INNER_BATCH_INPUT_HWNC_SEL()
155- 
156-#define CONV2D_INNER_BATCH_INPUT_HWNC_ABL1_FULLLOAD_N_FIRST_SEL() \
157- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2), \
158- ASCENDC_TPL_UINT_SEL(FmapTiling, ASCENDC_TPL_UI_LIST, CONV_FMAP_TILING_FULLLOAD_AL1), \
159- ASCENDC_TPL_UINT_SEL(WeightTiling, ASCENDC_TPL_UI_LIST, CONV_WEIGHT_TILING_FULLLOAD_BL1), \
160- ASCENDC_TPL_UINT_SEL(L1PingPong, ASCENDC_TPL_UI_LIST, CONV_L1_PINGPONG_ALL_CLOSE), \
161- ASCENDC_TPL_UINT_SEL(L0PingPong, ASCENDC_TPL_UI_LIST, CONV_L0_PINGPONG_BL0_OPEN, CONV_L0_PINGPONG_ALL_OPEN), \
162- ASCENDC_TPL_UINT_SEL(OutputOrder, ASCENDC_TPL_UI_LIST, CONV_OUTPUT_ORDER_M_MODE), \
163- ASCENDC_TPL_UINT_SEL(IterOrder, ASCENDC_TPL_UI_LIST, CONV_ITER_ORDER_NITER_FIRST), \
164- CONV2D_COMMON_INNER_BATCH_INPUT_HWNC_SEL()
165-#else
166-#define CONV2D_INPUT_HWNC_ONLY_MN_FULLLOAD_SEL() \
167- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_AIC_ONLY), CONV_COMMON_ONLY_MN_FULLLOAD_SEL(), \
168- CONV2D_COMMON_INPUT_HWNC_TPL_UINT_SEL()
169- 
170-#define CONV2D_INPUT_HWNC_NO_FULLLOAD_AL0_OPEN_SEL() \
171- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_AIC_ONLY), CONV_COMMON_NO_FULLLOAD_AL0_OPEN_SEL(), \
172- CONV2D_COMMON_INPUT_HWNC_TPL_UINT_SEL()
173- 
174-#define CONV2D_INPUT_HWNC_NO_FULLLOAD_BL0_OPEN_SEL() \
175- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_AIC_ONLY), CONV_COMMON_NO_FULLLOAD_BL0_OPEN_SEL(), \
176- CONV2D_COMMON_INPUT_HWNC_TPL_UINT_SEL()
177- 
178-#define CONV2D_INPUT_HWNC_NO_FULLLOAD_ALL_OPEN_SEL() \
179- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_AIC_ONLY), CONV_COMMON_NO_FULLLOAD_ALL_OPEN_SEL(), \
180- CONV2D_COMMON_INPUT_HWNC_TPL_UINT_SEL()
181- 
182-#define CONV2D_INPUT_HWNC_ONLY_AL1_FULLLOAD_SEL() \
183- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_AIC_ONLY), CONV_COMMON_ONLY_AL1_FULLLOAD_SEL(), \
184- CONV2D_COMMON_INPUT_HWNC_TPL_UINT_SEL()
185- 
186-#define CONV2D_INPUT_HWNC_ONLY_BL1_FULLLOAD_SEL() \
187- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_AIC_ONLY), CONV_COMMON_ONLY_BL1_FULLLOAD_SEL(), \
188- CONV2D_COMMON_INPUT_HWNC_TPL_UINT_SEL()
189- 
190-#define CONV2D_INPUT_HWNC_ABL1_FULLLOAD_M_FIRST_SEL() \
191- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_AIC_ONLY), CONV_COMMON_ABL1_FULLLOAD_M_FIRST_SEL(), \
192- CONV2D_COMMON_INPUT_HWNC_TPL_UINT_SEL()
193- 
194-#define CONV2D_INPUT_HWNC_ABL1_FULLLOAD_N_FIRST_SEL() \
195- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_AIC_ONLY), CONV_COMMON_ABL1_FULLLOAD_N_FIRST_SEL(), \
196- CONV2D_COMMON_INPUT_HWNC_TPL_UINT_SEL()
197- 
198-#define CONV2D_COMMON_INNER_BATCH_INPUT_HWNC_SEL() \
199- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_AIC_ONLY), \
200- ASCENDC_TPL_UINT_SEL(GroupType, ASCENDC_TPL_UI_LIST, CONV_GROUP_TYPE_NORMAL_CONV), \
201- ASCENDC_TPL_UINT_SEL(EnableSmallChannel, ASCENDC_TPL_UI_LIST, CONV_ENABLE_SMALL_CHANNEL_CLOSE), \
202- ASCENDC_TPL_UINT_SEL(WeightUbTrans, ASCENDC_TPL_UI_LIST, CONV_WEIGHT_UB_TRANS_CLOSE), \
203- ASCENDC_TPL_UINT_SEL(FmapCopyMode, ASCENDC_TPL_UI_LIST, CONV_FMAP_LOAD3D_MODE), \
204- ASCENDC_TPL_UINT_SEL(InnerBatch, ASCENDC_TPL_UI_LIST, CONV_INNER_BATCH_KERNEL_1X1_MULTI, \
205- CONV_INNER_BATCH_MULTI), \
206- ASCENDC_TPL_UINT_SEL(DisContinuous, ASCENDC_TPL_UI_LIST, CONV_DIS_CONTINUOUS_INPUT_HWNC)
207- 
208-#define CONV2D_INNER_BATCH_INPUT_HWNC_ONLY_MN_FULLLOAD_SEL() \
209- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_AIC_ONLY), \
210- ASCENDC_TPL_UINT_SEL(FmapTiling, ASCENDC_TPL_UI_LIST, CONV_FMAP_TILING_ONLY_M_FULLLOAD_AL1_AL0), \
211- ASCENDC_TPL_UINT_SEL(WeightTiling, ASCENDC_TPL_UI_LIST, CONV_WEIGHT_TILING_ONLY_N_FULLLOAD_BL1_BL0), \
212- ASCENDC_TPL_UINT_SEL(L1PingPong, ASCENDC_TPL_UI_LIST, CONV_L1_PINGPONG_ALL_CLOSE, CONV_L1_PINGPONG_AL1_OPEN, \
213- CONV_L1_PINGPONG_BL1_OPEN, CONV_L1_PINGPONG_ALL_OPEN), \
214- ASCENDC_TPL_UINT_SEL(L0PingPong, ASCENDC_TPL_UI_LIST, CONV_L0_PINGPONG_ALL_OPEN), \
215- ASCENDC_TPL_UINT_SEL(OutputOrder, ASCENDC_TPL_UI_LIST, CONV_OUTPUT_ORDER_M_MODE), \
216- ASCENDC_TPL_UINT_SEL(IterOrder, ASCENDC_TPL_UI_LIST, CONV_ITER_ORDER_MITER_FIRST, CONV_ITER_ORDER_NITER_FIRST), \
217- CONV2D_COMMON_INNER_BATCH_INPUT_HWNC_SEL()
218- 
219-#define CONV2D_INNER_BATCH_INPUT_HWNC_NO_FULLLOAD_AL0_OPEN_SEL() \
220- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_AIC_ONLY), \
221- ASCENDC_TPL_UINT_SEL(FmapTiling, ASCENDC_TPL_UI_LIST, CONV_FMAP_TILING_OTHER), \
222- ASCENDC_TPL_UINT_SEL(WeightTiling, ASCENDC_TPL_UI_LIST, CONV_WEIGHT_TILING_OTHER), \
223- ASCENDC_TPL_UINT_SEL(L1PingPong, ASCENDC_TPL_UI_LIST, CONV_L1_PINGPONG_ALL_CLOSE, CONV_L1_PINGPONG_AL1_OPEN, \
224- CONV_L1_PINGPONG_BL1_OPEN, CONV_L1_PINGPONG_ALL_OPEN), \
225- ASCENDC_TPL_UINT_SEL(L0PingPong, ASCENDC_TPL_UI_LIST, CONV_L0_PINGPONG_AL0_OPEN), \
226- ASCENDC_TPL_UINT_SEL(OutputOrder, ASCENDC_TPL_UI_LIST, CONV_OUTPUT_ORDER_M_MODE), \
227- ASCENDC_TPL_UINT_SEL(IterOrder, ASCENDC_TPL_UI_LIST, CONV_ITER_ORDER_MITER_FIRST), \
228- CONV2D_COMMON_INNER_BATCH_INPUT_HWNC_SEL()
229- 
230-#define CONV2D_INNER_BATCH_INPUT_HWNC_NO_FULLLOAD_BL0_OPEN_SEL() \
231- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_AIC_ONLY), \
232- ASCENDC_TPL_UINT_SEL(FmapTiling, ASCENDC_TPL_UI_LIST, CONV_FMAP_TILING_OTHER), \
233- ASCENDC_TPL_UINT_SEL(WeightTiling, ASCENDC_TPL_UI_LIST, CONV_WEIGHT_TILING_OTHER), \
234- ASCENDC_TPL_UINT_SEL(L1PingPong, ASCENDC_TPL_UI_LIST, CONV_L1_PINGPONG_ALL_CLOSE, CONV_L1_PINGPONG_AL1_OPEN, \
235- CONV_L1_PINGPONG_BL1_OPEN, CONV_L1_PINGPONG_ALL_OPEN), \
236- ASCENDC_TPL_UINT_SEL(L0PingPong, ASCENDC_TPL_UI_LIST, CONV_L0_PINGPONG_BL0_OPEN), \
237- ASCENDC_TPL_UINT_SEL(OutputOrder, ASCENDC_TPL_UI_LIST, CONV_OUTPUT_ORDER_M_MODE), \
238- ASCENDC_TPL_UINT_SEL(IterOrder, ASCENDC_TPL_UI_LIST, CONV_ITER_ORDER_NITER_FIRST), \
239- CONV2D_COMMON_INNER_BATCH_INPUT_HWNC_SEL()
240- 
241-#define CONV2D_INNER_BATCH_INPUT_HWNC_NO_FULLLOAD_ALL_OPEN_SEL() \
242- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_AIC_ONLY), \
243- ASCENDC_TPL_UINT_SEL(FmapTiling, ASCENDC_TPL_UI_LIST, CONV_FMAP_TILING_OTHER), \
244- ASCENDC_TPL_UINT_SEL(WeightTiling, ASCENDC_TPL_UI_LIST, CONV_WEIGHT_TILING_OTHER), \
245- ASCENDC_TPL_UINT_SEL(L1PingPong, ASCENDC_TPL_UI_LIST, CONV_L1_PINGPONG_ALL_CLOSE, CONV_L1_PINGPONG_AL1_OPEN, \
246- CONV_L1_PINGPONG_BL1_OPEN, CONV_L1_PINGPONG_ALL_OPEN), \
247- ASCENDC_TPL_UINT_SEL(L0PingPong, ASCENDC_TPL_UI_LIST, CONV_L0_PINGPONG_ALL_OPEN), \
248- ASCENDC_TPL_UINT_SEL(OutputOrder, ASCENDC_TPL_UI_LIST, CONV_OUTPUT_ORDER_M_MODE), \
249- ASCENDC_TPL_UINT_SEL(IterOrder, ASCENDC_TPL_UI_LIST, CONV_ITER_ORDER_MITER_FIRST, CONV_ITER_ORDER_NITER_FIRST), \
250- CONV2D_COMMON_INNER_BATCH_INPUT_HWNC_SEL()
251- 
252-#define CONV2D_INNER_BATCH_INPUT_HWNC_ONLY_AL1_FULLLOAD_SEL() \
253- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_AIC_ONLY), \
254- ASCENDC_TPL_UINT_SEL(FmapTiling, ASCENDC_TPL_UI_LIST, CONV_FMAP_TILING_FULLLOAD_AL1), \
255- ASCENDC_TPL_UINT_SEL(WeightTiling, ASCENDC_TPL_UI_LIST, CONV_WEIGHT_TILING_OTHER), \
256- ASCENDC_TPL_UINT_SEL(L1PingPong, ASCENDC_TPL_UI_LIST, CONV_L1_PINGPONG_ALL_CLOSE, CONV_L1_PINGPONG_BL1_OPEN), \
257- ASCENDC_TPL_UINT_SEL(L0PingPong, ASCENDC_TPL_UI_LIST, CONV_L0_PINGPONG_BL0_OPEN, CONV_L0_PINGPONG_ALL_OPEN), \
258- ASCENDC_TPL_UINT_SEL(OutputOrder, ASCENDC_TPL_UI_LIST, CONV_OUTPUT_ORDER_M_MODE), \
259- ASCENDC_TPL_UINT_SEL(IterOrder, ASCENDC_TPL_UI_LIST, CONV_ITER_ORDER_NITER_FIRST), \
260- CONV2D_COMMON_INNER_BATCH_INPUT_HWNC_SEL()
261- 
262-#define CONV2D_INNER_BATCH_INPUT_HWNC_ONLY_BL1_FULLLOAD_SEL() \
263- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_AIC_ONLY), \
264- ASCENDC_TPL_UINT_SEL(FmapTiling, ASCENDC_TPL_UI_LIST, CONV_FMAP_TILING_OTHER), \
265- ASCENDC_TPL_UINT_SEL(WeightTiling, ASCENDC_TPL_UI_LIST, CONV_WEIGHT_TILING_FULLLOAD_BL1), \
266- ASCENDC_TPL_UINT_SEL(L1PingPong, ASCENDC_TPL_UI_LIST, CONV_L1_PINGPONG_ALL_CLOSE, CONV_L1_PINGPONG_AL1_OPEN), \
267- ASCENDC_TPL_UINT_SEL(L0PingPong, ASCENDC_TPL_UI_LIST, CONV_L0_PINGPONG_ALL_CLOSE, CONV_L0_PINGPONG_AL0_OPEN, \
268- CONV_L0_PINGPONG_ALL_OPEN), \
269- ASCENDC_TPL_UINT_SEL(OutputOrder, ASCENDC_TPL_UI_LIST, CONV_OUTPUT_ORDER_M_MODE), \
270- ASCENDC_TPL_UINT_SEL(IterOrder, ASCENDC_TPL_UI_LIST, CONV_ITER_ORDER_MITER_FIRST), \
271- CONV2D_COMMON_INNER_BATCH_INPUT_HWNC_SEL()
272- 
273-#define CONV2D_INNER_BATCH_INPUT_HWNC_ABL1_FULLLOAD_M_FIRST_SEL() \
274- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_AIC_ONLY), \
275- ASCENDC_TPL_UINT_SEL(FmapTiling, ASCENDC_TPL_UI_LIST, CONV_FMAP_TILING_FULLLOAD_AL1), \
276- ASCENDC_TPL_UINT_SEL(WeightTiling, ASCENDC_TPL_UI_LIST, CONV_WEIGHT_TILING_FULLLOAD_BL1), \
277- ASCENDC_TPL_UINT_SEL(L1PingPong, ASCENDC_TPL_UI_LIST, CONV_L1_PINGPONG_ALL_CLOSE), \
278- ASCENDC_TPL_UINT_SEL(L0PingPong, ASCENDC_TPL_UI_LIST, CONV_L0_PINGPONG_ALL_CLOSE, CONV_L0_PINGPONG_AL0_OPEN, \
279- CONV_L0_PINGPONG_ALL_OPEN), \
280- ASCENDC_TPL_UINT_SEL(OutputOrder, ASCENDC_TPL_UI_LIST, CONV_OUTPUT_ORDER_M_MODE), \
281- ASCENDC_TPL_UINT_SEL(IterOrder, ASCENDC_TPL_UI_LIST, CONV_ITER_ORDER_MITER_FIRST), \
282- CONV2D_COMMON_INNER_BATCH_INPUT_HWNC_SEL()
283- 
284-#define CONV2D_INNER_BATCH_INPUT_HWNC_ABL1_FULLLOAD_N_FIRST_SEL() \
285- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_AIC_ONLY), \
286- ASCENDC_TPL_UINT_SEL(FmapTiling, ASCENDC_TPL_UI_LIST, CONV_FMAP_TILING_FULLLOAD_AL1), \
287- ASCENDC_TPL_UINT_SEL(WeightTiling, ASCENDC_TPL_UI_LIST, CONV_WEIGHT_TILING_FULLLOAD_BL1), \
288- ASCENDC_TPL_UINT_SEL(L1PingPong, ASCENDC_TPL_UI_LIST, CONV_L1_PINGPONG_ALL_CLOSE), \
289- ASCENDC_TPL_UINT_SEL(L0PingPong, ASCENDC_TPL_UI_LIST, CONV_L0_PINGPONG_BL0_OPEN, CONV_L0_PINGPONG_ALL_OPEN), \
290- ASCENDC_TPL_UINT_SEL(OutputOrder, ASCENDC_TPL_UI_LIST, CONV_OUTPUT_ORDER_M_MODE), \
291- ASCENDC_TPL_UINT_SEL(IterOrder, ASCENDC_TPL_UI_LIST, CONV_ITER_ORDER_NITER_FIRST), \
292- CONV2D_COMMON_INNER_BATCH_INPUT_HWNC_SEL()
293-#endif
294- 
295-#else
296-#define CONV2D_INPUT_HWNC_ONLY_MN_FULLLOAD_SEL()
297-#define CONV2D_INPUT_HWNC_NO_FULLLOAD_AL0_OPEN_SEL()
298-#define CONV2D_INPUT_HWNC_NO_FULLLOAD_BL0_OPEN_SEL()
299-#define CONV2D_INPUT_HWNC_NO_FULLLOAD_ALL_OPEN_SEL()
300-#define CONV2D_INPUT_HWNC_ONLY_AL1_FULLLOAD_SEL()
301-#define CONV2D_INPUT_HWNC_ONLY_BL1_FULLLOAD_SEL()
302-#define CONV2D_INPUT_HWNC_ABL1_FULLLOAD_M_FIRST_SEL()
303-#define CONV2D_INPUT_HWNC_ABL1_FULLLOAD_N_FIRST_SEL()
304-#define CONV2D_INNER_BATCH_INPUT_HWNC_ONLY_MN_FULLLOAD_SEL()
305-#define CONV2D_INNER_BATCH_INPUT_HWNC_NO_FULLLOAD_AL0_OPEN_SEL()
306-#define CONV2D_INNER_BATCH_INPUT_HWNC_NO_FULLLOAD_BL0_OPEN_SEL()
307-#define CONV2D_INNER_BATCH_INPUT_HWNC_NO_FULLLOAD_ALL_OPEN_SEL()
308-#define CONV2D_INNER_BATCH_INPUT_HWNC_ONLY_AL1_FULLLOAD_SEL()
309-#define CONV2D_INNER_BATCH_INPUT_HWNC_ONLY_BL1_FULLLOAD_SEL()
310-#define CONV2D_INNER_BATCH_INPUT_HWNC_ABL1_FULLLOAD_M_FIRST_SEL()
311-#define CONV2D_INNER_BATCH_INPUT_HWNC_ABL1_FULLLOAD_N_FIRST_SEL()
312-#endif
313- 
314-} // namespace Conv2DV2Key
315- 
316-#endif // CONV2D_V2_INPUT_HWNC_TILINGKEY_H
317- 
318-namespace Conv2DV2Key {
319-using namespace ConvKey;
320 34 
321ASCENDC_TPL_ARGS_DECL(35ASCENDC_TPL_ARGS_DECL(
322 Conv2DV2,36 Conv2DV2,
@@ -343,14 +57,21 @@ ASCENDC_TPL_ARGS_DECL(
343 ASCENDC_TPL_UINT_DECL(InnerBatch, ASCENDC_TPL_2_BW, ASCENDC_TPL_UI_LIST, CONV_INNER_BATCH_SINGLE,57 ASCENDC_TPL_UINT_DECL(InnerBatch, ASCENDC_TPL_2_BW, ASCENDC_TPL_UI_LIST, CONV_INNER_BATCH_SINGLE,
344 CONV_INNER_BATCH_KERNEL_1X1_MULTI, CONV_INNER_BATCH_MULTI),58 CONV_INNER_BATCH_KERNEL_1X1_MULTI, CONV_INNER_BATCH_MULTI),
345 ASCENDC_TPL_UINT_DECL(DisContinuous, ASCENDC_TPL_2_BW, ASCENDC_TPL_UI_LIST, CONV_DIS_CONTINUOUS_CLOSE,59 ASCENDC_TPL_UINT_DECL(DisContinuous, ASCENDC_TPL_2_BW, ASCENDC_TPL_UI_LIST, CONV_DIS_CONTINUOUS_CLOSE,
346- CONV_DIS_CONTINUOUS_INPUT_HWNC));60+ CONV_DIS_CONTINUOUS_INPUT_HWNC),
61+ ASCENDC_TPL_UINT_DECL(BatchOne, ASCENDC_TPL_1_BW, ASCENDC_TPL_UI_LIST, CONV_MULTI_BATCH, CONV_ONE_BATCH),
62+ ASCENDC_TPL_UINT_DECL(NoPad, ASCENDC_TPL_1_BW, ASCENDC_TPL_UI_LIST, CONV_HAS_PAD, CONV_NO_PAD),
63+ ASCENDC_TPL_UINT_DECL(SmallWeight, ASCENDC_TPL_2_BW, ASCENDC_TPL_UI_LIST, CONV_NOT_SMALL_WEIGHT,
64+ CONV_FULLLOAD_KL1_NL0, CONV_WEIGHT_SMALLER_THAN_BL0),
65+ ASCENDC_TPL_UINT_DECL(SmallKernel, ASCENDC_TPL_2_BW, ASCENDC_TPL_UI_LIST, CONV_NOT_SMALL_KERNEL, CONV_SMALL_KERNEL,
66+ CONV_SMALL_KERNEL_FM_PARTLOAD));
347 67 
348#define CONV2D_COMMON_C04_TPL_UINT_SEL() \68#define CONV2D_COMMON_C04_TPL_UINT_SEL() \
349 ASCENDC_TPL_UINT_SEL(EnableSmallChannel, ASCENDC_TPL_UI_LIST, CONV_ENABLE_SMALL_CHANNEL_CLOSE), \69 ASCENDC_TPL_UINT_SEL(EnableSmallChannel, ASCENDC_TPL_UI_LIST, CONV_ENABLE_SMALL_CHANNEL_CLOSE), \
350 ASCENDC_TPL_UINT_SEL(WeightUbTrans, ASCENDC_TPL_UI_LIST, CONV_WEIGHT_UB_TRANS_CLOSE), \70 ASCENDC_TPL_UINT_SEL(WeightUbTrans, ASCENDC_TPL_UI_LIST, CONV_WEIGHT_UB_TRANS_CLOSE), \
351 ASCENDC_TPL_UINT_SEL(FmapCopyMode, ASCENDC_TPL_UI_LIST, CONV_FMAP_LOAD3D_MODE), \71 ASCENDC_TPL_UINT_SEL(FmapCopyMode, ASCENDC_TPL_UI_LIST, CONV_FMAP_LOAD3D_MODE), \
352 ASCENDC_TPL_UINT_SEL(InnerBatch, ASCENDC_TPL_UI_LIST, CONV_INNER_BATCH_SINGLE), \72 ASCENDC_TPL_UINT_SEL(InnerBatch, ASCENDC_TPL_UI_LIST, CONV_INNER_BATCH_SINGLE), \
353- ASCENDC_TPL_UINT_SEL(DisContinuous, ASCENDC_TPL_UI_LIST, CONV_DIS_CONTINUOUS_CLOSE)73+ ASCENDC_TPL_UINT_SEL(DisContinuous, ASCENDC_TPL_UI_LIST, CONV_DIS_CONTINUOUS_CLOSE) \
74+ CONV2D_SCALAR_OPT_SEL(CONV_NOT_SMALL_WEIGHT, CONV_FULLLOAD_KL1_NL0, CONV_WEIGHT_SMALLER_THAN_BL0)
354 75 
355#define CONV2D_COMMON_C04_MIXCORE_TPL_UINT_SEL() \76#define CONV2D_COMMON_C04_MIXCORE_TPL_UINT_SEL() \
356 ASCENDC_TPL_UINT_SEL(EnableSmallChannel, ASCENDC_TPL_UI_LIST, CONV_ENABLE_SMALL_CHANNEL_OPEN), \77 ASCENDC_TPL_UINT_SEL(EnableSmallChannel, ASCENDC_TPL_UI_LIST, CONV_ENABLE_SMALL_CHANNEL_OPEN), \
@@ -358,41 +79,9 @@ ASCENDC_TPL_ARGS_DECL(
358 ASCENDC_TPL_UINT_SEL(FmapCopyMode, ASCENDC_TPL_UI_LIST, CONV_FMAP_LOAD3D_MODE), \79 ASCENDC_TPL_UINT_SEL(FmapCopyMode, ASCENDC_TPL_UI_LIST, CONV_FMAP_LOAD3D_MODE), \
359 ASCENDC_TPL_UINT_SEL(InnerBatch, ASCENDC_TPL_UI_LIST, CONV_INNER_BATCH_SINGLE), \80 ASCENDC_TPL_UINT_SEL(InnerBatch, ASCENDC_TPL_UI_LIST, CONV_INNER_BATCH_SINGLE), \
360 ASCENDC_TPL_UINT_SEL(DisContinuous, ASCENDC_TPL_UI_LIST, CONV_DIS_CONTINUOUS_CLOSE, \81 ASCENDC_TPL_UINT_SEL(DisContinuous, ASCENDC_TPL_UI_LIST, CONV_DIS_CONTINUOUS_CLOSE, \
361- CONV_DIS_CONTINUOUS_INPUT_HWNC)82+ CONV_DIS_CONTINUOUS_INPUT_HWNC) \
83+ CONV2D_SCALAR_OPT_SEL(CONV_NOT_SMALL_WEIGHT, CONV_FULLLOAD_KL1_NL0, CONV_WEIGHT_SMALLER_THAN_BL0)
362 84 
363-#if (defined(CV_UB_FUSION) || defined(CV_SAFETY_FUSION))
364-#define CONV2D_ONLY_MN_FULLLOAD_SEL() \
365- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2), CONV_COMMON_ONLY_MN_FULLLOAD_SEL(), \
366- CONV2D_COMMON_C04_TPL_UINT_SEL()
367- 
368-#define CONV2D_NO_FULLLOAD_AL0_OPEN_SEL() \
369- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2), CONV_COMMON_NO_FULLLOAD_AL0_OPEN_SEL(), \
370- CONV2D_COMMON_C04_TPL_UINT_SEL()
371- 
372-#define CONV2D_NO_FULLLOAD_BL0_OPEN_SEL() \
373- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2), CONV_COMMON_NO_FULLLOAD_BL0_OPEN_SEL(), \
374- CONV2D_COMMON_C04_TPL_UINT_SEL()
375- 
376-#define CONV2D_NO_FULLLOAD_ALL_OPEN_SEL() \
377- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2), CONV_COMMON_NO_FULLLOAD_ALL_OPEN_SEL(), \
378- CONV2D_COMMON_C04_TPL_UINT_SEL()
379- 
380-#define CONV2D_ONLY_AL1_FULLLOAD_SEL() \
381- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2), CONV_COMMON_ONLY_AL1_FULLLOAD_SEL(), \
382- CONV2D_COMMON_C04_TPL_UINT_SEL()
383- 
384-#define CONV2D_ONLY_BL1_FULLLOAD_SEL() \
385- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2), CONV_COMMON_ONLY_BL1_FULLLOAD_SEL(), \
386- CONV2D_COMMON_C04_TPL_UINT_SEL()
387- 
388-#define CONV2D_ABL1_FULLLOAD_M_FIRST_SEL() \
389- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2), CONV_COMMON_ABL1_FULLLOAD_M_FIRST_SEL(), \
390- CONV2D_COMMON_C04_TPL_UINT_SEL()
391- 
392-#define CONV2D_ABL1_FULLLOAD_N_FIRST_SEL() \
393- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2), CONV_COMMON_ABL1_FULLLOAD_N_FIRST_SEL(), \
394- CONV2D_COMMON_C04_TPL_UINT_SEL()
395-#else
396#define CONV2D_ONLY_MN_FULLLOAD_SEL() \85#define CONV2D_ONLY_MN_FULLLOAD_SEL() \
397 ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_AIC_ONLY), CONV_COMMON_ONLY_MN_FULLLOAD_SEL(), \86 ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_AIC_ONLY), CONV_COMMON_ONLY_MN_FULLLOAD_SEL(), \
398 CONV2D_COMMON_C04_TPL_UINT_SEL()87 CONV2D_COMMON_C04_TPL_UINT_SEL()
@@ -424,7 +113,6 @@ ASCENDC_TPL_ARGS_DECL(
424#define CONV2D_ABL1_FULLLOAD_N_FIRST_SEL() \113#define CONV2D_ABL1_FULLLOAD_N_FIRST_SEL() \
425 ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_AIC_ONLY), CONV_COMMON_ABL1_FULLLOAD_N_FIRST_SEL(), \114 ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_AIC_ONLY), CONV_COMMON_ABL1_FULLLOAD_N_FIRST_SEL(), \
426 CONV2D_COMMON_C04_TPL_UINT_SEL()115 CONV2D_COMMON_C04_TPL_UINT_SEL()
427-#endif
428 116 
429#if (!defined(ASCENDC_TPL_PRE) && !defined(ASCENDC_TPL_KERNEL)) || \117#if (!defined(ASCENDC_TPL_PRE) && !defined(ASCENDC_TPL_KERNEL)) || \
430 (defined(ORIG_DTYPE_X) && \118 (defined(ORIG_DTYPE_X) && \
@@ -477,25 +165,17 @@ ASCENDC_TPL_ARGS_DECL(
477 ASCENDC_TPL_UINT_SEL(WeightUbTrans, ASCENDC_TPL_UI_LIST, CONV_WEIGHT_UB_TRANS_CLOSE), \165 ASCENDC_TPL_UINT_SEL(WeightUbTrans, ASCENDC_TPL_UI_LIST, CONV_WEIGHT_UB_TRANS_CLOSE), \
478 ASCENDC_TPL_UINT_SEL(FmapCopyMode, ASCENDC_TPL_UI_LIST, CONV_FMAP_LOAD3D_MODE), \166 ASCENDC_TPL_UINT_SEL(FmapCopyMode, ASCENDC_TPL_UI_LIST, CONV_FMAP_LOAD3D_MODE), \
479 ASCENDC_TPL_UINT_SEL(InnerBatch, ASCENDC_TPL_UI_LIST, CONV_INNER_BATCH_SINGLE), \167 ASCENDC_TPL_UINT_SEL(InnerBatch, ASCENDC_TPL_UI_LIST, CONV_INNER_BATCH_SINGLE), \
480- ASCENDC_TPL_UINT_SEL(DisContinuous, ASCENDC_TPL_UI_LIST, CONV_DIS_CONTINUOUS_CLOSE)168+ ASCENDC_TPL_UINT_SEL(DisContinuous, ASCENDC_TPL_UI_LIST, CONV_DIS_CONTINUOUS_CLOSE) \
169+ CONV2D_SCALAR_OPT_SEL(CONV_NOT_SMALL_WEIGHT)
481 170 
482-#if (defined(CV_UB_FUSION) || defined(CV_SAFETY_FUSION))
483-#define CONV2D_ORI_GROUP_SEL() \
484- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2), CONV_COMMON_ORI_GROUP_SEL(), \
485- ASCENDC_TPL_UINT_SEL(EnableSmallChannel, ASCENDC_TPL_UI_LIST, CONV_ENABLE_SMALL_CHANNEL_CLOSE), \
486- ASCENDC_TPL_UINT_SEL(WeightUbTrans, ASCENDC_TPL_UI_LIST, CONV_WEIGHT_UB_TRANS_CLOSE), \
487- ASCENDC_TPL_UINT_SEL(FmapCopyMode, ASCENDC_TPL_UI_LIST, CONV_FMAP_LOAD3D_MODE), \
488- ASCENDC_TPL_UINT_SEL(InnerBatch, ASCENDC_TPL_UI_LIST, CONV_INNER_BATCH_SINGLE), \
489- ASCENDC_TPL_UINT_SEL(DisContinuous, ASCENDC_TPL_UI_LIST, CONV_DIS_CONTINUOUS_CLOSE)
490-#else
491#define CONV2D_ORI_GROUP_SEL() \171#define CONV2D_ORI_GROUP_SEL() \
492 ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_AIC_ONLY), CONV_COMMON_ORI_GROUP_SEL(), \172 ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_AIC_ONLY), CONV_COMMON_ORI_GROUP_SEL(), \
493 ASCENDC_TPL_UINT_SEL(EnableSmallChannel, ASCENDC_TPL_UI_LIST, CONV_ENABLE_SMALL_CHANNEL_CLOSE), \173 ASCENDC_TPL_UINT_SEL(EnableSmallChannel, ASCENDC_TPL_UI_LIST, CONV_ENABLE_SMALL_CHANNEL_CLOSE), \
494 ASCENDC_TPL_UINT_SEL(WeightUbTrans, ASCENDC_TPL_UI_LIST, CONV_WEIGHT_UB_TRANS_CLOSE), \174 ASCENDC_TPL_UINT_SEL(WeightUbTrans, ASCENDC_TPL_UI_LIST, CONV_WEIGHT_UB_TRANS_CLOSE), \
495 ASCENDC_TPL_UINT_SEL(FmapCopyMode, ASCENDC_TPL_UI_LIST, CONV_FMAP_LOAD3D_MODE), \175 ASCENDC_TPL_UINT_SEL(FmapCopyMode, ASCENDC_TPL_UI_LIST, CONV_FMAP_LOAD3D_MODE), \
496 ASCENDC_TPL_UINT_SEL(InnerBatch, ASCENDC_TPL_UI_LIST, CONV_INNER_BATCH_SINGLE), \176 ASCENDC_TPL_UINT_SEL(InnerBatch, ASCENDC_TPL_UI_LIST, CONV_INNER_BATCH_SINGLE), \
497- ASCENDC_TPL_UINT_SEL(DisContinuous, ASCENDC_TPL_UI_LIST, CONV_DIS_CONTINUOUS_CLOSE)177+ ASCENDC_TPL_UINT_SEL(DisContinuous, ASCENDC_TPL_UI_LIST, CONV_DIS_CONTINUOUS_CLOSE) \
498-#endif178+ CONV2D_SCALAR_OPT_SEL(CONV_NOT_SMALL_WEIGHT)
499 179 
500#define CONV2D_OPT_GROUP_PRELOAD_SEL() \180#define CONV2D_OPT_GROUP_PRELOAD_SEL() \
501 ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2), \181 ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2), \
@@ -511,7 +191,8 @@ ASCENDC_TPL_ARGS_DECL(
511 ASCENDC_TPL_UINT_SEL(WeightUbTrans, ASCENDC_TPL_UI_LIST, CONV_WEIGHT_UB_TRANS_CLOSE), \191 ASCENDC_TPL_UINT_SEL(WeightUbTrans, ASCENDC_TPL_UI_LIST, CONV_WEIGHT_UB_TRANS_CLOSE), \
512 ASCENDC_TPL_UINT_SEL(FmapCopyMode, ASCENDC_TPL_UI_LIST, CONV_FMAP_LOAD3D_MODE), \192 ASCENDC_TPL_UINT_SEL(FmapCopyMode, ASCENDC_TPL_UI_LIST, CONV_FMAP_LOAD3D_MODE), \
513 ASCENDC_TPL_UINT_SEL(InnerBatch, ASCENDC_TPL_UI_LIST, CONV_INNER_BATCH_SINGLE), \193 ASCENDC_TPL_UINT_SEL(InnerBatch, ASCENDC_TPL_UI_LIST, CONV_INNER_BATCH_SINGLE), \
514- ASCENDC_TPL_UINT_SEL(DisContinuous, ASCENDC_TPL_UI_LIST, CONV_DIS_CONTINUOUS_CLOSE)194+ ASCENDC_TPL_UINT_SEL(DisContinuous, ASCENDC_TPL_UI_LIST, CONV_DIS_CONTINUOUS_CLOSE) \
195+ CONV2D_SCALAR_OPT_SEL(CONV_NOT_SMALL_WEIGHT, CONV_FULLLOAD_KL1_NL0, CONV_WEIGHT_SMALLER_THAN_BL0)
515 196 
516// Weight Ub Trans Mode TilingKey SEL197// Weight Ub Trans Mode TilingKey SEL
517#if (!defined(ASCENDC_TPL_PRE) && !defined(ASCENDC_TPL_KERNEL)) || \198#if (!defined(ASCENDC_TPL_PRE) && !defined(ASCENDC_TPL_KERNEL)) || \
@@ -535,7 +216,8 @@ ASCENDC_TPL_ARGS_DECL(
535 ASCENDC_TPL_UINT_SEL(L0PingPong, ASCENDC_TPL_UI_LIST, CONV_L0_PINGPONG_ALL_OPEN), \216 ASCENDC_TPL_UINT_SEL(L0PingPong, ASCENDC_TPL_UI_LIST, CONV_L0_PINGPONG_ALL_OPEN), \
536 ASCENDC_TPL_UINT_SEL(OutputOrder, ASCENDC_TPL_UI_LIST, CONV_OUTPUT_ORDER_M_MODE), \217 ASCENDC_TPL_UINT_SEL(OutputOrder, ASCENDC_TPL_UI_LIST, CONV_OUTPUT_ORDER_M_MODE), \
537 ASCENDC_TPL_UINT_SEL(IterOrder, ASCENDC_TPL_UI_LIST, CONV_ITER_ORDER_MITER_FIRST, CONV_ITER_ORDER_NITER_FIRST), \218 ASCENDC_TPL_UINT_SEL(IterOrder, ASCENDC_TPL_UI_LIST, CONV_ITER_ORDER_MITER_FIRST, CONV_ITER_ORDER_NITER_FIRST), \
538- CONV2D_COMMON_WEIGHT_UB_SEL()219+ CONV2D_COMMON_WEIGHT_UB_SEL() \
220+ CONV2D_SCALAR_OPT_SEL(CONV_NOT_SMALL_WEIGHT, CONV_FULLLOAD_KL1_NL0, CONV_WEIGHT_SMALLER_THAN_BL0)
539 221 
540#define CONV2D_WEIGHT_UB_ONLY_AL1_FULLLOAD_SEL() \222#define CONV2D_WEIGHT_UB_ONLY_AL1_FULLLOAD_SEL() \
541 ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2), \223 ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2), \
@@ -544,7 +226,8 @@ ASCENDC_TPL_ARGS_DECL(
544 ASCENDC_TPL_UINT_SEL(L1PingPong, ASCENDC_TPL_UI_LIST, CONV_L1_PINGPONG_BL1_OPEN), \226 ASCENDC_TPL_UINT_SEL(L1PingPong, ASCENDC_TPL_UI_LIST, CONV_L1_PINGPONG_BL1_OPEN), \
545 ASCENDC_TPL_UINT_SEL(L0PingPong, ASCENDC_TPL_UI_LIST, CONV_L0_PINGPONG_BL0_OPEN, CONV_L0_PINGPONG_ALL_OPEN), \227 ASCENDC_TPL_UINT_SEL(L0PingPong, ASCENDC_TPL_UI_LIST, CONV_L0_PINGPONG_BL0_OPEN, CONV_L0_PINGPONG_ALL_OPEN), \
546 ASCENDC_TPL_UINT_SEL(OutputOrder, ASCENDC_TPL_UI_LIST, CONV_OUTPUT_ORDER_HW_MODE, CONV_OUTPUT_ORDER_M_MODE), \228 ASCENDC_TPL_UINT_SEL(OutputOrder, ASCENDC_TPL_UI_LIST, CONV_OUTPUT_ORDER_HW_MODE, CONV_OUTPUT_ORDER_M_MODE), \
547- ASCENDC_TPL_UINT_SEL(IterOrder, ASCENDC_TPL_UI_LIST, CONV_ITER_ORDER_NITER_FIRST), CONV2D_COMMON_WEIGHT_UB_SEL()229+ ASCENDC_TPL_UINT_SEL(IterOrder, ASCENDC_TPL_UI_LIST, CONV_ITER_ORDER_NITER_FIRST), \
230+ CONV2D_COMMON_WEIGHT_UB_SEL() CONV2D_SCALAR_OPT_SEL(CONV_NOT_SMALL_WEIGHT)
548 231 
549#define CONV2D_WEIGHT_UB_NO_FULLLOAD_AL0_OPEN_SEL() \232#define CONV2D_WEIGHT_UB_NO_FULLLOAD_AL0_OPEN_SEL() \
550 ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2), \233 ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2), \
@@ -553,7 +236,8 @@ ASCENDC_TPL_ARGS_DECL(
553 ASCENDC_TPL_UINT_SEL(L1PingPong, ASCENDC_TPL_UI_LIST, CONV_L1_PINGPONG_BL1_OPEN, CONV_L1_PINGPONG_ALL_OPEN), \236 ASCENDC_TPL_UINT_SEL(L1PingPong, ASCENDC_TPL_UI_LIST, CONV_L1_PINGPONG_BL1_OPEN, CONV_L1_PINGPONG_ALL_OPEN), \
554 ASCENDC_TPL_UINT_SEL(L0PingPong, ASCENDC_TPL_UI_LIST, CONV_L0_PINGPONG_AL0_OPEN), \237 ASCENDC_TPL_UINT_SEL(L0PingPong, ASCENDC_TPL_UI_LIST, CONV_L0_PINGPONG_AL0_OPEN), \
555 ASCENDC_TPL_UINT_SEL(OutputOrder, ASCENDC_TPL_UI_LIST, CONV_OUTPUT_ORDER_HW_MODE, CONV_OUTPUT_ORDER_M_MODE), \238 ASCENDC_TPL_UINT_SEL(OutputOrder, ASCENDC_TPL_UI_LIST, CONV_OUTPUT_ORDER_HW_MODE, CONV_OUTPUT_ORDER_M_MODE), \
556- ASCENDC_TPL_UINT_SEL(IterOrder, ASCENDC_TPL_UI_LIST, CONV_ITER_ORDER_MITER_FIRST), CONV2D_COMMON_WEIGHT_UB_SEL()239+ ASCENDC_TPL_UINT_SEL(IterOrder, ASCENDC_TPL_UI_LIST, CONV_ITER_ORDER_MITER_FIRST), \
240+ CONV2D_COMMON_WEIGHT_UB_SEL() CONV2D_SCALAR_OPT_SEL(CONV_NOT_SMALL_WEIGHT)
557 241 
558#define CONV2D_WEIGHT_UB_NO_FULLLOAD_BL0_OPEN_SEL() \242#define CONV2D_WEIGHT_UB_NO_FULLLOAD_BL0_OPEN_SEL() \
559 ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2), \243 ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2), \
@@ -562,7 +246,8 @@ ASCENDC_TPL_ARGS_DECL(
562 ASCENDC_TPL_UINT_SEL(L1PingPong, ASCENDC_TPL_UI_LIST, CONV_L1_PINGPONG_BL1_OPEN, CONV_L1_PINGPONG_ALL_OPEN), \246 ASCENDC_TPL_UINT_SEL(L1PingPong, ASCENDC_TPL_UI_LIST, CONV_L1_PINGPONG_BL1_OPEN, CONV_L1_PINGPONG_ALL_OPEN), \
563 ASCENDC_TPL_UINT_SEL(L0PingPong, ASCENDC_TPL_UI_LIST, CONV_L0_PINGPONG_BL0_OPEN), \247 ASCENDC_TPL_UINT_SEL(L0PingPong, ASCENDC_TPL_UI_LIST, CONV_L0_PINGPONG_BL0_OPEN), \
564 ASCENDC_TPL_UINT_SEL(OutputOrder, ASCENDC_TPL_UI_LIST, CONV_OUTPUT_ORDER_HW_MODE, CONV_OUTPUT_ORDER_M_MODE), \248 ASCENDC_TPL_UINT_SEL(OutputOrder, ASCENDC_TPL_UI_LIST, CONV_OUTPUT_ORDER_HW_MODE, CONV_OUTPUT_ORDER_M_MODE), \
565- ASCENDC_TPL_UINT_SEL(IterOrder, ASCENDC_TPL_UI_LIST, CONV_ITER_ORDER_NITER_FIRST), CONV2D_COMMON_WEIGHT_UB_SEL()249+ ASCENDC_TPL_UINT_SEL(IterOrder, ASCENDC_TPL_UI_LIST, CONV_ITER_ORDER_NITER_FIRST), \
250+ CONV2D_COMMON_WEIGHT_UB_SEL() CONV2D_SCALAR_OPT_SEL(CONV_NOT_SMALL_WEIGHT)
566 251 
567#define CONV2D_WEIGHT_UB_NO_FULLLOAD_ALL_OPEN_SEL() \252#define CONV2D_WEIGHT_UB_NO_FULLLOAD_ALL_OPEN_SEL() \
568 ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2), \253 ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2), \
@@ -572,7 +257,7 @@ ASCENDC_TPL_ARGS_DECL(
572 ASCENDC_TPL_UINT_SEL(L0PingPong, ASCENDC_TPL_UI_LIST, CONV_L0_PINGPONG_ALL_OPEN), \257 ASCENDC_TPL_UINT_SEL(L0PingPong, ASCENDC_TPL_UI_LIST, CONV_L0_PINGPONG_ALL_OPEN), \
573 ASCENDC_TPL_UINT_SEL(OutputOrder, ASCENDC_TPL_UI_LIST, CONV_OUTPUT_ORDER_HW_MODE, CONV_OUTPUT_ORDER_M_MODE), \258 ASCENDC_TPL_UINT_SEL(OutputOrder, ASCENDC_TPL_UI_LIST, CONV_OUTPUT_ORDER_HW_MODE, CONV_OUTPUT_ORDER_M_MODE), \
574 ASCENDC_TPL_UINT_SEL(IterOrder, ASCENDC_TPL_UI_LIST, CONV_ITER_ORDER_MITER_FIRST, CONV_ITER_ORDER_NITER_FIRST), \259 ASCENDC_TPL_UINT_SEL(IterOrder, ASCENDC_TPL_UI_LIST, CONV_ITER_ORDER_MITER_FIRST, CONV_ITER_ORDER_NITER_FIRST), \
575- CONV2D_COMMON_WEIGHT_UB_SEL()260+ CONV2D_COMMON_WEIGHT_UB_SEL() CONV2D_SCALAR_OPT_SEL(CONV_NOT_SMALL_WEIGHT)
576 261 
577#else262#else
578#define CONV2D_WEIGHT_UB_ONLY_MN_FULLLOAD_SEL()263#define CONV2D_WEIGHT_UB_ONLY_MN_FULLLOAD_SEL()
@@ -597,7 +282,9 @@ ASCENDC_TPL_ARGS_DECL(
597 ASCENDC_TPL_UINT_SEL(L1PingPong, ASCENDC_TPL_UI_LIST, CONV_L1_PINGPONG_ALL_CLOSE), \282 ASCENDC_TPL_UINT_SEL(L1PingPong, ASCENDC_TPL_UI_LIST, CONV_L1_PINGPONG_ALL_CLOSE), \
598 ASCENDC_TPL_UINT_SEL(L0PingPong, ASCENDC_TPL_UI_LIST, CONV_L0_PINGPONG_ALL_CLOSE, CONV_L0_PINGPONG_AL0_OPEN), \283 ASCENDC_TPL_UINT_SEL(L0PingPong, ASCENDC_TPL_UI_LIST, CONV_L0_PINGPONG_ALL_CLOSE, CONV_L0_PINGPONG_AL0_OPEN), \
599 ASCENDC_TPL_UINT_SEL(OutputOrder, ASCENDC_TPL_UI_LIST, CONV_OUTPUT_ORDER_HW_MODE), \284 ASCENDC_TPL_UINT_SEL(OutputOrder, ASCENDC_TPL_UI_LIST, CONV_OUTPUT_ORDER_HW_MODE), \
600- ASCENDC_TPL_UINT_SEL(IterOrder, ASCENDC_TPL_UI_LIST, CONV_ITER_ORDER_MITER_FIRST), CONV2D_COMMON_DMA_SEL()285+ ASCENDC_TPL_UINT_SEL(IterOrder, ASCENDC_TPL_UI_LIST, CONV_ITER_ORDER_MITER_FIRST), \
286+ CONV2D_COMMON_DMA_SEL() \
287+ CONV2D_SCALAR_OPT_SEL(CONV_NOT_SMALL_WEIGHT, CONV_FULLLOAD_KL1_NL0, CONV_WEIGHT_SMALLER_THAN_BL0)
601 288 
602#define CONV2D_DMA_L1_FULLLOAD_ONLY_L0B_OPEN_SEL() \289#define CONV2D_DMA_L1_FULLLOAD_ONLY_L0B_OPEN_SEL() \
603 ASCENDC_TPL_UINT_SEL(FmapTiling, ASCENDC_TPL_UI_LIST, CONV_FMAP_TILING_FULLLOAD_AL1), \290 ASCENDC_TPL_UINT_SEL(FmapTiling, ASCENDC_TPL_UI_LIST, CONV_FMAP_TILING_FULLLOAD_AL1), \
@@ -605,7 +292,9 @@ ASCENDC_TPL_ARGS_DECL(
605 ASCENDC_TPL_UINT_SEL(L1PingPong, ASCENDC_TPL_UI_LIST, CONV_L1_PINGPONG_ALL_CLOSE), \292 ASCENDC_TPL_UINT_SEL(L1PingPong, ASCENDC_TPL_UI_LIST, CONV_L1_PINGPONG_ALL_CLOSE), \
606 ASCENDC_TPL_UINT_SEL(L0PingPong, ASCENDC_TPL_UI_LIST, CONV_L0_PINGPONG_BL0_OPEN), \293 ASCENDC_TPL_UINT_SEL(L0PingPong, ASCENDC_TPL_UI_LIST, CONV_L0_PINGPONG_BL0_OPEN), \
607 ASCENDC_TPL_UINT_SEL(OutputOrder, ASCENDC_TPL_UI_LIST, CONV_OUTPUT_ORDER_HW_MODE), \294 ASCENDC_TPL_UINT_SEL(OutputOrder, ASCENDC_TPL_UI_LIST, CONV_OUTPUT_ORDER_HW_MODE), \
608- ASCENDC_TPL_UINT_SEL(IterOrder, ASCENDC_TPL_UI_LIST, CONV_ITER_ORDER_NITER_FIRST), CONV2D_COMMON_DMA_SEL()295+ ASCENDC_TPL_UINT_SEL(IterOrder, ASCENDC_TPL_UI_LIST, CONV_ITER_ORDER_NITER_FIRST), \
296+ CONV2D_COMMON_DMA_SEL() \
297+ CONV2D_SCALAR_OPT_SEL(CONV_NOT_SMALL_WEIGHT, CONV_FULLLOAD_KL1_NL0, CONV_WEIGHT_SMALLER_THAN_BL0)
609 298 
610#define CONV2D_DMA_L1_FULLLOAD_ALL_OPEN_SEL() \299#define CONV2D_DMA_L1_FULLLOAD_ALL_OPEN_SEL() \
611 ASCENDC_TPL_UINT_SEL(FmapTiling, ASCENDC_TPL_UI_LIST, CONV_FMAP_TILING_FULLLOAD_AL1), \300 ASCENDC_TPL_UINT_SEL(FmapTiling, ASCENDC_TPL_UI_LIST, CONV_FMAP_TILING_FULLLOAD_AL1), \
@@ -614,7 +303,8 @@ ASCENDC_TPL_ARGS_DECL(
614 ASCENDC_TPL_UINT_SEL(L0PingPong, ASCENDC_TPL_UI_LIST, CONV_L0_PINGPONG_ALL_OPEN), \303 ASCENDC_TPL_UINT_SEL(L0PingPong, ASCENDC_TPL_UI_LIST, CONV_L0_PINGPONG_ALL_OPEN), \
615 ASCENDC_TPL_UINT_SEL(OutputOrder, ASCENDC_TPL_UI_LIST, CONV_OUTPUT_ORDER_HW_MODE), \304 ASCENDC_TPL_UINT_SEL(OutputOrder, ASCENDC_TPL_UI_LIST, CONV_OUTPUT_ORDER_HW_MODE), \
616 ASCENDC_TPL_UINT_SEL(IterOrder, ASCENDC_TPL_UI_LIST, CONV_ITER_ORDER_MITER_FIRST, CONV_ITER_ORDER_NITER_FIRST), \305 ASCENDC_TPL_UINT_SEL(IterOrder, ASCENDC_TPL_UI_LIST, CONV_ITER_ORDER_MITER_FIRST, CONV_ITER_ORDER_NITER_FIRST), \
617- CONV2D_COMMON_DMA_SEL()306+ CONV2D_COMMON_DMA_SEL() \
307+ CONV2D_SCALAR_OPT_SEL(CONV_NOT_SMALL_WEIGHT, CONV_FULLLOAD_KL1_NL0, CONV_WEIGHT_SMALLER_THAN_BL0)
618 308 
619#define CONV2D_DMA_AL1_NO_FULLLOAD_M_FIRST_SEL() \309#define CONV2D_DMA_AL1_NO_FULLLOAD_M_FIRST_SEL() \
620 ASCENDC_TPL_UINT_SEL(FmapTiling, ASCENDC_TPL_UI_LIST, CONV_FMAP_TILING_OTHER), \310 ASCENDC_TPL_UINT_SEL(FmapTiling, ASCENDC_TPL_UI_LIST, CONV_FMAP_TILING_OTHER), \
@@ -623,7 +313,9 @@ ASCENDC_TPL_ARGS_DECL(
623 ASCENDC_TPL_UINT_SEL(L1PingPong, ASCENDC_TPL_UI_LIST, CONV_L1_PINGPONG_ALL_CLOSE), \313 ASCENDC_TPL_UINT_SEL(L1PingPong, ASCENDC_TPL_UI_LIST, CONV_L1_PINGPONG_ALL_CLOSE), \
624 ASCENDC_TPL_UINT_SEL(L0PingPong, ASCENDC_TPL_UI_LIST, CONV_L0_PINGPONG_AL0_OPEN, CONV_L0_PINGPONG_ALL_OPEN), \314 ASCENDC_TPL_UINT_SEL(L0PingPong, ASCENDC_TPL_UI_LIST, CONV_L0_PINGPONG_AL0_OPEN, CONV_L0_PINGPONG_ALL_OPEN), \
625 ASCENDC_TPL_UINT_SEL(OutputOrder, ASCENDC_TPL_UI_LIST, CONV_OUTPUT_ORDER_HW_MODE), \315 ASCENDC_TPL_UINT_SEL(OutputOrder, ASCENDC_TPL_UI_LIST, CONV_OUTPUT_ORDER_HW_MODE), \
626- ASCENDC_TPL_UINT_SEL(IterOrder, ASCENDC_TPL_UI_LIST, CONV_ITER_ORDER_MITER_FIRST), CONV2D_COMMON_DMA_SEL()316+ ASCENDC_TPL_UINT_SEL(IterOrder, ASCENDC_TPL_UI_LIST, CONV_ITER_ORDER_MITER_FIRST), \
317+ CONV2D_COMMON_DMA_SEL() \
318+ CONV2D_SCALAR_OPT_SEL(CONV_NOT_SMALL_WEIGHT, CONV_FULLLOAD_KL1_NL0, CONV_WEIGHT_SMALLER_THAN_BL0)
627 319 
628#define CONV2D_DMA_BL1_NO_FULLLOAD_N_FIRST_SEL() \320#define CONV2D_DMA_BL1_NO_FULLLOAD_N_FIRST_SEL() \
629 ASCENDC_TPL_UINT_SEL(FmapTiling, ASCENDC_TPL_UI_LIST, CONV_FMAP_TILING_FULLLOAD_AL1, CONV_FMAP_TILING_OTHER), \321 ASCENDC_TPL_UINT_SEL(FmapTiling, ASCENDC_TPL_UI_LIST, CONV_FMAP_TILING_FULLLOAD_AL1, CONV_FMAP_TILING_OTHER), \
@@ -631,24 +323,10 @@ ASCENDC_TPL_ARGS_DECL(
631 ASCENDC_TPL_UINT_SEL(L1PingPong, ASCENDC_TPL_UI_LIST, CONV_L1_PINGPONG_ALL_CLOSE), \323 ASCENDC_TPL_UINT_SEL(L1PingPong, ASCENDC_TPL_UI_LIST, CONV_L1_PINGPONG_ALL_CLOSE), \
632 ASCENDC_TPL_UINT_SEL(L0PingPong, ASCENDC_TPL_UI_LIST, CONV_L0_PINGPONG_BL0_OPEN, CONV_L0_PINGPONG_ALL_OPEN), \324 ASCENDC_TPL_UINT_SEL(L0PingPong, ASCENDC_TPL_UI_LIST, CONV_L0_PINGPONG_BL0_OPEN, CONV_L0_PINGPONG_ALL_OPEN), \
633 ASCENDC_TPL_UINT_SEL(OutputOrder, ASCENDC_TPL_UI_LIST, CONV_OUTPUT_ORDER_HW_MODE), \325 ASCENDC_TPL_UINT_SEL(OutputOrder, ASCENDC_TPL_UI_LIST, CONV_OUTPUT_ORDER_HW_MODE), \
634- ASCENDC_TPL_UINT_SEL(IterOrder, ASCENDC_TPL_UI_LIST, CONV_ITER_ORDER_NITER_FIRST), CONV2D_COMMON_DMA_SEL()326+ ASCENDC_TPL_UINT_SEL(IterOrder, ASCENDC_TPL_UI_LIST, CONV_ITER_ORDER_NITER_FIRST), \
327+ CONV2D_COMMON_DMA_SEL() \
328+ CONV2D_SCALAR_OPT_SEL(CONV_NOT_SMALL_WEIGHT, CONV_FULLLOAD_KL1_NL0, CONV_WEIGHT_SMALLER_THAN_BL0)
635 329 
636-#if (defined(CV_UB_FUSION) || defined(CV_SAFETY_FUSION))
637-#define CONV2D_ABL1_FULLLOAD_DB_OPEN_SEL() \
638- ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2), \
639- ASCENDC_TPL_UINT_SEL(FmapTiling, ASCENDC_TPL_UI_LIST, CONV_FMAP_TILING_FULLLOAD_AL1), \
640- ASCENDC_TPL_UINT_SEL(WeightTiling, ASCENDC_TPL_UI_LIST, CONV_WEIGHT_TILING_FULLLOAD_BL1), \
641- ASCENDC_TPL_UINT_SEL(L1PingPong, ASCENDC_TPL_UI_LIST, CONV_L1_PINGPONG_AL1_OPEN), \
642- ASCENDC_TPL_UINT_SEL(L0PingPong, ASCENDC_TPL_UI_LIST, CONV_L0_PINGPONG_AL0_OPEN), \
643- ASCENDC_TPL_UINT_SEL(OutputOrder, ASCENDC_TPL_UI_LIST, CONV_OUTPUT_ORDER_M_MODE), \
644- ASCENDC_TPL_UINT_SEL(IterOrder, ASCENDC_TPL_UI_LIST, CONV_ITER_ORDER_MITER_FIRST), \
645- ASCENDC_TPL_UINT_SEL(GroupType, ASCENDC_TPL_UI_LIST, CONV_GROUP_TYPE_NORMAL_CONV), \
646- ASCENDC_TPL_UINT_SEL(EnableSmallChannel, ASCENDC_TPL_UI_LIST, CONV_ENABLE_SMALL_CHANNEL_CLOSE), \
647- ASCENDC_TPL_UINT_SEL(WeightUbTrans, ASCENDC_TPL_UI_LIST, CONV_WEIGHT_UB_TRANS_CLOSE), \
648- ASCENDC_TPL_UINT_SEL(FmapCopyMode, ASCENDC_TPL_UI_LIST, CONV_FMAP_LOAD3D_MODE), \
649- ASCENDC_TPL_UINT_SEL(InnerBatch, ASCENDC_TPL_UI_LIST, CONV_INNER_BATCH_SINGLE), \
650- ASCENDC_TPL_UINT_SEL(DisContinuous, ASCENDC_TPL_UI_LIST, CONV_DIS_CONTINUOUS_CLOSE)
651-#else
652#define CONV2D_ABL1_FULLLOAD_DB_OPEN_SEL() \330#define CONV2D_ABL1_FULLLOAD_DB_OPEN_SEL() \
653 ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_AIC_ONLY), \331 ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_AIC_ONLY), \
654 ASCENDC_TPL_UINT_SEL(FmapTiling, ASCENDC_TPL_UI_LIST, CONV_FMAP_TILING_FULLLOAD_AL1), \332 ASCENDC_TPL_UINT_SEL(FmapTiling, ASCENDC_TPL_UI_LIST, CONV_FMAP_TILING_FULLLOAD_AL1), \
@@ -662,8 +340,8 @@ ASCENDC_TPL_ARGS_DECL(
662 ASCENDC_TPL_UINT_SEL(WeightUbTrans, ASCENDC_TPL_UI_LIST, CONV_WEIGHT_UB_TRANS_CLOSE), \340 ASCENDC_TPL_UINT_SEL(WeightUbTrans, ASCENDC_TPL_UI_LIST, CONV_WEIGHT_UB_TRANS_CLOSE), \
663 ASCENDC_TPL_UINT_SEL(FmapCopyMode, ASCENDC_TPL_UI_LIST, CONV_FMAP_LOAD3D_MODE), \341 ASCENDC_TPL_UINT_SEL(FmapCopyMode, ASCENDC_TPL_UI_LIST, CONV_FMAP_LOAD3D_MODE), \
664 ASCENDC_TPL_UINT_SEL(InnerBatch, ASCENDC_TPL_UI_LIST, CONV_INNER_BATCH_SINGLE), \342 ASCENDC_TPL_UINT_SEL(InnerBatch, ASCENDC_TPL_UI_LIST, CONV_INNER_BATCH_SINGLE), \
665- ASCENDC_TPL_UINT_SEL(DisContinuous, ASCENDC_TPL_UI_LIST, CONV_DIS_CONTINUOUS_CLOSE)343+ ASCENDC_TPL_UINT_SEL(DisContinuous, ASCENDC_TPL_UI_LIST, CONV_DIS_CONTINUOUS_CLOSE) \
666-#endif344+ CONV2D_SCALAR_OPT_SEL(CONV_NOT_SMALL_WEIGHT, CONV_FULLLOAD_KL1_NL0, CONV_WEIGHT_SMALLER_THAN_BL0)
667 345 
668ASCENDC_TPL_SEL(346ASCENDC_TPL_SEL(
669 ASCENDC_TPL_ARGS_SEL(CONV2D_ONLY_MN_FULLLOAD_SEL()), ASCENDC_TPL_ARGS_SEL(CONV2D_NO_FULLLOAD_AL0_OPEN_SEL()),347 ASCENDC_TPL_ARGS_SEL(CONV2D_ONLY_MN_FULLLOAD_SEL()), ASCENDC_TPL_ARGS_SEL(CONV2D_NO_FULLLOAD_AL0_OPEN_SEL()),
@@ -698,23 +376,6 @@ ASCENDC_TPL_SEL(
698 ASCENDC_TPL_ARGS_SEL(CONV2D_INNER_BATCH_WEIGHT_UB_NO_FULLLOAD_AL0_OPEN_SEL()),376 ASCENDC_TPL_ARGS_SEL(CONV2D_INNER_BATCH_WEIGHT_UB_NO_FULLLOAD_AL0_OPEN_SEL()),
699 ASCENDC_TPL_ARGS_SEL(CONV2D_INNER_BATCH_WEIGHT_UB_NO_FULLLOAD_BL0_OPEN_SEL()),377 ASCENDC_TPL_ARGS_SEL(CONV2D_INNER_BATCH_WEIGHT_UB_NO_FULLLOAD_BL0_OPEN_SEL()),
700 ASCENDC_TPL_ARGS_SEL(CONV2D_INNER_BATCH_WEIGHT_UB_NO_FULLLOAD_ALL_OPEN_SEL()),378 ASCENDC_TPL_ARGS_SEL(CONV2D_INNER_BATCH_WEIGHT_UB_NO_FULLLOAD_ALL_OPEN_SEL()),
701-#if (defined(CV_UB_FUSION) || defined(CV_SAFETY_FUSION))
702- ASCENDC_TPL_ARGS_SEL(ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2), CONV_INNER_BATCH_ONLY_MN_FULLLOAD_SEL()),
703- ASCENDC_TPL_ARGS_SEL(ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2),
704- CONV_INNER_BATCH_NO_FULLLOAD_AL0_OPEN_SEL()),
705- ASCENDC_TPL_ARGS_SEL(ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2),
706- CONV_INNER_BATCH_NO_FULLLOAD_BL0_OPEN_SEL()),
707- ASCENDC_TPL_ARGS_SEL(ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2),
708- CONV_INNER_BATCH_NO_FULLLOAD_ALL_OPEN_SEL()),
709- ASCENDC_TPL_ARGS_SEL(ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2),
710- CONV_INNER_BATCH_ONLY_AL1_FULLLOAD_SEL()),
711- ASCENDC_TPL_ARGS_SEL(ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2),
712- CONV_INNER_BATCH_ONLY_BL1_FULLLOAD_SEL()),
713- ASCENDC_TPL_ARGS_SEL(ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2),
714- CONV_INNER_BATCH_ABL1_FULLLOAD_M_FIRST_SEL()),
715- ASCENDC_TPL_ARGS_SEL(ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_MIX_AIC_1_2),
716- CONV_INNER_BATCH_ABL1_FULLLOAD_N_FIRST_SEL()),
717-#else
718 ASCENDC_TPL_ARGS_SEL(ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_AIC_ONLY), CONV_INNER_BATCH_ONLY_MN_FULLLOAD_SEL()),379 ASCENDC_TPL_ARGS_SEL(ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_AIC_ONLY), CONV_INNER_BATCH_ONLY_MN_FULLLOAD_SEL()),
719 ASCENDC_TPL_ARGS_SEL(ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_AIC_ONLY),380 ASCENDC_TPL_ARGS_SEL(ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_AIC_ONLY),
720 CONV_INNER_BATCH_NO_FULLLOAD_AL0_OPEN_SEL()),381 CONV_INNER_BATCH_NO_FULLLOAD_AL0_OPEN_SEL()),
@@ -728,8 +389,6 @@ ASCENDC_TPL_SEL(
728 CONV_INNER_BATCH_ABL1_FULLLOAD_M_FIRST_SEL()),389 CONV_INNER_BATCH_ABL1_FULLLOAD_M_FIRST_SEL()),
729 ASCENDC_TPL_ARGS_SEL(ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_AIC_ONLY),390 ASCENDC_TPL_ARGS_SEL(ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_AIC_ONLY),
730 CONV_INNER_BATCH_ABL1_FULLLOAD_N_FIRST_SEL()),391 CONV_INNER_BATCH_ABL1_FULLLOAD_N_FIRST_SEL()),
731- 
732-#endif
733 ASCENDC_TPL_ARGS_SEL(CONV2D_INPUT_HWNC_ONLY_MN_FULLLOAD_SEL()),392 ASCENDC_TPL_ARGS_SEL(CONV2D_INPUT_HWNC_ONLY_MN_FULLLOAD_SEL()),
734 ASCENDC_TPL_ARGS_SEL(CONV2D_INPUT_HWNC_NO_FULLLOAD_AL0_OPEN_SEL()),393 ASCENDC_TPL_ARGS_SEL(CONV2D_INPUT_HWNC_NO_FULLLOAD_AL0_OPEN_SEL()),
735 ASCENDC_TPL_ARGS_SEL(CONV2D_INPUT_HWNC_NO_FULLLOAD_BL0_OPEN_SEL()),394 ASCENDC_TPL_ARGS_SEL(CONV2D_INPUT_HWNC_NO_FULLLOAD_BL0_OPEN_SEL()),
@@ -26,66 +26,54 @@ namespace Conv2DV2Advanced {
26using namespace Atcos;26using namespace Atcos;
27using namespace Atcos::Conv;27using namespace Atcos::Conv;
28 28 
29-template <class A_TYPE, class B_TYPE, class C_TYPE, class BIAS_TYPE, class A_LAYOUT, class B_LAYOUT, class C_LAYOUT,29+template <const Conv2DTilingData &TilingData, class A_TYPE, class B_TYPE, class C_TYPE, class BIAS_TYPE,
30- class BIAS_LAYOUT, uint64_t FULL_LOAD_MODE = 0>30+ class SCALE_TYPE, class A_LAYOUT, class B_LAYOUT, class C_LAYOUT, class BIAS_LAYOUT, class CONV_CONFIG>
31-__aicore__ inline void ConvActKernel(GM_ADDR aGM, GM_ADDR bGM, GM_ADDR biasGM, GM_ADDR offsetWGM,31+__aicore__ inline void ConvActKernel(GM_ADDR aGM, GM_ADDR bGM, GM_ADDR biasGM, GM_ADDR offsetWGM, GM_ADDR scaleGM,
32#ifdef CV_UB_FUSION32#ifdef CV_UB_FUSION
33- GM_ADDR cGM, GM_ADDR workspaceGM, const Conv2DTilingData &tilingData,33+ GM_ADDR cGM, GM_ADDR workspaceGM, AutoFusionVector::Params *param
34- AutoFusionVector::Params *param
35#else34#else
36- GM_ADDR cGM, GM_ADDR workspaceGM, const Conv2DTilingData &tilingData35+ GM_ADDR cGM, GM_ADDR workspaceGM
37#endif36#endif
38) {37) {
39 using AType = A_TYPE;38 using AType = A_TYPE;
40 using BType = B_TYPE;39 using BType = B_TYPE;
41 using CType = C_TYPE;40 using CType = C_TYPE;
42 using BiasType = BIAS_TYPE;41 using BiasType = BIAS_TYPE;
43- 42+ using ScaleType = SCALE_TYPE;
44 using LayoutA = A_LAYOUT;43 using LayoutA = A_LAYOUT;
45 using LayoutB = B_LAYOUT;44 using LayoutB = B_LAYOUT;
46 using LayoutC = C_LAYOUT;45 using LayoutC = C_LAYOUT;
47 using LayoutBias = BIAS_LAYOUT;46 using LayoutBias = BIAS_LAYOUT;
48 47 
49- using BlockScheduler = Block::IterateMFirst;
50- 
51- using OutputOrder = order::OutputMMode;
52 using BlockPrologue = Block::BlockPrologueEmpty;48 using BlockPrologue = Block::BlockPrologueEmpty;
53 49 
54- using BlockConvPolicy = Atcos::Conv::Img2ColConvMModePolicy;50+ using BlockConv = Block::BlockConv<TilingData, CONV_CONFIG, AType, BType, CType, BiasType, ScaleType, LayoutA,
55- using BlockConv = Block::BlockConv<ConvShape, BlockConvPolicy, AType, BType, CType, BiasType, LayoutA, LayoutB,51+ LayoutB, LayoutC, LayoutBias>;
56- LayoutC, LayoutBias>;
57- 
58- ConvShape shape;
59- TilingData2ConvShape(tilingData, shape);
60- ConvDim dimArgs;
61- TilingData2ConvDim(tilingData, dimArgs);
62 52 
63#ifdef CV_UB_FUSION53#ifdef CV_UB_FUSION
64 using FusionOp = AutoFusionVector;54 using FusionOp = AutoFusionVector;
65 55 
66- using BlockEpilogue = Block::BlockEpilogueCV<ConvShape, CType, CType, FusionOp>;56+ using BlockEpilogue = Block::BlockEpilogueCV<TilingData, CType, CType, FusionOp>;
67 57 
68- using ConvKernel =58+ using ConvKernel = Kernel::KernelConv<TilingData, CONV_CONFIG, BlockConv, BlockPrologue, BlockEpilogue>;
69- Kernel::KernelConv<ConvShape, BlockConv, BlockPrologue, BlockEpilogue, BlockScheduler, OutputOrder>;
70 59 
71- typename ConvKernel::BlockConvArguments convArgs = {aGM, bGM, cGM, biasGM};60+ typename ConvKernel::BlockConvArguments convArgs = {aGM, bGM, cGM, biasGM, scaleGM};
72 61 
73 typename BlockEpilogue::Params epilogueParams;62 typename BlockEpilogue::Params epilogueParams;
74 epilogueParams.fusionParams = *param;63 epilogueParams.fusionParams = *param;
75 64 
76- typename ConvKernel::Params params = {shape, dimArgs, convArgs, {}, epilogueParams};65+ typename ConvKernel::Params params = {{}, {}, convArgs, {}, epilogueParams};
77 66 
78 ConvKernel conv;67 ConvKernel conv;
79 conv(params);68 conv(params);
80#else69#else
81 using BlockEpilogue = Block::BlockEpilogueEmpty;70 using BlockEpilogue = Block::BlockEpilogueEmpty;
82 71 
83- using ConvKernel =72+ using ConvKernel = Kernel::KernelConv<TilingData, CONV_CONFIG, BlockConv, BlockPrologue, BlockEpilogue>;
84- Kernel::KernelConv<ConvShape, BlockConv, BlockPrologue, BlockEpilogue, BlockScheduler, OutputOrder>;
85 73 
86- typename ConvKernel::BlockConvArguments convArgs = {aGM, bGM, cGM, biasGM};74+ typename ConvKernel::BlockConvArguments convArgs = {aGM, bGM, cGM, biasGM, scaleGM};
87 75 
88- typename ConvKernel::Params parmas = {shape, dimArgs, convArgs, {}, {}};76+ typename ConvKernel::Params parmas = {{}, {}, convArgs, {}, {}};
89 77 
90 ConvKernel conv;78 ConvKernel conv;
91 conv(parmas);79 conv(parmas);
@@ -1200,16 +1200,15 @@ REG_ASC_IR(Conv2D)
1200 .Attr<std::vector<int64_t>>("pads")1200 .Attr<std::vector<int64_t>>("pads")
1201 .Attr<std::vector<int64_t>>("dilations")1201 .Attr<std::vector<int64_t>>("dilations")
1202 .Attr<int64_t>("groups")1202 .Attr<int64_t>("groups")
1203- .Attr<int64_t>("has_relu")
1204 .Attr<std::string>("pad_mode")1203 .Attr<std::string>("pad_mode")
1205 .Attr<std::string>("data_format")1204 .Attr<std::string>("data_format")
1206 .Attr<int64_t>("offset_x")1205 .Attr<int64_t>("offset_x")
1207 .Attr<bool>("enable_hf32")1206 .Attr<bool>("enable_hf32")
1207+ .Attr<int64_t>("fixed_shift_value")
1208 .ComputeType(ComputeType::kComputeCube)1208 .ComputeType(ComputeType::kComputeCube)
1209 .Impl(v2_soc_versions, {af::ascir::AscIrImplCreator<Conv2DAscIrAttImplV2>(),1209 .Impl(v2_soc_versions, {af::ascir::AscIrImplCreator<Conv2DAscIrAttImplV2>(),
1210 af::ascir::AscIrImplCreator<af::ascir::Conv2DAscIrCodegenImplV2>(),1210 af::ascir::AscIrImplCreator<af::ascir::Conv2DAscIrCodegenImplV2>(),
1211- {{"T1", TensorType{DT_FLOAT16, DT_FLOAT, DT_BF16, DT_HIFLOAT8}},1211+ {{"T1", TensorType{DT_FLOAT16}}, {"T2", TensorType{DT_FLOAT16}}}});
1212- {"T2", TensorType{DT_FLOAT16, DT_FLOAT, DT_BF16, DT_HIFLOAT8}}}});
1213 1212 
1214REG_ASC_IR(Conv2DBias)1213REG_ASC_IR(Conv2DBias)
1215 .Input("x", "T1")1214 .Input("x", "T1")
@@ -1220,16 +1219,15 @@ REG_ASC_IR(Conv2DBias)
1220 .Attr<std::vector<int64_t>>("pads")1219 .Attr<std::vector<int64_t>>("pads")
1221 .Attr<std::vector<int64_t>>("dilations")1220 .Attr<std::vector<int64_t>>("dilations")
1222 .Attr<int64_t>("groups")1221 .Attr<int64_t>("groups")
1223- .Attr<int64_t>("has_relu")
1224 .Attr<std::string>("pad_mode")1222 .Attr<std::string>("pad_mode")
1225 .Attr<std::string>("data_format")1223 .Attr<std::string>("data_format")
1226 .Attr<int64_t>("offset_x")1224 .Attr<int64_t>("offset_x")
1227 .Attr<bool>("enable_hf32")1225 .Attr<bool>("enable_hf32")
1226+ .Attr<int64_t>("fixed_shift_value")
1228 .ComputeType(ComputeType::kComputeCube)1227 .ComputeType(ComputeType::kComputeCube)
1229 .Impl(v2_soc_versions, {af::ascir::AscIrImplCreator<Conv2DAscIrAttImplV2>(),1228 .Impl(v2_soc_versions, {af::ascir::AscIrImplCreator<Conv2DAscIrAttImplV2>(),
1230 af::ascir::AscIrImplCreator<af::ascir::Conv2DAscIrCodegenImplV2>(),1229 af::ascir::AscIrImplCreator<af::ascir::Conv2DAscIrCodegenImplV2>(),
1231- {{"T1", TensorType{DT_FLOAT16, DT_FLOAT, DT_BF16, DT_HIFLOAT8}},1230+ {{"T1", TensorType{DT_FLOAT16}}, {"T2", TensorType{DT_FLOAT16}}}});
1232- {"T2", TensorType{DT_FLOAT16, DT_FLOAT, DT_BF16, DT_HIFLOAT8}}}});
1233 1231 
1234REG_ASC_IR(Conv2DOffset)1232REG_ASC_IR(Conv2DOffset)
1235 .Input("x", "T1")1233 .Input("x", "T1")
@@ -1240,17 +1238,16 @@ REG_ASC_IR(Conv2DOffset)
1240 .Attr<std::vector<int64_t>>("pads")1238 .Attr<std::vector<int64_t>>("pads")
1241 .Attr<std::vector<int64_t>>("dilations")1239 .Attr<std::vector<int64_t>>("dilations")
1242 .Attr<int64_t>("groups")1240 .Attr<int64_t>("groups")
1243- .Attr<int64_t>("has_relu")
1244 .Attr<std::string>("pad_mode")1241 .Attr<std::string>("pad_mode")
1245 .Attr<std::string>("data_format")1242 .Attr<std::string>("data_format")
1246 .Attr<int64_t>("offset_x")1243 .Attr<int64_t>("offset_x")
1247 .Attr<bool>("enable_hf32")1244 .Attr<bool>("enable_hf32")
1245+ .Attr<int64_t>("fixed_shift_value")
1248 .ComputeType(ComputeType::kComputeCube)1246 .ComputeType(ComputeType::kComputeCube)
1249- .Impl(v2_soc_versions, {af::ascir::AscIrImplCreator<Conv2DAscIrAttImplV2>(),1247+ .Impl(v2_soc_versions,
1250- af::ascir::AscIrImplCreator<af::ascir::Conv2DAscIrCodegenImplV2>(),1248+ {af::ascir::AscIrImplCreator<Conv2DAscIrAttImplV2>(),
1251- {{"T1", TensorType{DT_FLOAT16, DT_FLOAT, DT_BF16, DT_HIFLOAT8}},1249+ af::ascir::AscIrImplCreator<af::ascir::Conv2DAscIrCodegenImplV2>(),
1252- {"T2", TensorType{DT_FLOAT16, DT_FLOAT, DT_BF16, DT_HIFLOAT8}},1250+ {{"T1", TensorType{DT_FLOAT16}}, {"T2", TensorType{DT_FLOAT16}}, {"T3", TensorType{DT_INT8}}}});
1253- {"T3", TensorType{DT_INT8}}}});
1254 1251 
1255REG_ASC_IR(Conv2DOffsetBias)1252REG_ASC_IR(Conv2DOffsetBias)
1256 .Input("x", "T1")1253 .Input("x", "T1")
@@ -1262,17 +1259,105 @@ REG_ASC_IR(Conv2DOffsetBias)
1262 .Attr<std::vector<int64_t>>("pads")1259 .Attr<std::vector<int64_t>>("pads")
1263 .Attr<std::vector<int64_t>>("dilations")1260 .Attr<std::vector<int64_t>>("dilations")
1264 .Attr<int64_t>("groups")1261 .Attr<int64_t>("groups")
1265- .Attr<int64_t>("has_relu")
1266 .Attr<std::string>("pad_mode")1262 .Attr<std::string>("pad_mode")
1267 .Attr<std::string>("data_format")1263 .Attr<std::string>("data_format")
1268 .Attr<int64_t>("offset_x")1264 .Attr<int64_t>("offset_x")
1269 .Attr<bool>("enable_hf32")1265 .Attr<bool>("enable_hf32")
1266+ .Attr<int64_t>("fixed_shift_value")
1267+ .ComputeType(ComputeType::kComputeCube)
1268+ .Impl(v2_soc_versions,
1269+ {af::ascir::AscIrImplCreator<Conv2DAscIrAttImplV2>(),
1270+ af::ascir::AscIrImplCreator<af::ascir::Conv2DAscIrCodegenImplV2>(),
1271+ {{"T1", TensorType{DT_FLOAT16}}, {"T2", TensorType{DT_FLOAT16}}, {"T3", TensorType{DT_INT8}}}});
1272+ 
1273+REG_ASC_IR(ExtendConv2D)
1274+ .Input("x", "T1")
1275+ .Input("filter", "T1")
1276+ .Output("y", "T2")
1277+ .Attr<std::vector<int64_t>>("strides")
1278+ .Attr<std::vector<int64_t>>("pads")
1279+ .Attr<std::vector<int64_t>>("dilations")
1280+ .Attr<int64_t>("groups")
1281+ .Attr<std::string>("pad_mode")
1282+ .Attr<std::string>("data_format")
1283+ .Attr<int64_t>("offset_x")
1284+ .Attr<std::string>("round_mode")
1285+ .Attr<bool>("enable_hf32")
1286+ .Attr<int64_t>("fixed_shift_value")
1287+ .Attr<bool>("enable_relu0")
1270 .ComputeType(ComputeType::kComputeCube)1288 .ComputeType(ComputeType::kComputeCube)
1271 .Impl(v2_soc_versions, {af::ascir::AscIrImplCreator<Conv2DAscIrAttImplV2>(),1289 .Impl(v2_soc_versions, {af::ascir::AscIrImplCreator<Conv2DAscIrAttImplV2>(),
1272 af::ascir::AscIrImplCreator<af::ascir::Conv2DAscIrCodegenImplV2>(),1290 af::ascir::AscIrImplCreator<af::ascir::Conv2DAscIrCodegenImplV2>(),
1273- {{"T1", TensorType{DT_FLOAT16, DT_FLOAT, DT_BF16, DT_HIFLOAT8}},1291+ {{"T1", TensorType{DT_FLOAT16}}, {"T2", TensorType{DT_FLOAT16}}}});
1274- {"T2", TensorType{DT_FLOAT16, DT_FLOAT, DT_BF16, DT_HIFLOAT8}},1292+ 
1275- {"T3", TensorType{DT_INT8}}}});1293+REG_ASC_IR(ExtendConv2DBias)
1294+ .Input("x", "T1")
1295+ .Input("filter", "T1")
1296+ .Input("bias", "T2")
1297+ .Output("y", "T3")
1298+ .Attr<std::vector<int64_t>>("strides")
1299+ .Attr<std::vector<int64_t>>("pads")
1300+ .Attr<std::vector<int64_t>>("dilations")
1301+ .Attr<int64_t>("groups")
1302+ .Attr<std::string>("pad_mode")
1303+ .Attr<std::string>("data_format")
1304+ .Attr<int64_t>("offset_x")
1305+ .Attr<std::string>("round_mode")
1306+ .Attr<bool>("enable_hf32")
1307+ .Attr<int64_t>("fixed_shift_value")
1308+ .Attr<bool>("enable_relu0")
1309+ .ComputeType(ComputeType::kComputeCube)
1310+ .Impl(v2_soc_versions,
1311+ {af::ascir::AscIrImplCreator<Conv2DAscIrAttImplV2>(),
1312+ af::ascir::AscIrImplCreator<af::ascir::Conv2DAscIrCodegenImplV2>(),
1313+ {{"T1", TensorType{DT_FLOAT16}}, {"T2", TensorType{DT_FLOAT16}}, {"T3", TensorType{DT_FLOAT16}}}});
1314+ 
1315+REG_ASC_IR(ExtendConv2DScale)
1316+ .Input("x", "T1")
1317+ .Input("filter", "T1")
1318+ .Input("scale0", "T3")
1319+ .Output("y", "T2")
1320+ .Attr<std::vector<int64_t>>("strides")
1321+ .Attr<std::vector<int64_t>>("pads")
1322+ .Attr<std::vector<int64_t>>("dilations")
1323+ .Attr<int64_t>("groups")
1324+ .Attr<std::string>("pad_mode")
1325+ .Attr<std::string>("data_format")
1326+ .Attr<int64_t>("offset_x")
1327+ .Attr<std::string>("round_mode")
1328+ .Attr<bool>("enable_hf32")
1329+ .Attr<int64_t>("fixed_shift_value")
1330+ .Attr<bool>("enable_relu0")
1331+ .ComputeType(ComputeType::kComputeCube)
1332+ .Impl(v2_soc_versions,
1333+ {af::ascir::AscIrImplCreator<Conv2DAscIrAttImplV2>(),
1334+ af::ascir::AscIrImplCreator<af::ascir::Conv2DAscIrCodegenImplV2>(),
1335+ {{"T1", TensorType{DT_INT8}}, {"T2", TensorType{DT_FLOAT16}}, {"T3", TensorType{DT_UINT64}}}});
1336+ 
1337+REG_ASC_IR(ExtendConv2DBiasScale)
1338+ .Input("x", "T1")
1339+ .Input("filter", "T1")
1340+ .Input("bias", "T2")
1341+ .Input("scale0", "T4")
1342+ .Output("y", "T3")
1343+ .Attr<std::vector<int64_t>>("strides")
1344+ .Attr<std::vector<int64_t>>("pads")
1345+ .Attr<std::vector<int64_t>>("dilations")
1346+ .Attr<int64_t>("groups")
1347+ .Attr<std::string>("pad_mode")
1348+ .Attr<std::string>("data_format")
1349+ .Attr<int64_t>("offset_x")
1350+ .Attr<std::string>("round_mode")
1351+ .Attr<bool>("enable_hf32")
1352+ .Attr<int64_t>("fixed_shift_value")
1353+ .Attr<bool>("enable_relu0")
1354+ .ComputeType(ComputeType::kComputeCube)
1355+ .Impl(v2_soc_versions, {af::ascir::AscIrImplCreator<Conv2DAscIrAttImplV2>(),
1356+ af::ascir::AscIrImplCreator<af::ascir::Conv2DAscIrCodegenImplV2>(),
1357+ {{"T1", TensorType{DT_INT8}},
1358+ {"T2", TensorType{DT_INT32}},
1359+ {"T3", TensorType{DT_FLOAT16}},
1360+ {"T4", TensorType{DT_UINT64}}}});
1276 1361 
1277REG_ASC_IR(Softmax)1362REG_ASC_IR(Softmax)
1278 .Input("x", "T")1363 .Input("x", "T")
@@ -91,6 +91,10 @@ REG_ASC_IR_ATT_V2_CLASS_DEFINE(Conv2D);
91REG_ASC_IR_ATT_V2_CLASS_DEFINE(Conv2DBias);91REG_ASC_IR_ATT_V2_CLASS_DEFINE(Conv2DBias);
92REG_ASC_IR_ATT_V2_CLASS_DEFINE(Conv2DOffset);92REG_ASC_IR_ATT_V2_CLASS_DEFINE(Conv2DOffset);
93REG_ASC_IR_ATT_V2_CLASS_DEFINE(Conv2DOffsetBias);93REG_ASC_IR_ATT_V2_CLASS_DEFINE(Conv2DOffsetBias);
94+REG_ASC_IR_ATT_V2_CLASS_DEFINE(ExtendConv2D);
95+REG_ASC_IR_ATT_V2_CLASS_DEFINE(ExtendConv2DBias);
96+REG_ASC_IR_ATT_V2_CLASS_DEFINE(ExtendConv2DScale);
97+REG_ASC_IR_ATT_V2_CLASS_DEFINE(ExtendConv2DBiasScale);
94// 当前未完整做完芯片隔离98// 当前未完整做完芯片隔离
95REG_ASC_IR_ATT_V2_CLASS_DEFINE(VectorFunc);99REG_ASC_IR_ATT_V2_CLASS_DEFINE(VectorFunc);
96// 目前无建模的ASCIR100// 目前无建模的ASCIR