本文介绍了我们如何使用 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"
顺便说一句,这是其余的代码:
By the way this is the rest of the code:
__global__ void hello_kernel (float f) {
printf ("Thread number %d. f = %d
", 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
", threadIdx.x, f);
你应该这样做:
cuPrintf ("Thread number %d. f = %d
", threadIdx.x, f);
除此之外,我相信您的代码是正确的(它适用于我).
Other than that, I believe your code is correct (it works for me).
此SO question/answer提供了有关正确使用 cuPrintf 的更多提示.
This SO question/answer gives more tips about using cuPrintf properly.
这篇关于我们如何使用 cuPrintf()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!