From ee91b032ab8cb280a220bdd2767cb385f97aa6bb Mon Sep 17 00:00:00 2001 From: Edward Smyth Date: Wed, 31 Jan 2024 11:25:32 -0500 Subject: [PATCH] GTestSuite: Ensure all elements are initialized in generators Rather than relying on implicit initialization of arrays, ensure all elements are explicitly set. Array elements that are not supposed to be altered by the BLAS or BLIS API are set to a large magnitude value to aid identication of incorrect usage. This includes: - Intervening elements in vectors when incx/incy > 1. - Extra elements in column/row when lda > matrix size. - Also set unused upper/lower values in triangular matrices to similar large magnitude value. AMD-Internal: [CPUPL-4430] Change-Id: Id5e8c1a4e80687f5f462e6b5aa2accac0ab8ec21 --- .../inc/common/data_generators.h | 256 ++++++++++-------- 1 file changed, 142 insertions(+), 114 deletions(-) diff --git a/gtestsuite/testinghelpers/inc/common/data_generators.h b/gtestsuite/testinghelpers/inc/common/data_generators.h index af3606c77..600f36eb4 100644 --- a/gtestsuite/testinghelpers/inc/common/data_generators.h +++ b/gtestsuite/testinghelpers/inc/common/data_generators.h @@ -83,6 +83,20 @@ void getfp(T2 from, T3 to, gtint_t n, gtint_t incx, T1* x) { using real_T = typename testinghelpers::type_info::real_type; T1* chi; + + if (incx != 1) + { + // First initialize all elements in vector to unusual value to help + // catch if intervening elements have been incorrectly used or modified. + for ( gtint_t i = 0; i < testinghelpers::buff_dim(n, incx); ++i ) + { + chi = x + i; + *chi = T1{-1.2345e38}; + } + } + + // Generate the values from the uniform distribution that + // the BLAS routine should read and/or modify. std::mt19937 generator(94); std::uniform_real_distribution distr(from, to); for ( gtint_t i = 0; i < n; ++i ) @@ -110,32 +124,52 @@ void getfp(T2 from, T3 to, char storage, gtint_t m, gtint_t n, T1* a, gtint_t ld std::mt19937 generator(1994); std::uniform_real_distribution distr(from, to); - gtint_t inca; - gtint_t n_iter; - gtint_t n_elem; - gtint_t j; - - // Initialize with optimal values for column-major storage. - inca = 1; - n_iter = n; - n_elem = m; - - // An optimization: if A is row-major, then let's access the matrix by - // rows instead of by columns for increased spatial locality. - if( (storage == 'r') || (storage == 'R') ) + if((storage == 'c') || (storage == 'C')) { - swap_dims( &n_iter, &n_elem ); - swap_dims( &lda, &inca ); - } - - for ( j = 0; j < n_iter; j++ ) - { - for(gtint_t i=0; i::is_real) - a[j+i*inca] = real_T(distr(generator)); + { + for(gtint_t i=0; i::is_real) + { + for(gtint_t j=0; j void getfp(T2 from, T3 to, char storage, gtint_t m, gtint_t n, T1* a, char transa, gtint_t lda ) { - using real_T = typename testinghelpers::type_info::real_type; - std::mt19937 generator(1994); - std::uniform_real_distribution distr(from, to); - if( chktrans( transa )) { swap_dims( &m, &n ); } - - if((storage == 'c') || (storage == 'C')) - { - for(gtint_t i=0; i::is_real) - a[i+j*lda] = real_T(distr(generator)); - else - a[i+j*lda] = {real_T(distr(generator)), real_T(distr(generator))}; - } - } - } - else if( (storage == 'r') || (storage == 'R') ) - { - for(gtint_t j=0; j::is_real) - a[j+i*lda] = real_T(distr(generator)); - else - a[j+i*lda] = {real_T(distr(generator)), real_T(distr(generator))}; - } - } - } + getfp( from, to, storage, m, n, a, lda); } /*************************************************** @@ -219,6 +223,20 @@ void getint(int from, int to, gtint_t n, gtint_t incx, T* x) { using real_T = typename testinghelpers::type_info::real_type; T* chi; + + if (incx != 1) + { + // First initialize all elements in vector to unusual value to help + // catch if intervening elements have been incorrectly used or modified. + for ( gtint_t i = 0; i < testinghelpers::buff_dim(n, incx); ++i ) + { + chi = x + i; + *chi = T{-1.2345e38}; + } + } + + // Generate the values from the uniform distribution that + // the BLAS routine should read and/or modify. std::mt19937 generator(94); std::uniform_int_distribution distr(from, to); for ( gtint_t i = 0; i < n; ++i ) @@ -246,32 +264,52 @@ void getint(int from, int to, char storage, gtint_t m, gtint_t n, T* a, gtint_t std::mt19937 generator(94); std::uniform_int_distribution distr(from, to); - gtint_t inca; - gtint_t n_iter; - gtint_t n_elem; - gtint_t j; - - // Initialize with optimal values for column-major storage. - inca = 1; - n_iter = n; - n_elem = m; - - // An optimization: if A is row-major, then let's access the matrix by - // rows instead of by columns for increased spatial locality. - if( (storage == 'r') || (storage == 'R') ) + if((storage == 'c') || (storage == 'C')) { - swap_dims( &n_iter, &n_elem ); - swap_dims( &lda, &inca ); - } - - for ( j = 0; j < n_iter; j++ ) - { - for(gtint_t i=0; i::is_real) - a[j+i*inca] = real_T(distr(generator)); + { + for(gtint_t i=0; i::is_real) + { + for(gtint_t j=0; j void getint(int from, int to, char storage, gtint_t m, gtint_t n, T* a, char transa, gtint_t lda ) { - using real_T = typename testinghelpers::type_info::real_type; - std::mt19937 generator(1994); - std::uniform_int_distribution distr(from, to); - if( chktrans( transa )) { swap_dims( &m, &n ); } - - if((storage == 'c') || (storage == 'C')) - { - for(gtint_t i=0; i::is_real) - a[i+j*lda] = real_T(distr(generator)); - else - a[i+j*lda] = {real_T(distr(generator)), real_T(distr(generator))}; - } - } - } - else if( (storage == 'r') || (storage == 'R') ) - { - for(gtint_t j=0; j::is_real) - a[j+i*lda] = real_T(distr(generator)); - else - a[j+i*lda] = {real_T(distr(generator)), real_T(distr(generator))}; - } - } - } + getint( from, to, storage, m, n, a, lda); } template @@ -365,11 +373,11 @@ void randomgenerators( T2 from, T3 to, char storage, char uplo, gtint_t k, { if( (uplo=='u')||(uplo=='U') ) { - if(i>j) a[i+j*lda] = T1{0}; + if(i>j) a[i+j*lda] = T1{2.987e38}; } else if ( (uplo=='l')||(uplo=='L') ) { - if (ij) a[j+i*lda] = T1{0}; + if(i>j) a[j+i*lda] = T1{2.987e38}; } else if ( (uplo=='l')||(uplo=='L') ) { - if (i void set_vector( gtint_t n, gtint_t incx, T* x, T value ) { T* chi; + + if (incx != 1) + { + // First initialize all elements in vector to unusual value to help + // catch if intervening elements have been incorrectly used or modified. + for ( gtint_t i = 0; i < testinghelpers::buff_dim(n, incx); ++i ) + { + chi = x + i; + *chi = T{-1.2345e38}; + } + } + for ( gtint_t i = 0; i < n; ++i ) { chi = x + i*std::abs(incx); @@ -446,22 +466,30 @@ void set_matrix( char storage, gtint_t m, gtint_t n, T* a, char transa, gtint_t if((storage == 'c') || (storage == 'C')) { - for( gtint_t i = 0 ; i < m ; i++ ) + for( gtint_t j = 0 ; j < n ; j++ ) { - for( gtint_t j = 0 ; j < n ; j++ ) + for( gtint_t i = 0 ; i < m ; i++ ) { a[i+j*lda] = value ; } + for(gtint_t i=m; i