Repository: pytorch
Issue: Build check for AVX512 fails with AMD CPU and march=native
Labels: module: build,triaged,module: vectorization

### 🐛 Describe the bug

```
Performing C SOURCE FILE Test C_HAS_AVX512_1 failed with the following output:
Change Dir: ./build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/ninja cmTC_02713 && [1/2] Building C object CMakeFiles/cmTC_02713.dir/src.c.o
FAILED: CMakeFiles/cmTC_02713.dir/src.c.o 
/usr/bin/cc -DC_HAS_AVX512_1  -march=native -mtune=native -O3 -pipe -Wno-deprecated-declarations -Wno-maybe-uninitialized   -std=gnu11 -o CMakeFiles/cmTC_02713.dir/src.c.o -c ./build/CMakeFiles/CMakeTmp/src.c
./build/CMakeFiles/CMakeTmp/src.c: In function 'main':
./build/CMakeFiles/CMakeTmp/src.c:6:13: warning: AVX512F vector return without AVX512F enabled changes the ABI [-Wpsabi]
    6 |     __m512i a = _mm512_set_epi8(0, 0, 0, 0, 0, 0, 0, 0,
      |             ^
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/12.1.0/include/immintrin.h:59,
                 from ./build/CMakeFiles/CMakeTmp/src.c:2:
/usr/lib/gcc/x86_64-pc-linux-gnu/12.1.0/include/avx512bwintrin.h:3088:1: error: inlining failed in call to 'always_inline' '_mm512_cmp_epi8_mask': target specific option mismatch
 3088 | _mm512_cmp_epi8_mask (__m512i __X, __m512i __Y, const int __P)
      | ^~~~~~~~~~~~~~~~~~~~
./build/CMakeFiles/CMakeTmp/src.c:15:31: note: called from here
   15 |     __mmask64 equality_mask = _mm512_cmp_epi8_mask(a, b, _MM_CMPINT_EQ);
      |                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/12.1.0/include/immintrin.h:49:
/usr/lib/gcc/x86_64-pc-linux-gnu/12.1.0/include/avx512fintrin.h:121:1: error: inlining failed in call to 'always_inline' '_mm512_set_epi8': target specific option mismatch
  121 | _mm512_set_epi8 (char __q63, char __q62, char __q61, char __q60,
      | ^~~~~~~~~~~~~~~
./build/CMakeFiles/CMakeTmp/src.c:6:17: note: called from here
    6 |     __m512i a = _mm512_set_epi8(0, 0, 0, 0, 0, 0, 0, 0,
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    7 |                                 0, 0, 0, 0, 0, 0, 0, 0,
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~
    8 |                                 0, 0, 0, 0, 0, 0, 0, 0,
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~
    9 |                                 0, 0, 0, 0, 0, 0, 0, 0,
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~
   10 |                                 0, 0, 0, 0, 0, 0, 0, 0,
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~
   11 |                                 0, 0, 0, 0, 0, 0, 0, 0,
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~
   12 |                                 0, 0, 0, 0, 0, 0, 0, 0,
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~
   13 |                                 0, 0, 0, 0, 0, 0, 0, 0);
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~
ninja: build stopped: subcommand failed.


Source file was:

  #include <immintrin.h>

  int main()
  {
    __m512i a = _mm512_set_epi8(0, 0, 0, 0, 0, 0, 0, 0,
                                0, 0, 0, 0, 0, 0, 0, 0,
                                0, 0, 0, 0, 0, 0, 0, 0,
                                0, 0, 0, 0, 0, 0, 0, 0,
                                0, 0, 0, 0, 0, 0, 0, 0,
                                0, 0, 0, 0, 0, 0, 0, 0,
                                0, 0, 0, 0, 0, 0, 0, 0,
                                0, 0, 0, 0, 0, 0, 0, 0);
    __m512i b = a;
    __mmask64 equality_mask = _mm512_cmp_epi8_mask(a, b, _MM_CMPINT_EQ);
    return 0;
  }

Performing C SOURCE FILE Test CXX_HAS_AVX512_1 failed with the following output:
Change Dir: ./build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/ninja cmTC_d12b0 && [1/2] Building C object CMakeFiles/cmTC_d12b0.dir/src.c.o
FAILED: CMakeFiles/cmTC_d12b0.dir/src.c.o 
/usr/bin/cc -DCXX_HAS_AVX512_1  -march=native -mtune=native -O3 -pipe -Wno-deprecated-declarations -Wno-maybe-uninitialized   -std=gnu11 -o CMakeFiles/cmTC_d12b0.dir/src.c.o -c ./build/CMakeFiles/CMakeTmp/src.c
./build/CMakeFiles/CMakeTmp/src.c: In function 'main':
./build/CMakeFiles/CMakeTmp/src.c:6:13: warning: AVX512F vector return without AVX512F enabled changes the ABI [-Wpsabi]
    6 |     __m512i a = _mm512_set_epi8(0, 0, 0, 0, 0, 0, 0, 0,
      |             ^
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/12.1.0/include/immintrin.h:59,
                 from ./build/CMakeFiles/CMakeTmp/src.c:2:
/usr/lib/gcc/x86_64-pc-linux-gnu/12.1.0/include/avx512bwintrin.h:3088:1: error: inlining failed in call to 'always_inline' '_mm512_cmp_epi8_mask': target specific option mismatch
 3088 | _mm512_cmp_epi8_mask (__m512i __X, __m512i __Y, const int __P)
      | ^~~~~~~~~~~~~~~~~~~~
./build/CMakeFiles/CMakeTmp/src.c:15:31: note: called from here
   15 |     __mmask64 equality_mask = _mm512_cmp_epi8_mask(a, b, _MM_CMPINT_EQ);
      |                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/12.1.0/include/immintrin.h:49:
/usr/lib/gcc/x86_64-pc-linux-gnu/12.1.0/include/avx512fintrin.h:121:1: error: inlining failed in call to 'always_inline' '_mm512_set_epi8': target specific option mismatch
  121 | _mm512_set_epi8 (char __q63, char __q62, char __q61, char __q60,
      | ^~~~~~~~~~~~~~~
./build/CMakeFiles/CMakeTmp/src.c:6:17: note: called from here
    6 |     __m512i a = _mm512_set_epi8(0, 0, 0, 0, 0, 0, 0, 0,
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    7 |                                 0, 0, 0, 0, 0, 0, 0, 0,
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~
    8 |                                 0, 0, 0, 0, 0, 0, 0, 0,
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~
    9 |                                 0, 0, 0, 0, 0, 0, 0, 0,
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~
   10 |                                 0, 0, 0, 0, 0, 0, 0, 0,
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~
   11 |                                 0, 0, 0, 0, 0, 0, 0, 0,
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~
   12 |                                 0, 0, 0, 0, 0, 0, 0, 0,
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~
   13 |                                 0, 0, 0, 0, 0, 0, 0, 0);
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~
ninja: build stopped: subcommand failed.


Source file was:

  #include <immintrin.h>

  int main()
  {
    __m512i a = _mm512_set_epi8(0, 0, 0, 0, 0, 0, 0, 0,
                                0, 0, 0, 0, 0, 0, 0, 0,
                                0, 0, 0, 0, 0, 0, 0, 0,
                                0, 0, 0, 0, 0, 0, 0, 0,
                                0, 0, 0, 0, 0, 0, 0, 0,
                                0, 0, 0, 0, 0, 0, 0, 0,
                                0, 0, 0, 0, 0, 0, 0, 0,
                                0, 0, 0, 0, 0, 0, 0, 0);
    __m512i b = a;
    __mmask64 equality_mask = _mm512_cmp_epi8_mask(a, b, _MM_CMPINT_EQ);
    return 0;
  }

Performing C SOURCE FILE Test BLAS_F2C_DOUBLE_WORKS failed with the following compile output:
Change Dir: ./build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/ninja cmTC_47eb1 && [1/2] Building C object CMakeFiles/cmTC_47eb1.dir/src.c.o
[2/2] Linking C executable cmTC_47eb1


...and run output:

Return value: 1
Source file was:

  #include <stdlib.h>
  #include <stdio.h>
  float x[4] = { 1, 2, 3, 4 };
  float y[4] = { .1, .01, .001, .0001 };
  int four = 4;
  int one = 1;
  extern double sdot_();
  int main() {
    int i;
    double r = sdot_(&four, x, &one, y, &one);
    exit((float)r != (float).1234);
  }
Determining if the function sbgemm_ exists failed with the following output:
Change Dir: ./build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/ninja cmTC_fd0ef && [1/2] Building C object CMakeFiles/cmTC_fd0ef.dir/CheckFunctionExists.c.o
[2/2] Linking C executable cmTC_fd0ef
FAILED: cmTC_fd0ef 
: && /usr/bin/cc -march=native -mtune=native -O3 -pipe -Wno-deprecated-declarations -Wno-maybe-uninitialized -DCHECK_FUNCTION_EXISTS=sbgemm_ -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -rdynamic CMakeFiles/cmTC_fd0ef.dir/CheckFunctionExists.c.o -o cmTC_fd0ef  /usr/lib/libopenblas.so && :
/usr/bin/ld: CMakeFiles/cmTC_fd0ef.dir/CheckFunctionExists.c.o: in function `main':
CheckFunctionExists.c:(.text.startup+0xc): undefined reference to `sbgemm_'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.



Performing C SOURCE FILE Test NNPACK_ARCH_IS_X86_32 failed with the following output:
Change Dir: ./build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/ninja cmTC_22689 && [1/2] Building C object CMakeFiles/cmTC_22689.dir/src.c.o
FAILED: CMakeFiles/cmTC_22689.dir/src.c.o 
/usr/bin/cc -DNNPACK_ARCH_IS_X86_32  -march=native -mtune=native -O3 -pipe -Wno-deprecated-declarations -Wno-maybe-uninitialized  -std=gnu11 -o CMakeFiles/cmTC_22689.dir/src.c.o -c ./build/CMakeFiles/CMakeTmp/src.c
./build/CMakeFiles/CMakeTmp/src.c:3:10: error: #error AVX only on x86_64
    3 |         #error AVX only on x86_64
      |          ^~~~~
ninja: build stopped: subcommand failed.


Source file was:

      #if ! (defined(__i386) || defined(_M_IX86))
        #error AVX only on x86_64
      #endif
      int main() {
        return 0;
      }
Performing C++ SOURCE FILE Test HAVE_CXX_FLAG_WSHORTEN_64_TO_32 failed with the following output:
Change Dir: ./build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/ninja cmTC_37d75 && [1/2] Building CXX object CMakeFiles/cmTC_37d75.dir/src.cxx.o
FAILED: CMakeFiles/cmTC_37d75.dir/src.cxx.o 
/usr/bin/c++ -DHAVE_CXX_FLAG_WSHORTEN_64_TO_32  -march=native -mtune=native -O3 -pipe -fno-plt -Wno-deprecated-declarations -Wno-maybe-uninitialized -Wno-array-bounds -Wno-uninitialized -fvisibility-inlines-hidden -DUSE_PTHREADPOOL  -std=c++11  -Wall  -Wextra  -Wshadow  -Wsuggest-override  -pedantic  -pedantic-errors  -Wshorten-64-to-32   -Wshorten-64-to-32 -std=gnu++14 -o CMakeFiles/cmTC_37d75.dir/src.cxx.o -c ./build/CMakeFiles/CMakeTmp/src.cxx
c++: error: unrecognized command-line option '-Wshorten-64-to-32'
c++: error: unrecognized command-line option '-Wshorten-64-to-32'
ninja: build stopped: subcommand failed.


Source file was:
int main() { return 0; }
Performing C++ SOURCE FILE Test HAVE_CXX_FLAG_WD654 failed with the following output:
Change Dir: ./build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/ninja cmTC_0b897 && [1/2] Building CXX object CMakeFiles/cmTC_0b897.dir/src.cxx.o
FAILED: CMakeFiles/cmTC_0b897.dir/src.cxx.o 
/usr/bin/c++ -DHAVE_CXX_FLAG_WD654  -march=native -mtune=native -O3 -pipe -fno-plt -Wno-deprecated-declarations -Wno-maybe-uninitialized -Wno-array-bounds -Wno-uninitialized -fvisibility-inlines-hidden -DUSE_PTHREADPOOL  -std=c++11  -Wall  -Wextra  -Wshadow  -Wsuggest-override  -pedantic  -pedantic-errors  -fstrict-aliasing  -Wno-deprecated-declarations  -Wstrict-aliasing  -wd654   -wd654 -std=gnu++14 -o CMakeFiles/cmTC_0b897.dir/src.cxx.o -c ./build/CMakeFiles/CMakeTmp/src.cxx
c++: error: unrecognized command-line option '-wd654'
c++: error: unrecognized command-line option '-wd654'
ninja: build stopped: subcommand failed.


Source file was:
int main() { return 0; }
Performing C++ SOURCE FILE Test HAVE_CXX_FLAG_WTHREAD_SAFETY failed with the following output:
Change Dir: ./build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/ninja cmTC_34f90 && [1/2] Building CXX object CMakeFiles/cmTC_34f90.dir/src.cxx.o
FAILED: CMakeFiles/cmTC_34f90.dir/src.cxx.o 
/usr/bin/c++ -DHAVE_CXX_FLAG_WTHREAD_SAFETY  -march=native -mtune=native -O3 -pipe -fno-plt -Wno-deprecated-declarations -Wno-maybe-uninitialized -Wno-array-bounds -Wno-uninitialized -fvisibility-inlines-hidden -DUSE_PTHREADPOOL  -std=c++11  -Wall  -Wextra  -Wshadow  -Wsuggest-override  -pedantic  -pedantic-errors  -fstrict-aliasing  -Wno-deprecated-declarations  -Wstrict-aliasing  -Wthread-safety   -Wthread-safety -std=gnu++14 -o CMakeFiles/cmTC_34f90.dir/src.cxx.o -c ./build/CMakeFiles/CMakeTmp/src.cxx
c++: error: unrecognized command-line option '-Wthread-safety'
c++: error: unrecognized command-line option '-Wthread-safety'
ninja: build stopped: subcommand failed.


Source file was:
int main() { return 0; }
Determining if the prototype magma_get_sgeqrf_nb exists for MAGMA_V2 failed with the following output:
Change Dir: ./build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/ninja cmTC_e0004 && [1/2] Building C object CMakeFiles/cmTC_e0004.dir/CheckPrototypeDefinition.c.o
FAILED: CMakeFiles/cmTC_e0004.dir/CheckPrototypeDefinition.c.o 
/usr/bin/cc   -march=native -mtune=native -O3 -pipe -Wno-deprecated-declarations -Wno-maybe-uninitialized -fopenmp -DNDEBUG  -fPIE -std=gnu11 -o CMakeFiles/cmTC_e0004.dir/CheckPrototypeDefinition.c.o -c ./build/CMakeFiles/CMakeTmp/CheckPrototypeDefinition.c
./build/CMakeFiles/CMakeTmp/CheckPrototypeDefinition.c:1:10: fatal error: magma.h: No such file or directory
    1 | #include <magma.h>
      |          ^~~~~~~~~
compilation terminated.
ninja: build stopped: subcommand failed.



#include <magma.h>


static void cmakeRequireSymbol(int dummy, ...) {
  (void) dummy;
}

static void checkSymbol(void) {
#ifndef magma_get_sgeqrf_nb
  cmakeRequireSymbol(0, &magma_get_sgeqrf_nb);
#endif
}

magma_int_t magma_get_sgeqrf_nb( magma_int_t m, magma_int_t n ) {
  return 0;
}

#ifdef __CLASSIC_C__
int main() {
  int ac;
  char*av[];
#else
int main(int ac, char *av[]) {
#endif
  checkSymbol();
  if (ac > 1000) {
    return *av[0];
  }
  return 0;
}


Determining if the strtod_l exist failed with the following output:
Change Dir: ./build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/ninja cmTC_d0839 && [1/2] Building C object CMakeFiles/cmTC_d0839.dir/CheckSymbolExists.c.o
FAILED: CMakeFiles/cmTC_d0839.dir/CheckSymbolExists.c.o 
/usr/bin/cc   -march=native -mtune=native -O3 -pipe -Wno-deprecated-declarations -Wno-maybe-uninitialized -fopenmp -DNDEBUG  -fPIE -std=gnu11 -o CMakeFiles/cmTC_d0839.dir/CheckSymbolExists.c.o -c ./build/CMakeFiles/CMakeTmp/CheckSymbolExists.c
./build/CMakeFiles/CMakeTmp/CheckSymbolExists.c: In function 'main':
./build/CMakeFiles/CMakeTmp/CheckSymbolExists.c:8:19: error: 'strtod_l' undeclared (first use in this function); did you mean 'strtoull'?
    8 |   return ((int*)(&strtod_l))[argc];
      |                   ^~~~~~~~
      |                   strtoull
./build/CMakeFiles/CMakeTmp/CheckSymbolExists.c:8:19: note: each undeclared identifier is reported only once for each function it appears in
ninja: build stopped: subcommand failed.


File ./build/CMakeFiles/CMakeTmp/CheckSymbolExists.c:
/* */
#include <stdlib.h>

int main(int argc, char** argv)
{
  (void)argv;
#ifndef strtod_l
  return ((int*)(&strtod_l))[argc];
#else
  (void)argc;
  return 0;
#endif
}
```

### Versions

Pytorch: git master 1.11.1
GCC: 12.1 - supports AVX512

cc @malfet @seemethere