@@ -14,6 +14,9 @@ Module Name:
1414 operation (SGEMM).
1515
1616--*/
17+ #ifdef MLAS_USE_SVE
18+ #include " sve/mlasi_sve.h"
19+ #endif
1720
1821#include " mlasi.h"
1922
@@ -259,8 +262,15 @@ Return Value:
259262
260263 do {
261264
262- #if defined(MLAS_NEON_INTRINSICS)
263- vst4q_f32 (D, vld4q_f32 (b));
265+ #if defined(MLAS_USE_SVE) && defined(MLAS_NEON_INTRINSICS)
266+ if (MLAS_CPUIDINFO::GetCPUIDInfo ().HasArmSve ()) {
267+ SVE_LOAD_STORE (D, b);
268+ }
269+ else {
270+ vst4q_f32 (D, vld4q_f32 (b));
271+ }
272+ #elif defined(MLAS_NEON_INTRINSICS)
273+ vst4q_f32 (D, vld4q_f32 (b));
264274#else
265275 MLAS_FLOAT32X4 t0 = MlasLoadFloat32x4 (&b[0 ]);
266276 MLAS_FLOAT32X4 t1 = MlasLoadFloat32x4 (&b[4 ]);
@@ -303,8 +313,14 @@ Return Value:
303313 float * d = D;
304314 const float * b = B;
305315
306- #if defined(MLAS_NEON_INTRINSICS)
307- vst4q_f32 (d, ZeroFloat32x4x4);
316+ #if defined(MLAS_USE_SVE) && defined(MLAS_NEON_INTRINSICS)
317+ if (MLAS_CPUIDINFO::GetCPUIDInfo ().HasArmSve ()) {
318+ SVE_ZERO_INITIALIZE (d);
319+ } else {
320+ vst4q_f32 (d, ZeroFloat32x4x4);
321+ }
322+ #elif defined(MLAS_NEON_INTRINSICS)
323+ vst4q_f32 (d, ZeroFloat32x4x4);
308324#else
309325 MlasStoreAlignedFloat32x4 (d, ZeroFloat32x4);
310326 MlasStoreAlignedFloat32x4 (d + 4 , ZeroFloat32x4);
@@ -486,6 +502,21 @@ Return Value:
486502 x -= 4 ;
487503 }
488504
505+ #elif defined(MLAS_USE_SVE)
506+ if (MLAS_CPUIDINFO::GetCPUIDInfo ().HasArmSve ()) {
507+ SVE_TRANSPOSE (D,b,ldb,x);
508+ }
509+ else
510+ {
511+ while (x >= 4 ) {
512+
513+ MlasSgemmTransposePackBNx4<16 >(&D[0 ], &b[0 ], ldb);
514+
515+ D += 16 * 4 ;
516+ b += 4 ;
517+ x -= 4 ;
518+ }
519+ }
489520#else
490521
491522 while (x >= 4 ) {
@@ -564,8 +595,15 @@ Return Value:
564595 const float * b = B;
565596
566597 if ((CountY & 8 ) != 0 ) {
567-
568- MlasSgemmTransposePackBNx4<8 >(&d[0 ], &b[0 ], ldb);
598+ #if defined(MLAS_USE_SVE)
599+ if (MLAS_CPUIDINFO::GetCPUIDInfo ().HasArmSve ()){
600+ MlasSveTransposePackBNx4<8 >(&d[0 ], &b[0 ], ldb);}
601+ else {
602+ MlasSgemmTransposePackBNx4<8 >(&d[0 ], &b[0 ], ldb);
603+ }
604+ #else
605+ MlasSgemmTransposePackBNx4<8 >(&d[0 ], &b[0 ], ldb);
606+ #endif
569607
570608 d += 8 ;
571609 b += ldb * 8 ;
@@ -584,7 +622,15 @@ Return Value:
584622
585623 if ((CountY & 4 ) != 0 ) {
586624
587- MlasSgemmTransposePackBNx4<4 >(&d[0 ], &b[0 ], ldb);
625+ #if defined(MLAS_USE_SVE)
626+ if (MLAS_CPUIDINFO::GetCPUIDInfo ().HasArmSve ()){
627+ MlasSveTransposePackBNx4<4 >(&d[0 ], &b[0 ], ldb);}
628+ else {
629+ MlasSgemmTransposePackBNx4<4 >(&d[0 ], &b[0 ], ldb);
630+ }
631+ #else
632+ MlasSgemmTransposePackBNx4<4 >(&d[0 ], &b[0 ], ldb);
633+ #endif
588634
589635 d += 4 ;
590636 b += ldb * 4 ;
@@ -631,7 +677,19 @@ Return Value:
631677
632678 if ((CountY & 1 ) != 0 ) {
633679
634- #if defined(MLAS_NEON_INTRINSICS)
680+ #if defined(MLAS_USE_SVE) && defined(MLAS_NEON_INTRINSICS)
681+ if (MLAS_CPUIDINFO::GetCPUIDInfo ().HasArmSve ())
682+ {
683+ SCATTER_STORE (&d[0 ],&b[0 ]);
684+ }
685+ else {
686+ MLAS_FLOAT32X4 t0 = MlasLoadFloat32x4 (&b[0 ]);
687+
688+ MlasStoreLaneFloat32x4<0 >(&d[0 ], t0);
689+ MlasStoreLaneFloat32x4<1 >(&d[16 ], t0);
690+ MlasStoreLaneFloat32x4<2 >(&d[32 ], t0);
691+ MlasStoreLaneFloat32x4<3 >(&d[48 ], t0);}
692+ #elif defined(MLAS_NEON_INTRINSICS)
635693 MLAS_FLOAT32X4 t0 = MlasLoadFloat32x4 (&b[0 ]);
636694
637695 MlasStoreLaneFloat32x4<0 >(&d[0 ], t0);
@@ -945,8 +1003,7 @@ Return Value:
9451003#endif
9461004
9471005MLAS_FORCEINLINE
948- float *
949- MlasSgemmKernelLoop (
1006+ float * MlasSgemmKernelLoop (
9501007 const float * A,
9511008 const float * B,
9521009 float * C,
@@ -1000,18 +1057,41 @@ Return Value:
10001057{
10011058 while (CountM > 0 ) {
10021059
1003- size_t RowsHandled;
1060+ size_t RowsHandled = 0 ;
10041061
10051062#if (defined(MLAS_TARGET_AMD64_IX86) || defined(MLAS_TARGET_POWER) || defined(MLAS_TARGET_S390X) || defined(MLAS_TARGET_LARCH64)) && !defined(FORCE_GENERIC_ALGORITHMS)
10061063 RowsHandled = GetMlasPlatform ().GemmFloatKernel (A, B, C, CountK, CountM, CountN, lda, ldc, alpha, ZeroMode);
1064+
10071065#else
1066+
10081067 if (ZeroMode) {
1068+
1069+ #if defined(MLAS_USE_SVE)
1070+ if (MLAS_CPUIDINFO::GetCPUIDInfo ().HasArmSve ()) {
1071+ RowsHandled = MlasSgemmKernelZero_sve (A, B, C, CountK, CountM, CountN, lda, ldc, alpha);
1072+ } else {
1073+ RowsHandled = MlasSgemmKernelZero (A, B, C, CountK, CountM, CountN, lda, ldc, alpha);
1074+ }
1075+ #else
10091076 RowsHandled = MlasSgemmKernelZero (A, B, C, CountK, CountM, CountN, lda, ldc, alpha);
1077+ #endif
1078+
10101079 } else {
1080+
1081+ #if defined(MLAS_USE_SVE)
1082+ if (MLAS_CPUIDINFO::GetCPUIDInfo ().HasArmSve ()) {
1083+ RowsHandled = MlasSgemmKernelAdd_sve (A, B, C, CountK, CountM, CountN, lda, ldc, alpha);
1084+ } else {
1085+ RowsHandled = MlasSgemmKernelAdd (A, B, C, CountK, CountM, CountN, lda, ldc, alpha);
1086+ }
1087+ #else
10111088 RowsHandled = MlasSgemmKernelAdd (A, B, C, CountK, CountM, CountN, lda, ldc, alpha);
1012- }
10131089#endif
10141090
1091+ }
1092+
1093+ #endif // platform check
1094+
10151095 C += ldc * RowsHandled;
10161096 A += lda * RowsHandled;
10171097 CountM -= RowsHandled;
@@ -1020,6 +1100,7 @@ Return Value:
10201100 return C;
10211101}
10221102
1103+
10231104void
10241105MlasSgemmOperation (
10251106 CBLAS_TRANSPOSE TransA,
0 commit comments