Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我意识到“cuPrintf”可以在内核中使用,但“cudaPrintfDisplay”只能在CPU代码中使用。在我看来,“cuPrintf”只能在从内核返回后刷新到标准输出。我的问题是:我们可以在内核运行期间得到准时打印吗?
正如您所注意到的cuPrintf()(printf()在计算能力 >= 2.0 的情况下),只需在内核运行时将字符串添加到缓冲区,然后在内核结束后打印出缓冲区。
cuPrintf()
printf()
我认为没有办法从内核中获取实时 printf 。但是,为了减少延迟,您可以每次使用更少的线程来运行内核。由于__device__ printf()它只是一个诊断或调试工具,因此任何性能损失都无关紧要。
__device__ printf()
也许最好的办法是在 CUDA 调试器中运行您的代码并以这种方式获得即时反馈。