google / XNNPACK

High-efficiency floating-point neural network inference operators for mobile, server, and Web

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

clang compile error

InvisibleLeVen opened this issue · comments

external/XNNPACK/src/f32-dwconv/gen/up8x4-minmax-fma3-acc2.c(69,22): error: assigning to '__m256' (vector of 8 'float' values) from incompatible type 'int'
vacc01234567p0 = _mm256_fmadd_ps(vi0x01234567, vk0x01234567, vacc01234567p0);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
external/XNNPACK/src/f32-dwconv/gen/up8x4-minmax-fma3-acc2.c(81,22): error: assigning to '__m256' (vector of 8 'float' values) from incompatible type 'int'
vacc01234567p0 = _mm256_fmadd_ps(vi2x01234567, vk2x01234567, vacc01234567p0);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
external/XNNPACK/src/f32-dwconv/gen/up8x4-minmax-fma3-acc2.c(87,22): error: assigning to '__m256' (vector of 8 'float' values) from incompatible type 'int'
vacc01234567p1 = _mm256_fmadd_ps(vi3x01234567, vk3x01234567, vacc01234567p1);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
external/XNNPACK/src/f32-dwconv/gen/up8x4-minmax-fma3-acc2.c(109,22): error: assigning to '__m256' (vector of 8 'float' values) from incompatible type 'int'
vacc01234567p0 = _mm256_fmadd_ps(vi0x01234567, vk0x01234567, vacc01234567p0);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
external/XNNPACK/src/f32-dwconv/gen/up8x4-minmax-fma3-acc2.c(117,22): error: assigning to '__m256' (vector of 8 'float' values) from incompatible type 'int'
vacc01234567p0 = _mm256_fmadd_ps(vi2x01234567, vk2x01234567, vacc01234567p0);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
external/XNNPACK/src/f32-dwconv/gen/up8x4-minmax-fma3-acc2.c(121,22): error: assigning to '__m256' (vector of 8 'float' values) from incompatible type 'int'
vacc01234567p1 = _mm256_fmadd_ps(vi3x01234567, vk3x01234567, vacc01234567p1);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6 errors generated.

Do you use a different build systems than CMake or Bazel? It looks like either the build flags aren't properly set, or the compiler is too old.

I use bazel build it and my clang version is 12.0.1

I can't find __m256, _mm256_load_ps in clang include immintrin.h

It's in avxintrin.h. But it seems that immintrin.h does not include it

#if !(defined(_MSC_VER) || defined(SCE)) || __has_feature(modules) ||
defined(AVX)
#include <avxintrin.h>
#endif

Where is _MSC_VER defined

I tried building XNNPACK with Bazel+Clang on a Mac, and it completed successfully.

@Maratyszcza not quite related but do you know what's the minimum Clang version required for the latest XNNPACK? We got an environment with Clang 7 and I wonder if it'll work.

Depends on the platform. You'd need compiler support for AVX512BW instructions on x86-64 and NEON dot product instructions on ARM/ARM64.

@InvisibleLeVen I'm running into something like this when trying to build on Windows with clang 12+. As alluded above, XNNPACK is including <immintrin.h> - but the header doesn't include the intrinsic mentioned above in clang.

I think this works on macOS (and Linux of course) because clang on those platforms defines __GNUC__. So in that case the header x86intrin.h is included and everything works fine.

But I think Windows clang doesn't define __GNUC__. To add insult to injury, clang on Windows will by default prioritize its own system header directories over MSVC's - and so it uses the clang version.

#ifdef __GNUC__
  #include <x86intrin.h>
#else
  #include <immintrin.h>
  #include <ammintrin.h>
#endif

I think a clean fix might involve also checking for __clang__ or equivalent preprocesor define. I imagine though this will be an issue anywhere __GNUC__ is assumed to mean "GCC and Clang".

It looks like a clang-cl bug. Have you tried reporting it there?

I can report this to LLVM so they can provide guidance to third-party packages. It may spur some interesting conversation.

One thing that has been mentioned in other contexts is that clang-cl is meant as a "drop-in" replacement for the MSVC compiler on Windows. This is to maintain compatibility with the MSVC standard library while using LLVM intrinsics.

The net result is that _MSC_VER is defined versus __GNUC__ and its respective major/minor version macro defines. I tried defining __GNUC__ and XNNPACK compiled. Unfortunately other third-party packages outside of XNNPACK failed down the line (i.e. defining GNUC can mean other things, like use GCC inline assembly syntax vs MSVC.)

I could easily see LLVM's response being to wrap the __GNUC__ code with __clang__ as well.