nvprof没有获取任何API调用或内核

时间:2016-05-01 18:55:41

标签: c cuda profiling nvprof

我试图通过nvprof在我的CUDA程序中获得一些基准时序,但不幸的是它似乎没有分析任何API调用或内核。我找了一个简单的初学者示例,以确保我做得对,并在Nvidia开发博客上找到一个:

documentation

代码:

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;
}

命令行:

-bash-4.2$ nvcc profile.cu -o profile_test
-bash-4.2$ nvprof ./profile_test

所以我逐字逐句地复制它,并运行相同的命令行参数。不幸的是我的结果是一样的:

-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. 

我正在运行Nvidia toolkit 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;
}

不幸的是,这并没有改变一切。

2 个答案:

答案 0 :(得分:2)

在退出线程之前,您需要调用cudaProfilerStop()(对于Runtime API)。这允许nvprof收集所有必要的数据。

根据CUDA doc

  

为避免丢失尚未刷新的个人资料信息,请执行此操作   被分析的应用程序应该在退出之前确保所有   完成GPU工作(使用CUDA同步调用),然后调用   cudaProfilerStop()cuProfilerStop()。这样做会强制缓冲   关于要刷新的相应上下文的简档信息。

答案 1 :(得分:2)

这是统一内存配置文件(标志)的错误

--unified-memory-profiling off  ./profile_test

为我解决了所有问题。