| 1 |
# ESL_AVX512([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) |
| 2 |
# |
| 3 |
# Checks whether compiler supports features we need in our AVX512 |
| 4 |
# implementations. |
| 5 |
# |
| 6 |
# We call this "AVX512" in the generic sense of the lab's vector |
| 7 |
# implementations in Easel, HMMER, Infernal, etc; more precisely, |
| 8 |
# we're checking for AVX-512 Foundation, Double/Quadword, and |
| 9 |
# Byte/Word instruction subsets. Xeon Phi200 "Knights Landing" does |
| 10 |
# not support BW or DQ instructions. We require Skylake EX/EP (Purley) |
| 11 |
# processors or later. |
| 12 |
# |
| 13 |
# Tries to compile and link a test program using the current CC, |
| 14 |
# CFLAGS, and (optionally) any AVX512_CFLAGS passed by the user. If |
| 15 |
# AVX512_CFLAGS are not provided, then we try to determine them, by |
| 16 |
# trying nothing (i.e. the compiler deals with AVX-512 intrinsics by |
| 17 |
# default), then trying each of: |
| 18 |
# "-mavx512f -mavx512dq -mavx512bw" |
| 19 |
# "-xCORE-AVX512" |
| 20 |
# "-march=skylake-avx512" |
| 21 |
# |
| 22 |
# Sets $esl_have_avx512 = yes | no |
| 23 |
# Sets $esl_avx512_cflags to any extra needed CFLAGS, such as "-mavx512f -mavx512dq -mavx512bw" |
| 24 |
# |
| 25 |
# A typical ACTION-IF-FOUND might be: |
| 26 |
# AC_DEFINE(HAVE_AVX512) |
| 27 |
# AVX512_CFLAGS=$esl_avx512_cflags |
| 28 |
# AC_SUBST(AVX512_CFLAGS) |
| 29 |
# |
| 30 |
# (Note that this is correct, even if user provided AVX512_CFLAGS; |
| 31 |
# because if they did, all the macro does is make sure that they |
| 32 |
# work, and sets esl_avx512_cflags=$AVX512_CFLAGS.) |
| 33 |
# |
| 34 |
# Do not replace the AC_LINK with an AC_RUN test. This is a test for |
| 35 |
# whether the _compiler_ supports AVX512, not whether the current |
| 36 |
# processor does. Our code uses runtime dispatching to choose an |
| 37 |
# appropriate ISA for the processor being used. |
| 38 |
# |
| 39 |
AC_DEFUN([ESL_AVX512],[ |
| 40 |
AC_MSG_CHECKING([whether $CC can compile our AVX-512 code]) |
| 41 |
esl_have_avx512=no |
| 42 |
|
| 43 |
# need to loop over array of whitespace-containing strings; |
| 44 |
# here's one way to do it, that I think is portable, by |
| 45 |
# temporarily munging IFS to use comma-delimited lists. |
| 46 |
save_IFS=$IFS |
| 47 |
IFS=, |
| 48 |
if test "x$AVX512_CFLAGS" != x; then |
| 49 |
esl_avx512_try_flags=$AVX_CFLAGS |
| 50 |
else |
| 51 |
esl_avx512_try_flags="none,-mavx512f -mavx512dq -mavx512bw,-xCORE-AVX512,-march=skylake-avx512" |
| 52 |
fi |
| 53 |
|
| 54 |
save_CFLAGS=$CFLAGS |
| 55 |
for esl_avx512_cflags in $esl_avx512_try_flags; do |
| 56 |
case $esl_avx512_cflags in |
| 57 |
none) CFLAGS=$save_CFLAGS;; |
| 58 |
*) CFLAGS="$save_CFLAGS $esl_avx512_cflags";; |
| 59 |
esac |
| 60 |
|
| 61 |
# The test program exercises F, DQ, and BW instructions, compactly. |
| 62 |
IFS=$save_IFS |
| 63 |
AC_LINK_IFELSE([AC_LANG_SOURCE([[ |
| 64 |
#include <x86intrin.h> |
| 65 |
#include <stdint.h> |
| 66 |
int main(void) { |
| 67 |
__m512i v1 = _mm512_set1_epi8(21); |
| 68 |
union { __m256i v; int8_t x[32]; } v2; |
| 69 |
v2.v = _mm512_extracti32x8_epi32(_mm512_adds_epi8(v1, v1), 0x1); |
| 70 |
return (v2.x[0] == 42 ? 0 : 1);} |
| 71 |
]])], [ esl_have_avx512=yes; break; ], []) |
| 72 |
IFS=, |
| 73 |
done |
| 74 |
|
| 75 |
IFS=$save_IFS |
| 76 |
CFLAGS=$save_CFLAGS |
| 77 |
|
| 78 |
if test "$esl_have_avx512" = "no"; then |
| 79 |
AC_MSG_RESULT([no]) |
| 80 |
esl_avx512_cflags= |
| 81 |
else |
| 82 |
if test "$esl_avx512_cflags" = "none"; then |
| 83 |
AC_MSG_RESULT([yes]) |
| 84 |
esl_avx512_cflags= |
| 85 |
else |
| 86 |
AC_MSG_RESULT([yes, with $esl_avx512_cflags]) |
| 87 |
fi |
| 88 |
fi |
| 89 |
|
| 90 |
AS_VAR_IF([esl_have_avx512],[yes],[$1],[$2]) |
| 91 |
]) |
| 92 |
|
| 93 |
|
| 94 |
|