Skip to content

Commit

Permalink
configure: reenable SSE2 and AVX optimization options for MPICH
Browse files Browse the repository at this point in the history
Previous PR#7074 consolidated SSE2 and AVX related optimization
options into MPL's configure because only MPL explicitly use them.
This change showed no performance degradation with GNU compiler.
But, with Intel compilers, this does results in some performance
degradation. Therefore, we should add them back in the main
configure. Currently, the main configure checks for availability
of SSE2, AVX and AVX512F, and add them to CFLAGS. The MPL configure
will further check for specific instructions that is used in MPL.
  • Loading branch information
yfguo committed Sep 24, 2024
1 parent 66480d3 commit 5eb6704
Show file tree
Hide file tree
Showing 2 changed files with 180 additions and 182 deletions.
84 changes: 81 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -906,11 +906,14 @@ for option in $enable_fast ; do
;;
alwaysinline) # No op in MPICH. See mpl/configure.ac
;;
sse2) # No op in MPICH. See mpl/configure.ac
sse2)
enable_fast_sse2_instr=yes
;;
avx) # No op in MPICH. See mpl/configure.ac
avx)
enable_fast_avx_instr=yes
;;
avx512f) # No op in MPICH. See mpl/configure.ac
avx512f)
enable_fast_avx512f_instr=yes
;;
all|yes)
enable_fast_ndebug=yes
Expand Down Expand Up @@ -955,6 +958,81 @@ if test -z "$enable_fast_no_strict_alignment" ; then
AC_DEFINE(NEEDS_STRICT_ALIGNMENT,1,[Define if strict alignment memory access is required])
fi

if test "$enable_fast_sse2_instr" = "yes" ; then
AC_CACHE_CHECK([whether -msse2 is supported], pac_cv_found_sse2,
[PAC_C_CHECK_COMPILER_OPTION([-msse2],pac_cv_found_sse2=yes,pac_cv_found_sse2=no)],
pac_cv_found_sse2=no,pac_cv_found_sse2=yes)
PAC_PUSH_FLAG([CFLAGS])
PAC_APPEND_FLAG([-msse2],[CFLAGS])
AC_CACHE_CHECK([whether SSE2 is supported by the CPU], pac_cv_found_sse2_runnable,[
AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <emmintrin.h>
int main() {
__m128i a = _mm_set1_epi32(1);
__asm__ volatile("" : : "x" (a) : "memory");
return 0;
}
]])], pac_cv_found_sse2_runnable="yes",
pac_cv_found_sse2_runnable="no",
pac_cv_found_sse2_runnable="unknown")
])
PAC_POP_FLAG([CFLAGS])
if test "$pac_cv_found_sse2" = "yes" && test "$pac_cv_found_sse2_runnable" = "yes"; then
PAC_APPEND_FLAG([-msse2],[CFLAGS])
fi
fi

if test "$enable_fast_avx_instr" = "yes" ; then
AC_CACHE_CHECK([whether -mavx is supported], pac_cv_found_avx,
[PAC_C_CHECK_COMPILER_OPTION([-mavx],pac_cv_found_avx=yes,pac_cv_found_avx=no)],
pac_cv_found_avx=no,pac_cv_found_avx=yes)
PAC_PUSH_FLAG([CFLAGS])
PAC_APPEND_FLAG([-mavx],[CFLAGS])
AC_CACHE_CHECK([whether AVX is supported by the CPU], pac_cv_found_avx_runnable,[
AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <immintrin.h>
int main() {
__m256i a = _mm256_set1_epi32(1);
__asm__ volatile("" : : "x" (a) : "memory");
return 0;
}
]])], pac_cv_found_avx_runnable="yes",
pac_cv_found_avx_runnable="no",
pac_cv_found_avx_runnable="unknown")
])
PAC_POP_FLAG([CFLAGS])
if test "$pac_cv_found_avx" = "yes" && test "$pac_cv_found_avx_runnable" = "yes"; then
PAC_APPEND_FLAG([-mavx],[CFLAGS])
fi
fi

if test "$enable_fast_avx512f_instr" = "yes" ; then
AC_CACHE_CHECK([whether -mavx512f is supported], pac_cv_found_avx512f,
[PAC_C_CHECK_COMPILER_OPTION([-mavx512f],pac_cv_found_avx512f=yes,pac_cv_found_avx512f=no)],
pac_cv_found_avx512f=no,pac_cv_found_avx512f=yes)
PAC_PUSH_FLAG([CFLAGS])
PAC_APPEND_FLAG([-mavx512f],[CFLAGS])
AC_CACHE_CHECK([whether AVX512F is supported by the CPU], pac_cv_found_avx512f_runnable,[
AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <immintrin.h>
int main() {
__m512i a = _mm512_set1_epi32(1);
__asm__ volatile("" : : "x" (a) : "memory");
return 0;
}
]])], pac_cv_found_avx512f_runnable="yes",
pac_cv_found_avx512f_runnable="no",
pac_cv_found_avx512f_runnable="unknown")
])
PAC_POP_FLAG([CFLAGS])
if test "$pac_cv_found_avx512f" = "yes" && test "$pac_cv_found_avx512f_runnable" = "yes"; then
PAC_APPEND_FLAG([-mavx512f],[CFLAGS])
fi
fi

# error-checking
# Change default into the specific value of the default
if test "$enable_error_checking" = "yes" ; then
Expand Down
Loading

0 comments on commit 5eb6704

Please sign in to comment.