CUDA cuPrintf

CUDA cuPrintf

February 8th, 2010 by Jeremy

I finally got an Nvidia developer account a few days ago which gave me access to a very useful library to use with CUDA.

cuPrintf allows printf equivalent statements to be placed inside CUDA kernels without the need for -deviceemu.

The following example demonstrates a simple use for cuPrintf and displays the current thread ID. 

演示了打印当前线程的ID.

  1. #include <cuda.h>
  2. #include "cuPrintf.cu"
  3.  
  4. __global__ void cuPrintfExample ( )
  5. {
  6.   int tid;
  7.  tid = blockIdx. x * blockDim. x + threadIdx. x;
  8.  cuPrintf ( "%d\n", tid );
  9. }
  10.  
  11. int main ( )
  12. {
  13.  cudaPrintfInit ( );
  14.  cuPrintfExample <<< 5, 2 >>> ( );
  15.  cudaPrintfDisplay ( stdout, true );
  16.  cudaPrintfEnd ( );
  17.   return 0;
  18. }

cudaPrintfInit and cudaPrintfEnd only need be called once throughout your entire project.

Output is not automatically displayed on the screen, but stored in a buffer which is cleared and displayed when cudaPrintfDisplay is called. The size of the buffer can be specified with the optional argument cudaPrintfInit(size_t bufferLen).

cudaPrintfEnd simply frees the memory allocated by cudaPrintfInit.

When cudaPrintfDisplay is called, output stored in the buffer is displayed to the console. The second argument in this call either displays the current thread (true) or doesn’t (false). The first arguemnt, specified by stdout in this example, simply defines the descriptor where the cuPrintf log is sent.

On another note, I’ve found that using cuPrintf impacts on the performance of my kernels, presumably due to the data transfer performed every time cuPrintfDisplay() is called.


http://www.jeremykemp.co.uk/08/02/2010/cuda-cuprintf/


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值