CUDA:CPU 计时器和 CUDA 计时器事件之间的区别? [英] CUDA: Difference between CPU timer and CUDA timer event?

查看:43
本文介绍了CUDA:CPU 计时器和 CUDA 计时器事件之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用CPU 计时器CUDA 计时器事件 来测量执行某些CUDA 代码所花费的时间有什么区别?CUDA 程序员应该使用哪些工具?为什么?

What is the difference between using a CPU timer and the CUDA timer event to measure the time taken for the execution of some CUDA code? Which of these should a CUDA programmer use and why?

CPU 计时器使用将涉及在记录任何时间之前调用 cudaThreadSynchronize.注意时间 clock() 可以使用或高分辨率性能计数器,如 QueryPerformanceCounter(在 Windows 上)可以被查询.

CPU timer usage would involve calling cudaThreadSynchronize before any time is noted. For noting the time clock() could be used or high-resolution performance counter like QueryPerformanceCounter (on Windows) could be queried.

CUDA 计时器事件将涉及使用 cudaEventRecord 记录前后.稍后,将通过对事件调用cudaEventSynchronize 获取经过时间,然后调用cudaEventElapsedTime 获取经过时间.

CUDA timer event would involve recording before and after by using cudaEventRecord. At a later time, the elapsed time would be obtained by calling cudaEventSynchronize on the events, followed by cudaEventElapsedTime to obtain the elapsed time.

推荐答案

第一部分问题的答案是 cudaEvents 计时器基于 GPU 上的高分辨率计数器,并且与使用相比,它们具有更低的延迟和更好的分辨率主机计时器,因为它们脱离金属".您应该期待 cudaEvents 计时器的亚微秒分辨率.正是出于这个原因,您应该更喜欢它们来为 GPU 操作计时.cudaEvents 的 per-stream 特性也可用于检测异步操作,如同时内核执行和重叠复制和内核执行.使用主机计时器进行这种时间测量几乎是不可能的.

The answer to the first part of question is that cudaEvents timers are based off high resolution counters on board the GPU, and they have lower latency and better resolution than using a host timer because they come "off the metal". You should expect sub-microsecond resolution from the cudaEvents timers. You should prefer them for timing GPU operations for precisely that reason. The per-stream nature of cudaEvents can also be useful for instrumenting asynchronous operations like simultaneous kernel execution and overlapped copy and kernel execution. Doing that sort of time measurement is just about impossible using host timers.

我不会回答最后一段,因为你删除了它.

I won't answer the last paragraph because you deleted it.

这篇关于CUDA:CPU 计时器和 CUDA 计时器事件之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆