gpt4 book ai didi

cuda - 我们如何使用 cuPrintf()?

转载 作者:行者123 更新时间:2023-12-05 01:32:11 26 4
gpt4 key购买 nike

我们必须做什么才能使用 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

谢谢!

最佳答案

在你的内核中而不是这个:

printf ("Thread number %d. f = %d\n", threadIdx.x, f);

你应该这样做:

cuPrintf ("Thread number %d. f = %d\n", threadIdx.x, f);

除此之外,我相信您的代码是正确的(对我有用)。

SO question/answer提供有关正确使用 cuPrintf 的更多提示。

关于cuda - 我们如何使用 cuPrintf()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13608287/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com