如何在可分离编译之后将主机代码与静态CUDA库链接? [英] How to link host code with a static CUDA library after separable compilation?
问题描述
好吧,我有一个真正令人不安的CUDA 5.0问题,如何正确链接的东西。我真的很感谢任何帮助!
Alright, I have a really troubling CUDA 5.0 question about how to link things properly. I'd be really grateful for any assistance!
使用CUDA 5.0的可分离编译功能,我生成了一个静态库(* .a)。这很好地链接到其他* .cu文件,当运行通过nvcc,我做了这很多次。
Using the separable compilation features of CUDA 5.0, I generated a static library (*.a). This nicely links with other *.cu files when run through nvcc, I have done this many times.
现在我想要一个* .cpp文件和链接它反对主机代码在这个静态库使用g ++或任何,但不是nvcc。如果我尝试这样,我会收到编译器错误,例如
I'd now like to take a *.cpp file and link it against the host code in this static library using g++ or whatever, but not nvcc. If I attempt this, I get compiler errors like
未定义引用__cudaRegisterLinkedBinary
undefined reference to __cudaRegisterLinkedBinary
我使用 -lcuda
和 -lcudart
,具有正确顺序的库(意味着 -lmylib -lcuda -lcudart
)。我不认为这是一个问题。也许我错了,但我觉得我缺少一个步骤,我需要做一些别的我的静态库(设备链接?),我可以使用它与g ++。
I'm using both -lcuda
and -lcudart
and, to my knowledge, have the libraries in the correct order (meaning -lmylib -lcuda -lcudart
). I don't think it is an issue with that. Maybe I'm wrong, but I feel I'm missing a step and that I need to do something else to my static library (device linking?) before I can use it with g++.
我错过了什么关键?这是可能吗?
Have I missed something crucial? Is this even possible?
奖金问题:我想最终结果是一个动态库。
Bonus question: I want the end result to be a dynamic library. How can I achieve this?
推荐答案
当你链接到nvcc时,它与主机链接一起隐式的设备链接。如果你使用主机编译器链接(和g ++一样),那么你需要添加一个显式步骤,使用-dlink选项进行设备链接,例如
When you link with nvcc, it does an implicit device link along with the host link. If you use the host compiler to link (like with g++), then you need to add an explicit step to do a device link with the –dlink option, e.g.
nvcc –arch=sm_35 –dc a.cu b.cu
nvcc –arch=sm_35 –dlink a.o b.o –o dlink.o
g++ a.o b.o dlink.o x.cpp –lcudart
目前我们只支持可重定位设备代码的静态库。我们有兴趣学习如何在动态库中使用这样的代码。请在评论中随意回答。
Currently we only support static libraries for relocatable device code. We’d be interested in learning how you would want to use such code in a dynamic library. Please feel free to answer in the comments.
编辑:
要在下面的评论中回答问题有没有什么办法使用nvcc将mylib.a转换成可以放入g ++的东西?
To answer the question in the comment below " Is there any way to use nvcc to turn mylib.a into something that can be put into g++?"
只需像下面这样使用库: p>
Just use the library like an object, like this:
nvcc –arch=sm_35 –dlink mylib.a –o dlink.o
g++ mylib.a dlink.o x.cpp –lcudart
这篇关于如何在可分离编译之后将主机代码与静态CUDA库链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!