Skip to content

Commit

Permalink
Merge pull request #4689 from martin-frbg/issue4684
Browse files Browse the repository at this point in the history
Fix compilation of the BLAS extension utests for NO_CBLAS=1
  • Loading branch information
martin-frbg authored May 11, 2024
2 parents e1e0d9a + d8baf2f commit f0560f9
Show file tree
Hide file tree
Showing 46 changed files with 224 additions and 62 deletions.
4 changes: 4 additions & 0 deletions utest/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ OBJS = utest_main2.o
OBJS_EXT = $(DIR_EXT)/utest_main2.o
endif

ifeq ($(NO_CBLAS), 1)
override CFLAGS += -DNO_CBLAS
endif

all : run_test

ifeq ($(OSNAME), AIX)
Expand Down
6 changes: 3 additions & 3 deletions utest/test_extensions/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ float smatrix_difference(float *a, float *b, blasint cols, blasint rows, blasint
for (j = 0; j < cols; j++) {
a_ptr[j] -= b_ptr[j];
}
norm += cblas_snrm2(cols, a_ptr, inc);
norm += BLASFUNC(snrm2)(&cols, a_ptr, &inc);

a_ptr += ld;
b_ptr += ld;
Expand All @@ -92,7 +92,7 @@ double dmatrix_difference(double *a, double *b, blasint cols, blasint rows, blas
for (j = 0; j < cols; j++) {
a_ptr[j] -= b_ptr[j];
}
norm += cblas_dnrm2(cols, a_ptr, inc);
norm += BLASFUNC(dnrm2)(&cols, a_ptr, &inc);

a_ptr += ld;
b_ptr += ld;
Expand Down Expand Up @@ -256,4 +256,4 @@ void zcopy(blasint rows, blasint cols, double *alpha, double *a_src, int lda_src
a_dst[i*lda_dst+j+1] = (-1.0) * conj *alpha[0] * a_src[i*lda_src+j+1] + alpha[1] * a_src[i*lda_src+j];
}
}
}
}
6 changes: 4 additions & 2 deletions utest/test_extensions/test_caxpby.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static float check_caxpby(blasint n, float *alpha, blasint incx, float *beta, bl
// Find the norm of differences
return BLASFUNC(scnrm2)(&n, data_caxpby.y_test, &incy_abs);
}

#ifndef NO_CBLAS
/**
* C API specific function
* Test caxpby by comparing it with cscal and caxpy.
Expand Down Expand Up @@ -146,7 +146,7 @@ static float c_api_check_caxpby(blasint n, float *alpha, blasint incx, float *be
// Find the norm of differences
return cblas_scnrm2(n, data_caxpby.y_test, incy_abs);
}

#endif
/**
* Fortran API specific test
* Test caxpby by comparing it with cscal and caxpy.
Expand Down Expand Up @@ -388,6 +388,7 @@ CTEST(caxpby, check_n_zero)
ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS);
}

#ifndef NO_CBLAS
/**
* C API specific test
* Test caxpby by comparing it with cscal and caxpy.
Expand Down Expand Up @@ -629,3 +630,4 @@ CTEST(caxpby, c_api_check_n_zero)
ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS);
}
#endif
#endif
12 changes: 9 additions & 3 deletions utest/test_extensions/test_cgeadd.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,14 @@ static void cgeadd_trusted(blasint m, blasint n, float *alpha, float *aptr,
blasint lda, float *beta, float *cptr, blasint ldc)
{
blasint i;
blasint one=1;

lda *= 2;
ldc *= 2;

for (i = 0; i < n; i++)
{
cblas_caxpby(m, alpha, aptr, 1, beta, cptr, 1);
BLASFUNC(caxpby)(&m, alpha, aptr, &one, beta, cptr, &one);
aptr += lda;
cptr += ldc;
}
Expand Down Expand Up @@ -116,9 +117,11 @@ static float check_cgeadd(char api, OPENBLAS_CONST enum CBLAS_ORDER order,
if (api == 'F')
BLASFUNC(cgeadd)(&m, &n, alpha, data_cgeadd.a_test, &lda,
beta, data_cgeadd.c_test, &ldc);
#ifndef NO_CBLAS
else
cblas_cgeadd(order, m, n, alpha, data_cgeadd.a_test, lda,
beta, data_cgeadd.c_test, ldc);
#endif

// Find the differences between output matrix caculated by cgeadd and sgemm
return smatrix_difference(data_cgeadd.c_test, data_cgeadd.c_verify, cols, rows, ldc*2);
Expand Down Expand Up @@ -150,9 +153,11 @@ static int check_badargs(char api, OPENBLAS_CONST enum CBLAS_ORDER order,
if (api == 'F')
BLASFUNC(cgeadd)(&m, &n, alpha, data_cgeadd.a_test, &lda,
beta, data_cgeadd.c_test, &ldc);
#ifndef NO_CBLAS
else
cblas_cgeadd(order, m, n, alpha, data_cgeadd.a_test, lda,
beta, data_cgeadd.c_test, ldc);
#endif

return check_error();
}
Expand Down Expand Up @@ -419,7 +424,7 @@ CTEST(cgeadd, m_zero)

ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS);
}

#ifndef NO_CBLAS
/**
* C API specific test
* Test cgeadd by comparing it against sgemm
Expand Down Expand Up @@ -877,4 +882,5 @@ CTEST(cgeadd, c_api_m_zero)

ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS);
}
#endif
#endif
#endif
7 changes: 4 additions & 3 deletions utest/test_extensions/test_cgemm.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ static float check_cgemm(char transa, char transb, blasint m, blasint n, blasint
float alpha_conj[] = {1.0f, 0.0f};
char transa_verify = transa;
char transb_verify = transb;
char cc[2]="C", cr[2]="R";

int arows = k, acols = m;
int brows = n, bcols = k;
Expand All @@ -99,12 +100,12 @@ static float check_cgemm(char transa, char transb, blasint m, blasint n, blasint
data_cgemm.c_verify[i] = data_cgemm.c_test[i];

if (transa == 'R'){
cblas_cimatcopy(CblasColMajor, CblasConjNoTrans, arows, acols, alpha_conj, data_cgemm.a_verify, lda, lda);
BLASFUNC(cimatcopy)(cc, cr, &arows, &acols, alpha_conj, data_cgemm.a_verify, &lda, &lda);
transa_verify = 'N';
}

if (transb == 'R'){
cblas_cimatcopy(CblasColMajor, CblasConjNoTrans, brows, bcols, alpha_conj, data_cgemm.b_verify, ldb, ldb);
BLASFUNC(cimatcopy)(cc, cr, &brows, &bcols, alpha_conj, data_cgemm.b_verify, &ldb, &ldb);
transb_verify = 'N';
}

Expand Down Expand Up @@ -270,4 +271,4 @@ CTEST(cgemm, transa_conjnotransb)

ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS);
}
#endif
#endif
12 changes: 11 additions & 1 deletion utest/test_extensions/test_cgemmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ static void cgemmt_trusted(char api, enum CBLAS_ORDER order, char uplo, char tra
if(api == 'F')
BLASFUNC(cgemm)(&transa, &transb, &m, &m, &k, alpha, data_cgemmt.a_test, &lda,
data_cgemmt.b_test, &ldb, beta, data_cgemmt.c_gemm, &ldc);
#ifndef NO_CBLAS
else
cblas_cgemm(order, transa, transb, m, m, k, alpha, data_cgemmt.a_test, lda,
data_cgemmt.b_test, ldb, beta, data_cgemmt.c_gemm, ldc);
#endif

ldc *= 2;

Expand Down Expand Up @@ -160,9 +162,11 @@ static float check_cgemmt(char api, enum CBLAS_ORDER order, char uplo, char tran
if (api == 'F')
BLASFUNC(cgemmt)(&uplo, &transa, &transb, &m, &k, alpha, data_cgemmt.a_test,
&lda, data_cgemmt.b_test, &ldb, beta, data_cgemmt.c_test, &ldc);
#ifndef NO_CBLAS
else
cblas_cgemmt(order, uplo, transa, transb, m, k, alpha, data_cgemmt.a_test, lda,
data_cgemmt.b_test, ldb, beta, data_cgemmt.c_test, ldc);
#endif

for (i = 0; i < m * ldc * 2; i++)
data_cgemmt.c_verify[i] -= data_cgemmt.c_test[i];
Expand Down Expand Up @@ -197,9 +201,11 @@ static int check_badargs(char api, enum CBLAS_ORDER order, char uplo, char trans
if (api == 'F')
BLASFUNC(cgemmt)(&uplo, &transa, &transb, &m, &k, alpha, data_cgemmt.a_test,
&lda, data_cgemmt.b_test, &ldb, beta, data_cgemmt.c_test, &ldc);
#ifndef NO_CBLAS
else
cblas_cgemmt(order, uplo, transa, transb, m, k, alpha, data_cgemmt.a_test, lda,
data_cgemmt.b_test, ldb, beta, data_cgemmt.c_test, ldc);
#endif

return check_error();
}
Expand Down Expand Up @@ -680,6 +686,7 @@ CTEST(cgemmt, lower_beta_one)
ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS);
}

#ifndef NO_CBLAS
/**
* C API specific test
* Test cgemmt by comparing it against sgemm
Expand Down Expand Up @@ -1591,6 +1598,7 @@ CTEST(cgemmt, c_api_rowmajor_lower_beta_one)

ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS);
}
#endif

/**
* Fortran API specific test
Expand Down Expand Up @@ -1736,6 +1744,7 @@ CTEST(cgemmt, xerbla_ldc_invalid)
ASSERT_EQUAL(TRUE, passed);
}

#ifndef NO_CBLAS
/**
* C API specific test.
* Test error function for an invalid param order.
Expand Down Expand Up @@ -2007,4 +2016,5 @@ CTEST(cgemmt, xerbla_c_api_rowmajor_ldc_invalid)
M, K, lda, ldb, ldc, expected_info);
ASSERT_EQUAL(TRUE, passed);
}
#endif
#endif
#endif
9 changes: 7 additions & 2 deletions utest/test_extensions/test_cgemv_t.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ static struct DATA_CGEMV_T data_cgemv_t;
static void matrix_vector_product(blasint n, blasint m, blasint lda, blasint inc_x)
{
blasint i;
blasint one=1;
float *a_ptr = data_cgemv_t.a_verify;
float *x_ptr = data_cgemv_t.x_test;
float *x_res = data_cgemv_t.x_verify;
Expand All @@ -73,7 +74,7 @@ static void matrix_vector_product(blasint n, blasint m, blasint lda, blasint inc

for (i = 0; i < n * inc_x; i+= inc_x)
{
result = cblas_cdotu(lda, a_ptr, 1, x_ptr, inc_x);
result = BLASFUNC(cdotu)(&lda, a_ptr, &one, x_ptr, &inc_x);
x_res[0] = CREAL(result);
x_res[1] = CIMAG(result);
a_ptr += lda * 2;
Expand Down Expand Up @@ -153,6 +154,7 @@ static float check_cgemv(char api, char order, char trans, blasint m, blasint n,
BLASFUNC(cgemv)(&trans, &m, &n, alpha, data_cgemv_t.a_test,
&lda, data_cgemv_t.x_test, &inc_x, beta, data_cgemv_t.y_test, &inc_y);
}
#ifndef NO_CBLAS
else {
if (order == 'C') corder = CblasColMajor;
if (order == 'R') corder = CblasRowMajor;
Expand All @@ -173,13 +175,14 @@ static float check_cgemv(char api, char order, char trans, blasint m, blasint n,
cblas_cgemv(corder, ctrans, m, n, alpha, data_cgemv_t.a_test,
lda, data_cgemv_t.x_test, inc_x, beta, data_cgemv_t.y_test, inc_y);
}
#endif

// Find the differences between output vector caculated by cgemv and reference funcs
for (i = 0; i < m * inc_y * 2; i++)
data_cgemv_t.y_test[i] -= data_cgemv_t.y_verify[i];

// Find the norm of differences
return cblas_scnrm2(m, data_cgemv_t.y_test, inc_y);
return BLASFUNC(scnrm2)(&m, data_cgemv_t.y_test, &inc_y);
}

/**
Expand Down Expand Up @@ -213,6 +216,7 @@ static int check_badargs(char order, char trans, blasint m, blasint n,
return check_error();
}

#ifndef NO_CBLAS
/**
* C API specific function
* Check if error function was called with expected function name
Expand Down Expand Up @@ -1130,3 +1134,4 @@ CTEST(cgemv, c_api_xerbla_invalid_order_col_major)
ASSERT_EQUAL(TRUE, passed);
}
#endif
#endif
6 changes: 5 additions & 1 deletion utest/test_extensions/test_cimatcopy.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ static float check_cimatcopy(char api, char order, char trans, blasint rows, bla
BLASFUNC(cimatcopy)(&order, &trans, &rows, &cols, alpha, data_cimatcopy.a_test,
&lda_src, &lda_dst);
}
#ifndef NO_CBLAS
else {
if (order == 'C') corder = CblasColMajor;
if (order == 'R') corder = CblasRowMajor;
Expand All @@ -108,6 +109,7 @@ static float check_cimatcopy(char api, char order, char trans, blasint rows, bla
cblas_cimatcopy(corder, ctrans, rows, cols, alpha, data_cimatcopy.a_test,
lda_src, lda_dst);
}
#endif

// Find the differences between output matrix computed by cimatcopy and reference func
return smatrix_difference(data_cimatcopy.a_test, data_cimatcopy.a_verify, cols_out, rows_out, 2*lda_dst);
Expand Down Expand Up @@ -502,6 +504,7 @@ CTEST(cimatcopy, rowmajor_conjtrans_col_50_row_100)
ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS);
}

#ifndef NO_CBLAS
/**
* C API specific test
* Test cimatcopy by comparing it against reference
Expand Down Expand Up @@ -681,6 +684,7 @@ CTEST(cimatcopy, c_api_rowmajor_conjtrans_col_100_row_100)

ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS);
}
#endif

/**
* Test error function for an invalid param order.
Expand Down Expand Up @@ -815,4 +819,4 @@ CTEST(cimatcopy, xerbla_colmajor_trans_invalid_ldb)
int passed = check_badargs(order, trans, m, n, lda_src, lda_dst, expected_info);
ASSERT_EQUAL(TRUE, passed);
}
#endif
#endif
4 changes: 4 additions & 0 deletions utest/test_extensions/test_comatcopy.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ static float check_comatcopy(char api, char order, char trans, blasint rows, bla
BLASFUNC(comatcopy)(&order, &trans, &rows, &cols, alpha, data_comatcopy.a_test,
&lda, data_comatcopy.b_test, &ldb);
}
#ifndef NO_CBLAS
else {
if (order == 'C') corder = CblasColMajor;
if (order == 'R') corder = CblasRowMajor;
Expand All @@ -109,6 +110,7 @@ static float check_comatcopy(char api, char order, char trans, blasint rows, bla
cblas_comatcopy(corder, ctrans, rows, cols, alpha, data_comatcopy.a_test,
lda, data_comatcopy.b_test, ldb);
}
#endif

return smatrix_difference(data_comatcopy.b_test, data_comatcopy.b_verify, b_cols, b_rows, ldb*2);
}
Expand Down Expand Up @@ -316,6 +318,7 @@ CTEST(comatcopy, rowmajor_conjtrans_col_100_row_100)
ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS);
}

#ifndef NO_CBLAS
/**
* C API specific test
* Test comatcopy by comparing it against refernce
Expand Down Expand Up @@ -491,6 +494,7 @@ CTEST(comatcopy, c_api_rowmajor_conjtrans_col_100_row_100)

ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS);
}
#endif

/**
* Test error function for an invalid param order.
Expand Down
4 changes: 3 additions & 1 deletion utest/test_extensions/test_crot.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ static float check_csrot(blasint n, blasint inc_x, blasint inc_y, float *c, floa
return (norm / 2);
}

#ifndef NO_CBLAS
/**
* C API specific function
* Comapare results computed by csrot and caxpby
Expand Down Expand Up @@ -789,4 +790,5 @@ CTEST(crot, c_api_check_n_zero)
float norm = c_api_check_csrot(n, inc_x, inc_y, c, s);
ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS);
}
#endif
#endif
#endif
5 changes: 3 additions & 2 deletions utest/test_extensions/test_crotg.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ CTEST(crotg, negative_real_negative_img)
ASSERT_DBL_NEAR_TOL(-5.26498f, sa[0], SINGLE_EPS);
ASSERT_DBL_NEAR_TOL(-7.01997f, sa[1], SINGLE_EPS);
}

#ifndef NO_CBLAS
/**
* C API specific test
* Test crotg by comparing it against pre-calculated values
Expand Down Expand Up @@ -287,4 +287,5 @@ CTEST(crotg, c_api_negative_real_negative_img)
ASSERT_DBL_NEAR_TOL(-5.26498f, sa[0], SINGLE_EPS);
ASSERT_DBL_NEAR_TOL(-7.01997f, sa[1], SINGLE_EPS);
}
#endif
#endif
#endif
Loading

0 comments on commit f0560f9

Please sign in to comment.