Improve OpenMP acceleration support, enable KissFFT OpenMP, and add build documentation (#601) - #865
Conversation
|
codex review: Reviewed at
Interesting part about this one is point 1, enabling openmp for kissfft makes everything slower not faster for most of the workloads with relatively low number of samples. Keeping in mind that most common sampling rate is 256 for eeg devices and most common window size is like 5 seconds, enabling openmp for kissfft all the time will slow down its performce. Please run more performance benchmarks to either prove this statement from codex or reject it |
…licit macOS architectures - Remove forced KISSFFT_OPENMP cache injection in src/data_handler/build.cmake (resolves P2 Issue 1 and Issue 2) - Empirical benchmarks show KissFFT OpenMP is 7x-114x slower on typical EEG window sizes (128-2048 samples) due to OpenMP barrier overhead on low-radix loops. - Keeps KISSFFT_OPENMP an independent OFF-by-default option in third_party/kissfft/build.cmake, preventing stale cache retention. - Update tools/build.py to preserve explicit --cmake-osx-architectures (resolves P2 Issue 3) - Distinguish user-specified architectures from defaults using default=None in argument parser. - Automatically default to platform.machine() for --use-openmp only when --cmake-osx-architectures is not explicitly provided. - Update BuildBrainFlow.rst documentation to reflect channel-level OpenMP parallelism.
|
Thanks for the review, @Andrey1994!
All three issues are resolved in commit
|
Description
Addresses #601 ("Performance tunning").
This PR focuses on the OpenMP performance and compilation subtasks outlined in #601:
Summary of Improvements
Enable OpenMP Parallel Execution in KissFFT (
src/data_handler/build.cmake):-DUSE_OPENMP=ON/tools/build.py --use-openmp),src/data_handler/build.cmakepreviously did not passKISSFFT_OPENMP=ONto KissFFT. KissFFT was always built in single-threaded mode even when OpenMP was explicitly requested.USE_OPENMPautomatically setsKISSFFT_OPENMP ON, enabling multi-threaded radix butterfly calculations in KissFFT (kiss_fft.c).Modernize KissFFT OpenMP Compiler Configuration (
third_party/kissfft/build.cmake):third_party/kissfft/build.cmaketo leverage CMake's standardOpenMP::OpenMP_Ctarget, properly configuring compiler flags, include paths, and runtime libraries across GCC, Clang, AppleClang, and MSVC.GNU|Clang|AppleClangcheck, causing MSVC OpenMP builds to fail.macOS OpenMP Discovery & Native Architecture Support (
CMakeLists.txt&tools/build.py):libompas a keg-only package.CMakeLists.txtnow automatically detects Homebrew'slibomppath (/opt/homebrew/opt/libompor/usr/local/opt/libomp) ifOpenMP_ROOTis not explicitly provided.tools/build.py --use-openmpon macOS, the default architecture is automatically adjusted to the native machine architecture (arm64on Apple Silicon,x86_64on Intel) to match Homebrew's single-architecture bottle, enabling smooth out-of-the-box OpenMP builds without manual configuration flags.Comprehensive OpenMP Build Documentation (
docs/BuildBrainFlow.rst):docs/BuildBrainFlow.rstdetailing:libomp-dev/libgomp), macOS (brew install libomp), and Windows (MSVC built-in).tools/build.py --use-openmpand direct CMake invocation.Verification
cmake -B build_test -DUSE_OPENMP=ONandcmake --build build_test --target kissfft DataHandleron macOS (AppleClang 17 + Homebrew libomp 23.1).python3 tools/build.py --use-openmpend-to-end build and installation.cmake -B build_test_default && cmake --build build_test_default --target DataHandler).