Is it possible for a kernel to know on which GPU device it is running?

I have multiple GPUs in the machine. I am launching each kernel on a separate stream on a separate GPU device.

I want to place a printf in the kernel code that prints debugging information that includes the device ID of the GPU on which the kernel is running.

Is there a cuda function that can be executed by a kernel that returns the device Id on which it is running?

cudaGetDevice() is callable from device code (link against -rdc=true -lcudadevrt) and should behave the same in device code as in host code, see here

1 Like