gnuradio / volk

The Vector Optimized Library of Kernels
http://libvolk.org
GNU Lesser General Public License v3.0
557 stars 202 forks source link

Fix flaky fm_detect test #715

Closed argilo closed 11 months ago

argilo commented 11 months ago

volk_32fc_s32f_magnitude_16i fails in i386 Debian CI and locally:

68: offset 763 in1: 0.0534787 in2: 0.0534787 tolerance was: 1e-06
68: offset 4405 in1: -0.0228593 in2: -0.0228593 tolerance was: 1e-06
68: offset 6398 in1: -0.0512945 in2: -0.0512946 tolerance was: 1e-06
68: offset 8635 in1: -0.0217852 in2: -0.0217853 tolerance was: 1e-06
68: offset 9565 in1: 0.0521163 in2: 0.0521164 tolerance was: 1e-06
68: offset 10353 in1: 0.0130416 in2: 0.0130415 tolerance was: 1e-06
68: offset 14364 in1: -0.0432156 in2: -0.0432155 tolerance was: 1e-06
68: offset 17398 in1: 0.0538341 in2: 0.0538342 tolerance was: 1e-06
68: offset 17866 in1: 0.0584753 in2: 0.0584753 tolerance was: 1e-06
68: offset 25493 in1: 0.0356272 in2: 0.0356271 tolerance was: 1e-06
68: volk_32f_x2_fm_detectpuppet_32f: fail on arch a_avx
68: offset 763 in1: 0.0534787 in2: 0.0534787 tolerance was: 1e-06
68: offset 4405 in1: -0.0228593 in2: -0.0228593 tolerance was: 1e-06
68: offset 6398 in1: -0.0512945 in2: -0.0512946 tolerance was: 1e-06
68: offset 8635 in1: -0.0217852 in2: -0.0217853 tolerance was: 1e-06
68: offset 9565 in1: 0.0521163 in2: 0.0521164 tolerance was: 1e-06
68: offset 10353 in1: 0.0130416 in2: 0.0130415 tolerance was: 1e-06
68: offset 14364 in1: -0.0432156 in2: -0.0432155 tolerance was: 1e-06
68: offset 17398 in1: 0.0538341 in2: 0.0538342 tolerance was: 1e-06
68: offset 17866 in1: 0.0584753 in2: 0.0584753 tolerance was: 1e-06
68: offset 25493 in1: 0.0356272 in2: 0.0356271 tolerance was: 1e-06
68: volk_32f_x2_fm_detectpuppet_32f: fail on arch a_sse
68: offset 763 in1: 0.0534787 in2: 0.0534787 tolerance was: 1e-06
68: offset 4405 in1: -0.0228593 in2: -0.0228593 tolerance was: 1e-06
68: offset 6398 in1: -0.0512945 in2: -0.0512946 tolerance was: 1e-06
68: offset 8635 in1: -0.0217852 in2: -0.0217853 tolerance was: 1e-06
68: offset 9565 in1: 0.0521163 in2: 0.0521164 tolerance was: 1e-06
68: offset 10353 in1: 0.0130416 in2: 0.0130415 tolerance was: 1e-06
68: offset 14364 in1: -0.0432156 in2: -0.0432155 tolerance was: 1e-06
68: offset 17398 in1: 0.0538341 in2: 0.0538342 tolerance was: 1e-06
68: offset 17866 in1: 0.0584753 in2: 0.0584753 tolerance was: 1e-06
68: offset 25493 in1: 0.0356272 in2: 0.0356271 tolerance was: 1e-06
68: volk_32f_x2_fm_detectpuppet_32f: fail on arch u_avx

There are two bugs:

  1. The test uses a relative tolerance, but the outputs are differences of two potentially large values. If the difference happens to be near zero, the test fails.
  2. If the difference between two inputs happens to be close to bound or -bound (both of which represent a phase difference of 180 degrees), then a small floating point error can flip the sign of the output value, causing the test to fail.

To fix the first problem, I've switched the test to an absolute tolerance, and to fix the second I've increased the bound to 2.0. After these changes, the test passes reliably on i386.