blob: 7cb9cab2205f7a7a815d664d52a32d312b1b3454 [file] [log] [blame]
SiCong Libd8b1e22021-02-04 13:07:09 +00001/*
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
31namespace arm_compute
32{
33namespace cl_gemm
34{
35namespace 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 */
40struct 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
50/** Result of querying about GEMM config ( @ref GEMMLHSMatrixInfo and @ref GEMMRHSMatrixInfo) */
51struct GEMMConfigResult
52{
53 GEMMConfigResult(bool valid, const GEMMLHSMatrixInfo &lhs_info, const GEMMRHSMatrixInfo &rhs_info)
54 : valid{ valid }, lhs_info{ lhs_info }, rhs_info{ rhs_info }
55 {
56 }
57 /** Test if the result is valid */
58 operator bool() const
59 {
60 return valid;
61 }
62 bool valid; /** If the result is valid */
63 GEMMLHSMatrixInfo lhs_info; /** @ref GEMMLHSMatrixInfo */
64 GEMMRHSMatrixInfo rhs_info; /** @ref GEMMRHSMatrixInfo */
65};
66
67/** Automatically select between mlgo and default heuristics to choose @ref CLGEMMKernelType
68 * @param query Query
69 * @param reshape_b_only_on_first_run Additional query parameter if reshape b only on first run
70 * @return CLGEMMKernelType
71 */
72CLGEMMKernelType auto_select_gemm_kernel(const CommonQuery &query, bool reshape_b_only_on_first_run);
73
74/** Select gemm config based on mlgo heuristics
75 * @param query Query
76 * @return GEMMConfigResult
77 */
78GEMMConfigResult select_mlgo_gemm_config_reshaped_only_rhs(const CommonQuery &query);
79
80/** Select gemm config based on default heuristics
81 * @param query Query
82 * @return GEMMConfigResult
83 */
84GEMMConfigResult select_default_gemm_config_reshaped_only_rhs(const CommonQuery &query);
SiCong Li8c23ba12021-02-08 14:19:23 +000085
86/** Select gemm config based on mlgo heuristics
87 * @param query Query
88 * @return GEMMConfigResult
89 */
90GEMMConfigResult select_mlgo_gemm_config_reshaped(const CommonQuery &query);
91
92/** Select gemm config based on default heuristics
93 * @param query Query
94 * @return GEMMConfigResult
95 */
96GEMMConfigResult select_default_gemm_config_reshaped(const CommonQuery &query);
97
SiCong Libd8b1e22021-02-04 13:07:09 +000098} // namespace auto_heuristics
99} // namespace cl_gemm
100} // namespace arm_compute
101
102#endif // SRC_RUNTIME_CL_GEMM_AUTO_HEURISTICS_CL_GEMM_AUTO_HEURISTICS_H