我们必须做什么才能使用 cuPrintf()?(设备计算能力 1.2,Ubuntu 12)我找不到“cuPrintf.cu”和“cudaPrintf.cuh”,所以我下载了它们的代码并包含它们:
#include "cuPrintf.cuh"
#include "cuPrintf.cu"
顺便说一句,这是代码的其余部分:
__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还是报错:
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
谢谢!