What is the CUDA driver's API equivalent for the runtime API function cudaSetDevice
?
I was looking into the driver API and cannot find an equivalent function. What I can do is
cuDeviceGet(&cuDevice, device_no);
cuCtxCreate(&cuContext, 0, cuDevice);
which is not equivalent since beside setting the device it also creates a context. The runtime API cudaSetDevice
does not create a context per se. In the runtime API the CUDA context is created implicitly with the first CUDA call that requires state on the device.
Background for this question: CUDA-aware MPI (MVAPICH2 1.8/9) initialization requires the CUDA device to be set before MPI_init
is called. Using the CUDA runtime API this can be done with
cudaSetDevice(device_no);
MPI_init();
However, I don't want to use the call to the CUDA runtime since the rest of my application is purely using the driver API and I'd like to avoid linking also to the runtime.
What's wrong in creating the context already before MPI is initialized? In principle nothing. Just wondering if there is an equivalent call in the driver API.
cudaSetDevice
does create a context, if one is not already in existence on the device in question. - talonmies