kfrlib / kfr

Fast, modern C++ DSP framework, FFT, Sample Rate Conversion, FIR/IIR/Biquad Filters (SSE, AVX, AVX-512, ARM NEON)
https://www.kfrlib.com
GNU General Public License v2.0
1.64k stars 252 forks source link

fft_accuracy test failure with Clang 11 #119

Closed m-hagelin closed 2 years ago

m-hagelin commented 3 years ago

The testcase fft_accuracy fails quite badly after building with clang 11.

...
    type = float, size = 254; complex-inverse:
    [fail]    rms_diff_outofplace < min_prec | 6.27181 < 0.00140648
[----RUN----] dct...
[--SUCCESS--] 2 subtests of 2
===============================================================================
[--SUCCESS--] 145/146 tests 2677857/2678067 checks
[---ERROR---] 1/146 tests 210/2678067 checks
              fft_accuracy
slarew commented 3 years ago

I see the same failures in the fft_accuracy test. I am running archlinux which moved to clang 11 not long ago. avx2 on an i7 8700k.

dancazarin commented 3 years ago

Investigating this. Likely vector optimizer bug in clang 11. Once a workaround will be found for this, patch for kfr will be released.

fcapozzi commented 3 years ago

I found same problem ... any news so far for kfr patch availability ?

slarew commented 2 years ago

I still see the failures in fft_accuracy test when compiling with clang 12.0.1 and clang 13 with CPU_ARCH=avx2. At the cost of a small performance loss, I found that disabling fast-math for libkfr_dft made all tests pass. Thus, it seems that one of the optimizations done by fast-math in newer clang/llvm versions is problematic.

dancazarin commented 2 years ago

Fixed in dev branch with no performance loss (spoiler: -ffp-contract=fast). @slarew, There was indeed a Clang bug in the code of optimizations enabled by -ffast-math switch but fortunately not -ffp-contract=fast. Newest Xcode 13 was also affected but clang-cl was not.