gnuradio / volk

The Vector Optimized Library of Kernels

Home Page:http://libvolk.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

qa_volk_32fc_index_* are flaky

argilo opened this issue · comments

While looking for flaky tests with ctest --repeat until-fail:<n>, the qa_volk_32fc_index_* tests turned out to be flaky. Failures are very rare, but can be induced by rounding the test framework's random numbers so that fewer unique values are produced:

diff --git a/lib/qa_utils.cc b/lib/qa_utils.cc
index 4be7b8a..756d1d5 100644
--- a/lib/qa_utils.cc
+++ b/lib/qa_utils.cc
@@ -34,7 +34,7 @@ void random_floats(void* buf, unsigned int n, std::default_random_engine& rnd_en
     T* array = static_cast<T*>(buf);
     std::uniform_real_distribution<T> uniform_dist(T(-1), T(1));
     for (unsigned int i = 0; i < n; i++) {
-        array[i] = uniform_dist(rnd_engine);
+        array[i] = rintf(uniform_dist(rnd_engine) * 10.f) / 10.f;
     }
 }

When multiple indices attain the same maximum value, the generic protokernel selects the first one, but the SIMD protokernels make no attempt to choose the first one (in contrast to 32f_index_*, where the SIMD protokernels are designed to select the first occurrence). However, even if the 32fc_index_* protokernels are refactored to behave the same way as the 32f_index_* protokernels, failures still occur due to floating-point error: the calculated magnitude of a+bj may not equal the calculated magnitude of b+aj. So there may be no hope of guaranteeing that the "first" maximum value is selected, in which case the only solution would be to make the test framework more flexible so that any index whose magnitude is within some tolerance of the maximum is accepted.

I'd argue that a specialized test would be great in this case.