从cuda内核打印
我正在编写一个cuda程序,并试图使用printf函数打印cuda内核中的某些内容。但是当我编译程序时,我得到了一个错误从cuda内核打印,c,visual-studio-2010,cuda,gpgpu,C,Visual Studio 2010,Cuda,Gpgpu,我正在编写一个cuda程序,并试图使用printf函数打印cuda内核中的某些内容。但是当我编译程序时,我得到了一个错误 error : calling a host function("printf") from a __device__/__global__ function("agent_movement_top") is not allowed error MSB3721: The command ""C:\Program Files\NVIDIA GPU Computing To
error : calling a host function("printf") from a __device__/__global__ function("agent_movement_top") is not allowed
error MSB3721: The command ""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.2\bin\nvcc.exe" -gencode=arch=compute_10,code=\"sm_10,compute_10\" --use-local-env --cl-version 2008 -ccbin "c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin" -I"C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 4.2\C\common\inc" -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\test.cu.obj" "C:\Users\umdutta\Desktop\SANKHA_ALL_MATERIALS\PROGRAMMING_FOLDER\ABM_MODELLING_2D_3D\TRY_NUM_2\test_proj_test\test_proj\test_proj\test.cu"" exited with code 2.
我正在使用GTX 560 ti卡,它的计算能力大于2.0。当我搜索了一下cuda内核的打印时,我还发现我需要将编译器从sm_10更改为sm_2.0,以充分利用该卡。也有人建议使用cuPrintf来达到这一目的。我有点困惑我应该做什么,以及什么是最简单、最快捷的方式来获得控制台屏幕上的打印输出。如果我需要将nvcc编译器从1.0更改为2.0,那么我应该怎么做?还有一件事我想提一提,我正在使用Windows7.0,并在VisualStudio2010中编程。感谢您的帮助。解决此问题的一种方法是使用能够从内核打印的cuPrintf函数。从文件夹中复制文件cuPrintf.cu和cuPrintf.cuh
C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 4.2\C\src\simplePrintf
到项目文件夹。然后将头文件cuPrintf.cuh添加到项目中并添加
#include "cuPrintf.cu"
到您的代码。然后,您的代码应该以下面提到的格式编写:
#include "cuPrintf.cu"
__global__ void testKernel(int val)
{
cuPrintf("Value is: %d\n", val);
}
int main()
{
cudaPrintfInit();
testKernel<<< 2, 3 >>>(10);
cudaPrintfDisplay(stdout, true);
cudaPrintfEnd();
return 0;
}
按照上述步骤,可以从设备功能在控制台窗口上获得打印。
虽然我用上面提到的方法解决了我的问题,但我仍然没有从设备函数中使用printf的解决方案。如果确实并且绝对有必要将我的nvcc编译器从sm_10升级到sm_21以启用printf功能,那么如果有人能告诉我这一点,那将非常有帮助。感谢您的通力合作在计算能力>=2.0的设备上启用纯printf,编译至少为CC 2.0的CC并禁用默认值非常重要,其中包括针对CC 1.0的构建
右键单击项目中的.cu文件,选择属性,选择配置属性| CUDA C/C++|设备。单击代码生成行,单击三角形,选择编辑。在“代码生成”对话框中,取消选中“从父级继承”或“项目默认值”,在顶部窗口中键入compute_20、sm_20,然后单击“确定”。您可以编写此代码以从CUDA内核内部打印所需内容:
# if __CUDA_ARCH__>=200
printf("%d \n", tid);
#endif
并且包含