在AVX上使用AVX2 / AVX512内部函数编译C ++代码 [英] Compile C++ code with AVX2/AVX512 intrinsics on AVX

查看:1323
本文介绍了在AVX上使用AVX2 / AVX512内部函数编译C ++代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的生产代码具有针对各种SIMD指令集(包括AVX,AVX2和AVX512)实现的内核。可以使用在目标计算机上为目标计算机编译代码。/configure--enable-proc = AVX CXXFLAGS =-mavx

I have production code that has kernels implemented for various SIMD instruction sets, including AVX, AVX2, and AVX512. The code can be compiled on the target machine for the target machine with something like ./configure --enable-proc=AVX CXXFLAGS="-mavx".

这在Travis CI(公开AVX内部函数)上也很好用。我想至少编译AVX2和AVX512版本,以查看是否所有文件都已签入。但是似乎为不同的ISA编译并不是那么容易。

This also works well on Travis CI which exposes AVX intrinsics. I would like to at least compile the AVX2 and AVX512 versions in order to see whether all files are checked in. But it seems that compiling for a different ISA is not that easy.

一个简单的AVX2测试程序:

A simple AVX2 test program:

#include <immintrin.h>

int main(int argc, char **argv) {
    __m256d a;
    __m256d b;
    __m256d c;

    _mm256_fnmadd_pd(a, b, c);
}

在我的AVX机器(Intel Core i5-2520M)上,它无法编译:

On my AVX machine (Intel Core i5-2520M), it does not compile:

$ g++ -Wall -Wpedantic --std=c++11 cpp.cpp -mavx2
In file included from /usr/lib/gcc/x86_64-redhat-linux/6.3.1/include/immintrin.h:79:0,
                 from cpp.cpp:3:
/usr/lib/gcc/x86_64-redhat-linux/6.3.1/include/fmaintrin.h:143:1: error: inlining failed in call to always_inline '__m256d _mm256_fnmadd_pd(__m256d, __m256d, __m256d)': target specific option mismatch
 _mm256_fnmadd_pd (__m256d __A, __m256d __B, __m256d __C)
 ^~~~~~~~~~~~~~~~

是否有某种方式可以编译代码?我不在乎跑步,我只想要抽烟测试。

Is there some way to compile the code? I do not care about running, I just want a smoke-test.

推荐答案

提供 -march = sandybridge -march = haswell -march = knl 启用所有必需的功能翻译代码。

Supplying -march=sandybridge, -march=haswell or -march=knl enables all the needed features to translate the code.

这篇关于在AVX上使用AVX2 / AVX512内部函数编译C ++代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆