Why do I get this compile error with GCC 5 and cilk-plus?
Asked Answered
U

2

12

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.

Unreason answered 6/8, 2015 at 3:37 Comment(5)
Can you try with gnu99 instead of c99 as the language?Pardner
No difference same error.Unreason
It compiles fine with Intel 15.0.3. You should file a bug with the GCC folks.Pardner
I seem to recall something about mm* functions only being able to run in parallel with other mm* functions. ICC may be better able to determine which processors allow different simultaneous contexts with the -march=native flag.Reube
Did you find a solution yet? I am running into the same problem with gcc 6.2. No intrinsics allowed :(Cyclamate
A
1

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.

Appleton answered 9/8, 2015 at 6:21 Comment(0)
R
-1

I was able to compile the code that was failing with the same error by specifying -msse and -msse2 flags.

https://www.mail-archive.com/[email protected]/msg00033.html


godbolt link referred to by the following comment, required by current SO "best practice".

Ridicule answered 24/3, 2016 at 3:52 Comment(2)
This problem happens with CILK even when -msse2 is enabled (even with gcc6-snapshot). The OP uses -march=native. This doesn't fix the problem with Cilk, only for normal cases of that error message (using intrinsics without the right -m options to tell gcc those insns are ok.) I had to edit the godbolt link that demonstrates the continued existence of this problem into your post, because SO broke commentsVanguard
Nice website. I didn't know such thing exists for gcc. Now I see that it indeed doesn't help.Ridicule

© 2022 - 2024 — McMap. All rights reserved.