C++ 在 GCC 中使用 AVX - 缺少 avxintrin.h

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18638051/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 22:05:11  来源:igfitidea点击:

Using AVX with GCC - avxintrin.h missing

c++gccavx

提问by toebs

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

我在 Ubuntu-64 位 12.04LTS 上运行我的笔记本电脑(coreI5)。我正在尝试进入 AVX 以生成一些随机数。

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.

在 Eclipse-CDT 中,我使用 Linux GCC 创建了一个新的 C++“Hello World”项目。我包含 immintrin.h 并尝试只加载 __m256 类型的内容。

The Compiler throws an Error:

编译器抛出一个错误:

Type '__m256' was not declared in this scope

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:

我查看了 immintrin.h 并查找了 avxintrin.h,以防万一,有拼写错误。单击 avxintrin.h 上的打开声明时 Eclipse 说:

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.

该文件在 /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(!?)

谁能给我提示,该怎么办?网上关于 AVX 的教程或帮助并不多。我想我必须在编译器选项或类似的东西中做一些调整(!?)

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!

提前致谢!

回答by Greg Allen

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

Compile with-mavx告诉编译器您要使用 AVX 指令。

回答by ZaX83

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.

为了“修复”eclipse“实时代码分析”上的问题,您必须在Window -> Preferences -> C/C++ -> Build -> Settings (Discovery) -> 中全局更新设置(不仅仅是针对项目) CDT GCC 内置编译器设置。

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

在该页面中,您应该在编译器规范的末尾添加: -std=c++11 -mavx

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

这样做您将在 Eclipse 中启用 avx 进行实时代码分析,并且将识别 m256 数据类型

回答by sekhar

for compiling use the command

编译使用命令

gcc -mavx program_name.c

gcc -mavx program_name.c

else __m256 will through the error.

否则 __m256 将通过错误。

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

如果您的 avx 标志被禁用,您将收到以下错误

Illegal instruction (core dumped)

非法指令(核心转储)

for checking your cpu flags use the folloing command

要检查您的 cpu 标志,请使用以下命令

cat /proc/cpuinfo

猫 /proc/cpuinfo