Skip to content

Commit

Permalink
Use an absolute tolerance to test the dot product kernels
Browse files Browse the repository at this point in the history
Signed-off-by: Clayton Smith <[email protected]>
  • Loading branch information
argilo committed Oct 22, 2023
1 parent 3bcc87d commit 470f257
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
4 changes: 2 additions & 2 deletions lib/kernel_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ std::vector<volk_test_case_t> init_test_list(volk_test_params_t test_params)
QA(VOLK_INIT_TEST(volk_16ic_x2_dot_prod_16ic, test_params))
QA(VOLK_INIT_TEST(volk_16i_s32f_convert_32f, test_params))
QA(VOLK_INIT_TEST(volk_16i_convert_8i, test_params))
QA(VOLK_INIT_TEST(volk_16i_32fc_dot_prod_32fc, test_params_inacc))
QA(VOLK_INIT_TEST(volk_16i_32fc_dot_prod_32fc, test_params.make_absolute(1e-1)))
QA(VOLK_INIT_TEST(volk_32f_accumulator_s32f, test_params_inacc))
QA(VOLK_INIT_TEST(volk_32f_x2_add_32f, test_params))
QA(VOLK_INIT_TEST(volk_32f_index_max_16u, test_params))
Expand Down Expand Up @@ -101,7 +101,7 @@ std::vector<volk_test_case_t> init_test_list(volk_test_params_t test_params)
QA(VOLK_INIT_TEST(volk_32fc_deinterleave_real_32f, test_params))
QA(VOLK_INIT_TEST(volk_32fc_deinterleave_real_64f, test_params))
QA(VOLK_INIT_TEST(volk_32fc_x2_dot_prod_32fc, test_params_inacc))
QA(VOLK_INIT_TEST(volk_32fc_32f_dot_prod_32fc, test_params_inacc))
QA(VOLK_INIT_TEST(volk_32fc_32f_dot_prod_32fc, test_params.make_absolute(1e-2)))
QA(VOLK_INIT_TEST(volk_32fc_index_max_16u, test_params))
QA(VOLK_INIT_TEST(volk_32fc_index_max_32u, test_params))
QA(VOLK_INIT_TEST(volk_32fc_index_min_16u, test_params))
Expand Down
44 changes: 24 additions & 20 deletions lib/qa_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,6 @@ bool fcompare(t* in1, t* in2, unsigned int vlen, float tol, bool absolute_mode)
template <class t>
bool ccompare(t* in1, t* in2, unsigned int vlen, float tol, bool absolute_mode)
{
if (absolute_mode) {
std::cout << "ccompare does not support absolute mode" << std::endl;
return true;
}
bool fail = false;
int print_max_errs = 10;
for (unsigned int i = 0; i < 2 * vlen; i += 2) {
Expand All @@ -423,9 +419,7 @@ bool ccompare(t* in1, t* in2, unsigned int vlen, float tol, bool absolute_mode)
t err = std::sqrt(diff[0] * diff[0] + diff[1] * diff[1]);
t norm = std::sqrt(in1[i] * in1[i] + in1[i + 1] * in1[i + 1]);

// for very small numbers we'll see round off errors due to limited
// precision. So a special test case...
if (norm < 1e-30) {
if (absolute_mode) {
if (err > tol) {
fail = true;
if (print_max_errs-- > 0) {
Expand All @@ -435,15 +429,29 @@ bool ccompare(t* in1, t* in2, unsigned int vlen, float tol, bool absolute_mode)
std::cout << " tolerance was: " << tol << std::endl;
}
}
}
// the primary test is the percent different greater than given tol
else if ((err / norm) > tol) {
fail = true;
if (print_max_errs-- > 0) {
std::cout << "offset " << i / 2 << " in1: " << in1[i] << " + "
<< in1[i + 1] << "j in2: " << in2[i] << " + " << in2[i + 1]
<< "j";
std::cout << " tolerance was: " << tol << std::endl;
} else {
// for very small numbers we'll see round off errors due to limited
// precision. So a special test case...
if (norm < 1e-30) {
if (err > tol) {
fail = true;
if (print_max_errs-- > 0) {
std::cout << "offset " << i / 2 << " in1: " << in1[i] << " + "
<< in1[i + 1] << "j in2: " << in2[i] << " + "
<< in2[i + 1] << "j";
std::cout << " tolerance was: " << tol << std::endl;
}
}
}
// the primary test is the percent different greater than given tol
else if ((err / norm) > tol) {
fail = true;
if (print_max_errs-- > 0) {
std::cout << "offset " << i / 2 << " in1: " << in1[i] << " + "
<< in1[i + 1] << "j in2: " << in2[i] << " + " << in2[i + 1]
<< "j";
std::cout << " tolerance was: " << tol << std::endl;
}
}
}
}
Expand All @@ -454,10 +462,6 @@ bool ccompare(t* in1, t* in2, unsigned int vlen, float tol, bool absolute_mode)
template <class t>
bool icompare(t* in1, t* in2, unsigned int vlen, unsigned int tol, bool absolute_mode)
{
if (absolute_mode) {
std::cout << "icompare does not support absolute mode" << std::endl;
return true;
}
bool fail = false;
int print_max_errs = 10;
for (unsigned int i = 0; i < vlen; i++) {
Expand Down

0 comments on commit 470f257

Please sign in to comment.