How to check if keras training is already running in a GPU?

Viewed 1030

Sometimes I make a mistake and try to run two simultaneous trainings with keras in the same GPU (two different scripts), making my machine crash or breaking both trainings.

I would like to be able to test in my script if there is some training running and therefore either change of gpu or stop the new training.

The only hint I found searching for an answer is to use nvidia-smi to check processes running in gpus?

An example of nvidia-smi output:

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 411.63                 Driver Version: 411.63                    |
|-------------------------------+----------------------+----------------------+
| GPU  Name            TCC/WDDM | Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  TITAN Xp           WDDM  | 00000000:03:00.0 Off |                  N/A |
| 42%   67C    P2    81W / 250W |  10114MiB / 12288MiB |     54%      Default |
+-------------------------------+----------------------+----------------------+
|   1  TITAN Xp           WDDM  | 00000000:04:00.0 Off |                  N/A |
| 35%   58C    P2   144W / 250W |  10315MiB / 12288MiB |     73%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0     11660      C   ...\conda\envs\tensorflow18-gpu\python.exe N/A      |
|    1      1532    C+G   Insufficient Permissions                   N/A      |
|    1      5388    C+G   C:\Windows\explorer.exe                    N/A      |
|    1      6648    C+G   Insufficient Permissions                   N/A      |
|    1      7396    C+G   ...t_cw5n1h2txyewy\ShellExperienceHost.exe N/A      |
|    1      7688    C+G   ...dows.Cortana_cw5n1h2txyewy\SearchUI.exe N/A      |
|    1      9808      C   ...\conda\envs\tensorflow18-gpu\python.exe N/A      |
|    1     10820    C+G   Insufficient Permissions                   N/A      |
|    1     11232    C+G   ...x64__8wekyb3d8bbwe\Microsoft.Photos.exe N/A      |
+-----------------------------------------------------------------------------+

In this case there is python.exe running in GPU 0 and in GPU 1.

Is there a more direct solution? Thanks

1 Answers
Related