I am trying to develop some Hybrid program using Intel's Cilk++ and Nvidia's CUDA. I created a Shared library from Cuda code(libtest.so). And I want to link it with Cilk++ program, so that I can offload some work to GPU. But when I compile cilk++ program I am not able to link it with this cuda library and I get error as follows:
nvcc -arch=compute_20 -L. -code=sm_20 -L. -o libtest.so --shared -Xcompiler -fPIC test.cu;
cilk++ -o main -L. -ltest main.cilk;
/tmp/ccwDvzCG.o: In function `int cilk_main(int, char**)':
main.cilk:(.text+0x26): undefined reference to `void entry()'
collect2: ld returned 1 exit status
File: test.cu
#include <stdio.h>
__global__ void myk(void){
printf("Hello from thread %d block %d\n", threadIdx.x, blockIdx.x);
}
extern "C++"
void entry(void){
myk<<<1,1>>>();
printf("CUDA status: %d\n", cudaDeviceSynchronize());
}
File: main.cilk
#include <cilk.h>
void entry(void);
int cilk_main(void){
entry();
}
Previously I have linked Cilk library with CUDA code, But now I want the other way round. Is it possible to link CUDA with Cilk? If So, what am I missing?
The extern clause should be in C++ code and not in the CUDA code because here you have definition of function in CUDA file but you call it in C++ code.