1 | #!/bin/bash - |
---|
2 | |
---|
3 | false=0; true=1 |
---|
4 | |
---|
5 | # Usage: arch [ hostname ] returns hostname, cores, startcore |
---|
6 | # |
---|
7 | # Define machine architecture based on starting socket, CPUs (cores) per socket, number of |
---|
8 | # sockets, has hyperthreading. |
---|
9 | |
---|
10 | start=0 |
---|
11 | |
---|
12 | arch() { |
---|
13 | hostname=${1:-`hostname`} # return value |
---|
14 | hashyper=${true} # assume machine has hyperthreads |
---|
15 | if [ "${hostname}" = "plg2" ] ; then |
---|
16 | startsocket=${start} |
---|
17 | cps=16 # coresPerSocket |
---|
18 | sockets=2 |
---|
19 | hashyper=${false} # has no hyperthreads |
---|
20 | elif [ "${hostname}" = "nasus" ] ; then |
---|
21 | startsocket=${start} |
---|
22 | cps=64 # coresPerSocket |
---|
23 | sockets=2 |
---|
24 | elif [ "${hostname}" = "pyke" ] ; then |
---|
25 | startsocket=${start} |
---|
26 | cps=24 # coresPerSocket |
---|
27 | sockets=2 |
---|
28 | elif [ "${hostname}" = "jax" ] ; then |
---|
29 | startsocket=${start} |
---|
30 | cps=24 # coresPerSocket |
---|
31 | sockets=4 |
---|
32 | else |
---|
33 | echo "unsupported host" ${hostname} |
---|
34 | exit 1 |
---|
35 | fi |
---|
36 | cores=$(( ${cps} * ${sockets} )) |
---|
37 | startcore=$(( ${startsocket} * ${cps} )) |
---|
38 | } |
---|
39 | |
---|
40 | # Usage: affinity (global cps, sockets, startsocket, hashyper, cores, startcore, wrap) |
---|
41 | # returns taskset argument |
---|
42 | # |
---|
43 | # This routine assumes hyperthreading has only 2 hyperthreads per core. |
---|
44 | # |
---|
45 | # If hyperthread scanning is used: processor units are assigned across the low-number hyperthreads |
---|
46 | # of the socket's cores. When the low-number hyperthreads are filled, the high-number hyperhtreads |
---|
47 | # are assigned across the socket's cores. Then the next socket is assigned. |
---|
48 | # |
---|
49 | # If hyperthread wrapping is used: processor units are assigned in low/high-number pairs of |
---|
50 | # hyperthreads across the socket's cores. Then the next socket is assigned. |
---|
51 | |
---|
52 | wrap=${false} # set to control hyperthread assignment across socket cores |
---|
53 | |
---|
54 | affinity() { |
---|
55 | if [ ${wrap} -eq ${true} -a ${hashyper} -eq ${false} ] ; then |
---|
56 | echo "architecture does not support hyperthreading for wrapping" |
---|
57 | exit 1 |
---|
58 | fi |
---|
59 | taskset="" # return value |
---|
60 | set -- $(( ${1} - 1 )) # decrement $1 |
---|
61 | if [ ${1} -eq 0 ] ; then taskset="${startcore}-${startcore}"; return; fi |
---|
62 | if [ ${1} -ge $(( ${cps} * ( ${sockets} - ${startsocket} ) * ( ${hashyper} + 1 ) )) ] ; then # error |
---|
63 | echo "not enough cores $(( ${cores} * ${sockets} )) for $(( ${1} + 1 )) starting at ${startcore}" |
---|
64 | exit 1 |
---|
65 | fi |
---|
66 | if [ ${hashyper} -eq ${false} ] ; then taskset="${startcore}-$(( ${1} + ${startcore} ))"; return; fi # no hyperthreads |
---|
67 | start2=$(( ${startcore} + ${cores} )) |
---|
68 | if [ ${wrap} -eq ${true} ] ; then # hyperthread wrapping |
---|
69 | end1=$(( ${1} / 2 + ${startcore} )) |
---|
70 | end2=$(( ${end1} + ${cores} )) |
---|
71 | if [ $(( ${1} % 2 )) -eq 0 ] ; then |
---|
72 | end2=$(( ${end2} - 1 )) |
---|
73 | fi |
---|
74 | taskset="${startcore}-${end1},${start2}-${end2}" |
---|
75 | else # hyperthread scanning |
---|
76 | if [ ${1} -lt ${cps} ] ; then taskset="${startcore}-$(( ${1} + ${startcore} ))"; return; fi |
---|
77 | filled=$(( ${1} / ( ${cps} * 2 ) * ${cps} )) |
---|
78 | modulus=$(( ${1} % ( ${cps} * 2 ) )) # leftover cores added to saturated sockets |
---|
79 | if [ ${modulus} -gt ${cps} ] ; then |
---|
80 | taskset="${startcore}-$(( ${startcore} + ${filled} + ${cps} - 1 )),${start2}-$(( ${start2} + ${filled} + ${modulus} % ${cps} ))" |
---|
81 | else |
---|
82 | taskset="${startcore}-$(( ${startcore} + ${filled} + ${modulus} )),${start2}-$(( ${start2} + ${filled} - 1 ))" |
---|
83 | fi |
---|
84 | fi |
---|
85 | } |
---|
86 | |
---|
87 | numtimes=11 |
---|
88 | |
---|
89 | # locks=('-DLOCKS=L1' '-DLOCKS=L2' '-DLOCKS=L3' '-DLOCKS=L4' '-DLOCKS=L5' '-DLOCKS=L6' '-DLOCKS=L7' '-DLOCKS=L8') |
---|
90 | # locks='1 2 3 4 5 6 7 8' |
---|
91 | lock_flags=('-DLOCKS=L2' '-DLOCKS=L4' '-DLOCKS=L8') |
---|
92 | locks=('2' '4' '8') |
---|
93 | |
---|
94 | num_threads='2 4 8 16 24 32' |
---|
95 | # num_threads='2 4 8' |
---|
96 | |
---|
97 | # toggle benchmarks |
---|
98 | order=${true} |
---|
99 | rand=${true} |
---|
100 | baseline=${true} |
---|
101 | |
---|
102 | runCFA=${true} |
---|
103 | runCPP=${true} |
---|
104 | # runCFA=${false} |
---|
105 | # runCPP=${false} |
---|
106 | |
---|
107 | cfa=~/cfa-cc/driver/cfa |
---|
108 | cpp=g++ |
---|
109 | |
---|
110 | # Helpers to minimize code duplication |
---|
111 | |
---|
112 | # repeats a command ${numtimes} |
---|
113 | preprint='' |
---|
114 | repeat_command() { |
---|
115 | t=1 |
---|
116 | while [ ${t} -le ${numtimes} ] ; do |
---|
117 | echo -n -e ${preprint} |
---|
118 | "${@}" |
---|
119 | t=`expr ${t} + 1` |
---|
120 | done |
---|
121 | } |
---|
122 | |
---|
123 | # prints the leading info for a given run of a variant |
---|
124 | print_header() { |
---|
125 | echo ${1}':' |
---|
126 | echo -e "cores\tthroughput (entries)" |
---|
127 | } |
---|
128 | |
---|
129 | # runs the current benchmark with provided args |
---|
130 | # only works for standard-run benchmarks (not Akka) |
---|
131 | # must split into pre and post args to be able to supply val of p |
---|
132 | pre_args='' |
---|
133 | post_args='' |
---|
134 | single_run() { |
---|
135 | affinity ${1} |
---|
136 | preprint="${1}\t" |
---|
137 | repeat_command taskset -c ${taskset} ./a.${hostname} ${pre_args} ${1} ${post_args} |
---|
138 | } |
---|
139 | |
---|
140 | # runs the current bench for all processor vals |
---|
141 | # works for standard benchs that dont need to set a config file (not Akka or CAF) |
---|
142 | run_bench() { |
---|
143 | for p in ${num_threads} ; do |
---|
144 | single_run ${p} |
---|
145 | done |
---|
146 | } |
---|
147 | |
---|
148 | arch # get hostname |
---|
149 | |
---|
150 | # set up leading info for python script |
---|
151 | echo $numtimes |
---|
152 | echo $num_threads |
---|
153 | |
---|
154 | for i in ${!locks[@]}; do |
---|
155 | echo -n ${locks[$i]}' ' |
---|
156 | done |
---|
157 | echo "" |
---|
158 | |
---|
159 | if [ ${runCFA} -eq ${true} ] ; then |
---|
160 | if [ ${order} -eq ${true} ] ; then |
---|
161 | echo -n 'CFA-order ' |
---|
162 | fi |
---|
163 | if [ ${baseline} -eq ${true} ] ; then |
---|
164 | echo -n 'CFA-baseline ' |
---|
165 | fi |
---|
166 | if [ ${rand} -eq ${true} ] ; then |
---|
167 | echo -n 'CFA-rand ' |
---|
168 | fi |
---|
169 | fi # done CFA |
---|
170 | if [ ${runCPP} -eq ${true} ] ; then |
---|
171 | if [ ${order} -eq ${true} ] ; then |
---|
172 | echo -n 'CPP-order ' |
---|
173 | fi |
---|
174 | if [ ${baseline} -eq ${true} ] ; then |
---|
175 | echo -n 'CPP-baseline ' |
---|
176 | fi |
---|
177 | if [ ${rand} -eq ${true} ] ; then |
---|
178 | echo -n 'CPP-rand ' |
---|
179 | fi |
---|
180 | fi # done CPP |
---|
181 | echo "" |
---|
182 | |
---|
183 | # done printing header info for output |
---|
184 | |
---|
185 | # cfa flags |
---|
186 | cfa_flags='-quiet -O3 -nodebug -DNDEBUG' |
---|
187 | |
---|
188 | # cpp flagse |
---|
189 | cpp_flags='-O3 -std=c++17 -lpthread -pthread -DNDEBUG' |
---|
190 | |
---|
191 | # run the benchmarks |
---|
192 | |
---|
193 | run_order() { |
---|
194 | echo "locks: "${1} |
---|
195 | post_args=${1} |
---|
196 | |
---|
197 | if [ ${runCFA} -eq ${true} ] ; then |
---|
198 | cd cfa # CFA RUN |
---|
199 | print_header 'CFA-'${3} |
---|
200 | ${cfa} ${cfa_flags} ${2} ${3}.cfa -o a.${hostname} > /dev/null 2>&1 |
---|
201 | run_bench |
---|
202 | rm a.${hostname} |
---|
203 | cd - > /dev/null |
---|
204 | fi # done CFA |
---|
205 | |
---|
206 | if [ ${runCPP} -eq ${true} ] ; then |
---|
207 | cd cpp # CPP RUN |
---|
208 | print_header 'CPP-'${3} |
---|
209 | ${cpp} ${cpp_flags} ${2} ${3}.cc -o a.${hostname} > /dev/null 2>&1 |
---|
210 | run_bench |
---|
211 | rm a.${hostname} |
---|
212 | cd - > /dev/null |
---|
213 | fi # done CPP |
---|
214 | } |
---|
215 | |
---|
216 | # /usr/bin/time -f "%Uu %Ss %Er %Mkb" |
---|
217 | |
---|
218 | for i in ${!locks[@]}; do |
---|
219 | if [ ${order} -eq ${true} ] ; then |
---|
220 | run_order ${locks[$i]} ${lock_flags[$i]} 'order' |
---|
221 | fi |
---|
222 | if [ ${baseline} -eq ${true} ] ; then |
---|
223 | run_order ${locks[$i]} ${lock_flags[$i]} 'baseline' |
---|
224 | fi |
---|
225 | if [ ${rand} -eq ${true} ] ; then |
---|
226 | run_order ${locks[$i]} '-DLOCKS=L8' 'rand' |
---|
227 | fi |
---|
228 | done |
---|
229 | |
---|
230 | |
---|