I am using a program which queries the number of GPUs on the system and then creates a separate thread using pthreads_create() to run a calculation on each device.
for(i = 0; i < numDevices; ++i) {
args[i].id = i;
args[i].gpu = i;
pthread_create(&threads[i], NULL, threadRoutine, &args[i]);
}
This program runs as expected when the device is in DEFAULT compute mode. However, I would like to run it in EXCLUSIVE_PROCESS compute mode. In that mode, it produces an error message for the thread that is associated with the GPU that is in use by the main process:
Thread 0 CUDA Error: exclusivethread device already in use by a different thread (see Programmer’s Guide)
I can run this program properly in EXCLUSIVE_PROCESS mode using the Multiprocess service (MPS) daemon if it is launched as root. However, I cannot run it if the MPS is launched by my own user account.
I can also run this program properly if the function call involving the device that the main program is using is made by the main program itself and not by a separate pthread.
I have two questions about this scenario:
-
The description of EXCLUSIVE_PROCESS compute mode says: Many threads in one process will be able to use cudaSetDevice() with this device. My expectation is that creating new threads with pthreads that use the same device as the main process should not cause a conflict with the device in this mode. My understanding is that this error message should show up for EXCLUSIVE_THREAD mode, but should not show up for EXCLUSIVE_PROCESS or DEFAULT compute mode. Why am I getting the error message in EXCLUSIVE_PROCESS mode?
-
The MPS documentation states that it can be run in user mode to manage processes created by that user (See 5.1.2 https://docs.nvidia.com/deploy/pdf/CUDA_Multi_Process_Service_Overview.pdf ). However, I find that the daemon fails to provide access to the spawned threads unless MPS is run as root. What might be causing the MPS daemon to misbehave when running in single user mode?
I am happy to provide more information if requested. I cannot share the code I am using, but I may be able to prepare a minimal example if it is difficult to answer my questions without one.
Thanks.
Dan