diff --git a/frame/compat/cblas/src/cblas.h b/frame/compat/cblas/src/cblas.h index 21f14fbda..093da7fc4 100644 --- a/frame/compat/cblas/src/cblas.h +++ b/frame/compat/cblas/src/cblas.h @@ -1,3 +1,33 @@ +/* + + Copyright (C) 2020, Advanced Micro Devices, Inc. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + - Neither the name(s) of the copyright holder(s) nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ + #ifndef CBLAS_H #define CBLAS_H #include @@ -605,6 +635,16 @@ void BLIS_EXPORT_BLAS cblas_zher2k(enum CBLAS_ORDER Order, enum CBLAS_UPLO Uplo, void BLIS_EXPORT_BLAS cblas_xerbla(f77_int p, const char *rout, const char *form, ...); +/* + * =========================================================================== + * Prototypes for Aux Functions BLAS + * =========================================================================== + */ + +BLIS_EXPORT_BLAS float cblas_scabs1( const void *z); + +BLIS_EXPORT_BLAS double cblas_dcabs1( const void *z); + #ifdef __cplusplus } #endif diff --git a/frame/compat/cblas/src/cblas_dcabs1.c b/frame/compat/cblas/src/cblas_dcabs1.c new file mode 100644 index 000000000..63d25cda0 --- /dev/null +++ b/frame/compat/cblas/src/cblas_dcabs1.c @@ -0,0 +1,52 @@ +/* + Copyright (C) 2020, Advanced Micro Devices, Inc. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + - Neither the name(s) of the copyright holder(s) nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ + +#include "blis.h" +#ifdef BLIS_ENABLE_CBLAS + +/* + * cblas_dcabs1.c + * + * The program is a C interface to dcabs1. + * + */ + +#include "cblas.h" +#include "cblas_f77.h" + +// double cblas_dcabs1 (const void *z); +// result = |Re(z)|+|Im(z)|, +// where z is a complex number, and +// this function returns sum of abs(re(z)) & abs(im(z)) + +double cblas_dcabs1( const void *z ) +{ + return F77_dcabs1( (dcomplex*)z ); +} +#endif \ No newline at end of file diff --git a/frame/compat/cblas/src/cblas_f77.h b/frame/compat/cblas/src/cblas_f77.h index 7e4db4940..d4b41d8d3 100644 --- a/frame/compat/cblas/src/cblas_f77.h +++ b/frame/compat/cblas/src/cblas_f77.h @@ -175,4 +175,10 @@ #define F77_cgemmt cgemmt_ #define F77_zgemmt zgemmt_ +/* +* Aux Function +*/ +#define F77_scabs1 scabs1_ +#define F77_dcabs1 dcabs1_ + #endif /* CBLAS_F77_H */ diff --git a/frame/compat/cblas/src/cblas_scabs1.c b/frame/compat/cblas/src/cblas_scabs1.c new file mode 100644 index 000000000..5eea790ee --- /dev/null +++ b/frame/compat/cblas/src/cblas_scabs1.c @@ -0,0 +1,50 @@ +/* + Copyright (C) 2020, Advanced Micro Devices, Inc. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + - Neither the name(s) of the copyright holder(s) nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ + +#include "blis.h" +#ifdef BLIS_ENABLE_CBLAS +/* + * cblas_scabs1.c + * + * The program is a C interface to scabs1. + * + */ +#include "cblas.h" +#include "cblas_f77.h" + +// float cblas_scabs1 (const void *z); +// result = |Re(z)|+|Im(z)|, +// where z is a complex number, and +// this function returns sum of abs(re(z)) & abs(im(z)) + +float cblas_scabs1( const void *z ) +{ + return F77_scabs1( (scomplex*) z ); +} +#endif \ No newline at end of file diff --git a/frame/compat/f2c/bla_cabs1.c b/frame/compat/f2c/bla_cabs1.c index 59459f2fe..6f2915670 100644 --- a/frame/compat/f2c/bla_cabs1.c +++ b/frame/compat/f2c/bla_cabs1.c @@ -5,6 +5,7 @@ libraries. Copyright (C) 2014, The University of Texas at Austin + Copyright (C) 2020, Advanced Micro Devices, Inc. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are @@ -43,8 +44,17 @@ /* Subroutine */ bla_real PASTEF77(s,cabs1)(bla_scomplex *z) { - return bli_fabs( bli_creal( *z ) ) + - bli_fabs( bli_cimag( *z ) ); + if ( bli_creal(*z) == 0.0f && bli_cimag(*z) == 0.0f ) + { + /*If input is zero, return zero. + As the else part returns -0.0 */ + return 0.0f; + } + else + { + return bli_fabs( bli_creal( *z ) ) + + bli_fabs( bli_cimag( *z ) ); /* code */ + } } /* scabs1_ */ /* dcabs1.f -- translated by f2c (version 19991025). @@ -54,8 +64,18 @@ /* Subroutine */ bla_double PASTEF77(d,cabs1)(bla_dcomplex *z) { - return bli_fabs( bli_zreal( *z ) ) + + if ( bli_creal(*z) == 0.0 && bli_cimag(*z) == 0.0 ) + { + /*If input is zero, return zero. + As the else part returns -0.0 */ + return 0.0; + } + else + { + return bli_fabs( bli_zreal( *z ) ) + bli_fabs( bli_zimag( *z ) ); + } + } /* dcabs1_ */ #endif diff --git a/test/Makefile b/test/Makefile index 7a486860f..87439d73a 100644 --- a/test/Makefile +++ b/test/Makefile @@ -178,7 +178,8 @@ CFLAGS += -I$(TEST_SRC_PATH) #all: blis openblas atlas mkl all: blis openblas mkl -blis: check-env \ +blis: check-env \ + test_cabs1_blis.x \ test_dotv_blis.x \ test_axpyv_blis.x \ test_axpbyv_blis.x \ @@ -202,6 +203,7 @@ blis: check-env \ test_trsm_blis.x openblas: check-env \ + test_cabs1_openblas.x \ test_dotv_openblas.x \ test_axpyv_openblas.x \ test_axpbyv_openblas.x \ @@ -246,6 +248,7 @@ atlas: check-env \ test_trsm_atlas.x mkl: check-env \ + test_cabs1_mkl.x \ test_dotv_mkl.x \ test_axpyv_mkl.x \ test_axpbyv_mkl.x \ diff --git a/test/test_cabs1.c b/test/test_cabs1.c new file mode 100644 index 000000000..4b325bdd5 --- /dev/null +++ b/test/test_cabs1.c @@ -0,0 +1,120 @@ +/* + + BLIS + An object-based framework for developing high-performance BLAS-like + libraries. + + Copyright (C) 2020, 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 + met: + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + - Neither the name(s) of the copyright holder(s) nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ + +#include +#include "blis.h" +#include + +#define PRINT +#define FLOAT +#define CHECK_CBLAS // Macro to test cblas interface of the function cblas?cabs1 + +#ifdef CHECK_CBLAS +#include "cblas.h" +#endif + +int main(int argc, char**argv) +{ + /* initialize random seed: */ + srand (time(NULL)); + + int r, n_repeats; + n_repeats = 5; + +#ifdef FLOAT + + float z_abs = 0.0f; + +#else + + double z_abs = 0.0; + +#endif + + for ( r = 0; r < n_repeats; ++r ) + { + +#ifdef FLOAT + + float maxRandVal = 1000.0f; + scomplex inp; + inp.real = ((float)rand()/(float)(RAND_MAX)) * maxRandVal - maxRandVal/2; + inp.imag = ((float)rand()/(float)(RAND_MAX)) * maxRandVal - maxRandVal/2; + +#ifdef BLIS + printf( "data_scabs1_BLIS"); +#else + printf( "data_scabs1_%s", BLAS ); +#endif + +#else + + double maxRandVal = 1000.0; + dcomplex inp; + inp.real = ((double)rand()/(double)(RAND_MAX)) * maxRandVal - maxRandVal/2; + inp.imag = ((double)rand()/(double)(RAND_MAX)) * maxRandVal - maxRandVal/2; + +#ifdef BLIS + printf( "data_dcabs1_BLIS"); +#else + printf( "data_dcabs1_%s", BLAS ); +#endif + +#endif + +#ifdef FLOAT + + #ifdef CHECK_CBLAS + z_abs = cblas_scabs1( &inp ); + #else + z_abs = scabs1_( &inp ); + #endif + +#else + + #ifdef CHECK_CBLAS + z_abs = cblas_dcabs1( &inp ); + #else + z_abs = dcabs1_( &inp ); + #endif + +#endif + + printf("inp = %lf + %lf i , cabs1 result = %lf \n", + inp.real, inp.imag, z_abs); + + } + + return 0; +}