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.65k stars 253 forks source link

Release 3.0.5 breaks Android Support #41

Closed Jman420 closed 5 years ago

Jman420 commented 5 years ago

Due to a custom implementation of pthreads in Android the latest release of KFR can not easily be included in an Android. The 3.0.5 release currently results in a build error of 'cannot find -lpthread' when adding KFR to CMakeList using add_subdirectory().

https://developer.android.com/ndk/guides/stable_apis#clib

Edit : I've added a branch in my project to illustrate the issue : https://github.com/Jman420/menrva/tree/feature/upgrade-kfr

Jman420 commented 5 years ago

I've managed to workaround the 'cannot find -lpthread' error by using the attached CMakeList for KFR. And by ensuring that 'libc++_shared.so' gets included in my APK by adding the following line to the defaultSettings cmake section of my app's gradle build script : arguments "-DANDROID_STL=c++_shared". CMakeLists.txt

But unfortunately now I get SIGILL errors at runtime even in tests when I do not use KFR. The SIGILL is raised on this line : https://github.com/kfrlib/kfr/blob/0907b9254786d5008dd6e33c33cdfff21d8c8585/include/kfr/simd/vec.hpp#L224

Logcat Error Dump attached. logcat dump.txt

dancazarin commented 5 years ago

Hi,

Thank you for suggested change. Can you make pull request?

In the new version, default architecture in KFR is AVX2 for x86. If AVX2 is not supported by your CPU, set CPU_ARCH cmake variable to the name of the target architecture. One of:

avx512
avx2
avx
sse42
sse41
ssse3
sse3
sse2
generic

This needs to be done only for x86 mode.

Or set CPU_ARCH to detect, then KFR will try to detect cpu capabilities before building any code.

Jman420 commented 5 years ago

Sure, PR incoming for the pthread fix.

I'll play around with the CPU_ARCH; I'm definitely using x86 mode in my testing and will be distributing the standard Android architectures (x86, x86_64, arm64-v8a and armeabi-v7a). Will post results from CPU_ARCH experiments here.

Jman420 commented 5 years ago

Great news! The CPU_ARCH suggestion worked. I'll have another PR coming shortly to incorporate that fix as well.

For reference I looked up the supported Android instruction sets here : https://developer.android.com/ndk/guides/abis.html#sa

triplef commented 5 years ago

@Jman420 did you already get a chance to submit that PR for CPU_ARCH? I’m running into what I think is the same issue compiling for Android, where the CPU_ARCH auto-detection won’t work due to cross-compiling mode.