Gian Marco Iodice | 5a4fe19 | 2020-03-16 12:22:37 +0000 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2020 Arm Limited. |
Gian Marco Iodice | 5a4fe19 | 2020-03-16 12:22:37 +0000 | [diff] [blame] | 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 | #include "arm_compute/runtime/CL/gemm/CLGEMMKernelSelectionValhall.h" |
| 25 | |
| 26 | #include "arm_compute/core/CL/CLHelpers.h" |
| 27 | #include "arm_compute/core/CL/CLKernelLibrary.h" |
| 28 | #include "arm_compute/core/CL/gemm/CLGEMMHelpers.h" |
| 29 | |
| 30 | #include <map> |
| 31 | #include <utility> |
| 32 | |
| 33 | namespace arm_compute |
| 34 | { |
| 35 | namespace cl_gemm |
| 36 | { |
| 37 | CLGEMMKernelSelectionValhall::CLGEMMKernelSelectionValhall(GPUTarget gpu) |
| 38 | : ICLGEMMKernelSelection(gpu) |
| 39 | { |
| 40 | } |
| 41 | |
| 42 | CLGEMMKernelType CLGEMMKernelSelectionValhall::select_kernel(const CLGEMMKernelSelectionParams ¶ms) |
| 43 | { |
| 44 | // _target could be used in the future to have a dedicated heuristic for each GPU IP |
| 45 | ARM_COMPUTE_UNUSED(_target); |
| 46 | |
| 47 | using FunctionExecutorPtr = CLGEMMKernelType (CLGEMMKernelSelectionValhall::*)(unsigned int m, unsigned int n, unsigned int k, bool is_rhs_constant); |
| 48 | |
| 49 | // Configurations for Valhall architectures |
| 50 | static std::map<DataType, FunctionExecutorPtr> gemm_configs = |
| 51 | { |
| 52 | { DataType::F32, &CLGEMMKernelSelectionValhall::default_f32 }, |
| 53 | { DataType::F16, &CLGEMMKernelSelectionValhall::default_f16 }, |
| 54 | { DataType::QASYMM8, &CLGEMMKernelSelectionValhall::default_q8 }, |
| 55 | { DataType::QASYMM8_SIGNED, &CLGEMMKernelSelectionValhall::default_q8 }, |
| 56 | { DataType::QSYMM8, &CLGEMMKernelSelectionValhall::default_q8 }, |
| 57 | { DataType::QSYMM8_PER_CHANNEL, &CLGEMMKernelSelectionValhall::default_q8 } |
| 58 | }; |
| 59 | |
| 60 | const DataType data_type = params.data_type; |
| 61 | |
| 62 | if(gemm_configs.find(data_type) != gemm_configs.end()) |
| 63 | { |
| 64 | return (this->*gemm_configs[data_type])(params.m, params.n, params.k, params.is_rhs_constant); |
| 65 | } |
| 66 | |
| 67 | ARM_COMPUTE_ERROR("Not supported data type"); |
| 68 | } |
| 69 | |
| 70 | CLGEMMKernelType CLGEMMKernelSelectionValhall::default_f32(unsigned int m, unsigned int n, unsigned int k, bool is_rhs_constant) |
| 71 | { |
| 72 | ARM_COMPUTE_UNUSED(m, n, k); |
| 73 | |
| 74 | return is_rhs_constant ? CLGEMMKernelType::RESHAPED_ONLY_RHS : CLGEMMKernelType::NATIVE_V1; |
| 75 | } |
| 76 | |
| 77 | CLGEMMKernelType CLGEMMKernelSelectionValhall::default_f16(unsigned int m, unsigned int n, unsigned int k, bool is_rhs_constant) |
| 78 | { |
| 79 | ARM_COMPUTE_UNUSED(m, n, k); |
| 80 | |
| 81 | return is_rhs_constant ? CLGEMMKernelType::RESHAPED_ONLY_RHS : CLGEMMKernelType::NATIVE_V1; |
| 82 | } |
| 83 | |
| 84 | CLGEMMKernelType CLGEMMKernelSelectionValhall::default_q8(unsigned int m, unsigned int n, unsigned int k, bool is_rhs_constant) |
| 85 | { |
Gian Marco Iodice | eb65f6d | 2020-04-15 11:42:15 +0100 | [diff] [blame] | 86 | ARM_COMPUTE_UNUSED(m, n, k); |
Gian Marco Iodice | 5a4fe19 | 2020-03-16 12:22:37 +0000 | [diff] [blame] | 87 | |
| 88 | if(is_rhs_constant) |
| 89 | { |
Gian Marco Iodice | eb65f6d | 2020-04-15 11:42:15 +0100 | [diff] [blame] | 90 | return CLGEMMKernelType::RESHAPED_ONLY_RHS; |
Gian Marco Iodice | 5a4fe19 | 2020-03-16 12:22:37 +0000 | [diff] [blame] | 91 | } |
| 92 | else |
| 93 | { |
Gian Marco Iodice | eb65f6d | 2020-04-15 11:42:15 +0100 | [diff] [blame] | 94 | return CLGEMMKernelType::NATIVE; |
Gian Marco Iodice | 5a4fe19 | 2020-03-16 12:22:37 +0000 | [diff] [blame] | 95 | } |
| 96 | } |
| 97 | } // namespace cl_gemm |
| 98 | } // namespace arm_compute |