1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
// Copyright (c) 2017-2023, University of Tennessee. All rights reserved.
// SPDX-License-Identifier: BSD-3-Clause
// This program is free software: you can redistribute it and/or modify it under
// the terms of the BSD 3-Clause license. See the accompanying LICENSE file.
#include "test.hh"
#include "cblas_wrappers.hh"
#include "lapack_wrappers.hh"
#include "blas/flops.hh"
#include "print_matrix.hh"
#include "check_gemm.hh"
// -----------------------------------------------------------------------------
template <typename TA, typename TX, typename TY>
void test_geru_work( Params& params, bool run )
{
using namespace testsweeper;
using std::real;
using std::imag;
using blas::Layout;
using scalar_t = blas::scalar_type< TA, TX, TY >;
using real_t = blas::real_type< scalar_t >;
// get & mark input values
blas::Layout layout = params.layout();
scalar_t alpha = params.alpha.get<scalar_t>();
int64_t m = params.dim.m();
int64_t n = params.dim.n();
int64_t incx = params.incx();
int64_t incy = params.incy();
int64_t align = params.align();
int64_t verbose = params.verbose();
// mark non-standard output values
params.gflops();
params.gbytes();
params.ref_time();
params.ref_gflops();
params.ref_gbytes();
// adjust header to msec
params.time.name( "time (ms)" );
params.ref_time.name( "ref time (ms)" );
params.ref_time.width( 13 );
if (! run)
return;
// setup
int64_t Am = (layout == Layout::ColMajor ? m : n);
int64_t An = (layout == Layout::ColMajor ? n : m);
int64_t lda = roundup( Am, align );
size_t size_A = size_t(lda)*An;
size_t size_x = (m - 1) * std::abs(incx) + 1;
size_t size_y = (n - 1) * std::abs(incy) + 1;
TA* A = new TA[ size_A ];
TA* Aref = new TA[ size_A ];
TX* x = new TX[ size_x ];
TX* y = new TX[ size_y ];
int64_t idist = 1;
int iseed[4] = { 0, 0, 0, 1 };
lapack_larnv( idist, iseed, size_A, A );
lapack_larnv( idist, iseed, size_x, x );
lapack_larnv( idist, iseed, size_y, y );
lapack_lacpy( "g", Am, An, A, lda, Aref, lda );
// norms for error check
real_t work[1];
real_t Anorm = lapack_lange( "f", Am, An, A, lda, work );
real_t Xnorm = cblas_nrm2( m, x, std::abs(incx) );
real_t Ynorm = cblas_nrm2( n, y, std::abs(incy) );
// test error exits
assert_throw( blas::geru( Layout(0), m, n, alpha, A, lda, x, incx, y, incy ), blas::Error );
assert_throw( blas::geru( layout, -1, n, alpha, A, lda, x, incx, y, incy ), blas::Error );
assert_throw( blas::geru( layout, m, -1, alpha, A, lda, x, incx, y, incy ), blas::Error );
assert_throw( blas::geru( Layout::ColMajor, m, n, alpha, A, m-1, x, incx, y, incy ), blas::Error );
assert_throw( blas::geru( Layout::RowMajor, m, n, alpha, A, n-1, x, incx, y, incy ), blas::Error );
assert_throw( blas::geru( layout, m, n, alpha, A, lda, x, 0, y, incy ), blas::Error );
assert_throw( blas::geru( layout, m, n, alpha, A, lda, x, incx, y, 0 ), blas::Error );
if (verbose >= 1) {
printf( "\n"
"A Am=%5lld, An=%5lld, lda=%5lld, size=%10lld, norm=%.2e\n"
"x Xm=%5lld, inc=%5lld, size=%10lld, norm=%.2e\n"
"y Ym=%5lld, inc=%5lld, size=%10lld, norm=%.2e\n",
llong( Am ), llong( An ), llong( lda ), llong( size_A ), Anorm,
llong( m ), llong( incx ), llong( size_x ), Xnorm,
llong( n ), llong( incy ), llong( size_y ), Ynorm );
}
if (verbose >= 2) {
printf( "alpha = %.4e + %.4ei;\n",
real(alpha), imag(alpha) );
printf( "A = " ); print_matrix( Am, An, A, lda );
printf( "x = " ); print_vector( m, x, incx );
printf( "y = " ); print_vector( n, y, incy );
}
// run test
testsweeper::flush_cache( params.cache() );
double time = get_wtime();
blas::geru( layout, m, n, alpha, x, incx, y, incy, A, lda );
time = get_wtime() - time;
double gflop = blas::Gflop< scalar_t >::ger( m, n );
double gbyte = blas::Gbyte< scalar_t >::ger( m, n );
params.time() = time * 1000; // msec
params.gflops() = gflop / time;
params.gbytes() = gbyte / time;
if (verbose >= 2) {
printf( "A2 = " ); print_matrix( Am, An, A, lda );
}
if (params.check() == 'y') {
// run reference
testsweeper::flush_cache( params.cache() );
time = get_wtime();
cblas_geru( cblas_layout_const(layout), m, n, alpha, x, incx, y, incy, Aref, lda );
time = get_wtime() - time;
params.ref_time() = time * 1000; // msec
params.ref_gflops() = gflop / time;
params.ref_gbytes() = gbyte / time;
if (verbose >= 2) {
printf( "Aref = " ); print_matrix( Am, An, Aref, lda );
}
// check error compared to reference
// beta = 1
real_t error;
bool okay;
check_gemm( Am, An, 1, alpha, scalar_t(1), Xnorm, Ynorm, Anorm,
Aref, lda, A, lda, verbose, &error, &okay );
params.error() = error;
params.okay() = okay;
}
delete[] A;
delete[] Aref;
delete[] x;
delete[] y;
}
// -----------------------------------------------------------------------------
void test_geru( Params& params, bool run )
{
switch (params.datatype()) {
case testsweeper::DataType::Single:
test_geru_work< float, float, float >( params, run );
break;
case testsweeper::DataType::Double:
test_geru_work< double, double, double >( params, run );
break;
case testsweeper::DataType::SingleComplex:
test_geru_work< std::complex<float>, std::complex<float>,
std::complex<float> >( params, run );
break;
case testsweeper::DataType::DoubleComplex:
test_geru_work< std::complex<double>, std::complex<double>,
std::complex<double> >( params, run );
break;
default:
throw std::exception();
break;
}
}
|