Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 1 | /* |
SiCong Li | c5ab4df | 2023-10-17 17:38:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2021-2023 Arm Limited. |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [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 | */ |
Georgios Pinitas | 7891a73 | 2021-08-20 21:39:25 +0100 | [diff] [blame] | 24 | #include "src/cpu/operators/CpuWinogradConv2d.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 25 | |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 26 | #include "arm_compute/core/Error.h" |
| 27 | #include "arm_compute/core/Utils.h" |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 28 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
| 29 | #include "arm_compute/core/utils/quantization/AsymmHelpers.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 30 | #include "arm_compute/core/Validate.h" |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 31 | #include "arm_compute/runtime/FunctionDescriptors.h" |
| 32 | #include "arm_compute/runtime/NEON/NEScheduler.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 33 | |
ramelg01 | 3ae3d88 | 2021-09-12 23:07:47 +0100 | [diff] [blame] | 34 | #include "src/common/utils/Log.h" |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 35 | #include "src/core/CPP/Validate.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 36 | #include "src/core/helpers/MemoryHelpers.h" |
| 37 | #include "src/core/helpers/WindowHelpers.h" |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 38 | #include "src/core/NEON/kernels/assembly/winograd.hpp" |
| 39 | #include "src/core/NEON/kernels/convolution/common/tensor.hpp" |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 40 | #include "src/core/NEON/kernels/convolution/common/utils.hpp" |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 41 | #include "src/core/utils/AssemblyUtils.h" |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 42 | #include "src/cpu/kernels/assembly/arm_gemm.hpp" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 43 | #include "src/cpu/kernels/CpuWinogradConv2dKernel.h" |
Georgios Pinitas | 7891a73 | 2021-08-20 21:39:25 +0100 | [diff] [blame] | 44 | #include "src/cpu/operators/CpuActivation.h" |
| 45 | #include "src/cpu/operators/CpuPermute.h" |
Georgios Pinitas | 7891a73 | 2021-08-20 21:39:25 +0100 | [diff] [blame] | 46 | #include "src/cpu/utils/CpuAuxTensorHandler.h" |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 47 | #include "support/Cast.h" |
| 48 | |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 49 | namespace arm_compute |
| 50 | { |
| 51 | namespace cpu |
| 52 | { |
| 53 | using namespace arm_compute::experimental; |
| 54 | using namespace arm_compute::utils::cast; |
| 55 | |
| 56 | namespace |
| 57 | { |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 58 | inline Tensor4DShape internal_get_shape(const ITensorInfo *in) |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 59 | { |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 60 | const DataLayout data_layout = in->data_layout(); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 61 | const int in_width = in->dimension(get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH)); |
| 62 | const int in_height = in->dimension(get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT)); |
| 63 | const int in_channels = in->dimension(get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL)); |
| 64 | const int in_batches = in->dimension(get_data_layout_dimension_index(data_layout, DataLayoutDimension::BATCHES)); |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 65 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 66 | return Tensor4DShape{in_batches, in_height, in_width, in_channels}; |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 67 | } |
| 68 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 69 | Status validate_arguments(const ITensorInfo *src, |
| 70 | const ITensorInfo *weights, |
| 71 | const ITensorInfo *biases, |
| 72 | const ITensorInfo *dst, |
| 73 | const PadStrideInfo &conv_info) |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 74 | { |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 75 | ARM_COMPUTE_UNUSED(dst, weights); |
Michele Di Giorgio | d9cdf14 | 2021-07-02 15:17:08 +0100 | [diff] [blame] | 76 | ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(src); |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 77 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 78 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(conv_info.stride().first != 1 || conv_info.stride().second != 1, |
| 79 | "Winograd layer only supports unit strides."); |
| 80 | if (biases != nullptr) |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 81 | { |
Michele Di Giorgio | d9cdf14 | 2021-07-02 15:17:08 +0100 | [diff] [blame] | 82 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(src, biases); |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 83 | ARM_COMPUTE_RETURN_ERROR_ON(biases->num_dimensions() > 1); |
| 84 | } |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 85 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(src, 1, DataType::F16, DataType::F32); |
| 86 | ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(src, weights); |
| 87 | return Status{}; |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 88 | } |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 89 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 90 | bool get_winograd_kernel_implementation(const ITensorInfo *src, |
| 91 | const ITensorInfo *weights, |
| 92 | const ITensorInfo *dst, |
| 93 | const PadStrideInfo &conv_info, |
| 94 | const ActivationLayerInfo &act_info, |
| 95 | bool enable_fast_math, |
| 96 | arm_conv::winograd::WinogradImpl *winograd_impl, |
| 97 | std::unique_ptr<arm_conv::ConvolutionArgs> &conv_args) |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 98 | { |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 99 | arm_conv::winograd::WinogradConfig winograd_cfg; |
| 100 | arm_gemm::GemmConfig cfg; |
| 101 | |
| 102 | const DataType data_type = src->data_type(); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 103 | Tensor4DShape in_shape{internal_get_shape(src)}; |
| 104 | Tensor4DShape out_shape{internal_get_shape(dst)}; |
| 105 | Tensor4DShape kernel_shape{internal_get_shape(weights)}; |
David Svantesson | ded5b18 | 2023-08-02 14:23:00 +0000 | [diff] [blame] | 106 | uint32_t nthreads = NEScheduler::num_threads(); |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 107 | // Get configuration arguments for Winograd |
| 108 | winograd_cfg.output_rows = 0; |
| 109 | winograd_cfg.output_cols = 0; |
| 110 | conv_args = std::make_unique<arm_conv::ConvolutionArgs>( |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 111 | in_shape.n_batches, |
| 112 | arm_conv::Shape2D{static_cast<uint32_t>(in_shape.n_rows), static_cast<uint32_t>(in_shape.n_cols)}, |
| 113 | in_shape.n_channels, conv_info.pad_top(), conv_info.pad_left(), |
| 114 | arm_conv::Shape2D{static_cast<uint32_t>(out_shape.n_rows), static_cast<uint32_t>(out_shape.n_cols)}, |
| 115 | out_shape.n_channels, |
| 116 | arm_conv::Shape2D{static_cast<uint32_t>(kernel_shape.n_rows), static_cast<uint32_t>(kernel_shape.n_cols)}, |
| 117 | assembly_utils::map_to_arm_gemm_activation(act_info)); |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 118 | |
| 119 | bool success = false; |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 120 | if (data_type == DataType::F32) |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 121 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 122 | success = arm_conv::winograd::get_implementation<float>(*winograd_impl, &CPUInfo::get(), *conv_args, nthreads, |
| 123 | enable_fast_math, &winograd_cfg, nullptr); |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 124 | } |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 125 | #if defined(__aarch64__) && defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 126 | else if (data_type == DataType::F16) |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 127 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 128 | success = arm_conv::winograd::get_implementation<__fp16>(*winograd_impl, &CPUInfo::get(), *conv_args, nthreads, |
| 129 | enable_fast_math, &winograd_cfg, nullptr); |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 130 | } |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 131 | #endif // defined(__aarch64__) && defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) |
| 132 | else |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 133 | { |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 134 | success = false; |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 135 | } |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 136 | return success; |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 137 | } |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 138 | inline bool fuse_function_supported(const ActivationLayerInfo &act_info) |
| 139 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 140 | return act_info.activation() == ActivationLayerInfo::ActivationFunction::RELU || |
| 141 | act_info.activation() == ActivationLayerInfo::ActivationFunction::BOUNDED_RELU; |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 142 | } |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 143 | } // namespace |
| 144 | |
| 145 | CpuWinogradConv2d::CpuWinogradConv2d() |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 146 | |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 147 | : _gemm_function(std::make_unique<CpuGemm>()), |
| 148 | _activation_func(std::make_unique<CpuActivation>()), |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 149 | _transform_input_kernel(nullptr), |
| 150 | _transform_output_kernel(nullptr), |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 151 | _permute_input(std::make_unique<CpuPermute>()), |
| 152 | _permute_output(std::make_unique<CpuPermute>()), |
| 153 | _permute_weights(std::make_unique<CpuPermute>()), |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 154 | _aux_mem(AuxTensorIdx::Count), |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 155 | _conv_args{nullptr}, |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 156 | _winograd_impl{}, |
| 157 | _data_layout(), |
| 158 | _winograd_transformed_input{}, |
| 159 | _winograd_transformed_output{}, |
| 160 | _winograd_transformed_weights{}, |
| 161 | _input_workspace(), |
| 162 | _output_workspace(), |
| 163 | _weights_hwio(), |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 164 | _input_nhwc(), |
| 165 | _output_nhwc(), |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 166 | _is_prepared{false}, |
| 167 | _run_activation{false} |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 168 | { |
| 169 | } |
| 170 | |
| 171 | CpuWinogradConv2d::~CpuWinogradConv2d() = default; |
| 172 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 173 | void CpuWinogradConv2d::configure(const ITensorInfo *src, |
| 174 | const ITensorInfo *weights, |
| 175 | const ITensorInfo *biases, |
| 176 | ITensorInfo *dst, |
| 177 | const PadStrideInfo &conv_info, |
| 178 | const ActivationLayerInfo &act_info, |
| 179 | bool enable_fast_math) |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 180 | { |
| 181 | ARM_COMPUTE_ERROR_ON_NULLPTR(src, weights, dst); |
Ramy Elgammal | e4e3b2e | 2022-09-07 12:38:46 +0100 | [diff] [blame] | 182 | ARM_COMPUTE_ERROR_THROW_ON(validate(src, weights, biases, dst, conv_info, act_info, enable_fast_math)); |
ramelg01 | 3ae3d88 | 2021-09-12 23:07:47 +0100 | [diff] [blame] | 183 | ARM_COMPUTE_LOG_PARAMS(src, weights, biases, dst, conv_info, act_info, enable_fast_math); |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 184 | ARM_COMPUTE_UNUSED(biases); |
| 185 | const DataType data_type = src->data_type(); |
David Svantesson | ded5b18 | 2023-08-02 14:23:00 +0000 | [diff] [blame] | 186 | uint32_t nthreads = NEScheduler::num_threads(); |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 187 | _data_layout = src->data_layout(); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 188 | const Tensor4DShape kernel_shape{internal_get_shape(weights)}; |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 189 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 190 | bool success = get_winograd_kernel_implementation(src, weights, dst, conv_info, act_info, enable_fast_math, |
| 191 | &_winograd_impl, _conv_args); |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 192 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 193 | ARM_COMPUTE_EXIT_ON_MSG_VAR(!success, "Unsupported kernel size: %d x %d.\n", kernel_shape.n_rows, |
| 194 | kernel_shape.n_cols); |
| 195 | ARM_COMPUTE_LOG_MSG_WITH_FORMAT_ACL(arm_compute::logging::LogLevel::INFO, "Using input transform: %s\n", |
| 196 | _winograd_impl.input_transform->get_name().c_str()); |
| 197 | ARM_COMPUTE_LOG_MSG_WITH_FORMAT_ACL(arm_compute::logging::LogLevel::INFO, "Using weight transform: %s\n", |
| 198 | _winograd_impl.input_transform->get_name().c_str()); |
| 199 | ARM_COMPUTE_LOG_MSG_WITH_FORMAT_ACL(arm_compute::logging::LogLevel::INFO, "Using output transform: %s\n", |
| 200 | _winograd_impl.input_transform->get_name().c_str()); |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 201 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 202 | const bool has_impl = ((_winograd_impl.input_transform != nullptr) && |
| 203 | (_winograd_impl.output_transform != nullptr) && (_winograd_impl.gemm_args != nullptr)); |
| 204 | if (has_impl) |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 205 | { |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 206 | // Determine how much working space is required, allocate it. |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 207 | const size_t input_workspace_size = |
| 208 | _winograd_impl.input_transform->get_working_space_size(*_conv_args, nthreads); |
| 209 | const size_t output_workspace_size = |
| 210 | _winograd_impl.output_transform->get_working_space_size(*_conv_args, nthreads); |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 211 | |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 212 | TensorInfo input_workspace_info(TensorShape(input_workspace_size), 1, DataType::U8); |
| 213 | TensorInfo output_workspace_info(TensorShape(output_workspace_size), 1, DataType::U8); |
| 214 | _input_workspace = input_workspace_info; |
| 215 | _output_workspace = output_workspace_info; |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 216 | |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 217 | const auto &wds = _winograd_impl.winograd_spec; |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 218 | |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 219 | // Preparing winograd transformed input tensor |
| 220 | const size_t data_type_size = src->element_size(); |
| 221 | const uint32_t m = _winograd_impl.gemm_args->_Msize; // Total number of tiles |
| 222 | const uint32_t k = _winograd_impl.gemm_args->_Ksize; // Input channels |
| 223 | const uint32_t n = _winograd_impl.gemm_args->_Nsize; // Output channels |
| 224 | const uint32_t n_gemms = _winograd_impl.gemm_args->_nmulti; |
| 225 | const uint32_t n_batches = _winograd_impl.gemm_args->_nbatches; |
| 226 | constexpr size_t storage_alignment = 64; |
| 227 | |
| 228 | const TensorShape a_shape(k, m, n_batches, n_gemms); |
| 229 | Strides a_strides(data_type_size); |
| 230 | a_strides.set(1, data_type_size * _winograd_impl.winograd_spec.input_ld_row); |
| 231 | a_strides.set(2, data_type_size * _winograd_impl.winograd_spec.input_ld_batch); |
| 232 | a_strides.set(3, data_type_size * _winograd_impl.winograd_spec.input_ld_matrix); |
| 233 | |
| 234 | const TensorShape b_shape(n, k, n_gemms); |
| 235 | Strides b_strides(data_type_size); |
| 236 | b_strides.set(1, data_type_size * _winograd_impl.winograd_spec.weight_ld_row); |
| 237 | b_strides.set(2, data_type_size * _winograd_impl.winograd_spec.weight_ld_matrix); |
| 238 | |
| 239 | const TensorShape d_shape(n, m, n_batches, n_gemms); |
| 240 | Strides d_strides(data_type_size); |
| 241 | d_strides.set(1, data_type_size * _winograd_impl.winograd_spec.output_ld_row); |
| 242 | d_strides.set(2, data_type_size * _winograd_impl.winograd_spec.output_ld_batch); |
| 243 | d_strides.set(3, data_type_size * _winograd_impl.winograd_spec.output_ld_matrix); |
| 244 | |
| 245 | TensorInfo a_info{}; |
| 246 | TensorInfo b_info{}; |
| 247 | TensorInfo d_info{}; |
| 248 | a_info.init(a_shape, 1, data_type, a_strides, 0, wds.input_matrix_size_bytes); |
| 249 | b_info.init(b_shape, 1, data_type, b_strides, 0, wds.weight_matrix_size_bytes); |
| 250 | d_info.init(d_shape, 1, data_type, d_strides, 0, wds.output_matrix_size_bytes); |
| 251 | |
| 252 | _winograd_transformed_input = a_info; |
| 253 | _winograd_transformed_weights = b_info; |
| 254 | _winograd_transformed_output = d_info; |
| 255 | |
| 256 | PermutationVector weights_permutation_vector(3U, 0U, 1U, 2U); |
| 257 | |
| 258 | // Configure the kernel to transform the input tensor from NCHW -> NHWC |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 259 | if (_data_layout == DataLayout::NCHW) |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 260 | { |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 261 | _permute_input->configure(src, &_input_nhwc, PermutationVector(2U, 0U, 1U)); |
| 262 | weights_permutation_vector = PermutationVector(3U, 2U, 0U, 1U); |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 263 | } |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 264 | |
| 265 | // Re-order a weight tensor from [Output feature map x Input feature map x Height x Width] to [Height x Width x Input feature map x Output feature map] |
| 266 | _permute_weights->configure(weights, &_weights_hwio, weights_permutation_vector); |
| 267 | |
| 268 | // Reorder the convoluted output to ACL's ordering NCHW |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 269 | if (_data_layout == DataLayout::NCHW) |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 270 | { |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 271 | // configure and allocate dst tensor to be used to convert from winograd domain to spatial domain when calling to reshape_output() |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 272 | TensorInfo info(TensorShape(dst->dimension(2), dst->dimension(0), dst->dimension(1), dst->dimension(3)), 1, |
| 273 | dst->data_type()); |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 274 | _output_nhwc = info; |
| 275 | _permute_output->configure(&_output_nhwc, dst, PermutationVector(1U, 2U, 0U)); |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 276 | } |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 277 | |
Viet-Hoa Do | 65c8db8 | 2022-08-03 16:39:23 +0100 | [diff] [blame] | 278 | // Configure input transform kernel |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 279 | _transform_input_kernel = |
| 280 | std::make_unique<CpuWinogradConv2dTransformInputKernel>(_winograd_impl, *_conv_args, nthreads); |
Viet-Hoa Do | 65c8db8 | 2022-08-03 16:39:23 +0100 | [diff] [blame] | 281 | |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 282 | // Configure GEMM function |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 283 | _gemm_function->configure(&_winograd_transformed_input, &_winograd_transformed_weights, nullptr, |
| 284 | &_winograd_transformed_output, 1.0f, 0.f); |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 285 | |
Viet-Hoa Do | 65c8db8 | 2022-08-03 16:39:23 +0100 | [diff] [blame] | 286 | // Configure output transform kernel |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 287 | _transform_output_kernel = |
| 288 | std::make_unique<CpuWinogradConv2dTransformOutputKernel>(_winograd_impl, *_conv_args, nthreads); |
Viet-Hoa Do | 65c8db8 | 2022-08-03 16:39:23 +0100 | [diff] [blame] | 289 | |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 290 | //Configure Activation Layer |
| 291 | _run_activation = act_info.enabled() && !fuse_function_supported(act_info); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 292 | if (_run_activation) |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 293 | { |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 294 | _activation_func->configure(dst, nullptr, act_info); |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 295 | } |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 296 | |
SiCong Li | c5ab4df | 2023-10-17 17:38:57 +0100 | [diff] [blame] | 297 | const auto mm_mem_req = _gemm_function->workspace(); |
| 298 | for (unsigned int slot = 0; slot < mm_mem_req.size(); ++slot) |
| 299 | { |
| 300 | _aux_mem[slot] = mm_mem_req[slot]; |
| 301 | } |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 302 | |
| 303 | // Request temporary memory. Overlap memory needed for Input/Output transformations as they run on different non-overlapping time-steps. |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 304 | _aux_mem[TransformedInput] = MemoryInfo(offset_int_vec(TransformedInput), MemoryLifetime::Temporary, |
| 305 | wds.input_matrix_size_bytes, storage_alignment); |
| 306 | _aux_mem[TransformedOutput] = MemoryInfo(offset_int_vec(TransformedOutput), MemoryLifetime::Temporary, |
| 307 | wds.output_matrix_size_bytes, storage_alignment); |
| 308 | _aux_mem[WorkspaceIO] = MemoryInfo(offset_int_vec(WorkspaceIO), MemoryLifetime::Temporary, |
| 309 | std::max(input_workspace_size, output_workspace_size)); |
| 310 | _aux_mem[PermutedWeights] = |
| 311 | MemoryInfo(offset_int_vec(PermutedWeights), MemoryLifetime::Prepare, _weights_hwio.total_size()); |
| 312 | _aux_mem[TransformedWeights] = MemoryInfo(offset_int_vec(TransformedWeights), MemoryLifetime::Persistent, |
| 313 | wds.weight_matrix_size_bytes, storage_alignment); |
| 314 | if (_data_layout == DataLayout::NCHW) |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 315 | { |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 316 | _aux_mem[PermutedInput].merge(offset_int_vec(PermutedInput), src->total_size()); |
| 317 | _aux_mem[PermutedOutput].merge(offset_int_vec(PermutedOutput), dst->total_size()); |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 318 | } |
Georgios Pinitas | 87a74ef | 2021-08-20 17:26:45 +0100 | [diff] [blame] | 319 | } |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 320 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 321 | Status CpuWinogradConv2d::validate(const ITensorInfo *src, |
| 322 | const ITensorInfo *weights, |
| 323 | const ITensorInfo *biases, |
| 324 | const ITensorInfo *dst, |
| 325 | const PadStrideInfo &conv_info, |
| 326 | const ActivationLayerInfo &act_info, |
| 327 | bool enable_fast_math) |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 328 | { |
Michele Di Giorgio | d9cdf14 | 2021-07-02 15:17:08 +0100 | [diff] [blame] | 329 | ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(src, weights, dst); |
| 330 | ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(src, weights, biases, dst, conv_info)); |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 331 | |
Ramy Elgammal | e4e3b2e | 2022-09-07 12:38:46 +0100 | [diff] [blame] | 332 | // Disable winograd for fp16 if fast math is false. |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 333 | if (!enable_fast_math) |
Ramy Elgammal | e4e3b2e | 2022-09-07 12:38:46 +0100 | [diff] [blame] | 334 | { |
| 335 | ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(src, 1, DataType::F32); |
| 336 | } |
| 337 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 338 | const Tensor4DShape kernel_shape{internal_get_shape(weights)}; |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 339 | arm_conv::winograd::WinogradImpl winograd_impl{}; |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 340 | |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 341 | std::unique_ptr<arm_conv::ConvolutionArgs> conv_args; |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 342 | const bool success = get_winograd_kernel_implementation(src, weights, dst, conv_info, act_info, enable_fast_math, |
| 343 | &winograd_impl, conv_args); |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 344 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 345 | ARM_COMPUTE_RETURN_ERROR_ON_MSG_VAR(success == false, "Unsupported kernel size: %d x %d.\n", kernel_shape.n_rows, |
| 346 | kernel_shape.n_cols); |
| 347 | ARM_COMPUTE_LOG_MSG_WITH_FORMAT_ACL(arm_compute::logging::LogLevel::INFO, "Using input transform: %s\n", |
| 348 | winograd_impl.input_transform->get_name().c_str()); |
| 349 | ARM_COMPUTE_LOG_MSG_WITH_FORMAT_ACL(arm_compute::logging::LogLevel::INFO, "Using weight transform: %s\n", |
| 350 | winograd_impl.input_transform->get_name().c_str()); |
| 351 | ARM_COMPUTE_LOG_MSG_WITH_FORMAT_ACL(arm_compute::logging::LogLevel::INFO, "Using output transform: %s\n", |
| 352 | winograd_impl.input_transform->get_name().c_str()); |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 353 | return Status{}; |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | void CpuWinogradConv2d::run(ITensorPack &tensors) |
| 357 | { |
| 358 | prepare(tensors); |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 359 | auto src = tensors.get_const_tensor(ACL_SRC_0); |
| 360 | auto biases = tensors.get_const_tensor(ACL_SRC_2); |
| 361 | auto output = tensors.get_tensor(ACL_DST); |
| 362 | Window win; |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 363 | |
David Svantesson | ded5b18 | 2023-08-02 14:23:00 +0000 | [diff] [blame] | 364 | const uint32_t nthreads = NEScheduler::num_threads(); |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 365 | |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 366 | // The Winograd transform implementation does fine-grain threading inside the transforms. Just pass thread_id and nthreads. |
| 367 | win.set(Window::DimX, Window::Dimension(0, nthreads, 1)); |
| 368 | |
| 369 | // Wrap the winograd-domain tensorInfos created in configuration in tensors and allocate the required memory. |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 370 | CpuAuxTensorHandler input_nhwc(offset_int_vec(PermutedInput), _input_nhwc, tensors, true); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 371 | CpuAuxTensorHandler winograd_input_transformed(offset_int_vec(TransformedInput), _winograd_transformed_input, |
| 372 | tensors, true); |
Georgios Pinitas | 87a74ef | 2021-08-20 17:26:45 +0100 | [diff] [blame] | 373 | CpuAuxTensorHandler input_workspace(offset_int_vec(WorkspaceIO), _input_workspace, tensors, true); |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 374 | const bool is_nchw = _data_layout == DataLayout::NCHW; |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 375 | if (is_nchw) |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 376 | { |
| 377 | //Bring channels to the front as Winograd code expects the tensor to be in the format NHWC |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 378 | ITensorPack pack{{ACL_SRC, src}, {ACL_DST, input_nhwc.get()}}; |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 379 | _permute_input->run(pack); |
| 380 | } |
| 381 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 382 | CpuAuxTensorHandler winograd_output_transformed(offset_int_vec(TransformedOutput), _winograd_transformed_output, |
| 383 | tensors, true); |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 384 | CpuAuxTensorHandler output_workspace(offset_int_vec(WorkspaceIO), _output_workspace, tensors, true); |
| 385 | CpuAuxTensorHandler output_nhwc(offset_int_vec(PermutedOutput), _output_nhwc, tensors, true); |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 386 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 387 | ITensorPack transform_input_pack{{ACL_SRC, is_nchw ? input_nhwc.get() : src}, |
| 388 | {ACL_DST, winograd_input_transformed.get()}, |
| 389 | {ACL_INT, input_workspace.get()}}; |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 390 | NEScheduler::get().schedule_op(_transform_input_kernel.get(), Window::DimX, win, transform_input_pack); |
| 391 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 392 | CpuAuxTensorHandler winograd_weights_transformed(offset_int_vec(TransformedWeights), _winograd_transformed_weights, |
| 393 | tensors, true); |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 394 | |
| 395 | // Run 16 GEMMs in multiple threads, each kernel runs one or more GEMMs |
Georgios Pinitas | 87a74ef | 2021-08-20 17:26:45 +0100 | [diff] [blame] | 396 | ITensorPack gemm_pack = tensors; |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 397 | gemm_pack.add_const_tensor(ACL_SRC, winograd_input_transformed.get()); |
| 398 | gemm_pack.add_const_tensor(ACL_SRC_1, winograd_weights_transformed.get()); |
Georgios Pinitas | 87a74ef | 2021-08-20 17:26:45 +0100 | [diff] [blame] | 399 | gemm_pack.add_const_tensor(ACL_BIAS, nullptr); |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 400 | gemm_pack.add_tensor(ACL_DST, winograd_output_transformed.get()); |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 401 | _gemm_function->run(gemm_pack); |
| 402 | |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 403 | // Output transform |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 404 | ITensorPack transform_output_pack{{ACL_SRC_0, winograd_output_transformed.get()}, |
| 405 | {ACL_DST, is_nchw ? output_nhwc.get() : output}, |
| 406 | {ACL_SRC_1, biases}, |
| 407 | {ACL_INT, output_workspace.get()}}; |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 408 | NEScheduler::get().schedule_op(_transform_output_kernel.get(), Window::DimX, win, transform_output_pack); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 409 | if (is_nchw) |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 410 | { |
| 411 | // Reorder the convoluted output to ACL's ordering NCHW |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 412 | ITensorPack pack{{ACL_SRC, output_nhwc.get()}, {ACL_DST, output}}; |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 413 | _permute_output->run(pack); |
| 414 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 415 | if (_run_activation) |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 416 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 417 | ITensorPack pack{{ACL_SRC, output}, {ACL_DST, output}}; |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 418 | _activation_func->run(pack); |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | void CpuWinogradConv2d::prepare(ITensorPack &tensors) |
| 423 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 424 | if (!_is_prepared) |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 425 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 426 | const ITensor *weights = tensors.get_const_tensor(ACL_SRC_1); |
| 427 | ITensor *weights_aux = |
| 428 | utils::cast::polymorphic_cast<ITensor *>(tensors.get_tensor(offset_int_vec(PermutedWeights))); |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 429 | |
| 430 | CpuAuxTensorHandler permuted_weights(_weights_hwio, *weights_aux); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 431 | ITensorPack permute_tensors{{ACL_SRC, weights}, {ACL_DST, permuted_weights.get()}}; |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 432 | _permute_weights->run(permute_tensors); |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 433 | const int element_size_in_bytes = permuted_weights.get()->info()->element_size(); |
| 434 | // Weights were in OHWI format, before being permuted "permuted_weights" to be in HWIO format. |
| 435 | const unsigned int height_idx = 3; // H in HWIO |
| 436 | const unsigned int width_idx = 2; // W in HWIO |
| 437 | const unsigned int channel_idx = 1; // I in HWIO |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 438 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 439 | const int permuted_weight_row_stride = |
| 440 | permuted_weights.get()->info()->strides_in_bytes()[height_idx] / element_size_in_bytes; |
| 441 | const int permuted_weight_col_stride = |
| 442 | permuted_weights.get()->info()->strides_in_bytes()[width_idx] / element_size_in_bytes; |
| 443 | const int permuted_weight_channel_stride = |
| 444 | permuted_weights.get()->info()->strides_in_bytes()[channel_idx] / element_size_in_bytes; |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 445 | |
| 446 | // Wrap the winograd-domain transformed weight TensorInfo in Auxiliary tensor and allocate the required memory. |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 447 | ITensor *weights_transf = |
| 448 | utils::cast::polymorphic_cast<ITensor *>(tensors.get_tensor(offset_int_vec(TransformedWeights))); |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 449 | ARM_COMPUTE_ERROR_ON_NULLPTR(weights_transf); |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 450 | CpuAuxTensorHandler winograd_transformed_weights(_winograd_transformed_weights, *weights_transf); |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 451 | |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 452 | const void *permuted_weights_ptr; |
| 453 | void *win_wght_transf_ptr; |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 454 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 455 | permuted_weights_ptr = reinterpret_cast<const void *>( |
| 456 | permuted_weights.get()->buffer() + permuted_weights.get()->info()->offset_first_element_in_bytes()); |
| 457 | win_wght_transf_ptr = |
| 458 | reinterpret_cast<void *>(winograd_transformed_weights.get()->buffer() + |
| 459 | winograd_transformed_weights.get()->info()->offset_first_element_in_bytes()); |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 460 | |
| 461 | // Prepare Weights |
| 462 | _winograd_impl.weight_transform->execute( |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 463 | *_conv_args, permuted_weights_ptr, permuted_weight_row_stride, permuted_weight_col_stride, |
| 464 | permuted_weight_channel_stride, win_wght_transf_ptr, _winograd_impl.winograd_spec, 0, 1 // Thread 1 of 1 |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 465 | ); |
Georgios Pinitas | 6634194 | 2021-07-30 12:21:07 +0100 | [diff] [blame] | 466 | ITensorPack gemm_pack = tensors; |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 467 | gemm_pack.add_const_tensor(ACL_SRC_1, winograd_transformed_weights.get()); |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 468 | _gemm_function->prepare(gemm_pack); |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 469 | _is_prepared = 1; |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 470 | } |
| 471 | } |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 472 | experimental::MemoryRequirements CpuWinogradConv2d::workspace() const |
| 473 | { |
| 474 | return _aux_mem; |
| 475 | } |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 476 | |
Michalis Spyrou | 96f977e | 2021-07-01 12:20:56 +0100 | [diff] [blame] | 477 | } // namespace cpu |
ramelg01 | a1f7851 | 2022-06-29 16:28:10 +0100 | [diff] [blame] | 478 | } // namespace arm_compute |