如何创建 CUDA 上下文? [英] How to create a CUDA context?

查看:21
本文介绍了如何创建 CUDA 上下文?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建 CUDA 上下文?CUDA 的第一次调用很慢,我想在启动内核之前创建上下文.

How can I create a CUDA context? The first call of CUDA is slow and I want to create the context before I launch my kernel.

推荐答案

强制建立运行时 API 上下文的规范方法是调用 cudaFree(0).如果您有多个设备,调用 cudaSetDevice() 并使用您要在其上建立上下文的设备的 ID,然后调用 cudaFree(0) 来建立上下文.

The canonical way to force runtime API context establishment is to call cudaFree(0). If you have multiple devices, call cudaSetDevice() with the ID of the device you want to establish a context on, then cudaFree(0) to establish the context.

请注意,从 CUDA 5.0 开始,上下文建立的启发式方法似乎略有不同,cudaSetDevice() 本身会在调用设备时建立上下文.所以不再需要显式的 cudaFree(0) 调用(尽管它不会伤害任何东西).

Note that as of CUDA 5.0, it appears that the heuristics of context establishment are slightly different and cudaSetDevice() itself establishes context on the device is it called on. So the explicit cudaFree(0) call is no longer necessary (although it won't hurt anything).

这篇关于如何创建 CUDA 上下文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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