mirror of
https://github.com/amd/blis.git
synced 2026-04-19 23:28:52 +00:00
Bugfix: Fix for gemmsup_r Reference Kernels
- The existing row-preferred reference kernels for GEMM SUP path were not taking into consideration the packing state of matrices A or B. Thus, whenever either or both A and B matrices were packed the kernel was unable to iterate appropriately through the matrices thereby calculating incorrect values resulting in failures. - Though, for generic configuration, the SUP path is disabled by default the set of Pack and Compute Extension APIs use these kernels thus, this issue resulted in their failures as well. - With this patch, the loops being used in these kernels have been fixed to iterate over steps of MR and NR while also accounting for the fringe cases. Within the updated loops, temporary pointers used to point to the correct block/panel of the matrices are incremented with panel strides of respective matrices. AMD-Internal: [CPUPL-5674] Change-Id: Ic3939877c79ebb9ccf9e53b1d1672cea4b8c5959
This commit is contained in:
committed by
Arnav Sharma
parent
c7a5d04d4d
commit
df0ce5a799
@@ -4,7 +4,7 @@
|
||||
An object-based framework for developing high-performance BLAS-like
|
||||
libraries.
|
||||
|
||||
Copyright (C) 2019 - 2023, Advanced Micro Devices, Inc. All rights reserved.
|
||||
Copyright (C) 2019 - 2024, Advanced Micro Devices, Inc. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
@@ -59,180 +59,225 @@ void PASTEMAC3(ch,opname,arch,suf) \
|
||||
{ \
|
||||
/* NOTE: This microkernel can actually handle arbitrarily large
|
||||
values of m, n, and k. */ \
|
||||
const num_t dt = PASTEMAC(ch,type); \
|
||||
const dim_t MR = bli_cntx_get_l3_sup_blksz_def_dt( dt, BLIS_MR, cntx ); \
|
||||
const dim_t NR = bli_cntx_get_l3_sup_blksz_def_dt( dt, BLIS_NR, cntx ); \
|
||||
\
|
||||
uint64_t ps_a = bli_auxinfo_ps_a( data ); \
|
||||
uint64_t ps_b = bli_auxinfo_ps_b( data ); \
|
||||
\
|
||||
ctype* restrict abuf = a; \
|
||||
ctype* restrict bbuf = b; \
|
||||
\
|
||||
if ( bli_is_noconj( conja ) && bli_is_noconj( conjb ) ) \
|
||||
{ \
|
||||
/* Traverse c by rows. */ \
|
||||
for ( dim_t i = 0; i < m; ++i ) \
|
||||
for ( dim_t i = 0; i < m; i += MR ) \
|
||||
{ \
|
||||
ctype* restrict ci = &c[ i*rs_c ]; \
|
||||
ctype* restrict ai = &a[ i*rs_a ]; \
|
||||
\
|
||||
for ( dim_t j = 0; j < n; ++j ) \
|
||||
for ( dim_t ii = 0; ii < bli_min( MR, m-i ); ++ii ) \
|
||||
{ \
|
||||
ctype* restrict cij = &ci[ j*cs_c ]; \
|
||||
ctype* restrict bj = &b [ j*cs_b ]; \
|
||||
ctype ab; \
|
||||
bbuf = b; \
|
||||
ctype* restrict ci = c + (i+ii) * rs_c; \
|
||||
ctype* restrict ai = abuf + ii * rs_a; \
|
||||
\
|
||||
PASTEMAC(ch,set0s)( ab ); \
|
||||
for ( dim_t j = 0; j < n; j += NR ) \
|
||||
{ \
|
||||
for ( dim_t jj = 0; jj < bli_min( NR, n-j ); ++jj ) \
|
||||
{ \
|
||||
ctype* restrict cij = ci + (j+jj) * cs_c; \
|
||||
ctype* restrict bj = bbuf + jj * cs_b; \
|
||||
ctype ab; \
|
||||
\
|
||||
/* Perform a dot product to update the (i,j) element of c. */ \
|
||||
for ( dim_t l = 0; l < k; ++l ) \
|
||||
{ \
|
||||
ctype* restrict aij = &ai[ l*cs_a ]; \
|
||||
ctype* restrict bij = &bj[ l*rs_b ]; \
|
||||
PASTEMAC(ch,set0s)( ab ); \
|
||||
\
|
||||
PASTEMAC(ch,dots)( *aij, *bij, ab ); \
|
||||
} \
|
||||
/* Perform a dot product to update the (i,j) element of c. */ \
|
||||
for ( dim_t l = 0; l < k; ++l ) \
|
||||
{ \
|
||||
ctype* restrict aij = ai + l * cs_a; \
|
||||
ctype* restrict bij = bj + l * rs_b; \
|
||||
\
|
||||
/* If beta is one, add ab into c. If beta is zero, overwrite c
|
||||
with the result in ab. Otherwise, scale by beta and accumulate
|
||||
ab to c. */ \
|
||||
if ( PASTEMAC(ch,eq1)( *beta ) ) \
|
||||
{ \
|
||||
PASTEMAC(ch,axpys)( *alpha, ab, *cij ); \
|
||||
} \
|
||||
else if ( PASTEMAC(ch,eq0)( *beta ) ) \
|
||||
{ \
|
||||
PASTEMAC(ch,scal2s)( *alpha, ab, *cij ); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
PASTEMAC(ch,axpbys)( *alpha, ab, *beta, *cij ); \
|
||||
PASTEMAC(ch,dots)( *aij, *bij, ab ); \
|
||||
} \
|
||||
\
|
||||
/* If beta is one, add ab into c. If beta is zero, overwrite c
|
||||
with the result in ab. Otherwise, scale by beta and accumulate
|
||||
ab to c. */ \
|
||||
if ( PASTEMAC(ch,eq1)( *beta ) ) \
|
||||
{ \
|
||||
PASTEMAC(ch,axpys)( *alpha, ab, *cij ); \
|
||||
} \
|
||||
else if ( PASTEMAC(ch,eq0)( *beta ) ) \
|
||||
{ \
|
||||
PASTEMAC(ch,scal2s)( *alpha, ab, *cij ); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
PASTEMAC(ch,axpbys)( *alpha, ab, *beta, *cij ); \
|
||||
} \
|
||||
} \
|
||||
bbuf += ps_b; \
|
||||
} \
|
||||
} \
|
||||
abuf += ps_a; \
|
||||
} \
|
||||
} \
|
||||
else if ( bli_is_noconj( conja ) && bli_is_conj( conjb ) ) \
|
||||
{ \
|
||||
/* Traverse c by rows. */ \
|
||||
for ( dim_t i = 0; i < m; ++i ) \
|
||||
for ( dim_t i = 0; i < m; i += MR ) \
|
||||
{ \
|
||||
ctype* restrict ci = &c[ i*rs_c ]; \
|
||||
ctype* restrict ai = &a[ i*rs_a ]; \
|
||||
\
|
||||
for ( dim_t j = 0; j < n; ++j ) \
|
||||
for ( dim_t ii = 0; ii < bli_min( MR, m-i ); ++ii ) \
|
||||
{ \
|
||||
ctype* restrict cij = &ci[ j*cs_c ]; \
|
||||
ctype* restrict bj = &b [ j*cs_b ]; \
|
||||
ctype ab; \
|
||||
bbuf = b; \
|
||||
ctype* restrict ci = c + (i+ii) * rs_c; \
|
||||
ctype* restrict ai = abuf + ii * rs_a; \
|
||||
\
|
||||
PASTEMAC(ch,set0s)( ab ); \
|
||||
for ( dim_t j = 0; j < n; j += NR ) \
|
||||
{ \
|
||||
for ( dim_t jj = 0; jj < bli_min( NR, n-j ); ++jj ) \
|
||||
{ \
|
||||
ctype* restrict cij = ci + (j+jj) * cs_c; \
|
||||
ctype* restrict bj = bbuf + jj * cs_b; \
|
||||
ctype ab; \
|
||||
\
|
||||
/* Perform a dot product to update the (i,j) element of c. */ \
|
||||
for ( dim_t l = 0; l < k; ++l ) \
|
||||
{ \
|
||||
ctype* restrict aij = &ai[ l*cs_a ]; \
|
||||
ctype* restrict bij = &bj[ l*rs_b ]; \
|
||||
PASTEMAC(ch,set0s)( ab ); \
|
||||
\
|
||||
PASTEMAC(ch,axpyjs)( *aij, *bij, ab ); \
|
||||
} \
|
||||
/* Perform a dot product to update the (i,j) element of c. */ \
|
||||
for ( dim_t l = 0; l < k; ++l ) \
|
||||
{ \
|
||||
ctype* restrict aij = ai + l * cs_a; \
|
||||
ctype* restrict bij = bj + l * rs_b; \
|
||||
\
|
||||
/* If beta is one, add ab into c. If beta is zero, overwrite c
|
||||
with the result in ab. Otherwise, scale by beta and accumulate
|
||||
ab to c. */ \
|
||||
if ( PASTEMAC(ch,eq1)( *beta ) ) \
|
||||
{ \
|
||||
PASTEMAC(ch,axpys)( *alpha, ab, *cij ); \
|
||||
} \
|
||||
else if ( PASTEMAC(ch,eq0)( *beta ) ) \
|
||||
{ \
|
||||
PASTEMAC(ch,scal2s)( *alpha, ab, *cij ); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
PASTEMAC(ch,axpbys)( *alpha, ab, *beta, *cij ); \
|
||||
PASTEMAC(ch,axpyjs)( *aij, *bij, ab ); \
|
||||
} \
|
||||
\
|
||||
/* If beta is one, add ab into c. If beta is zero, overwrite c
|
||||
with the result in ab. Otherwise, scale by beta and accumulate
|
||||
ab to c. */ \
|
||||
if ( PASTEMAC(ch,eq1)( *beta ) ) \
|
||||
{ \
|
||||
PASTEMAC(ch,axpys)( *alpha, ab, *cij ); \
|
||||
} \
|
||||
else if ( PASTEMAC(ch,eq0)( *beta ) ) \
|
||||
{ \
|
||||
PASTEMAC(ch,scal2s)( *alpha, ab, *cij ); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
PASTEMAC(ch,axpbys)( *alpha, ab, *beta, *cij ); \
|
||||
} \
|
||||
} \
|
||||
bbuf += ps_b; \
|
||||
} \
|
||||
} \
|
||||
abuf += ps_a; \
|
||||
} \
|
||||
} \
|
||||
else if ( bli_is_conj( conja ) && bli_is_noconj( conjb ) ) \
|
||||
{ \
|
||||
/* Traverse c by rows. */ \
|
||||
for ( dim_t i = 0; i < m; ++i ) \
|
||||
for ( dim_t i = 0; i < m; i += MR ) \
|
||||
{ \
|
||||
ctype* restrict ci = &c[ i*rs_c ]; \
|
||||
ctype* restrict ai = &a[ i*rs_a ]; \
|
||||
\
|
||||
for ( dim_t j = 0; j < n; ++j ) \
|
||||
for ( dim_t ii = 0; ii < bli_min( MR, m-i ); ++ii ) \
|
||||
{ \
|
||||
ctype* restrict cij = &ci[ j*cs_c ]; \
|
||||
ctype* restrict bj = &b [ j*cs_b ]; \
|
||||
ctype ab; \
|
||||
bbuf = b; \
|
||||
ctype* restrict ci = c + (i+ii) * rs_c; \
|
||||
ctype* restrict ai = abuf + ii * rs_a; \
|
||||
\
|
||||
PASTEMAC(ch,set0s)( ab ); \
|
||||
for ( dim_t j = 0; j < n; j += NR ) \
|
||||
{ \
|
||||
for ( dim_t jj = 0; jj < bli_min( NR, n-j ); ++jj ) \
|
||||
{ \
|
||||
ctype* restrict cij = ci + (j+jj) * cs_c; \
|
||||
ctype* restrict bj = bbuf + jj * cs_b; \
|
||||
ctype ab; \
|
||||
\
|
||||
/* Perform a dot product to update the (i,j) element of c. */ \
|
||||
for ( dim_t l = 0; l < k; ++l ) \
|
||||
{ \
|
||||
ctype* restrict aij = &ai[ l*cs_a ]; \
|
||||
ctype* restrict bij = &bj[ l*rs_b ]; \
|
||||
PASTEMAC(ch,set0s)( ab ); \
|
||||
\
|
||||
PASTEMAC(ch,dotjs)( *aij, *bij, ab ); \
|
||||
} \
|
||||
/* Perform a dot product to update the (i,j) element of c. */ \
|
||||
for ( dim_t l = 0; l < k; ++l ) \
|
||||
{ \
|
||||
ctype* restrict aij = ai + l * cs_a; \
|
||||
ctype* restrict bij = bj + l * rs_b; \
|
||||
\
|
||||
/* If beta is one, add ab into c. If beta is zero, overwrite c
|
||||
with the result in ab. Otherwise, scale by beta and accumulate
|
||||
ab to c. */ \
|
||||
if ( PASTEMAC(ch,eq1)( *beta ) ) \
|
||||
{ \
|
||||
PASTEMAC(ch,axpys)( *alpha, ab, *cij ); \
|
||||
} \
|
||||
else if ( PASTEMAC(ch,eq0)( *beta ) ) \
|
||||
{ \
|
||||
PASTEMAC(ch,scal2s)( *alpha, ab, *cij ); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
PASTEMAC(ch,axpbys)( *alpha, ab, *beta, *cij ); \
|
||||
PASTEMAC(ch,dotjs)( *aij, *bij, ab ); \
|
||||
} \
|
||||
\
|
||||
/* If beta is one, add ab into c. If beta is zero, overwrite c
|
||||
with the result in ab. Otherwise, scale by beta and accumulate
|
||||
ab to c. */ \
|
||||
if ( PASTEMAC(ch,eq1)( *beta ) ) \
|
||||
{ \
|
||||
PASTEMAC(ch,axpys)( *alpha, ab, *cij ); \
|
||||
} \
|
||||
else if ( PASTEMAC(ch,eq0)( *beta ) ) \
|
||||
{ \
|
||||
PASTEMAC(ch,scal2s)( *alpha, ab, *cij ); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
PASTEMAC(ch,axpbys)( *alpha, ab, *beta, *cij ); \
|
||||
} \
|
||||
} \
|
||||
bbuf += ps_b; \
|
||||
} \
|
||||
} \
|
||||
abuf += ps_a; \
|
||||
} \
|
||||
} \
|
||||
else /* if ( bli_is_conj( conja ) && bli_is_conj( conjb ) ) */ \
|
||||
{ \
|
||||
/* Traverse c by rows. */ \
|
||||
for ( dim_t i = 0; i < m; ++i ) \
|
||||
for ( dim_t i = 0; i < m; i += MR ) \
|
||||
{ \
|
||||
ctype* restrict ci = &c[ i*rs_c ]; \
|
||||
ctype* restrict ai = &a[ i*rs_a ]; \
|
||||
\
|
||||
for ( dim_t j = 0; j < n; ++j ) \
|
||||
for ( dim_t ii = 0; ii < bli_min( MR, m-i ); ++ii ) \
|
||||
{ \
|
||||
ctype* restrict cij = &ci[ j*cs_c ]; \
|
||||
ctype* restrict bj = &b [ j*cs_b ]; \
|
||||
ctype ab; \
|
||||
bbuf = b; \
|
||||
ctype* restrict ci = c + (i+ii) * rs_c; \
|
||||
ctype* restrict ai = abuf + ii * rs_a; \
|
||||
\
|
||||
PASTEMAC(ch,set0s)( ab ); \
|
||||
\
|
||||
/* Perform a dot product to update the (i,j) element of c. */ \
|
||||
for ( dim_t l = 0; l < k; ++l ) \
|
||||
for ( dim_t j = 0; j < n; j += NR ) \
|
||||
{ \
|
||||
ctype* restrict aij = &ai[ l*cs_a ]; \
|
||||
ctype* restrict bij = &bj[ l*rs_b ]; \
|
||||
for ( dim_t jj = 0; jj < bli_min( NR, n-j ); ++jj ) \
|
||||
{ \
|
||||
ctype* restrict cij = ci + (j+jj) * cs_c; \
|
||||
ctype* restrict bj = bbuf + jj * cs_b; \
|
||||
ctype ab; \
|
||||
\
|
||||
PASTEMAC(ch,dots)( *aij, *bij, ab ); \
|
||||
} \
|
||||
PASTEMAC(ch,set0s)( ab ); \
|
||||
\
|
||||
/* Conjugate the result to simulate conj(a^T) * conj(b). */ \
|
||||
PASTEMAC(ch,conjs)( ab ); \
|
||||
/* Perform a dot product to update the (i,j) element of c. */ \
|
||||
for ( dim_t l = 0; l < k; ++l ) \
|
||||
{ \
|
||||
ctype* restrict aij = ai + l * cs_a; \
|
||||
ctype* restrict bij = bj + l * rs_b; \
|
||||
\
|
||||
/* If beta is one, add ab into c. If beta is zero, overwrite c
|
||||
with the result in ab. Otherwise, scale by beta and accumulate
|
||||
ab to c. */ \
|
||||
if ( PASTEMAC(ch,eq1)( *beta ) ) \
|
||||
{ \
|
||||
PASTEMAC(ch,axpys)( *alpha, ab, *cij ); \
|
||||
} \
|
||||
else if ( PASTEMAC(ch,eq0)( *beta ) ) \
|
||||
{ \
|
||||
PASTEMAC(ch,scal2s)( *alpha, ab, *cij ); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
PASTEMAC(ch,axpbys)( *alpha, ab, *beta, *cij ); \
|
||||
PASTEMAC(ch,dots)( *aij, *bij, ab ); \
|
||||
} \
|
||||
\
|
||||
/* Conjugate the result to simulate conj(a^T) * conj(b). */ \
|
||||
PASTEMAC(ch,conjs)( ab ); \
|
||||
\
|
||||
/* If beta is one, add ab into c. If beta is zero, overwrite c
|
||||
with the result in ab. Otherwise, scale by beta and accumulate
|
||||
ab to c. */ \
|
||||
if ( PASTEMAC(ch,eq1)( *beta ) ) \
|
||||
{ \
|
||||
PASTEMAC(ch,axpys)( *alpha, ab, *cij ); \
|
||||
} \
|
||||
else if ( PASTEMAC(ch,eq0)( *beta ) ) \
|
||||
{ \
|
||||
PASTEMAC(ch,scal2s)( *alpha, ab, *cij ); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
PASTEMAC(ch,axpbys)( *alpha, ab, *beta, *cij ); \
|
||||
} \
|
||||
} \
|
||||
bbuf += ps_b; \
|
||||
} \
|
||||
} \
|
||||
abuf += ps_a; \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user