本文介绍了我们如何使用cuPrintf()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们要使用cuPrintf()做什么? (设备计算能力1.2,Ubuntu 12)我找不到cuPrintf.cu和cudaPrintf.cuh,所以我下载他们的代码,并包括他们:
What do we have to do to use cuPrintf()? (device compute capability 1.2, Ubuntu 12) I couldn't find "cuPrintf.cu" and "cudaPrintf.cuh", so i downloaded their code and include them:
#include "cuPrintf.cuh"
#include "cuPrintf.cu"
b $ b
顺便说一句,这是剩下的代码:
By the way this is the rest of the code:
__global__ void hello_kernel (float f) {
printf ("Thread number %d. f = %d\n", threadIdx.x, f);
}
int main () {
dim3 gridSize = dim3 (1);
dim3 blockSize = dim3 (16);
cudaPrintfInit ();
hello_kernel <<< gridSize, blockSize >>> (1.2345f);
cudaPrintfDisplay (stdout, true);
cudaPrintfEnd ();
return (0);
}
但是nvcc仍然会出错:
But nvcc still gives a mistake:
max@max-Lenovo-G560:~/CUDA/matrixMult$ nvcc printfTest.cu -o printfTest
printfTest.cu(5): error: calling a __host__ function("printf") from a __global__
function("hello_kernel") is not allowed
感谢!
推荐答案
在您的内核中,而不是这样:
In your kernel instead of this:
printf ("Thread number %d. f = %d\n", threadIdx.x, f);
您应该这样做:
cuPrintf ("Thread number %d. f = %d\n", threadIdx.x, f);
除此之外,我相信你的代码是正确的(它适用于我)。
Other than that, I believe your code is correct (it works for me).
此提供了有关正确使用cuPrintf的更多提示。
This SO question/answer gives more tips about using cuPrintf properly.
这篇关于我们如何使用cuPrintf()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!