如何将CUDA库与Cilk ++链接 [英] How to link CUDA library with Cilk++
问题描述
我正在尝试使用Intel的Cilk ++和Nvidia的CUDA开发一些混合程序. 我从Cuda代码(libtest.so)创建了一个共享库.我想将其与Cilk ++程序链接,以便可以将一些工作卸载到GPU.但是,当我编译cilk ++程序时,无法将其与此cuda库链接,并且出现如下错误:
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
文件: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());
}
文件:main.cilk
#include <cilk.h>
void entry(void);
int cilk_main(void){
entry();
}
以前,我已将Cilk库与CUDA代码链接在一起,但现在我想反过来. 是否可以将CUDA与Cilk链接?如果是这样,我想念什么?
extern子句应该在C ++代码中,而不在CUDA代码中,因为在这里您在CUDA文件中定义了功能,但是在C ++代码中对其进行了定义./p>
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.
这篇关于如何将CUDA库与Cilk ++链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!