已合并
mm和bmm支持16in32out输入 #4823
mm和bmm支持16in32out输入 #4823
已合并
HKFLYE创建于 5月14日
13 个文件变更+2272-102
@@ -721,6 +721,486 @@
721 "value": false721 "value": false
722 }722 }
723 ]723 ]
724+ },
725+ {
726+ "bin_filename": "BatchMatMulV3_ND_ND_ND_ND_FP16_FP16_FP32_FP32",
727+ "simplified_key": "diy,2/2/2/2/1/1/0/0",
728+ "inputs": [
729+ {
730+ "name": "x1",
731+ "index": 0,
732+ "dtype": "float16",
733+ "format": "ND",
734+ "paramType": "required",
735+ "shape": [
736+ -2
737+ ]
738+ },
739+ {
740+ "name": "x2",
741+ "index": 1,
742+ "dtype": "float16",
743+ "format": "ND",
744+ "paramType": "required",
745+ "shape": [
746+ -2
747+ ]
748+ },
749+ {
750+ "name": "bias",
751+ "index": 2,
752+ "dtype": "float32",
753+ "format": "ND",
754+ "paramType": "optional",
755+ "shape": [
756+ -2
757+ ]
758+ },
759+ {
760+ "name": "offset_w",
761+ "index": 3,
762+ "dtype": "int8",
763+ "format": "ND",
764+ "paramType": "optional",
765+ "shape": [
766+ -2
767+ ]
768+ }
769+ ],
770+ "outputs": [
771+ {
772+ "name": "y",
773+ "index": 0,
774+ "dtype": "float32",
775+ "format": "ND",
776+ "paramType": "required",
777+ "shape": [
778+ -2
779+ ]
780+ }
781+ ],
782+ "attrs": [
783+ {
784+ "name": "adj_x1",
785+ "dtype": "bool",
786+ "value": false
787+ },
788+ {
789+ "name": "adj_x2",
790+ "dtype": "bool",
791+ "value": false
792+ },
793+ {
794+ "name": "offset_x",
795+ "dtype": "int",
796+ "value": 0
797+ },
798+ {
799+ "name": "enable_hf32",
800+ "dtype": "bool",
801+ "value": false
802+ }
803+ ]
804+ },
805+ {
806+ "bin_filename": "BatchMatMulV3_ND_ND_ND_ND_BF16_BF16_FP32_FP32",
807+ "simplified_key": "diy,2/2/2/2/27/27/0/0",
808+ "inputs": [
809+ {
810+ "name": "x1",
811+ "index": 0,
812+ "dtype": "bfloat16",
813+ "format": "ND",
814+ "paramType": "required",
815+ "shape": [
816+ -2
817+ ]
818+ },
819+ {
820+ "name": "x2",
821+ "index": 1,
822+ "dtype": "bfloat16",
823+ "format": "ND",
824+ "paramType": "required",
825+ "shape": [
826+ -2
827+ ]
828+ },
829+ {
830+ "name": "bias",
831+ "index": 2,
832+ "dtype": "float32",
833+ "format": "ND",
834+ "paramType": "optional",
835+ "shape": [
836+ -2
837+ ]
838+ },
839+ {
840+ "name": "offset_w",
841+ "index": 3,
842+ "dtype": "int8",
843+ "format": "ND",
844+ "paramType": "optional",
845+ "shape": [
846+ -2
847+ ]
848+ }
849+ ],
850+ "outputs": [
851+ {
852+ "name": "y",
853+ "index": 0,
854+ "dtype": "float32",
855+ "format": "ND",
856+ "paramType": "required",
857+ "shape": [
858+ -2
859+ ]
860+ }
861+ ],
862+ "attrs": [
863+ {
864+ "name": "adj_x1",
865+ "dtype": "bool",
866+ "value": false
867+ },
868+ {
869+ "name": "adj_x2",
870+ "dtype": "bool",
871+ "value": false
872+ },
873+ {
874+ "name": "offset_x",
875+ "dtype": "int",
876+ "value": 0
877+ },
878+ {
879+ "name": "enable_hf32",
880+ "dtype": "bool",
881+ "value": false
882+ }
883+ ]
884+ },
885+ {
886+ "bin_filename": "BatchMatMulV3_ND_NZ_ND_ND_FP16_FP16_FP16_FP32",
887+ "simplified_key": "diy,2/29/2/2/1/1/1/0",
888+ "inputs": [
889+ {
890+ "name": "x1",
891+ "index": 0,
892+ "dtype": "float16",
893+ "format": "ND",
894+ "paramType": "required",
895+ "shape": [
896+ -2
897+ ]
898+ },
899+ {
900+ "name": "x2",
901+ "index": 1,
902+ "dtype": "float16",
903+ "format": "FRACTAL_NZ",
904+ "paramType": "required",
905+ "shape": [
906+ -2
907+ ]
908+ },
909+ {
910+ "name": "bias",
911+ "index": 2,
912+ "dtype": "float16",
913+ "format": "ND",
914+ "paramType": "optional",
915+ "shape": [
916+ -2
917+ ]
918+ },
919+ {
920+ "name": "offset_w",
921+ "index": 3,
922+ "dtype": "int8",
923+ "format": "ND",
924+ "paramType": "optional",
925+ "shape": [
926+ -2
927+ ]
928+ }
929+ ],
930+ "outputs": [
931+ {
932+ "name": "y",
933+ "index": 0,
934+ "dtype": "float32",
935+ "format": "ND",
936+ "paramType": "required",
937+ "shape": [
938+ -2
939+ ]
940+ }
941+ ],
942+ "attrs": [
943+ {
944+ "name": "adj_x1",
945+ "dtype": "bool",
946+ "value": false
947+ },
948+ {
949+ "name": "adj_x2",
950+ "dtype": "bool",
951+ "value": false
952+ },
953+ {
954+ "name": "offset_x",
955+ "dtype": "int",
956+ "value": 0
957+ },
958+ {
959+ "name": "enable_hf32",
960+ "dtype": "bool",
961+ "value": false
962+ }
963+ ]
964+ },
965+ {
966+ "bin_filename": "BatchMatMulV3_ND_NZ_ND_ND_FP16_FP16_FP32_FP32",
967+ "simplified_key": "diy,2/29/2/2/1/1/0/0",
968+ "inputs": [
969+ {
970+ "name": "x1",
971+ "index": 0,
972+ "dtype": "float16",
973+ "format": "ND",
974+ "paramType": "required",
975+ "shape": [
976+ -2
977+ ]
978+ },
979+ {
980+ "name": "x2",
981+ "index": 1,
982+ "dtype": "float16",
983+ "format": "FRACTAL_NZ",
984+ "paramType": "required",
985+ "shape": [
986+ -2
987+ ]
988+ },
989+ {
990+ "name": "bias",
991+ "index": 2,
992+ "dtype": "float32",
993+ "format": "ND",
994+ "paramType": "optional",
995+ "shape": [
996+ -2
997+ ]
998+ },
999+ {
1000+ "name": "offset_w",
1001+ "index": 3,
1002+ "dtype": "int8",
1003+ "format": "ND",
1004+ "paramType": "optional",
1005+ "shape": [
1006+ -2
1007+ ]
1008+ }
1009+ ],
1010+ "outputs": [
1011+ {
1012+ "name": "y",
1013+ "index": 0,
1014+ "dtype": "float32",
1015+ "format": "ND",
1016+ "paramType": "required",
1017+ "shape": [
1018+ -2
1019+ ]
1020+ }
1021+ ],
1022+ "attrs": [
1023+ {
1024+ "name": "adj_x1",
1025+ "dtype": "bool",
1026+ "value": false
1027+ },
1028+ {
1029+ "name": "adj_x2",
1030+ "dtype": "bool",
1031+ "value": false
1032+ },
1033+ {
1034+ "name": "offset_x",
1035+ "dtype": "int",
1036+ "value": 0
1037+ },
1038+ {
1039+ "name": "enable_hf32",
1040+ "dtype": "bool",
1041+ "value": false
1042+ }
1043+ ]
1044+ },
1045+ {
1046+ "bin_filename": "BatchMatMulV3_ND_NZ_ND_ND_BF16_BF16_BF16_FP32",
1047+ "simplified_key": "diy,2/29/2/2/27/27/27/0",
1048+ "inputs": [
1049+ {
1050+ "name": "x1",
1051+ "index": 0,
1052+ "dtype": "bfloat16",
1053+ "format": "ND",
1054+ "paramType": "required",
1055+ "shape": [
1056+ -2
1057+ ]
1058+ },
1059+ {
1060+ "name": "x2",
1061+ "index": 1,
1062+ "dtype": "bfloat16",
1063+ "format": "FRACTAL_NZ",
1064+ "paramType": "required",
1065+ "shape": [
1066+ -2
1067+ ]
1068+ },
1069+ {
1070+ "name": "bias",
1071+ "index": 2,
1072+ "dtype": "bfloat16",
1073+ "format": "ND",
1074+ "paramType": "optional",
1075+ "shape": [
1076+ -2
1077+ ]
1078+ },
1079+ {
1080+ "name": "offset_w",
1081+ "index": 3,
1082+ "dtype": "int8",
1083+ "format": "ND",
1084+ "paramType": "optional",
1085+ "shape": [
1086+ -2
1087+ ]
1088+ }
1089+ ],
1090+ "outputs": [
1091+ {
1092+ "name": "y",
1093+ "index": 0,
1094+ "dtype": "float32",
1095+ "format": "ND",
1096+ "paramType": "required",
1097+ "shape": [
1098+ -2
1099+ ]
1100+ }
1101+ ],
1102+ "attrs": [
1103+ {
1104+ "name": "adj_x1",
1105+ "dtype": "bool",
1106+ "value": false
1107+ },
1108+ {
1109+ "name": "adj_x2",
1110+ "dtype": "bool",
1111+ "value": false
1112+ },
1113+ {
1114+ "name": "offset_x",
1115+ "dtype": "int",
1116+ "value": 0
1117+ },
1118+ {
1119+ "name": "enable_hf32",
1120+ "dtype": "bool",
1121+ "value": false
1122+ }
1123+ ]
1124+ },
1125+ {
1126+ "bin_filename": "BatchMatMulV3_ND_NZ_ND_ND_BF16_BF16_FP32_FP32",
1127+ "simplified_key": "diy,2/29/2/2/27/27/0/0",
1128+ "inputs": [
1129+ {
1130+ "name": "x1",
1131+ "index": 0,
1132+ "dtype": "bfloat16",
1133+ "format": "ND",
1134+ "paramType": "required",
1135+ "shape": [
1136+ -2
1137+ ]
1138+ },
1139+ {
1140+ "name": "x2",
1141+ "index": 1,
1142+ "dtype": "bfloat16",
1143+ "format": "FRACTAL_NZ",
1144+ "paramType": "required",
1145+ "shape": [
1146+ -2
1147+ ]
1148+ },
1149+ {
1150+ "name": "bias",
1151+ "index": 2,
1152+ "dtype": "float32",
1153+ "format": "ND",
1154+ "paramType": "optional",
1155+ "shape": [
1156+ -2
1157+ ]
1158+ },
1159+ {
1160+ "name": "offset_w",
1161+ "index": 3,
1162+ "dtype": "int8",
1163+ "format": "ND",
1164+ "paramType": "optional",
1165+ "shape": [
1166+ -2
1167+ ]
1168+ }
1169+ ],
1170+ "outputs": [
1171+ {
1172+ "name": "y",
1173+ "index": 0,
1174+ "dtype": "float32",
1175+ "format": "ND",
1176+ "paramType": "required",
1177+ "shape": [
1178+ -2
1179+ ]
1180+ }
1181+ ],
1182+ "attrs": [
1183+ {
1184+ "name": "adj_x1",
1185+ "dtype": "bool",
1186+ "value": false
1187+ },
1188+ {
1189+ "name": "adj_x2",
1190+ "dtype": "bool",
1191+ "value": false
1192+ },
1193+ {
1194+ "name": "offset_x",
1195+ "dtype": "int",
1196+ "value": 0
1197+ },
1198+ {
1199+ "name": "enable_hf32",
1200+ "dtype": "bool",
1201+ "value": false
1202+ }
1203+ ]
724 }1204 }
725 ]1205 ]
726}1206}
@@ -721,6 +721,486 @@
721 "value": false721 "value": false
722 }722 }
723 ]723 ]
724+ },
725+ {
726+ "bin_filename": "BatchMatMulV3_ND_ND_ND_ND_FP16_FP16_FP32_FP32",
727+ "simplified_key": "diy,2/2/2/2/1/1/0/0",
728+ "inputs": [
729+ {
730+ "name": "x1",
731+ "index": 0,
732+ "dtype": "float16",
733+ "format": "ND",
734+ "paramType": "required",
735+ "shape": [
736+ -2
737+ ]
738+ },
739+ {
740+ "name": "x2",
741+ "index": 1,
742+ "dtype": "float16",
743+ "format": "ND",
744+ "paramType": "required",
745+ "shape": [
746+ -2
747+ ]
748+ },
749+ {
750+ "name": "bias",
751+ "index": 2,
752+ "dtype": "float32",
753+ "format": "ND",
754+ "paramType": "optional",
755+ "shape": [
756+ -2
757+ ]
758+ },
759+ {
760+ "name": "offset_w",
761+ "index": 3,
762+ "dtype": "int8",
763+ "format": "ND",
764+ "paramType": "optional",
765+ "shape": [
766+ -2
767+ ]
768+ }
769+ ],
770+ "outputs": [
771+ {
772+ "name": "y",
773+ "index": 0,
774+ "dtype": "float32",
775+ "format": "ND",
776+ "paramType": "required",
777+ "shape": [
778+ -2
779+ ]
780+ }
781+ ],
782+ "attrs": [
783+ {
784+ "name": "adj_x1",
785+ "dtype": "bool",
786+ "value": false
787+ },
788+ {
789+ "name": "adj_x2",
790+ "dtype": "bool",
791+ "value": false
792+ },
793+ {
794+ "name": "offset_x",
795+ "dtype": "int",
796+ "value": 0
797+ },
798+ {
799+ "name": "enable_hf32",
800+ "dtype": "bool",
801+ "value": false
802+ }
803+ ]
804+ },
805+ {
806+ "bin_filename": "BatchMatMulV3_ND_ND_ND_ND_BF16_BF16_FP32_FP32",
807+ "simplified_key": "diy,2/2/2/2/27/27/0/0",
808+ "inputs": [
809+ {
810+ "name": "x1",
811+ "index": 0,
812+ "dtype": "bfloat16",
813+ "format": "ND",
814+ "paramType": "required",
815+ "shape": [
816+ -2
817+ ]
818+ },
819+ {
820+ "name": "x2",
821+ "index": 1,
822+ "dtype": "bfloat16",
823+ "format": "ND",
824+ "paramType": "required",
825+ "shape": [
826+ -2
827+ ]
828+ },
829+ {
830+ "name": "bias",
831+ "index": 2,
832+ "dtype": "float32",
833+ "format": "ND",
834+ "paramType": "optional",
835+ "shape": [
836+ -2
837+ ]
838+ },
839+ {
840+ "name": "offset_w",
841+ "index": 3,
842+ "dtype": "int8",
843+ "format": "ND",
844+ "paramType": "optional",
845+ "shape": [
846+ -2
847+ ]
848+ }
849+ ],
850+ "outputs": [
851+ {
852+ "name": "y",
853+ "index": 0,
854+ "dtype": "float32",
855+ "format": "ND",
856+ "paramType": "required",
857+ "shape": [
858+ -2
859+ ]
860+ }
861+ ],
862+ "attrs": [
863+ {
864+ "name": "adj_x1",
865+ "dtype": "bool",
866+ "value": false
867+ },
868+ {
869+ "name": "adj_x2",
870+ "dtype": "bool",
871+ "value": false
872+ },
873+ {
874+ "name": "offset_x",
875+ "dtype": "int",
876+ "value": 0
877+ },
878+ {
879+ "name": "enable_hf32",
880+ "dtype": "bool",
881+ "value": false
882+ }
883+ ]
884+ },
885+ {
886+ "bin_filename": "BatchMatMulV3_ND_NZ_ND_ND_FP16_FP16_FP16_FP32",
887+ "simplified_key": "diy,2/29/2/2/1/1/1/0",
888+ "inputs": [
889+ {
890+ "name": "x1",
891+ "index": 0,
892+ "dtype": "float16",
893+ "format": "ND",
894+ "paramType": "required",
895+ "shape": [
896+ -2
897+ ]
898+ },
899+ {
900+ "name": "x2",
901+ "index": 1,
902+ "dtype": "float16",
903+ "format": "FRACTAL_NZ",
904+ "paramType": "required",
905+ "shape": [
906+ -2
907+ ]
908+ },
909+ {
910+ "name": "bias",
911+ "index": 2,
912+ "dtype": "float16",
913+ "format": "ND",
914+ "paramType": "optional",
915+ "shape": [
916+ -2
917+ ]
918+ },
919+ {
920+ "name": "offset_w",
921+ "index": 3,
922+ "dtype": "int8",
923+ "format": "ND",
924+ "paramType": "optional",
925+ "shape": [
926+ -2
927+ ]
928+ }
929+ ],
930+ "outputs": [
931+ {
932+ "name": "y",
933+ "index": 0,
934+ "dtype": "float32",
935+ "format": "ND",
936+ "paramType": "required",
937+ "shape": [
938+ -2
939+ ]
940+ }
941+ ],
942+ "attrs": [
943+ {
944+ "name": "adj_x1",
945+ "dtype": "bool",
946+ "value": false
947+ },
948+ {
949+ "name": "adj_x2",
950+ "dtype": "bool",
951+ "value": false
952+ },
953+ {
954+ "name": "offset_x",
955+ "dtype": "int",
956+ "value": 0
957+ },
958+ {
959+ "name": "enable_hf32",
960+ "dtype": "bool",
961+ "value": false
962+ }
963+ ]
964+ },
965+ {
966+ "bin_filename": "BatchMatMulV3_ND_NZ_ND_ND_FP16_FP16_FP32_FP32",
967+ "simplified_key": "diy,2/29/2/2/1/1/0/0",
968+ "inputs": [
969+ {
970+ "name": "x1",
971+ "index": 0,
972+ "dtype": "float16",
973+ "format": "ND",
974+ "paramType": "required",
975+ "shape": [
976+ -2
977+ ]
978+ },
979+ {
980+ "name": "x2",
981+ "index": 1,
982+ "dtype": "float16",
983+ "format": "FRACTAL_NZ",
984+ "paramType": "required",
985+ "shape": [
986+ -2
987+ ]
988+ },
989+ {
990+ "name": "bias",
991+ "index": 2,
992+ "dtype": "float32",
993+ "format": "ND",
994+ "paramType": "optional",
995+ "shape": [
996+ -2
997+ ]
998+ },
999+ {
1000+ "name": "offset_w",
1001+ "index": 3,
1002+ "dtype": "int8",
1003+ "format": "ND",
1004+ "paramType": "optional",
1005+ "shape": [
1006+ -2
1007+ ]
1008+ }
1009+ ],
1010+ "outputs": [
1011+ {
1012+ "name": "y",
1013+ "index": 0,
1014+ "dtype": "float32",
1015+ "format": "ND",
1016+ "paramType": "required",
1017+ "shape": [
1018+ -2
1019+ ]
1020+ }
1021+ ],
1022+ "attrs": [
1023+ {
1024+ "name": "adj_x1",
1025+ "dtype": "bool",
1026+ "value": false
1027+ },
1028+ {
1029+ "name": "adj_x2",
1030+ "dtype": "bool",
1031+ "value": false
1032+ },
1033+ {
1034+ "name": "offset_x",
1035+ "dtype": "int",
1036+ "value": 0
1037+ },
1038+ {
1039+ "name": "enable_hf32",
1040+ "dtype": "bool",
1041+ "value": false
1042+ }
1043+ ]
1044+ },
1045+ {
1046+ "bin_filename": "BatchMatMulV3_ND_NZ_ND_ND_BF16_BF16_BF16_FP32",
1047+ "simplified_key": "diy,2/29/2/2/27/27/27/0",
1048+ "inputs": [
1049+ {
1050+ "name": "x1",
1051+ "index": 0,
1052+ "dtype": "bfloat16",
1053+ "format": "ND",
1054+ "paramType": "required",
1055+ "shape": [
1056+ -2
1057+ ]
1058+ },
1059+ {
1060+ "name": "x2",
1061+ "index": 1,
1062+ "dtype": "bfloat16",
1063+ "format": "FRACTAL_NZ",
1064+ "paramType": "required",
1065+ "shape": [
1066+ -2
1067+ ]
1068+ },
1069+ {
1070+ "name": "bias",
1071+ "index": 2,
1072+ "dtype": "bfloat16",
1073+ "format": "ND",
1074+ "paramType": "optional",
1075+ "shape": [
1076+ -2
1077+ ]
1078+ },
1079+ {
1080+ "name": "offset_w",
1081+ "index": 3,
1082+ "dtype": "int8",
1083+ "format": "ND",
1084+ "paramType": "optional",
1085+ "shape": [
1086+ -2
1087+ ]
1088+ }
1089+ ],
1090+ "outputs": [
1091+ {
1092+ "name": "y",
1093+ "index": 0,
1094+ "dtype": "float32",
1095+ "format": "ND",
1096+ "paramType": "required",
1097+ "shape": [
1098+ -2
1099+ ]
1100+ }
1101+ ],
1102+ "attrs": [
1103+ {
1104+ "name": "adj_x1",
1105+ "dtype": "bool",
1106+ "value": false
1107+ },
1108+ {
1109+ "name": "adj_x2",
1110+ "dtype": "bool",
1111+ "value": false
1112+ },
1113+ {
1114+ "name": "offset_x",
1115+ "dtype": "int",
1116+ "value": 0
1117+ },
1118+ {
1119+ "name": "enable_hf32",
1120+ "dtype": "bool",
1121+ "value": false
1122+ }
1123+ ]
1124+ },
1125+ {
1126+ "bin_filename": "BatchMatMulV3_ND_NZ_ND_ND_BF16_BF16_FP32_FP32",
1127+ "simplified_key": "diy,2/29/2/2/27/27/0/0",
1128+ "inputs": [
1129+ {
1130+ "name": "x1",
1131+ "index": 0,
1132+ "dtype": "bfloat16",
1133+ "format": "ND",
1134+ "paramType": "required",
1135+ "shape": [
1136+ -2
1137+ ]
1138+ },
1139+ {
1140+ "name": "x2",
1141+ "index": 1,
1142+ "dtype": "bfloat16",
1143+ "format": "FRACTAL_NZ",
1144+ "paramType": "required",
1145+ "shape": [
1146+ -2
1147+ ]
1148+ },
1149+ {
1150+ "name": "bias",
1151+ "index": 2,
1152+ "dtype": "float32",
1153+ "format": "ND",
1154+ "paramType": "optional",
1155+ "shape": [
1156+ -2
1157+ ]
1158+ },
1159+ {
1160+ "name": "offset_w",
1161+ "index": 3,
1162+ "dtype": "int8",
1163+ "format": "ND",
1164+ "paramType": "optional",
1165+ "shape": [
1166+ -2
1167+ ]
1168+ }
1169+ ],
1170+ "outputs": [
1171+ {
1172+ "name": "y",
1173+ "index": 0,
1174+ "dtype": "float32",
1175+ "format": "ND",
1176+ "paramType": "required",
1177+ "shape": [
1178+ -2
1179+ ]
1180+ }
1181+ ],
1182+ "attrs": [
1183+ {
1184+ "name": "adj_x1",
1185+ "dtype": "bool",
1186+ "value": false
1187+ },
1188+ {
1189+ "name": "adj_x2",
1190+ "dtype": "bool",
1191+ "value": false
1192+ },
1193+ {
1194+ "name": "offset_x",
1195+ "dtype": "int",
1196+ "value": 0
1197+ },
1198+ {
1199+ "name": "enable_hf32",
1200+ "dtype": "bool",
1201+ "value": false
1202+ }
1203+ ]
724 }1204 }
725 ]1205 ]
726}1206}
@@ -207,11 +207,11 @@ bool CheckDtypeValidWeightNz(const aclTensor* self, const aclTensor* mat2, const
207 "batchmatmulweightnz is unsupported in this npu arch");207 "batchmatmulweightnz is unsupported in this npu arch");
208 return false;208 return false;
209 }209 }
210- bool enable3510Fp32Output = NeedEnable3510Fp32Output(210+ bool enable16In32Out = NeedEnableFp32Output(
211 self->GetDataType(), mat2->GetDataType(), out->GetDataType(), cubeMathType);211 self->GetDataType(), mat2->GetDataType(), out->GetDataType(), cubeMathType);
212 OP_CHECK_DTYPE_NOT_SUPPORT(self, DTYPE_SUPPORT_LIST_WEIGHTNZ, return false);212 OP_CHECK_DTYPE_NOT_SUPPORT(self, DTYPE_SUPPORT_LIST_WEIGHTNZ, return false);
213 OP_CHECK_DTYPE_NOT_SUPPORT(mat2, DTYPE_SUPPORT_LIST_WEIGHTNZ, return false);213 OP_CHECK_DTYPE_NOT_SUPPORT(mat2, DTYPE_SUPPORT_LIST_WEIGHTNZ, return false);
214- if (enable3510Fp32Output) {214+ if (enable16In32Out) {
215 OP_CHECK_DTYPE_NOT_SUPPORT(out, DTYPE_SUPPORT_LIST, return false);215 OP_CHECK_DTYPE_NOT_SUPPORT(out, DTYPE_SUPPORT_LIST, return false);
216 } else {216 } else {
217 OP_CHECK_DTYPE_NOT_SUPPORT(out, DTYPE_SUPPORT_LIST_WEIGHTNZ, return false);217 OP_CHECK_DTYPE_NOT_SUPPORT(out, DTYPE_SUPPORT_LIST_WEIGHTNZ, return false);
@@ -14,6 +14,7 @@
14 14 
15#include "../../../op_host/op_api/aclnn_batch_matmul.h"15#include "../../../op_host/op_api/aclnn_batch_matmul.h"
16#include "opdev/platform.h"16#include "opdev/platform.h"
17+#include "op_api/op_api_def.h"
17#include "op_api_ut_common/op_api_ut.h"18#include "op_api_ut_common/op_api_ut.h"
18#include "op_api_ut_common/scalar_desc.h"19#include "op_api_ut_common/scalar_desc.h"
19#include "op_api_ut_common/tensor_desc.h"20#include "op_api_ut_common/tensor_desc.h"
@@ -1391,4 +1392,276 @@ TEST_F(l2_batch_matmul_test, batch_matmul_310_FP32_FP16_FP16FP32_KEEP_DTYPE)
1391 OP_API_UT(aclnnBatchMatMul, INPUT(tensor_1_desc, tensor_2_desc), OUTPUT(out_tensor_desc), cube_math_type);1392 OP_API_UT(aclnnBatchMatMul, INPUT(tensor_1_desc, tensor_2_desc), OUTPUT(out_tensor_desc), cube_math_type);
1392 aclRet = ut_false_false.TestGetWorkspaceSize(&workspace_size);1393 aclRet = ut_false_false.TestGetWorkspaceSize(&workspace_size);
1393 EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID);1394 EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID);
1395+}
1396+ 
1397+TEST_F(l2_batch_matmul_test, batch_matmul_16in32out_fp16_fp16_fp32_keep_dtype_aligned)
1398+{
1399+ op::SocVersionManager versionManager(op::SocVersion::ASCEND910B);
1400+ auto tensor_1_desc = TensorDesc({8, 16, 32}, ACL_FLOAT16, ACL_FORMAT_ND).ValueRange(-2, 2);
1401+ auto tensor_2_desc = TensorDesc({8, 32, 64}, ACL_FLOAT16, ACL_FORMAT_ND).ValueRange(-2, 2);
1402+ auto out_tensor_desc = TensorDesc({8, 16, 64}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.005, 0.005);
1403+ int8_t cube_math_type = KEEP_DTYPE;
1404+ auto ut = OP_API_UT(aclnnBatchMatMul, INPUT(tensor_1_desc, tensor_2_desc), OUTPUT(out_tensor_desc), cube_math_type);
1405+ 
1406+ uint64_t workspace_size = 0;
1407+ aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size);
1408+ EXPECT_EQ(aclRet, ACL_SUCCESS);
1409+}
1410+ 
1411+TEST_F(l2_batch_matmul_test, batch_matmul_16in32out_bf16_bf16_fp32_keep_dtype_aligned)
1412+{
1413+ op::SocVersionManager versionManager(op::SocVersion::ASCEND910B);
1414+ auto tensor_1_desc = TensorDesc({8, 16, 32}, ACL_BF16, ACL_FORMAT_ND).ValueRange(-2, 2);
1415+ auto tensor_2_desc = TensorDesc({8, 32, 64}, ACL_BF16, ACL_FORMAT_ND).ValueRange(-2, 2);
1416+ auto out_tensor_desc = TensorDesc({8, 16, 64}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.005, 0.005);
1417+ int8_t cube_math_type = KEEP_DTYPE;
1418+ auto ut = OP_API_UT(aclnnBatchMatMul, INPUT(tensor_1_desc, tensor_2_desc), OUTPUT(out_tensor_desc), cube_math_type);
1419+ 
1420+ uint64_t workspace_size = 0;
1421+ aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size);
1422+ EXPECT_EQ(aclRet, ACL_SUCCESS);
1423+}
1424+ 
1425+TEST_F(l2_batch_matmul_test, batch_matmul_16in32out_fp16_fp16_fp32_keep_dtype_not_aligned)
1426+{
1427+ op::SocVersionManager versionManager(op::SocVersion::ASCEND910B);
1428+ auto tensor_1_desc = TensorDesc({3, 5, 7}, ACL_FLOAT16, ACL_FORMAT_ND).ValueRange(-2, 2);
1429+ auto tensor_2_desc = TensorDesc({3, 7, 9}, ACL_FLOAT16, ACL_FORMAT_ND).ValueRange(-2, 2);
1430+ auto out_tensor_desc = TensorDesc({3, 5, 9}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.001, 0.001);
1431+ int8_t cube_math_type = KEEP_DTYPE;
1432+ auto ut = OP_API_UT(aclnnBatchMatMul, INPUT(tensor_1_desc, tensor_2_desc), OUTPUT(out_tensor_desc), cube_math_type);
1433+ 
1434+ uint64_t workspace_size = 0;
1435+ aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size);
1436+ EXPECT_EQ(aclRet, ACL_SUCCESS);
1437+}
1438+ 
1439+TEST_F(l2_batch_matmul_test, batch_matmul_16in32out_bf16_bf16_fp32_keep_dtype_not_aligned)
1440+{
1441+ op::SocVersionManager versionManager(op::SocVersion::ASCEND910B);
1442+ auto tensor_1_desc = TensorDesc({3, 5, 7}, ACL_BF16, ACL_FORMAT_ND).ValueRange(-2, 2);
1443+ auto tensor_2_desc = TensorDesc({3, 7, 9}, ACL_BF16, ACL_FORMAT_ND).ValueRange(-2, 2);
1444+ auto out_tensor_desc = TensorDesc({3, 5, 9}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.001, 0.001);
1445+ int8_t cube_math_type = KEEP_DTYPE;
1446+ auto ut = OP_API_UT(aclnnBatchMatMul, INPUT(tensor_1_desc, tensor_2_desc), OUTPUT(out_tensor_desc), cube_math_type);
1447+ 
1448+ uint64_t workspace_size = 0;
1449+ aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size);
1450+ EXPECT_EQ(aclRet, ACL_SUCCESS);
1451+}
1452+ 
1453+TEST_F(l2_batch_matmul_test, batch_matmul_16in32out_fp16_fp16_fp32_use_hf32)
1454+{
1455+ op::SocVersionManager versionManager(op::SocVersion::ASCEND910B);
1456+ auto tensor_1_desc = TensorDesc({4, 16, 32}, ACL_FLOAT16, ACL_FORMAT_ND).ValueRange(-2, 2);
1457+ auto tensor_2_desc = TensorDesc({4, 32, 16}, ACL_FLOAT16, ACL_FORMAT_ND).ValueRange(-2, 2);
1458+ auto out_tensor_desc = TensorDesc({4, 16, 16}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.001, 0.001);
1459+ int8_t cube_math_type = USE_HF32;
1460+ auto ut = OP_API_UT(aclnnBatchMatMul, INPUT(tensor_1_desc, tensor_2_desc), OUTPUT(out_tensor_desc), cube_math_type);
1461+ 
1462+ uint64_t workspace_size = 0;
1463+ aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size);
1464+ EXPECT_EQ(aclRet, ACL_SUCCESS);
1465+}
1466+ 
1467+TEST_F(l2_batch_matmul_test, batch_matmul_16in32out_bf16_bf16_fp32_use_hf32)
1468+{
1469+ op::SocVersionManager versionManager(op::SocVersion::ASCEND910B);
1470+ auto tensor_1_desc = TensorDesc({4, 16, 32}, ACL_BF16, ACL_FORMAT_ND).ValueRange(-2, 2);
1471+ auto tensor_2_desc = TensorDesc({4, 32, 16}, ACL_BF16, ACL_FORMAT_ND).ValueRange(-2, 2);
1472+ auto out_tensor_desc = TensorDesc({4, 16, 16}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.001, 0.001);
1473+ int8_t cube_math_type = USE_HF32;
1474+ auto ut = OP_API_UT(aclnnBatchMatMul, INPUT(tensor_1_desc, tensor_2_desc), OUTPUT(out_tensor_desc), cube_math_type);
1475+ 
1476+ uint64_t workspace_size = 0;
1477+ aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size);
1478+ EXPECT_EQ(aclRet, ACL_SUCCESS);
1479+}
1480+ 
1481+TEST_F(l2_batch_matmul_test, batch_matmul_16in32out_fp16_fp16_fp32_allow_fp32_down_precision)
1482+{
1483+ op::SocVersionManager versionManager(op::SocVersion::ASCEND910B);
1484+ auto tensor_1_desc = TensorDesc({4, 16, 32}, ACL_FLOAT16, ACL_FORMAT_ND).ValueRange(-2, 2);
1485+ auto tensor_2_desc = TensorDesc({4, 32, 16}, ACL_FLOAT16, ACL_FORMAT_ND).ValueRange(-2, 2);
1486+ auto out_tensor_desc = TensorDesc({4, 16, 16}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.001, 0.001);
1487+ int8_t cube_math_type = ALLOW_FP32_DOWN_PRECISION;
1488+ auto ut = OP_API_UT(aclnnBatchMatMul, INPUT(tensor_1_desc, tensor_2_desc), OUTPUT(out_tensor_desc), cube_math_type);
1489+ 
1490+ uint64_t workspace_size = 0;
1491+ aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size);
1492+ EXPECT_EQ(aclRet, ACL_SUCCESS);
1493+}
1494+ 
1495+TEST_F(l2_batch_matmul_test, batch_matmul_16in32out_bf16_bf16_fp32_allow_fp32_down_precision)
1496+{
1497+ op::SocVersionManager versionManager(op::SocVersion::ASCEND910B);
1498+ auto tensor_1_desc = TensorDesc({4, 16, 32}, ACL_BF16, ACL_FORMAT_ND).ValueRange(-2, 2);
1499+ auto tensor_2_desc = TensorDesc({4, 32, 16}, ACL_BF16, ACL_FORMAT_ND).ValueRange(-2, 2);
1500+ auto out_tensor_desc = TensorDesc({4, 16, 16}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.001, 0.001);
1501+ int8_t cube_math_type = ALLOW_FP32_DOWN_PRECISION;
1502+ auto ut = OP_API_UT(aclnnBatchMatMul, INPUT(tensor_1_desc, tensor_2_desc), OUTPUT(out_tensor_desc), cube_math_type);
1503+ 
1504+ uint64_t workspace_size = 0;
1505+ aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size);
1506+ EXPECT_EQ(aclRet, ACL_SUCCESS);
1507+}
1508+ 
1509+TEST_F(l2_batch_matmul_test, batch_matmul_16in32out_fp16_fp16_fp32_large_batch)
1510+{
1511+ op::SocVersionManager versionManager(op::SocVersion::ASCEND910B);
1512+ auto tensor_1_desc = TensorDesc({128, 16, 32}, ACL_FLOAT16, ACL_FORMAT_ND).ValueRange(-2, 2);
1513+ auto tensor_2_desc = TensorDesc({128, 32, 64}, ACL_FLOAT16, ACL_FORMAT_ND).ValueRange(-2, 2);
1514+ auto out_tensor_desc = TensorDesc({128, 16, 64}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.005, 0.005);
1515+ int8_t cube_math_type = KEEP_DTYPE;
1516+ auto ut = OP_API_UT(aclnnBatchMatMul, INPUT(tensor_1_desc, tensor_2_desc), OUTPUT(out_tensor_desc), cube_math_type);
1517+ 
1518+ uint64_t workspace_size = 0;
1519+ aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size);
1520+ EXPECT_EQ(aclRet, ACL_SUCCESS);
1521+}
1522+ 
1523+TEST_F(l2_batch_matmul_test, batch_matmul_16in32out_bf16_bf16_fp32_large_batch)
1524+{
1525+ op::SocVersionManager versionManager(op::SocVersion::ASCEND910B);
1526+ auto tensor_1_desc = TensorDesc({128, 16, 32}, ACL_BF16, ACL_FORMAT_ND).ValueRange(-2, 2);
1527+ auto tensor_2_desc = TensorDesc({128, 32, 64}, ACL_BF16, ACL_FORMAT_ND).ValueRange(-2, 2);
1528+ auto out_tensor_desc = TensorDesc({128, 16, 64}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.005, 0.005);
1529+ int8_t cube_math_type = KEEP_DTYPE;
1530+ auto ut = OP_API_UT(aclnnBatchMatMul, INPUT(tensor_1_desc, tensor_2_desc), OUTPUT(out_tensor_desc), cube_math_type);
1531+ 
1532+ uint64_t workspace_size = 0;
1533+ aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size);
1534+ EXPECT_EQ(aclRet, ACL_SUCCESS);
1535+}
1536+ 
1537+TEST_F(l2_batch_matmul_test, batch_matmul_16in32out_fp16_fp16_fp32_batch_broadcast)
1538+{
1539+ op::SocVersionManager versionManager(op::SocVersion::ASCEND910B);
1540+ auto tensor_1_desc = TensorDesc({4, 16, 32}, ACL_FLOAT16, ACL_FORMAT_ND).ValueRange(-2, 2);
1541+ auto tensor_2_desc = TensorDesc({1, 32, 16}, ACL_FLOAT16, ACL_FORMAT_ND).ValueRange(-2, 2);
1542+ auto out_tensor_desc = TensorDesc({4, 16, 16}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.001, 0.001);
1543+ int8_t cube_math_type = KEEP_DTYPE;
1544+ auto ut = OP_API_UT(aclnnBatchMatMul, INPUT(tensor_1_desc, tensor_2_desc), OUTPUT(out_tensor_desc), cube_math_type);
1545+ 
1546+ uint64_t workspace_size = 0;
1547+ aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size);
1548+ EXPECT_EQ(aclRet, ACL_SUCCESS);
1549+}
1550+ 
1551+TEST_F(l2_batch_matmul_test, batch_matmul_16in32out_bf16_bf16_fp32_batch_broadcast)
1552+{
1553+ op::SocVersionManager versionManager(op::SocVersion::ASCEND910B);
1554+ auto tensor_1_desc = TensorDesc({4, 16, 32}, ACL_BF16, ACL_FORMAT_ND).ValueRange(-2, 2);
1555+ auto tensor_2_desc = TensorDesc({1, 32, 16}, ACL_BF16, ACL_FORMAT_ND).ValueRange(-2, 2);
1556+ auto out_tensor_desc = TensorDesc({4, 16, 16}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.001, 0.001);
1557+ int8_t cube_math_type = KEEP_DTYPE;
1558+ auto ut = OP_API_UT(aclnnBatchMatMul, INPUT(tensor_1_desc, tensor_2_desc), OUTPUT(out_tensor_desc), cube_math_type);
1559+ 
1560+ uint64_t workspace_size = 0;
1561+ aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size);
1562+ EXPECT_EQ(aclRet, ACL_SUCCESS);
1563+}
1564+ 
1565+TEST_F(l2_batch_matmul_test, batch_matmul_16in32out_fp16_fp16_fp32_k1_special)
1566+{
1567+ op::SocVersionManager versionManager(op::SocVersion::ASCEND910B);
1568+ auto tensor_1_desc = TensorDesc({4, 16, 1}, ACL_FLOAT16, ACL_FORMAT_ND).ValueRange(-2, 2);
1569+ auto tensor_2_desc = TensorDesc({4, 1, 16}, ACL_FLOAT16, ACL_FORMAT_ND).ValueRange(-2, 2);
1570+ auto out_tensor_desc = TensorDesc({4, 16, 16}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.001, 0.001);
1571+ int8_t cube_math_type = KEEP_DTYPE;
1572+ auto ut = OP_API_UT(aclnnBatchMatMul, INPUT(tensor_1_desc, tensor_2_desc), OUTPUT(out_tensor_desc), cube_math_type);
1573+ 
1574+ uint64_t workspace_size = 0;
1575+ aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size);
1576+ EXPECT_EQ(aclRet, ACL_SUCCESS);
1577+}
1578+ 
1579+TEST_F(l2_batch_matmul_test, batch_matmul_16in32out_bf16_bf16_fp32_k1_special)
1580+{
1581+ op::SocVersionManager versionManager(op::SocVersion::ASCEND910B);
1582+ auto tensor_1_desc = TensorDesc({4, 16, 1}, ACL_BF16, ACL_FORMAT_ND).ValueRange(-2, 2);
1583+ auto tensor_2_desc = TensorDesc({4, 1, 16}, ACL_BF16, ACL_FORMAT_ND).ValueRange(-2, 2);
1584+ auto out_tensor_desc = TensorDesc({4, 16, 16}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.001, 0.001);
1585+ int8_t cube_math_type = KEEP_DTYPE;
1586+ auto ut = OP_API_UT(aclnnBatchMatMul, INPUT(tensor_1_desc, tensor_2_desc), OUTPUT(out_tensor_desc), cube_math_type);
1587+ 
1588+ uint64_t workspace_size = 0;
1589+ aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size);
1590+ EXPECT_EQ(aclRet, ACL_SUCCESS);
1591+}
1592+ 
1593+TEST_F(l2_batch_matmul_test, batch_matmul_16in32out_fp16_fp16_fp32_empty_tensor)
1594+{
1595+ op::SocVersionManager versionManager(op::SocVersion::ASCEND910B);
1596+ auto tensor_1_desc = TensorDesc({2, 0, 4}, ACL_FLOAT16, ACL_FORMAT_ND).ValueRange(-2, 2);
1597+ auto tensor_2_desc = TensorDesc({2, 4, 5}, ACL_FLOAT16, ACL_FORMAT_ND).ValueRange(-2, 2);
1598+ auto out_tensor_desc = TensorDesc({2, 0, 5}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.001, 0.001);
1599+ int8_t cube_math_type = KEEP_DTYPE;
1600+ auto ut = OP_API_UT(aclnnBatchMatMul, INPUT(tensor_1_desc, tensor_2_desc), OUTPUT(out_tensor_desc), cube_math_type);
1601+ 
1602+ uint64_t workspace_size = 0;
1603+ aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size);
1604+ EXPECT_EQ(aclRet, ACL_SUCCESS);
1605+}
1606+ 
1607+TEST_F(l2_batch_matmul_test, batch_matmul_16in32out_fp16_fp16_fp32_transpose)
1608+{
1609+ op::SocVersionManager versionManager(op::SocVersion::ASCEND910B);
1610+ auto tensor_1_desc = TensorDesc({4, 16, 32}, ACL_FLOAT16, ACL_FORMAT_ND).ValueRange(-2, 2);
1611+ auto tensor_1_desc_t = TensorDesc({4, 16, 32}, ACL_FLOAT16, ACL_FORMAT_ND,
1612+ {512, 1, 16}, 0, {4, 32, 16}).ValueRange(-2, 2);
1613+ auto tensor_2_desc = TensorDesc({4, 32, 16}, ACL_FLOAT16, ACL_FORMAT_ND).ValueRange(-2, 2);
1614+ auto tensor_2_desc_t = TensorDesc({4, 32, 16}, ACL_FLOAT16, ACL_FORMAT_ND,
1615+ {64, 1, 32}, 0, {4, 16, 32}).ValueRange(-2, 2);
1616+ auto out_tensor_desc = TensorDesc({4, 16, 16}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.005, 0.005);
1617+ 
1618+ int8_t math_type = KEEP_DTYPE;
1619+ uint64_t workspace_size = 0;
1620+ aclnnStatus aclRet = 0;
1621+ auto ut_false_false = OP_API_UT(aclnnBatchMatMul, INPUT(tensor_1_desc, tensor_2_desc),
1622+ OUTPUT(out_tensor_desc), math_type);
1623+ aclRet = ut_false_false.TestGetWorkspaceSize(&workspace_size);
1624+ EXPECT_EQ(aclRet, ACL_SUCCESS);
1625+ auto ut_true_false = OP_API_UT(aclnnBatchMatMul, INPUT(tensor_1_desc_t, tensor_2_desc),
1626+ OUTPUT(out_tensor_desc), math_type);
1627+ aclRet = ut_true_false.TestGetWorkspaceSize(&workspace_size);
1628+ EXPECT_EQ(aclRet, ACL_SUCCESS);
1629+ auto ut_false_true = OP_API_UT(aclnnBatchMatMul, INPUT(tensor_1_desc, tensor_2_desc_t),
1630+ OUTPUT(out_tensor_desc), math_type);
1631+ aclRet = ut_false_true.TestGetWorkspaceSize(&workspace_size);
1632+ EXPECT_EQ(aclRet, ACL_SUCCESS);
1633+ auto ut_true_true = OP_API_UT(aclnnBatchMatMul, INPUT(tensor_1_desc_t, tensor_2_desc_t),
1634+ OUTPUT(out_tensor_desc), math_type);
1635+ aclRet = ut_true_true.TestGetWorkspaceSize(&workspace_size);
1636+ EXPECT_EQ(aclRet, ACL_SUCCESS);
1637+}
1638+ 
1639+TEST_F(l2_batch_matmul_test, batch_matmul_16in32out_bf16_bf16_fp32_transpose)
1640+{
1641+ op::SocVersionManager versionManager(op::SocVersion::ASCEND910B);
1642+ auto tensor_1_desc = TensorDesc({4, 16, 32}, ACL_BF16, ACL_FORMAT_ND).ValueRange(-2, 2);
1643+ auto tensor_1_desc_t = TensorDesc({4, 16, 32}, ACL_BF16, ACL_FORMAT_ND, {512, 1, 16}, 0, {4, 32, 16}).ValueRange(-2, 2);
1644+ auto tensor_2_desc = TensorDesc({4, 32, 16}, ACL_BF16, ACL_FORMAT_ND).ValueRange(-2, 2);
1645+ auto tensor_2_desc_t = TensorDesc({4, 32, 16}, ACL_BF16, ACL_FORMAT_ND, {64, 1, 32}, 0, {4, 16, 32}).ValueRange(-2, 2);
1646+ auto out_tensor_desc = TensorDesc({4, 16, 16}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.005, 0.005);
1647+ 
1648+ int8_t math_type = KEEP_DTYPE;
1649+ uint64_t workspace_size = 0;
1650+ aclnnStatus aclRet = 0;
1651+ auto ut_false_false = OP_API_UT(aclnnBatchMatMul, INPUT(tensor_1_desc, tensor_2_desc),
1652+ OUTPUT(out_tensor_desc), math_type);
1653+ aclRet = ut_false_false.TestGetWorkspaceSize(&workspace_size);
1654+ EXPECT_EQ(aclRet, ACL_SUCCESS);
1655+ auto ut_true_false = OP_API_UT(aclnnBatchMatMul, INPUT(tensor_1_desc_t, tensor_2_desc),
1656+ OUTPUT(out_tensor_desc), math_type);
1657+ aclRet = ut_true_false.TestGetWorkspaceSize(&workspace_size);
1658+ EXPECT_EQ(aclRet, ACL_SUCCESS);
1659+ auto ut_false_true = OP_API_UT(aclnnBatchMatMul, INPUT(tensor_1_desc, tensor_2_desc_t),
1660+ OUTPUT(out_tensor_desc), math_type);
1661+ aclRet = ut_false_true.TestGetWorkspaceSize(&workspace_size);
1662+ EXPECT_EQ(aclRet, ACL_SUCCESS);
1663+ auto ut_true_true = OP_API_UT(aclnnBatchMatMul, INPUT(tensor_1_desc_t, tensor_2_desc_t),
1664+ OUTPUT(out_tensor_desc), math_type);
1665+ aclRet = ut_true_true.TestGetWorkspaceSize(&workspace_size);
1666+ EXPECT_EQ(aclRet, ACL_SUCCESS);
1394}1667}
oscillatedoscillated5月21日

是否需要修改对应aclnn接口文档,更新相关内容?

likedislike
HKFLYE
HKFLYE
5月21日 评论:
@@ -382,11 +382,11 @@ const static std::map<NpuArch, CheckArchIfBatchMatMulToMulFunc> CheckArchIfBatch
382 382 
383const aclTensor* GetBatchMatmulOp(383const aclTensor* GetBatchMatmulOp(
384 const aclTensor* selfTransdata, const aclTensor* mat2Transdata, const aclTensor* bias, const MmOpInfo& matmulOpInfo,384 const aclTensor* selfTransdata, const aclTensor* mat2Transdata, const aclTensor* bias, const MmOpInfo& matmulOpInfo,
385- bool adjX1, bool adjX2, const bool offsetX, aclOpExecutor* executor, bool isBaddbmm)385+ bool adjX1, bool adjX2, const bool offsetX, aclOpExecutor* executor)
386{386{
387 auto bmmOpOut = selfTransdata;387 auto bmmOpOut = selfTransdata;
388 auto npuArch = GetCurrentPlatformInfo().GetCurNpuArch();388 auto npuArch = GetCurrentPlatformInfo().GetCurNpuArch();
389- bool enable3510Fp32Output = NeedEnable3510Fp32Output(389+ bool enable16In32Out = NeedEnableFp32Output(
390 matmulOpInfo.support_info.self_dtype, matmulOpInfo.support_info.mat2_dtype,390 matmulOpInfo.support_info.self_dtype, matmulOpInfo.support_info.mat2_dtype,
391 matmulOpInfo.support_info.output_dtype, KEEP_DTYPE, bias);391 matmulOpInfo.support_info.output_dtype, KEEP_DTYPE, bias);
392 if (CheckAscendCScenario(selfTransdata, mat2Transdata, bias, matmulOpInfo, adjX1, adjX2)) {392 if (CheckAscendCScenario(selfTransdata, mat2Transdata, bias, matmulOpInfo, adjX1, adjX2)) {
@@ -396,20 +396,13 @@ const aclTensor* GetBatchMatmulOp(
396 int64_t opImplModeEnumV3 = matmulOpInfo.enableHf32 ? 0x40 : (matmulOpInfo.enableForceGrpAccForFp32 ? 0x4 : 0x1);396 int64_t opImplModeEnumV3 = matmulOpInfo.enableHf32 ? 0x40 : (matmulOpInfo.enableForceGrpAccForFp32 ? 0x4 : 0x1);
397 return TransBmm2Mm(397 return TransBmm2Mm(
398 selfTransdata, mat2Transdata, bias, opImplModeEnumV3, adjX1, adjX2, offsetX,398 selfTransdata, mat2Transdata, bias, opImplModeEnumV3, adjX1, adjX2, offsetX,
399- enable3510Fp32Output, executor);399+ enable16In32Out, executor);
400 }400 }
401 OP_LOGI("Hit batch_mat_mul_v3 scenario.");401 OP_LOGI("Hit batch_mat_mul_v3 scenario.");
402- if ((matmulOpInfo.support_info.self_dtype == op::DataType::DT_FLOAT16 ||402+ if (enable16In32Out) {
403- matmulOpInfo.support_info.self_dtype == op::DataType::DT_BF16) &&
404- isBaddbmm &&
405- (npuArch == NpuArch::DAV_2201)) {
406 OP_LOGI("Hit batch_mat_mul_v3 fp16/bf16 in - fp32 out scenario.");403 OP_LOGI("Hit batch_mat_mul_v3 fp16/bf16 in - fp32 out scenario.");
407 bmmOpOut = l0op::BatchMatMulV3NdFp16Bf162Fp32(404 bmmOpOut = l0op::BatchMatMulV3NdFp16Bf162Fp32(
408 selfTransdata, mat2Transdata, bias, nullptr, adjX1, adjX2, offsetX, matmulOpInfo.enableHf32, executor);405 selfTransdata, mat2Transdata, bias, nullptr, adjX1, adjX2, offsetX, matmulOpInfo.enableHf32, executor);
409- } else if (enable3510Fp32Output) {
410- OP_LOGI("Hit batch_mat_mul_v3 fp16/bf16 in - fp32 out 3510 scenario.");
411- bmmOpOut = l0op::BatchMatMulV3NdFp16Bf162Fp32(
412- selfTransdata, mat2Transdata, bias, nullptr, adjX1, adjX2, offsetX, matmulOpInfo.enableHf32, executor);
413 } else {406 } else {
414 OP_LOGI("Hit BatchMatMulV3Nd scenario.");407 OP_LOGI("Hit BatchMatMulV3Nd scenario.");
415 bmmOpOut = l0op::BatchMatMulV3Nd(408 bmmOpOut = l0op::BatchMatMulV3Nd(
@@ -418,7 +411,8 @@ const aclTensor* GetBatchMatmulOp(
418 return bmmOpOut;411 return bmmOpOut;
419 }412 }
420 // 输入是FP16的场景413 // 输入是FP16的场景
421- if (matmulOpInfo.support_info.self_dtype == op::DataType::DT_FLOAT16) {414+ if (matmulOpInfo.support_info.self_dtype == op::DataType::DT_FLOAT16 ||
415+ matmulOpInfo.support_info.self_dtype == op::DataType::DT_BF16) {
422 if (matmulOpInfo.support_info.output_dtype == op::DataType::DT_FLOAT16) {416 if (matmulOpInfo.support_info.output_dtype == op::DataType::DT_FLOAT16) {
423 // 输入是FP16, 输出是FP16的场景417 // 输入是FP16, 输出是FP16的场景
424 if (matmulOpInfo.support_info.self_format == op::Format::FORMAT_ND) {418 if (matmulOpInfo.support_info.self_format == op::Format::FORMAT_ND) {
@@ -443,7 +437,7 @@ const aclTensor* GetBatchMatmulOp(
443 }437 }
444 }438 }
445 } else {439 } else {
446- // 输入是FP32/BF16,输出是FP32/BF16的场景440+ // 输入是FP32,输出是FP32/BF16的场景
447 bmmOpOut = l0op::BatchMatMulNd(441 bmmOpOut = l0op::BatchMatMulNd(
448 selfTransdata, mat2Transdata, bias, nullptr, adjX1, adjX2, offsetX, matmulOpInfo.opImplModeEnum, executor);442 selfTransdata, mat2Transdata, bias, nullptr, adjX1, adjX2, offsetX, matmulOpInfo.opImplModeEnum, executor);
449 }443 }
@@ -820,11 +814,11 @@ bool CheckDtypeValidWeightNz(const aclTensor* self, const aclTensor* mat2, const
820 "batchmatmulweightnz is unsupported in this npu arch");814 "batchmatmulweightnz is unsupported in this npu arch");
821 return false;815 return false;
822 }816 }
823- bool enable3510Fp32Output = NeedEnable3510Fp32Output(817+ bool enable16In32Out = NeedEnableFp32Output(
824 self->GetDataType(), mat2->GetDataType(), out->GetDataType(), cubeMathType);818 self->GetDataType(), mat2->GetDataType(), out->GetDataType(), cubeMathType);
825 OP_CHECK_DTYPE_NOT_SUPPORT(self, DTYPE_SUPPORT_LIST_WEIGHTNZ, return false);819 OP_CHECK_DTYPE_NOT_SUPPORT(self, DTYPE_SUPPORT_LIST_WEIGHTNZ, return false);
826 OP_CHECK_DTYPE_NOT_SUPPORT(mat2, DTYPE_SUPPORT_LIST_WEIGHTNZ, return false);820 OP_CHECK_DTYPE_NOT_SUPPORT(mat2, DTYPE_SUPPORT_LIST_WEIGHTNZ, return false);
827- if (enable3510Fp32Output) {821+ if (enable16In32Out) {
828 OP_CHECK_DTYPE_NOT_SUPPORT(out, DTYPE_SUPPORT_LIST, return false);822 OP_CHECK_DTYPE_NOT_SUPPORT(out, DTYPE_SUPPORT_LIST, return false);
829 } else {823 } else {
830 OP_CHECK_DTYPE_NOT_SUPPORT(out, DTYPE_SUPPORT_LIST_WEIGHTNZ, return false);824 OP_CHECK_DTYPE_NOT_SUPPORT(out, DTYPE_SUPPORT_LIST_WEIGHTNZ, return false);
@@ -909,14 +903,25 @@ const aclTensor* ExecBatchMatmulOpWithBiasAndAttrs(
909 }903 }
910 904 
911 const aclTensor* bmmOpOut = nullptr;905 const aclTensor* bmmOpOut = nullptr;
906+ bool enable16In32Out = NeedEnableFp32Output(
907+ self->GetDataType(), mat2->GetDataType(), out->GetDataType(), cubeMathType, bias);
908+ auto selfCastfp32 = selfTransdata;
909+ auto mat2Castfp32 = mat2Transdata;
912 if (isTransposeMat2Contiguous) {910 if (isTransposeMat2Contiguous) {
913 bmmOpOut = GetBatchMatmulOp(911 bmmOpOut = GetBatchMatmulOp(
914- selfTransdata, mat2Transdata, bias, matmulOpInfo, adjX1, adjX2, 0, executor, isBaddbmm);912+ selfTransdata, mat2Transdata, bias, matmulOpInfo, adjX1, adjX2, 0, executor);
915 } else if (ifKEqual1) {913 } else if (ifKEqual1) {
916- bmmOpOut = l0op::Mul(selfTransdata, mat2Transdata, executor);914+ if (enable16In32Out) {
915+ // 16in32out场景下升精度处理
916+ selfCastfp32 = l0op::Cast(selfTransdata, op::DataType::DT_FLOAT, executor);
917+ CHECK_RET(selfCastfp32 != nullptr, nullptr);
918+ mat2Castfp32 = l0op::Cast(mat2Transdata, op::DataType::DT_FLOAT, executor);
919+ CHECK_RET(mat2Castfp32 != nullptr, nullptr);
920+ }
921+ bmmOpOut = l0op::Mul(selfCastfp32, mat2Castfp32, executor);
917 } else {922 } else {
918 bmmOpOut = GetBatchMatmulOp(923 bmmOpOut = GetBatchMatmulOp(
919- selfTransdata, mat2Transdata, bias, matmulOpInfo, adjX1, adjX2, 0, executor, isBaddbmm);924+ selfTransdata, mat2Transdata, bias, matmulOpInfo, adjX1, adjX2, 0, executor);
920 }925 }
921 926 
922 CHECK_RET(bmmOpOut != nullptr, nullptr);927 CHECK_RET(bmmOpOut != nullptr, nullptr);
@@ -1213,11 +1218,22 @@ const aclTensor* ExecBatchMatmulOpWithBiasAndAttrsV2(
1213 }1218 }
1214 1219 
1215 const aclTensor* bmmOpOut = nullptr;1220 const aclTensor* bmmOpOut = nullptr;
1221+ bool enable16In32Out = NeedEnableFp32Output(
1222+ self->GetDataType(), mat2->GetDataType(), out->GetDataType(), cubeMathType, bias);
1223+ auto selfCastfp32 = selfTransdata;
1224+ auto mat2Castfp32 = mat2Transdata;
1216 if (ifKEqual1) {1225 if (ifKEqual1) {
1217- bmmOpOut = l0op::Mul(selfTransdata, mat2Transdata, executor);1226+ if (enable16In32Out) {
1227+ // 16in32out场景下升精度处理
1228+ selfCastfp32 = l0op::Cast(selfTransdata, op::DataType::DT_FLOAT, executor);
1229+ CHECK_RET(selfCastfp32 != nullptr, nullptr);
1230+ mat2Castfp32 = l0op::Cast(mat2Transdata, op::DataType::DT_FLOAT, executor);
1231+ CHECK_RET(mat2Castfp32 != nullptr, nullptr);
1232+ }
1233+ bmmOpOut = l0op::Mul(selfCastfp32, mat2Castfp32, executor);
1218 } else {1234 } else {
1219 bmmOpOut = GetBatchMatmulOp(1235 bmmOpOut = GetBatchMatmulOp(
1220- selfTransdata, mat2Transdata, contiguousBias, matmulOpInfo, adjX1, adjX2, 0, executor, isBaddbmm);1236+ selfTransdata, mat2Transdata, contiguousBias, matmulOpInfo, adjX1, adjX2, 0, executor);
1221 }1237 }
1222 1238 
1223 CHECK_RET(bmmOpOut != nullptr, nullptr);1239 CHECK_RET(bmmOpOut != nullptr, nullptr);
@@ -134,6 +134,30 @@ bool CheckCubeMathTypeForMm(const op::DataType cubeTensorDtype, int8_t cubeMathT
134 }134 }
135}135}
136 136 
137+bool CheckAddmmTensorShapeNeedBroadcast(const aclTensor* mat1, const aclTensor* mat2, const aclTensor* self)
138+{
139+ uint64_t dimNum = mat1->GetViewShape().GetDimNum();
140+ uint64_t selfDimNum = self->GetViewShape().GetDimNum();
141+ if (dimNum != selfDimNum) {
142+ OP_LOGI("self's dimnum != matmul out's dimnum.");
143+ return true;
144+ }
145+ const op::Shape selfShape = self->GetViewShape();
146+ const op::Shape mat1Shape = mat1->GetViewShape();
147+ const op::Shape mat2Shape = mat2->GetViewShape();
148+ if (dimNum == 3UL) {
149+ OP_CHECK(selfShape[0] == mat1Shape[0] && selfShape[1] == mat1Shape[1] && selfShape[2] == mat2Shape[2],
150+ OP_LOGI("self shape not equal to matmul out shape."),
151+ return true);
152+ } else if (dimNum == 2UL) {
153+ OP_CHECK(selfShape[0] == mat1Shape[0] && selfShape[1] == mat2Shape[1],
154+ OP_LOGI("self shape not equal to matmul out shape."),
155+ return true);
156+ }
157+ return false;
158+}
159+ 
160+ 
137bool CheckCubeMathTypeForAddMm(161bool CheckCubeMathTypeForAddMm(
138 const aclTensor* mat1, const aclTensor* mat2, const aclTensor* self, const aclTensor* out, int8_t cubeMathType)162 const aclTensor* mat1, const aclTensor* mat2, const aclTensor* self, const aclTensor* out, int8_t cubeMathType)
139{163{
@@ -146,43 +170,26 @@ bool CheckCubeMathTypeForAddMm(
146 cubeMathType);170 cubeMathType);
147 return false;171 return false;
148 }172 }
173+ 
174+ auto npuArch = GetCurrentPlatformInfo().GetCurNpuArch();
149 if (cubeMathType != USE_FP32_ADD) {175 if (cubeMathType != USE_FP32_ADD) {
150 return true;176 return true;
151 }177 }
152 // 平台校验178 // 平台校验
153- if (GetCurrentPlatformInfo().GetCurNpuArch() != NpuArch::DAV_2201 &&179+ if (npuArch != NpuArch::DAV_2201 && npuArch != NpuArch::DAV_3510) {
154- GetCurrentPlatformInfo().GetCurNpuArch() != NpuArch::DAV_3510) {180+ OP_LOGE(
155- OP_LOGE(ACLNN_ERR_PARAM_INVALID, "current platform not support cubeMathType = 4: USE_FP32_ADD.");181+ ACLNN_ERR_PARAM_INVALID,
182+ "current platform not support cubeMathType = 4: USE_FP32_ADD.");
156 return false;183 return false;
157 }184 }
158 // A2平台上,当cubeMathType=USE_FP32_ADD时,当前不支持self与mmout broadcast185 // A2平台上,当cubeMathType=USE_FP32_ADD时,当前不支持self与mmout broadcast
159- uint64_t dimNum = mat1->GetViewShape().GetDimNum();186+ if (npuArch == NpuArch::DAV_2201) {
160- uint64_t selfDimNum = self->GetViewShape().GetDimNum();187+ bool needBroadcast = CheckAddmmTensorShapeNeedBroadcast(mat1, mat2, self);
161- if (GetCurrentPlatformInfo().GetCurNpuArch() == NpuArch::DAV_2201) {188+ OP_CHECK(!needBroadcast,
162- if (dimNum != selfDimNum) {189+ OP_LOGE(ACLNN_ERR_PARAM_INVALID,
163- OP_LOGE(190+ "when cubeMathType = 4:USE_FP32_ADD, do not support broadcast between self and mmout."),
164- ACLNN_ERR_PARAM_INVALID,
165- "when cubeMathType = 4:USE_FP32_ADD, do not support self's dimnum != matmul out's dimnum.");
166 return false;191 return false;
167- }192+ );
168- const op::Shape selfShape = self->GetViewShape();
169- const op::Shape mat1Shape = mat1->GetViewShape();
170- const op::Shape mat2Shape = mat2->GetViewShape();
171- if (dimNum == 3UL) {
172- OP_CHECK(
173- selfShape[0] == mat1Shape[0] && selfShape[1] == mat1Shape[1] && selfShape[2] == mat2Shape[2],
174- OP_LOGE(
175- ACLNN_ERR_PARAM_INVALID,
176- "when cubeMathType = 4:USE_FP32_ADD, self shape should equal to matmul out shape."),
177- return false);
178- } else if (dimNum == 2UL) {
179- OP_CHECK(
180- selfShape[0] == mat1Shape[0] && selfShape[1] == mat2Shape[1],
181- OP_LOGE(
182- ACLNN_ERR_PARAM_INVALID,
183- "when cubeMathType = 4:USE_FP32_ADD, self shape should equal to matmul out shape."),
184- return false);
185- }
186 }193 }
187 return true;194 return true;
188}195}
@@ -26,6 +26,9 @@ bool CheckCubeMathType(const op::DataType cubeTensorDtype, int8_t cubeMathType);
26// 校验针对mm算子 tensor的dtype,cubeMathType的值是否符合预期26// 校验针对mm算子 tensor的dtype,cubeMathType的值是否符合预期
27bool CheckCubeMathTypeForMm(const op::DataType cubeTensorDtype, int8_t cubeMathType);27bool CheckCubeMathTypeForMm(const op::DataType cubeTensorDtype, int8_t cubeMathType);
28 28 
29+// 校验针对addmm算子的输入shape检验其是否需要广播,是否可以广播需要预先校验
30+bool CheckAddmmTensorShapeNeedBroadcast(const aclTensor* mat1, const aclTensor* mat2, const aclTensor* self);
31+ 
29// 校验针对Addmm算子的cubeMathType和平台是否符合预期32// 校验针对Addmm算子的cubeMathType和平台是否符合预期
30bool CheckCubeMathTypeForAddMm(const aclTensor* mat1, const aclTensor* mat2, const aclTensor* self,33bool CheckCubeMathTypeForAddMm(const aclTensor* mat1, const aclTensor* mat2, const aclTensor* self,
31 const aclTensor* out, int8_t cubeMathType);34 const aclTensor* out, int8_t cubeMathType);
@@ -323,12 +323,12 @@ static aclnnStatus SetMatmulOpSupportInfo(
323 bool isNdNzIn =323 bool isNdNzIn =
324 self->GetStorageFormat() == Format::FORMAT_ND && mat2->GetStorageFormat() == Format::FORMAT_FRACTAL_NZ;324 self->GetStorageFormat() == Format::FORMAT_ND && mat2->GetStorageFormat() == Format::FORMAT_FRACTAL_NZ;
325 // 支持weightnz16进32出325 // 支持weightnz16进32出
326- bool enable3510Fp32Output = NeedEnable3510Fp32Output(326+ bool enable16In32Out = NeedEnableFp32Output(
327 self->GetDataType(), mat2->GetDataType(), mmOpInfo.support_info.output_dtype, cubeMathType);327 self->GetDataType(), mat2->GetDataType(), mmOpInfo.support_info.output_dtype, cubeMathType);
328 mmOpInfo.support_info.mat2_format = isNdNzIn ? Format::FORMAT_FRACTAL_NZ : mmOpInfo.support_info.mat2_format;328 mmOpInfo.support_info.mat2_format = isNdNzIn ? Format::FORMAT_FRACTAL_NZ : mmOpInfo.support_info.mat2_format;
329 mmOpInfo.support_info.output_dtype =329 mmOpInfo.support_info.output_dtype =
330 isNdNzIn ? mmOpInfo.support_info.mat2_dtype : mmOpInfo.support_info.output_dtype;330 isNdNzIn ? mmOpInfo.support_info.mat2_dtype : mmOpInfo.support_info.output_dtype;
331- if (enable3510Fp32Output) {331+ if (enable16In32Out) {
332 mmOpInfo.support_info.output_dtype = op::DataType::DT_FLOAT;332 mmOpInfo.support_info.output_dtype = op::DataType::DT_FLOAT;
333 }333 }
334 return ACLNN_SUCCESS;334 return ACLNN_SUCCESS;
@@ -465,25 +465,23 @@ static const aclTensor* GetMatMulOp(
465 const aclTensor* x1, const aclTensor* x2, const aclTensor* bias, MmOpInfo& mmOpInfo, const bool transposeX1,465 const aclTensor* x1, const aclTensor* x2, const aclTensor* bias, MmOpInfo& mmOpInfo, const bool transposeX1,
466 const bool transposeX2, const bool offsetX, const int64_t opImplModeEnum, aclOpExecutor* executor)466 const bool transposeX2, const bool offsetX, const int64_t opImplModeEnum, aclOpExecutor* executor)
467{467{
468- bool enableFp32Output = NeedEnable3510Fp32Output(468+ auto npuArch = GetCurrentPlatformInfo().GetCurNpuArch();
469+ bool enable16In32Out = NeedEnableFp32Output(
V
Vvoid_ptr5月19日

[Major] PR 在 A2/A3(DAV_2201)扩展了 fp16/bf16 输入 + fp32 输出的 16in32out 路径,但 aclnnMm / aclnnBatchMatMul 等文档未同步。请更新约束说明(支持的平台、是否支持 bias、与 950 原有行为的差异)。

likedislike
HKFLYE
HKFLYE
5月21日 评论:
469 mmOpInfo.support_info.self_dtype, mmOpInfo.support_info.mat2_dtype, mmOpInfo.support_info.output_dtype,470 mmOpInfo.support_info.self_dtype, mmOpInfo.support_info.mat2_dtype, mmOpInfo.support_info.output_dtype,
470 KEEP_DTYPE, bias);471 KEEP_DTYPE, bias);
472+ bool supportNdNz = mmOpInfo.support_info.self_format == ge::FORMAT_ND &&
473+ mmOpInfo.support_info.mat2_format == ge::FORMAT_FRACTAL_NZ;
474+ bool addmm16In32Out = enable16In32Out && (bias != nullptr || supportNdNz);
471 if (CheckMatmulV3Support(x1, x2, bias, mmOpInfo, transposeX1, transposeX2, opImplModeEnum) ||475 if (CheckMatmulV3Support(x1, x2, bias, mmOpInfo, transposeX1, transposeX2, opImplModeEnum) ||
472- (CheckMMV3NzNzNdSupport(mmOpInfo) && CheckSupportInfoFormatNzNzNd(mmOpInfo))) {476+ (CheckMMV3NzNzNdSupport(mmOpInfo) && CheckSupportInfoFormatNzNzNd(mmOpInfo)) || addmm16In32Out) {
473 OP_LOGI("Hit matmul_v3 scenario.");477 OP_LOGI("Hit matmul_v3 scenario.");
474- 478+
475- if (enableFp32Output) {479+ if ((enable16In32Out && npuArch == NpuArch::DAV_3510)) {
476 const aclTensor* mmOut =480 const aclTensor* mmOut =
477 l0op::MatMulV3NdFp162Fp32(x1, x2, bias, transposeX1, transposeX2, offsetX, opImplModeEnum, executor);481 l0op::MatMulV3NdFp162Fp32(x1, x2, bias, transposeX1, transposeX2, offsetX, opImplModeEnum, executor);
478 return mmOut;482 return mmOut;
479- } else if (483+ } else if (enable16In32Out) {
480- mmOpInfo.support_info.output_dtype == DataType::DT_FLOAT &&484+ if (CheckSupportInfoFormatNzNzNd(mmOpInfo) && bias == nullptr) {
481- ((mmOpInfo.support_info.mat2_dtype == DataType::DT_FLOAT16 &&
482- mmOpInfo.support_info.self_dtype == DataType::DT_FLOAT16) ||
483- (mmOpInfo.support_info.mat2_dtype == DataType::DT_BF16 &&
484- mmOpInfo.support_info.self_dtype == DataType::DT_BF16)) &&
485- bias == nullptr) {
486- if (CheckSupportInfoFormatNzNzNd(mmOpInfo)) {
487 OP_LOGD("check SocVersion, call MatMulV3NzNzNdFp162Fp32.");485 OP_LOGD("check SocVersion, call MatMulV3NzNzNdFp162Fp32.");
488 x1 = l0op::ReFormat(x1, op::Format::FORMAT_FRACTAL_NZ);486 x1 = l0op::ReFormat(x1, op::Format::FORMAT_FRACTAL_NZ);
489 x2 = l0op::ReFormat(x2, op::Format::FORMAT_FRACTAL_NZ);487 x2 = l0op::ReFormat(x2, op::Format::FORMAT_FRACTAL_NZ);
@@ -495,6 +493,7 @@ static const aclTensor* GetMatMulOp(
495 493 
496 const aclTensor* mmOut =494 const aclTensor* mmOut =
497 l0op::MatMulV3NdFp162Fp32(x1, x2, bias, transposeX1, transposeX2, offsetX, opImplModeEnum, executor);495 l0op::MatMulV3NdFp162Fp32(x1, x2, bias, transposeX1, transposeX2, offsetX, opImplModeEnum, executor);
496+ OP_LOGI("hit matmulv3 fp16/bp16 in fp32 out case.");
498 return mmOut;497 return mmOut;
499 }498 }
500 499 
@@ -511,14 +510,9 @@ static const aclTensor* GetMatMulOp(
511 const aclTensor* mmOut =510 const aclTensor* mmOut =
512 l0op::MatMulV3Nd(x1, x2, bias, transposeX1, transposeX2, offsetX, opImplModeEnum, executor);511 l0op::MatMulV3Nd(x1, x2, bias, transposeX1, transposeX2, offsetX, opImplModeEnum, executor);
513 return mmOut;512 return mmOut;
514- } else if (513+ } else if (enable16In32Out && bias == nullptr) {
515- mmOpInfo.support_info.output_dtype == DataType::DT_FLOAT &&
516- ((mmOpInfo.support_info.mat2_dtype == DataType::DT_FLOAT16 &&
517- mmOpInfo.support_info.self_dtype == DataType::DT_FLOAT16) ||
518- (mmOpInfo.support_info.mat2_dtype == DataType::DT_BF16 &&
519- mmOpInfo.support_info.self_dtype == DataType::DT_BF16)) &&
520- bias == nullptr) {
521 // This is Split K Mode; Check if MatMul using Nd in Nd Out514 // This is Split K Mode; Check if MatMul using Nd in Nd Out
515+ OP_LOGI("hit matmulv2 fp16/bp16 in fp32 out case.");
522 const aclTensor* mmOut =516 const aclTensor* mmOut =
523 (mmOpInfo.support_info.self_format == ge::FORMAT_ND &&517 (mmOpInfo.support_info.self_format == ge::FORMAT_ND &&
524 mmOpInfo.support_info.output_format == ge::FORMAT_ND) ?518 mmOpInfo.support_info.output_format == ge::FORMAT_ND) ?
@@ -781,11 +775,30 @@ static aclnnStatus SetMatmulOpSupportFormat(const aclTensor* self, const aclTens
781 775 
782namespace Ops {776namespace Ops {
783namespace NN {777namespace NN {
784-bool NeedEnable3510Fp32Output(778+bool Check16In32OutWithBiasValid(
V
Vvoid_ptr5月19日

[Major] 新增了 Check16In32OutWithBiasValid(校验 16in32out 场景下 bias dtype 需与输入一致或为 FP32),但全仓未见调用。若带 bias 的 fp16/bf16→fp32 场景需要约束,请在 CheckParam / dtype 校验路径接入;若暂不支持带 bias 的 16in32out,建议删除死代码或在文档中明确「bias 必须为 nullptr」。

likedislike
HKFLYE
HKFLYE
5月21日 评论:
779+ op::DataType selfDtype, op::DataType mat2Dtype, op::DataType outputDtype, const aclTensor* bias)
780+{
781+ bool isFp32Output = outputDtype == DataType::DT_FLOAT;
782+ if (!isFp32Output) {
783+ return true;
784+ }
785+ bool isLowPrecisionInput =
786+ (selfDtype == DataType::DT_FLOAT16 && mat2Dtype == DataType::DT_FLOAT16) ||
787+ (selfDtype == DataType::DT_BF16 && mat2Dtype == DataType::DT_BF16);
788+ if (isLowPrecisionInput && bias != nullptr) {
789+ // bias Dtype should match mat Dtype, or be DT_FLOAT
790+ op::DataType biasDataType = bias->GetDataType();
791+ return biasDataType == selfDtype || biasDataType == DataType::DT_FLOAT;
792+ }
793+ return true;
794+}
795+ 
796+bool NeedEnableFp32Output(
785 op::DataType selfDtype, op::DataType mat2Dtype, op::DataType outputDtype, int8_t cubeMathType,797 op::DataType selfDtype, op::DataType mat2Dtype, op::DataType outputDtype, int8_t cubeMathType,
786 const aclTensor* bias, bool isFusion)798 const aclTensor* bias, bool isFusion)
787{799{
788- if (op::GetCurrentPlatformInfo().GetCurNpuArch() != NpuArch::DAV_3510) {800+ auto npuArch = GetCurrentPlatformInfo().GetCurNpuArch();
801+ if (npuArch != NpuArch::DAV_2201 && npuArch != NpuArch::DAV_3510) {
789 return false;802 return false;
790 }803 }
791 bool isSameLowPrecisionInput = (selfDtype == DataType::DT_FLOAT16 && mat2Dtype == DataType::DT_FLOAT16) ||804 bool isSameLowPrecisionInput = (selfDtype == DataType::DT_FLOAT16 && mat2Dtype == DataType::DT_FLOAT16) ||
@@ -793,9 +806,9 @@ bool NeedEnable3510Fp32Output(
793 if (!isSameLowPrecisionInput) {806 if (!isSameLowPrecisionInput) {
794 return false;807 return false;
795 }808 }
796- bool isLowPrecisionFp32Output = outputDtype == DataType::DT_FLOAT;809+ bool isFp32Output = outputDtype == DataType::DT_FLOAT;
797 bool isFusionAddMatmulFp32Output = isFusion && bias == nullptr && cubeMathType == USE_FP32_ADD;810 bool isFusionAddMatmulFp32Output = isFusion && bias == nullptr && cubeMathType == USE_FP32_ADD;
798- return isLowPrecisionFp32Output || isFusionAddMatmulFp32Output;811+ return isFp32Output || isFusionAddMatmulFp32Output;
799}812}
800 813 
801// 非连续条件的shape范围限制814// 非连续条件的shape范围限制
@@ -1017,7 +1030,8 @@ MmOpInfo GetMatmulOpInfo(
1017 mmOpInfo.ori_info.output_dtype = self->GetDataType();1030 mmOpInfo.ori_info.output_dtype = self->GetDataType();
1018 op::DataType outDtype = out == nullptr ? DataType::DT_UNDEFINED : out->GetDataType();1031 op::DataType outDtype = out == nullptr ? DataType::DT_UNDEFINED : out->GetDataType();
1019 if (FP16FP32_KEEP_DTYPE == cubeMathType ||1032 if (FP16FP32_KEEP_DTYPE == cubeMathType ||
1020- NeedEnable3510Fp32Output(self->GetDataType(), mat2->GetDataType(), outDtype, cubeMathType, bias, isFusion)) {1033+ NeedEnableFp32Output(
1034+ self->GetDataType(), mat2->GetDataType(), outDtype, cubeMathType, bias, isFusion)) {
1021 mmOpInfo.ori_info.output_dtype = DataType::DT_FLOAT;1035 mmOpInfo.ori_info.output_dtype = DataType::DT_FLOAT;
1022 }1036 }
1023 mmOpInfo.ori_info.output_format = op::Format::FORMAT_ND;1037 mmOpInfo.ori_info.output_format = op::Format::FORMAT_ND;
@@ -1337,12 +1351,24 @@ const aclTensor* ExecMmOpWithBias(
1337 OP_LOGI("Format of mat2 is mat2TransdataOut [%s].", op::ToString(mat2TransdataOut->GetStorageShape()).GetString());1351 OP_LOGI("Format of mat2 is mat2TransdataOut [%s].", op::ToString(mat2TransdataOut->GetStorageShape()).GetString());
1338 1352 
1339 const aclTensor* mmOut = nullptr;1353 const aclTensor* mmOut = nullptr;
1354+ op::DataType outDtype = out == nullptr ? DataType::DT_UNDEFINED : out->GetDataType();
1355+ bool enable16In32Out = NeedEnableFp32Output(
1356+ self->GetDataType(), mat2->GetDataType(), outDtype, cubeMathType, bias);
1357+ auto selfCastfp32 = selfTransdataOut;
1358+ auto mat2Castfp32 = mat2TransdataOut;
1340 if (isSelfSlice) {1359 if (isSelfSlice) {
1341 mmOut = GetMatMulOp(1360 mmOut = GetMatMulOp(
1342 selfTransdataOut, mat2TransdataOut, contiguousBias, mmOpInfo, mmOpInfo.shapeInfo.transposeX1,1361 selfTransdataOut, mat2TransdataOut, contiguousBias, mmOpInfo, mmOpInfo.shapeInfo.transposeX1,
1343 mmOpInfo.shapeInfo.transposeX2, 0, mmOpInfo.opImplModeEnum, executor);1362 mmOpInfo.shapeInfo.transposeX2, 0, mmOpInfo.opImplModeEnum, executor);
1344 } else if (ifKEqual1) {1363 } else if (ifKEqual1) {
1345- mmOut = l0op::Mul(selfTransdataOut, mat2TransdataOut, executor);1364+ if (enable16In32Out) {
1365+ // 16in32out场景下升精度处理
1366+ selfCastfp32 = l0op::Cast(selfTransdataOut, op::DataType::DT_FLOAT, executor);
1367+ CHECK_RET(selfCastfp32 != nullptr, nullptr);
1368+ mat2Castfp32 = l0op::Cast(mat2TransdataOut, op::DataType::DT_FLOAT, executor);
1369+ CHECK_RET(mat2Castfp32 != nullptr, nullptr);
1370+ }
1371+ mmOut = l0op::Mul(selfCastfp32, mat2Castfp32, executor);
1346 } else {1372 } else {
1347 mmOut = GetMatMulOp(1373 mmOut = GetMatMulOp(
1348 selfTransdataOut, mat2TransdataOut, contiguousBias, mmOpInfo, mmOpInfo.shapeInfo.transposeX1,1374 selfTransdataOut, mat2TransdataOut, contiguousBias, mmOpInfo, mmOpInfo.shapeInfo.transposeX1,
@@ -2003,7 +2029,7 @@ aclnnStatus SetMmSupportDType(MmOpInfo& mmOpInfo, int8_t cubeMathType)
2003 } else if (IsInputSupportFp32() && cubeMathType == USE_FP32_ADD && lowPrecisionInput) {2029 } else if (IsInputSupportFp32() && cubeMathType == USE_FP32_ADD && lowPrecisionInput) {
2004 mmOpInfo.support_info.output_dtype = DataType::DT_FLOAT;2030 mmOpInfo.support_info.output_dtype = DataType::DT_FLOAT;
2005 } else if (2031 } else if (
2006- npuArch == NpuArch::DAV_3510 && lowPrecisionInput && (mmOpInfo.ori_info.output_dtype == DataType::DT_FLOAT)) {2032+ IsInputSupportFp32()&& lowPrecisionInput && (mmOpInfo.ori_info.output_dtype == DataType::DT_FLOAT)) {
2007 mmOpInfo.support_info.output_dtype = DataType::DT_FLOAT;2033 mmOpInfo.support_info.output_dtype = DataType::DT_FLOAT;
2008 }2034 }
2009 return ACLNN_SUCCESS;2035 return ACLNN_SUCCESS;
@@ -2377,12 +2403,12 @@ aclnnStatus Dav2201MatMulRule::PromoteDtype(
2377 // 更新 kernel support outputDtype2403 // 更新 kernel support outputDtype
2378 mmOpInfo.support_info.output_dtype = UpdateOutputDtype(upperDtype, out->GetDataType(), cubeMathType);2404 mmOpInfo.support_info.output_dtype = UpdateOutputDtype(upperDtype, out->GetDataType(), cubeMathType);
2379 2405 
2380- bool enable3510Fp32Output = NeedEnable3510Fp32Output(2406+ bool enable16In32Out = NeedEnableFp32Output(
2381- matA->GetDataType(), matB->GetDataType(), out->GetDataType(), cubeMathType, bias, isFusion);2407+ matA->GetDataType(), matB->GetDataType(), out->GetDataType(), cubeMathType, bias, isFusion);
2382- if (enable3510Fp32Output) {2408+ if (enable16In32Out) {
2383- mmOpInfo.ori_info.output_dtype = op::DataType::DT_FLOAT;2409+ mmOpInfo.ori_info.output_dtype = op::DataType::DT_FLOAT;
2384- mmOpInfo.support_info.output_dtype = op::DataType::DT_FLOAT;2410+ mmOpInfo.support_info.output_dtype = op::DataType::DT_FLOAT;
2385- }2411+ }
2386 2412 
2387 // 更新 biasDtype2413 // 更新 biasDtype
2388 if (bias != nullptr) {2414 if (bias != nullptr) {
@@ -2588,6 +2614,20 @@ op::DataType DefaultMatMulRule::PromoteOutputAndBiasDtype(op::DataType outputDty
2588 return op::DataType::DT_FLOAT16;2614 return op::DataType::DT_FLOAT16;
2589}2615}
2590 2616 
2617+const aclTensor* TransposeAndContiguousMat(const aclTensor* mat, aclOpExecutor* executor)
2618+{
2619+ auto transpose = Ops::NN::IsTransposeLastTwoDims(mat);
2620+ // 转置并转连续
2621+ auto contiguousMat = mat;
2622+ if (transpose) {
2623+ contiguousMat = executor->CreateView(mat, SwapLastTwoDimValue(mat->GetViewShape()), mat->GetViewOffset());
2624+ } else {
2625+ contiguousMat = l0op::Contiguous(mat, executor);
2626+ }
2627+ CHECK_RET(contiguousMat != nullptr, nullptr);
2628+ return contiguousMat;
2629+}
2630+ 
2591const aclTensor* ExecGemmV3WithAlphaBetaOp(const aclTensor* bias,2631const aclTensor* ExecGemmV3WithAlphaBetaOp(const aclTensor* bias,
2592 const aclTensor* self,2632 const aclTensor* self,
2593 const aclTensor* mat2,2633 const aclTensor* mat2,
@@ -2601,25 +2641,13 @@ const aclTensor* ExecGemmV3WithAlphaBetaOp(const aclTensor* bias,
2601 auto reformatSelf = self;2641 auto reformatSelf = self;
2602 reformatSelf = l0op::ReFormat(self, op::Format::FORMAT_ND);2642 reformatSelf = l0op::ReFormat(self, op::Format::FORMAT_ND);
2603 // 左输入非连续转连续2643 // 左输入非连续转连续
2604- auto contiguousSelf = reformatSelf;2644+ auto contiguousSelf = TransposeAndContiguousMat(reformatSelf, executor);
2605- if (transposeSelf) {
2606- contiguousSelf = executor->CreateView(
2607- reformatSelf, SwapLastTwoDimValue(reformatSelf->GetViewShape()), reformatSelf->GetViewOffset());
2608- } else {
2609- contiguousSelf = l0op::Contiguous(reformatSelf, executor);
2610- }
2611 CHECK_RET(contiguousSelf != nullptr, nullptr);2645 CHECK_RET(contiguousSelf != nullptr, nullptr);
2612 // reformat, 转成ND2646 // reformat, 转成ND
2613 auto reformatMat2 = mat2;2647 auto reformatMat2 = mat2;
2614 reformatMat2 = l0op::ReFormat(mat2, op::Format::FORMAT_ND);2648 reformatMat2 = l0op::ReFormat(mat2, op::Format::FORMAT_ND);
2615 // 右输入非连续转连续2649 // 右输入非连续转连续
2616- auto contiguousMat2 = reformatMat2;2650+ auto contiguousMat2 = TransposeAndContiguousMat(reformatMat2, executor);;
2617- if (transposeMat2) {
2618- contiguousMat2 = executor->CreateView(
2619- reformatMat2, SwapLastTwoDimValue(reformatMat2->GetViewShape()), reformatMat2->GetViewOffset());
2620- } else {
2621- contiguousMat2 = l0op::Contiguous(reformatMat2, executor);
2622- }
2623 CHECK_RET(contiguousMat2 != nullptr, nullptr);2651 CHECK_RET(contiguousMat2 != nullptr, nullptr);
2624 2652 
2625 // bias非连续转连续2653 // bias非连续转连续
@@ -101,7 +101,10 @@ bool IsTransposeLastTwoDims(const aclTensor* tensor);
101bool CheckGemmV3Support(const aclTensor* mat1, const aclTensor* mat2, MmOpInfo& mmOpInfo,101bool CheckGemmV3Support(const aclTensor* mat1, const aclTensor* mat2, MmOpInfo& mmOpInfo,
102 int8_t cubeMathType);102 int8_t cubeMathType);
103 103 
104-bool NeedEnable3510Fp32Output(104+bool Check16In32OutWithBiasValid(
105+ op::DataType selfDtype, op::DataType mat2Dtype, op::DataType outputDtype, const aclTensor* bias);
106+ 
107+bool NeedEnableFp32Output(
105 op::DataType selfDtype, op::DataType mat2Dtype, op::DataType outputDtype, int8_t cubeMathType,108 op::DataType selfDtype, op::DataType mat2Dtype, op::DataType outputDtype, int8_t cubeMathType,
106 const aclTensor* bias = nullptr, bool isFusion = false);109 const aclTensor* bias = nullptr, bool isFusion = false);
107 110 
@@ -803,8 +803,88 @@
803 ]803 ]
804 },804 },
805 {805 {
806- "bin_filename": "MatMulV3_ND_ND_ND_ND_FP16_FP16_FP32_FP32",806+ "bin_filename": "MatMulV3_ND_ND_ND_ND_FP16_FP16_FP16_FP32",
807 "simplified_key": "diy,2/2/2/2/1/1/1/0",807 "simplified_key": "diy,2/2/2/2/1/1/1/0",
808+ "inputs": [
809+ {
810+ "name": "x1",
811+ "index": 0,
812+ "dtype": "float16",
813+ "format": "ND",
814+ "paramType": "required",
815+ "shape": [
816+ -2
817+ ]
818+ },
819+ {
820+ "name": "x2",
821+ "index": 1,
822+ "dtype": "float16",
823+ "format": "ND",
824+ "paramType": "required",
825+ "shape": [
826+ -2
827+ ]
828+ },
829+ {
830+ "name": "bias",
831+ "index": 2,
832+ "dtype": "float16",
833+ "format": "ND",
834+ "paramType": "optional",
835+ "shape": [
836+ -2
837+ ]
838+ },
839+ {
840+ "name": "offset_w",
841+ "index": 3,
842+ "dtype": "int8",
843+ "format": "ND",
844+ "paramType": "optional",
845+ "shape": [
846+ -2
847+ ]
848+ }
849+ ],
850+ "outputs": [
851+ {
852+ "name": "y",
853+ "index": 0,
854+ "dtype": "float32",
855+ "format": "ND",
856+ "paramType": "required",
857+ "shape": [
858+ -2
859+ ]
860+ }
861+ ],
862+ "attrs": [
863+ {
864+ "name": "transpose_x1",
865+ "dtype": "bool",
866+ "value": false
867+ },
868+ {
869+ "name": "transpose_x2",
870+ "dtype": "bool",
871+ "value": false
872+ },
873+ {
874+ "name": "offset_x",
875+ "dtype": "int",
876+ "value": 0
877+ },
878+ {
879+ "name": "opImplMode",
880+ "dtype": "int",
881+ "value": 1
882+ }
883+ ]
884+ },
885+ {
886+ "bin_filename": "MatMulV3_ND_ND_ND_ND_FP16_FP16_FP32_FP32",
887+ "simplified_key": "diy,2/2/2/2/1/1/0/0",
808 "inputs": [888 "inputs": [
809 {889 {
810 "name": "x1",890 "name": "x1",
@@ -1681,6 +1761,326 @@
1681 "value": 11761 "value": 1
1682 }1762 }
1683 ]1763 ]
1764+ },
1765+ {
1766+ "bin_filename": "MatMulV3_ND_NZ_ND_ND_FP16_FP16_FP32_FP32",
1767+ "simplified_key": "diy,2/29/2/2/1/1/0/0",
1768+ "inputs": [
1769+ {
1770+ "name": "x1",
1771+ "index": 0,
1772+ "dtype": "float16",
1773+ "format": "ND",
1774+ "paramType": "required",
1775+ "shape": [
1776+ -2
1777+ ]
1778+ },
1779+ {
1780+ "name": "x2",
1781+ "index": 1,
1782+ "dtype": "float16",
1783+ "format": "FRACTAL_NZ",
1784+ "paramType": "required",
1785+ "shape": [
1786+ -2
1787+ ]
1788+ },
1789+ {
1790+ "name": "bias",
1791+ "index": 2,
1792+ "dtype": "float32",
1793+ "format": "ND",
1794+ "paramType": "optional",
1795+ "shape": [
1796+ -2
1797+ ]
1798+ },
1799+ {
1800+ "name": "offset_w",
1801+ "index": 3,
1802+ "dtype": "int8",
1803+ "format": "ND",
1804+ "paramType": "optional",
1805+ "shape": [
1806+ -2
1807+ ]
1808+ }
1809+ ],
1810+ "outputs": [
1811+ {
1812+ "name": "y",
1813+ "index": 0,
1814+ "dtype": "float32",
1815+ "format": "ND",
1816+ "paramType": "required",
1817+ "shape": [
1818+ -2
1819+ ]
1820+ }
1821+ ],
1822+ "attrs": [
1823+ {
1824+ "name": "transpose_x1",
1825+ "dtype": "bool",
1826+ "value": false
1827+ },
1828+ {
1829+ "name": "transpose_x2",
1830+ "dtype": "bool",
1831+ "value": false
1832+ },
1833+ {
1834+ "name": "offset_x",
1835+ "dtype": "int",
1836+ "value": 0
1837+ },
1838+ {
1839+ "name": "opImplMode",
1840+ "dtype": "int",
1841+ "value": 1
1842+ }
1843+ ]
1844+ },
1845+ {
1846+ "bin_filename": "MatMulV3_ND_NZ_ND_ND_BF16_BF16_FP32_FP32",
1847+ "simplified_key": "diy,2/29/2/2/27/27/0/0",
1848+ "inputs": [
1849+ {
1850+ "name": "x1",
1851+ "index": 0,
1852+ "dtype": "bfloat16",
1853+ "format": "ND",
1854+ "paramType": "required",
1855+ "shape": [
1856+ -2
1857+ ]
1858+ },
1859+ {
1860+ "name": "x2",
1861+ "index": 1,
1862+ "dtype": "bfloat16",
1863+ "format": "FRACTAL_NZ",
1864+ "paramType": "required",
1865+ "shape": [
1866+ -2
1867+ ]
1868+ },
1869+ {
1870+ "name": "bias",
1871+ "index": 2,
1872+ "dtype": "float32",
1873+ "format": "ND",
1874+ "paramType": "optional",
1875+ "shape": [
1876+ -2
1877+ ]
1878+ },
1879+ {
1880+ "name": "offset_w",
1881+ "index": 3,
1882+ "dtype": "int8",
1883+ "format": "ND",
1884+ "paramType": "optional",
1885+ "shape": [
1886+ -2
1887+ ]
1888+ }
1889+ ],
1890+ "outputs": [
1891+ {
1892+ "name": "y",
1893+ "index": 0,
1894+ "dtype": "float32",
1895+ "format": "ND",
1896+ "paramType": "required",
1897+ "shape": [
1898+ -2
1899+ ]
1900+ }
1901+ ],
1902+ "attrs": [
1903+ {
1904+ "name": "transpose_x1",
1905+ "dtype": "bool",
1906+ "value": false
1907+ },
1908+ {
1909+ "name": "transpose_x2",
1910+ "dtype": "bool",
1911+ "value": false
1912+ },
1913+ {
1914+ "name": "offset_x",
1915+ "dtype": "int",
1916+ "value": 0
1917+ },
1918+ {
1919+ "name": "opImplMode",
1920+ "dtype": "int",
1921+ "value": 1
1922+ }
1923+ ]
1924+ },
1925+ {
1926+ "bin_filename": "MatMulV3_ND_NZ_ND_ND_FP16_FP16_FP16_FP32",
1927+ "simplified_key": "diy,2/29/2/2/1/1/1/0",
1928+ "inputs": [
1929+ {
1930+ "name": "x1",
1931+ "index": 0,
1932+ "dtype": "float16",
1933+ "format": "ND",
1934+ "paramType": "required",
1935+ "shape": [
1936+ -2
1937+ ]
1938+ },
1939+ {
1940+ "name": "x2",
1941+ "index": 1,
1942+ "dtype": "float16",
1943+ "format": "FRACTAL_NZ",
1944+ "paramType": "required",
1945+ "shape": [
1946+ -2
1947+ ]
1948+ },
1949+ {
1950+ "name": "bias",
1951+ "index": 2,
1952+ "dtype": "float16",
1953+ "format": "ND",
1954+ "paramType": "optional",
1955+ "shape": [
1956+ -2
1957+ ]
1958+ },
1959+ {
1960+ "name": "offset_w",
1961+ "index": 3,
1962+ "dtype": "int8",
1963+ "format": "ND",
1964+ "paramType": "optional",
1965+ "shape": [
1966+ -2
1967+ ]
1968+ }
1969+ ],
1970+ "outputs": [
1971+ {
1972+ "name": "y",
1973+ "index": 0,
1974+ "dtype": "float32",
1975+ "format": "ND",
1976+ "paramType": "required",
1977+ "shape": [
1978+ -2
1979+ ]
1980+ }
1981+ ],
1982+ "attrs": [
1983+ {
1984+ "name": "transpose_x1",
1985+ "dtype": "bool",
1986+ "value": false
1987+ },
1988+ {
1989+ "name": "transpose_x2",
1990+ "dtype": "bool",
1991+ "value": false
1992+ },
1993+ {
1994+ "name": "offset_x",
1995+ "dtype": "int",
1996+ "value": 0
1997+ },
1998+ {
1999+ "name": "opImplMode",
2000+ "dtype": "int",
2001+ "value": 1
2002+ }
2003+ ]
2004+ },
2005+ {
2006+ "bin_filename": "MatMulV3_ND_NZ_ND_ND_BF16_BF16_BF16_FP32",
2007+ "simplified_key": "diy,2/29/2/2/27/27/27/0",
2008+ "inputs": [
2009+ {
2010+ "name": "x1",
2011+ "index": 0,
2012+ "dtype": "bfloat16",
2013+ "format": "ND",
2014+ "paramType": "required",
2015+ "shape": [
2016+ -2
2017+ ]
2018+ },
2019+ {
2020+ "name": "x2",
2021+ "index": 1,
2022+ "dtype": "bfloat16",
2023+ "format": "FRACTAL_NZ",
2024+ "paramType": "required",
2025+ "shape": [
2026+ -2
2027+ ]
2028+ },
2029+ {
2030+ "name": "bias",
2031+ "index": 2,
2032+ "dtype": "bfloat16",
2033+ "format": "ND",
2034+ "paramType": "optional",
2035+ "shape": [
2036+ -2
2037+ ]
2038+ },
2039+ {
2040+ "name": "offset_w",
2041+ "index": 3,
2042+ "dtype": "int8",
2043+ "format": "ND",
2044+ "paramType": "optional",
2045+ "shape": [
2046+ -2
2047+ ]
2048+ }
2049+ ],
2050+ "outputs": [
2051+ {
2052+ "name": "y",
2053+ "index": 0,
2054+ "dtype": "float32",
2055+ "format": "ND",
2056+ "paramType": "required",
2057+ "shape": [
2058+ -2
2059+ ]
2060+ }
2061+ ],
2062+ "attrs": [
2063+ {
2064+ "name": "transpose_x1",
2065+ "dtype": "bool",
2066+ "value": false
2067+ },
2068+ {
2069+ "name": "transpose_x2",
2070+ "dtype": "bool",
2071+ "value": false
2072+ },
2073+ {
2074+ "name": "offset_x",
2075+ "dtype": "int",
2076+ "value": 0
2077+ },
2078+ {
2079+ "name": "opImplMode",
2080+ "dtype": "int",
2081+ "value": 1
2082+ }
2083+ ]
1684 }2084 }
1685 ]2085 ]
1686}2086}
@@ -803,8 +803,88 @@
803 ]803 ]
804 },804 },
805 {805 {
806- "bin_filename": "MatMulV3_ND_ND_ND_ND_FP16_FP16_FP32_FP32",806+ "bin_filename": "MatMulV3_ND_ND_ND_ND_FP16_FP16_FP16_FP32",
807 "simplified_key": "diy,2/2/2/2/1/1/1/0",807 "simplified_key": "diy,2/2/2/2/1/1/1/0",
808+ "inputs": [
809+ {
810+ "name": "x1",
811+ "index": 0,
812+ "dtype": "float16",
813+ "format": "ND",
814+ "paramType": "required",
815+ "shape": [
816+ -2
817+ ]
818+ },
819+ {
820+ "name": "x2",
821+ "index": 1,
822+ "dtype": "float16",
823+ "format": "ND",
824+ "paramType": "required",
825+ "shape": [
826+ -2
827+ ]
828+ },
829+ {
830+ "name": "bias",
831+ "index": 2,
832+ "dtype": "float16",
833+ "format": "ND",
834+ "paramType": "optional",
835+ "shape": [
836+ -2
837+ ]
838+ },
839+ {
840+ "name": "offset_w",
841+ "index": 3,
842+ "dtype": "int8",
843+ "format": "ND",
844+ "paramType": "optional",
845+ "shape": [
846+ -2
847+ ]
848+ }
849+ ],
850+ "outputs": [
851+ {
852+ "name": "y",
853+ "index": 0,
854+ "dtype": "float32",
855+ "format": "ND",
856+ "paramType": "required",
857+ "shape": [
858+ -2
859+ ]
860+ }
861+ ],
862+ "attrs": [
863+ {
864+ "name": "transpose_x1",
865+ "dtype": "bool",
866+ "value": false
867+ },
868+ {
869+ "name": "transpose_x2",
870+ "dtype": "bool",
871+ "value": false
872+ },
873+ {
874+ "name": "offset_x",
875+ "dtype": "int",
876+ "value": 0
877+ },
878+ {
879+ "name": "opImplMode",
880+ "dtype": "int",
881+ "value": 1
882+ }
883+ ]
884+ },
885+ {
886+ "bin_filename": "MatMulV3_ND_ND_ND_ND_FP16_FP16_FP32_FP32",
887+ "simplified_key": "diy,2/2/2/2/1/1/0/0",
808 "inputs": [888 "inputs": [
809 {889 {
810 "name": "x1",890 "name": "x1",
@@ -1681,6 +1761,326 @@
1681 "value": 11761 "value": 1
1682 }1762 }
1683 ]1763 ]
1764+ },
1765+ {
1766+ "bin_filename": "MatMulV3_ND_NZ_ND_ND_FP16_FP16_FP32_FP32",
1767+ "simplified_key": "diy,2/29/2/2/1/1/0/0",
1768+ "inputs": [
1769+ {
1770+ "name": "x1",
1771+ "index": 0,
1772+ "dtype": "float16",
1773+ "format": "ND",
1774+ "paramType": "required",
1775+ "shape": [
1776+ -2
1777+ ]
1778+ },
1779+ {
1780+ "name": "x2",
1781+ "index": 1,
1782+ "dtype": "float16",
1783+ "format": "FRACTAL_NZ",
1784+ "paramType": "required",
1785+ "shape": [
1786+ -2
1787+ ]
1788+ },
1789+ {
1790+ "name": "bias",
1791+ "index": 2,
1792+ "dtype": "float32",
1793+ "format": "ND",
1794+ "paramType": "optional",
1795+ "shape": [
1796+ -2
1797+ ]
1798+ },
1799+ {
1800+ "name": "offset_w",
1801+ "index": 3,
1802+ "dtype": "int8",
1803+ "format": "ND",
1804+ "paramType": "optional",
1805+ "shape": [
1806+ -2
1807+ ]
1808+ }
1809+ ],
1810+ "outputs": [
1811+ {
1812+ "name": "y",
1813+ "index": 0,
1814+ "dtype": "float32",
1815+ "format": "ND",
1816+ "paramType": "required",
1817+ "shape": [
1818+ -2
1819+ ]
1820+ }
1821+ ],
1822+ "attrs": [
1823+ {
1824+ "name": "transpose_x1",
1825+ "dtype": "bool",
1826+ "value": false
1827+ },
1828+ {
1829+ "name": "transpose_x2",
1830+ "dtype": "bool",
1831+ "value": false
1832+ },
1833+ {
1834+ "name": "offset_x",
1835+ "dtype": "int",
1836+ "value": 0
1837+ },
1838+ {
1839+ "name": "opImplMode",
1840+ "dtype": "int",
1841+ "value": 1
1842+ }
1843+ ]
1844+ },
1845+ {
1846+ "bin_filename": "MatMulV3_ND_NZ_ND_ND_BF16_BF16_FP32_FP32",
1847+ "simplified_key": "diy,2/29/2/2/27/27/0/0",
1848+ "inputs": [
1849+ {
1850+ "name": "x1",
1851+ "index": 0,
1852+ "dtype": "bfloat16",
1853+ "format": "ND",
1854+ "paramType": "required",
1855+ "shape": [
1856+ -2
1857+ ]
1858+ },
1859+ {
1860+ "name": "x2",
1861+ "index": 1,
1862+ "dtype": "bfloat16",
1863+ "format": "FRACTAL_NZ",
1864+ "paramType": "required",
1865+ "shape": [
1866+ -2
1867+ ]
1868+ },
1869+ {
1870+ "name": "bias",
1871+ "index": 2,
1872+ "dtype": "float32",
1873+ "format": "ND",
1874+ "paramType": "optional",
1875+ "shape": [
1876+ -2
1877+ ]
1878+ },
1879+ {
1880+ "name": "offset_w",
1881+ "index": 3,
1882+ "dtype": "int8",
1883+ "format": "ND",
1884+ "paramType": "optional",
1885+ "shape": [
1886+ -2
1887+ ]
1888+ }
1889+ ],
1890+ "outputs": [
1891+ {
1892+ "name": "y",
1893+ "index": 0,
1894+ "dtype": "float32",
1895+ "format": "ND",
1896+ "paramType": "required",
1897+ "shape": [
1898+ -2
1899+ ]
1900+ }
1901+ ],
1902+ "attrs": [
1903+ {
1904+ "name": "transpose_x1",
1905+ "dtype": "bool",
1906+ "value": false
1907+ },
1908+ {
1909+ "name": "transpose_x2",
1910+ "dtype": "bool",
1911+ "value": false
1912+ },
1913+ {
1914+ "name": "offset_x",
1915+ "dtype": "int",
1916+ "value": 0
1917+ },
1918+ {
1919+ "name": "opImplMode",
1920+ "dtype": "int",
1921+ "value": 1
1922+ }
1923+ ]
1924+ },
1925+ {
1926+ "bin_filename": "MatMulV3_ND_NZ_ND_ND_FP16_FP16_FP16_FP32",
1927+ "simplified_key": "diy,2/29/2/2/1/1/1/0",
1928+ "inputs": [
1929+ {
1930+ "name": "x1",
1931+ "index": 0,
1932+ "dtype": "float16",
1933+ "format": "ND",
1934+ "paramType": "required",
1935+ "shape": [
1936+ -2
1937+ ]
1938+ },
1939+ {
1940+ "name": "x2",
1941+ "index": 1,
1942+ "dtype": "float16",
1943+ "format": "FRACTAL_NZ",
1944+ "paramType": "required",
1945+ "shape": [
1946+ -2
1947+ ]
1948+ },
1949+ {
1950+ "name": "bias",
1951+ "index": 2,
1952+ "dtype": "float16",
1953+ "format": "ND",
1954+ "paramType": "optional",
1955+ "shape": [
1956+ -2
1957+ ]
1958+ },
1959+ {
1960+ "name": "offset_w",
1961+ "index": 3,
1962+ "dtype": "int8",
1963+ "format": "ND",
1964+ "paramType": "optional",
1965+ "shape": [
1966+ -2
1967+ ]
1968+ }
1969+ ],
1970+ "outputs": [
1971+ {
1972+ "name": "y",
1973+ "index": 0,
1974+ "dtype": "float32",
1975+ "format": "ND",
1976+ "paramType": "required",
1977+ "shape": [
1978+ -2
1979+ ]
1980+ }
1981+ ],
1982+ "attrs": [
1983+ {
1984+ "name": "transpose_x1",
1985+ "dtype": "bool",
1986+ "value": false
1987+ },
1988+ {
1989+ "name": "transpose_x2",
1990+ "dtype": "bool",
1991+ "value": false
1992+ },
1993+ {
1994+ "name": "offset_x",
1995+ "dtype": "int",
1996+ "value": 0
1997+ },
1998+ {
1999+ "name": "opImplMode",
2000+ "dtype": "int",
2001+ "value": 1
2002+ }
2003+ ]
2004+ },
2005+ {
2006+ "bin_filename": "MatMulV3_ND_NZ_ND_ND_BF16_BF16_BF16_FP32",
2007+ "simplified_key": "diy,2/29/2/2/27/27/27/0",
2008+ "inputs": [
2009+ {
2010+ "name": "x1",
2011+ "index": 0,
2012+ "dtype": "bfloat16",
2013+ "format": "ND",
2014+ "paramType": "required",
2015+ "shape": [
2016+ -2
2017+ ]
2018+ },
2019+ {
2020+ "name": "x2",
2021+ "index": 1,
2022+ "dtype": "bfloat16",
2023+ "format": "FRACTAL_NZ",
2024+ "paramType": "required",
2025+ "shape": [
2026+ -2
2027+ ]
2028+ },
2029+ {
2030+ "name": "bias",
2031+ "index": 2,
2032+ "dtype": "bfloat16",
2033+ "format": "ND",
2034+ "paramType": "optional",
2035+ "shape": [
2036+ -2
2037+ ]
2038+ },
2039+ {
2040+ "name": "offset_w",
2041+ "index": 3,
2042+ "dtype": "int8",
2043+ "format": "ND",
2044+ "paramType": "optional",
2045+ "shape": [
2046+ -2
2047+ ]
2048+ }
2049+ ],
2050+ "outputs": [
2051+ {
2052+ "name": "y",
2053+ "index": 0,
2054+ "dtype": "float32",
2055+ "format": "ND",
2056+ "paramType": "required",
2057+ "shape": [
2058+ -2
2059+ ]
2060+ }
2061+ ],
2062+ "attrs": [
2063+ {
2064+ "name": "transpose_x1",
2065+ "dtype": "bool",
2066+ "value": false
2067+ },
2068+ {
2069+ "name": "transpose_x2",
2070+ "dtype": "bool",
2071+ "value": false
2072+ },
2073+ {
2074+ "name": "offset_x",
2075+ "dtype": "int",
2076+ "value": 0
2077+ },
2078+ {
2079+ "name": "opImplMode",
2080+ "dtype": "int",
2081+ "value": 1
2082+ }
2083+ ]
1684 }2084 }
1685 ]2085 ]
1686}2086}
@@ -1344,3 +1344,39 @@ TEST_F(l2_addmm_test, addmm_inplace_310_FP32_FP16_FP16FP32_KEEP_DTYPE)
1344 aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size);1344 aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size);
1345 EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID);1345 EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID);
1346}1346}
1347+ 
1348+TEST_F(l2_addmm_test, addmm_910b_fp16_fp16_use_fp32_add_with_self_need_broadcast)
1349+{
1350+ op::SocVersionManager versionManager(op::SocVersion::ASCEND910B);
1351+ auto self = TensorDesc({16}, ACL_FLOAT16, ACL_FORMAT_ND).ValueRange(0, 2);
1352+ auto mat1 = TensorDesc({16, 16}, ACL_FLOAT16, ACL_FORMAT_ND).ValueRange(0, 2);
1353+ auto mat2 = TensorDesc({16, 16}, ACL_FLOAT16, ACL_FORMAT_ND).ValueRange(0, 2);
1354+ auto out = TensorDesc({16, 16}, ACL_FLOAT16, ACL_FORMAT_ND).Precision(0.005, 0.005);
1355+ auto beta = ScalarDesc(1.0f);
1356+ auto alpha = ScalarDesc(1.0f);
1357+ int8_t cubeMathType = USE_FP32_ADD;
1358+ 
1359+ auto ut = OP_API_UT(aclnnAddmm, INPUT(self, mat1, mat2, beta, alpha), OUTPUT(out), cubeMathType);
1360+ 
1361+ uint64_t workspace_size = 0;
1362+ aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size);
1363+ EXPECT_NE(aclRet, ACL_SUCCESS);
1364+}
1365+ 
1366+TEST_F(l2_addmm_test, addmm_910b_bf16_bf16_use_fp32_add_with_self_need_broadcast)
1367+{
1368+ op::SocVersionManager versionManager(op::SocVersion::ASCEND910B);
1369+ auto self = TensorDesc({16}, ACL_BF16, ACL_FORMAT_ND).ValueRange(0, 2);
1370+ auto mat1 = TensorDesc({16, 16}, ACL_BF16, ACL_FORMAT_ND).ValueRange(0, 2);
1371+ auto mat2 = TensorDesc({16, 16}, ACL_BF16, ACL_FORMAT_ND).ValueRange(0, 2);
1372+ auto out = TensorDesc({16, 16}, ACL_FLOAT16, ACL_FORMAT_ND).Precision(0.005, 0.005);
1373+ auto beta = ScalarDesc(1.0f);
1374+ auto alpha = ScalarDesc(1.0f);
1375+ int8_t cubeMathType = USE_FP32_ADD;
1376+ 
1377+ auto ut = OP_API_UT(aclnnAddmm, INPUT(self, mat1, mat2, beta, alpha), OUTPUT(out), cubeMathType);
1378+ 
1379+ uint64_t workspace_size = 0;
1380+ aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size);
1381+ EXPECT_NE(aclRet, ACL_SUCCESS);
1382+}
@@ -1230,4 +1230,48 @@ TEST_F(l2_mm_test, mm_FP32_FP16_FP16FP32_KEEP_DTYPE)
1230 uint64_t workspace_size = 0;1230 uint64_t workspace_size = 0;
1231 aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size);1231 aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size);
1232 EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID);1232 EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID);
1233+}
1234+ 
1235+TEST_F(l2_mm_test, mm_V3_FP16_FP16_FP32_KEEP_DTYPE)
1236+{
1237+ TensorDesc a_desc = TensorDesc({20480, 6656}, ACL_FLOAT16, ACL_FORMAT_ND).ValueRange(0, 2);
1238+ TensorDesc b_desc = TensorDesc({6656, 8192}, ACL_FLOAT16, ACL_FORMAT_ND).ValueRange(0, 2);
1239+ TensorDesc out_desc = TensorDesc({20480, 8192}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.005, 0.005);
1240+ cout << "-----------Testing MMV3 trans_x1 = false trans_x2 = false ----------" << endl;
1241+ MmCommonTest(a_desc, b_desc, out_desc, ACL_SUCCESS);
1242+}
1243+ 
1244+TEST_F(l2_mm_test, mm_V2_FP16_FP16_FP32_KEEP_DTYPE)
1245+{
1246+ auto tensor_1_desc = TensorDesc({256, 2048}, ACL_FLOAT16, ACL_FORMAT_ND).ValueRange(-2, 2);
1247+ auto tensor_2_desc = TensorDesc({2048, 1024}, ACL_FLOAT16, ACL_FORMAT_ND).ValueRange(-2, 2);
1248+ auto out_tensor_desc = TensorDesc({256, 1024}, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(-2, 2).Precision(0.005, 0.005);
1249+ int8_t cube_math_type = 0;
1250+ auto ut = OP_API_UT(aclnnMm, INPUT(tensor_1_desc, tensor_2_desc), OUTPUT(out_tensor_desc), cube_math_type);
1251+ 
1252+ uint64_t workspace_size = 0;
1253+ aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size);
1254+ EXPECT_EQ(aclRet, ACL_SUCCESS);
1255+}
1256+ 
1257+TEST_F(l2_mm_test, mm_V3_BF16_BF16__FP32_KEEP_DTYPE)
1258+{
1259+ TensorDesc a_desc = TensorDesc({20480, 6656}, ACL_BF16, ACL_FORMAT_ND).ValueRange(0, 2);
1260+ TensorDesc b_desc = TensorDesc({6656, 8192}, ACL_BF16, ACL_FORMAT_ND).ValueRange(0, 2);
1261+ TensorDesc out_desc = TensorDesc({20480, 8192}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.005, 0.005);
1262+ cout << "-----------Testing MMV3 trans_x1 = false trans_x2 = false ----------" << endl;
1263+ MmCommonTest(a_desc, b_desc, out_desc, ACL_SUCCESS);
1264+}
1265+ 
1266+TEST_F(l2_mm_test, mm_V2_BF16_BF16_FP32_KEEP_DTYPE)
1267+{
1268+ auto tensor_1_desc = TensorDesc({256, 2048}, ACL_BF16, ACL_FORMAT_ND).ValueRange(-2, 2);
1269+ auto tensor_2_desc = TensorDesc({2048, 1024}, ACL_BF16, ACL_FORMAT_ND).ValueRange(-2, 2);
1270+ auto out_tensor_desc = TensorDesc({256, 1024}, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(-2, 2).Precision(0.005, 0.005);
1271+ int8_t cube_math_type = 0;
1272+ auto ut = OP_API_UT(aclnnMm, INPUT(tensor_1_desc, tensor_2_desc), OUTPUT(out_tensor_desc), cube_math_type);
1273+ 
1274+ uint64_t workspace_size = 0;
1275+ aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size);
1276+ EXPECT_EQ(aclRet, ACL_SUCCESS);
1233}1277}