c++gcccilk-plus

gcc-5.2 cilk plus offload to intel gfx hardware


Can we offload to the graphics hardware using cilk plus with gcc-5.2

g++ -std=c++14 -Wall -O3 -march=native -fcilkplus vec_add.cpp -o vec_add
vec_add.cpp:6:0: warning: ignoring #pragma offload target [-Wunknown-pragmas]
 #pragma offload target(gfx) pin(out, in1, in2 : length(n))

The compiler gives the above warning for the following test code:

#include <iostream>
#include <cilk/cilk.h>

void vec_add(int n, float *out, float *in1, float *in2)
{
#pragma offload target(gfx) pin(out, in1, in2 : length(n))
    cilk_for(int i = 0; i != n; ++i)
    {
        out[i] = in1[i] + in2[i];
    }
}

static int ar_sz = 100000;
int main (int argc, char **argv)
{
    float foo[ar_sz];
    float bar[ar_sz];
    float out[ar_sz];
    for(int i = 0; i != ar_sz; ++i)
    {
        foo[i] = i + ar_sz * 10;
        bar[i] = i;
    }
    vec_add(ar_sz, out, foo, bar);

    for(int i = 0; i != ar_sz; i += 100)
    {
        std::cout << "foo[" << i << "] =" << foo[i] << "\t|\tbar[" << i << "] =" <<  bar[i] << std::endl;
    }
}

Compiled with

FLAGS=-std=c++14 -Wall -O3 -march=native -fcilkplus

all: vec_add fib

vec_add: vec_add.cpp
    g++ $(FLAGS) $< -o $@

Solution

  • "Full support for Cilk Plus has been added to the GCC compiler." This means full support for only the language extensions of cilk plus. Gcc cannot offload to intel integrated graphics at all. OpenMP reportedly can offload to a Xeon Phi coprocessor and nvidia graphics cards.

    https://gcc.gnu.org/ml/gcc/2016-04/msg00182.html