【发布时间】:2018-06-23 16:49:40
【问题描述】:
我们有一个我们想用 AVX2 编译的翻译单元(只有那个): 它预先告诉 GCC,文件中的第一行:
#pragma GCC target "arch=core-avx2,tune=core-avx2"
这曾经与 GCC 4.8 和 4.9 一起工作,但从 6 开始(也尝试了 7 和 8)我们收到此警告(我们将其视为错误):
error: SSE instruction set disabled, using 387 arithmetics
在第一个函数返回一个浮点数。我试图像这样启用回 SSE 4.2(以及 avx 和 avx2)
#pragma GCC target "sse4.2,arch=core-avx2,tune=core-avx2"
但这还不够,错误仍然存在。
编辑:
相关编译器标志,我们将 AVX 用于大多数东西:
-mfpmath=sse,387 -march=corei7-avx -mtune=corei7-avx
EDIT2:最小样本:
#pragma GCC target "arch=core-avx2,tune=core-avx2"
#include <immintrin.h>
#include <math.h>
static inline float
lg1pf( float x ) {
return log1pf(x)*1.44269504088896338700465f;
}
int main()
{
log1pf(2.0f);
}
这样编译的:
gcc -o test test.c -O2 -Wall -Werror -pedantic -std=c99 -mfpmath=sse,387 -march=corei7-avx -mtune=corei7-avx
In file included from /home/xxx/gcc-7.1.0/lib/gcc/x86_64-pc-linux-gnu/7.1.0/include/immintrin.h:45:0,
from test.c:3:
/home/xxx/gcc-7.1.0/lib/gcc/x86_64-pc-linux-gnu/7.1.0/include/avx512fintrin.h: In function ‘_mm_add_round_sd’:
/home/xxx/gcc-7.1.0/lib/gcc/x86_64-pc-linux-gnu/7.1.0/include/avx512fintrin.h:1412:1: error: SSE register return with SSE disabled
{
^
GCC 详细信息(虽然我没有用于编译它的标志) gcc --版本 海合会 (GCC) 7.1.0 版权所有 (C) 2017 Free Software Foundation, Inc. 这是免费软件;查看复制条件的来源。没有 保修单;甚至不考虑适销性或特定用途的适用性。
可能的解决方案
#pragma GCC target "avx2"
为我工作,无需对代码进行其他更改。 将属性应用于单个函数也不起作用:
相关问题:
__attribute__((__target__("arch=broadwell"))) // does not compile
__m256 use_avx(__m256 a) { return _mm256_add_ps(a,a); }
__attribute__((__target__("avx2,arch=broadwell"))) // does not compile
__m256 use_avx(__m256 a) { return _mm256_add_ps(a,a); }
__attribute__((__target__("avx2"))) // compiles
__m256 use_avx(__m256 a) { return _mm256_add_ps(a,a); }
【问题讨论】:
-
你能显示整个 GCC 命令行吗?真的,您应该生成一个minimal reproducible example。有没有机会
-mno-mmx -mno-sse偷偷溜进去? -
提取总是有点困难......幸运的是,在较小的上下文中实际上很容易重现。
-
你试过用
-march=haswell代替奇怪/模糊的corei7-avx吗? (顺便说一句,-march暗示-mtune,如果你想以不同方式设置它,你只需要一个单独的-mtune。例如-march=sandybridge -mtune=haswell) -
我确实尝试过 haswell 和其他架构名称。我会根据建议修改makefile。