我试图在 Visual Studio 2010 下使用 CUDA 4.2 编译一些 CUDA 代码(我使用 Parallel Nsight 2.2 创建了这个 CUDA 项目),但我遇到了一个原子问题“错误:标识符“atomicAdd”未定义”,我仍然不能检查几个论坛后解决。
所以我试图从 CUDA SDK Samples 中获取一些信息。首先,我在 CUDA SDK 中运行了 simpleAtomicIntrinsics 示例,它通过了测试。然后,我将此示例中的所有文件复制到 Visual Studio 2010 中的新 CUDA 4.2 项目并编译它们,结果如下。
1> E:\CUDA exercise Codes\CUDA_EXERCISES\CUDA_EXERCISES\CUDA_EXERCISES>"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.2\bin\nvcc.exe" -gencode=arch=compute_20,code=\"sm_20,compute_20\" -gencode=arch=compute_20,code=\"sm_20,compute_20\" -gencode=arch=compute_10,code=\"sm_10,compute_10\" --use-local-env --cl-version 2010 -ccbin "c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.2\include" -G --keep-dir "Debug" -maxrregcount=0 --machine 32 --compile -g -Xcompiler "/EHsc /nologo /Od /Zi /MDd " -o "Debug\simpleAtomicIntrinsics.cu.obj" "E:\CUDA exercise Codes\CUDA_EXERCISES\CUDA_EXERCISES\CUDA_EXERCISES\simpleAtomicIntrinsics.cu"
1> simpleAtomicIntrinsics.cu
1> tmpxft_00007220_00000000-3_simpleAtomicIntrinsics.compute_20.cudafe1.gpu
1> tmpxft_00007220_00000000-7_simpleAtomicIntrinsics.compute_20.cudafe2.gpu
1> simpleAtomicIntrinsics.cu
1>e:\cuda exercise codes\cuda_exercises\cuda_exercises\cuda_exercises\simpleAtomicIntrinsics_kernel.cu(33): error : identifier "atomicAdd" is undefined
1>
1>e:\cuda exercise codes\cuda_exercises\cuda_exercises\cuda_exercises\simpleAtomicIntrinsics_kernel.cu(36): error : identifier "atomicSub" is undefined
1>
1>e:\cuda exercise codes\cuda_exercises\cuda_exercises\cuda_exercises\simpleAtomicIntrinsics_kernel.cu(39): error : identifier "atomicExch" is undefined
1>
1>e:\cuda exercise codes\cuda_exercises\cuda_exercises\cuda_exercises\simpleAtomicIntrinsics_kernel.cu(42): error : identifier "atomicMax" is undefined
1>
1>e:\cuda exercise codes\cuda_exercises\cuda_exercises\cuda_exercises\simpleAtomicIntrinsics_kernel.cu(45): error : identifier "atomicMin" is undefined
1>
1>e:\cuda exercise codes\cuda_exercises\cuda_exercises\cuda_exercises\simpleAtomicIntrinsics_kernel.cu(48): error : identifier "atomicInc" is undefined
1>
1>e:\cuda exercise codes\cuda_exercises\cuda_exercises\cuda_exercises\simpleAtomicIntrinsics_kernel.cu(51): error : identifier "atomicDec" is undefined
1>
1>e:\cuda exercise codes\cuda_exercises\cuda_exercises\cuda_exercises\simpleAtomicIntrinsics_kernel.cu(54): error : identifier "atomicCAS" is undefined
1>
1>e:\cuda exercise codes\cuda_exercises\cuda_exercises\cuda_exercises\simpleAtomicIntrinsics_kernel.cu(59): error : identifier "atomicAnd" is undefined
1>
1>e:\cuda exercise codes\cuda_exercises\cuda_exercises\cuda_exercises\simpleAtomicIntrinsics_kernel.cu(62): error : identifier "atomicOr" is undefined
1>
1>e:\cuda exercise codes\cuda_exercises\cuda_exercises\cuda_exercises\simpleAtomicIntrinsics_kernel.cu(65): error : identifier "atomicXor" is undefined
1>
1> 11 errors detected in the compilation of "C:/Users/NIEXIA~1/AppData/Local/Temp/tmpxft_00007220_00000000-9_simpleAtomicIntrinsics.compute_10.cpp1.ii".
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\BuildCustomizations\CUDA 4.2.targets(361,9): error MSB3721: The command ""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.2\bin\nvcc.exe" -gencode=arch=compute_20,code=\"sm_20,compute_20\" -gencode=arch=compute_20,code=\"sm_20,compute_20\" -gencode=arch=compute_10,code=\"sm_10,compute_10\" --use-local-env --cl-version 2010 -ccbin "c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.2\include" -G --keep-dir "Debug" -maxrregcount=0 --machine 32 --compile -g -Xcompiler "/EHsc /nologo /Od /Zi /MDd " -o "Debug\simpleAtomicIntrinsics.cu.obj" "E:\CUDA exercise Codes\CUDA_EXERCISES\CUDA_EXERCISES\CUDA_EXERCISES\simpleAtomicIntrinsics.cu"" exited with code 2.
1>
1>Build FAILED.
顺便说一句,我可以在这个 vs2010 CUDA 项目下运行其他示例,例如时钟、matrixMul 等。(这意味着包含路径设置正确)
我用谷歌搜索并找到以下链接Some issue with Atomic add in CUDA kernel operation。我根据它更改了项目和.cu文件的属性,但仍然无法解决问题。
有什么建议吗?