nvprof 不接收任何 API 调用或内核

the*_*unz 2 c profiling cuda nvprof

我正在尝试使用 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 were profiled.

==85454== API calls:
No API activities were profiled. 
Run Code Online (Sandbox Code Playgroud)

我正在运行 Nvidia 工具包 7.5

如果有人知道我做错了什么,我会很感激知道答案。

-----编辑-----

所以我将代码修改为

#include<cuda_profiler_api.h>

int main()
{
    cudaProfilerStart();
    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);

    cudaProfilerStop();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

不幸的是,它并没有改变事情。

小智 5

这是统一内存分析的错误,标志

--unified-memory-profiling off  ./profile_test
Run Code Online (Sandbox Code Playgroud)

为我解决所有问题。