My question is whether it is possible to somehow query the MPS server and check if it is running on the GPU during application runtime?
As far as I know, by using the nvidia-smi it can be checked whether CUDA MPS Server is running on the GPU, but I am not sure how to use this system command during application runtime. Is there potentially any other way to check whether the MPS server is running on the GPU during application runtime?
I found a way to do so, but if you think that there might be a better way please share it. Anyway, this approach is working for me.
Basically, when the MPS control daemon starts, a file named control gets created in /tmp/nvidia-mps/ and when the daemon exits, the file will no longer exist.
I used access function to check if /tmp/nvidia-mps/control file exists.
Here is the code:
#include <unistd.h>
#include <stdio.h>
int main()
{
int result;
const char *filename = "/tmp/nvidia-mps/control"; // only available if nvidia-cuda-mps-control daemon is running
result = access (filename, F_OK); // F_OK tests existence also (R_OK,W_OK,X_OK).
// for readable, writeable, executable
if (result == 0)
{
printf("%s MPS demon is running!!\n",filename);
}
else
{
printf("%s MPS demon doesn't exist!\n",filename);
}
return 0;
}
And here is the result:
# gcc mps-checker.c -o mps-status
# nvidia-cuda-mps-control -d
# ./mps-status
/tmp/nvidia-mps/control MPS demon is running!!
# echo quit | nvidia-cuda-mps-control
# ./mps-status
/tmp/nvidia-mps/control MPS demon doesn't exist!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With