odelaneau / shapeit4

Segmented HAPlotype Estimation and Imputation Tool
MIT License
89 stars 17 forks source link

AVX2 usage is determined at compile-time, not runtime #80

Open pettyalex opened 1 year ago

pettyalex commented 1 year ago

Right now, the AVX2 support in shapeit4 is controlled via compiler flags managed in the Makefile. Because of this, distributions that are focusing on compatibility are distributing shapeit4 without AVX2 support, meaning that the shapeit4 that is most easily installable with most Linux distros performs extremely poorly. Here is the patchset that the Debian Med team applies: https://salsa.debian.org/med-team/shapeit4/-/blob/master/debian/patches/use_shared_libs.patch

If Shapeit4 is OK with targeting GCC only, GCC built-ins like __builtin_cpu_supports could be used to easily determine instruction support at runtime, and follow different code-paths, making high-performance binaries more portable: https://gcc.gnu.org/onlinedocs/gcc/x86-Built-in-Functions.html

There's other ways to do this, but GCC built-ins are among the easier. This feature would also make it easier in the future to add AVX512 support, or any other instruction sets that could significantly increase performance, but may not be present on all CPUs.