从CUDA内核印刷 [英] printing from cuda kernels

查看:130
本文介绍了从CUDA内核印刷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一个CUDA程序,并试图打印使用printf函数的CUDA内核里面的东西。但是,当我编译程序,然后我得到一个错误

I am writing a cuda program and trying to print something inside the cuda kernels using the printf function. But when I am compiling the program then I am getting an error

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.

我使用具有计算能力大于2.0和卡GTX 560 TI的时候我已经搜索了一下有关从CUDA内核我也看到了,我需要编译器sm_10改变sm_2.0采取印刷充分利用卡。也有的建议对cuPrintf为服务宗旨。我有点困惑,我应该怎么做,应该是什么让我的控制台屏幕上打印输出的最简单,最快捷的方式。如果我需要改变,从1.0 NVCC编译器2.0那么我该怎么办?一个我想更多的事情提一提,我使用Windows 7.0和编程在Visual Studio 2010感谢您的帮助。

I am using the card GTX 560 ti having a compute capability greater than 2.0 and when I have searched a bit about the printing from cuda kernels I also saw that I need to change the compiler from sm_10 to sm_2.0 to take the full advantage of the card. Also some suggested for cuPrintf to serve the purpose. I am bit confused what should I do and what should be the simplest and quickest way to get the printouts on my console screen. If I need to change the nvcc compiler from 1.0 to 2.0 then what should I do? One more thing I would like to mention that I am using windows 7.0 and programming in visual studio 2010. Thanks for all your help.

推荐答案

要计算能力的设备能够使用普通的的printf()> = 2.0,这是重要的编译至少CC 2.0 CC和禁用默认,其中包括CC 1.0版本。

To enable use of plain printf() on devices of Compute Capability >= 2.0, it's important to compile for CC of at least CC 2.0 and disable the default, which includes a build for CC 1.0.

右键单击 .CU 文件在你的项目中,选择属性,选择配置属性 | CUDA C / C ++ | 设备。点击 code代行,单击该三角形,选择修改。在code生成对话框,取消选中从父母或项目默认继承键入 compute_20,sm_20 在顶部窗口,单击确定。

Right-click the .cu file in your project, select Properties, select Configuration Properties | CUDA C/C++ | Device. Click on the Code Generation line, click the triangle, select Edit. In the Code Generation dialog box, uncheck Inherit from parent or project defaults, type compute_20,sm_20 in the top window, click OK.

这篇关于从CUDA内核印刷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆