CUDA:CPU定时器和CUDA定时器事件之间的差异? [英] CUDA: Difference between CPU timer and CUDA timer event?

查看:516
本文介绍了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操作的原因。 cudaEvent的每流性质也可用于检测异步操作,例如同时内核执行和重叠复制和内核执行。使用主持人计时器来做这种时间测量是不可能的。

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天全站免登陆