我正在尝试使用 nvprof 在我的 CUDA 程序中获得一些基准时间,但不幸的是它似乎没有分析任何 API 调用或内核。我寻找了一个简单的初学者示例以确保我做对了,并在 Nvidia 开发者博客上找到了一个:
https://devblogs.nvidia.com/parallelforall/how-optimize-data-transfers-cuda-cc/
代码:
int main()
{
const unsigned int N = 1048576;
const unsigned int bytes = N * sizeof(int);
int *h_a = (int*)malloc(bytes);
int *d_a;
cudaMalloc((int**)&d_a, bytes);
memset(h_a, 0, bytes);
cudaMemcpy(d_a, h_a, bytes, cudaMemcpyHostToDevice);
cudaMemcpy(h_a, d_a, bytes, cudaMemcpyDeviceToHost);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
命令行:
-bash-4.2$ nvcc profile.cu -o profile_test
-bash-4.2$ nvprof ./profile_test
Run Code Online (Sandbox Code Playgroud)
所以我逐字逐行复制它,并运行相同的命令行参数。不幸的是,我的结果是一样的:
-bash-4.2$ nvprof ./profile_test
==85454== NVPROF is profiling process 85454, command: ./profile_test
==85454== Profiling application: ./profile_test
==85454== Profiling result:
No kernels …Run Code Online (Sandbox Code Playgroud)