麻烦编译cuda代码

时间:2011-08-31 03:51:45

标签: cuda makefile

我想编译this volume rendering project。我在我的Ubuntu 10.10机器上安装了CUDA工具包和SDK,并且能够运行它的示例,但我得到了这个:

antonio@antonio-desktop:~/vfray$ make
make -f MakefileCPU
make[1]: Entering directory `/home/antonio/vfray'
make[1]: `vfRayCPU' is up to date.
make[1]: Leaving directory `/home/antonio/vfray'
make -f MakefileCUDA
make[1]: Entering directory `/home/antonio/vfray'
nvcc  -o vfRay.cu_o -c vfRay.cu --ptxas-options=-v --compiler-bindir=/usr/bin/gcc-4.3 --compiler-options -fno-strict-aliasing   -I. -I/usr/local/cuda/include -I/usr/local/cuda/SDK/C/common/inc -DUNIX -O3 
/usr/bin/gcc-4.3: No such file or directory
make[1]: *** [vfRay.cu_o] Error 1
make[1]: Leaving directory `/home/antonio/vfray'
make: *** [cuda] Error 2

我该如何解决这个问题?


编辑:在vfRay.cu文件中运行talonmies描述的步骤时,我得到:

  antonio@antonio-desktop:~/vfray$ nvcc --compiler-bindir=./jdir -arch=sm_20 -c -Xptxas="-v" vfRay.cu
    vfRay.cu:25: fatal error: cutil.h: No such file or directory
    compilation terminated.

新编辑:好吧,当做-L包含cutil.h目录时,我得到了vfRay.cu和vfRayKernel.cu。

antonio@antonio-desktop:~/vfray$ nvcc --compiler-bindir=./jdir -arch=sm_20 -c -Xptxas="-v"  vfRay.cu -I/home/antonio/NVIDIA_GPU_Computing_SDK/C/common/inc/
vfRay.cu:48: fatal error: vfRayKernel.cu: No such file or directory
compilation terminated.
antonio@antonio-desktop:~/vfray$ nvcc --compiler-bindir=./jdir -arch=sm_20 -c -Xptxas="-v"  vfRayKernel.cu -I/home/antonio/NVIDIA_GPU_Computing_SDK/C/common/inc/
vfRayKernel.cu(80): error: identifier "BLOCK_SIZE" is undefined

vfRayKernel.cu(181): error: identifier "BLOCK_SIZE" is undefined

vfRayKernel.cu(262): error: identifier "BLOCK_SIZE" is undefined

3 errors detected in the compilation of "/tmp/tmpxft_000064a5_00000000-4_vfRayKernel.cpp1.ii".

我认为这是一个makefile问题,我怀疑这个编译在没有修改它的情况下会有效。

这是项目的makefile:

#
# Makefile CPU / CUDA
#

#-----------------------------------------------------------------------------

all:    cpu cuda

cpu:        MakefileCPU
            make -f MakefileCPU

cuda:       MakefileCUDA
            make -f MakefileCUDA

clean:
            make -f MakefileCPU clean
            make -f MakefileCUDA clean

我制作了这个mod并且无法正常工作:

all:    cpu cuda

cpu:    MakefileCPU
        make -f MakefileCPU

cuda:   MakefileCUDA
        make -f MakefileCUDA
        nvcc --compiler-bindir=./jdir -arch=sm_20 -c -Xptxas="-v"

clean:
        make -f MakefileCPU clean
        make -f MakefileCUDA clean

编辑:我修改了common.mk文件,以便第93行指向gcc 4.4,现在我收到了cutil missing错误。我在哪里可以修改它?我尝试将它放在usr / bin中的ld文件夹中,但ld是一个程序,我无法删除它。

antonio @ antonio-desktop:〜/ vfray $ make

make -f MakefileCPU
make[1]: Entering directory `/home/antonio/vfray'
make[1]: `vfRayCPU' is up to date.
make[1]: Leaving directory `/home/antonio/vfray'
make -f MakefileCUDA
make[1]: Entering directory `/home/antonio/vfray'
g++ -fPIC -o .///vfRay  .///vfRayPreComp.o  .///vfRay.cu_o -L/usr/local/cuda/lib64 -L/usr/local/cuda/SDK/C/lib -L/usr/local/cuda/SDK/C/common/lib -lcudart -lGL -lGLU -lglut   -L/usr/local/cuda/lib64 -L/usr/local/cuda/SDK/C/lib -L/usr/local/cuda/SDK/C/common/lib -lcutil
/usr/bin/ld: cannot find -lcutil
collect2: ld returned 1 exit status
make[1]: *** [vfRay] Error 1
make[1]: Leaving directory `/home/antonio/vfray'
make: *** [cuda] Error 2

1 个答案:

答案 0 :(得分:3)

nvcc --compiler-bindir,顾名思义,将目录作为参数,而不是编译器可执行文件本身。为了以这种方式使用替代编译器,您需要传递一个目录,该目录包含一个名为gcc的可执行文件,或一个名为gcc的链接,该链接指向有效的gcc版本。最简单的方法是创建一个包含指向支持的编译器版本的符号链接的locate目录。像这样:

1.   user@cuda:~$ mkdir jdir

2.   user@cuda:~$ cd jdir

3.   user@cuda:~/jdir$ ln -s /usr/bin/gcc-4.4 ./gcc

4.   user@cuda:~$ ls -l jdir
     total 0
     lrwxrwxrwx 1 user user 12 2011-08-31 08:34 gcc -> /usr/bin/gcc-4.4

5.   user@cuda:~/jdir$ cd ..

6.   user@cuda:~$ nvcc --compiler-bindir=./jdir -arch=sm_20 -c -Xptxas="-v" particles3.cu
     ptxas info    : Compiling entry function '_Z6pointsP6float4f' for 'sm_20'
     ptxas info    : Function properties for _Z6pointsP6float4f
         0 bytes stack frame, 0 bytes spill stores, 0 bytes spill loads
     ptxas info    : Used 29 registers, 44 bytes cmem[0], 4 bytes cmem[14], 12 bytes cmem[16]

编辑1:

在您正在尝试构建的代码中,您需要编辑文件common.mk, line 93并将--compiler-bindir选项更改为您在上面演示的方式设置包含链接的某个绝对路径。


编辑2:

您尝试编译的代码依赖于NVIDIA GPU Computing SDK。您必须设置环境变量ROOT_DIR以指向SDK分发中的C树,或者修改您尝试构建的代码附带的common.mk文件的line 50。您还必须确保通过在SDK根目录的C / common目录中运行make来编译cutil库。

相关问题