SiCong Li | bd8b1e2 | 2021-02-04 13:07:09 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2021 Arm Limited. |
| 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
| 24 | #ifndef SRC_RUNTIME_CL_GEMM_AUTO_HEURISTICS_CL_GEMM_AUTO_HEURISTICS_H |
| 25 | #define SRC_RUNTIME_CL_GEMM_AUTO_HEURISTICS_CL_GEMM_AUTO_HEURISTICS_H |
| 26 | |
| 27 | #include "arm_compute/core/GPUTarget.h" |
| 28 | #include "arm_compute/core/Types.h" |
| 29 | #include "arm_compute/runtime/CL/CLTypes.h" |
| 30 | |
| 31 | namespace arm_compute |
| 32 | { |
| 33 | namespace cl_gemm |
| 34 | { |
| 35 | namespace auto_heuristics |
| 36 | { |
| 37 | /** A collection of adaptor functions that enable the auto selection between mlgo-based heuristics and default heuristics */ |
| 38 | |
| 39 | /** Common query */ |
| 40 | struct CommonQuery |
| 41 | { |
| 42 | GPUTarget gpu_target; /**< Which @ref GPUTarget to query about */ |
| 43 | DataType data_type; /**< Data type */ |
| 44 | unsigned int m; /**< Number of rows for the lhs matrix. Lhs matrix NOT transposed */ |
| 45 | unsigned int n; /**< Number of columns for the rhs matrix. Rhs matrix NOT transposed */ |
| 46 | unsigned int k; /**< Number of rows for the rhs matrix. Rhs matrix NOT transposed */ |
| 47 | unsigned int b; /**< Batch size */ |
| 48 | }; |
| 49 | |
SiCong Li | 1a28e73 | 2021-02-10 16:57:33 +0000 | [diff] [blame] | 50 | /** Result of querying about GEMM type ( @ref CLGEMMKernelType) */ |
| 51 | struct GEMMTypeResult |
| 52 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 53 | GEMMTypeResult(bool valid, CLGEMMKernelType gemm_type) : valid{valid}, gemm_type{gemm_type} |
SiCong Li | 1a28e73 | 2021-02-10 16:57:33 +0000 | [diff] [blame] | 54 | { |
| 55 | } |
| 56 | /** Test if the result is valid */ |
| 57 | operator bool() const |
| 58 | { |
| 59 | return valid; |
| 60 | } |
| 61 | bool valid; /** If the result is valid */ |
| 62 | CLGEMMKernelType gemm_type; /** @ref CLGEMMKernelType */ |
| 63 | }; |
| 64 | |
SiCong Li | bd8b1e2 | 2021-02-04 13:07:09 +0000 | [diff] [blame] | 65 | /** Result of querying about GEMM config ( @ref GEMMLHSMatrixInfo and @ref GEMMRHSMatrixInfo) */ |
| 66 | struct GEMMConfigResult |
| 67 | { |
| 68 | GEMMConfigResult(bool valid, const GEMMLHSMatrixInfo &lhs_info, const GEMMRHSMatrixInfo &rhs_info) |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 69 | : valid{valid}, lhs_info{lhs_info}, rhs_info{rhs_info} |
SiCong Li | bd8b1e2 | 2021-02-04 13:07:09 +0000 | [diff] [blame] | 70 | { |
| 71 | } |
| 72 | /** Test if the result is valid */ |
| 73 | operator bool() const |
| 74 | { |
| 75 | return valid; |
| 76 | } |
| 77 | bool valid; /** If the result is valid */ |
| 78 | GEMMLHSMatrixInfo lhs_info; /** @ref GEMMLHSMatrixInfo */ |
| 79 | GEMMRHSMatrixInfo rhs_info; /** @ref GEMMRHSMatrixInfo */ |
| 80 | }; |
| 81 | |
SiCong Li | 1a28e73 | 2021-02-10 16:57:33 +0000 | [diff] [blame] | 82 | /** Select gemm type based on mlgo heuristics |
SiCong Li | bd8b1e2 | 2021-02-04 13:07:09 +0000 | [diff] [blame] | 83 | * @param query Query |
| 84 | * @param reshape_b_only_on_first_run Additional query parameter if reshape b only on first run |
SiCong Li | 1a28e73 | 2021-02-10 16:57:33 +0000 | [diff] [blame] | 85 | * @return GEMMTypeResult. Result is valid if bool(GEMMTypeResult) == true and invalid otherwise |
SiCong Li | bd8b1e2 | 2021-02-04 13:07:09 +0000 | [diff] [blame] | 86 | */ |
SiCong Li | 1a28e73 | 2021-02-10 16:57:33 +0000 | [diff] [blame] | 87 | GEMMTypeResult select_mlgo_gemm_kernel(const CommonQuery &query, bool reshape_b_only_on_first_run); |
| 88 | |
| 89 | /** Select gemm type based on default heuristics |
| 90 | * @param query Query |
| 91 | * @param reshape_b_only_on_first_run Additional query parameter if reshape b only on first run |
| 92 | * @return GEMMTypeResult. Result is valid if bool(GEMMTypeResult) == true and invalid otherwise |
| 93 | */ |
| 94 | GEMMTypeResult select_default_gemm_kernel(const CommonQuery &query, bool reshape_b_only_on_first_run); |
SiCong Li | bd8b1e2 | 2021-02-04 13:07:09 +0000 | [diff] [blame] | 95 | |
| 96 | /** Select gemm config based on mlgo heuristics |
| 97 | * @param query Query |
SiCong Li | 1a28e73 | 2021-02-10 16:57:33 +0000 | [diff] [blame] | 98 | * @return GEMMConfigResult. Result is valid if bool(GEMMConfigResult) == true and invalid otherwise |
SiCong Li | bd8b1e2 | 2021-02-04 13:07:09 +0000 | [diff] [blame] | 99 | */ |
| 100 | GEMMConfigResult select_mlgo_gemm_config_reshaped_only_rhs(const CommonQuery &query); |
| 101 | |
| 102 | /** Select gemm config based on default heuristics |
| 103 | * @param query Query |
SiCong Li | 1a28e73 | 2021-02-10 16:57:33 +0000 | [diff] [blame] | 104 | * @return GEMMConfigResult. Result is valid if bool(GEMMConfigResult) == true and invalid otherwise |
SiCong Li | bd8b1e2 | 2021-02-04 13:07:09 +0000 | [diff] [blame] | 105 | */ |
| 106 | GEMMConfigResult select_default_gemm_config_reshaped_only_rhs(const CommonQuery &query); |
SiCong Li | 8c23ba1 | 2021-02-08 14:19:23 +0000 | [diff] [blame] | 107 | |
| 108 | /** Select gemm config based on mlgo heuristics |
| 109 | * @param query Query |
SiCong Li | 1a28e73 | 2021-02-10 16:57:33 +0000 | [diff] [blame] | 110 | * @return GEMMConfigResult. Result is valid if bool(GEMMConfigResult) == true and invalid otherwise |
SiCong Li | 8c23ba1 | 2021-02-08 14:19:23 +0000 | [diff] [blame] | 111 | */ |
| 112 | GEMMConfigResult select_mlgo_gemm_config_reshaped(const CommonQuery &query); |
| 113 | |
| 114 | /** Select gemm config based on default heuristics |
| 115 | * @param query Query |
SiCong Li | 1a28e73 | 2021-02-10 16:57:33 +0000 | [diff] [blame] | 116 | * @return GEMMConfigResult. Result is valid if bool(GEMMConfigResult) == true and invalid otherwise |
SiCong Li | 8c23ba1 | 2021-02-08 14:19:23 +0000 | [diff] [blame] | 117 | */ |
| 118 | GEMMConfigResult select_default_gemm_config_reshaped(const CommonQuery &query); |
| 119 | |
SiCong Li | db35345 | 2021-02-08 15:16:13 +0000 | [diff] [blame] | 120 | /** Select gemm config based on mlgo heuristics |
| 121 | * @param query Query |
SiCong Li | 1a28e73 | 2021-02-10 16:57:33 +0000 | [diff] [blame] | 122 | * @return GEMMConfigResult. Result is valid if bool(GEMMConfigResult) == true and invalid otherwise |
SiCong Li | db35345 | 2021-02-08 15:16:13 +0000 | [diff] [blame] | 123 | */ |
| 124 | GEMMConfigResult select_mlgo_gemm_config_native(const CommonQuery &query); |
| 125 | |
| 126 | /** Select gemm config based on default heuristics |
| 127 | * @param query Query |
SiCong Li | 1a28e73 | 2021-02-10 16:57:33 +0000 | [diff] [blame] | 128 | * @return GEMMConfigResult. Result is valid if bool(GEMMConfigResult) == true and invalid otherwise |
SiCong Li | db35345 | 2021-02-08 15:16:13 +0000 | [diff] [blame] | 129 | */ |
| 130 | GEMMConfigResult select_default_gemm_config_native(const CommonQuery &query); |
| 131 | |
SiCong Li | bd8b1e2 | 2021-02-04 13:07:09 +0000 | [diff] [blame] | 132 | } // namespace auto_heuristics |
| 133 | } // namespace cl_gemm |
| 134 | } // namespace arm_compute |
| 135 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 136 | #endif // SRC_RUNTIME_CL_GEMM_AUTO_HEURISTICS_CL_GEMM_AUTO_HEURISTICS_H |