SiCong Li | 8b4c730 | 2019-09-19 12:18:15 +0100 | [diff] [blame] | 1 | # Copyright (c) 2019 ARM Limited. |
| 2 | # |
| 3 | # SPDX-License-Identifier: MIT |
| 4 | # |
| 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | # of this software and associated documentation files (the "Software"), to |
| 7 | # deal in the Software without restriction, including without limitation the |
| 8 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 9 | # sell copies of the Software, and to permit persons to whom the Software is |
| 10 | # furnished to do so, subject to the following conditions: |
| 11 | # |
| 12 | # The above copyright notice and this permission notice shall be included in all |
| 13 | # copies or substantial portions of the Software. |
| 14 | # |
| 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 | # SOFTWARE. |
| 22 | |
| 23 | #!/bin/sh |
| 24 | |
| 25 | # Global: Global variables and global settings {{{ |
| 26 | # Treat unset variables as an error when substituting |
| 27 | set -u |
| 28 | |
| 29 | CMD=$( basename $0 ) |
| 30 | |
| 31 | # All supported strategy options |
SiCong Li | ea80348 | 2019-09-26 16:55:49 +0100 | [diff] [blame] | 32 | ALL_STRATEGY_OPTIONS=("native" "reshaped_rhs_only" "reshaped") |
SiCong Li | 8b4c730 | 2019-09-19 12:18:15 +0100 | [diff] [blame] | 33 | |
| 34 | # Names of example binary for each strategy |
SiCong Li | ea80348 | 2019-09-26 16:55:49 +0100 | [diff] [blame] | 35 | EXAMPLE_BIN_NATIVE="benchmark_cl_gemm_native" |
SiCong Li | 8b4c730 | 2019-09-19 12:18:15 +0100 | [diff] [blame] | 36 | EXAMPLE_BIN_RESHAPED_RHS_ONLY="benchmark_cl_gemm_reshaped_rhs_only" |
SiCong Li | bc166d5 | 2019-09-26 14:58:53 +0100 | [diff] [blame] | 37 | EXAMPLE_BIN_RESHAPED="benchmark_cl_gemm_reshaped" |
SiCong Li | 8b4c730 | 2019-09-19 12:18:15 +0100 | [diff] [blame] | 38 | |
| 39 | # Default output directory |
| 40 | DEFAULT_OUT_DIR="out" |
| 41 | |
| 42 | # Number of iterations for each benchmark run |
SiCong Li | bc166d5 | 2019-09-26 14:58:53 +0100 | [diff] [blame] | 43 | NUM_ITERATION=5 |
SiCong Li | 8b4c730 | 2019-09-19 12:18:15 +0100 | [diff] [blame] | 44 | # Global }}} |
| 45 | |
| 46 | # Functions {{{ |
| 47 | ####################################### |
| 48 | # Print gemm shape file help message |
| 49 | # Globals: |
| 50 | # None |
| 51 | # Arguments: |
| 52 | # None |
| 53 | # Returns: |
| 54 | # None |
| 55 | ####################################### |
| 56 | function help_gemm_shape_file() { |
| 57 | cat >&2 << EOF |
| 58 | Gemm shape file: |
| 59 | Gemm shape file is a headerless csv file with fields separated by commas and commas only (there cannot be whitespaces |
| 60 | around each field). |
SiCong Li | 8abbabd | 2020-04-03 12:39:41 +0100 | [diff] [blame] | 61 | |
| 62 | Note also comments and extraneous empty lines are not permitted. |
| 63 | |
SiCong Li | 8b4c730 | 2019-09-19 12:18:15 +0100 | [diff] [blame] | 64 | A gemm shape is a list of 4 positive integers <M, N, K, B> describing the shapes of the two matrices (LHS and RHS) |
| 65 | with: |
| 66 | M - Number of lhs matrix rows |
| 67 | N - Number of rhs matrix columns |
| 68 | K - Number of lhs matrix columns/rhs matrix rows |
| 69 | B - Batch size |
| 70 | |
| 71 | An example gemm shape file looks like: |
| 72 | 100,100,30,1 |
| 73 | 100,100,30,3 |
| 74 | ... |
| 75 | |
| 76 | EOF |
| 77 | } |
| 78 | |
| 79 | ####################################### |
SiCong Li | ea80348 | 2019-09-26 16:55:49 +0100 | [diff] [blame] | 80 | # Print gemm config file for native help message |
| 81 | # Globals: |
| 82 | # None |
| 83 | # Arguments: |
| 84 | # None |
| 85 | # Returns: |
| 86 | # None |
| 87 | ####################################### |
| 88 | function help_gemm_config_file_native() { |
| 89 | cat >&2 << EOF |
| 90 | Gemm config file (Strategy native): |
| 91 | Gemm config file is a headerless csv file with fields separated by commas and commas only (there cannot be whitespaces |
| 92 | around each field). |
SiCong Li | 8abbabd | 2020-04-03 12:39:41 +0100 | [diff] [blame] | 93 | |
| 94 | Note also comments and extraneous empty lines are not permitted. |
| 95 | |
| 96 | A gemm config is a list of 3 positive integers <m0, n0, k0>, with: |
SiCong Li | ea80348 | 2019-09-26 16:55:49 +0100 | [diff] [blame] | 97 | m0 - Number of rows processed by the matrix multiplication |
| 98 | n0 - Number of columns processed by the matrix multiplication |
| 99 | k0 - Number of partial accumulations performed by the matrix multiplication |
| 100 | |
| 101 | Only the following configurations of M0, N0 and K0 are currently supported: |
| 102 | M0 = 1, 2, 3, 4, 5, 6, 7, 8 |
| 103 | N0 = 2, 3, 4, 8, 16 |
| 104 | K0 = 2, 3, 4, 8, 16 |
| 105 | |
| 106 | An example gemm config file looks like: |
| 107 | 1,4,4 |
| 108 | 2,3,8 |
| 109 | ... |
| 110 | |
| 111 | EOF |
| 112 | } |
| 113 | |
| 114 | ####################################### |
SiCong Li | bc166d5 | 2019-09-26 14:58:53 +0100 | [diff] [blame] | 115 | # Print gemm config file for reshaped_rhs_only help message |
SiCong Li | 8b4c730 | 2019-09-19 12:18:15 +0100 | [diff] [blame] | 116 | # Globals: |
| 117 | # None |
| 118 | # Arguments: |
| 119 | # None |
| 120 | # Returns: |
| 121 | # None |
| 122 | ####################################### |
| 123 | function help_gemm_config_file_reshaped_rhs_only() { |
| 124 | cat >&2 << EOF |
| 125 | Gemm config file (Strategy reshaped_rhs_only): |
| 126 | Gemm config file is a headerless csv file with fields separated by commas and commas only (there cannot be whitespaces |
| 127 | around each field). |
SiCong Li | 8abbabd | 2020-04-03 12:39:41 +0100 | [diff] [blame] | 128 | |
| 129 | Note also comments and extraneous empty lines are not permitted. |
| 130 | |
SiCong Li | 8b4c730 | 2019-09-19 12:18:15 +0100 | [diff] [blame] | 131 | A gemm config is a list of 4 positive integers <m0, n0, k0, h0> and 2 boolean values interleave_rhs and transpose_rhs, with: |
| 132 | m0 - Number of rows processed by the matrix multiplication |
| 133 | n0 - Number of columns processed by the matrix multiplication |
| 134 | k0 - Number of partial accumulations performed by the matrix multiplication |
| 135 | h0 - Number of horizontal blocks of size (k0xn0) stored on the same output row |
| 136 | interleave_rhs - Interleave rhs matrix (1) / Do not interleave rhs matrix (0) |
SiCong Li | bc166d5 | 2019-09-26 14:58:53 +0100 | [diff] [blame] | 137 | transpose_rhs - Transpose rhs matrix (1) / Do not transpose rhs matrix (0) |
SiCong Li | 8b4c730 | 2019-09-19 12:18:15 +0100 | [diff] [blame] | 138 | |
| 139 | Only the following configurations of M0, N0 and K0 are currently supported: |
| 140 | M0 = 1, 2, 3, 4, 5, 6, 7, 8 |
| 141 | N0 = 2, 3, 4, 8, 16 |
| 142 | K0 = 2, 3, 4, 8, 16 |
| 143 | H0 >= 1 |
| 144 | |
| 145 | An example gemm config file looks like: |
SiCong Li | bc166d5 | 2019-09-26 14:58:53 +0100 | [diff] [blame] | 146 | 4,4,4,1,1,1 |
| 147 | 4,4,4,3,1,0 |
| 148 | ... |
| 149 | |
| 150 | EOF |
| 151 | } |
| 152 | |
| 153 | ####################################### |
| 154 | # Print gemm config file for reshaped help message |
| 155 | # Globals: |
| 156 | # None |
| 157 | # Arguments: |
| 158 | # None |
| 159 | # Returns: |
| 160 | # None |
| 161 | ####################################### |
| 162 | function help_gemm_config_file_reshaped() { |
| 163 | cat >&2 << EOF |
| 164 | Gemm config file (Strategy reshaped): |
| 165 | Gemm config file is a headerless csv file with fields separated by commas and commas only (there cannot be whitespaces |
| 166 | around each field). |
SiCong Li | 8abbabd | 2020-04-03 12:39:41 +0100 | [diff] [blame] | 167 | |
| 168 | Note also comments and extraneous empty lines are not permitted. |
| 169 | |
SiCong Li | bc166d5 | 2019-09-26 14:58:53 +0100 | [diff] [blame] | 170 | A gemm config is a list of 5 positive integers <m0, n0, k0, v0, h0> and 3 boolean values interleave_lhs, interleave_rhs and transpose_rhs, with: |
| 171 | m0 - Number of rows processed by the matrix multiplication |
| 172 | n0 - Number of columns processed by the matrix multiplication |
| 173 | k0 - Number of partial accumulations performed by the matrix multiplication |
| 174 | v0 - Number of vertical blocks of size (m0xk0) stored on the same output row |
| 175 | h0 - Number of horizontal blocks of size (k0xn0) stored on the same output row |
| 176 | interleave_lhs - Interleave lhs matrix (1) / Do not interleave lhs matrix (0) |
| 177 | interleave_rhs - Interleave rhs matrix (1) / Do not interleave rhs matrix (0) |
| 178 | transpose_rhs - Transpose rhs matrix but not lhs matrix (1) / Do not transpose rhs matrix but do transpose lhs matrix (0) |
| 179 | |
| 180 | If rhs matrix is transposed only the following configurations are currently supported: |
| 181 | M0 = 2, 3, 4, 5, 6, 7, 8 |
| 182 | N0 = 2, 3, 4, 8, 16 |
| 183 | K0 = 2, 3, 4, 8, 16 |
| 184 | V0 >= 1 |
| 185 | H0 >= 1 |
| 186 | |
| 187 | If lhs matrix is transposed only the following configurations are currently supported: |
| 188 | M0 = 2, 3, 4, 8 |
| 189 | N0 = 2, 3, 4, 8, 16 |
| 190 | K0 = 2, 3, 4, 8, 16 |
| 191 | V0 >= 1 |
| 192 | H0 >= 1 |
| 193 | |
| 194 | An example gemm config file looks like: |
| 195 | 4,4,4,1,3,1,1,1 |
| 196 | 4,4,4,3,3,1,1,0 |
SiCong Li | 8b4c730 | 2019-09-19 12:18:15 +0100 | [diff] [blame] | 197 | ... |
| 198 | |
| 199 | EOF |
| 200 | } |
| 201 | |
| 202 | ####################################### |
| 203 | # Print usage of this program and exit with Error |
| 204 | # Globals: |
| 205 | # Assumes all globals are required |
| 206 | # Arguments: |
| 207 | # None |
| 208 | # Returns: |
| 209 | # Error(1) |
| 210 | ####################################### |
| 211 | function usage() { |
| 212 | cat >&2 << EOF |
| 213 | Run gemm examples of a selected strategy, over provided tunable configurationsa and gemm shapes. |
| 214 | Save the benchmark results to json files in an output directory. |
| 215 | |
SiCong Li | bc166d5 | 2019-09-26 14:58:53 +0100 | [diff] [blame] | 216 | Usage: ${CMD} [-h] -s <strategy> -e <example_binary_dir> -g <gemm_shape_file> -c <gemm_config_file> [-o <out_dir>] |
SiCong Li | 8b4c730 | 2019-09-19 12:18:15 +0100 | [diff] [blame] | 217 | |
| 218 | Options: |
| 219 | -h |
SiCong Li | bc166d5 | 2019-09-26 14:58:53 +0100 | [diff] [blame] | 220 | Print help messages. If a strategy is specified with -s <strategy>, then only display messages relevant to that |
| 221 | strategy. Otherwise if no strategy is specified, display messages for all available strategies. |
| 222 | |
| 223 | -s <strategy> |
| 224 | Strategy option. |
| 225 | Options: ${ALL_STRATEGY_OPTIONS[@]}. |
SiCong Li | 8b4c730 | 2019-09-19 12:18:15 +0100 | [diff] [blame] | 226 | |
| 227 | -e <example_binary_dir> |
| 228 | Path to directory that holds all example binaries |
| 229 | |
| 230 | -g <gemm_shape_file> |
| 231 | Path to gemm shape csv file |
| 232 | |
| 233 | -c <gemm_config_file> |
| 234 | Path to gemm config csv file |
| 235 | |
SiCong Li | 8b4c730 | 2019-09-19 12:18:15 +0100 | [diff] [blame] | 236 | -o <out_dir> |
| 237 | Path to output directory that holds output json files |
| 238 | Default: ${DEFAULT_OUT_DIR} |
| 239 | |
| 240 | EOF |
| 241 | # Print help messages about gemm shapes and various gemm configs |
| 242 | $HELP && help_gemm_shape_file |
SiCong Li | ea80348 | 2019-09-26 16:55:49 +0100 | [diff] [blame] | 243 | $HELP && ( [ "${STRATEGY_OPTION}" == "" ] || [ "${STRATEGY_OPTION}" == "native" ] ) && help_gemm_config_file_native |
SiCong Li | 8b4c730 | 2019-09-19 12:18:15 +0100 | [diff] [blame] | 244 | $HELP && ( [ "${STRATEGY_OPTION}" == "" ] || [ "${STRATEGY_OPTION}" == "reshaped_rhs_only" ] ) && help_gemm_config_file_reshaped_rhs_only |
SiCong Li | bc166d5 | 2019-09-26 14:58:53 +0100 | [diff] [blame] | 245 | $HELP && ( [ "${STRATEGY_OPTION}" == "" ] || [ "${STRATEGY_OPTION}" == "reshaped" ] ) && help_gemm_config_file_reshaped |
SiCong Li | 8b4c730 | 2019-09-19 12:18:15 +0100 | [diff] [blame] | 246 | exit 1 |
| 247 | } |
| 248 | |
| 249 | ####################################### |
| 250 | # Print error message and exit with Error. |
| 251 | # Globals: |
| 252 | # None |
| 253 | # Arguments: |
| 254 | # $1 - Error message |
| 255 | # Returns: |
| 256 | # None |
| 257 | ####################################### |
| 258 | function error_msg() { |
| 259 | echo "Error: $1" 1>&2 |
| 260 | exit 1 |
| 261 | } |
| 262 | |
| 263 | ####################################### |
| 264 | # Convert string to lower-case |
| 265 | # Globals: |
| 266 | # None |
| 267 | # Arguments: |
| 268 | # target - String |
| 269 | # Returns: |
| 270 | # (stdout) - String in lowercase |
| 271 | ####################################### |
| 272 | function to_lower() { |
| 273 | local target=$1 |
| 274 | echo "$target" | tr '[:upper:]' '[:lower:]' |
| 275 | } |
| 276 | |
| 277 | ####################################### |
| 278 | # Test if the argument is an integer |
| 279 | # Globals: |
| 280 | # None |
| 281 | # Arguments: |
| 282 | # in - Input |
| 283 | # Returns: |
| 284 | # true/false |
| 285 | ####################################### |
| 286 | function is_integer() { |
| 287 | local in=$1 |
| 288 | [ "$in" -eq "$in" ] 2> /dev/null |
| 289 | } |
| 290 | |
| 291 | ####################################### |
SiCong Li | bc166d5 | 2019-09-26 14:58:53 +0100 | [diff] [blame] | 292 | # Test if a string is in an array of strings |
| 293 | # Globals: |
| 294 | # None |
| 295 | # Arguments: |
| 296 | # target - String to test |
| 297 | # array - Array of strings to search |
| 298 | # Returns: |
| 299 | # true/false |
| 300 | ####################################### |
| 301 | function arr_contains() { |
| 302 | local target=$1 |
| 303 | shift |
| 304 | local array |
| 305 | array=("$@") |
| 306 | for s in "${array[@]}" |
| 307 | do |
| 308 | [ "$s" == "${target}" ] && return |
| 309 | done |
| 310 | false |
| 311 | } |
| 312 | |
| 313 | ####################################### |
SiCong Li | e36b526 | 2019-10-01 19:26:00 +0100 | [diff] [blame] | 314 | # Run a single example with all tunable gemm configurations on all gemm parameters |
SiCong Li | 8b4c730 | 2019-09-19 12:18:15 +0100 | [diff] [blame] | 315 | # Globals: |
| 316 | # OUT_DIR |
SiCong Li | e36b526 | 2019-10-01 19:26:00 +0100 | [diff] [blame] | 317 | # OUT_EXTENSION |
SiCong Li | 8b4c730 | 2019-09-19 12:18:15 +0100 | [diff] [blame] | 318 | # EXAMPLE_BIN_DIR |
| 319 | # NUM_ITERATION |
| 320 | # GEMM_CONFIGS_FILE |
| 321 | # GEMM_SHAPES_FILE |
| 322 | # Arguments: |
| 323 | # example_bin Name of the example binary to run |
| 324 | # Returns: |
| 325 | # None |
| 326 | ####################################### |
| 327 | function run() { |
| 328 | local example_bin=$1 |
| 329 | echo "Running all configs for ${example_bin}" 1>&2 |
| 330 | local example_args |
SiCong Li | e36b526 | 2019-10-01 19:26:00 +0100 | [diff] [blame] | 331 | local expr_count=1 |
| 332 | # Total number of experiment runs scheduled for this session |
| 333 | local total_num_experiment |
| 334 | local num_params |
| 335 | local num_configs |
| 336 | num_params=$( wc -l ${GEMM_SHAPES_FILE} | cut -d " " -f 1) |
| 337 | num_configs=$( wc -l ${GEMM_CONFIGS_FILE} | cut -d " " -f 1 ) |
| 338 | (( total_num_experiment=${num_params} * ${num_configs} )) |
| 339 | # Time elapsed since the beginning in seconds |
| 340 | local time_elapsed_s |
| 341 | # Time estimated to finish in seconds |
| 342 | local time_est_s |
| 343 | echo "Running a total number of ${total_num_experiment} experiments" 1>&2 |
| 344 | |
SiCong Li | 8b4c730 | 2019-09-19 12:18:15 +0100 | [diff] [blame] | 345 | while read gemm_shape |
| 346 | do |
| 347 | while read gemm_config |
| 348 | do |
SiCong Li | e36b526 | 2019-10-01 19:26:00 +0100 | [diff] [blame] | 349 | echo "Running..." 1>&2 |
SiCong Li | 8b4c730 | 2019-09-19 12:18:15 +0100 | [diff] [blame] | 350 | example_args="${gemm_shape},${gemm_config}" |
SiCong Li | e36b526 | 2019-10-01 19:26:00 +0100 | [diff] [blame] | 351 | # Run experiment |
| 352 | ${EXAMPLE_BIN_DIR}/${example_bin} --example_args=${example_args} --iterations=${NUM_ITERATION} --json-file=${OUT_DIR}/${expr_count}.${OUT_EXTENSION} --instruments=OPENCL_TIMER_MS |
| 353 | # Print progress |
| 354 | print_progress ${expr_count} ${total_num_experiment} |
| 355 | # Print time statistics |
| 356 | time_elapsed_s=$SECONDS |
| 357 | echo "Time elapsed since beginning: $(( $time_elapsed_s / 60 ))m $(( $time_elapsed_s % 60 ))s" 1>&2 |
| 358 | (( time_est_s=(${total_num_experiment} - ${expr_count}) * ${time_elapsed_s} / ${expr_count} )) |
| 359 | echo "Time estimated to finish: $(( $time_est_s / 60 ))m $(( $time_est_s % 60 ))s" 1>&2 |
| 360 | (( expr_count++ )) |
| 361 | echo "Done." 1>&2 |
SiCong Li | 8b4c730 | 2019-09-19 12:18:15 +0100 | [diff] [blame] | 362 | done < "${GEMM_CONFIGS_FILE}" |
| 363 | done < "${GEMM_SHAPES_FILE}" |
| 364 | echo "Finished running all configs for ${example_bin}" 1>&2 |
| 365 | echo "All results saved to ${OUT_DIR}" 1>&2 |
| 366 | } |
| 367 | |
SiCong Li | e36b526 | 2019-10-01 19:26:00 +0100 | [diff] [blame] | 368 | ####################################### |
| 369 | # Print the progress of the current session |
| 370 | # Globals: |
| 371 | # None |
| 372 | # Arguments: |
| 373 | # current Current number of items |
| 374 | # total Total number of items |
| 375 | # Returns: |
| 376 | # None |
| 377 | ####################################### |
| 378 | function print_progress() { |
| 379 | local current |
| 380 | local total |
| 381 | current=$1 |
| 382 | total=$2 |
| 383 | # Width of progress bar |
| 384 | local width |
| 385 | width=20 |
| 386 | (( current_width= $width * current / total )) |
| 387 | echo -n -e "Progress [" 1>&2 |
| 388 | for i in $(seq 1 ${width}); do |
| 389 | if [[ $i -le ${current_width} ]]; then |
| 390 | echo -n "#" 1>&2 |
| 391 | else |
| 392 | echo -n " " 1>&2 |
| 393 | fi |
| 394 | done |
| 395 | echo "] $current / $total Experiments" 1>&2 |
| 396 | } |
| 397 | |
SiCong Li | 8b4c730 | 2019-09-19 12:18:15 +0100 | [diff] [blame] | 398 | # Functions }}} |
| 399 | |
| 400 | # Main: Main script {{{ |
| 401 | # Path to directory containing all benchmark examples binaries |
| 402 | EXAMPLE_BIN_DIR="" |
| 403 | # Path to gemm shapes file |
| 404 | GEMM_SHAPES_FILE="" |
| 405 | # Path to gemm configs file |
| 406 | GEMM_CONFIGS_FILE="" |
SiCong Li | bc166d5 | 2019-09-26 14:58:53 +0100 | [diff] [blame] | 407 | STRATEGY_OPTION="" |
SiCong Li | 8b4c730 | 2019-09-19 12:18:15 +0100 | [diff] [blame] | 408 | # Path to output directory |
| 409 | OUT_DIR=${DEFAULT_OUT_DIR} |
SiCong Li | e36b526 | 2019-10-01 19:26:00 +0100 | [diff] [blame] | 410 | # Output benchmark result file extension |
| 411 | OUT_EXTENSION="gemmtuner_benchmark" |
SiCong Li | 8b4c730 | 2019-09-19 12:18:15 +0100 | [diff] [blame] | 412 | # Toggle help |
| 413 | HELP=false |
| 414 | |
| 415 | # Obtain options |
SiCong Li | bc166d5 | 2019-09-26 14:58:53 +0100 | [diff] [blame] | 416 | while getopts "hs:e:g:c:o:" opt; do |
SiCong Li | 8b4c730 | 2019-09-19 12:18:15 +0100 | [diff] [blame] | 417 | case "$opt" in |
SiCong Li | bc166d5 | 2019-09-26 14:58:53 +0100 | [diff] [blame] | 418 | h) HELP=true ;; |
SiCong Li | 8b4c730 | 2019-09-19 12:18:15 +0100 | [diff] [blame] | 419 | s) STRATEGY_OPTION=$(to_lower "${OPTARG}");; |
SiCong Li | bc166d5 | 2019-09-26 14:58:53 +0100 | [diff] [blame] | 420 | e) EXAMPLE_BIN_DIR="${OPTARG}";; |
SiCong Li | 8b4c730 | 2019-09-19 12:18:15 +0100 | [diff] [blame] | 421 | g) GEMM_SHAPES_FILE="${OPTARG}";; |
| 422 | c) GEMM_CONFIGS_FILE="${OPTARG}";; |
| 423 | o) OUT_DIR="${OPTARG}";; |
| 424 | esac |
| 425 | done |
| 426 | shift $((OPTIND - 1)) |
| 427 | |
| 428 | # Lazily print usage (after arguments have been parsed) |
| 429 | $HELP && |
| 430 | usage |
| 431 | |
| 432 | # Parse and validate options |
SiCong Li | bc166d5 | 2019-09-26 14:58:53 +0100 | [diff] [blame] | 433 | # Verify all compulsory arguments are passed in |
| 434 | ( [ ! -z "${STRATEGY_OPTION}" ] && [ ! -z "${EXAMPLE_BIN_DIR}" ] && [ ! -z "${GEMM_SHAPES_FILE}" ] && [ ! -z "${GEMM_CONFIGS_FILE}" ] ) || |
SiCong Li | 8b4c730 | 2019-09-19 12:18:15 +0100 | [diff] [blame] | 435 | usage |
| 436 | |
| 437 | # Verify example binaries directory exists |
| 438 | [ -d "${EXAMPLE_BIN_DIR}" ] || |
| 439 | error_msg "${EXAMPLE_BIN_DIR} does not exist." |
| 440 | |
| 441 | # Verify all benchmark example binaries exist |
| 442 | [ -f "${EXAMPLE_BIN_DIR}/${EXAMPLE_BIN_RESHAPED_RHS_ONLY}" ] || |
| 443 | error_msg "Cannot find ${EXAMPLE_BIN_RESHAPED_RHS_ONLY} at ${EXAMPLE_BIN_DIR}" |
| 444 | |
| 445 | # Verify Gemm shapes file exists |
| 446 | [ -f "${GEMM_SHAPES_FILE}" ] || |
| 447 | error_msg "Cannot find gemm shapes file ${GEMM_SHAPES_FILE}" |
| 448 | |
SiCong Li | bc166d5 | 2019-09-26 14:58:53 +0100 | [diff] [blame] | 449 | # Verify Gemm configs file exists |
SiCong Li | 8b4c730 | 2019-09-19 12:18:15 +0100 | [diff] [blame] | 450 | [ -f "${GEMM_CONFIGS_FILE}" ] || |
| 451 | error_msg "Cannot find gemm configs file ${GEMM_CONFIGS_FILE}" |
| 452 | |
| 453 | # Verify strategy option is valid |
SiCong Li | bc166d5 | 2019-09-26 14:58:53 +0100 | [diff] [blame] | 454 | arr_contains "${STRATEGY_OPTION}" "${ALL_STRATEGY_OPTIONS[@]}" || |
SiCong Li | 8b4c730 | 2019-09-19 12:18:15 +0100 | [diff] [blame] | 455 | error_msg "Does not support strategy ${STRATEGY_OPTION}" |
| 456 | |
| 457 | # Make sure existing benchmark outputs are not overwritten |
| 458 | [ ! -d "${OUT_DIR}" ] || |
| 459 | error_msg "Output directory ${OUT_DIR} already exists!" |
| 460 | |
| 461 | # Make output directory |
| 462 | mkdir ${OUT_DIR} |
| 463 | |
| 464 | # Run selected strategy with all configurations |
SiCong Li | e36b526 | 2019-10-01 19:26:00 +0100 | [diff] [blame] | 465 | # Restart the built-in timer |
| 466 | SECONDS=0 |
SiCong Li | ea80348 | 2019-09-26 16:55:49 +0100 | [diff] [blame] | 467 | [ "${STRATEGY_OPTION}" == "native" ] && run $EXAMPLE_BIN_NATIVE |
SiCong Li | 8b4c730 | 2019-09-19 12:18:15 +0100 | [diff] [blame] | 468 | [ "${STRATEGY_OPTION}" == "reshaped_rhs_only" ] && run $EXAMPLE_BIN_RESHAPED_RHS_ONLY |
SiCong Li | bc166d5 | 2019-09-26 14:58:53 +0100 | [diff] [blame] | 469 | [ "${STRATEGY_OPTION}" == "reshaped" ] && run $EXAMPLE_BIN_RESHAPED |
SiCong Li | 8b4c730 | 2019-09-19 12:18:15 +0100 | [diff] [blame] | 470 | # Main: Main script }}} |