toebs
toebs

Reputation: 409

Using AVX with GCC - avxintrin.h missing

I'm running my Laptop(coreI5) on Ubuntu-64bit 12.04LTS. I'm trying to get into AVX for some random number generation.

In Eclipse-CDT I created a new C++ "Hello World" project using Linux GCC. I included immintrin.h and tried just to load something in a __m256 type.

The Compiler throws an Error:

Type '__m256' was not declared in this scope

I looked in the immintrin.h and looked for the avxintrin.h, just in case, there is a spelling error. When clicking open declaration on avxintrin.h Eclipse says:

Could not find include file 'avxintrin.h' on include paths

allthow the file is available at /usr/lib/gcc/x86_64-linux-gnu/4.6/include/avxintrin.h.

Can anyone give me hint , what to do? There are not a lot of tutorials or help about AVX online. I think I have to make some adjustments in the compiler options or something like this(!?)

Anyways here is the code:

#include <immintrin.h>
#include <iostream>
using namespace std;

int main() {
    float out[8];
    float a[8] = { 0.0,1.0,2.0,3.0,4.0,5.0,6.0,7};
    __m256 test =  _mm256_load_ps(&a[0]);
    cout << "" << endl; // prints 
    return 0;
}

And here the errors:

../src/seminar.cpp:15:2: error: '__m256' was not declared in this scope
../src/seminar.cpp:15:9: error: expected ';' before 'test'

Thanks in advance!

Upvotes: 13

Views: 32726

Answers (3)

sekhar
sekhar

Reputation: 99

for compiling use the command

gcc -mavx program_name.c

else __m256 will through the error.

if your avx flag is disable you will get the below error

Illegal instruction (core dumped)

for checking your cpu flags use the folloing command

cat /proc/cpuinfo

Upvotes: 0

ZaX83
ZaX83

Reputation: 1

In order to "fix" the issue on eclipse "live code analysis" you have to update the settings globally (not just for the project) in Window -> Preferences -> C/C++ -> Build -> Settings (Discovery) -> CDT GCC Built-in Compiler Settings.

In that page you should add this at the end of compiler specs: -std=c++11 -mavx

Doing this you will enable avx for live code analysis in eclipse and m256 data types will be recognised

Upvotes: 0

Greg Allen
Greg Allen

Reputation: 595

Compile with -mavx to tell the compiler that you want to use AVX instructions.

Upvotes: 18

Related Questions