Files
blis/bench/bench_scalv.c
Edward Smyth 82bdf7c8c7 Code cleanup: Copyright notices
- Standardize formatting (spacing etc).
- Add full copyright to cmake files (excluding .json)
- Correct copyright and disclaimer text for frame and
  zen, skx and a couple of other kernels to cover all
  contributors, as is commonly used in other files.
- Fixed some typos and missing lines in copyright
  statements.

AMD-Internal: [CPUPL-4415]
Change-Id: Ib248bb6033c4d0b408773cf0e2a2cda6c2a74371
2024-08-05 15:35:08 -04:00

308 lines
9.2 KiB
C

/*
BLIS
An object-based framework for developing high-performance BLAS-like
libraries.
Copyright (C) 2021 - 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
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.
*/
#ifdef WIN32
#include <io.h>
#else
#include <unistd.h>
#endif
#include "blis.h"
// Benchmark application to process aocl logs generated by BLIS library.
#ifndef DT
#define DT BLIS_DOUBLE
#endif
#define AOCL_MATRIX_INITIALISATION
//#define BLIS_ENABLE_CBLAS
/* For BLIS since logs are collected at BLAS interfaces
* we disable cblas interfaces for this benchmark application
*/
/* #ifdef BLIS_ENABLE_CBLAS */
/* #define CBLAS */
/* #endif */
int main( int argc, char** argv )
{
obj_t x, x_save;
obj_t alpha;
dim_t p_inc = 0; // to keep track of number of inputs
num_t dt_x, dt_alpha;
char dt_ch_x, dt_ch_alpha;
int r, n_repeats;
double dtime;
double dtime_save;
double gflops;
FILE* fin = NULL;
FILE* fout = NULL;
n_repeats = N_REPEAT; // This macro will get from Makefile.
dt_x = DT;
dt_alpha = DT;
if (argc < 3)
{
printf("Usage: ./test_scalv_XX.x input.csv output.csv\n");
exit(1);
}
fin = fopen(argv[1], "r");
if (fin == NULL)
{
printf("Error opening the file %s\n", argv[1]);
exit(1);
}
fout = fopen(argv[2], "w");
if (fout == NULL)
{
printf("Error opening output file %s\n", argv[2]);
exit(1);
}
fprintf(fout, "Func Dt alphaR alphaI n incx gflops\n");
dim_t n;
double alpha_r, alpha_i;
inc_t incx;
char dt_ch[3]; // to store the API datatype
char tmp[256]; // to store function name, line no present in logs.
// {S,D,C,Z} {alpha n incx}
while (fscanf(fin, "%s %s %lf %lf " INT_FS INT_FS "\n",
tmp, dt_ch, &alpha_r, &alpha_i, &n, &incx) == 6)
{
dt_ch[2] = '\0'; // Null terminating the string for logging purpose
#ifdef PRINT
fprintf (stdout, "Input = %s %s %lf %lf %ld %ld\n",
tmp, dt_ch, alpha_r, alpha_i, n, incx);
#endif
// Acquiring the datatype of input vector x
dt_ch_x = dt_ch[0];
if (dt_ch_x == 'D' || dt_ch_x == 'd') dt_x = BLIS_DOUBLE;
else if (dt_ch_x == 'Z' || dt_ch_x == 'z') dt_x = BLIS_DCOMPLEX;
else if (dt_ch_x == 'S' || dt_ch_x == 's') dt_x = BLIS_FLOAT;
else if (dt_ch_x == 'C' || dt_ch_x == 'c') dt_x = BLIS_SCOMPLEX;
else
{
printf("Invalid data type %c\n", dt_ch_x);
continue;
}
// Acquiring the datatype of input scalar alpha
dt_ch_alpha = dt_ch[1];
if (dt_ch_alpha == 'D' || dt_ch_alpha == 'd') dt_alpha = BLIS_DOUBLE;
else if (dt_ch_alpha == 'S' || dt_ch_alpha == 's') dt_alpha = BLIS_FLOAT;
else if(dt_ch_alpha == '\0') dt_alpha = dt_x;
else
{
printf("Invalid data type %c\n", dt_ch_alpha);
continue;
}
// Create objects with required sizes and strides.
// ger operation is defined as
//
// The ?scal routines perform a vector operation defined as
// X = a*X
//
// where:
// a is a scalar
// X is an n-element vector.
bli_obj_create( dt_x, n, 1, incx, 1, &x );
bli_obj_create( dt_x, n, 1, incx, 1, &x_save );
#ifdef AOCL_MATRIX_INITIALISATION
bli_randm( &x );
#endif
bli_obj_create( dt_alpha, 1, 1, 0, 0, &alpha );
bli_setsc( alpha_r, alpha_i, &alpha );
bli_copym( &x, &x_save );
dtime_save = DBL_MAX;
for ( r = 0; r < n_repeats; ++r )
{
bli_copym( &x_save, &x );
#ifdef PRINT
bli_printm( "x", &x, "%4.1f", "" );
#endif
dtime = bli_clock();
#ifdef BLIS
bli_scalv(&alpha, &x);
#else // BLIS Interface
// Set data type independent inputs for BLAS and
// CBLAS API's
f77_int nn = bli_obj_length( &x );
f77_int blas_incx = bli_obj_vector_inc( &x );
if ( bli_is_float( dt_x ) && bli_is_float( dt_alpha ) ){
float* xp = bli_obj_buffer( &x );
float* scalar = bli_obj_buffer( &alpha );
#ifdef CBLAS
cblas_sscal( nn,
*scalar,
xp, blas_incx );
#else // cblas sscal
sscal_( &nn, scalar,
xp, &blas_incx );
#endif // cblas sscal
}
else if ( bli_is_double( dt_x ) && bli_is_double( dt_alpha ) )
{
double* xp = bli_obj_buffer( &x );
double* scalar = bli_obj_buffer( &alpha );
#ifdef CBLAS
cblas_dscal( nn,
*scalar,
xp, blas_incx );
#else // cblas dscal
dscal_( &nn, scalar,
xp, &blas_incx );
#endif // cblas dscal
}
else if ( bli_is_scomplex( dt_x ) && bli_is_scomplex( dt_alpha ) )
{
scomplex* xp = bli_obj_buffer( &x );
scomplex* scalar = bli_obj_buffer( &alpha );
#ifdef CBLAS
cblas_cscal( nn,
scalar,
xp, blas_incx );
#else // cblas cscal
cscal_( &nn, scalar,
xp, &blas_incx );
#endif // cblas cscal
}
else if ( bli_is_dcomplex( dt_x ) && bli_is_dcomplex( dt_alpha ) )
{
dcomplex* xp = bli_obj_buffer( &x );
dcomplex* scalar = bli_obj_buffer( &alpha );
#ifdef CBLAS
cblas_zscal( nn,
scalar,
xp, blas_incx );
#else // cblas zscal
zscal_( &nn, scalar,
xp, &blas_incx );
#endif // cblas zscal
}
else if ( bli_is_scomplex( dt_x ) && bli_is_float( dt_alpha ) )
{
scomplex* xp = bli_obj_buffer( &x );
float* scalar = bli_obj_buffer( &alpha );
#ifdef CBLAS
cblas_csscal( nn,
*scalar,
xp, blas_incx );
#else // cblas csscal
csscal_( &nn, scalar,
xp, &blas_incx );
#endif // cblas csscal
}
else if ( bli_is_dcomplex( dt_x ) && bli_is_double( dt_alpha ) )
{
dcomplex* xp = bli_obj_buffer( &x );
double* scalar = bli_obj_buffer( &alpha );
#ifdef CBLAS
cblas_zdscal( nn,
*scalar,
xp, blas_incx );
#else // cblas zdscal
zdscal_( &nn, scalar,
xp, &blas_incx );
#endif // cblas zdscal
}
#endif // BLIS Interface
#ifdef PRINT
bli_printm( "x after", &x "%4.1f", "" );
exit(1);
#endif
dtime_save = bli_clock_min_diff( dtime_save, dtime );
}
gflops = n / ( dtime_save * 1.0e9 );
if ( bli_is_complex( dt_x ) )
{
if( bli_is_complex( dt_alpha ) ) gflops *= 4.0;
else if( bli_is_real( dt_alpha ) ) gflops *= 2.0;
}
printf( "data_scalv_%s", BLAS );
p_inc++;
printf("( %2lu, 1:4 ) = [ %4lu %7.2f ];\n",
(unsigned long)(p_inc),
(unsigned long)n,
gflops);
fprintf (fout, "%s %s %lf %lf %ld %ld %6.3f\n",
tmp, dt_ch, alpha_r, alpha_i, n, incx, gflops);
fflush(fout);
bli_obj_free( &alpha );
bli_obj_free( &x );
bli_obj_free( &x_save);
}
//bli_finalize();
fclose(fin);
fclose(fout);
return 0;
}