Skip to content

Commit dcc5d62

Browse files
committed
skylakex: Make the sgemm/dgemm beta code robust for a N=0 or M=0 case
in the threading code there are cases where N or M can become 0, and the optimized beta code did not handle this well, leading to a crash during the audit for the crash a few edge conditions on the if statements were found and fixed as well
1 parent f5595d0 commit dcc5d62

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

kernel/x86_64/dgemm_beta_skylakex.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ int CNAME(BLASLONG m, BLASLONG n, BLASLONG dummy1, FLOAT beta,
5555
return 0;
5656
}
5757

58+
if (m == 0 || n == 0)
59+
return 0;
5860

5961
c_offset = c;
6062

@@ -69,15 +71,15 @@ int CNAME(BLASLONG m, BLASLONG n, BLASLONG dummy1, FLOAT beta,
6971

7072
i = m;
7173

72-
while (i > 32) {
74+
while (i >= 32) {
7375
_mm512_storeu_pd(c_offset1, z_zero);
7476
_mm512_storeu_pd(c_offset1 + 8, z_zero);
7577
_mm512_storeu_pd(c_offset1 + 16, z_zero);
7678
_mm512_storeu_pd(c_offset1 + 24 , z_zero);
7779
c_offset1 += 32;
7880
i -= 32;
7981
}
80-
while (i > 8) {
82+
while (i >= 8) {
8183
_mm512_storeu_pd(c_offset1, z_zero);
8284
c_offset1 += 8;
8385
i -= 8;

kernel/x86_64/sgemm_beta_skylakex.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ int CNAME(BLASLONG m, BLASLONG n, BLASLONG dummy1, FLOAT beta,
5555
return 0;
5656
}
5757

58+
if (n == 0 || m == 0)
59+
return;
5860

5961
c_offset = c;
6062

@@ -71,13 +73,13 @@ int CNAME(BLASLONG m, BLASLONG n, BLASLONG dummy1, FLOAT beta,
7173

7274
i = m;
7375

74-
while (i > 32) {
76+
while (i >= 32) {
7577
_mm512_storeu_ps(c_offset1, z_zero);
7678
_mm512_storeu_ps(c_offset1 + 16, z_zero);
7779
c_offset1 += 32;
7880
i -= 32;
7981
}
80-
while (i > 8) {
82+
while (i >= 8) {
8183
_mm256_storeu_ps(c_offset1, y_zero);
8284
c_offset1 += 8;
8385
i -= 8;

0 commit comments

Comments
 (0)