Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get GPU usage per process?

I have a temperature monitor program I wrote a while back which monitors the temperatures and fans on my AMD Graphics cards, checking for fan failure OR overheats. The problem with it, is that it needs to know in advance which process will be using the GPU(Graphics Processing Unit), in order to kill it or gracefully make it stop to avoid overheating.

To make my program more dynamic, I needed a way to find which process is using the GPU, much like which process is using CPU time(Task Manager). One such application is Process Explorer from SysInternals.

I am asking, how may I do this in Windows in C? I am aware that if there is such a way, it would target Vista and above.

like image 801
farmdve Avatar asked Oct 22 '12 18:10

farmdve


1 Answers

If you have a Tesla board or high-end Quadro and running on Windows Server 2008 R2 64bit, Windows 7 64bit (or 32/64bit Linux) then you can use NVML to do that.

Download latest NVML SDK (Tespla Deployment Kit) and take a look at these two functions:

nvmlReturn_t nvmlDeviceGetComputeRunningProcesses (nvmlDevice_t device, 
                                                   unsigned int  infoCount,
                                                   nvmlProcessInfo_t * infos)

nvmlReturn_t nvmlDeviceGetTemperature (nvmlDevice_t device,
                                       nvmlTemperatureSensors_t sensorType,
                                       unsigned int * temp)

Watch out for:

nvmlReturn_t nvmlDeviceGetFanSpeed (nvmlDevice_t device, unsigned int * speed)

It "retrieves the intended operating speed of the device’s fan" not real fan speed. So you can't use it for checking fan failures.

I'm not aware of nvmlDeviceGetComputeRunningProcesses replacement that'd work on GeForce boards, but Windows NvAPI (which also works on GeForce) allows to query both Fan Speed and Temperature.

like image 107
Przemyslaw Zych Avatar answered Oct 06 '22 15:10

Przemyslaw Zych