-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.sh
executable file
·145 lines (115 loc) · 3.32 KB
/
run.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
#!/bin/bash
# ----------------------------------------------
# Author - Shalitha Suranga
# ----------------------------------------------
# ---------- Configuration ---------------------
CUDA=1
SIZES=( 32 64 128 256 512 1024 )
THREADS_PER_BLOCK=( 16 64 256 1024 )
AVG_TIMES=10
FIXED_MATRIX=1024
FIXED_BLOCK_SIZE=256
MATRIX_FOR_TABLE=1024
AVG_TIMES_O=$AVG_TIMES
let AVG_TIMES=AVG_TIMES-1
# commands for each program compilation and its output files
if [ $CUDA -eq 0 ]
then
programs=( 'c99 MatrixCPU.c -o output/out' 'c99 MatrixGPUGlobal.c -o output/out' 'c99 MatrixGPUShared.c -o output/out' 'c99 MatrixGPUGlobal.c -o output/out' 'c99 MatrixGPUShared.c -o output/out')
else
programs=( 'c99 MatrixCPU.c -o output/out' 'nvcc MatrixGPUGlobal.cu -o output/out -Wno-deprecated-gpu-targets' 'nvcc MatrixGPUShared.cu -o output/out -Wno-deprecated-gpu-targets' 'nvcc MatrixGPUGlobal.cu -o output/out -Wno-deprecated-gpu-targets' 'nvcc MatrixGPUShared.cu -o output/out -Wno-deprecated-gpu-targets')
fi
outputfiles=('output/datafile0.dat' 'output/datafile1.dat' 'output/datafile2.dat' 'output/datafile3.dat' 'output/datafile4.dat')
echo ""
echo "This script will create ${#outputfiles[@]} datafiles"
echo ""
# Remove if outputfile exists otherwise create
function createOrEmpty {
if [ -e $1 ]
then
rm -rf $1
touch $1
else
touch $1
fi
}
GRAPHS=($(seq 1 ${#programs[@]}))
for g in "${GRAPHS[@]}"
do
:
if [ $g -lt 4 ]
then
outputfile="${outputfiles[$g-1]}"
program="${programs[$g-1]}"
createOrEmpty $outputfile
echo ""
echo "---------- [STAGE 1] generating data for $outputfile ----------"
echo ""
for i in "${SIZES[@]}"
do
:
TIMES=($(seq 0 $AVG_TIMES))
total="0"
echo "N=$i"
for j in "${TIMES[@]}"
do
:
eval $program
resp=$(./output/out $i $FIXED_BLOCK_SIZE)
total=$(bc <<< "scale=10; $total+$resp")
echo "# iteration=$j T=$resp"
done
avg=$(bc <<< "scale=10; $total/${#TIMES[@]}")
printf "( $i, $avg )\n" >> $outputfile
echo "T avg. = $avg"
if [ $i -eq $MATRIX_FOR_TABLE ]
then
printf "%s" $avg > output/meta_tablematrix_$g.dat
fi
done
echo "Written data to $outputfile"
fi
done
# threads per block -----------------
GRAPHS=($(seq 4 ${#programs[@]}))
for g in "${GRAPHS[@]}"
do
:
outputfile="${outputfiles[$g-1]}"
program="${programs[$g-1]}"
createOrEmpty $outputfile
echo ""
echo "---------- [STAGE 2] generating data for $outputfile ----------"
echo ""
for i in "${THREADS_PER_BLOCK[@]}"
do
:
TIMES=($(seq 0 $AVG_TIMES))
total="0"
echo "TPB=$i"
for j in "${TIMES[@]}"
do
:
eval $program
resp=$(./output/out $FIXED_MATRIX $i)
total=$(bc <<< "scale=10; $total+$resp")
echo "# iteration=$j T=$resp"
done
avg=$(bc <<< "scale=10; $total/${#TIMES[@]}")
printf "( $i, $avg )\n" >> $outputfile
echo "T avg. = $avg"
done
echo "Written data to $outputfile"
done
echo ""
echo "Processing completed. Now executing report.sh"
echo ""
# Save metadata
printf "%s " "${SIZES[@]}" > output/meta_sizes.dat
printf "%s " "${THREADS_PER_BLOCK[@]}" > output/meta_block.dat
printf "%s " "${AVG_TIMES_O}" > output/meta_avg.dat
printf "%s " "${FIXED_MATRIX}" > output/meta_fixedmatrix.dat
printf "%s " "${FIXED_BLOCK_SIZE}" > output/meta_fixedblock.dat
printf "%s " "${MATRIX_FOR_TABLE}" > output/meta_tablematrixsize.dat
bash report.sh
bash report.sh