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

查看:528
本文介绍了如何创建一个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)。如果您有多个设备,请使用您要建立上下文的设备的ID调用 cudaSetDevice(),然后 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天全站免登陆