除了第一个 cudaMalloc 调用之外,还有什么特殊的函数可以初始化 GPU? [英] Any particular function to initialize GPU other than the first cudaMalloc call?

查看:11
本文介绍了除了第一个 cudaMalloc 调用之外,还有什么特殊的函数可以初始化 GPU?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于 GPU 上的一些初始化工作,第一次 cudaMalloc 调用很慢(例如 0.2 秒).有没有只做初始化的函数,这样我就可以分开时间了?cudaSetDevice 似乎将时间减少到 0.15 秒,但仍然没有消除所有初始化开销.

The first cudaMalloc call is slow (like 0.2 sec) because of some initialization work on GPU. Is there any function that solely do initialization, so that I can separate the time? cudaSetDevice seems to reduce the time to 0.15 secs, but still does not eliminate all init overheads.

推荐答案

调用

cudaFree(0);

是在 CUDA 运行时强制建立惰性上下文的规范方法.您无法减少开销,这是驱动程序、运行时和操作系统延迟的函数.但是上面的调用可以让您控制这些开销在程序执行期间如何/何时发生.

is the canonical way to force lazy context establishment in the CUDA runtime. You can't reduce the overhead, that is a function of driver, runtime and operating system latencies. But the call above will let you control how/when those overheads occur during program execution.

2015 年编辑 添加运行时 API 中上下文初始化的启发式随着时间的推移发生了微妙的变化,因此 cudaSetDevice 现在建立了一个上下文,因此 cudaFree() 调用不是明确要求初始化上下文的,您可以使用 cudaSetDevice 代替.另请注意,在第一次内核启动时仍会产生一些设置时间,而在此之前情况并非如此.对于内核计时,最好在启动内核之前先包含一个预热调用,您将有时间消除此设置延迟.似乎各种分析工具都内置了足够的粒度来避免这种情况,而无需任何额外的 API 调用或内核调用.

EDIT in 2015 to add that the heuristics of context initialisation in the runtime API have subtly changed over time so that cudaSetDevice now establishes a context, so the cudaFree() call isn't explicitly required to intialise a context, you can use cudaSetDeviceinstead. Also note that some set-up time will still be incurred at the first kernel launch, whereas before this wasn't the case. For for kernel timing, it is best to include a warm-up call first before launching the kernel you will time to remove this set-up latency. It appears that the various profiling tools have enough granularity built in to avoid this without any extra API calls or kernel calls.

这篇关于除了第一个 cudaMalloc 调用之外,还有什么特殊的函数可以初始化 GPU?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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