Files
blis/gtestsuite/testsuite/level1/copyv/dcopyv_generic.cpp
Vignesh Balasubramanian 16aaafc8ec Added memory testing for DAXPY, DAXPBY and DCOPY kernels.
- Utilized the memory testing feature in GTestsuite
   to update the testing interfaces for micro-kernel
   testing of DAXPY, DAXPBY and DCOPY APIs.

 - The interface allocates memory using objects of
   ProtectedBuffer class, which define the redzones
   and greenzones as per the requirement.

 - Updated the test fixture classes, test-case loggers and
   the instantiators to use the new testing interface for
   memory testing.

 - Added special cases of alpha and beta values to API
   level functionality tests, to check for any possible
   framework level optimizations against the standard.

 - Code cleanup of ?_generic.cpp and ?_evt_testing.cpp
   files of DAXPY, DAXPBY and DCOPY APIs.

AMD-Internal: [CPUPL-4402]
Change-Id: Id945cabbbb42604d76a9e34269bff0f9f6712604
2024-02-23 09:06:08 -05:00

160 lines
6.9 KiB
C++

/*
BLIS
An object-based framework for developing high-performance BLAS-like
libraries.
Copyright (C) 2023, 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 <gtest/gtest.h>
#include "test_copyv.h"
class dcopyvGenericTest :
public ::testing::TestWithParam<std::tuple<char,
gtint_t,
gtint_t,
gtint_t>> {};
// Tests using random integers as vector elements.
TEST_P( dcopyvGenericTest, RandomData )
{
using T = double;
//----------------------------------------------------------
// Initialize values from the parameters passed through
// test suite instantiation (INSTANTIATE_TEST_SUITE_P).
//----------------------------------------------------------
// denotes whether vec x is n,c
char conjx = std::get<0>(GetParam());
// vector length:
gtint_t n = std::get<1>(GetParam());
// stride size for x:
gtint_t incx = std::get<2>(GetParam());
// stride size for y:
gtint_t incy = std::get<3>(GetParam());
// Set the threshold for the errors:
double thresh = testinghelpers::getEpsilon<T>();
//----------------------------------------------------------
// Call generic test body using those parameters
//----------------------------------------------------------
test_copyv<T>( conjx, n, incx, incy, thresh );
}
// Used to generate a test case with a sensible name.
// Beware that we cannot use fp numbers (e.g., 2.3) in the names,
// so we are only printing int(2.3). This should be enough for debugging purposes.
// If this poses an issue, please reach out.
class dcopyvGenericTestPrint {
public:
std::string operator()(
testing::TestParamInfo<std::tuple<char,gtint_t,gtint_t,gtint_t>> str) const {
char conjx = std::get<0>(str.param);
gtint_t n = std::get<1>(str.param);
gtint_t incx = std::get<2>(str.param);
gtint_t incy = std::get<3>(str.param);
#ifdef TEST_BLAS
std::string str_name = "blas_";
#elif TEST_CBLAS
std::string str_name = "cblas_";
#else //#elif TEST_BLIS_TYPED
std::string str_name = "bli_";
#endif
str_name += "_" + std::to_string(n);
str_name += "_" + std::string(&conjx, 1);
std::string incx_str = ( incx >= 0) ? std::to_string(incx) : "m" + std::to_string(std::abs(incx));
str_name += "_" + incx_str;
std::string incy_str = ( incy >= 0) ? std::to_string(incy) : "m" + std::to_string(std::abs(incy));
str_name += "_" + incy_str;
return str_name;
}
};
// Black box testing for generic and main use of scopy.
INSTANTIATE_TEST_SUITE_P(
Blackbox,
dcopyvGenericTest,
::testing::Combine(
::testing::Values('n'), // n: use x, not conj(x) (since it is real)
::testing::Range(gtint_t(10), gtint_t(101), 10), // m size of vector takes values from 10 to 100 with step size of 10.
::testing::Values(gtint_t(1)), // stride size for x
::testing::Values(gtint_t(1)) // stride size for y
),
::dcopyvGenericTestPrint()
);
#ifdef TEST_BLIS_TYPED // BLIS-api specific
// Test when conjugate of x is used as an argument.
// Only test very few cases as sanity check since conj(x) = x for real types.
// We can modify the values using implementantion details.
INSTANTIATE_TEST_SUITE_P(
ConjX,
dcopyvGenericTest,
::testing::Combine(
::testing::Values('c'), // c: use conj(x)
::testing::Values(gtint_t(3), gtint_t(30), gtint_t(112)), // m size of vector
::testing::Values(gtint_t(1)), // stride size for x
::testing::Values(gtint_t(1)) // stride size for y
),
::dcopyvGenericTestPrint()
);
#endif
// Test for non-unit increments.
// Only test very few cases as sanity check.
// We can modify the values using implementantion details.
INSTANTIATE_TEST_SUITE_P(
NonUnitPositiveIncrements,
dcopyvGenericTest,
::testing::Combine(
::testing::Values('n'), // use x, not conj(x) (since it is real)
::testing::Values(gtint_t(3), gtint_t(30), gtint_t(112)), // m size of vector
::testing::Values(gtint_t(2), gtint_t(11)), // stride size for x
::testing::Values(gtint_t(3), gtint_t(33)) // stride size for y
),
::dcopyvGenericTestPrint()
);
#ifndef TEST_BLIS_TYPED
// Test for negative increments.
// Only test very few cases as sanity check.
// We can modify the values using implementantion details.
INSTANTIATE_TEST_SUITE_P(
NegativeIncrements,
dcopyvGenericTest,
::testing::Combine(
::testing::Values('n'), // n: use x, c: use conj(x)
::testing::Values(gtint_t(3), gtint_t(30), gtint_t(112)), // m size of vector
::testing::Values(gtint_t(-5), gtint_t(7)), // stride size for x
::testing::Values(gtint_t(13), gtint_t(-9)) // stride size for y
),
::dcopyvGenericTestPrint()
);
#endif