From ca419dde35118fcfe07fa0a5ce388c0a40b75c49 Mon Sep 17 00:00:00 2001 From: Gian Marco Iodice Date: Wed, 3 Mar 2021 17:25:07 +0000 Subject: Add tuner mode support in GeMM benchmark Change-Id: Ie1ad9880d22daa2a8ee4f239b5b23d3a7ba4cb1b Signed-off-by: Gian Marco Iodice Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/5210 Tested-by: Arm Jenkins Reviewed-by: Georgios Pinitas Reviewed-by: SiCong Li --- examples/gemm_tuner/CommonGemmExampleOptions.cpp | 29 ++++++++++++++++------ examples/gemm_tuner/CommonGemmExampleOptions.h | 27 +++++++++++--------- examples/gemm_tuner/cl_gemm_benchmark.sh | 17 ++++++++++--- examples/gemm_tuner/cl_gemm_native.cpp | 4 ++- examples/gemm_tuner/cl_gemm_reshaped.cpp | 2 ++ examples/gemm_tuner/cl_gemm_reshaped_rhs_only.cpp | 2 ++ examples/gemm_tuner/cl_gemmlowp_reshaped.cpp | 2 ++ ...aped_rhs_only_fused_output_stage_fixedpoint.cpp | 2 ++ 8 files changed, 61 insertions(+), 24 deletions(-) (limited to 'examples/gemm_tuner') diff --git a/examples/gemm_tuner/CommonGemmExampleOptions.cpp b/examples/gemm_tuner/CommonGemmExampleOptions.cpp index 440973737c..f1306ccf5c 100644 --- a/examples/gemm_tuner/CommonGemmExampleOptions.cpp +++ b/examples/gemm_tuner/CommonGemmExampleOptions.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020 Arm Limited. + * Copyright (c) 2019-2021 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -35,6 +35,7 @@ using namespace utils; os << "K : " << common_params.K << std::endl; os << "B : " << common_params.B << std::endl; os << "Data type : " << common_params.data_type << std::endl; + os << "OpenCL tuner mode : " << common_params.tuner_mode << std::endl; return os; } @@ -44,7 +45,8 @@ CommonGemmExampleOptions::CommonGemmExampleOptions(CommandLineParser &parser, Da N(parser.add_positional_option>("N", 100)), K(parser.add_positional_option>("K", 50)), B(parser.add_positional_option>("B", 1)), - data_type() + data_type(), + tuner_mode() { const std::set supported_data_types { @@ -52,9 +54,18 @@ CommonGemmExampleOptions::CommonGemmExampleOptions(CommandLineParser &parser, Da DataType::F32, DataType::QASYMM8, }; + + const std::set supported_tuner_modes + { + CLTunerMode::EXHAUSTIVE, + CLTunerMode::NORMAL, + CLTunerMode::RAPID + }; + ARM_COMPUTE_ERROR_ON_MSG(supported_data_types.find(default_data_type) == supported_data_types.end(), "Default data type unsupported"); - data_type = parser.add_option>("type", supported_data_types, default_data_type); + data_type = parser.add_option>("type", supported_data_types, default_data_type); + tuner_mode = parser.add_option>("tuner-mode", supported_tuner_modes, CLTunerMode::RAPID); help->set_help("Show this help message."); M->set_help("Number of lhs matrix rows."); @@ -62,16 +73,18 @@ CommonGemmExampleOptions::CommonGemmExampleOptions(CommandLineParser &parser, Da K->set_help("Number of lhs matrix columns/rhs matrix rows."); B->set_help("Batch size."); data_type->set_help("Data type to use"); + tuner_mode->set_help("OpenCL tuner mode"); } CommonGemmExampleParams consume_common_gemm_example_parameters(const CommonGemmExampleOptions &options) { CommonGemmExampleParams common_params; - common_params.M = options.M->value(); - common_params.N = options.N->value(); - common_params.K = options.K->value(); - common_params.B = options.B->value(); - common_params.data_type = options.data_type->value(); + common_params.M = options.M->value(); + common_params.N = options.N->value(); + common_params.K = options.K->value(); + common_params.B = options.B->value(); + common_params.data_type = options.data_type->value(); + common_params.tuner_mode = options.tuner_mode->value(); return common_params; } } // namespace gemm_tuner diff --git a/examples/gemm_tuner/CommonGemmExampleOptions.h b/examples/gemm_tuner/CommonGemmExampleOptions.h index 633e9252bd..f7447e3db3 100644 --- a/examples/gemm_tuner/CommonGemmExampleOptions.h +++ b/examples/gemm_tuner/CommonGemmExampleOptions.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020 Arm Limited. + * Copyright (c) 2019-2021 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -26,6 +26,7 @@ #include "arm_compute/core/Types.h" #include "arm_compute/core/Utils.h" +#include "arm_compute/runtime/CL/CLTuner.h" #include "utils/TypePrinter.h" #include "utils/command_line/CommandLineOptions.h" #include "utils/command_line/CommandLineParser.h" @@ -35,11 +36,12 @@ namespace gemm_tuner /** Structure holding all the common gemm example parameters */ struct CommonGemmExampleParams { - size_t M{ 100 }; /**< Number of lhs matrix rows */ - size_t N{ 100 }; /**< Number of rhs matrix columns */ - size_t K{ 50 }; /**< Number of lhs matrix columns/rhs matrix rows */ - size_t B{ 1 }; /**< Batch size */ - arm_compute::DataType data_type{ arm_compute::DataType::F32 }; /**< Data type */ + size_t M{ 100 }; /**< Number of lhs matrix rows */ + size_t N{ 100 }; /**< Number of rhs matrix columns */ + size_t K{ 50 }; /**< Number of lhs matrix columns/rhs matrix rows */ + size_t B{ 1 }; /**< Batch size */ + arm_compute::DataType data_type{ arm_compute::DataType::F32 }; /**< Data type */ + arm_compute::CLTunerMode tuner_mode{ arm_compute::CLTunerMode::RAPID }; /**< OpenCL tuner mode */ }; /** Formatted output of the CommonGemmExampleParams type @@ -80,12 +82,13 @@ public: /** Default destructor */ ~CommonGemmExampleOptions() = default; - arm_compute::utils::ToggleOption *help; /**< Show help option */ - arm_compute::utils::SimpleOption *M; /**< Number of lhs matrix rows option */ - arm_compute::utils::SimpleOption *N; /**< Number of rhs matrix columns option */ - arm_compute::utils::SimpleOption *K; /**< Number of lhs matrix columns/rhs matrix rows option */ - arm_compute::utils::SimpleOption *B; /**< Batch size option */ - arm_compute::utils::EnumOption *data_type; /**< Data type */ + arm_compute::utils::ToggleOption *help; /**< Show help option */ + arm_compute::utils::SimpleOption *M; /**< Number of lhs matrix rows option */ + arm_compute::utils::SimpleOption *N; /**< Number of rhs matrix columns option */ + arm_compute::utils::SimpleOption *K; /**< Number of lhs matrix columns/rhs matrix rows option */ + arm_compute::utils::SimpleOption *B; /**< Batch size option */ + arm_compute::utils::EnumOption *data_type; /**< Data type */ + arm_compute::utils::EnumOption *tuner_mode; /**< OpenCL tuner mode */ }; /** Consumes the common gemm example options and creates a structure containing all information diff --git a/examples/gemm_tuner/cl_gemm_benchmark.sh b/examples/gemm_tuner/cl_gemm_benchmark.sh index a49c2e154b..92fe6b194e 100755 --- a/examples/gemm_tuner/cl_gemm_benchmark.sh +++ b/examples/gemm_tuner/cl_gemm_benchmark.sh @@ -54,7 +54,10 @@ DEFAULT_ID_EXPERIMENT_START=0 DEFAULT_NUM_EXPERIMENTS="all" # Default output file extension -DEFAULT_OUT_EXTENSION="gemm_benchmark" +DEFAULT_OUT_EXTENSION="mlgo_benchmark" + +# Default OpenCL tuner mode +DEFAULT_TUNER_MODE="rapid" # Number of iterations for each benchmark run NUM_ITERATION=5 @@ -269,6 +272,10 @@ Options: Output file extension. Default: ${DEFAULT_OUT_EXTENSION} + -m + OpenCL tuner mode. + Default: ${DEFAULT_TUNER_MODE} + EOF # Print help messages about gemm shapes and various gemm configs $HELP && help_gemm_shape_file @@ -347,6 +354,7 @@ function arr_contains() { # Globals: # OUT_DIR # OUT_EXTENSION +# TUNER_MODE # EXAMPLE_BIN_DIR # NUM_ITERATION # GEMM_CONFIGS_FILE @@ -437,7 +445,7 @@ function run() { echo "Running shape[$array_shapes_idx]=$gemm_shape with config[$array_configs_idx]=$gemm_config" 1>&2 - example_args="${gemm_shape},${gemm_config},--type=${DATA_TYPE}" + example_args="${gemm_shape},${gemm_config},--type=${DATA_TYPE},--tuner-mode=${TUNER_MODE}" json_filename="${STRATEGY_OPTION}_${gemm_shape}_${gemm_config}_${DATA_TYPE}" # Replace "," with "_" json_filename=${json_filename//,/_} @@ -510,11 +518,13 @@ ID_EXPERIMENT_START=${DEFAULT_ID_EXPERIMENT_START} NUM_EXPERIMENTS=${DEFAULT_NUM_EXPERIMENTS} # Output benchmark result file extension OUT_EXTENSION=${DEFAULT_OUT_EXTENSION} +# OpenCL tuner mode +TUNER_MODE=${DEFAULT_TUNER_MODE} # Toggle help HELP=false # Obtain options -while getopts "hs:e:g:c:d:o:i:n:t:" opt; do +while getopts "hs:e:g:c:d:o:i:n:t:m:" opt; do case "$opt" in h) HELP=true ;; s) STRATEGY_OPTION=$(to_lower "${OPTARG}");; @@ -526,6 +536,7 @@ while getopts "hs:e:g:c:d:o:i:n:t:" opt; do i) ID_EXPERIMENT_START="${OPTARG}";; n) NUM_EXPERIMENTS="${OPTARG}";; t) OUT_EXTENSION="${OPTARG}";; + m) TUNER_MODE="${OPTARG}";; esac done shift $((OPTIND - 1)) diff --git a/examples/gemm_tuner/cl_gemm_native.cpp b/examples/gemm_tuner/cl_gemm_native.cpp index 02f144ea12..5a144dabf7 100644 --- a/examples/gemm_tuner/cl_gemm_native.cpp +++ b/examples/gemm_tuner/cl_gemm_native.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2020 Arm Limited. + * Copyright (c) 2019-2021 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -170,6 +170,8 @@ public: std::cout << "Gemm configurations:" << std::endl; std::cout << configs << std::endl; + tuner.set_tuner_mode(params.tuner_mode); + CLScheduler::get().default_init(&tuner); lhs.allocator()->init(TensorInfo(TensorShape(params.K, params.M, params.B), 1, params.data_type)); diff --git a/examples/gemm_tuner/cl_gemm_reshaped.cpp b/examples/gemm_tuner/cl_gemm_reshaped.cpp index 2ea4769dd3..444a342d74 100644 --- a/examples/gemm_tuner/cl_gemm_reshaped.cpp +++ b/examples/gemm_tuner/cl_gemm_reshaped.cpp @@ -222,6 +222,8 @@ public: std::cout << "Gemm configurations:" << std::endl; std::cout << configs << std::endl; + tuner.set_tuner_mode(params.tuner_mode); + CLScheduler::get().default_init(&tuner); lhs.allocator()->init(TensorInfo(TensorShape(params.K, params.M, params.B), 1, params.data_type)); diff --git a/examples/gemm_tuner/cl_gemm_reshaped_rhs_only.cpp b/examples/gemm_tuner/cl_gemm_reshaped_rhs_only.cpp index 10fd2984cf..68bec9da6e 100644 --- a/examples/gemm_tuner/cl_gemm_reshaped_rhs_only.cpp +++ b/examples/gemm_tuner/cl_gemm_reshaped_rhs_only.cpp @@ -195,6 +195,8 @@ public: std::cout << "Gemm configurations:" << std::endl; std::cout << configs << std::endl; + tuner.set_tuner_mode(params.tuner_mode); + CLScheduler::get().default_init(&tuner); lhs.allocator()->init(TensorInfo(TensorShape(params.K, params.M, params.B), 1, params.data_type)); diff --git a/examples/gemm_tuner/cl_gemmlowp_reshaped.cpp b/examples/gemm_tuner/cl_gemmlowp_reshaped.cpp index 7c26e0f389..5b81963752 100644 --- a/examples/gemm_tuner/cl_gemmlowp_reshaped.cpp +++ b/examples/gemm_tuner/cl_gemmlowp_reshaped.cpp @@ -208,6 +208,8 @@ public: std::cout << "Gemm configurations:" << std::endl; std::cout << configs << std::endl; + tuner.set_tuner_mode(params.tuner_mode); + CLScheduler::get().default_init(&tuner); lhs.allocator()->init(TensorInfo(TensorShape(params.K, params.M, params.B), 1, params.data_type)); diff --git a/examples/gemm_tuner/cl_gemmlowp_reshaped_rhs_only_fused_output_stage_fixedpoint.cpp b/examples/gemm_tuner/cl_gemmlowp_reshaped_rhs_only_fused_output_stage_fixedpoint.cpp index f25341ce25..95431ed50c 100644 --- a/examples/gemm_tuner/cl_gemmlowp_reshaped_rhs_only_fused_output_stage_fixedpoint.cpp +++ b/examples/gemm_tuner/cl_gemmlowp_reshaped_rhs_only_fused_output_stage_fixedpoint.cpp @@ -187,6 +187,8 @@ public: std::cout << "Gemm configurations:" << std::endl; std::cout << configs << std::endl; + tuner.set_tuner_mode(params.tuner_mode); + CLScheduler::get().default_init(&tuner); lhs.allocator()->init(TensorInfo(TensorShape(params.K, params.M, params.B), 1, params.data_type)); -- cgit v1.2.1