blob: a49c2e154b5de5c1649084cce5cc4c49d9fa4391 [file] [log] [blame]
Gian Marco Iodice716b1be2021-02-10 17:33:27 +00001# Copyright (c) 2019-2021 Arm Limited.
SiCong Li8b4c7302019-09-19 12:18:15 +01002#
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
27set -u
28
29CMD=$( basename $0 )
30
31# All supported strategy options
SiCong Liea803482019-09-26 16:55:49 +010032ALL_STRATEGY_OPTIONS=("native" "reshaped_rhs_only" "reshaped")
SiCong Li8b4c7302019-09-19 12:18:15 +010033
Gian Marco Iodice716b1be2021-02-10 17:33:27 +000034# All supported data type options
35ALL_DATA_TYPE_OPTIONS=("f32" "f16" "qasymm8")
36
SiCong Li8b4c7302019-09-19 12:18:15 +010037# Names of example binary for each strategy
SiCong Liea803482019-09-26 16:55:49 +010038EXAMPLE_BIN_NATIVE="benchmark_cl_gemm_native"
SiCong Li8b4c7302019-09-19 12:18:15 +010039EXAMPLE_BIN_RESHAPED_RHS_ONLY="benchmark_cl_gemm_reshaped_rhs_only"
SiCong Libc166d52019-09-26 14:58:53 +010040EXAMPLE_BIN_RESHAPED="benchmark_cl_gemm_reshaped"
SiCongLi282f3242020-11-24 15:24:16 +000041EXAMPLE_BIN_RESHAPED_RHS_ONLY_LOWP="benchmark_cl_gemmlowp_reshaped_rhs_only_fused_output_stage_fixedpoint"
42EXAMPLE_BIN_RESHAPED_LOWP="benchmark_cl_gemmlowp_reshaped"
SiCong Li8b4c7302019-09-19 12:18:15 +010043
Eren Kopuz6977b372020-07-13 12:37:06 +010044# Default data type
Gian Marco Iodice716b1be2021-02-10 17:33:27 +000045DEFAULT_DATA_TYPE="f32"
Eren Kopuz6977b372020-07-13 12:37:06 +010046
SiCong Li8b4c7302019-09-19 12:18:15 +010047# Default output directory
48DEFAULT_OUT_DIR="out"
49
Gian Marco Iodice716b1be2021-02-10 17:33:27 +000050# Default ID of the first experiment
51DEFAULT_ID_EXPERIMENT_START=0
52
53# Default total number of experiments
54DEFAULT_NUM_EXPERIMENTS="all"
55
56# Default output file extension
57DEFAULT_OUT_EXTENSION="gemm_benchmark"
58
SiCong Li8b4c7302019-09-19 12:18:15 +010059# Number of iterations for each benchmark run
SiCong Libc166d52019-09-26 14:58:53 +010060NUM_ITERATION=5
SiCong Li8b4c7302019-09-19 12:18:15 +010061# Global }}}
62
63# Functions {{{
64#######################################
65# Print gemm shape file help message
66# Globals:
67# None
68# Arguments:
69# None
70# Returns:
71# None
72#######################################
73function help_gemm_shape_file() {
74 cat >&2 << EOF
75Gemm shape file:
Gian Marco Iodice716b1be2021-02-10 17:33:27 +000076 Gemm shape file is a csv file with fields separated by commas. The optional header and comments are ignored by the parser.
SiCong Li8abbabd2020-04-03 12:39:41 +010077
SiCong Li8b4c7302019-09-19 12:18:15 +010078 A gemm shape is a list of 4 positive integers <M, N, K, B> describing the shapes of the two matrices (LHS and RHS)
79 with:
80 M - Number of lhs matrix rows
81 N - Number of rhs matrix columns
82 K - Number of lhs matrix columns/rhs matrix rows
83 B - Batch size
84
85 An example gemm shape file looks like:
86 100,100,30,1
87 100,100,30,3
88 ...
89
90EOF
91}
92
93#######################################
SiCong Liea803482019-09-26 16:55:49 +010094# Print gemm config file for native help message
95# Globals:
96# None
97# Arguments:
98# None
99# Returns:
100# None
101#######################################
102function help_gemm_config_file_native() {
103 cat >&2 << EOF
104Gemm config file (Strategy native):
Gian Marco Iodice716b1be2021-02-10 17:33:27 +0000105 Gemm config file is a csv file with fields separated by commas. The optional header and comments are ignored by the parser.
SiCong Li8abbabd2020-04-03 12:39:41 +0100106
107 A gemm config is a list of 3 positive integers <m0, n0, k0>, with:
SiCong Liea803482019-09-26 16:55:49 +0100108 m0 - Number of rows processed by the matrix multiplication
109 n0 - Number of columns processed by the matrix multiplication
110 k0 - Number of partial accumulations performed by the matrix multiplication
111
112 Only the following configurations of M0, N0 and K0 are currently supported:
113 M0 = 1, 2, 3, 4, 5, 6, 7, 8
114 N0 = 2, 3, 4, 8, 16
115 K0 = 2, 3, 4, 8, 16
116
117 An example gemm config file looks like:
118 1,4,4
119 2,3,8
120 ...
121
122EOF
123}
124
125#######################################
SiCong Libc166d52019-09-26 14:58:53 +0100126# Print gemm config file for reshaped_rhs_only help message
SiCong Li8b4c7302019-09-19 12:18:15 +0100127# Globals:
128# None
129# Arguments:
130# None
131# Returns:
132# None
133#######################################
134function help_gemm_config_file_reshaped_rhs_only() {
135 cat >&2 << EOF
136Gemm config file (Strategy reshaped_rhs_only):
Gian Marco Iodice716b1be2021-02-10 17:33:27 +0000137 Gemm config file is a csv file with fields separated by commas. The optional header and comments are ignored by the parser.
SiCong Li8abbabd2020-04-03 12:39:41 +0100138
SiCong Lib10181b2020-08-11 13:00:20 +0100139 A gemm config is a list of 4 positive integers <m0, n0, k0, h0> and 3 boolean values:
SiCong Li8b4c7302019-09-19 12:18:15 +0100140 m0 - Number of rows processed by the matrix multiplication
141 n0 - Number of columns processed by the matrix multiplication
142 k0 - Number of partial accumulations performed by the matrix multiplication
143 h0 - Number of horizontal blocks of size (k0xn0) stored on the same output row
144 interleave_rhs - Interleave rhs matrix (1) / Do not interleave rhs matrix (0)
SiCong Libc166d52019-09-26 14:58:53 +0100145 transpose_rhs - Transpose rhs matrix (1) / Do not transpose rhs matrix (0)
SiCongLi282f3242020-11-24 15:24:16 +0000146 export_to_cl_image_rhs - (Not supported for quantized types) Export rhs matrix to cl_image (1) / Do not export rhs matrix to cl_image (0). Can only be true
SiCong Lib10181b2020-08-11 13:00:20 +0100147 with certain combinations of the GEMMParams and other configs. Please refer to CLGEMMReshapeRHSMatrixKernel
148 for more details
SiCong Li8b4c7302019-09-19 12:18:15 +0100149
150 Only the following configurations of M0, N0 and K0 are currently supported:
151 M0 = 1, 2, 3, 4, 5, 6, 7, 8
152 N0 = 2, 3, 4, 8, 16
153 K0 = 2, 3, 4, 8, 16
154 H0 >= 1
155
156 An example gemm config file looks like:
Eren Kopuz15205d92020-07-17 15:13:39 +0100157 4,4,4,1,1,1,0
158 4,4,4,3,1,0,1
SiCong Libc166d52019-09-26 14:58:53 +0100159 ...
160
161EOF
162}
163
164#######################################
165# Print gemm config file for reshaped help message
166# Globals:
167# None
168# Arguments:
169# None
170# Returns:
171# None
172#######################################
173function help_gemm_config_file_reshaped() {
174 cat >&2 << EOF
175Gemm config file (Strategy reshaped):
Gian Marco Iodice716b1be2021-02-10 17:33:27 +0000176 Gemm config file is a csv file with fields separated by commas. The header and comments are ignored by the parser.
SiCong Li8abbabd2020-04-03 12:39:41 +0100177
SiCong Lib10181b2020-08-11 13:00:20 +0100178 A gemm config is a list of 5 positive integers <m0, n0, k0, v0, h0> and 4 boolean values:
SiCong Libc166d52019-09-26 14:58:53 +0100179 m0 - Number of rows processed by the matrix multiplication
180 n0 - Number of columns processed by the matrix multiplication
181 k0 - Number of partial accumulations performed by the matrix multiplication
182 v0 - Number of vertical blocks of size (m0xk0) stored on the same output row
183 h0 - Number of horizontal blocks of size (k0xn0) stored on the same output row
184 interleave_lhs - Interleave lhs matrix (1) / Do not interleave lhs matrix (0)
185 interleave_rhs - Interleave rhs matrix (1) / Do not interleave rhs matrix (0)
186 transpose_rhs - Transpose rhs matrix but not lhs matrix (1) / Do not transpose rhs matrix but do transpose lhs matrix (0)
SiCongLi282f3242020-11-24 15:24:16 +0000187 export_to_cl_image_rhs - (Not supported for quantized types) Export rhs matrix to cl_image (1) / Do not export rhs matrix to cl_image (0). Can only be true
SiCong Lib10181b2020-08-11 13:00:20 +0100188 with certain combinations of the GEMMParams and other configs. Please refer to CLGEMMReshapeRHSMatrixKernel
189 for more details
SiCong Libc166d52019-09-26 14:58:53 +0100190
191 If rhs matrix is transposed only the following configurations are currently supported:
192 M0 = 2, 3, 4, 5, 6, 7, 8
193 N0 = 2, 3, 4, 8, 16
194 K0 = 2, 3, 4, 8, 16
195 V0 >= 1
196 H0 >= 1
197
198 If lhs matrix is transposed only the following configurations are currently supported:
199 M0 = 2, 3, 4, 8
200 N0 = 2, 3, 4, 8, 16
201 K0 = 2, 3, 4, 8, 16
202 V0 >= 1
203 H0 >= 1
204
205 An example gemm config file looks like:
Eren Kopuz15205d92020-07-17 15:13:39 +0100206 4,4,4,1,3,1,1,1,0
207 4,4,4,3,3,1,1,0,1
SiCong Li8b4c7302019-09-19 12:18:15 +0100208 ...
209
210EOF
211}
212
213#######################################
214# Print usage of this program and exit with Error
215# Globals:
216# Assumes all globals are required
217# Arguments:
218# None
219# Returns:
220# Error(1)
221#######################################
222function usage() {
223 cat >&2 << EOF
224Run gemm examples of a selected strategy, over provided tunable configurationsa and gemm shapes.
225Save the benchmark results to json files in an output directory.
226
Gian Marco Iodice716b1be2021-02-10 17:33:27 +0000227Usage: ${CMD} [-h] -s <strategy> -e <example_binary_dir> -g <gemm_shape_file> -c <gemm_config_file> [-o <out_dir>] [-d <data_type>] [-i <id_experiment_start>] [-n <num_experiments>] [-t <output_extension>]
SiCong Li8b4c7302019-09-19 12:18:15 +0100228
229Options:
230 -h
SiCong Libc166d52019-09-26 14:58:53 +0100231 Print help messages. If a strategy is specified with -s <strategy>, then only display messages relevant to that
232 strategy. Otherwise if no strategy is specified, display messages for all available strategies.
233
234 -s <strategy>
235 Strategy option.
236 Options: ${ALL_STRATEGY_OPTIONS[@]}.
SiCong Li8b4c7302019-09-19 12:18:15 +0100237
238 -e <example_binary_dir>
239 Path to directory that holds all example binaries
240
241 -g <gemm_shape_file>
242 Path to gemm shape csv file
243
244 -c <gemm_config_file>
245 Path to gemm config csv file
246
Eren Kopuz6977b372020-07-13 12:37:06 +0100247 -d <data_type>
248 Data type option with which to run benchmark examples
249 Default: ${DEFAULT_DATA_TYPE}
Eren Kopuz15205d92020-07-17 15:13:39 +0100250 Supported options:
251 Strategy : Data Types
Gian Marco Iodice716b1be2021-02-10 17:33:27 +0000252 Native : f32
253 Reshaped : f32, f16, qasymm8
254 Reshaped RHS Only : f32, f16, qasymm8
Eren Kopuz6977b372020-07-13 12:37:06 +0100255
SiCong Li8b4c7302019-09-19 12:18:15 +0100256 -o <out_dir>
257 Path to output directory that holds output json files
258 Default: ${DEFAULT_OUT_DIR}
259
Gian Marco Iodice716b1be2021-02-10 17:33:27 +0000260 -i <id_experiment_start>
261 ID of the first experiment.
262 Default: ${DEFAULT_ID_EXPERIMENT_START}
263
264 -n <num_experiments>
265 Total number of experiments to execute in this session. [1-all]
266 Default: ${DEFAULT_NUM_EXPERIMENTS}
267
268 -t <output_extension>
269 Output file extension.
270 Default: ${DEFAULT_OUT_EXTENSION}
271
SiCong Li8b4c7302019-09-19 12:18:15 +0100272EOF
273# Print help messages about gemm shapes and various gemm configs
274$HELP && help_gemm_shape_file
SiCong Liea803482019-09-26 16:55:49 +0100275$HELP && ( [ "${STRATEGY_OPTION}" == "" ] || [ "${STRATEGY_OPTION}" == "native" ] ) && help_gemm_config_file_native
SiCong Li8b4c7302019-09-19 12:18:15 +0100276$HELP && ( [ "${STRATEGY_OPTION}" == "" ] || [ "${STRATEGY_OPTION}" == "reshaped_rhs_only" ] ) && help_gemm_config_file_reshaped_rhs_only
SiCong Libc166d52019-09-26 14:58:53 +0100277$HELP && ( [ "${STRATEGY_OPTION}" == "" ] || [ "${STRATEGY_OPTION}" == "reshaped" ] ) && help_gemm_config_file_reshaped
SiCong Li8b4c7302019-09-19 12:18:15 +0100278exit 1
279}
280
281#######################################
282# Print error message and exit with Error.
283# Globals:
284# None
285# Arguments:
286# $1 - Error message
287# Returns:
288# None
289#######################################
290function error_msg() {
291 echo "Error: $1" 1>&2
292 exit 1
293}
294
295#######################################
296# Convert string to lower-case
297# Globals:
298# None
299# Arguments:
300# target - String
301# Returns:
302# (stdout) - String in lowercase
303#######################################
304function to_lower() {
305 local target=$1
306 echo "$target" | tr '[:upper:]' '[:lower:]'
307}
308
309#######################################
310# Test if the argument is an integer
311# Globals:
312# None
313# Arguments:
314# in - Input
315# Returns:
316# true/false
317#######################################
318function is_integer() {
319 local in=$1
320 [ "$in" -eq "$in" ] 2> /dev/null
321}
322
323#######################################
SiCong Libc166d52019-09-26 14:58:53 +0100324# Test if a string is in an array of strings
325# Globals:
326# None
327# Arguments:
328# target - String to test
329# array - Array of strings to search
330# Returns:
331# true/false
332#######################################
333function arr_contains() {
334 local target=$1
335 shift
336 local array
337 array=("$@")
338 for s in "${array[@]}"
339 do
340 [ "$s" == "${target}" ] && return
341 done
342 false
343}
344
345#######################################
SiCong Lie36b5262019-10-01 19:26:00 +0100346# Run a single example with all tunable gemm configurations on all gemm parameters
SiCong Li8b4c7302019-09-19 12:18:15 +0100347# Globals:
348# OUT_DIR
SiCong Lie36b5262019-10-01 19:26:00 +0100349# OUT_EXTENSION
SiCong Li8b4c7302019-09-19 12:18:15 +0100350# EXAMPLE_BIN_DIR
351# NUM_ITERATION
352# GEMM_CONFIGS_FILE
353# GEMM_SHAPES_FILE
Gian Marco Iodice716b1be2021-02-10 17:33:27 +0000354# STRATEGY_OPTION
355# DATA_TYPE
356# OUT_DIR
357# ID_EXPERIMENT_START
358# NUM_EXPERIMENTS
359
SiCong Li8b4c7302019-09-19 12:18:15 +0100360# Arguments:
361# example_bin Name of the example binary to run
362# Returns:
363# None
364#######################################
365function run() {
366 local example_bin=$1
Gian Marco Iodice716b1be2021-02-10 17:33:27 +0000367 echo "Running experiments for ${example_bin}" 1>&2
SiCong Li8b4c7302019-09-19 12:18:15 +0100368 local example_args
Gian Marco Iodice716b1be2021-02-10 17:33:27 +0000369 local json_filename
370 local expr_count=0
371 # Total number of experiments available
372 local num_experiments_total
SiCong Lie36b5262019-10-01 19:26:00 +0100373 # Total number of experiment runs scheduled for this session
Gian Marco Iodice716b1be2021-02-10 17:33:27 +0000374 local num_experiments_session
375 local id_experiment_start
376 local id_experiment_end
377 local array_shapes
378 local array_configs
379 local array_shapes_len
380 local array_configs_len
381 local array_shapes_idx
382 local array_configs_idx
Gian Marco Iodiced72bd122020-08-12 18:39:55 +0100383 local match_expression_shape="^([^,]*,){3}[^,]*$"
384 local match_expression_config="^(\s*[0-9]+\s*,)+\s*[0-9]\s*$"
Gian Marco Iodice716b1be2021-02-10 17:33:27 +0000385 local shapes_list_cmd="grep -E "$match_expression_shape" "${GEMM_SHAPES_FILE}""
386 local configs_list_cmd="grep -E "$match_expression_config" "${GEMM_CONFIGS_FILE}""
387
388 # Create array from CSV file
389 array_shapes=($( $shapes_list_cmd ))
390 array_configs=($( $configs_list_cmd ))
391
392 # Get array length
393 array_shapes_len=${#array_shapes[@]}
394 array_configs_len=${#array_configs[@]}
395
396 # Get the total number of experiments available
397 (( num_experiments_total=${array_shapes_len} * ${array_configs_len} ))
398
399 # Get the number of experiments to execute in this session
400 if [ ${NUM_EXPERIMENTS} == ${DEFAULT_NUM_EXPERIMENTS} ]
401 then
402 (( num_experiments_session=${array_shapes_len} * ${array_configs_len} ))
403 else
404 num_experiments_session=$NUM_EXPERIMENTS
405 fi
406
407 # Id experiment start
408 id_experiment_start=${ID_EXPERIMENT_START}
409
410 # Id experiment end
411 (( id_experiment_end=(${num_experiments_session} + ${id_experiment_start} - 1) ))
412
413 # Check if the id experiment end is grater than or equal to the total number of experiments available.
414 # If the condition is satisfied, clamp the id experiment end
415 if [ "$id_experiment_end" -ge "$num_experiments_total" ]
416 then
417 echo "Clamping idx experiment end" 1>&2
418 (( id_experiment_end=${num_experiments_total} - 1 ))
419 (( num_experiments_session=${id_experiment_start} + ${id_experiment_end} + 1 ))
420 fi
421
SiCong Lie36b5262019-10-01 19:26:00 +0100422 # Time elapsed since the beginning in seconds
423 local time_elapsed_s
424 # Time estimated to finish in seconds
425 local time_est_s
Gian Marco Iodice716b1be2021-02-10 17:33:27 +0000426 echo "Running a total number of ${num_experiments_session} experiments" 1>&2
427 echo "Experiment idx start/end [${id_experiment_start}, ${id_experiment_end}]" 1>&2
SiCong Lie36b5262019-10-01 19:26:00 +0100428
Gian Marco Iodice716b1be2021-02-10 17:33:27 +0000429 # Run experiments
430 for i in $(seq $id_experiment_start $id_experiment_end);
SiCong Li8b4c7302019-09-19 12:18:15 +0100431 do
Gian Marco Iodice716b1be2021-02-10 17:33:27 +0000432 (( array_shapes_idx=${i} / ${array_configs_len} ))
433 (( array_configs_idx=${i} % ${array_configs_len} ))
434
435 gemm_shape=${array_shapes[$array_shapes_idx]}
436 gemm_config=${array_configs[$array_configs_idx]}
437
438 echo "Running shape[$array_shapes_idx]=$gemm_shape with config[$array_configs_idx]=$gemm_config" 1>&2
439
440 example_args="${gemm_shape},${gemm_config},--type=${DATA_TYPE}"
441 json_filename="${STRATEGY_OPTION}_${gemm_shape}_${gemm_config}_${DATA_TYPE}"
442 # Replace "," with "_"
443 json_filename=${json_filename//,/_}
444
445 # Run experiment
446 ${EXAMPLE_BIN_DIR}/${example_bin} --example_args=${example_args} --iterations=${NUM_ITERATION} --json-file=${OUT_DIR}/${json_filename}.${OUT_EXTENSION} --instruments=OPENCL_TIMER_MS
447 # Print progress
448 (( expr_count++ ))
449 print_progress ${expr_count} ${num_experiments_session}
450 # Print time statistics
451 time_elapsed_s=$SECONDS
452 echo "Time elapsed since beginning: $(( $time_elapsed_s / 60 ))m $(( $time_elapsed_s % 60 ))s" 1>&2
453 (( time_est_s=(${num_experiments_session} - ${expr_count}) * ${time_elapsed_s} / ${expr_count} ))
454 echo "Time estimated to finish: $(( $time_est_s / 60 ))m $(( $time_est_s % 60 ))s" 1>&2
455 echo "Done." 1>&2
456 done
457
SiCong Li8b4c7302019-09-19 12:18:15 +0100458 echo "Finished running all configs for ${example_bin}" 1>&2
459 echo "All results saved to ${OUT_DIR}" 1>&2
460}
461
SiCong Lie36b5262019-10-01 19:26:00 +0100462#######################################
463# Print the progress of the current session
464# Globals:
465# None
466# Arguments:
467# current Current number of items
468# total Total number of items
469# Returns:
470# None
471#######################################
472function print_progress() {
473 local current
474 local total
475 current=$1
476 total=$2
477 # Width of progress bar
478 local width
479 width=20
480 (( current_width= $width * current / total ))
481 echo -n -e "Progress [" 1>&2
482 for i in $(seq 1 ${width}); do
483 if [[ $i -le ${current_width} ]]; then
484 echo -n "#" 1>&2
485 else
486 echo -n " " 1>&2
487 fi
488 done
489 echo "] $current / $total Experiments" 1>&2
490}
491
SiCong Li8b4c7302019-09-19 12:18:15 +0100492# Functions }}}
493
494# Main: Main script {{{
495# Path to directory containing all benchmark examples binaries
496EXAMPLE_BIN_DIR=""
497# Path to gemm shapes file
498GEMM_SHAPES_FILE=""
499# Path to gemm configs file
500GEMM_CONFIGS_FILE=""
Gian Marco Iodice716b1be2021-02-10 17:33:27 +0000501# Strategy option
SiCong Libc166d52019-09-26 14:58:53 +0100502STRATEGY_OPTION=""
Eren Kopuz6977b372020-07-13 12:37:06 +0100503# Data type to use
504DATA_TYPE=${DEFAULT_DATA_TYPE}
SiCong Li8b4c7302019-09-19 12:18:15 +0100505# Path to output directory
506OUT_DIR=${DEFAULT_OUT_DIR}
Gian Marco Iodice716b1be2021-02-10 17:33:27 +0000507# ID of the first experiment
508ID_EXPERIMENT_START=${DEFAULT_ID_EXPERIMENT_START}
509# Total number of experiments to execute in this session
510NUM_EXPERIMENTS=${DEFAULT_NUM_EXPERIMENTS}
SiCong Lie36b5262019-10-01 19:26:00 +0100511# Output benchmark result file extension
Gian Marco Iodice716b1be2021-02-10 17:33:27 +0000512OUT_EXTENSION=${DEFAULT_OUT_EXTENSION}
SiCong Li8b4c7302019-09-19 12:18:15 +0100513# Toggle help
514HELP=false
515
516# Obtain options
Gian Marco Iodice716b1be2021-02-10 17:33:27 +0000517while getopts "hs:e:g:c:d:o:i:n:t:" opt; do
SiCong Li8b4c7302019-09-19 12:18:15 +0100518 case "$opt" in
SiCong Libc166d52019-09-26 14:58:53 +0100519 h) HELP=true ;;
SiCong Li8b4c7302019-09-19 12:18:15 +0100520 s) STRATEGY_OPTION=$(to_lower "${OPTARG}");;
SiCong Libc166d52019-09-26 14:58:53 +0100521 e) EXAMPLE_BIN_DIR="${OPTARG}";;
SiCong Li8b4c7302019-09-19 12:18:15 +0100522 g) GEMM_SHAPES_FILE="${OPTARG}";;
523 c) GEMM_CONFIGS_FILE="${OPTARG}";;
SiCongLi282f3242020-11-24 15:24:16 +0000524 d) DATA_TYPE=$(to_lower "${OPTARG}");;
SiCong Li8b4c7302019-09-19 12:18:15 +0100525 o) OUT_DIR="${OPTARG}";;
Gian Marco Iodice716b1be2021-02-10 17:33:27 +0000526 i) ID_EXPERIMENT_START="${OPTARG}";;
527 n) NUM_EXPERIMENTS="${OPTARG}";;
528 t) OUT_EXTENSION="${OPTARG}";;
SiCong Li8b4c7302019-09-19 12:18:15 +0100529 esac
530done
531shift $((OPTIND - 1))
532
533# Lazily print usage (after arguments have been parsed)
534$HELP &&
535 usage
536
537# Parse and validate options
SiCong Libc166d52019-09-26 14:58:53 +0100538# Verify all compulsory arguments are passed in
539( [ ! -z "${STRATEGY_OPTION}" ] && [ ! -z "${EXAMPLE_BIN_DIR}" ] && [ ! -z "${GEMM_SHAPES_FILE}" ] && [ ! -z "${GEMM_CONFIGS_FILE}" ] ) ||
SiCong Li8b4c7302019-09-19 12:18:15 +0100540 usage
541
542# Verify example binaries directory exists
543[ -d "${EXAMPLE_BIN_DIR}" ] ||
544 error_msg "${EXAMPLE_BIN_DIR} does not exist."
545
546# Verify all benchmark example binaries exist
547[ -f "${EXAMPLE_BIN_DIR}/${EXAMPLE_BIN_RESHAPED_RHS_ONLY}" ] ||
548 error_msg "Cannot find ${EXAMPLE_BIN_RESHAPED_RHS_ONLY} at ${EXAMPLE_BIN_DIR}"
549
550# Verify Gemm shapes file exists
551[ -f "${GEMM_SHAPES_FILE}" ] ||
552 error_msg "Cannot find gemm shapes file ${GEMM_SHAPES_FILE}"
553
SiCong Libc166d52019-09-26 14:58:53 +0100554# Verify Gemm configs file exists
SiCong Li8b4c7302019-09-19 12:18:15 +0100555[ -f "${GEMM_CONFIGS_FILE}" ] ||
556 error_msg "Cannot find gemm configs file ${GEMM_CONFIGS_FILE}"
557
558# Verify strategy option is valid
SiCong Libc166d52019-09-26 14:58:53 +0100559arr_contains "${STRATEGY_OPTION}" "${ALL_STRATEGY_OPTIONS[@]}" ||
SiCong Li8b4c7302019-09-19 12:18:15 +0100560 error_msg "Does not support strategy ${STRATEGY_OPTION}"
561
Gian Marco Iodice716b1be2021-02-10 17:33:27 +0000562# Verify data type option is valid
563arr_contains "${DATA_TYPE}" "${ALL_DATA_TYPE_OPTIONS[@]}" ||
564 error_msg "Does not support data type ${DATA_TYPE}"
565
SiCong Li8b4c7302019-09-19 12:18:15 +0100566# Make sure existing benchmark outputs are not overwritten
567[ ! -d "${OUT_DIR}" ] ||
568 error_msg "Output directory ${OUT_DIR} already exists!"
569
570# Make output directory
SiCong Liac4c0302020-07-28 12:24:45 +0100571echo "Making output directory ${OUT_DIR}" 1>&2
572mkdir -p ${OUT_DIR} || error_msg "Failed to make output directory ${OUT_DIR}"
SiCong Li8b4c7302019-09-19 12:18:15 +0100573
574# Run selected strategy with all configurations
SiCong Lie36b5262019-10-01 19:26:00 +0100575# Restart the built-in timer
Gian Marco Iodice716b1be2021-02-10 17:33:27 +0000576SECONDS=0
SiCongLi282f3242020-11-24 15:24:16 +0000577if [ "$DATA_TYPE" == "qasymm8" ]; then
SiCongLi282f3242020-11-24 15:24:16 +0000578 [ "${STRATEGY_OPTION}" == "reshaped_rhs_only" ] && run $EXAMPLE_BIN_RESHAPED_RHS_ONLY_LOWP
579 [ "${STRATEGY_OPTION}" == "reshaped" ] && run $EXAMPLE_BIN_RESHAPED_LOWP
SiCongLi282f3242020-11-24 15:24:16 +0000580else
SiCongLi282f3242020-11-24 15:24:16 +0000581 [ "${STRATEGY_OPTION}" == "native" ] && run $EXAMPLE_BIN_NATIVE
582 [ "${STRATEGY_OPTION}" == "reshaped_rhs_only" ] && run $EXAMPLE_BIN_RESHAPED_RHS_ONLY
583 [ "${STRATEGY_OPTION}" == "reshaped" ] && run $EXAMPLE_BIN_RESHAPED
SiCongLi282f3242020-11-24 15:24:16 +0000584fi
SiCong Li8b4c7302019-09-19 12:18:15 +0100585# Main: Main script }}}