12

I have production code that has kernels implemented for various SIMD instruction sets, including AVX, AVX2, and AVX512. The code can be compiled on the target machine for the target machine with something like ./configure --enable-proc=AVX CXXFLAGS="-mavx".

This also works well on Travis CI which exposes AVX intrinsics. I would like to at least compile the AVX2 and AVX512 versions in order to see whether all files are checked in. But it seems that compiling for a different ISA is not that easy.

A simple AVX2 test program:

#include <immintrin.h>

int main(int argc, char **argv) {
    __m256d a;
    __m256d b;
    __m256d c;

    _mm256_fnmadd_pd(a, b, c);
}

On my AVX machine (Intel Core i5-2520M), it does not compile:

$ g++ -Wall -Wpedantic --std=c++11 cpp.cpp -mavx2
In file included from /usr/lib/gcc/x86_64-redhat-linux/6.3.1/include/immintrin.h:79:0,
                 from cpp.cpp:3:
/usr/lib/gcc/x86_64-redhat-linux/6.3.1/include/fmaintrin.h:143:1: error: inlining failed in call to always_inline '__m256d _mm256_fnmadd_pd(__m256d, __m256d, __m256d)': target specific option mismatch
 _mm256_fnmadd_pd (__m256d __A, __m256d __B, __m256d __C)
 ^~~~~~~~~~~~~~~~

Is there some way to compile the code? I do not care about running, I just want a smoke-test.

Martin Ueding
  • 8,245
  • 6
  • 46
  • 92
  • 3
    Not sure if it's supposed to be like that, but your particular example works for me if I enable `-march=haswell`. – Dolda2000 Apr 25 '17 at 14:41
  • As the name of the function (or Intel's documentation) indicates, you need `-mfma` to tell the compiler that you want to compile for such a target. Or of course some `-march=` flag that implies it. – Marc Glisse Apr 25 '17 at 15:30

1 Answers1

8

Supplying -march=sandybridge, -march=haswell or -march=knl enables all the needed features to translate the code.

Martin Ueding
  • 8,245
  • 6
  • 46
  • 92