From 470f257a258deedcff0c4551c8f673d45c3f6fa2 Mon Sep 17 00:00:00 2001 From: Clayton Smith Date: Sat, 14 Oct 2023 20:33:29 -0400 Subject: [PATCH] Use an absolute tolerance to test the dot product kernels Signed-off-by: Clayton Smith --- lib/kernel_tests.h | 4 ++-- lib/qa_utils.cc | 44 ++++++++++++++++++++++++-------------------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/lib/kernel_tests.h b/lib/kernel_tests.h index 499255b78..e6af9310f 100644 --- a/lib/kernel_tests.h +++ b/lib/kernel_tests.h @@ -71,7 +71,7 @@ std::vector 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)) @@ -101,7 +101,7 @@ std::vector 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)) diff --git a/lib/qa_utils.cc b/lib/qa_utils.cc index a74f7bc2c..251bbfd0e 100644 --- a/lib/qa_utils.cc +++ b/lib/qa_utils.cc @@ -401,10 +401,6 @@ bool fcompare(t* in1, t* in2, unsigned int vlen, float tol, bool absolute_mode) template 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) { @@ -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) { @@ -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; + } } } } @@ -454,10 +462,6 @@ bool ccompare(t* in1, t* in2, unsigned int vlen, float tol, bool absolute_mode) template 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++) {