2013-05-30 53 views
1

是否有任何选项可用于分析CUDA内核?不是整体,而是其中的一部分。我有一些设备功能调用,我想测量他们的时间。是否有可以设置的标志/事件/说明,然后在NVIDIA Visual Profiler中可以看到?或者我需要手动插入cudaEventCreate和类似的功能。内核中的CUDA分析

回答

3

你可以在时间使用手动clock()clock64()功能内核的特定部分:

unsigned long long* time_spent; 

__global__ void kernel(...) 
{ 
    unsigned int t1, t2; 
    // ... 
    t1 = clock(); 
    // code of interest 
    t2 = clock(); 
    atomicAdd(&time_spent, t2 - t1); 
} 

“时钟()`正式返回clock_t表示,但我更喜欢明确的使用unsigned int类型的做出明显的办法上面的代码正确处理时钟值环绕(只要定时代码不超过2^32-1周期来完成。

确保也时间

t1 = clock(); 
    t2 = clock(); 
01码

背靠背,所以你可以减去时间开销。

+0

是不是'clock()'为每个SM返回一个本地计数器? – KiaMorot

+0

沉迷于此答案:http://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#time-function – KiaMorot

+0

是的。但只要我们仅仅从同一个SM中获得时间差异,这并不重要。 (动态并行性确实会在这里产生一个问题,为简单起见,我只是假设感兴趣的代码不会启动任何其他内核)。 – tera