Cuda 我们如何使用cuPrintf()?
要使用cuPrintf(),我们必须做什么?(设备计算能力1.2,Ubuntu 12)我找不到“cuPrintf.cu”和“cudaPrintf.cuh”,所以我下载了它们的代码并包括:Cuda 我们如何使用cuPrintf()?,cuda,nvcc,Cuda,Nvcc,要使用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,
#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);
}
谢谢 在内核中,而不是此:
printf ("Thread number %d. f = %d\n", threadIdx.x, f);
您应该这样做:
cuPrintf ("Thread number %d. f = %d\n", threadIdx.x, f);
除此之外,我相信你的代码是正确的(它适合我)
这为正确使用cuPrintf提供了更多提示。包括
并使用-arch=sm\u 20
编译
详细信息:
代码:
在内核中调用
cuPrintf
,而不是printf
,这是内核printf,而不是cuPrintfOops!我错过了计算能力。哎呀!首先我尝试使用printf(),但后来发现计算能力低于2.0。最后我忘了将printf()更改为cuPrintf()。抱歉问了个愚蠢的问题:(
cuPrintf ("Thread number %d. f = %d\n", threadIdx.x, f);
#include <stdio.h>
__global__ void hello_kernel (float f) {
printf ("Thread number %d. f = %d\n", threadIdx.x, f);
}
int main(){
return 0;
}
nvcc -arch=sm_20 -o printfTest printfTest.cu