Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,4 +307,7 @@ hheei <hheei@users.noreply.github.com>
* [2026-11-21] Fix the sine in the small-cosine branch of CROTG/ZROTG for complex inputs

* Ryan Curtin <ryan@ratml.org>
* [2026-11-27] Fix TRMM kernels for mips architectures.
* [2026-11-27] Fix TRMM kernels for mips architectures.

* proffitteoy <https://github.com/proffitteoy>
* [2026-12-04] Fix conjugation of A in complex GEADD.
9 changes: 9 additions & 0 deletions docs/extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ This page documents those non-standard APIs.
| cblas_?gemm_batch | s,d,c,z,b | `gemm` with several groups of input data |
| cblas_?gemm_batch_strided | s,d,c,z,b | `gemm` with groups of data stored at fixed offsets in the input arrays |

### Complex GEADD operations on A

For `cblas_cgeadd` and `cblas_zgeadd` with `transC=CblasNoTrans`, the operation
is `C = alpha*op(A) + beta*C`. The `transA` argument selects `A`, `A^T`,
`conj(A)`, or `conj(A)^T` with `CblasNoTrans`, `CblasTrans`,
`CblasConjNoTrans`, or `CblasConjTrans`, respectively. The Fortran-style
`cgeadd` and `zgeadd` interfaces use `N`, `T`, `R`, or `C` for these A
operations, accepting either letter case.

## bfloat16 functionality

BLAS-like and conversion functions for `bfloat16` (available when OpenBLAS was compiled with `BUILD_BFLOAT16=1`):
Expand Down
8 changes: 6 additions & 2 deletions interface/zgeadd.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ void NAME(blasint *M, blasint *N, FLOAT *ALPHA, FLOAT *a, blasint *LDA,
blasint ldc = *LDC;

blasint info;
int conja = (*TRANS_A == 'C') || (*TRANS_A == 'c') ||
(*TRANS_A == 'R') || (*TRANS_A == 'r');
char transa = (*TRANS_A == 'T') || (*TRANS_A == 't') || (*TRANS_A == 'C') || (*TRANS_A == 'c');
char transc = (*TRANS_C == 'T') || (*TRANS_C == 't') || (*TRANS_C == 'C') || (*TRANS_C == 'c');

Expand Down Expand Up @@ -112,6 +114,7 @@ void CNAME(enum CBLAS_ORDER order,
FLOAT *c, blasint ldc){ */

blasint info, t;
int conja = (transa == CblasConjNoTrans) || (transa == CblasConjTrans);

PRINT_DEBUG_CNAME;

Expand Down Expand Up @@ -178,10 +181,11 @@ if ( (transc == CblasNoTrans) || (transc == CblasConjNoTrans) ) {
GEADD_K(m,n,ALPHA[0],ALPHA[1], a, lda, BETA[0], BETA[1], c, ldc,

#ifdef CBLAS
(transa == CblasTrans) || (transa == CblasConjTrans),
/* Bit 0 transposes A; bit 1 conjugates it. */
((transa == CblasTrans) || (transa == CblasConjTrans)) | (conja << 1),
(transc == CblasTrans) || (transc == CblasConjTrans)
#else
transa, transc
transa | (conja << 1), transc
#endif
);

Expand Down
24 changes: 24 additions & 0 deletions kernel/generic/zgeadd.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ int CNAME(BLASLONG rows, BLASLONG cols, FLOAT alphar, FLOAT alphai, FLOAT *a,
FLOAT *aptr, *bptr;
BLASLONG lda_elem = lda;
BLASLONG ldb_elem = ldb;
BLASLONG conja = transa & 2;
transa &= 1;
if (rows <= 0)
return (0);
if (cols <= 0)
Expand All @@ -58,6 +60,28 @@ int CNAME(BLASLONG rows, BLASLONG cols, FLOAT alphar, FLOAT alphai, FLOAT *a,
}
return (0);
}
if (conja) {
BLASLONG j;
BLASLONG inc_a = transa ? lda : 2;
BLASLONG inc_b = transb ? ldb : 2;
for (i = 0; i < cols; i++) {
for (j = 0; j < rows; j++) {
FLOAT ar = aptr[j * inc_a], ai = aptr[j * inc_a + 1];
FLOAT real = alphar * ar + alphai * ai;
FLOAT imag = alphai * ar - alphar * ai;
if (betar != 0.0 || betai != 0.0) {
FLOAT br = bptr[j * inc_b], bi = bptr[j * inc_b + 1];
real += betar * br - betai * bi;
imag += betar * bi + betai * br;
}
bptr[j * inc_b] = real;
bptr[j * inc_b + 1] = imag;
}
aptr += transa ? 2 : lda;
bptr += transb ? 2 : ldb;
}
return (0);
}
if (!transa && !transb) {
for (i = 0; i < cols; i++) {
AXPBY_K(rows, alphar, alphai, aptr, 1, betar, betai, bptr, 1);
Expand Down
91 changes: 91 additions & 0 deletions utest/test_extensions/test_cgeadd.c
Original file line number Diff line number Diff line change
Expand Up @@ -976,4 +976,95 @@ CTEST(cgeadd, c_api_matrix_n_100_m_100_transA) {
ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS);
}
#endif

/* Check conjugation independently of the AXPBY-based reference helper. */
CTEST(cgeadd, conjugate_a) {
#ifndef NO_CBLAS
const enum CBLAS_ORDER orders[] = {CblasColMajor, CblasRowMajor};
const enum CBLAS_TRANSPOSE transa[] = {CblasConjNoTrans, CblasConjTrans};
const enum CBLAS_TRANSPOSE transc[] = {CblasNoTrans, CblasTrans};
#endif
const float alphas[4][2] = {{1.5, -0.5}, {1.0, 0.0}, {0.0, 0.0}, {0.0, 0.0}};
const float betas[4][2] = {{-0.5, 1.0}, {0.0, 0.0}, {0.5, -0.5}, {0.0, 0.0}};
blasint m = 2, n = 3, lda = 5, ldc = 5;
int api, order, ta, tc, coeff, i, j, k;

for (api = 0; api < 3; api++) {
#ifdef NO_CBLAS
if (api == 0) continue;
#endif
for (order = 0; order < 2; order++) {
if (api > 0 && order == 1) continue;
for (ta = 0; ta < 2; ta++) {
for (tc = 0; tc < 2; tc++) {
for (coeff = 0; coeff < 4; coeff++) {
float a[32], a_copy[32], c[32], expected[32];
float alpha[2] = {alphas[coeff][0], alphas[coeff][1]};
float beta[2] = {betas[coeff][0], betas[coeff][1]};

for (k = 0; k < 32; k++) {
a[k] = coeff >= 2 ? NAN : (float)(k + 1) * 0.25;
c[k] = (float)(k - 3) * 0.5;
}
if (coeff == 1 || coeff == 3) {
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
int r = tc ? j : i, col = tc ? i : j;
int pos = 2 * (order ? r * ldc + col : r + col * ldc);
c[pos] = c[pos + 1] = NAN;
}
}
}
memcpy(a_copy, a, sizeof(a));
memcpy(expected, c, sizeof(c));

for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
int ar = ta ? j : i, ac = ta ? i : j;
int cr = tc ? j : i, cc = tc ? i : j;
int apos = 2 * (order ? ar * lda + ac : ar + ac * lda);
int cpos = 2 * (order ? cr * ldc + cc : cr + cc * ldc);
float real = 0.0, imag = 0.0;
if (coeff < 2) {
float xr = a[apos], xi = -a[apos + 1];
real = alpha[0] * xr - alpha[1] * xi;
imag = alpha[0] * xi + alpha[1] * xr;
}
if (coeff == 0 || coeff == 2) {
real += beta[0] * c[cpos] - beta[1] * c[cpos + 1];
imag += beta[0] * c[cpos + 1] + beta[1] * c[cpos];
}
expected[cpos] = real;
expected[cpos + 1] = imag;
}
}

#ifndef NO_CBLAS
if (api == 0) {
cblas_cgeadd(orders[order], transa[ta], transc[tc],
m, n, alpha, a, lda, beta, c, ldc);
} else
#endif
{
char transa_f = ta ? 'C' : 'R', transc_f = tc ? 'T' : 'N';
if (api == 2) {
transa_f = ta ? 'c' : 'r';
transc_f = tc ? 't' : 'n';
}
BLASFUNC(cgeadd)(&m, &n, alpha, a, &lda, beta, c, &ldc,
&transa_f, &transc_f);
}

ASSERT_EQUAL(0, memcmp(a_copy, a, sizeof(a)));
for (k = 0; k < 32; k++) {
ASSERT_TRUE(isfinite(c[k]));
ASSERT_DBL_NEAR_TOL(expected[k], c[k], SINGLE_EPS);
}
}
}
}
}
}
}

#endif
91 changes: 91 additions & 0 deletions utest/test_extensions/test_zgeadd.c
Original file line number Diff line number Diff line change
Expand Up @@ -989,4 +989,95 @@ CTEST(zgeadd, c_api_matrix_n_100_m_100_transA) {


#endif

/* Check conjugation independently of the AXPBY-based reference helper. */
CTEST(zgeadd, conjugate_a) {
#ifndef NO_CBLAS
const enum CBLAS_ORDER orders[] = {CblasColMajor, CblasRowMajor};
const enum CBLAS_TRANSPOSE transa[] = {CblasConjNoTrans, CblasConjTrans};
const enum CBLAS_TRANSPOSE transc[] = {CblasNoTrans, CblasTrans};
#endif
const double alphas[4][2] = {{1.5, -0.5}, {1.0, 0.0}, {0.0, 0.0}, {0.0, 0.0}};
const double betas[4][2] = {{-0.5, 1.0}, {0.0, 0.0}, {0.5, -0.5}, {0.0, 0.0}};
blasint m = 2, n = 3, lda = 5, ldc = 5;
int api, order, ta, tc, coeff, i, j, k;

for (api = 0; api < 3; api++) {
#ifdef NO_CBLAS
if (api == 0) continue;
#endif
for (order = 0; order < 2; order++) {
if (api > 0 && order == 1) continue;
for (ta = 0; ta < 2; ta++) {
for (tc = 0; tc < 2; tc++) {
for (coeff = 0; coeff < 4; coeff++) {
double a[32], a_copy[32], c[32], expected[32];
double alpha[2] = {alphas[coeff][0], alphas[coeff][1]};
double beta[2] = {betas[coeff][0], betas[coeff][1]};

for (k = 0; k < 32; k++) {
a[k] = coeff >= 2 ? NAN : (double)(k + 1) * 0.25;
c[k] = (double)(k - 3) * 0.5;
}
if (coeff == 1 || coeff == 3) {
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
int r = tc ? j : i, col = tc ? i : j;
int pos = 2 * (order ? r * ldc + col : r + col * ldc);
c[pos] = c[pos + 1] = NAN;
}
}
}
memcpy(a_copy, a, sizeof(a));
memcpy(expected, c, sizeof(c));

for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
int ar = ta ? j : i, ac = ta ? i : j;
int cr = tc ? j : i, cc = tc ? i : j;
int apos = 2 * (order ? ar * lda + ac : ar + ac * lda);
int cpos = 2 * (order ? cr * ldc + cc : cr + cc * ldc);
double real = 0.0, imag = 0.0;
if (coeff < 2) {
double xr = a[apos], xi = -a[apos + 1];
real = alpha[0] * xr - alpha[1] * xi;
imag = alpha[0] * xi + alpha[1] * xr;
}
if (coeff == 0 || coeff == 2) {
real += beta[0] * c[cpos] - beta[1] * c[cpos + 1];
imag += beta[0] * c[cpos + 1] + beta[1] * c[cpos];
}
expected[cpos] = real;
expected[cpos + 1] = imag;
}
}

#ifndef NO_CBLAS
if (api == 0) {
cblas_zgeadd(orders[order], transa[ta], transc[tc],
m, n, alpha, a, lda, beta, c, ldc);
} else
#endif
{
char transa_f = ta ? 'C' : 'R', transc_f = tc ? 'T' : 'N';
if (api == 2) {
transa_f = ta ? 'c' : 'r';
transc_f = tc ? 't' : 'n';
}
BLASFUNC(zgeadd)(&m, &n, alpha, a, &lda, beta, c, &ldc,
&transa_f, &transc_f);
}

ASSERT_EQUAL(0, memcmp(a_copy, a, sizeof(a)));
for (k = 0; k < 32; k++) {
ASSERT_TRUE(isfinite(c[k]));
ASSERT_DBL_NEAR_TOL(expected[k], c[k], DOUBLE_EPS);
}
}
}
}
}
}
}

#endif
Loading