BLIS: CBLAS Extensions. cblas_?cabs1 : Absolute value of a complex number cabs1

Details:
   - added cblas extension cblas_?cabs1.
   - Functionality : res=|Re(z)|+|Im(z)|, z is a complex number, and res is a      value containing the absolute value of a complex number z.

AMD-Internal: [CPUPL-1129]

Change-Id: I4a3c265c89527c8fd3060c5d2ed38b1953ce6343
This commit is contained in:
Nageshwar Singh
2020-09-03 13:08:48 +05:30
parent 80828f6fda
commit 5243da5cec
7 changed files with 295 additions and 4 deletions

View File

@@ -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 <stddef.h>
@@ -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

View File

@@ -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

View File

@@ -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 */

View File

@@ -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

View File

@@ -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

View File

@@ -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 \

120
test/test_cabs1.c Normal file
View File

@@ -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 <unistd.h>
#include "blis.h"
#include <time.h>
#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;
}