-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
gpuowl-bench.sh
170 lines (151 loc) · 4.71 KB
/
gpuowl-bench.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/bin/bash
# Copyright © 2020 Teal Dulcet
# Benchmark GpuOwl
# Run: ./gpuowl-bench.sh <GpuOwl binary> [Iterations] [ROE option]
set -e
if [[ $# -lt 1 || $# -gt 3 ]]; then
echo "Usage: $0 <GpuOwl binary> [Iterations] [ROE option]" >&2
exit 1
fi
# GpuOwl
GPUOWL=$1
# Number of iterations
ITERS=${2:-20000}
# Device number
DEVICE=0
# Minimum FFT length (in K)
MIN=1024
# MIN=1
# Maximum FFT length (in K)
MAX=12288
# MAX=32768
# GpuOwl -use option to show roundoff error (ROE)
# USE=STATS
# USE=ROE1,ROE2
USE=${3:-STATS}
# GpuOwl arguments
ARGS=(
-device $DEVICE
# -log 10000
-use "$USE"
)
if command -v clinfo >/dev/null; then
mapfile -t TOTAL_GPU_MEM < <(clinfo --raw | sed -n 's/.*CL_DEVICE_GLOBAL_MEM_SIZE *//p')
for i in "${!TOTAL_GPU_MEM[@]}"; do
TOTAL_GPU_MEM[i]=$((TOTAL_GPU_MEM[i] >> 20))
done
elif command -v nvidia-smi >/dev/null && nvidia-smi >/dev/null; then
mapfile -t TOTAL_GPU_MEM < <(nvidia-smi --query-gpu=memory.total --format=csv,noheader,nounits | grep -iv 'not supported')
fi
if [[ -n $TOTAL_GPU_MEM ]]; then
ARGS+=(-maxAlloc "$(echo "${TOTAL_GPU_MEM[DEVICE]}" | awk '{ printf "%d", $1 * 0.9 }')M")
fi
if [[ ! -x $GPUOWL ]]; then
echo "Error: GpuOwl binary not found" >&2
exit 1
fi
RE='^[0-9]+$'
if ! [[ $ITERS =~ $RE ]]; then
echo "Usage: [Iterations] must be a number" >&2
exit 1
fi
if ! ((ITERS && ITERS % 10000 == 0)); then
echo "Usage: [Iterations] must be a multiple of 10000" >&2
exit 1
fi
output=$("$GPUOWL" -h)
if echo "$output" | grep -q '^-unsafeMath'; then
ARGS+=(-unsafeMath)
# elif echo "$output" | grep -q '^-safeMath'; then
# ARGS+=( -safeMath )
fi
if echo "$output" | grep -q '^-nospin'; then
ARGS+=(-nospin)
fi
{
file=$(dirname "$GPUOWL")/version.inc
if [[ -r $file ]]; then
cat "$file"
fi
printf 'FFT length\tVariant\tMax exp\tus/iter\tError mean / max / SD / z / N\n\n'
} >>bench.txt
DIR=$PWD
cd /tmp
output=$(echo "$output" | grep '^FFT' | tail -n +2)
ffts=$(echo "$output" | awk '{ print $2 }')
mapfile -t FFTS <<<"$ffts"
mapfile -t AFFTS < <(echo "$ffts" | numfmt --from=iec)
mapfile -t MAX_EXPS < <(echo "$output" | awk -F'[][ ]+' '{ print $5 }' | numfmt --from=si)
mapfile -t VARIANTS < <(echo "$output" | sed -n 's/^.*] //p')
echo -e "\nWarming up the GPU...\n"
exp=2976221
"$DIR/$GPUOWL" -prp "$exp" -iters $((ITERS * 10)) -fft 256:3:256 "${ARGS[@]}"
rm -rf -- "$exp" gpuowl.log
for i in "${!MAX_EXPS[@]}"; do
if [[ -n $MIN && ${AFFTS[i]} -lt $((MIN << 10)) ]]; then
continue
elif [[ -n $MAX && ${AFFTS[i]} -gt $((MAX << 10)) ]]; then
break
fi
if [[ ${MAX_EXPS[i]} -ge 100 ]]; then
exp=$(seq $((MAX_EXPS[i] - 100)) "${MAX_EXPS[i]}" | factor | awk 'NF == 2 { print $2 }' | tail -n 1)
printf "\nTiming FFT length: %s (%s),\tExponent: %'d\n" "${FFTS[i]}" "$(numfmt --to=iec "${AFFTS[i]}")" "$exp"
variants=(${VARIANTS[i]})
for j in "${!variants[@]}"; do
printf "\n\t%'d Variant: %s\n\n" $((j + 1)) "${variants[j]}"
"$DIR/$GPUOWL" -prp "$exp" -iters "$ITERS" -fft "${variants[j]}" "${ARGS[@]}" | grep -i 'gpuowl\|loaded\|on-load\|[[:digit:]]\{6,\} \(LL\|P1\|OK\|EE\)\? \+[[:digit:]]\{4,\}\|check\|jacobi\|roundoff\|ROE\|error\| E :\|exception\|exiting'
time=''
if output=$(grep '[[:digit:]]\{7,\} \(LL\|P1\|OK\|EE\)\? \+[[:digit:]]\{5,\}' gpuowl.log | grep "$ITERS"); then
RE='([[:digit:]]+) us/it'
if [[ $output =~ $RE ]]; then
time=${BASH_REMATCH[1]}
fi
fi
mean=''
max=''
stddev=''
z=''
N=''
if output=$(grep -i 'roundoff\|ROE ' gpuowl.log); then
output=$(echo "$output" | tail -n 1)
RE='mean ([[:digit:]]+(\.[[:digit:]]+)?)'
if [[ $output =~ $RE ]]; then
mean=${BASH_REMATCH[1]}
fi
RE='ROE ([[:digit:]]+(\.[[:digit:]]+)?)'
if [[ $output =~ $RE ]]; then
max=${BASH_REMATCH[1]}
fi
RE='max ([[:digit:]]+(\.[[:digit:]]+)?)'
if [[ $output =~ $RE ]]; then
max=${BASH_REMATCH[1]}
fi
RE='SD ([[:digit:]]+(\.[[:digit:]]+)?)'
if [[ $output =~ $RE ]]; then
stddev=${BASH_REMATCH[1]}
fi
RE=' z[= ]([[:digit:]]+(\.[[:digit:]]+)?)'
if [[ $output =~ $RE ]]; then
z=${BASH_REMATCH[1]}
fi
RE='N=([[:digit:]]+)'
if [[ $output =~ $RE ]]; then
N=${BASH_REMATCH[1]}
fi
elif output=$(grep -i 'ROE=' gpuowl.log); then
output=$(echo "$output" | tail -n 1)
RE='ROE=([[:digit:]]+(\.[[:digit:]]+)?) ([[:digit:]]+(\.[[:digit:]]+)?) ([[:digit:]]+)'
if [[ $output =~ $RE ]]; then
max=${BASH_REMATCH[1]}
stddev=${BASH_REMATCH[3]}
N=${BASH_REMATCH[5]}
fi
fi
printf '%s\t%s\t%s\t%s\t%s / %s / %s / %s / %s\n' "${FFTS[i]}" "${variants[j]}" "$exp" "${time:--}" "${mean:--}" "${max:--}" "${stddev:--}" "${z:--}" "${N:--}" >>"$DIR/bench.txt"
rm -rf -- "$exp" gpuowl.log
# sleep 1
done
fi
echo >>"$DIR/bench.txt"
done
echo >>"$DIR/bench.txt"