为什么我用GCC 5和cilk-plus得到这个编译错误? [英] Why do I get this compile error with GCC 5 and cilk-plus?

查看:391
本文介绍了为什么我用GCC 5和cilk-plus得到这个编译错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于某种原因,cilk_spawn不能用于x86内部函数。每次我尝试将这两者结合在同一个函数的主体中时,我都会遇到错误。 (请注意,cilk_for正常工作)。如果我删除了所有SIMD指令,它就会编译并运行正常。

  #include< stdio.h> 
#include< x86intrin.h>
#include< math.h>
#include< cilk / cilk.h>

int main()
{
int w = cilk_spawn sqrt(10);
__m128i x = _mm_set_epi64x(1,1);
x = _mm_add_epi64(x,x);
cilk_sync;
printf(%d \\\
,w);
返回0;
}

这里是gcc输出:

  gcc-4.9 -std = c99 -march = native -fcilkplus -O0 -g3 -Wall -c -fmessage-length = 0 -MMD -MP -MFmain.d -MTmain.d-omain.o../main.c
从/usr/lib/gcc/x86_64-linux-gnu/4.9/include/xmmintrin包含的文件中。 h:1258:0,
来自/usr/lib/gcc/x86_64-linux-gnu/4.9/include/x86intrin.h:31,
来自../main.c:2:
../main.c:在函数'main'中:
/usr/lib/gcc/x86_64-linux-gnu/4.9/include/emmintrin.h:581:1:错误:内联失败to always_inline'_mm_set_epi64x':函数不可inlinable
_mm_set_epi64x(long long __q1,long long __q0)
^
../main.c:9:10:错误:从这里调用
__m128i x = _mm_set_epi64x(1,1);
^
从/usr/lib/gcc/x86_64-linux-gnu/4.9/include/xmmintrin.h:1258:0包含的文件中,
来自/ usr / lib / gcc / x86_64-linux-gnu / 4.9 / include / x86intrin.h:31,
来自../main.c:2:
/usr/lib/gcc/x86_64-linux-gnu/4.9/include /emmintrin.h:1025:1:错误:inline调用always_inline时内联失败'_mm_add_epi64':函数不可inlinable
_mm_add_epi64(__m128i __A,__m128i __B)
^
subdir.mk:18 :目标'main.o'的配方失败
../main.c:10:4:错误:从这里调用
x = _mm_add_epi64(x,x);

make:*** [main.o]错误1

我刚刚注意到那是在GCC 4.9中,但错误信息与GCC 5是一样的。

我猜cilk创建两个函数(包含sqrt和你的主函数),以便在不同的线程中调度它们(如果需要/可能的话)。问题在于,在这些条件下,现在间接调用 mm *函数,因此不能内联,至少在没有关闭优化analasys阶段的附加信息的情况下是不行的。



我注意到你用-O0进行编译。我怀疑如果你编译了-O2,它可能会起作用,因为额外的优化过程将为编译器提供更多内联这些函数所需的信息。


For some reason cilk_spawn does not work with x86 intrinsics. I get an error every time I try to combine the two in the body of the same function. (Note that cilk_for works fine). If I remove all of the SIMD instructions it compiles and runs fine.

#include <stdio.h>
#include <x86intrin.h>
#include <math.h>
#include <cilk/cilk.h>

int main()
{
    int w = cilk_spawn sqrt(10);
    __m128i x = _mm_set_epi64x(1, 1);
    x = _mm_add_epi64(x, x);
    cilk_sync;
    printf("%d\n", w);
    return 0;
}

here is gcc ouput:

gcc-4.9 -std=c99 -march=native -fcilkplus -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.c"
In file included from /usr/lib/gcc/x86_64-linux-gnu/4.9/include/xmmintrin.h:1258:0,
                 from /usr/lib/gcc/x86_64-linux-gnu/4.9/include/x86intrin.h:31,
                 from ../main.c:2:
../main.c: In function ‘main’:
/usr/lib/gcc/x86_64-linux-gnu/4.9/include/emmintrin.h:581:1: error: inlining failed in call to always_inline ‘_mm_set_epi64x’: function not inlinable
 _mm_set_epi64x (long long __q1, long long __q0)
 ^
../main.c:9:10: error: called from here
  __m128i x = _mm_set_epi64x(1, 1);
          ^
In file included from /usr/lib/gcc/x86_64-linux-gnu/4.9/include/xmmintrin.h:1258:0,
                 from /usr/lib/gcc/x86_64-linux-gnu/4.9/include/x86intrin.h:31,
                 from ../main.c:2:
/usr/lib/gcc/x86_64-linux-gnu/4.9/include/emmintrin.h:1025:1: error: inlining failed in call to always_inline ‘_mm_add_epi64’: function not inlinable
 _mm_add_epi64 (__m128i __A, __m128i __B)
 ^
subdir.mk:18: recipe for target 'main.o' failed
../main.c:10:4: error: called from here
  x = _mm_add_epi64(x, x);
    ^
make: *** [main.o] Error 1

I just noticed that that was with GCC 4.9 but the error message is the same with GCC 5.

解决方案

I am guessing cilk creates two functions (wrapper over sqrt and your main) in order to schedule them in different threads, if needed/possible. The issue is that under these conditions the mm* function are now called indirectly and therefore cannot be inlined, at least not without additional information from optimization analasys stages which you have turned off.

I noticed that you compile with -O0. I suspect that if you compile -O2 it might work since the additional optimization passes will provide the compiler with more information that is needed to inline these functions.

这篇关于为什么我用GCC 5和cilk-plus得到这个编译错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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