Gian Marco Iodice | 2cc50b3 | 2022-05-30 14:41:49 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2022 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 | */ |
Ramy Elgammal | df6a3b0 | 2022-11-30 16:23:10 +0000 | [diff] [blame] | 24 | #include "src/runtime/heuristics/direct_conv/ClDirectConvDefaultConfigBifrost.h" |
Gian Marco Iodice | 2cc50b3 | 2022-05-30 14:41:49 +0100 | [diff] [blame] | 25 | |
| 26 | #include "arm_compute/core/CL/CLHelpers.h" |
| 27 | #include "arm_compute/core/CL/CLKernelLibrary.h" |
| 28 | #include "arm_compute/core/GPUTarget.h" |
| 29 | #include "arm_compute/core/TensorInfo.h" |
| 30 | #include "arm_compute/core/TensorShape.h" |
| 31 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 32 | |
Gian Marco Iodice | 2cc50b3 | 2022-05-30 14:41:49 +0100 | [diff] [blame] | 33 | #include <utility> |
| 34 | |
| 35 | namespace arm_compute |
| 36 | { |
| 37 | namespace cl_direct_conv |
| 38 | { |
| 39 | using namespace arm_compute::misc::shape_calculator; |
| 40 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 41 | ClDirectConvDefaultConfigBifrost::ClDirectConvDefaultConfigBifrost(GPUTarget gpu) : IClDirectConvKernelConfig(gpu) |
Gian Marco Iodice | 2cc50b3 | 2022-05-30 14:41:49 +0100 | [diff] [blame] | 42 | { |
| 43 | } |
| 44 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 45 | DirectConvComputeKernelInfo ClDirectConvDefaultConfigBifrost::configure(const ITensorInfo *src, |
| 46 | const ITensorInfo *wei, |
| 47 | const PadStrideInfo &conv_info) |
Gian Marco Iodice | 2cc50b3 | 2022-05-30 14:41:49 +0100 | [diff] [blame] | 48 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 49 | using ConfigurationFunctionExecutorPtr = DirectConvComputeKernelInfo (ClDirectConvDefaultConfigBifrost::*)( |
| 50 | const ITensorInfo *src, const ITensorInfo *wei, const PadStrideInfo &conv_info); |
Gian Marco Iodice | 2cc50b3 | 2022-05-30 14:41:49 +0100 | [diff] [blame] | 51 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 52 | ClDirectConvConfigArray<ConfigurationFunctionExecutorPtr> configs_G71( |
| 53 | &ClDirectConvDefaultConfigBifrost::configure_G71_f32, &ClDirectConvDefaultConfigBifrost::configure_G71_f16, |
| 54 | &ClDirectConvDefaultConfigBifrost::configure_G71_u8); |
Gian Marco Iodice | 2cc50b3 | 2022-05-30 14:41:49 +0100 | [diff] [blame] | 55 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 56 | ClDirectConvConfigArray<ConfigurationFunctionExecutorPtr> configs_default( |
| 57 | &ClDirectConvDefaultConfigBifrost::configure_default_f32, |
| 58 | &ClDirectConvDefaultConfigBifrost::configure_default_f16, &ClDirectConvDefaultConfigBifrost::configure_G71_u8); |
Gian Marco Iodice | 2cc50b3 | 2022-05-30 14:41:49 +0100 | [diff] [blame] | 59 | |
| 60 | ConfigurationFunctionExecutorPtr func = nullptr; |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 61 | switch (_target) |
Gian Marco Iodice | 2cc50b3 | 2022-05-30 14:41:49 +0100 | [diff] [blame] | 62 | { |
| 63 | case GPUTarget::G71: |
| 64 | func = configs_G71.get_function(src->data_type()); |
| 65 | break; |
| 66 | default: |
| 67 | func = configs_default.get_function(src->data_type()); |
| 68 | break; |
| 69 | } |
| 70 | |
| 71 | ARM_COMPUTE_ERROR_ON_MSG(func == nullptr, "Data type not supported for direct convolution"); |
| 72 | return (this->*func)(src, wei, conv_info); |
| 73 | } |
| 74 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 75 | DirectConvComputeKernelInfo ClDirectConvDefaultConfigBifrost::configure_G71_f32(const ITensorInfo *src, |
| 76 | const ITensorInfo *wei, |
| 77 | const PadStrideInfo &conv_info) |
Gian Marco Iodice | 2cc50b3 | 2022-05-30 14:41:49 +0100 | [diff] [blame] | 78 | { |
| 79 | DirectConvComputeKernelInfo desc; |
| 80 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 81 | if (src->data_layout() == DataLayout::NHWC) |
Gian Marco Iodice | 2cc50b3 | 2022-05-30 14:41:49 +0100 | [diff] [blame] | 82 | { |
| 83 | // Get the output shape |
| 84 | TensorShape output_shape = misc::shape_calculator::compute_deep_convolution_shape(*src, *wei, conv_info); |
| 85 | |
| 86 | desc.n0 = 4; |
| 87 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 88 | if (output_shape[0] > 16) |
Gian Marco Iodice | 2cc50b3 | 2022-05-30 14:41:49 +0100 | [diff] [blame] | 89 | { |
| 90 | desc.m0 = 2; |
| 91 | } |
| 92 | |
| 93 | desc.k0 = 8; |
| 94 | |
| 95 | desc.export_weights_to_cl_image = false; |
| 96 | } |
| 97 | |
| 98 | return desc; |
| 99 | } |
| 100 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 101 | DirectConvComputeKernelInfo ClDirectConvDefaultConfigBifrost::configure_G71_f16(const ITensorInfo *src, |
| 102 | const ITensorInfo *wei, |
| 103 | const PadStrideInfo &conv_info) |
Gian Marco Iodice | 2cc50b3 | 2022-05-30 14:41:49 +0100 | [diff] [blame] | 104 | { |
| 105 | DirectConvComputeKernelInfo desc; |
| 106 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 107 | if (src->data_layout() == DataLayout::NHWC) |
Gian Marco Iodice | 2cc50b3 | 2022-05-30 14:41:49 +0100 | [diff] [blame] | 108 | { |
| 109 | // Get the output shape |
| 110 | TensorShape output_shape = misc::shape_calculator::compute_deep_convolution_shape(*src, *wei, conv_info); |
| 111 | |
| 112 | desc.n0 = 4; |
| 113 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 114 | if (output_shape[0] > 16) |
Gian Marco Iodice | 2cc50b3 | 2022-05-30 14:41:49 +0100 | [diff] [blame] | 115 | { |
| 116 | desc.m0 = 4; |
| 117 | } |
| 118 | |
| 119 | desc.k0 = 8; |
| 120 | |
| 121 | desc.export_weights_to_cl_image = false; |
| 122 | } |
| 123 | |
| 124 | return desc; |
| 125 | } |
| 126 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 127 | DirectConvComputeKernelInfo ClDirectConvDefaultConfigBifrost::configure_G71_u8(const ITensorInfo *src, |
| 128 | const ITensorInfo *wei, |
| 129 | const PadStrideInfo &conv_info) |
Gian Marco Iodice | 2cc50b3 | 2022-05-30 14:41:49 +0100 | [diff] [blame] | 130 | { |
| 131 | DirectConvComputeKernelInfo desc; |
| 132 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 133 | if (src->data_layout() == DataLayout::NHWC) |
Gian Marco Iodice | 2cc50b3 | 2022-05-30 14:41:49 +0100 | [diff] [blame] | 134 | { |
| 135 | // Get the output shape |
| 136 | TensorShape output_shape = misc::shape_calculator::compute_deep_convolution_shape(*src, *wei, conv_info); |
| 137 | |
| 138 | desc.n0 = 4; |
| 139 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 140 | if (output_shape[0] > 16) |
Gian Marco Iodice | 2cc50b3 | 2022-05-30 14:41:49 +0100 | [diff] [blame] | 141 | { |
| 142 | desc.m0 = 4; |
| 143 | } |
| 144 | |
| 145 | desc.k0 = 16; |
| 146 | |
| 147 | desc.export_weights_to_cl_image = false; |
| 148 | } |
| 149 | |
| 150 | return desc; |
| 151 | } |
| 152 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 153 | DirectConvComputeKernelInfo ClDirectConvDefaultConfigBifrost::configure_default_f32(const ITensorInfo *src, |
| 154 | const ITensorInfo *wei, |
| 155 | const PadStrideInfo &conv_info) |
Gian Marco Iodice | 2cc50b3 | 2022-05-30 14:41:49 +0100 | [diff] [blame] | 156 | { |
| 157 | DirectConvComputeKernelInfo desc; |
| 158 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 159 | if (src->data_layout() == DataLayout::NHWC) |
Gian Marco Iodice | 2cc50b3 | 2022-05-30 14:41:49 +0100 | [diff] [blame] | 160 | { |
| 161 | // Get the output shape |
| 162 | TensorShape output_shape = misc::shape_calculator::compute_deep_convolution_shape(*src, *wei, conv_info); |
| 163 | |
| 164 | desc.n0 = 4; |
| 165 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 166 | if (output_shape[0] > 16) |
Gian Marco Iodice | 2cc50b3 | 2022-05-30 14:41:49 +0100 | [diff] [blame] | 167 | { |
| 168 | desc.m0 = 2; |
| 169 | } |
| 170 | |
| 171 | desc.k0 = 8; |
| 172 | |
Gian Marco Iodice | ad9a7ed | 2022-09-16 14:14:21 +0100 | [diff] [blame] | 173 | desc.export_weights_to_cl_image = export_to_cl_image(wei); |
Gian Marco Iodice | 2cc50b3 | 2022-05-30 14:41:49 +0100 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | return desc; |
| 177 | } |
| 178 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 179 | DirectConvComputeKernelInfo ClDirectConvDefaultConfigBifrost::configure_default_f16(const ITensorInfo *src, |
| 180 | const ITensorInfo *wei, |
| 181 | const PadStrideInfo &conv_info) |
Gian Marco Iodice | 2cc50b3 | 2022-05-30 14:41:49 +0100 | [diff] [blame] | 182 | { |
| 183 | DirectConvComputeKernelInfo desc; |
| 184 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 185 | if (src->data_layout() == DataLayout::NHWC) |
Gian Marco Iodice | 2cc50b3 | 2022-05-30 14:41:49 +0100 | [diff] [blame] | 186 | { |
| 187 | // Get the output shape |
| 188 | TensorShape output_shape = misc::shape_calculator::compute_deep_convolution_shape(*src, *wei, conv_info); |
| 189 | |
| 190 | desc.n0 = 4; |
| 191 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 192 | if (output_shape[0] > 16) |
Gian Marco Iodice | 2cc50b3 | 2022-05-30 14:41:49 +0100 | [diff] [blame] | 193 | { |
| 194 | desc.m0 = 4; |
| 195 | } |
| 196 | |
| 197 | desc.k0 = 8; |
| 198 | |
Gian Marco Iodice | ad9a7ed | 2022-09-16 14:14:21 +0100 | [diff] [blame] | 199 | desc.export_weights_to_cl_image = export_to_cl_image(wei); |
Gian Marco Iodice | 2cc50b3 | 2022-05-30 14:41:49 +0100 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | return desc; |
| 203 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 204 | } // namespace cl_direct_conv |
Gian Marco Iodice | 2cc50b3 | 2022-05-30 14:41:49 +0100 | [diff] [blame] | 205 | } // namespace arm_compute |