-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgpu.sh
executable file
·84 lines (70 loc) · 1.67 KB
/
gpu.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash -
#===============================================================================
#
# FILE: gpu.sh
#
# USAGE: ./gpu.sh
#
# DESCRIPTION:
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: YOUR NAME (),
# ORGANIZATION:
# CREATED: 08/19/2015 17:11
# REVISION: ---
#===============================================================================
set -o nounset # Treat unset variables as an error
#!/bin/bash
#
# simply displays the current GPU usage and memory consumption every
# second on the console, or in genmon bar style when started with
# --genmon
#
# works only on Nvidia cards
#
export GPU=0
export MEM=0
function genmon_mode {
get_gpu
get_mem
if [ ${GPU} -lt 10 ]; then
GPU=0${GPU}
fi
if [ ${MEM} -lt 10 ]; then
MEM=0${MEM}
fi
echo "<img>/usr/share/pixmaps/nvidia-current-settings.png</img>"
echo "<txt><b><big><tt>${GPU} ${MEM}</tt></big></b></txt>"
echo "<tool>GPU: ${GPU}%, Memory: ${MEM}%</tool>"
}
function console_mode {
echo -e "\033[30;42mPress Ctrl-C to break ...\033[0m"
while true; do
get_gpu
get_mem
## gpu usage
echo -ne "\033[5G"
echo -ne "\033[1;37;41mGPU:\033[0m ${GPU} %"
## gpu memory
echo -ne "\033[15G"
echo -e "\033[1;37;41mMEM:\033[0m ${MEM} %"
sleep 1
done
}
function get_mem {
MEM=`nvidia-smi -q -g 0 2>&1 | grep -A 2 -i utilization | grep -i memory | tail -1 | awk '{print $3}' | sed s/\%//g`
}
function get_gpu {
GPU=`nvidia-smi -q -g 0 2>&1 | grep -A 2 -i utilization | grep -i gpu | tail -1 | awk '{print $3}' | sed s/\%//g`
}
if [ $# -eq 0 ]; then
console_mode
else
case $1 in
"--genmon") genmon_mode;;
"--console") console_mode;;
esac
fi