我们可以使用 cilk plus 和 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))
编译器对以下测试代码给出上述警告:
#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;
}
}
编译
FLAGS=-std=c++14 -Wall -O3 -march=native -fcilkplus
all: vec_add fib
vec_add: vec_add.cpp
g++ $(FLAGS) $< -o $@