|
| 1 | +# -*- shell-script -*- |
| 2 | +# |
| 3 | +# Copyright (c) 2019-2020 The University of Tennessee and The University |
| 4 | +# of Tennessee Research Foundation. All rights |
| 5 | +# reserved. |
| 6 | +# Copyright (c) 2020 Cisco Systems, Inc. All rights reserved. |
| 7 | +# |
| 8 | +# $COPYRIGHT$ |
| 9 | +# |
| 10 | +# Additional copyrights may follow |
| 11 | +# |
| 12 | +# $HEADER$ |
| 13 | +# |
| 14 | + |
| 15 | +# MCA_ompi_op_avx_CONFIG([action-if-can-compile], |
| 16 | +# [action-if-cant-compile]) |
| 17 | +# ------------------------------------------------ |
| 18 | +# We can always build, unless we were explicitly disabled. |
| 19 | +AC_DEFUN([MCA_ompi_op_avx_CONFIG],[ |
| 20 | + AC_CONFIG_FILES([ompi/mca/op/avx/Makefile]) |
| 21 | + |
| 22 | + MCA_BUILD_OP_AVX_FLAGS="" |
| 23 | + MCA_BUILD_OP_AVX2_FLAGS="" |
| 24 | + MCA_BUILD_OP_AVX512_FLAGS="" |
| 25 | + op_sse3_support=0 |
| 26 | + op_sse41_support=0 |
| 27 | + op_avx_support=0 |
| 28 | + op_avx2_support=0 |
| 29 | + op_avx512_support=0 |
| 30 | + OPAL_VAR_SCOPE_PUSH([op_avx_cflags_save]) |
| 31 | + |
| 32 | + AS_IF([test "$opal_cv_asm_arch" = "X86_64"], |
| 33 | + [AC_LANG_PUSH([C]) |
| 34 | + |
| 35 | + # |
| 36 | + # Check for AVX512 support |
| 37 | + # |
| 38 | + AC_MSG_CHECKING([for AVX512 support (no additional flags)]) |
| 39 | + AC_LINK_IFELSE( |
| 40 | + [AC_LANG_PROGRAM([[#include <immintrin.h>]], |
| 41 | + [[ |
| 42 | + __m512 vA, vB; |
| 43 | + _mm512_add_ps(vA, vB) |
| 44 | + ]])], |
| 45 | + [op_avx512_support=1 |
| 46 | + AC_MSG_RESULT([yes])], |
| 47 | + [AC_MSG_RESULT([no])]) |
| 48 | + |
| 49 | + AS_IF([test $op_avx512_support -eq 0], |
| 50 | + [AC_MSG_CHECKING([for AVX512 support (with -march=skylake-avx512)]) |
| 51 | + op_avx_cflags_save="$CFLAGS" |
| 52 | + CFLAGS="$CFLAGS -march=skylake-avx512" |
| 53 | + AC_LINK_IFELSE( |
| 54 | + [AC_LANG_PROGRAM([[#include <immintrin.h>]], |
| 55 | + [[ |
| 56 | + __m512 vA, vB; |
| 57 | + _mm512_add_ps(vA, vB) |
| 58 | + ]])], |
| 59 | + [op_avx512_support=1 |
| 60 | + MCA_BUILD_OP_AVX512_FLAGS="-march=skylake-avx512" |
| 61 | + AC_MSG_RESULT([yes])], |
| 62 | + [AC_MSG_RESULT([no])]) |
| 63 | + CFLAGS="$op_avx_cflags_save" |
| 64 | + ]) |
| 65 | + # |
| 66 | + # Some combination of gcc and older as would not correctly build the code generated by |
| 67 | + # _mm256_loadu_si256. Screen them out. |
| 68 | + # |
| 69 | + AS_IF([test $op_avx512_support -eq 1], |
| 70 | + [AC_MSG_CHECKING([if _mm512_loadu_si512 generates code that can be compiled]) |
| 71 | + op_avx_cflags_save="$CFLAGS" |
| 72 | + CFLAGS="$CFLAGS_WITHOUT_OPTFLAGS -O0 $MCA_BUILD_OP_AVX512_FLAGS" |
| 73 | + AC_LINK_IFELSE( |
| 74 | + [AC_LANG_PROGRAM([[#include <immintrin.h>]], |
| 75 | + [[ |
| 76 | + int A[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; |
| 77 | + __m512i vA = _mm512_loadu_si512((__m512i*)&(A[1])) |
| 78 | + ]])], |
| 79 | + [AC_MSG_RESULT([yes])], |
| 80 | + [op_avx512_support=0 |
| 81 | + MCA_BUILD_OP_AVX512_FLAGS="" |
| 82 | + AC_MSG_RESULT([no])]) |
| 83 | + CFLAGS="$op_avx_cflags_save" |
| 84 | + ]) |
| 85 | + # |
| 86 | + # Check support for AVX2 |
| 87 | + # |
| 88 | + AC_MSG_CHECKING([for AVX2 support (no additional flags)]) |
| 89 | + AC_LINK_IFELSE( |
| 90 | + [AC_LANG_PROGRAM([[#include <immintrin.h>]], |
| 91 | + [[ |
| 92 | + __m256 vA, vB; |
| 93 | + _mm256_add_ps(vA, vB) |
| 94 | + ]])], |
| 95 | + [op_avx2_support=1 |
| 96 | + AC_MSG_RESULT([yes])], |
| 97 | + [AC_MSG_RESULT([no])]) |
| 98 | + AS_IF([test $op_avx2_support -eq 0], |
| 99 | + [AC_MSG_CHECKING([for AVX2 support (with -mavx2)]) |
| 100 | + op_avx_cflags_save="$CFLAGS" |
| 101 | + CFLAGS="$CFLAGS -mavx2" |
| 102 | + AC_LINK_IFELSE( |
| 103 | + [AC_LANG_PROGRAM([[#include <immintrin.h>]], |
| 104 | + [[ |
| 105 | + __m256 vA, vB; |
| 106 | + _mm256_add_ps(vA, vB) |
| 107 | + ]])], |
| 108 | + [op_avx2_support=1 |
| 109 | + MCA_BUILD_OP_AVX2_FLAGS="-mavx2" |
| 110 | + AC_MSG_RESULT([yes])], |
| 111 | + [AC_MSG_RESULT([no])]) |
| 112 | + CFLAGS="$op_avx_cflags_save" |
| 113 | + ]) |
| 114 | + # |
| 115 | + # Some combination of gcc and older as would not correctly build the code generated by |
| 116 | + # _mm256_loadu_si256. Screen them out. |
| 117 | + # |
| 118 | + AS_IF([test $op_avx2_support -eq 1], |
| 119 | + [AC_MSG_CHECKING([if _mm256_loadu_si256 generates code that can be compiled]) |
| 120 | + op_avx_cflags_save="$CFLAGS" |
| 121 | + CFLAGS="$CFLAGS_WITHOUT_OPTFLAGS -O0 $MCA_BUILD_OP_AVX2_FLAGS" |
| 122 | + AC_LINK_IFELSE( |
| 123 | + [AC_LANG_PROGRAM([[#include <immintrin.h>]], |
| 124 | + [[ |
| 125 | + int A[8] = {0, 1, 2, 3, 4, 5, 6, 7}; |
| 126 | + __m256i vA = _mm256_loadu_si256((__m256i*)&A) |
| 127 | + ]])], |
| 128 | + [AC_MSG_RESULT([yes])], |
| 129 | + [op_avx2_support=0 |
| 130 | + MCA_BUILD_OP_AVX2_FLAGS="" |
| 131 | + AC_MSG_RESULT([no])]) |
| 132 | + CFLAGS="$op_avx_cflags_save" |
| 133 | + ]) |
| 134 | + # |
| 135 | + # What about early AVX support. The rest of the logic is slightly different as |
| 136 | + # we need to include some of the SSE4.1 and SSE3 instructions. So, we first check |
| 137 | + # if we can compile AVX code without a flag, then we validate that we have support |
| 138 | + # for the SSE4.1 and SSE3 instructions we need. If not, we check for the usage of |
| 139 | + # the AVX flag, and then recheck if we have support for the SSE4.1 and SSE3 |
| 140 | + # instructions. |
| 141 | + # |
| 142 | + AC_MSG_CHECKING([for AVX support (no additional flags)]) |
| 143 | + AC_LINK_IFELSE( |
| 144 | + [AC_LANG_PROGRAM([[#include <immintrin.h>]], |
| 145 | + [[ |
| 146 | + __m128 vA, vB; |
| 147 | + _mm_add_ps(vA, vB) |
| 148 | + ]])], |
| 149 | + [op_avx_support=1 |
| 150 | + AC_MSG_RESULT([yes])], |
| 151 | + [AC_MSG_RESULT([no])]) |
| 152 | + # |
| 153 | + # Check for SSE4.1 support |
| 154 | + # |
| 155 | + AS_IF([test $op_avx_support -eq 1], |
| 156 | + [AC_MSG_CHECKING([for SSE4.1 support]) |
| 157 | + AC_LINK_IFELSE( |
| 158 | + [AC_LANG_PROGRAM([[#include <immintrin.h>]], |
| 159 | + [[ |
| 160 | + __m128i vA, vB; |
| 161 | + (void)_mm_max_epi8(vA, vB) |
| 162 | + ]])], |
| 163 | + [op_sse41_support=1 |
| 164 | + AC_MSG_RESULT([yes])], |
| 165 | + [AC_MSG_RESULT([no])]) |
| 166 | + ]) |
| 167 | + # |
| 168 | + # Check for SSE3 support |
| 169 | + # |
| 170 | + AS_IF([test $op_avx_support -eq 1], |
| 171 | + [AC_MSG_CHECKING([for SSE3 support]) |
| 172 | + AC_LINK_IFELSE( |
| 173 | + [AC_LANG_PROGRAM([[#include <immintrin.h>]], |
| 174 | + [[ |
| 175 | + int A[4] = {0, 1, 2, 3}; |
| 176 | + __m128i vA = _mm_lddqu_si128((__m128i*)&A) |
| 177 | + ]])], |
| 178 | + [op_sse3_support=1 |
| 179 | + AC_MSG_RESULT([yes])], |
| 180 | + [AC_MSG_RESULT([no])]) |
| 181 | + ]) |
| 182 | + # Second pass, do we need to add the AVX flag ? |
| 183 | + AS_IF([test $op_avx_support -eq 0 || test $op_sse41_support -eq 0 || test $op_sse3_support -eq 0], |
| 184 | + [AC_MSG_CHECKING([for AVX support (with -mavx)]) |
| 185 | + op_avx_cflags_save="$CFLAGS" |
| 186 | + CFLAGS="$CFLAGS -mavx" |
| 187 | + AC_LINK_IFELSE( |
| 188 | + [AC_LANG_PROGRAM([[#include <immintrin.h>]], |
| 189 | + [[ |
| 190 | + __m128 vA, vB; |
| 191 | + _mm_add_ps(vA, vB) |
| 192 | + ]])], |
| 193 | + [op_avx_support=1 |
| 194 | + MCA_BUILD_OP_AVX_FLAGS="-mavx" |
| 195 | + op_sse41_support=0 |
| 196 | + op_sse3_support=0 |
| 197 | + AC_MSG_RESULT([yes])], |
| 198 | + [AC_MSG_RESULT([no])]) |
| 199 | +
|
| 200 | + AS_IF([test $op_sse41_support -eq 0], |
| 201 | + [AC_MSG_CHECKING([for SSE4.1 support]) |
| 202 | + AC_LINK_IFELSE( |
| 203 | + [AC_LANG_PROGRAM([[#include <immintrin.h>]], |
| 204 | + [[ |
| 205 | + __m128i vA, vB; |
| 206 | + (void)_mm_max_epi8(vA, vB) |
| 207 | + ]])], |
| 208 | + [op_sse41_support=1 |
| 209 | + AC_MSG_RESULT([yes])], |
| 210 | + [AC_MSG_RESULT([no])]) |
| 211 | + ]) |
| 212 | + AS_IF([test $op_sse3_support -eq 0], |
| 213 | + [AC_MSG_CHECKING([for SSE3 support]) |
| 214 | + AC_LINK_IFELSE( |
| 215 | + [AC_LANG_PROGRAM([[#include <immintrin.h>]], |
| 216 | + [[ |
| 217 | + int A[4] = {0, 1, 2, 3}; |
| 218 | + __m128i vA = _mm_lddqu_si128((__m128i*)&A) |
| 219 | + ]])], |
| 220 | + [op_sse3_support=1 |
| 221 | + AC_MSG_RESULT([yes])], |
| 222 | + [AC_MSG_RESULT([no])]) |
| 223 | + ]) |
| 224 | + CFLAGS="$op_avx_cflags_save" |
| 225 | + ]) |
| 226 | +
|
| 227 | + AC_LANG_POP([C]) |
| 228 | + ]) |
| 229 | + AC_DEFINE_UNQUOTED([OMPI_MCA_OP_HAVE_AVX512], |
| 230 | + [$op_avx512_support], |
| 231 | + [AVX512 supported in the current build]) |
| 232 | + AC_DEFINE_UNQUOTED([OMPI_MCA_OP_HAVE_AVX2], |
| 233 | + [$op_avx2_support], |
| 234 | + [AVX2 supported in the current build]) |
| 235 | + AC_DEFINE_UNQUOTED([OMPI_MCA_OP_HAVE_AVX], |
| 236 | + [$op_avx_support], |
| 237 | + [AVX supported in the current build]) |
| 238 | + AC_DEFINE_UNQUOTED([OMPI_MCA_OP_HAVE_SSE41], |
| 239 | + [$op_sse41_support], |
| 240 | + [SSE4.1 supported in the current build]) |
| 241 | + AC_DEFINE_UNQUOTED([OMPI_MCA_OP_HAVE_SSE3], |
| 242 | + [$op_sse3_support], |
| 243 | + [SSE3 supported in the current build]) |
| 244 | + AM_CONDITIONAL([MCA_BUILD_ompi_op_has_avx512_support], |
| 245 | + [test "$op_avx512_support" == "1"]) |
| 246 | + AM_CONDITIONAL([MCA_BUILD_ompi_op_has_avx2_support], |
| 247 | + [test "$op_avx2_support" == "1"]) |
| 248 | + AM_CONDITIONAL([MCA_BUILD_ompi_op_has_avx_support], |
| 249 | + [test "$op_avx_support" == "1"]) |
| 250 | + AM_CONDITIONAL([MCA_BUILD_ompi_op_has_sse41_support], |
| 251 | + [test "$op_sse41_support" == "1"]) |
| 252 | + AM_CONDITIONAL([MCA_BUILD_ompi_op_has_sse3_support], |
| 253 | + [test "$op_sse3_support" == "1"]) |
| 254 | + AC_SUBST(MCA_BUILD_OP_AVX512_FLAGS) |
| 255 | + AC_SUBST(MCA_BUILD_OP_AVX2_FLAGS) |
| 256 | + AC_SUBST(MCA_BUILD_OP_AVX_FLAGS) |
| 257 | +
|
| 258 | + OPAL_VAR_SCOPE_POP |
| 259 | + # Enable this component iff we have at least the most basic form of support |
| 260 | + # for vectorial ISA |
| 261 | + AS_IF([test $op_avx_support -eq 1 || test $op_avx2_support -eq 1 || test $op_avx512_support -eq 1], |
| 262 | + [$1], |
| 263 | + [$2]) |
| 264 | +
|
| 265 | +])dnl |
0 commit comments