forked from AdaCore/cuda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compute_capability.sh
64 lines (58 loc) · 1.19 KB
/
compute_capability.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
#!/bin/sh
set -e
usage() {
echo "usage: $(basename "$0") [--expect-single | -s] [--no-expect-single | -S] [--compute-prefix | -c] [--sm-prefix | -C]"
}
expect_single=0
compute_prefix=1
while [ -n "$1" ]; do
case $1 in
-c|--compute-prefix)
compute_prefix=1
;;
-C|--sm-prefix)
compute_prefix=0
;;
-s|--expect-single)
expect_single=1
;;
-S|--no-expect-single)
expect_single=0
;;
-h|--help)
usage
exit 0
;;
*)
echo "unknown arg $1" >&2
usage
exit 2
;;
esac
shift
done
csv=$(nvidia-smi --query-gpu=compute_cap --format=csv)
cap=$(echo "$csv" | tail -n +2 | tr -d '. \t')
if [ -z "$cap" ]; then
number=0
else
number=$(echo "$cap" | wc -l)
fi
# number of GPU
if [ "$expect_single" -eq 0 ]; then
echo "$number GPU"
elif [ "$number" -ne 1 ]; then
echo "expected a single GPU, found $number" >&2
exit 1
fi
# capacity
if [ "$number" -ne 0 ]; then
echo "$cap" | while read -r c; do
if [ $compute_prefix -eq 0 ]; then
prefix="sm_"
else
prefix="compute_"
fi
echo "$prefix$c"
done
fi