1.GPU高性能编程之Julia_CUDA

刚刚开始学习CUDA,选择了Jason Sanders的《GPU高性能编程——CUDA实战》这本书作为入门书籍。目前只看到第三章,觉得这本书非常不错,讲得比较详细,开始比较浅显,适合入门。

     今天运行了书中的配套例程Julia_cuda,遇到了一些错误,记录一下。

  C:/yf/CUDA_Y/text/Julia_cuda/Julia.cu(47): error : calling a __host__ function("cuComplex::cuComplex") from a __device__ function("julia") is not allowed
1>  
1>C:/yf/CUDA_Y/text/Julia_cuda/Julia.cu(48): error : calling a __host__ function("cuComplex::cuComplex") from a __device__ function("julia") is not allowed
1>  
1>C:/yf/CUDA_Y/text/Julia_cuda/Julia.cu(35): error : calling a __host__ function("cuComplex::cuComplex") from a __device__ function("cuComplex::operator *") is not allowed
1>  
1>C:/yf/CUDA_Y/text/Julia_cuda/Julia.cu(38): error : calling a __host__ function("cuComplex::cuComplex") from a __device__ function("cuComplex::operator +") is not allowed
1>  
1>  4 errors detected in the compilation of "D:/Users/y/AppData/Local/Temp/tmpxft_00000858_00000000-5_Julia.cpp1.ii".
1>  Julia.cu
1>D:\Program Files\MSBuild\Microsoft.Cpp\v4.0\BuildCustomizations\CUDA 6.5.targets(593,9): error MSB3721: 命令“"D:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5\bin\nvcc.exe" -gencode=arch=compute_20,code=\"sm_20,compute_20\" --use-local-env --cl-version 2010 -ccbin "D:\Program Files\Microsoft Visual Studio 10.0\VC\bin"  -I"D:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5\include" -I"D:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5\include"  -G   --keep-dir Debug -maxrregcount=0  --machine 32 --compile -cudart static  -g   -DWIN32 -D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nologo /Od /Zi /RTC1 /MDd  " -o Debug\Julia.cu.obj "C:\yf\CUDA_Y\text\Julia_cuda\Julia.cu"”已退出,返回代码为 2。

 

     针对以上错误做出修改:

     将struct cuComplex中的构造函数“cuComplex( float a, float b ) : r(a), i(b)  {}”  改为:

                                                                “__device__cuComplex( float a, float b ) : r(a), i(b)  {}”。

    PS为了避免在VS中配置CUDA,我在新建项目时选择了“CUDA 6.5 Runtime”,这个项目中含有一个“kernel.cu”文件,所以只要把“julia_gpu.cu”中的代码替换到 “kernel.cu”中就可以了。

你可能感兴趣的:(CUDA)