我们可以在内核运行期间获得按时打印输出吗? [英] can we get the on-time print-out during the kernel running?

查看:49
本文介绍了我们可以在内核运行期间获得按时打印输出吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我意识到"cuPrintf"可以在内核中使用,但是"cudaPrintfDisplay"只能在CPU代码中使用.在我看来,"cuPrintf"只能从内核返回后才能刷新到stdout.我的问题是:我们可以在内核运行期间获得按时打印吗?

I realized that "cuPrintf" can be used in the kernel, but "cudaPrintfDisplay" can only be used in the CPU code. This seems to me that the "cuPrintf" can only be flushed to stdout after returning from kernel. My question is: can we get the on-time print-out during the kernel running?

推荐答案

您已经注意到,计算能力> = 2.0的 cuPrintf()(和 printf())),只需在内核运行时将字符串添加到缓冲区中,然后在内核结束后打印出缓冲区.

As you have noticed, cuPrintf() (and printf() in compute capability >= 2.0), simply add strings to a buffer while the kernel is running, and the buffer is printed out after the kernel ends.

我认为没有办法从内核获取实时printf.但是,为了减少延迟,您可能每次都可以使用更少的线程运行内核.由于 __ device__ printf()仅仅是诊断或调试工具,因此任何性能损失都无关紧要.

I don't think there is a way to get real time printf from a kernel. But, to get less delay, you may be able to run the kernel with fewer threads each time. Since __device__ printf() is only a diagnostics or debugging tool, any loss in performance shouldn't matter.

也许最好的办法是在CUDA调试器中运行代码并以这种方式立即获得反馈.

Maybe the best thing would be to run your code in a CUDA debugger and get immediate feedback that way.

这篇关于我们可以在内核运行期间获得按时打印输出吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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