Device number selection in CUDA code called from OpenACC code that uses "set device_num"

Hi,

I have an MPI+OpenACC code that uses
!$acc set_device(N)
before later calling routines in a C code that uses CUDA library calls.

Do the CUDA calls know which device to use automatically because they are called after the acc device_num(N) or do I need to send the device number N into the C code and set the device manually with
a call to cudaSetDevice(N)?

– Ron

Hi Ron,

Under the hood, acc set_device will call cudaSetDevice so any CUDA code called after this will correctly inherit the selected device. However if calling cudaSetDevice directly, it will not update the OpenACC runtime. Hence best to use acc set_device when mixing OpenACC and CUDA.

-Mat