即使编译正常,cuPrintf也不会打印任何内容

时间:2013-12-07 19:58:43

标签: c++ cuda

这是我的包括:

#include "cuPrintf.cu"
#include "cuPrintf.cuh"

我的内核:

__global__ void testKernel()
{
  cuPrintf("Test");
}

和我的主要:

int main( int argc, char** argv) 
{   
    dim3 threads(1,1);
    dim3 blocks(1, 1);
    testKernel<<<blocks, threads>>>();
}

有人可以向我解释为什么cuPrintf没有打印任何东西,汇编没问题我正在使用Cuda 5.5

1 个答案:

答案 0 :(得分:0)

如果您使用的是cc 2.0或更高版本的设备,则直接从内核使用printf会更容易。只要您的编译命令为您的实际设备指定-arch=sm_20或类似命令,就可以执行此操作。

如果您确实想使用cuPrintf,请study the relevant sample code。您在main例程中缺少一些cuPrintf正常工作所需的函数调用。

最后,无论何时从内核打印,都应该确保在程序退出之前有一些同步功能。如果您的内核之后没有其他任何内容,则以下内容将执行:

cudaDeviceSynchronize();
在最后一次内核调用之后,在main例程中

如果您修改main例程,请执行以下操作:

int main( int argc, char** argv) 
{   
    dim3 threads(1,1);
    dim3 blocks(1, 1);
    cudaPrintfInit();
    testKernel<<<blocks, threads>>>();
    cudaDeviceSynchronize();
    cudaPrintfDisplay(stdout,true);
    cudaPrintfEnd();
}

我相信它会奏效。