From 41b19ba6e64d74cf0a196c0cc30433590a4e3d22 Mon Sep 17 00:00:00 2001 From: mangala v Date: Tue, 6 Feb 2024 18:09:00 +0530 Subject: [PATCH] Gtestuite: ZGEMM API testing Functionality testing for below apis are carried out with various input ranges and values Interface would invoke listed API's in the below sequence if the condition is satisified List of API's - Condition SCALM : alpha = 0 GEMV : m = 1 or n = 1 Small ST : ((m0*k0) <= 16384) || ((n0*k0) <= 16384))) SUP AVX2 : (m || n || k) <= 128 SUP AVX512 : (m || k) <= 128 || n <= 110 Native : Default path, If above API's doesn't support the given input values AMD-Internal: [CPUPL-4426] Change-Id: I40cd30a11592e4e553e09f0d81153abf0bf0b002 --- .../testsuite/level3/gemm/zgemm_generic.cpp | 327 ++++++++++++++---- 1 file changed, 267 insertions(+), 60 deletions(-) diff --git a/gtestsuite/testsuite/level3/gemm/zgemm_generic.cpp b/gtestsuite/testsuite/level3/gemm/zgemm_generic.cpp index 6bdb2d63e..646d3710b 100644 --- a/gtestsuite/testsuite/level3/gemm/zgemm_generic.cpp +++ b/gtestsuite/testsuite/level3/gemm/zgemm_generic.cpp @@ -4,7 +4,7 @@ An object-based framework for developing high-performance BLAS-like libraries. - Copyright (C) 2023, Advanced Micro Devices, Inc. All rights reserved. + Copyright (C) 2023-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 @@ -33,22 +33,23 @@ */ #include -#include "test_gemm.h" + #include "test_gemm.h" -class ZGemmAccTest : - public ::testing::TestWithParam> {}; +class ZGEMMAPI : + public ::testing::TestWithParam> {}; -TEST_P(ZGemmAccTest, Unit_Tester) +TEST_P(ZGEMMAPI, FunctionalTest) { using T = dcomplex; //---------------------------------------------------------- @@ -87,7 +88,7 @@ TEST_P(ZGemmAccTest, Unit_Tester) test_gemm( storage, transa, transb, m, n, k, lda_inc, ldb_inc, ldc_inc, alpha, beta, thresh ); } -class ZGemmAccPrint { +class ZGEMMPrint { public: std::string operator()( testing::TestParamInfo> str) const { @@ -103,77 +104,283 @@ public: gtint_t ldb_inc = std::get<9>(str.param); gtint_t ldc_inc = std::get<10>(str.param); #ifdef TEST_BLAS - std::string str_name = "zgemm_"; + std::string str_name = "blas_"; #elif TEST_CBLAS - std::string str_name = "cblas_zgemm"; + std::string str_name = "cblas_"; #else //#elif TEST_BLIS_TYPED - std::string str_name = "bli_zgemm"; + std::string str_name = "bli_"; #endif - str_name = str_name + "_" + sfm+sfm+sfm; - str_name = str_name + "_" + tsa + tsb; - str_name = str_name + "_" + std::to_string(m); - str_name = str_name + "_" + std::to_string(n); - str_name = str_name + "_" + std::to_string(k); - str_name = str_name + "_a" + testinghelpers::get_value_string(alpha);; - str_name = str_name + "_b" + testinghelpers::get_value_string(beta);; - str_name = str_name + "_" + std::to_string(lda_inc); - str_name = str_name + "_" + std::to_string(ldb_inc); - str_name = str_name + "_" + std::to_string(ldc_inc); + str_name = str_name + "storageC_" + sfm; + str_name = str_name + "_transA_" + tsa + "_transB_" + tsb; + str_name = str_name + "_m_" + std::to_string(m); + str_name = str_name + "_n_" + std::to_string(n); + str_name = str_name + "_k_" + std::to_string(k); + std::string alpha_str = (alpha.real < 0) ? ("m" + std::to_string(int(std::abs(alpha.real)))) : std::to_string(int(alpha.real)); + alpha_str = alpha_str + ((alpha.imag < 0) ? ("m" + std::to_string(int(std::abs(alpha.imag)))) : "i" + std::to_string(int(alpha.imag))); + std::string beta_str = (beta.real < 0) ? ("m" + std::to_string(int(std::abs(beta.real)))) : std::to_string(int(beta.real)); + beta_str = beta_str + ((beta.imag < 0) ? ("m" + std::to_string(int(std::abs(beta.imag)))) : "i" + std::to_string(int(beta.imag))); + str_name = str_name + "_alpha_" + alpha_str; + str_name = str_name + "_beta_" + beta_str; + gtint_t lda = testinghelpers::get_leading_dimension( sfm, tsa, m, k, lda_inc ); + gtint_t ldb = testinghelpers::get_leading_dimension( sfm, tsb, k, n, ldb_inc ); + gtint_t ldc = testinghelpers::get_leading_dimension( sfm, 'n', m, n, ldc_inc ); + str_name = str_name + "_lda_" + std::to_string(lda); + str_name = str_name + "_ldb_" + std::to_string(ldb); + str_name = str_name + "_ldc_" + std::to_string(ldc); return str_name; } }; +/********************************************************************/ +/* Blas interface testing as per the code sequence */ +/* Below API's will be invoked if input condition is satisified */ +/* List of API's - Input conditions */ +/* SCALM : alpha = 0 */ +/* GEMV : m = 1 or n = 1 */ +/* K1 : k = 1 & tranaA = 'n' & transB = 'n; */ +/* Small ST : ((m0*k0) <= 16384) || ((n0*k0) <= 16384))) */ +/* SUP AVX2 : (m & n & k) <= 128 */ +/* SUP AVX512 : (m & k) <= 128 & n <= 110 */ +/* Native : Default path, */ +/* : when none of the above API's are invoked */ +/********************************************************************/ +INSTANTIATE_TEST_SUITE_P( + SCALM, + ZGEMMAPI, + ::testing::Combine( + ::testing::Values('c' +#ifndef TEST_BLAS + ,'r' +#endif + ), // storage format + ::testing::Values('n','c','t'), // transa + ::testing::Values('n','c','t'), // transb + ::testing::Values(gtint_t(10)), // m + ::testing::Values(gtint_t(10)), // n + ::testing::Values(gtint_t(10)), // k + ::testing::Values(dcomplex{0.0, 0.0}), // alpha + ::testing::Values(dcomplex{1.0, 0.0}, dcomplex{-1.0, 0.0}, + dcomplex{0.0, 1.0}, dcomplex{3.1, 15.9}, + dcomplex{0.0, 0.0}), //beta + ::testing::Values(gtint_t(0), gtint_t(130)), // increment to the leading dim of a + ::testing::Values(gtint_t(0), gtint_t(120)), // increment to the leading dim of b + ::testing::Values(gtint_t(0), gtint_t(150)) // increment to the leading dim of c + ), + ::ZGEMMPrint() + ); + +INSTANTIATE_TEST_SUITE_P( + GEMV_M1_N1, + ZGEMMAPI, + ::testing::Combine( + ::testing::Values('c' +#ifndef TEST_BLAS + ,'r' +#endif + ), // storage format + ::testing::Values('n', 'c', 't'), // transa + ::testing::Values('n', 'c', 't'), // transb + ::testing::Values(gtint_t(1)), // m + ::testing::Values(gtint_t(1)), // n + ::testing::Range(gtint_t(100), gtint_t(200), gtint_t(100)), // k + ::testing::Values(dcomplex{1.0, 0.0}, dcomplex{-1.0, 0.0}, + dcomplex{0.0, 1.0}, dcomplex{2.1, -1.9}, + dcomplex{0.0, 0.0}), // alpha + ::testing::Values(dcomplex{1.0, 0.0}, dcomplex{-1.0, 0.0}, + dcomplex{0.0, 1.0}, dcomplex{2.1, -1.9}, + dcomplex{0.0, 0.0}), // beta + ::testing::Values(gtint_t(0), gtint_t(230)), // increment to the leading dim of a + ::testing::Values(gtint_t(0), gtint_t(220)), // increment to the leading dim of b + ::testing::Values(gtint_t(0), gtint_t(250)) // increment to the leading dim of c + ), + ::ZGEMMPrint() + ); + +INSTANTIATE_TEST_SUITE_P( + GEMV_M1, + ZGEMMAPI, + ::testing::Combine( + ::testing::Values('c' +#ifndef TEST_BLAS + ,'r' +#endif + ), // storage format + ::testing::Values('n', 'c', 't'), // transa + ::testing::Values('n', 'c', 't'), // transb + ::testing::Values(gtint_t(1)), // m + ::testing::Range(gtint_t(2), gtint_t(200), gtint_t(40)), // n + ::testing::Range(gtint_t(100), gtint_t(200), gtint_t(100)), // k + ::testing::Values(dcomplex{1.0, 0.0}, dcomplex{-1.0, 0.0}, + dcomplex{0.0, 1.0}, dcomplex{2.1, -1.9}, + dcomplex{0.0, 0.0}), // alpha + ::testing::Values(dcomplex{1.0, 0.0}, dcomplex{-1.0, 0.0}, + dcomplex{0.0, 1.0}, dcomplex{2.1, -1.9}, + dcomplex{0.0, 0.0}), // beta + ::testing::Values(gtint_t(0), gtint_t(230)), // increment to the leading dim of a + ::testing::Values(gtint_t(0), gtint_t(220)), // increment to the leading dim of b + ::testing::Values(gtint_t(0), gtint_t(250)) // increment to the leading dim of c + ), + ::ZGEMMPrint() + ); + +INSTANTIATE_TEST_SUITE_P( + GEMV_N1, + ZGEMMAPI, + ::testing::Combine( + ::testing::Values('c' +#ifndef TEST_BLAS + ,'r' +#endif + ), // storage format + ::testing::Values('n', 'c', 't'), // transa + ::testing::Values('n', 'c', 't'), // transb + ::testing::Range(gtint_t(1), gtint_t(100), gtint_t(20)), // m + ::testing::Values(gtint_t(1)), // n + ::testing::Range(gtint_t(100), gtint_t(200), gtint_t(100)), // k + ::testing::Values(dcomplex{1.0, 0.0}, dcomplex{-1.0, 0.0}, + dcomplex{0.0, 1.0}, dcomplex{3.1, -1.5}, + dcomplex{0.0, 0.0}), // alpha + ::testing::Values(dcomplex{1.0, 0.0}, dcomplex{-1.0, 0.0}, + dcomplex{0.0, 1.0}, dcomplex{2.3, -2.9}, + dcomplex{0.0, 0.0}), // beta + ::testing::Values(gtint_t(0), gtint_t(300)), // increment to the leading dim of a + ::testing::Values(gtint_t(0), gtint_t(200)), // increment to the leading dim of b + ::testing::Values(gtint_t(0), gtint_t(500)) // increment to the leading dim of c + ), + ::ZGEMMPrint() + ); + // Unit testing for bli_zgemm_4x4_avx2_k1_nn kernel /* From the BLAS layer(post parameter checking), the inputs will be redirected to this kernel if m != 1, n !=1 and k == 1 */ INSTANTIATE_TEST_SUITE_P( - bli_zgemm_4x4_avx2_k1_nn, - ZGemmAccTest, + K_1, + ZGEMMAPI, ::testing::Combine( ::testing::Values('c' #ifndef TEST_BLAS - ,'r' + ,'r' #endif - ), // storage format - ::testing::Values('n'), // transa - ::testing::Values('n'), // transb - ::testing::Range(gtint_t(2), gtint_t(8), 1), // m - ::testing::Range(gtint_t(2), gtint_t(8), 1), // n - ::testing::Values(gtint_t(1)), // k + ), // storage format + ::testing::Values('n'), // transa + ::testing::Values('n'), // transb + ::testing::Range(gtint_t(2), gtint_t(8), 1), // m + ::testing::Range(gtint_t(2), gtint_t(8), 1), // n + ::testing::Values(gtint_t(1)), // k ::testing::Values(dcomplex{1.0, 0.0}, dcomplex{-1.0, 0.0}, dcomplex{0.0, 1.0}, dcomplex{2.1, -1.9}, - dcomplex{0.0, 0.0}), // alpha + dcomplex{0.0, 0.0}), // alpha ::testing::Values(dcomplex{1.0, 0.0}, dcomplex{-1.0, 0.0}, dcomplex{0.0, 1.0}, dcomplex{2.1, -1.9}, - dcomplex{0.0, 0.0}), // beta - ::testing::Values(gtint_t(0), gtint_t(3)), // increment to the leading dim of a - ::testing::Values(gtint_t(0), gtint_t(2)), // increment to the leading dim of b - ::testing::Values(gtint_t(0), gtint_t(5)) // increment to the leading dim of c + dcomplex{0.0, 0.0}), // beta + ::testing::Values(gtint_t(0), gtint_t(390)), // increment to the leading dim of a + ::testing::Values(gtint_t(0), gtint_t(290)), // increment to the leading dim of b + ::testing::Values(gtint_t(0), gtint_t(590)) // increment to the leading dim of c ), - ::ZGemmAccPrint() + ::ZGEMMPrint() ); -// Black box testing. INSTANTIATE_TEST_SUITE_P( - Blackbox, - ZGemmAccTest, + SMALL_Matrix_ST, + ZGEMMAPI, ::testing::Combine( ::testing::Values('c' #ifndef TEST_BLAS - ,'r' + ,'r' #endif - ), // storage format - ::testing::Values('n','c','t'), // transa - ::testing::Values('n','c','t'), // transb - ::testing::Range(gtint_t(10), gtint_t(31), 10), // m - ::testing::Range(gtint_t(10), gtint_t(31), 10), // n - ::testing::Range(gtint_t(10), gtint_t(31), 10), // k - ::testing::Values(dcomplex{2.0,-1.0}), // alpha - ::testing::Values(dcomplex{1.0,2.0}), // beta - ::testing::Values(gtint_t(0), gtint_t(3)), // increment to the leading dim of a - ::testing::Values(gtint_t(0), gtint_t(2)), // increment to the leading dim of b - ::testing::Values(gtint_t(0), gtint_t(5)) // increment to the leading dim of c + ), // storage format + ::testing::Values('n', 'c', 't'), // transa + ::testing::Values('n', 'c', 't'), // transb + ::testing::Values(gtint_t(2), gtint_t(3), gtint_t(7), gtint_t(8)), // m + ::testing::Values(gtint_t(2), gtint_t(3), gtint_t(7), gtint_t(8)), // n + ::testing::Values(gtint_t(2), gtint_t(4), gtint_t(10)), // k + ::testing::Values(dcomplex{0.0, 0.0}, dcomplex{1.0, 0}, dcomplex{0, 1.0}, dcomplex{-1.0, -2.0}), // alpha + ::testing::Values(dcomplex{0.0, 0.0}, dcomplex{1.0, 0}, dcomplex{0, 1.0}, dcomplex{1.0, 2.0}), // beta + ::testing::Values(gtint_t(0), gtint_t(1)), // increment to the leading dim of a + ::testing::Values(gtint_t(0), gtint_t(2)), // increment to the leading dim of b + ::testing::Values(gtint_t(0), gtint_t(3)) // increment to the leading dim of c ), - ::ZGemmAccPrint() + ::ZGEMMPrint() ); + +INSTANTIATE_TEST_SUITE_P( + Skinny_Matrix_Trans_N, + ZGEMMAPI, + ::testing::Combine( + ::testing::Values('c' +#ifndef TEST_BLAS + ,'r' +#endif + ), // storage format + ::testing::Values('n'), // transa + ::testing::Values('n'), // transb + ::testing::Range(gtint_t(100), gtint_t(105), gtint_t(1)), // m + ::testing::Range(gtint_t(80), gtint_t(85), gtint_t(1)), // n + ::testing::Range(gtint_t(1000), gtint_t(1010), gtint_t(1)), // k + ::testing::Values(dcomplex{-1.0, -2.0}, dcomplex{0.0, -30.0}, + dcomplex{1.0, 0.0}, dcomplex{-1.0, 0.0}, + dcomplex{5.0, 0.0}), // alpha + ::testing::Values(dcomplex{12.0, 2.3}, dcomplex{0.0, 1.3}, + dcomplex{1.0, 0.0}, dcomplex{-1.0, 0.0}, + dcomplex{5.0, 0.0}), // beta + ::testing::Values(gtint_t(540)), // increment to the leading dim of a + ::testing::Values(gtint_t(940)), // increment to the leading dim of b + ::testing::Values(gtint_t(240)) // increment to the leading dim of c + ), + ::ZGEMMPrint() + ); + +INSTANTIATE_TEST_SUITE_P( + SKinny_Matrix_Trans_T, + ZGEMMAPI, + ::testing::Combine( + ::testing::Values('c' +#ifndef TEST_BLAS + ,'r' +#endif + ), // storage format + ::testing::Values('t'), // transa + ::testing::Values('t'), // transb + ::testing::Range(gtint_t(105), gtint_t(110), gtint_t(1)), // m + ::testing::Range(gtint_t(190), gtint_t(195), gtint_t(1)), // n + ::testing::Range(gtint_t(500), gtint_t(510), gtint_t(1)), // k + ::testing::Values(dcomplex{-1.8, -21.0}, dcomplex{0.0, -33.0}, + dcomplex{1.0, 0.0}, dcomplex{-1.0, 0.0}, + dcomplex{5.3, 0.0}), // alpha + ::testing::Values(dcomplex{1.8, 9.3}, dcomplex{0.0, 3.3}, + dcomplex{1.0, 0.0}, dcomplex{-1.0, 0.0}, + dcomplex{2.91, 0.0}, dcomplex{0.0, 0.0}), // beta + ::testing::Values(gtint_t(0)), // increment to the leading dim of a + ::testing::Values(gtint_t(0)), // increment to the leading dim of b + ::testing::Values(gtint_t(0)) // increment to the leading dim of c + ), + ::ZGEMMPrint() + ); + +INSTANTIATE_TEST_SUITE_P( + Large_Matrix_Trans_N_C_T, + ZGEMMAPI, + ::testing::Combine( + ::testing::Values('c' +#ifndef TEST_BLAS + ,'r' +#endif + ), // storage format + ::testing::Values('n', 'c', 't'), // transa + ::testing::Values('n', 'c', 't'), // transb + ::testing::Values(gtint_t(200)), // m + ::testing::Values(gtint_t(180)), // n + ::testing::Values(gtint_t(170)), // k + ::testing::Values(dcomplex{1.5, 3.5}, dcomplex{0.0, -10.0}, + dcomplex{1.0, 0.0}, dcomplex{-1.0, 0.0}, + dcomplex{2.0, 0.0}), // alpha + ::testing::Values(dcomplex{2.0, 4.1}, dcomplex{0.0, 3.4}, + dcomplex{1.0, 0.0}, dcomplex{-1.0, 0.0}, + dcomplex{3.3, 0.0}, dcomplex{0.0, 0.0}), // beta + ::testing::Values(gtint_t(0), gtint_t(300)), // increment to the leading dim of a + ::testing::Values(gtint_t(0), gtint_t(200)), // increment to the leading dim of b + ::testing::Values(gtint_t(0), gtint_t(500)) // increment to the leading dim of c + ), + ::ZGEMMPrint() + ); \ No newline at end of file