File Logger Example

This notebook is a small demo of how to use gpumon in Jupyter notebooks and some convenience methods for working with GPUs


In [1]:
from gpumon.file import log_context

device_name and device_count will return the name of the GPU found on the system and the number of GPUs


In [2]:
from gpumon import device_name, device_count

In [22]:
device_count() # Returns the number of GPUs available


Out[22]:
4

In [5]:
device_name() # Returns the type of GPU available


Out[5]:
'Tesla P40'

In [6]:
from bokeh.io import output_notebook, show
import time

In [7]:
output_notebook()


Loading BokehJS ...

Here we are simply going to tell the log context to record GPU measurements to the file test_gpu.txt


In [8]:
with log_context('test_gpu.txt') as log:
    time.sleep(10)

We can then cat the file to see what we recorded in the 10 seconds


In [9]:
!cat test_gpu.txt


#Date       Time        gpu   pwr  temp    sm   mem   enc   dec  mclk  pclk
#YYYYMMDD   HH:MM:SS    Idx     W     C     %     %     %     %   MHz   MHz
 20180330   16:21:28      0    10    21     0     0     0     0   405   544
 20180330   16:21:28      1     9    26     0     0     0     0   405   544
 20180330   16:21:28      2     9    21     0     0     0     0   405   544
 20180330   16:21:28      3     9    21     0     0     0     0   405   544
 20180330   16:21:29      0     9    21     0     0     0     0   405   544
 20180330   16:21:29      1     9    26     0     0     0     0   405   544
 20180330   16:21:29      2     9    21     0     0     0     0   405   544
 20180330   16:21:29      3     9    21     0     0     0     0   405   544
 20180330   16:21:31      0     9    21     0     0     0     0   405   544
 20180330   16:21:31      1     9    26     0     0     0     0   405   544
 20180330   16:21:31      2     9    21     0     0     0     0   405   544
 20180330   16:21:31      3     9    21     0     0     0     0   405   544
 20180330   16:21:32      0     9    21     0     0     0     0   405   544
 20180330   16:21:32      1     9    26     0     0     0     0   405   544
 20180330   16:21:32      2     9    21     0     0     0     0   405   544
 20180330   16:21:32      3     9    21     0     0     0     0   405   544
 20180330   16:21:33      0     9    21     0     0     0     0   405   544
 20180330   16:21:33      1     9    26     0     0     0     0   405   544
 20180330   16:21:33      2     9    21     0     0     0     0   405   544
 20180330   16:21:33      3     9    21     0     0     0     0   405   544
 20180330   16:21:35      0     9    21     0     0     0     0   405   544
 20180330   16:21:35      1     9    26     0     0     0     0   405   544
 20180330   16:21:35      2     9    21     0     0     0     0   405   544
 20180330   16:21:35      3     9    21     0     0     0     0   405   544
 20180330   16:21:36      0    10    21     0     0     0     0   405   544
 20180330   16:21:36      1    10    26     0     0     0     0   405   544
 20180330   16:21:36      2     9    21     0     0     0     0   405   544
 20180330   16:21:36      3     9    21     0     0     0     0   405   544

By calling the log object we get all the data returned to us in a dataframe


In [10]:
df = log()

In [11]:
df


Out[11]:
timestamp gpu pwr temp sm mem enc dec mclk pclk
0 2018-03-30 16:21:28 0 10 21 0 0 0 0 405 544
1 2018-03-30 16:21:28 1 9 26 0 0 0 0 405 544
2 2018-03-30 16:21:28 2 9 21 0 0 0 0 405 544
3 2018-03-30 16:21:28 3 9 21 0 0 0 0 405 544
4 2018-03-30 16:21:29 0 9 21 0 0 0 0 405 544
5 2018-03-30 16:21:29 1 9 26 0 0 0 0 405 544
6 2018-03-30 16:21:29 2 9 21 0 0 0 0 405 544
7 2018-03-30 16:21:29 3 9 21 0 0 0 0 405 544
8 2018-03-30 16:21:31 0 9 21 0 0 0 0 405 544
9 2018-03-30 16:21:31 1 9 26 0 0 0 0 405 544
10 2018-03-30 16:21:31 2 9 21 0 0 0 0 405 544
11 2018-03-30 16:21:31 3 9 21 0 0 0 0 405 544
12 2018-03-30 16:21:32 0 9 21 0 0 0 0 405 544
13 2018-03-30 16:21:32 1 9 26 0 0 0 0 405 544
14 2018-03-30 16:21:32 2 9 21 0 0 0 0 405 544
15 2018-03-30 16:21:32 3 9 21 0 0 0 0 405 544
16 2018-03-30 16:21:33 0 9 21 0 0 0 0 405 544
17 2018-03-30 16:21:33 1 9 26 0 0 0 0 405 544
18 2018-03-30 16:21:33 2 9 21 0 0 0 0 405 544
19 2018-03-30 16:21:33 3 9 21 0 0 0 0 405 544
20 2018-03-30 16:21:35 0 9 21 0 0 0 0 405 544
21 2018-03-30 16:21:35 1 9 26 0 0 0 0 405 544
22 2018-03-30 16:21:35 2 9 21 0 0 0 0 405 544
23 2018-03-30 16:21:35 3 9 21 0 0 0 0 405 544
24 2018-03-30 16:21:36 0 10 21 0 0 0 0 405 544
25 2018-03-30 16:21:36 1 10 26 0 0 0 0 405 544
26 2018-03-30 16:21:36 2 9 21 0 0 0 0 405 544
27 2018-03-30 16:21:36 3 9 21 0 0 0 0 405 544

We can also call plot on the log object to plot the measurements we want


In [21]:
p = log.plot(gpu_measurement='pwr', num_gpus=4)

In [20]:
show(p)