cuda之cusp在ubuntu 12.10下的使用问题及解决

cusp是cuda下对cusparse及cublas库的一个C++封装,需要在C++代码里调用CUDA的矩阵功能,因此尝试使用了cusp,发现第一步的工作就不是很简单。

首先要cuda toolkit,这个倒是很简单:

sudo apt-get install nvidia-cuda-toolkit

cusp是一套C++的模板库,因此只需要将其代码拷贝到/usr/include下即可,下载后将其目录解压缩到/usr/include/cusp目录下。

将examples解压到home下,然后找了一个example试验看看:

cd examples/Version
nvcc -O2 -o t version.cu

然后出现错误:

$ nvcc -O2 -o t version.cu
/tmp/tmpxft_000075f4_00000000-13_version.o:在函数‘__cudaUnregisterBinaryUtil()’中:
tmpxft_000075f4_00000000-1_version.cudafe1.cpp:(.text+0x8):对‘__cudaUnregisterFatBinary’未定义的引用
/tmp/tmpxft_000075f4_00000000-13_version.o:在函数‘__sti____cudaRegisterAll_42_tmpxft_000075f4_00000000_4_version_cpp1_ii_main()’中:
tmpxft_000075f4_00000000-1_version.cudafe1.cpp:(.text.startup+0x11a):对‘__cudaRegisterFatBinary’未定义的引用
collect2: ld returned 1 exit status

网上搜索后发现是需要link cudart,因此可以这样处理:
nvcc -O2 -o t version.cu -lcudart
但其实有更好的办法,即修改/etc/nvcc.profile

sudo nano /etc/nvcc.profile

将其中LIBRARIES那一行的注释去掉,即不要注释。

LIBRARIES += $(_SPACE_) -lcudart

这样就可以编译通过了,然后再尝试另外一个example,即Algorithm/blas.cu,又出现错误了:

error: kernel launches from templates are not allowed in system files

这个就比较难处理了,发现类似的问题基本都是出在thrust库上,如:
http://chrislaidler.blogspot.com/2012/05/cuda-429-and-kubuntu-1204.html
这个页面的评论也提到这个错误,其解决办法是建立一个符号连接,将/usr/include/thrust目录ln到/usr/lib/nvidia-cuda-toolkit/include/thrust目录。
但检查这个link已经存在了,突然想到会不会是cusp的问题?
因此将cusp也做了类似的link,问题果然就解决了。


已发布

分类

,

来自

标签:

评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注