Only use AVX512 in own-FFTW if GROMACS also uses it
authorSzilárd Páll <pall.szilard@gmail.com>
Thu, 20 Jun 2019 17:18:23 +0000 (19:18 +0200)
committerPaul Bauer <paul.bauer.q@gmail.com>
Mon, 24 Jun 2019 08:34:21 +0000 (10:34 +0200)
Building the own FFTW with AVX512 enabled for all AVX-flavors means that
an AVX2 build can end up loosing a significant amount of performance due
to clock throttle if the FFTW auto-tuner inadvertently picks and AVX512
kernel. This is not unlikely as measurements at startup are very noisy
and often lead to inconsistent kernel choice (observed in practice).

Change-Id: I857326a13a7c4dd1a6f5ab44360211301b05d3ac

docs/release-notes/2020/major/performance.rst
src/external/build-fftw/CMakeLists.txt

index 6598c3cb5f8c9487608b1220db849c431e281710..b7ad1cd9317a5b628a0ba8784fd53e2bc02d64cd 100644 (file)
@@ -7,4 +7,12 @@ Performance improvements
    Also, please use the syntax :issue:`number` to reference issues on redmine, without the
    a space between the colon and number!
 
+Avoid configuring the own-FFTW with AVX512 enabled when GROMACS does not use AVX512
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 
+Previously if GROMACS was configured to use any AVX flavor, the internally built FFTW
+would be configured to also contain AVX512 kernels. This could cause performance loss
+if the (often noisy) FFTW auto-tuner picks an AVX512 kernel in a run that otherwise 
+only uses AVX/AVX2 which could run at higher CPU clocks without AVX512 clock speed limitation.
+Now AVX512 is only used for the internal FFTW if GROMACS is also configured with
+the same SIMD flavor.
index 1c2c1ae38b934fe403efda7b720fe7050e1faa0a..aada5438d667487825ea941c7010c8909824b678 100644 (file)
@@ -67,20 +67,26 @@ if(${GMX_SIMD_ACTIVE} MATCHES "^(SSE|AVX)" AND APPLE)
     set(_fftw_simd_support_level "--enable-sse2")
 elseif(${GMX_SIMD_ACTIVE} MATCHES "^(SSE)")
     set(_fftw_simd_support_level "--enable-sse2")
-elseif(${GMX_SIMD_ACTIVE} MATCHES "^(AVX)")
+elseif(${GMX_SIMD_ACTIVE} MATCHES "^(AVX)" AND NOT ${GMX_SIMD_ACTIVE} MATCHES "^(AVX_512)")
     # Testing shows FFTW configured with --enable-sse2 --enable-avx is
     # slightly faster on most architectures than --enable-sse2 alone.
     # Support for --enable-avx2 was only added in 3.3.5, but
     # configuring with it is at worst a warning, even on an earlier
     # version.
+    # On platforms capable of AVX512 where we are building with AVX2,
+    # enabling AVX512 risks clock-throttling the entire mdrun if
+    # fftw happens to pick up an AVX512 kernel (which is not unlikely
+    # as fftw tuning is known to produce highly varying results).
+    set(_fftw_simd_support_level --enable-sse2;--enable-avx;--enable-avx2)
+elseif(${GMX_SIMD_ACTIVE} MATCHES "^(AVX_512)")
     # MSVC, GCC < 4.9, Clang < 3.9 do not support AVX-512, so
     # we should not enable it.
-if(MSVC OR (CMAKE_COMPILER_IS_GNUCC AND CMAKE_C_COMPILER_VERSION VERSION_LESS 4.9.0) OR
-   (CMAKE_C_COMPILER_ID MATCHES "Clang" AND CMAKE_C_COMPILER_VERSION VERSION_LESS 3.9.0))
-    set(_fftw_simd_support_level --enable-sse2;--enable-avx;--enable-avx2)
-else()
-    set(_fftw_simd_support_level --enable-sse2;--enable-avx;--enable-avx2;--enable-avx512)
-endif()
+    if(MSVC OR (CMAKE_COMPILER_IS_GNUCC AND CMAKE_C_COMPILER_VERSION VERSION_LESS 4.9.0) OR
+       (CMAKE_C_COMPILER_ID MATCHES "Clang" AND CMAKE_C_COMPILER_VERSION VERSION_LESS 3.9.0))
+        set(_fftw_simd_support_level --enable-sse2;--enable-avx;--enable-avx2)
+    else()
+        set(_fftw_simd_support_level --enable-sse2;--enable-avx;--enable-avx2;--enable-avx512)
+    endif()
 elseif(${GMX_SIMD_ACTIVE} MATCHES "^(VSX)")
     set(_fftw_simd_support_level --enable-vsx)
 endif()