GPU 0 is the only GPU being used when I have 2 GPUs

I’m experiencing an issue where I have multiple GPUs (two Quadro P5000s) and I’m running into this problem where I try to use GPU 1 to do processing for (encoding/decoding), but all of the processes keep going to GPU 0 by default. Would there be a way to set GPU 1 to do the processes. I’ve tried cudaSetDevice(1) and it still goes to GPU 0.

Hi @TabascoV !

Since this seems to be an issue with the correct use of your CUDA environment, I redirected your request to the CUDA category. I think there you will receive the help you need!

Thanks,
Markus

This is not managed or controlled by CUDA. However, the basic methodology is described here in the NVENC codec SDK user’s manual. If you are using CUDA to interact with NVENC:

CUDA

  • The client should create a floating CUDA context, and pass the CUDA context handle as NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS::device, and set NV_ENC_OPEN_ENCODE_SESSION_EX_PARAMS::deviceType to NV_ENC_DEVICE_TYPE_CUDA. Use of CUDA device for Encoding is supported on Linux and Windows 7 and later versions of Windows OS.

So it is not done via cudaSetDevice(). You must use the driver API to create a context. This context will be created on a particular device. You then pass the handle to that context to the NVENC API as described in that manual that I linked. If the context you created is on device 0, the encode operations requested (and indeed all NVENC API activity) will be directed to device 0. Likewise if you pass a context created on device 1, then your encode activity will take place on device 1.

Further questions about NVENC or NVDEC should not be posted here. They should be posted on the Video Codec SDK forum.

2 Likes

Thanks Robert!

One more question, if I wanted to use both gpus with NVENC I would have to create a context for each gpu and pass each device’s context handle as a parameter when I open the encode session, and set the device type for each to type CUDA? And if I wanted to implement P2P access I would use the driver API to enable peer access through contexts correct?

I believe the answer to all those questions is yes.