Gromacs
2025.0-dev-20241011-013a99c
|
#include <gromacs/simd/tests/base.h>
Inherits Test.
Base class for SIMD test fixtures.
This class contains settings that are common for SIMD and SIMD4 tests, and it is thus not used directly for any tests, but derived separately in simd.h and simd4.h.
Public Member Functions | |
SimdBaseTest () | |
Initialize new SIMD test fixture with default tolerances. More... | |
void | setUlpTol (std::int64_t newTol) |
Adjust ulp tolerance from the default 10 (float) or 255 (double). | |
void | setUlpTolSingleAccuracy (std::int64_t newTol) |
Adjust ulp tolerance for single accuracy functions. | |
void | setAbsTol (real newTol) |
Adjust the absolute tolerance from the default 0. More... | |
::testing::AssertionResult | compareVectorRealUlp (const char *refExpr, const char *tstExpr, const std::vector< real > &ref, const std::vector< real > &tst) const |
Compare two std::vector<real> for approximate equality. More... | |
template<typename T > | |
::testing::AssertionResult | compareVectorEq (const char *refExpr, const char *tstExpr, const std::vector< T > &ref, const std::vector< T > &tst) |
Compare std::vectors for exact equality. More... | |
Static Public Member Functions | |
static constexpr std::int64_t | defaultRealUlpTol () |
Return the default ulp tolerance for current precision. | |
Static Public Attributes | |
static int | s_nPoints = 10000 |
Number of test points to use, settable on command line. More... | |
Protected Attributes | |
std::int64_t | ulpTol_ |
Current tolerance in units-in-last-position. | |
real | absTol_ |
Current absolute tolerance. | |
|
inline |
Initialize new SIMD test fixture with default tolerances.
The default absolute tolerance is set to 0, which means the we always check the ulp tolerance by default (passing the absolute tolerance test would otherwise mean we approve the test instantly).
The default ulp tolerance is set based on the target number of bits requested for single or double precision, depending on what the default Gromacs precision is. We add two bits to avoid tests failing due to corner cases where compiler optimization might cause a slight precision loss e.g. for very small numbers.
Most SIMD math functions actually achieve 2-3 ulp accuracy in single, but by being a bit liberal we only catch real errors rather than doing compiler-standard-compliance debugging.
The range is used by derived classes to test math functions. The default test range will be [1,10], which is intentionally conservative so it works with (inverse) square root, division, exponentials, logarithms, and error functions.
|
inline |
Compare std::vectors for exact equality.
The template in this class makes it usable for testing both SIMD floating-point and integers variables, after conversion to vectors. This is an internal implementation routine that will be used by routines in derived child classes that first convert SIMD or SIMD4 variables to std::vector<real>. Do not call it directly.
This routine is designed according to the Google test specs, so the char strings will describe the arguments to the macro.
The comparison is applied to each element, and it returns true if each element in the vector test variable is within the class tolerances of the corresponding reference elements.
|
inline |
Adjust the absolute tolerance from the default 0.
If values are closer than the absolute tolerance, the test will pass no matter what their ulp difference is.