Christoph
Christoph

Reputation: 606

cuInit(0) not needed anymore?

I'm currently writing an app to stream openGL content, therefore using CUDA with NVidias NVenc-API. I have noticed that calling cuInit(0) - which should be done as a first call to initialize Cuda, according to many tutorials, does not change the success of my Cuda Kernel. So whether I'm calling it or not, the program runs in both scenarios.

Have they changed it? I was looking for some information but could not find anything about this.

Thanks!

A bit more information:

First step is to create a Cuda Device using cudaSetDevice() - Runtime API. Second step, create a context using cuCtxCreate() - Driver API. After this I can launch a kernel using triple chevron syntax with a cuda array allocated via cudaMalloc().

Upvotes: 1

Views: 5029

Answers (1)

talonmies
talonmies

Reputation: 72348

If the first call in your code is, as you say, cudaSetDevice(), and your CUDA version is CUDA 4 or newer, then that will implicitly establish a context, and there is no requirement to do anything else to make a CUDA runtime API session work correctly.

You should not call cuCtxCreate or cuInit after that. If you have a genuine requirement to use both the runtime and driver APIs (and it doesn't sound like you do), there is a supported and documented method for doing so. The rule of thumb is to use either the driver API or the runtime API, but not, both, and if you don't have a reason to use the driver API, then don't use it. The runtime API is simpler, cleaner and less verbose.

Upvotes: 2

Related Questions