I have been trying to get AVX to run properly yet I am not able to compile my c++ project. I am new to C++ and the compiling so I use CMake together with CLion and GCC.
I know that my processor supports AVX and AVX2 and I wrote a simple test program:
#include <immintrin.h>
...
__m256 A{};
__m256 B{};
__m256 AB = _mm256_add_ps(A,B);
for(int i = 0; i < 8; i++){
std::cout << AB[i] << std::endl;
}
Sadly when trying to run this, I get the following error:
warning: AVX vector return without AVX enabled changes the ABI [-Wpsabi]
91 | __m256 AB = _mm256_add_ps(A,B);
| ^
In file included from C:/msys64/mingw64/lib/gcc/x86_64-w64-mingw32/10.1.0/include/immintrin.h:51,
from A:\OneDrive\ProgrammSpeicher\CLionProjects\Koivisto\src_files\main.cpp:85:
C:/msys64/mingw64/lib/gcc/x86_64-w64-mingw32/10.1.0/include/avxintrin.h:147:1: error: inlining failed in call to 'always_inline' '__m256 _mm256_add_ps(__m256, __m256)': target specific option mismatch
147 | _mm256_add_ps (__m256 __A, __m256 __B)
I assume I need to set some flag in my CmakeLists.txt but I didnt find anything for this on the web.
I am very happy if someone could help me out!
Greetings, Finn
SOLUTION
I had to add
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
and it will compile nicely.