GPU 代码在从 VS2008 运行时和仅运行 .exe 时给出不同的时间
我的代码中有 cuda 事件来记录执行时间。当我在 VS 2008 中单击“开始调试”时,计时器给出的值为 1.5 秒。但是,当我从 .exe 文件运行该程序时,它给出的时间为 0.4 秒。为什么会有这样的差异?
I have cuda events in my code to record the time of execution. When I click "Start Debuggin" from VS 2008, the timer gives a value of 1.5 seconds. However, when I run the program from .exe file, it gives time of .4 seconds. Why this difference?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除了(只有几种可能性)之外,附加到调试器运行应该引入性能差异并没有固有的原因:
您是否设置了任何条件断点?根据具体情况,这些可能会对执行时间产生巨大影响。
您是否显式地将大量数据写入
Debug
或Trace
侦听器? (编辑:这与 C# 相关,可能与 C++ 无关。)EXE 是否在发布模式下编译?默认情况下,发布配置会启用在调试模式下构建时不存在的优化。
您的计时代码真的仅对相关部分进行计时吗?如果您在程序执行开始时启动计时器,而不是在您真正感兴趣的 GPU 调用周围启动计时器,则可能会意外地对一些与调试器运行相关的启动任务进行计时,而这些任务在调试器中不会处于活动状态。一个独立的应用程序。
There's no inherent reason that running attached to the debugger should introduce a performance difference, other than (just a few possibilities):
Do you have any conditional breakpoints set? Depending on the condition, these can have a dramatic impact on execution time.
Are you explicitly writing large amounts of data to the
Debug
orTrace
listeners? (Edit: that's relevant for C#, probably not for C++.)Is the EXE compiled in Release mode? By default, the Release config turns on optimizations that aren't present when building in Debug mode.
Is your timing code really only timing the relevant section? If you're starting the timer at the start of program execution instead of around the GPU calls that you're really interested in, you may be accidentally timing some startup tasks that are tied to running with the debugger that won't be active in a standalone app.