aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorramelg01 <ramy.elgammal@arm.com>2022-06-29 16:28:10 +0100
committerRamy Elgammal <ramy.elgammal@arm.com>2022-07-14 17:56:01 +0000
commita1f7851e2f776610019db8725c2963c36b0c85eb (patch)
treeeddf90d87594bec2a88d9ad76bf4d03907ff5958
parent4bfc70e31766587c951204c93a127a486e007d0c (diff)
downloadComputeLibrary-a1f7851e2f776610019db8725c2963c36b0c85eb.tar.gz
Integrate new winograd APIs from MLTech
Resolves: COMPMID-5400 Signed-off-by: Ramy Elgammal <ramy.elgammal@arm.com> Change-Id: Ib4428436dd7a6e40d8b2d8a2f8dac1b079154551 Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/7894 Reviewed-by: Pablo Marquez Tello <pablo.tello@arm.com> Tested-by: Arm Jenkins <bsgcomp@arm.com> Comments-Addressed: Arm Jenkins <bsgcomp@arm.com> Benchmark: Arm Jenkins <bsgcomp@arm.com>
-rw-r--r--Android.bp48
-rw-r--r--arm_compute/core/CPP/CPPTypes.h10
-rw-r--r--arm_compute/runtime/NEON/functions/NEWinogradConvolutionLayer.h3
-rw-r--r--filelist.json77
-rw-r--r--src/core/CPP/CPPTypes.cpp10
-rw-r--r--src/core/NEON/kernels/assembly/winograd.hpp234
-rw-r--r--src/core/NEON/kernels/convolution/winograd/input_transform.hpp384
-rw-r--r--src/core/NEON/kernels/convolution/winograd/input_transforms/a64_fp16_6x6.cpp (renamed from src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_6x6_fp16_fp16_integers.cpp)33
-rw-r--r--src/core/NEON/kernels/convolution/winograd/input_transforms/a64_fp32_6x6.cpp (renamed from src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_6x6_fp32_fp32_integers.cpp)244
-rw-r--r--src/core/NEON/kernels/convolution/winograd/input_transforms/arm_fp32_1x8.cpp (renamed from src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_1x8_fp32_fp32_integers.cpp)33
-rw-r--r--src/core/NEON/kernels/convolution/winograd/input_transforms/arm_fp32_4x4.cpp (renamed from src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_4x4_fp32_fp32_integers.cpp)36
-rw-r--r--src/core/NEON/kernels/convolution/winograd/input_transforms/arm_fp32_6x6.cpp202
-rw-r--r--src/core/NEON/kernels/convolution/winograd/input_transforms/sve_fp32_6x6.cpp361
-rw-r--r--src/core/NEON/kernels/convolution/winograd/input_transforms_fp16.cpp56
-rw-r--r--src/core/NEON/kernels/convolution/winograd/input_transforms_fp32.cpp71
-rw-r--r--src/core/NEON/kernels/convolution/winograd/output_transform.hpp302
-rw-r--r--src/core/NEON/kernels/convolution/winograd/output_transforms/a64_fp16_4x4_3x3.cpp (renamed from src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_4x4_3x3_fp16_fp16_integers.cpp)31
-rw-r--r--src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_1x2_1x7.cpp (renamed from src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_2_7_fp32_fp32_integers.cpp)69
-rw-r--r--src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_1x4_1x5.cpp (renamed from src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_4_5_fp32_fp32_integers.cpp)69
-rw-r--r--src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_1x6_1x3.cpp (renamed from src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_6_3_fp32_fp32_integers.cpp)72
-rw-r--r--src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_2x2_3x3.cpp (renamed from src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_2x2_3x3_fp32_fp32_integers.cpp)99
-rw-r--r--src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_2x2_5x5.cpp (renamed from src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_2x2_5x5_fp32_fp32_integers.cpp)99
-rw-r--r--src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_4x4_3x3.cpp (renamed from src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_4x4_3x3_fp32_fp32_integers.cpp)98
-rw-r--r--src/core/NEON/kernels/convolution/winograd/output_transforms_fp16.cpp55
-rw-r--r--src/core/NEON/kernels/convolution/winograd/output_transforms_fp32.cpp68
-rw-r--r--src/core/NEON/kernels/convolution/winograd/weight_transform.hpp145
-rw-r--r--src/core/NEON/kernels/convolution/winograd/weight_transforms/a64_fp16_4x4_3x3.cpp (renamed from src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_4x4_3x3_fp16_fp16_integers.cpp)161
-rw-r--r--src/core/NEON/kernels/convolution/winograd/weight_transforms/arm_fp32_2x2_3x3.cpp200
-rw-r--r--src/core/NEON/kernels/convolution/winograd/weight_transforms/arm_fp32_2x2_5x5.cpp381
-rw-r--r--src/core/NEON/kernels/convolution/winograd/weight_transforms/arm_fp32_4x4_3x3.cpp236
-rw-r--r--src/core/NEON/kernels/convolution/winograd/weight_transforms/cpp_fp32_1x2_1x7.cpp71
-rw-r--r--src/core/NEON/kernels/convolution/winograd/weight_transforms/cpp_fp32_1x4_1x5.cpp77
-rw-r--r--src/core/NEON/kernels/convolution/winograd/weight_transforms/cpp_fp32_1x6_1x3.cpp71
-rw-r--r--src/core/NEON/kernels/convolution/winograd/weight_transforms_fp16.cpp54
-rw-r--r--src/core/NEON/kernels/convolution/winograd/weight_transforms_fp32.cpp74
-rw-r--r--src/core/NEON/kernels/convolution/winograd/winograd.cpp182
-rw-r--r--src/core/NEON/kernels/convolution/winograd/winograd.hpp621
-rw-r--r--src/core/NEON/kernels/convolution/winograd/winograd_fp16.cpp45
-rw-r--r--src/core/NEON/kernels/convolution/winograd/winograd_fp32.cpp41
-rw-r--r--src/core/NEON/kernels/convolution/winograd/winograd_implementations.hpp332
-rw-r--r--src/core/NEON/kernels/convolution/winograd/winograd_layer.hpp207
-rw-r--r--src/core/NEON/kernels/convolution/winograd/winograd_transforms/input.hpp268
-rw-r--r--src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_4x4_fp16_fp16_integers.cpp257
-rw-r--r--src/core/NEON/kernels/convolution/winograd/winograd_transforms/kernel.hpp78
-rw-r--r--src/core/NEON/kernels/convolution/winograd/winograd_transforms/output.hpp252
-rw-r--r--src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_2_7_fp32_fp32_integers.cpp90
-rw-r--r--src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_2x2_3x3_fp32_fp32_integers.cpp220
-rw-r--r--src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_2x2_5x5_fp32_fp32_integers.cpp401
-rw-r--r--src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_4_5_fp32_fp32_integers.cpp90
-rw-r--r--src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_4x4_3x3_fp32_fp32_integers.cpp257
-rw-r--r--src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_6_3_fp32_fp32_integers.cpp90
-rw-r--r--src/cpu/kernels/CpuWinogradConv2dKernel.cpp568
-rw-r--r--src/cpu/kernels/CpuWinogradConv2dKernel.h533
-rw-r--r--src/cpu/kernels/assembly/arm_gemm.hpp8
-rw-r--r--src/cpu/operators/CpuWinogradConv2d.cpp914
-rw-r--r--src/cpu/operators/CpuWinogradConv2d.h54
-rw-r--r--src/runtime/NEON/functions/NEWinogradConvolutionLayer.cpp3
57 files changed, 4327 insertions, 5418 deletions
diff --git a/Android.bp b/Android.bp
index 16e67ad893..9d056f99b6 100644
--- a/Android.bp
+++ b/Android.bp
@@ -340,27 +340,30 @@ cc_library_static {
"src/core/NEON/kernels/convolution/common/qasymm8.cpp",
"src/core/NEON/kernels/convolution/common/qsymm8.cpp",
"src/core/NEON/kernels/convolution/common/utils.cpp",
+ "src/core/NEON/kernels/convolution/winograd/input_transforms/arm_fp32_1x8.cpp",
+ "src/core/NEON/kernels/convolution/winograd/input_transforms/arm_fp32_4x4.cpp",
+ "src/core/NEON/kernels/convolution/winograd/input_transforms/arm_fp32_6x6.cpp",
+ "src/core/NEON/kernels/convolution/winograd/input_transforms_fp16.cpp",
+ "src/core/NEON/kernels/convolution/winograd/input_transforms_fp32.cpp",
+ "src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_1x2_1x7.cpp",
+ "src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_1x4_1x5.cpp",
+ "src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_1x6_1x3.cpp",
+ "src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_2x2_3x3.cpp",
+ "src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_2x2_5x5.cpp",
+ "src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_4x4_3x3.cpp",
+ "src/core/NEON/kernels/convolution/winograd/output_transforms_fp16.cpp",
+ "src/core/NEON/kernels/convolution/winograd/output_transforms_fp32.cpp",
"src/core/NEON/kernels/convolution/winograd/padding.cpp",
- "src/core/NEON/kernels/convolution/winograd/winograd.cpp",
- "src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_1x8_fp32_fp32_integers.cpp",
- "src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_4x4_fp16_fp16_integers.cpp",
- "src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_4x4_fp32_fp32_integers.cpp",
- "src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_6x6_fp16_fp16_integers.cpp",
- "src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_6x6_fp32_fp32_integers.cpp",
- "src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_2_7_fp32_fp32_integers.cpp",
- "src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_2x2_3x3_fp32_fp32_integers.cpp",
- "src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_2x2_5x5_fp32_fp32_integers.cpp",
- "src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_4_5_fp32_fp32_integers.cpp",
- "src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_4x4_3x3_fp16_fp16_integers.cpp",
- "src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_4x4_3x3_fp32_fp32_integers.cpp",
- "src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_6_3_fp32_fp32_integers.cpp",
- "src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_2_7_fp32_fp32_integers.cpp",
- "src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_2x2_3x3_fp32_fp32_integers.cpp",
- "src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_2x2_5x5_fp32_fp32_integers.cpp",
- "src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_4_5_fp32_fp32_integers.cpp",
- "src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_4x4_3x3_fp16_fp16_integers.cpp",
- "src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_4x4_3x3_fp32_fp32_integers.cpp",
- "src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_6_3_fp32_fp32_integers.cpp",
+ "src/core/NEON/kernels/convolution/winograd/weight_transforms/arm_fp32_2x2_3x3.cpp",
+ "src/core/NEON/kernels/convolution/winograd/weight_transforms/arm_fp32_2x2_5x5.cpp",
+ "src/core/NEON/kernels/convolution/winograd/weight_transforms/arm_fp32_4x4_3x3.cpp",
+ "src/core/NEON/kernels/convolution/winograd/weight_transforms/cpp_fp32_1x2_1x7.cpp",
+ "src/core/NEON/kernels/convolution/winograd/weight_transforms/cpp_fp32_1x4_1x5.cpp",
+ "src/core/NEON/kernels/convolution/winograd/weight_transforms/cpp_fp32_1x6_1x3.cpp",
+ "src/core/NEON/kernels/convolution/winograd/weight_transforms_fp16.cpp",
+ "src/core/NEON/kernels/convolution/winograd/weight_transforms_fp32.cpp",
+ "src/core/NEON/kernels/convolution/winograd/winograd_fp16.cpp",
+ "src/core/NEON/kernels/convolution/winograd/winograd_fp32.cpp",
"src/core/Rounding.cpp",
"src/core/Size2D.cpp",
"src/core/Size3D.cpp",
@@ -1184,6 +1187,11 @@ cc_library_static {
"src/core/NEON/kernels/arm_gemm/kernels/sve_smallK_hybrid_fp32_mla_8x1VL/generic.cpp",
"src/core/NEON/kernels/arm_gemm/kernels/sve_smallK_hybrid_s8s32_dot_8x1VL/generic.cpp",
"src/core/NEON/kernels/arm_gemm/kernels/sve_smallK_hybrid_u8u32_dot_8x1VL/generic.cpp",
+ "src/core/NEON/kernels/convolution/winograd/input_transforms/a64_fp16_6x6.cpp",
+ "src/core/NEON/kernels/convolution/winograd/input_transforms/a64_fp32_6x6.cpp",
+ "src/core/NEON/kernels/convolution/winograd/input_transforms/sve_fp32_6x6.cpp",
+ "src/core/NEON/kernels/convolution/winograd/output_transforms/a64_fp16_4x4_3x3.cpp",
+ "src/core/NEON/kernels/convolution/winograd/weight_transforms/a64_fp16_4x4_3x3.cpp",
],
},
diff --git a/arm_compute/core/CPP/CPPTypes.h b/arm_compute/core/CPP/CPPTypes.h
index a021bdf5e4..afefb1aeb0 100644
--- a/arm_compute/core/CPP/CPPTypes.h
+++ b/arm_compute/core/CPP/CPPTypes.h
@@ -127,6 +127,16 @@ public:
* @return true of the cpu supports sve2, false otherwise
*/
bool has_sve2() const;
+ /** Checks if the cpu model supports sme.
+ *
+ * @return true of the cpu supports sme, false otherwise
+ */
+ bool has_sme() const;
+ /** Checks if the cpu model supports sme2.
+ *
+ * @return true of the cpu supports sme2, false otherwise
+ */
+ bool has_sme2() const;
/** Gets the cpu model for a given cpuid.
*
* @param[in] cpuid the id of the cpu core to be retrieved,
diff --git a/arm_compute/runtime/NEON/functions/NEWinogradConvolutionLayer.h b/arm_compute/runtime/NEON/functions/NEWinogradConvolutionLayer.h
index 2a49f2be59..85b4d047ef 100644
--- a/arm_compute/runtime/NEON/functions/NEWinogradConvolutionLayer.h
+++ b/arm_compute/runtime/NEON/functions/NEWinogradConvolutionLayer.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2021 Arm Limited.
+ * Copyright (c) 2017-2022 Arm Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -38,7 +38,6 @@ class ITensor;
/** Basic function to simulate a convolution layer. This function calls the following kernels:
*
- * -# @ref cpu::CpuWinogradConv2dTransformWeightsKernel (executed only once in the first call to the run() method )
* -# @ref cpu::CpuWinogradConv2dTransformInputKernel
* -# @ref cpu::CpuWinogradConv2dTransformOutputKernel
* -# @ref cpu::CpuGemmAssemblyDispatch
diff --git a/filelist.json b/filelist.json
index 513a2207c1..5294fed6b7 100644
--- a/filelist.json
+++ b/filelist.json
@@ -668,7 +668,7 @@
"Reduction": {
"deps": [ "Reshape" ],
"files": {
- "common": [
+ "common": [
"src/core/CL/kernels/CLReductionOperationKernel.cpp",
"src/runtime/CL/functions/CLReductionOperation.cpp"
]
@@ -1062,27 +1062,34 @@
"src/core/NEON/kernels/convolution/common/qasymm8.cpp",
"src/core/NEON/kernels/convolution/common/qsymm8.cpp",
"src/core/NEON/kernels/convolution/common/utils.cpp",
- "src/core/NEON/kernels/convolution/winograd/padding.cpp",
- "src/core/NEON/kernels/convolution/winograd/winograd.cpp",
- "src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_1x8_fp32_fp32_integers.cpp",
- "src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_4x4_fp16_fp16_integers.cpp",
- "src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_4x4_fp32_fp32_integers.cpp",
- "src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_6x6_fp16_fp16_integers.cpp",
- "src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_6x6_fp32_fp32_integers.cpp",
- "src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_2_7_fp32_fp32_integers.cpp",
- "src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_2x2_3x3_fp32_fp32_integers.cpp",
- "src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_2x2_5x5_fp32_fp32_integers.cpp",
- "src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_4_5_fp32_fp32_integers.cpp",
- "src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_4x4_3x3_fp16_fp16_integers.cpp",
- "src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_4x4_3x3_fp32_fp32_integers.cpp",
- "src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_6_3_fp32_fp32_integers.cpp",
- "src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_2_7_fp32_fp32_integers.cpp",
- "src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_2x2_3x3_fp32_fp32_integers.cpp",
- "src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_2x2_5x5_fp32_fp32_integers.cpp",
- "src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_4_5_fp32_fp32_integers.cpp",
- "src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_4x4_3x3_fp16_fp16_integers.cpp",
- "src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_4x4_3x3_fp32_fp32_integers.cpp",
- "src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_6_3_fp32_fp32_integers.cpp",
+ "src/core/NEON/kernels/convolution/winograd/input_transforms_fp16.cpp",
+ "src/core/NEON/kernels/convolution/winograd/input_transforms_fp32.cpp",
+ "src/core/NEON/kernels/convolution/winograd/output_transforms_fp16.cpp",
+ "src/core/NEON/kernels/convolution/winograd/output_transforms_fp32.cpp",
+ "src/core/NEON/kernels/convolution/winograd/weight_transforms_fp16.cpp",
+ "src/core/NEON/kernels/convolution/winograd/weight_transforms_fp32.cpp",
+ "src/core/NEON/kernels/convolution/winograd/winograd_fp16.cpp",
+ "src/core/NEON/kernels/convolution/winograd/winograd_fp32.cpp",
+ "src/core/NEON/kernels/convolution/winograd/input_transforms/a64_fp16_6x6.cpp",
+ "src/core/NEON/kernels/convolution/winograd/input_transforms/a64_fp32_6x6.cpp",
+ "src/core/NEON/kernels/convolution/winograd/input_transforms/arm_fp32_1x8.cpp",
+ "src/core/NEON/kernels/convolution/winograd/input_transforms/arm_fp32_4x4.cpp",
+ "src/core/NEON/kernels/convolution/winograd/input_transforms/arm_fp32_6x6.cpp",
+ "src/core/NEON/kernels/convolution/winograd/input_transforms/sve_fp32_6x6.cpp",
+ "src/core/NEON/kernels/convolution/winograd/output_transforms/a64_fp16_4x4_3x3.cpp",
+ "src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_1x2_1x7.cpp",
+ "src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_1x4_1x5.cpp",
+ "src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_1x6_1x3.cpp",
+ "src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_2x2_3x3.cpp",
+ "src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_2x2_5x5.cpp",
+ "src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_4x4_3x3.cpp",
+ "src/core/NEON/kernels/convolution/winograd/weight_transforms/a64_fp16_4x4_3x3.cpp",
+ "src/core/NEON/kernels/convolution/winograd/weight_transforms/arm_fp32_2x2_3x3.cpp",
+ "src/core/NEON/kernels/convolution/winograd/weight_transforms/arm_fp32_2x2_5x5.cpp",
+ "src/core/NEON/kernels/convolution/winograd/weight_transforms/arm_fp32_4x4_3x3.cpp",
+ "src/core/NEON/kernels/convolution/winograd/weight_transforms/cpp_fp32_1x2_1x7.cpp",
+ "src/core/NEON/kernels/convolution/winograd/weight_transforms/cpp_fp32_1x4_1x5.cpp",
+ "src/core/NEON/kernels/convolution/winograd/weight_transforms/cpp_fp32_1x6_1x3.cpp",
"src/cpu/kernels/directconv2d/nhwc/neon/impl.cpp",
"src/cpu/kernels/directconv2d/nchw/all.cpp"
],
@@ -1220,10 +1227,10 @@
"src/core/NEON/kernels/arm_conv/depthwise/interleaves/generic.cpp",
"src/core/NEON/kernels/arm_conv/depthwise/interleaves/generic_quantized_dot_product.cpp",
"src/cpu/kernels/depthwiseconv2d/generic/neon/impl.cpp"
- ],
+ ],
"fp16":["src/cpu/kernels/depthwiseconv2d/generic/neon/fp16.cpp"],
- "fp32":["src/cpu/kernels/depthwiseconv2d/generic/neon/fp32.cpp"],
- "qasymm8":["src/cpu/kernels/depthwiseconv2d/generic/neon/qasymm8.cpp"],
+ "fp32":["src/cpu/kernels/depthwiseconv2d/generic/neon/fp32.cpp"],
+ "qasymm8":["src/cpu/kernels/depthwiseconv2d/generic/neon/qasymm8.cpp"],
"qasymm8_signed":["src/cpu/kernels/depthwiseconv2d/generic/neon/qasymm8_signed.cpp"]
},
"sve": {
@@ -1324,7 +1331,7 @@
"fp32": ["src/cpu/kernels/elementwise_binary/generic/sve/fp32.cpp"],
"fp16": ["src/cpu/kernels/elementwise_binary/generic/sve/fp16.cpp"]
- },
+ },
"sve2":{
"qasymm8": ["src/cpu/kernels/elementwise_binary/generic/sve2/qasymm8.cpp"],
"qasymm8_signed": ["src/cpu/kernels/elementwise_binary/generic/sve2/qasymm8_signed.cpp"]
@@ -1528,7 +1535,7 @@
"src/core/NEON/kernels/arm_gemm/kernels/a64_smallK_hybrid_u8u32_dot_6x4/a55.cpp",
"src/core/NEON/kernels/arm_gemm/kernels/a64_smallK_hybrid_u8u32_dot_6x4/generic.cpp",
"src/core/NEON/kernels/arm_gemm/kernels/a64_smallK_hybrid_u8u32_dot_8x4/a55.cpp",
- "src/core/NEON/kernels/arm_gemm/kernels/a64_smallK_hybrid_u8u32_dot_8x4/generic.cpp",
+ "src/core/NEON/kernels/arm_gemm/kernels/a64_smallK_hybrid_u8u32_dot_8x4/generic.cpp",
"src/cpu/kernels/gemm_matrix_mul/generic/neon/impl.cpp",
"src/cpu/kernels/gemm_matrix_add/generic/neon/impl.cpp"
],
@@ -1635,7 +1642,7 @@
"common": [
"src/core/NEON/kernels/NEInstanceNormalizationLayerKernel.cpp",
"src/runtime/NEON/functions/NEInstanceNormalizationLayer.cpp"
- ],
+ ],
"neon":{
"common":["src/cpu/kernels/instancenorm/generic/neon/impl.cpp"],
"fp16":["src/cpu/kernels/instancenorm/generic/neon/fp16.cpp"],
@@ -1695,7 +1702,7 @@
"files": {
"common": [
"src/cpu/kernels/CpuMaxUnpoolingLayerKernel.cpp",
- "src/runtime/NEON/functions/NEMaxUnpoolingLayer.cpp",
+ "src/runtime/NEON/functions/NEMaxUnpoolingLayer.cpp",
"src/cpu/operators/CpuMaxUnpooling.cpp"
],
"neon":{
@@ -1796,12 +1803,12 @@
"src/core/NEON/kernels/arm_conv/pooling/kernels/a64_u8_nhwc_max_2x2_s1_output2x2_depthfirst/generic.cpp",
"src/core/NEON/kernels/arm_conv/pooling/kernels/a64_u8_nhwc_max_generic_depthfirst/generic.cpp",
"src/core/NEON/kernels/arm_conv/pooling/kernels/a64_u8q_nhwc_avg_generic_depthfirst/generic.cpp",
- "src/core/NEON/kernels/arm_conv/pooling/kernels/a64_u8q_nhwc_max_generic_depthfirst/generic.cpp"
+ "src/core/NEON/kernels/arm_conv/pooling/kernels/a64_u8q_nhwc_max_generic_depthfirst/generic.cpp"
],
"nchw": [ "src/cpu/kernels/pool2d/neon/nchw/all.cpp" ],
"fp16": [ "src/cpu/kernels/pool2d/neon/fp16.cpp" ],
- "fp32": [ "src/cpu/kernels/pool2d/neon/fp32.cpp" ],
- "qasymm8":[ "src/cpu/kernels/pool2d/neon/qasymm8.cpp" ],
+ "fp32": [ "src/cpu/kernels/pool2d/neon/fp32.cpp" ],
+ "qasymm8":[ "src/cpu/kernels/pool2d/neon/qasymm8.cpp" ],
"qasymm8_signed":["src/cpu/kernels/pool2d/neon/qasymm8_signed.cpp"]
},
"sve": {
@@ -2001,8 +2008,8 @@
"neon":{
"common":["src/cpu/kernels/softmax/generic/neon/impl.cpp"],
"fp32": ["src/cpu/kernels/softmax/generic/neon/fp32.cpp"],
- "fp16": ["src/cpu/kernels/softmax/generic/neon/fp16.cpp"],
- "qasymm8":[ "src/cpu/kernels/softmax/generic/neon/qasymm8.cpp"],
+ "fp16": ["src/cpu/kernels/softmax/generic/neon/fp16.cpp"],
+ "qasymm8":[ "src/cpu/kernels/softmax/generic/neon/qasymm8.cpp"],
"qasymm8_signed":["src/cpu/kernels/softmax/generic/neon/qasymm8_signed.cpp"]
},
"sve": {
@@ -2014,7 +2021,7 @@
},
"sve2":{
"common" :["src/cpu/kernels/softmax/generic/sve2/impl.cpp"],
- "qasymm8":[ "src/cpu/kernels/softmax/generic/sve2/qasymm8.cpp"],
+ "qasymm8":[ "src/cpu/kernels/softmax/generic/sve2/qasymm8.cpp"],
"qasymm8_signed":["src/cpu/kernels/softmax/generic/sve2/qasymm8_signed.cpp"]
}
}
diff --git a/src/core/CPP/CPPTypes.cpp b/src/core/CPP/CPPTypes.cpp
index c197932a13..bd5236fcf8 100644
--- a/src/core/CPP/CPPTypes.cpp
+++ b/src/core/CPP/CPPTypes.cpp
@@ -101,6 +101,16 @@ bool CPUInfo::has_sve2() const
return _impl->info.has_sve2();
}
+bool CPUInfo::has_sme() const
+{
+ return false;
+}
+
+bool CPUInfo::has_sme2() const
+{
+ return false;
+}
+
CPUModel CPUInfo::get_cpu_model() const
{
return _impl->info.cpu_model();
diff --git a/src/core/NEON/kernels/assembly/winograd.hpp b/src/core/NEON/kernels/assembly/winograd.hpp
new file mode 100644
index 0000000000..836402e83d
--- /dev/null
+++ b/src/core/NEON/kernels/assembly/winograd.hpp
@@ -0,0 +1,234 @@
+/*
+ * Copyright (c) 2022 Arm Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#pragma once
+
+#include "src/cpu/kernels/assembly/arm_gemm.hpp"
+#include <cstddef>
+
+namespace arm_conv
+{
+struct Shape2D
+{
+ unsigned int rows, cols;
+};
+
+struct ConvolutionArgs
+{
+ unsigned int n_batches;
+ Shape2D input_shape;
+ unsigned int n_input_channels;
+ unsigned int pad_top, pad_left;
+ Shape2D output_shape;
+ unsigned int n_output_channels;
+ Shape2D kernel_shape;
+ arm_gemm::Activation activation;
+
+ ConvolutionArgs(
+ unsigned int n_batches,
+ const Shape2D &input_shape,
+ unsigned int n_input_channels,
+ unsigned int pad_top, unsigned int pad_left,
+ const Shape2D &output_shape,
+ unsigned int n_output_channels,
+ const Shape2D kernel_shape,
+ const arm_gemm::Activation &activation = {})
+ : n_batches(n_batches), input_shape(input_shape), n_input_channels(n_input_channels), pad_top(pad_top), pad_left(pad_left), output_shape(output_shape), n_output_channels(n_output_channels),
+ kernel_shape(kernel_shape), activation(activation)
+ {
+ }
+};
+
+namespace winograd
+{
+/* Constrain the selected Winograd implementation.
+ */
+struct WinogradConfig
+{
+ unsigned int output_rows = 0, output_cols = 0;
+ std::string input_transform_filter = "";
+ std::string output_transform_filter = "";
+ std::string weight_transform_filter = "";
+};
+
+/* Struct describing (suggested) memory layout within the Winograd domain.
+ */
+struct WinogradDomainSpec
+{
+ size_t weight_matrix_size_bytes, input_matrix_size_bytes, output_matrix_size_bytes;
+
+ size_t weight_ld_matrix, weight_ld_row;
+ size_t input_ld_batch, input_ld_matrix, input_ld_row;
+ size_t output_ld_batch, output_ld_matrix, output_ld_row;
+};
+
+class ITransformCommon
+{
+public:
+ virtual ~ITransformCommon() = default;
+
+ // Get the name of the transform
+ virtual const std::string &get_name(void) const = 0;
+};
+
+namespace weight_transform
+{
+class ITransform : public ITransformCommon
+{
+public:
+ ~ITransform() = default;
+
+ virtual unsigned int get_kernel_rows(void) const = 0;
+ virtual unsigned int get_kernel_cols(void) const = 0;
+
+ virtual unsigned int get_transformed_tile_rows(void) const = 0;
+ virtual unsigned int get_transformed_tile_cols(void) const = 0;
+
+ void execute(
+ const ConvolutionArgs &args,
+ const void *inptr, size_t ld_in_row, size_t ld_in_col, size_t ld_input_channel,
+ void *outptr, const WinogradDomainSpec &wds,
+ unsigned int thread_id, unsigned int n_threads) const
+ {
+ this->execute(
+ args, inptr, ld_in_row, ld_in_col, ld_input_channel,
+ outptr, wds.weight_ld_matrix, wds.weight_ld_row,
+ thread_id, n_threads);
+ }
+
+ virtual void execute(
+ const ConvolutionArgs &args,
+ const void *inptr, size_t ld_in_row, size_t ld_in_col, size_t ld_input_channel,
+ void *outptr, size_t ld_out_matrix, size_t ld_out_row,
+ unsigned int thread_id, unsigned int n_threads) const = 0;
+};
+
+} // namespace weight_transform
+
+namespace input_transform
+{
+class ITransform : public ITransformCommon
+{
+public:
+ ~ITransform() = default;
+
+ virtual unsigned int get_input_rows(void) const = 0;
+ virtual unsigned int get_input_cols(void) const = 0;
+
+ virtual size_t get_working_space_size(
+ const ConvolutionArgs &args,
+ unsigned int n_threads) const = 0;
+
+ void execute(
+ const ConvolutionArgs &args,
+ const void *inptr, size_t ld_in_batch, size_t ld_in_row, size_t ld_in_col,
+ void *outptr, const WinogradDomainSpec &wds,
+ void *working_space, unsigned int thread_id, unsigned int n_threads) const
+ {
+ this->execute(
+ args, inptr, ld_in_batch, ld_in_row, ld_in_col,
+ outptr, wds.input_ld_batch, wds.input_ld_matrix, wds.input_ld_row,
+ working_space, thread_id, n_threads);
+ }
+
+ virtual void execute(
+ const ConvolutionArgs &args,
+ const void *inptr, size_t ld_in_batch, size_t ld_in_row, size_t ld_in_col,
+ void *outptr, size_t ld_out_batch, size_t ld_out_matrix, size_t ld_out_row,
+ void *working_space, unsigned int thread_id, unsigned int n_threads) const = 0;
+};
+
+} // namespace input_transform
+
+namespace output_transform
+{
+class ITransform : public ITransformCommon
+{
+public:
+ ~ITransform() = default;
+
+ virtual unsigned int get_input_rows(void) const = 0;
+ virtual unsigned int get_input_cols(void) const = 0;
+
+ virtual unsigned int get_output_rows(void) const = 0;
+ virtual unsigned int get_output_cols(void) const = 0;
+
+ virtual unsigned int get_kernel_rows(void) const = 0;
+ virtual unsigned int get_kernel_cols(void) const = 0;
+
+ virtual size_t get_working_space_size(
+ const ConvolutionArgs &args,
+ unsigned int n_threads) const = 0;
+
+ void execute(
+ const ConvolutionArgs &args,
+ const void *inptr, const WinogradDomainSpec &wds,
+ const void *bias,
+ void *outptr, size_t ld_out_batch, size_t ld_out_row, size_t ld_out_col,
+ void *working_space, unsigned int thread_id, unsigned int n_threads) const
+ {
+ this->execute(
+ args,
+ inptr, wds.output_ld_batch, wds.output_ld_matrix, wds.output_ld_row,
+ bias,
+ outptr, ld_out_batch, ld_out_row, ld_out_col,
+ working_space, thread_id, n_threads);
+ }
+
+ virtual void execute(
+ const ConvolutionArgs &args,
+ const void *inptr, size_t ld_in_batch, size_t ld_in_matrix, size_t ld_in_row,
+ const void *bias,
+ void *outptr, size_t ld_out_batch, size_t ld_out_row, size_t ld_out_col,
+ void *working_space, unsigned int thread_id, unsigned int n_threads) const = 0;
+};
+
+} // namespace output_transform
+
+struct WinogradImpl
+{
+ const output_transform::ITransform *output_transform = nullptr;
+ const weight_transform::ITransform *weight_transform = nullptr;
+ const input_transform::ITransform *input_transform = nullptr;
+ std::unique_ptr<arm_gemm::GemmArgs> gemm_args;
+ WinogradDomainSpec winograd_spec;
+};
+
+/* Get pointers to Winograd transforms for the given convolution problem.
+ *
+ * Assigns to the pointers in the `dest` struct and returns true or false to
+ * indicate whether the given problem can be executed or not.
+ */
+template <typename TIn, typename TWeight = TIn, typename TOut = TIn, typename TWinogradIn = TIn, typename TWinogradOut = TOut>
+bool get_implementation(
+ WinogradImpl &dest, // Destination for the selected implementation
+ const CPUInfo *,
+ const ConvolutionArgs &,
+ int max_threads,
+ bool fast_mode,
+ const WinogradConfig *,
+ const arm_gemm::GemmConfig *);
+
+} // namespace winograd
+} // namespace arm_conv
diff --git a/src/core/NEON/kernels/convolution/winograd/input_transform.hpp b/src/core/NEON/kernels/convolution/winograd/input_transform.hpp
new file mode 100644
index 0000000000..113b7ea928
--- /dev/null
+++ b/src/core/NEON/kernels/convolution/winograd/input_transform.hpp
@@ -0,0 +1,384 @@
+/*
+ * Copyright (c) 2022 Arm Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#pragma once
+
+#include "arm_compute/core/Error.h"
+
+#include "src/core/NEON/kernels/assembly/winograd.hpp"
+
+#include "src/core/NEON/kernels/arm_conv/addressing.hpp"
+#include <algorithm>
+#include <cstring>
+#include <functional>
+
+namespace arm_conv {
+namespace winograd {
+namespace input_transform {
+
+namespace {
+
+template <typename T>
+constexpr T iceildiv(const T a, const T b)
+{
+ return (a + b - 1) / b;
+}
+
+}
+
+/* Driver class for the Winograd input transforms.
+ *
+ * This provides a base implementation which handles iteration over the input
+ * tensor; subclasses are responsible for managing working space and executing
+ * the transform on individual tiles.
+ */
+template <typename TIn, typename TOut=TIn>
+class TransformBase : public ITransform
+{
+ const std::string m_name;
+ const unsigned int m_input_rows, m_input_cols;
+
+ protected:
+ virtual size_t get_working_space_per_thread(const ConvolutionArgs &) const
+ {
+ return 0;
+ }
+
+ virtual void initialise_thread_working_space(const ConvolutionArgs &, void *) const
+ {
+ // Nothing to do
+ }
+
+ virtual void execute_tile(
+ unsigned int n_channels,
+ const TIn *inptr, size_t ld_in_row, size_t ld_in_col,
+ TOut *outptr, size_t ld_out_matrix,
+ unsigned int pad_top, unsigned int valid_rows,
+ unsigned int pad_left, unsigned int valid_cols,
+ void *working_space
+ ) const = 0;
+
+ void execute_internal(
+ const ConvolutionArgs &args,
+ const TIn *inptr, size_t ld_in_batch, size_t ld_in_row, size_t ld_in_col,
+ TOut *outptr, size_t ld_out_batch, size_t ld_out_matrix, size_t ld_out_row,
+ void *working_space, unsigned int thread_id, unsigned int n_threads
+ ) const
+ {
+ // Get the working space for this thread, and initialise it.
+ working_space = reinterpret_cast<char *>(working_space) +
+ this->get_working_space_per_thread(args) * thread_id;
+ this->initialise_thread_working_space(args, working_space);
+
+ // Get tile traversal parameters
+ const auto tile_stride_rows = std::max(1u, m_input_rows - args.kernel_shape.rows + 1);
+ const auto tile_stride_cols = std::max(1u, m_input_cols - args.kernel_shape.cols + 1);
+ const auto n_tile_rows = iceildiv(
+ args.output_shape.rows, m_input_rows - args.kernel_shape.rows + 1);
+ const auto n_tile_cols = iceildiv(
+ args.output_shape.cols, m_input_cols - args.kernel_shape.cols + 1);
+
+ // Execute over all batches
+ for (unsigned int batch = 0; batch < args.n_batches; batch++)
+ {
+ auto outptr_tile = outptr + thread_id * n_tile_cols * ld_out_row;
+
+ // For a single batch, stripe the rows over the threads.
+ for (auto tile_i = thread_id; tile_i < n_tile_rows; tile_i += n_threads)
+ {
+ // Compute pointers and padding for this row of tiles
+ const auto start_i = tile_i * tile_stride_rows;
+ const auto pad_top = start_i < args.pad_top ? args.pad_top - start_i : 0;
+ const auto inptr_row = inptr + (pad_top ? 0 : start_i - args.pad_top) * ld_in_row;
+ const auto valid_rows = args.input_shape.rows - (pad_top ? 0 : start_i - args.pad_top);
+
+ // Iterate over columns
+ for (auto tile_j = 0u; tile_j < n_tile_cols; tile_j++)
+ {
+ // Compute pointers and padding for this tile, then delegate to
+ // execute the kernel.
+ const auto start_j = tile_j * tile_stride_cols;
+ const auto pad_left = start_j < args.pad_left ? args.pad_left - start_j : 0;
+ const auto inptr_tile = inptr_row + (pad_left ? 0 : start_j - args.pad_left) * ld_in_col;
+ const auto valid_cols = args.input_shape.cols - (pad_left ? 0 : start_j - args.pad_left);
+
+ this->execute_tile(
+ args.n_input_channels,
+ inptr_tile, ld_in_row, ld_in_col,
+ outptr_tile, ld_out_matrix,
+ pad_top, valid_rows, pad_left, valid_cols,
+ working_space
+ );
+ outptr_tile += ld_out_row;
+ }
+
+ outptr_tile += (n_threads - 1) * n_tile_cols * ld_out_row;
+ }
+
+ inptr += ld_in_batch;
+ outptr += ld_out_batch;
+ }
+ }
+
+ public:
+ TransformBase(const std::string &name, unsigned int input_rows, unsigned int input_cols)
+ : m_name(name), m_input_rows(input_rows), m_input_cols(input_cols)
+ {
+ }
+
+ const std::string &get_name(void) const override { return m_name; }
+
+ unsigned int get_input_rows(void) const override final { return m_input_rows; }
+ unsigned int get_input_cols(void) const override final { return m_input_cols; }
+
+ size_t get_working_space_size(const ConvolutionArgs &args, unsigned int n_threads) const override
+ {
+ return n_threads * this->get_working_space_per_thread(args);
+ }
+
+ void execute(
+ const ConvolutionArgs &args,
+ const void *inptr, size_t ld_in_batch, size_t ld_in_row, size_t ld_in_col,
+ void *outptr, size_t ld_out_batch, size_t ld_out_matrix, size_t ld_out_row,
+ void *working_space, unsigned int thread_id, unsigned int n_threads
+ ) const override
+ {
+ execute_internal(
+ args,
+ reinterpret_cast<const TIn *>(inptr), ld_in_batch, ld_in_row, ld_in_col,
+ reinterpret_cast<TOut *>(outptr), ld_out_batch, ld_out_matrix, ld_out_row,
+ working_space, thread_id, n_threads
+ );
+ }
+};
+
+template <typename TIn, typename TOut=TIn>
+class TransformDirect : public TransformBase<TIn, TOut>
+{
+ using Kernel = std::function<void(
+ unsigned int, // Number of channels
+ const TIn *, size_t, size_t, // Pointer to first valid input element, row and column stride
+ unsigned int, unsigned int, unsigned int, unsigned int, // Top, left, bottom and right padding
+ TOut *, size_t // Base output pointer, stride between matrices
+ )>;
+ const Kernel m_kernel;
+
+ protected:
+ void execute_tile(
+ unsigned int n_channels,
+ const TIn *inptr, size_t ld_in_row, size_t ld_in_col,
+ TOut *outptr, size_t ld_out_matrix,
+ unsigned int pad_top, unsigned int valid_rows,
+ unsigned int pad_left, unsigned int valid_cols,
+ void *working_space
+ ) const override
+ {
+ ARM_COMPUTE_UNUSED(working_space);
+ const auto end_i = this->get_input_rows() - pad_top;
+ const auto pad_bottom = end_i < valid_rows ? 0 : end_i - valid_rows;
+ const auto end_j = this->get_input_cols() - pad_left;
+ const auto pad_right = end_j < valid_cols ? 0 : end_j - valid_cols;
+
+ // Execute the kernel
+ m_kernel(
+ n_channels, inptr, ld_in_row, ld_in_col,
+ pad_top, pad_left, pad_bottom, pad_right,
+ outptr, ld_out_matrix
+ );
+ }
+
+ public:
+ TransformDirect(const std::string &name, unsigned int input_rows, unsigned int input_cols, Kernel kernel)
+ : TransformBase<TIn, TOut>(name, input_rows, input_cols), m_kernel(kernel)
+ {
+ }
+};
+
+template <typename TIn, typename TOut=TIn>
+class TransformIndirect : public TransformBase<TIn, TOut>
+{
+ using Kernel = std::function<void(
+ unsigned int, // Number of channels
+ const TIn *const *, // Input pointers (one per point)
+ TOut *, size_t // Base output pointer, stride between matrices
+ )>;
+ const Kernel m_kernel;
+
+ struct Workspace
+ {
+ const TIn **inptrs;
+ const TIn *input_buffer;
+ };
+
+ size_t sizeof_inptr_array(void) const
+ {
+ return sizeof(const TIn **) * this->get_input_rows() * this->get_input_cols();
+ }
+
+ protected:
+ size_t get_working_space_per_thread(const ConvolutionArgs &args) const override
+ {
+ return sizeof(Workspace) + sizeof_inptr_array() + sizeof(TIn) * args.n_input_channels;
+ }
+
+ void initialise_thread_working_space(const ConvolutionArgs &args, void *buffer) const override
+ {
+ Workspace *ws = reinterpret_cast<Workspace *>(buffer);
+ buffer = ws + 1;
+
+ ws->inptrs = reinterpret_cast<const TIn **>(buffer);
+ buffer = reinterpret_cast<char *>(buffer) + sizeof_inptr_array();
+
+ ws->input_buffer = reinterpret_cast<const TIn *>(buffer);
+ memset(buffer, 0, sizeof(TIn) * args.n_input_channels);
+ }
+
+ void execute_tile(
+ unsigned int n_channels,
+ const TIn *inptr, size_t ld_in_row, size_t ld_in_col,
+ TOut *outptr, size_t ld_out_matrix,
+ unsigned int pad_top, unsigned int valid_rows,
+ unsigned int pad_left, unsigned int valid_cols,
+ void *working_space
+ ) const override
+ {
+ // Get the working space
+ auto ws = reinterpret_cast<Workspace *>(working_space);
+
+ // Construct the input pointer array based on the given arguments
+ fill_pointer_array<const TIn>(
+ ws->inptrs, this->get_input_rows(), this->get_input_cols(),
+ inptr, ld_in_row, ld_in_col,
+ ws->input_buffer,
+ pad_top, valid_rows,
+ pad_left, valid_cols
+ );
+
+ // Execute the kernel
+ m_kernel(n_channels, ws->inptrs, outptr, ld_out_matrix);
+ }
+
+ public:
+ TransformIndirect(const std::string &name, unsigned int input_rows, unsigned int input_cols, Kernel kernel)
+ : TransformBase<TIn, TOut>(name, input_rows, input_cols), m_kernel(kernel)
+ {
+ }
+};
+
+template <typename TIn, typename TOut=TIn>
+class TransformUnpadded : public TransformBase<TIn, TOut>
+{
+ using Kernel = std::function<void(
+ unsigned int, // Number of channels
+ const TIn *, size_t, size_t, // Pointer to first input element, row and column stride
+ TOut *, size_t // Base output pointer, stride between matrices
+ )>;
+ const Kernel m_kernel;
+
+ protected:
+ size_t get_working_space_per_thread(const ConvolutionArgs &args) const override
+ {
+ const auto input_points = this->get_input_rows() * this->get_input_cols();
+ return sizeof(TIn) * input_points * args.n_input_channels;
+ }
+
+ void execute_tile(
+ unsigned int n_channels,
+ const TIn *inptr, size_t ld_in_row, size_t ld_in_col,
+ TOut *const outptr, const size_t ld_out_matrix,
+ const unsigned int pad_top, const unsigned int valid_rows,
+ const unsigned int pad_left, const unsigned int valid_cols,
+ void *const working_space
+ ) const override
+ {
+ // If there's any padding, then copy the valid portion of the tensor into
+ // the working space and reset the pointer, row and column strides to point
+ // at this copy of the data.
+ if (pad_top || valid_rows < this->get_input_rows() ||
+ pad_left || valid_cols < this->get_input_cols())
+ {
+ const auto patch_ld_col = n_channels;
+ const auto patch_ld_row = patch_ld_col * this->get_input_cols();
+ auto patch = reinterpret_cast<TIn *>(working_space) +
+ pad_top*patch_ld_row + pad_left*patch_ld_col;
+
+ // Fill the input patch with padding
+ memset(working_space, 0, sizeof(TIn) * this->get_input_rows() * patch_ld_row);
+
+ // Determine the bounds for which to copy
+ const auto last_i = std::min(valid_rows + pad_top, this->get_input_rows());
+ const auto last_j = std::min(valid_cols + pad_left, this->get_input_cols());
+
+ // Copy across the valid portion of the patch
+ for (auto i = pad_top; i < last_i; i++)
+ {
+ auto inptr_col = inptr;
+ inptr += ld_in_row;
+
+ auto patch_col = patch;
+ patch += patch_ld_row;
+
+ for (auto j = pad_left; j < last_j; j++)
+ {
+ // Perform the copy and progress both input and patch pointers
+ memcpy(patch_col, inptr_col, n_channels * sizeof(TIn));
+ inptr_col += ld_in_col;
+ patch_col += patch_ld_col;
+ }
+ }
+
+ // Override the input pointer and strides
+ inptr = reinterpret_cast<const TIn *>(working_space);
+ ld_in_col = patch_ld_col;
+ ld_in_row = patch_ld_row;
+ }
+
+ // Call the kernel
+ m_kernel(n_channels, inptr, ld_in_row, ld_in_col, outptr, ld_out_matrix);
+ }
+
+ public:
+ TransformUnpadded(const std::string &name, unsigned int input_rows, unsigned int input_cols, Kernel kernel)
+ : TransformBase<TIn, TOut>(name, input_rows, input_cols), m_kernel(kernel)
+ {
+ }
+
+ /* Utility method which can be used to get a transposed version of a kernel,
+ * this just calls the kernel with the input row and column strides reversed.
+ */
+ static constexpr Kernel get_transposed_kernel(const Kernel &kernel)
+ {
+ return [kernel] (
+ const unsigned int n_channels,
+ const TIn *const inptr, const size_t ld_in_row, const size_t ld_in_col,
+ TOut *const outptr, const size_t ld_out_matrix
+ ) {
+ kernel(n_channels, inptr, ld_in_col, ld_in_row, outptr, ld_out_matrix);
+ };
+ }
+};
+
+} // namespace input_transform
+} // namespace winograd
+} // namespace arm_conv
diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_6x6_fp16_fp16_integers.cpp b/src/core/NEON/kernels/convolution/winograd/input_transforms/a64_fp16_6x6.cpp
index d0ce307988..ad759b225e 100644
--- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_6x6_fp16_fp16_integers.cpp
+++ b/src/core/NEON/kernels/convolution/winograd/input_transforms/a64_fp16_6x6.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020 Arm Limited.
+ * Copyright (c) 2022 Arm Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -21,20 +21,22 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
-#include "arm.hpp"
-#include "input.hpp"
+#if defined(__aarch64__) && defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
-namespace winograd
-{
-template <>
-void InputTransform<6, 6, __fp16, __fp16, WinogradRoots::Integers>::transform_tile(
- const int n_channels,
+#include <arm_neon.h>
+#include <cstddef>
+
+namespace arm_conv {
+namespace winograd {
+namespace input_transform {
+
+void a64_fp16_6x6(
+ const unsigned int n_channels,
const __fp16* const input_base,
- const int input_row_stride,
- const int input_col_stride,
+ const size_t input_row_stride,
+ const size_t input_col_stride,
__fp16* outptr,
- const int matrix_stride
+ const size_t matrix_stride
)
{
constexpr int inner_tile_rows = 6;
@@ -271,7 +273,8 @@ void InputTransform<6, 6, __fp16, __fp16, WinogradRoots::Integers>::transform_ti
}
}
-template class InputTransform<6, 6, __fp16, __fp16, WinogradRoots::Integers>;
-
+} // namespace input_transform
} // namespace winograd
-#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC \ No newline at end of file
+} // namespace arm_conv
+
+#endif // defined(__aarch64__) && defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_6x6_fp32_fp32_integers.cpp b/src/core/NEON/kernels/convolution/winograd/input_transforms/a64_fp32_6x6.cpp
index 0095e6c96b..6f818c69ff 100644
--- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_6x6_fp32_fp32_integers.cpp
+++ b/src/core/NEON/kernels/convolution/winograd/input_transforms/a64_fp32_6x6.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019 Arm Limited.
+ * Copyright (c) 2022 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -22,31 +22,30 @@
* SOFTWARE.
*/
-#include "arm.hpp"
-#include "input.hpp"
+#ifdef __aarch64__
-namespace winograd
-{
+#include <cstddef>
-#ifdef __aarch64__
+namespace arm_conv {
+namespace winograd {
+namespace input_transform {
-template <>
-void InputTransform<6, 6, float, float, WinogradRoots::Integers>::transform_tile(
- int n_channels,
- const float* input_base,
- const int input_row_stride,
- const int input_col_stride,
- float* matrix_base,
- const int matrix_stride
+void a64_fp32_6x6(
+ unsigned int n_channels,
+ const float *input_base,
+ const size_t input_row_stride,
+ const size_t input_col_stride,
+ float *matrix_base,
+ const size_t matrix_stride
)
{
const float pcoeffs[4] = {1.0f, 2.0f, 4.0f, 5.0f};
__asm__ __volatile__(
"ldr q0, [%[pcoeffs]]\n"
"add x25, %[inptr0], %[input_row_stride]\n"
- "add x9, %[input_col_stride1], %[input_col_stride1]\n"
+ "add x10, %[input_col_stride1], %[input_col_stride1]\n"
"add x16, x25, %[input_row_stride]\n"
- "add x19, x9, %[input_col_stride1]\n"
+ "add x19, x10, %[input_col_stride1]\n"
"add x26, x16, %[input_row_stride]\n"
"add x20, x19, %[input_col_stride1]\n"
"add x17, x26, %[input_row_stride]\n"
@@ -65,7 +64,7 @@ void InputTransform<6, 6, float, float, WinogradRoots::Integers>::transform_tile
"blt 2f\n"
"1:\n"
"ldr q8, [%[inptr0], x20]\n"
- "ldr q2, [%[inptr0], x9]\n"
+ "ldr q2, [%[inptr0], x10]\n"
"mov v14.16b, v8.16b\n"
"ldr q9, [%[inptr0]]\n"
"mov v10.16b, v8.16b\n"
@@ -77,7 +76,7 @@ void InputTransform<6, 6, float, float, WinogradRoots::Integers>::transform_tile
"fmls v10.4s, v12.4s, v0.s[2]\n"
"ldr q5, [x16, x20]\n"
"fmls v14.4s, v2.4s, v0.s[3]\n"
- "ldr q20, [x16, x9]\n"
+ "ldr q20, [x16, x10]\n"
"fmla v9.4s, v12.4s, v0.s[2]\n"
"ldr q3, [x16]\n"
"fmls v10.4s, v2.4s, v0.s[2]\n"
@@ -89,7 +88,7 @@ void InputTransform<6, 6, float, float, WinogradRoots::Integers>::transform_tile
"fadd v10.4s, v10.4s, v4.4s\n"
"ldr q17, [x17, x20]\n"
"fmls v7.4s, v12.4s, v0.s[1]\n"
- "ldr q15, [x17, x9]\n"
+ "ldr q15, [x17, x10]\n"
"fsub v9.4s, v9.4s, v4.4s\n"
"ldr q19, [x17]\n"
"mov v8.16b, v8.16b\n"
@@ -180,7 +179,7 @@ void InputTransform<6, 6, float, float, WinogradRoots::Integers>::transform_tile
"mov v25.16b, v19.16b\n"
"ldr q11, [x25, x20]\n"
"mov v10.16b, v11.16b\n"
- "ldr q23, [x25, x9]\n"
+ "ldr q23, [x25, x10]\n"
"mov v9.16b, v11.16b\n"
"ldr q7, [x25]\n"
"fmla v10.4s, v7.4s, v0.s[2]\n"
@@ -192,7 +191,7 @@ void InputTransform<6, 6, float, float, WinogradRoots::Integers>::transform_tile
"fmls v10.4s, v23.4s, v0.s[3]\n"
"ldr q30, [x26, x20]\n"
"fmls v9.4s, v21.4s, v0.s[2]\n"
- "ldr q29, [x26, x9]\n"
+ "ldr q29, [x26, x10]\n"
"fmla v7.4s, v21.4s, v0.s[2]\n"
"ldr q22, [x26]\n"
"fmls v8.4s, v21.4s, v0.s[1]\n"
@@ -360,7 +359,7 @@ void InputTransform<6, 6, float, float, WinogradRoots::Integers>::transform_tile
"add x14, x14, #16\n"
"ldr q2, [x27, x20]\n"
"mov v4.16b, v2.16b\n"
- "ldr q17, [x27, x9]\n"
+ "ldr q17, [x27, x10]\n"
"mov v12.16b, v2.16b\n"
"ldr q18, [x27]\n"
"fmla v4.4s, v18.4s, v0.s[2]\n"
@@ -420,7 +419,7 @@ void InputTransform<6, 6, float, float, WinogradRoots::Integers>::transform_tile
"blt 3f\n"
"ldr d8, [%[inptr0], x20]\n"
"mov v14.16b, v8.16b\n"
- "ldr d2, [%[inptr0], x9]\n"
+ "ldr d2, [%[inptr0], x10]\n"
"mov v10.16b, v8.16b\n"
"ldr d9, [%[inptr0]]\n"
"fmla v14.4s, v9.4s, v0.s[2]\n"
@@ -432,7 +431,7 @@ void InputTransform<6, 6, float, float, WinogradRoots::Integers>::transform_tile
"fmls v14.4s, v2.4s, v0.s[3]\n"
"ldr d5, [x16, x20]\n"
"fmls v10.4s, v12.4s, v0.s[2]\n"
- "ldr d20, [x16, x9]\n"
+ "ldr d20, [x16, x10]\n"
"fmla v9.4s, v12.4s, v0.s[2]\n"
"ldr d3, [x16]\n"
"fmls v7.4s, v12.4s, v0.s[1]\n"
@@ -444,7 +443,7 @@ void InputTransform<6, 6, float, float, WinogradRoots::Integers>::transform_tile
"fsub v7.4s, v7.4s, v2.4s\n"
"ldr d17, [x17, x20]\n"
"fadd v10.4s, v10.4s, v4.4s\n"
- "ldr d15, [x17, x9]\n"
+ "ldr d15, [x17, x10]\n"
"fsub v9.4s, v9.4s, v4.4s\n"
"ldr d19, [x17]\n"
"fmla v7.4s, v4.4s, v0.s[1]\n"
@@ -534,7 +533,7 @@ void InputTransform<6, 6, float, float, WinogradRoots::Integers>::transform_tile
"mov v25.16b, v19.16b\n"
"ldr d11, [x25, x20]\n"
"mov v10.16b, v11.16b\n"
- "ldr d23, [x25, x9]\n"
+ "ldr d23, [x25, x10]\n"
"mov v9.16b, v11.16b\n"
"ldr d7, [x25]\n"
"fmla v10.4s, v7.4s, v0.s[2]\n"
@@ -546,7 +545,7 @@ void InputTransform<6, 6, float, float, WinogradRoots::Integers>::transform_tile
"fmls v10.4s, v23.4s, v0.s[3]\n"
"ldr d30, [x26, x20]\n"
"fmls v9.4s, v21.4s, v0.s[2]\n"
- "ldr d29, [x26, x9]\n"
+ "ldr d29, [x26, x10]\n"
"fmla v7.4s, v21.4s, v0.s[2]\n"
"ldr d22, [x26]\n"
"fmls v8.4s, v21.4s, v0.s[1]\n"
@@ -714,7 +713,7 @@ void InputTransform<6, 6, float, float, WinogradRoots::Integers>::transform_tile
"add x14, x14, #8\n"
"ldr d2, [x27, x20]\n"
"mov v4.16b, v2.16b\n"
- "ldr d17, [x27, x9]\n"
+ "ldr d17, [x27, x10]\n"
"mov v12.16b, v2.16b\n"
"ldr d18, [x27]\n"
"fmla v4.4s, v18.4s, v0.s[2]\n"
@@ -771,7 +770,7 @@ void InputTransform<6, 6, float, float, WinogradRoots::Integers>::transform_tile
"cbz %w[n_channels], 4f\n"
"ldr s8, [%[inptr0], x20]\n"
"mov v14.16b, v8.16b\n"
- "ldr s2, [%[inptr0], x9]\n"
+ "ldr s2, [%[inptr0], x10]\n"
"mov v10.16b, v8.16b\n"
"ldr s9, [%[inptr0]]\n"
"fmla v14.4s, v9.4s, v0.s[2]\n"
@@ -783,7 +782,7 @@ void InputTransform<6, 6, float, float, WinogradRoots::Integers>::transform_tile
"fmls v14.4s, v2.4s, v0.s[3]\n"
"ldr s5, [x16, x20]\n"
"fmls v10.4s, v12.4s, v0.s[2]\n"
- "ldr s20, [x16, x9]\n"
+ "ldr s20, [x16, x10]\n"
"fmla v9.4s, v12.4s, v0.s[2]\n"
"ldr s3, [x16]\n"
"fmls v7.4s, v12.4s, v0.s[1]\n"
@@ -795,7 +794,7 @@ void InputTransform<6, 6, float, float, WinogradRoots::Integers>::transform_tile
"fsub v7.4s, v7.4s, v2.4s\n"
"ldr s17, [x17, x20]\n"
"fadd v10.4s, v10.4s, v4.4s\n"
- "ldr s15, [x17, x9]\n"
+ "ldr s15, [x17, x10]\n"
"fsub v9.4s, v9.4s, v4.4s\n"
"ldr s19, [x17]\n"
"fmla v7.4s, v4.4s, v0.s[1]\n"
@@ -885,7 +884,7 @@ void InputTransform<6, 6, float, float, WinogradRoots::Integers>::transform_tile
"mov v25.16b, v19.16b\n"
"ldr s11, [x25, x20]\n"
"mov v10.16b, v11.16b\n"
- "ldr s23, [x25, x9]\n"
+ "ldr s23, [x25, x10]\n"
"mov v9.16b, v11.16b\n"
"ldr s7, [x25]\n"
"fmla v10.4s, v7.4s, v0.s[2]\n"
@@ -897,7 +896,7 @@ void InputTransform<6, 6, float, float, WinogradRoots::Integers>::transform_tile
"fmls v10.4s, v23.4s, v0.s[3]\n"
"ldr s30, [x26, x20]\n"
"fmls v9.4s, v21.4s, v0.s[2]\n"
- "ldr s29, [x26, x9]\n"
+ "ldr s29, [x26, x10]\n"
"fmla v7.4s, v21.4s, v0.s[2]\n"
"ldr s22, [x26]\n"
"fmls v8.4s, v21.4s, v0.s[1]\n"
@@ -1065,7 +1064,7 @@ void InputTransform<6, 6, float, float, WinogradRoots::Integers>::transform_tile
"add x14, x14, #4\n"
"ldr s2, [x27, x20]\n"
"mov v4.16b, v2.16b\n"
- "ldr s17, [x27, x9]\n"
+ "ldr s17, [x27, x10]\n"
"mov v12.16b, v2.16b\n"
"ldr s18, [x27]\n"
"fmla v4.4s, v18.4s, v0.s[2]\n"
@@ -1129,180 +1128,13 @@ void InputTransform<6, 6, float, float, WinogradRoots::Integers>::transform_tile
: "cc", "v0", "v1", "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17",
"v18", "v19", "v2", "v20", "v21", "v22", "v23", "v24", "v25", "v26",
"v27", "v28", "v29", "v3", "v30", "v31", "v4", "v5", "v6", "v7", "v8",
- "v9", "x11", "x12", "x13", "x14", "x15", "x16", "x17", "x9", "x19",
+ "v9", "x11", "x12", "x13", "x14", "x15", "x16", "x17", "x10", "x19",
"x20", "x21", "x22", "x23", "x24", "x25", "x26", "x27", "x28", "memory"
);
}
-#else // __arm__ not __aarch64__
-
-template <>
-void InputTransform<6, 6, float, float, WinogradRoots::Integers>::transform_tile(
- const int n_channels,
- const float* const input_base,
- const int input_row_stride,
- const int input_col_stride,
- float* outptr,
- const int matrix_stride
-)
-{
- constexpr int inner_tile_rows = 6;
- constexpr int inner_tile_cols = 6;
-
- // Get pointers into the input tile
- const float *x_ptrs[inner_tile_rows][inner_tile_cols];
- for (int i = 0, xi = 0; i < inner_tile_rows; i++, xi++)
- {
- // Get a pointer into the row
- const float* const row_ptr = input_base + xi*input_row_stride;
-
- for (int j = 0, xj = 0; j < inner_tile_cols; j++, xj++)
- {
- x_ptrs[i][j] = row_ptr + xj*input_col_stride;
- }
- }
-
- // Matrices used/computed in this kernel.
- float x[inner_tile_rows][inner_tile_cols];
- float XTx[inner_tile_rows][inner_tile_cols];
- float U[inner_tile_rows][inner_tile_cols];
- for (int i = 0; i < inner_tile_rows; i++)
- {
- for (int j = 0; j < inner_tile_cols; j++)
- {
- x[i][j] = XTx[i][j] = 0.0f;
- }
- }
-
- // Perform the Winograd input transformation for each channel in the input
- // tensor.
- int channels_remaining = n_channels;
- for (; channels_remaining >= 2; channels_remaining -= 2)
- {
- // Matrices used/computed in this kernel
- float32x2_t x[inner_tile_rows][inner_tile_cols];
- float32x2_t XTx[inner_tile_rows][inner_tile_cols];
- float32x2_t U[inner_tile_rows][inner_tile_cols];
- for (int i = 0; i < inner_tile_rows; i++)
- {
- for (int j = 0; j < inner_tile_cols; j++)
- {
- x[i][j] = vdup_n_f32(0.0f);
- XTx[i][j] = vdup_n_f32(0.0f);
- }
- }
-
- // Read a 6x6 tile in the Winograd domain
- for (int i = 0; i < inner_tile_rows; i++)
- {
- for (int j = 0; j < inner_tile_cols; j++)
- {
- x[i][j] = vld1_f32(x_ptrs[i][j]);
- x_ptrs[i][j] += 2;
- }
- }
-
- // Compute XT . x
- for (int j = 0; j < inner_tile_cols; j++)
- {
- // XTx[0][j] = 4*x[0][j] + -5*x[2][j] + 1*x[4][j];
- XTx[0][j] = vmls_n_f32(vmla_n_f32(x[4][j], x[0][j], 4.0f), x[2][j], 5.0f);
-
- // XTx[1][j] = -4*x[1][j] + -4*x[2][j] + 1*x[3][j] + 1*x[4][j];
- XTx[1][j] = vmls_n_f32(vadd_f32(x[3][j], x[4][j]), vadd_f32(x[1][j], x[2][j]), 4.0f);
-
- // XTx[2][j] = 4*x[1][j] + -4*x[2][j] + -1*x[3][j] + 1*x[4][j];
- XTx[2][j] = vmla_n_f32(vsub_f32(x[4][j], x[3][j]), vsub_f32(x[1][j], x[2][j]), 4.0f);
-
- // XTx[3][j] = -2*x[1][j] + -1*x[2][j] + 2*x[3][j] + 1*x[4][j];
- XTx[3][j] = vmla_n_f32(vsub_f32(x[4][j], x[2][j]), vsub_f32(x[3][j], x[1][j]), 2.0f);
-
- // XTx[4][j] = 2*x[1][j] + -1*x[2][j] + -2*x[3][j] + 1*x[4][j];
- XTx[4][j] = vmla_n_f32(vsub_f32(x[4][j], x[2][j]), vsub_f32(x[1][j], x[3][j]), 2.0f);
-
- // XTx[5][j] = 4*x[1][j] + -5*x[3][j] + 1*x[5][j];
- XTx[5][j] = vmls_n_f32(vmla_n_f32(x[5][j], x[1][j], 4.0f), x[3][j], 5.0f);
- }
-
- // Compute U = XT . x . X
- for (int i = 0; i < inner_tile_rows; i++)
- {
- // U[i][0] = 4*XTx[i][0] + -5*XTx[i][2] + 1*XTx[i][4];
- U[i][0] = vmls_n_f32(vmla_n_f32(XTx[i][4], XTx[i][0], 4.0f), XTx[i][2], 5.0f);
-
- // U[i][1] = -4*XTx[i][1] + -4*XTx[i][2] + 1*XTx[i][3] + 1*XTx[i][4];
- U[i][1] = vmls_n_f32(vadd_f32(XTx[i][3], XTx[i][4]), vadd_f32(XTx[i][1], XTx[i][2]), 4.0f);
-
- // U[i][2] = 4*XTx[i][1] + -4*XTx[i][2] + -1*XTx[i][3] + 1*XTx[i][4];
- U[i][2] = vmla_n_f32(vsub_f32(XTx[i][4], XTx[i][3]), vsub_f32(XTx[i][1], XTx[i][2]), 4.0f);
-
- // U[i][3] = -2*XTx[i][1] + -1*XTx[i][2] + 2*XTx[i][3] + 1*XTx[i][4];
- U[i][3] = vmla_n_f32(vsub_f32(XTx[i][4], XTx[i][2]), vsub_f32(XTx[i][3], XTx[i][1]), 2.0f);
-
- // U[i][4] = 2*XTx[i][1] + -1*XTx[i][2] + -2*XTx[i][3] + 1*XTx[i][4];
- U[i][4] = vmla_n_f32(vsub_f32(XTx[i][4], XTx[i][2]), vsub_f32(XTx[i][1], XTx[i][3]), 2.0f);
-
- // U[i][5] = 4*XTx[i][1] + -5*XTx[i][3] + 1*XTx[i][5];
- U[i][5] = vmls_n_f32(vmla_n_f32(XTx[i][5], XTx[i][1], 4.0f), XTx[i][3], 5.0f);
- }
-
- // Store the transformed matrix
- for (int i = 0, m = 0; i < inner_tile_rows; i++)
- {
- for (int j = 0; j < inner_tile_cols; j++, m++)
- {
- vst1_f32(outptr + m*matrix_stride, U[i][j]);
- }
- }
- outptr += 2;
- }
- for (; channels_remaining; channels_remaining--)
- {
- // Load x
- for (int i = 0; i < inner_tile_rows; i++)
- {
- for (int j = 0; j < inner_tile_cols; j++)
- {
- x[i][j] = *(x_ptrs[i][j]++);
- }
- }
-
- // Compute XT . x
- for (int j = 0; j < inner_tile_cols; j++)
- {
- XTx[0][j] = 4*x[0][j] + -5*x[2][j] + 1*x[4][j];
- XTx[1][j] = -4*x[1][j] + -4*x[2][j] + 1*x[3][j] + 1*x[4][j];
- XTx[2][j] = 4*x[1][j] + -4*x[2][j] + -1*x[3][j] + 1*x[4][j];
- XTx[3][j] = -2*x[1][j] + -1*x[2][j] + 2*x[3][j] + 1*x[4][j];
- XTx[4][j] = 2*x[1][j] + -1*x[2][j] + -2*x[3][j] + 1*x[4][j];
- XTx[5][j] = 4*x[1][j] + -5*x[3][j] + 1*x[5][j];
- }
-
- // Compute U = XT . x . X
- for (int i = 0; i < inner_tile_rows; i++)
- {
- U[i][0] = 4*XTx[i][0] + -5*XTx[i][2] + 1*XTx[i][4];
- U[i][1] = -4*XTx[i][1] + -4*XTx[i][2] + 1*XTx[i][3] + 1*XTx[i][4];
- U[i][2] = 4*XTx[i][1] + -4*XTx[i][2] + -1*XTx[i][3] + 1*XTx[i][4];
- U[i][3] = -2*XTx[i][1] + -1*XTx[i][2] + 2*XTx[i][3] + 1*XTx[i][4];
- U[i][4] = 2*XTx[i][1] + -1*XTx[i][2] + -2*XTx[i][3] + 1*XTx[i][4];
- U[i][5] = 4*XTx[i][1] + -5*XTx[i][3] + 1*XTx[i][5];
- }
-
- // Store the transformed matrix
- for (int i = 0, m = 0; i < inner_tile_rows; i++)
- {
- for (int j = 0; j < inner_tile_cols; j++, m++)
- {
- *(outptr + m*matrix_stride) = U[i][j];
- }
- }
- outptr++;
- }
-}
-
-#endif
-
-template class InputTransform<6, 6, float, float, WinogradRoots::Integers>;
-
+} // namespace input_transform
} // namespace winograd
+} // namespace arm_conv
+
+#endif // __aarch64__
diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_1x8_fp32_fp32_integers.cpp b/src/core/NEON/kernels/convolution/winograd/input_transforms/arm_fp32_1x8.cpp
index 8f6e9e8b40..2d6b333a59 100644
--- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_1x8_fp32_fp32_integers.cpp
+++ b/src/core/NEON/kernels/convolution/winograd/input_transforms/arm_fp32_1x8.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019 Arm Limited.
+ * Copyright (c) 2022 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -22,20 +22,20 @@
* SOFTWARE.
*/
-#include "arm.hpp"
-#include "input.hpp"
+#include <cstddef>
+#include <arm_neon.h>
-namespace winograd
-{
+namespace arm_conv {
+namespace winograd {
+namespace input_transform {
-template <>
-void InputTransform<1, 8, float, float, WinogradRoots::Integers>::transform_tile(
- const int n_channels,
- const float* const input_base,
- const int, // We don't need to stride over rows
- const int input_col_stride,
- float* outptr,
- const int matrix_stride
+void arm_fp32_1x8(
+ const unsigned int n_channels,
+ const float *const input_base,
+ size_t, // We don't need to stride over rows
+ const size_t input_col_stride,
+ float *outptr,
+ const size_t matrix_stride
)
{
constexpr int inner_tile_cols = 8;
@@ -59,7 +59,6 @@ void InputTransform<1, 8, float, float, WinogradRoots::Integers>::transform_tile
// Perform the Winograd input transformation for each channel in the input
// tensor.
int channels_remaining = n_channels;
-#ifdef _arm_any_
for (; channels_remaining >= 4; channels_remaining -= 4)
{
float32x4_t x[inner_tile_cols], U[inner_tile_cols];
@@ -124,7 +123,6 @@ void InputTransform<1, 8, float, float, WinogradRoots::Integers>::transform_tile
}
outptr += 2;
}
-#endif // _arm_any_
for (; channels_remaining; channels_remaining--)
{
// Load x
@@ -152,7 +150,6 @@ void InputTransform<1, 8, float, float, WinogradRoots::Integers>::transform_tile
}
}
-template class InputTransform<1, 8, float, float, WinogradRoots::Integers>;
-template class InputTransform<8, 1, float, float, WinogradRoots::Integers>;
-
+} // namespace input_transform
} // namespace winograd
+} // namespace arm_conv
diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_4x4_fp32_fp32_integers.cpp b/src/core/NEON/kernels/convolution/winograd/input_transforms/arm_fp32_4x4.cpp
index 69d3e8feb5..fae0173374 100644
--- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_4x4_fp32_fp32_integers.cpp
+++ b/src/core/NEON/kernels/convolution/winograd/input_transforms/arm_fp32_4x4.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019 Arm Limited.
+ * Copyright (c) 2022 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -22,20 +22,20 @@
* SOFTWARE.
*/
-#include "input.hpp"
-#include "arm.hpp"
+#include <cstddef>
+#include <arm_neon.h>
-namespace winograd
-{
+namespace arm_conv {
+namespace winograd {
+namespace input_transform {
-template <>
-void InputTransform<4, 4, float, float, WinogradRoots::Integers>::transform_tile(
- const int n_channels,
- const float* const input_base,
- const int input_row_stride,
- const int input_col_stride,
- float* outptr,
- const int matrix_stride
+void arm_fp32_4x4(
+ const unsigned int n_channels,
+ const float *input_base,
+ const size_t input_row_stride,
+ const size_t input_col_stride,
+ float *outptr,
+ const size_t matrix_stride
)
{
constexpr int inner_tile_rows = 4, inner_tile_cols = 4;
@@ -69,7 +69,6 @@ void InputTransform<4, 4, float, float, WinogradRoots::Integers>::transform_tile
// Perform the Winograd input transformation for each channel in the input
// tensor.
int channels_remaining = n_channels;
-#ifdef __aarch64__
for (; channels_remaining >= 4; channels_remaining -= 4)
{
// Matrices used/computed in this kernel.
@@ -138,8 +137,6 @@ void InputTransform<4, 4, float, float, WinogradRoots::Integers>::transform_tile
}
outptr += 4;
}
-#endif // __aarch64__
-#ifdef __arm_any__
for (; channels_remaining >= 2; channels_remaining -= 2)
{
// Matrices used/computed in this kernel.
@@ -208,7 +205,6 @@ void InputTransform<4, 4, float, float, WinogradRoots::Integers>::transform_tile
}
outptr += 2;
}
-#endif // __arm_any__
for (; channels_remaining; channels_remaining--)
{
// Load x
@@ -250,6 +246,6 @@ void InputTransform<4, 4, float, float, WinogradRoots::Integers>::transform_tile
}
}
-template class InputTransform<4, 4, float, float, WinogradRoots::Integers>;
-
-} // namespace
+} // namespace input_transform
+} // namespace winograd
+} // namespace arm_conv
diff --git a/src/core/NEON/kernels/convolution/winograd/input_transforms/arm_fp32_6x6.cpp b/src/core/NEON/kernels/convolution/winograd/input_transforms/arm_fp32_6x6.cpp
new file mode 100644
index 0000000000..4adc45768e
--- /dev/null
+++ b/src/core/NEON/kernels/convolution/winograd/input_transforms/arm_fp32_6x6.cpp
@@ -0,0 +1,202 @@
+/*
+ * Copyright (c) 2022 Arm Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef __aarch64__
+
+#include <arm_neon.h>
+#include <cstddef>
+
+namespace arm_conv {
+namespace winograd {
+namespace input_transform {
+
+void arm_fp32_6x6(
+ unsigned int n_channels,
+ const float* const input_base,
+ const size_t input_row_stride,
+ const size_t input_col_stride,
+ float* outptr,
+ const size_t matrix_stride
+)
+{
+ constexpr int inner_tile_rows = 6;
+ constexpr int inner_tile_cols = 6;
+
+ // Get pointers into the input tile
+ const float *x_ptrs[inner_tile_rows][inner_tile_cols];
+ for (int i = 0, xi = 0; i < inner_tile_rows; i++, xi++)
+ {
+ // Get a pointer into the row
+ const float* const row_ptr = input_base + xi*input_row_stride;
+
+ for (int j = 0, xj = 0; j < inner_tile_cols; j++, xj++)
+ {
+ x_ptrs[i][j] = row_ptr + xj*input_col_stride;
+ }
+ }
+
+ // Matrices used/computed in this kernel.
+ float x[inner_tile_rows][inner_tile_cols];
+ float XTx[inner_tile_rows][inner_tile_cols];
+ float U[inner_tile_rows][inner_tile_cols];
+ for (int i = 0; i < inner_tile_rows; i++)
+ {
+ for (int j = 0; j < inner_tile_cols; j++)
+ {
+ x[i][j] = XTx[i][j] = 0.0f;
+ }
+ }
+
+ // Perform the Winograd input transformation for each channel in the input
+ // tensor.
+ int channels_remaining = n_channels;
+ for (; channels_remaining >= 2; channels_remaining -= 2)
+ {
+ // Matrices used/computed in this kernel
+ float32x2_t x[inner_tile_rows][inner_tile_cols];
+ float32x2_t XTx[inner_tile_rows][inner_tile_cols];
+ float32x2_t U[inner_tile_rows][inner_tile_cols];
+ for (int i = 0; i < inner_tile_rows; i++)
+ {
+ for (int j = 0; j < inner_tile_cols; j++)
+ {
+ x[i][j] = vdup_n_f32(0.0f);
+ XTx[i][j] = vdup_n_f32(0.0f);
+ }
+ }
+
+ // Read a 6x6 tile in the Winograd domain
+ for (int i = 0; i < inner_tile_rows; i++)
+ {
+ for (int j = 0; j < inner_tile_cols; j++)
+ {
+ x[i][j] = vld1_f32(x_ptrs[i][j]);
+ x_ptrs[i][j] += 2;
+ }
+ }
+
+ // Compute XT . x
+ for (int j = 0; j < inner_tile_cols; j++)
+ {
+ // XTx[0][j] = 4*x[0][j] + -5*x[2][j] + 1*x[4][j];
+ XTx[0][j] = vmls_n_f32(vmla_n_f32(x[4][j], x[0][j], 4.0f), x[2][j], 5.0f);
+
+ // XTx[1][j] = -4*x[1][j] + -4*x[2][j] + 1*x[3][j] + 1*x[4][j];
+ XTx[1][j] = vmls_n_f32(vadd_f32(x[3][j], x[4][j]), vadd_f32(x[1][j], x[2][j]), 4.0f);
+
+ // XTx[2][j] = 4*x[1][j] + -4*x[2][j] + -1*x[3][j] + 1*x[4][j];
+ XTx[2][j] = vmla_n_f32(vsub_f32(x[4][j], x[3][j]), vsub_f32(x[1][j], x[2][j]), 4.0f);
+
+ // XTx[3][j] = -2*x[1][j] + -1*x[2][j] + 2*x[3][j] + 1*x[4][j];
+ XTx[3][j] = vmla_n_f32(vsub_f32(x[4][j], x[2][j]), vsub_f32(x[3][j], x[1][j]), 2.0f);
+
+ // XTx[4][j] = 2*x[1][j] + -1*x[2][j] + -2*x[3][j] + 1*x[4][j];
+ XTx[4][j] = vmla_n_f32(vsub_f32(x[4][j], x[2][j]), vsub_f32(x[1][j], x[3][j]), 2.0f);
+
+ // XTx[5][j] = 4*x[1][j] + -5*x[3][j] + 1*x[5][j];
+ XTx[5][j] = vmls_n_f32(vmla_n_f32(x[5][j], x[1][j], 4.0f), x[3][j], 5.0f);
+ }
+
+ // Compute U = XT . x . X
+ for (int i = 0; i < inner_tile_rows; i++)
+ {
+ // U[i][0] = 4*XTx[i][0] + -5*XTx[i][2] + 1*XTx[i][4];
+ U[i][0] = vmls_n_f32(vmla_n_f32(XTx[i][4], XTx[i][0], 4.0f), XTx[i][2], 5.0f);
+
+ // U[i][1] = -4*XTx[i][1] + -4*XTx[i][2] + 1*XTx[i][3] + 1*XTx[i][4];
+ U[i][1] = vmls_n_f32(vadd_f32(XTx[i][3], XTx[i][4]), vadd_f32(XTx[i][1], XTx[i][2]), 4.0f);
+
+ // U[i][2] = 4*XTx[i][1] + -4*XTx[i][2] + -1*XTx[i][3] + 1*XTx[i][4];
+ U[i][2] = vmla_n_f32(vsub_f32(XTx[i][4], XTx[i][3]), vsub_f32(XTx[i][1], XTx[i][2]), 4.0f);
+
+ // U[i][3] = -2*XTx[i][1] + -1*XTx[i][2] + 2*XTx[i][3] + 1*XTx[i][4];
+ U[i][3] = vmla_n_f32(vsub_f32(XTx[i][4], XTx[i][2]), vsub_f32(XTx[i][3], XTx[i][1]), 2.0f);
+
+ // U[i][4] = 2*XTx[i][1] + -1*XTx[i][2] + -2*XTx[i][3] + 1*XTx[i][4];
+ U[i][4] = vmla_n_f32(vsub_f32(XTx[i][4], XTx[i][2]), vsub_f32(XTx[i][1], XTx[i][3]), 2.0f);
+
+ // U[i][5] = 4*XTx[i][1] + -5*XTx[i][3] + 1*XTx[i][5];
+ U[i][5] = vmls_n_f32(vmla_n_f32(XTx[i][5], XTx[i][1], 4.0f), XTx[i][3], 5.0f);
+ }
+
+ // Store the transformed matrix
+ for (int i = 0, m = 0; i < inner_tile_rows; i++)
+ {
+ for (int j = 0; j < inner_tile_cols; j++, m++)
+ {
+ vst1_f32(outptr + m*matrix_stride, U[i][j]);
+ }
+ }
+ outptr += 2;
+ }
+ for (; channels_remaining; channels_remaining--)
+ {
+ // Load x
+ for (int i = 0; i < inner_tile_rows; i++)
+ {
+ for (int j = 0; j < inner_tile_cols; j++)
+ {
+ x[i][j] = *(x_ptrs[i][j]++);
+ }
+ }
+
+ // Compute XT . x
+ for (int j = 0; j < inner_tile_cols; j++)
+ {
+ XTx[0][j] = 4*x[0][j] + -5*x[2][j] + 1*x[4][j];
+ XTx[1][j] = -4*x[1][j] + -4*x[2][j] + 1*x[3][j] + 1*x[4][j];
+ XTx[2][j] = 4*x[1][j] + -4*x[2][j] + -1*x[3][j] + 1*x[4][j];
+ XTx[3][j] = -2*x[1][j] + -1*x[2][j] + 2*x[3][j] + 1*x[4][j];
+ XTx[4][j] = 2*x[1][j] + -1*x[2][j] + -2*x[3][j] + 1*x[4][j];
+ XTx[5][j] = 4*x[1][j] + -5*x[3][j] + 1*x[5][j];
+ }
+
+ // Compute U = XT . x . X
+ for (int i = 0; i < inner_tile_rows; i++)
+ {
+ U[i][0] = 4*XTx[i][0] + -5*XTx[i][2] + 1*XTx[i][4];
+ U[i][1] = -4*XTx[i][1] + -4*XTx[i][2] + 1*XTx[i][3] + 1*XTx[i][4];
+ U[i][2] = 4*XTx[i][1] + -4*XTx[i][2] + -1*XTx[i][3] + 1*XTx[i][4];
+ U[i][3] = -2*XTx[i][1] + -1*XTx[i][2] + 2*XTx[i][3] + 1*XTx[i][4];
+ U[i][4] = 2*XTx[i][1] + -1*XTx[i][2] + -2*XTx[i][3] + 1*XTx[i][4];
+ U[i][5] = 4*XTx[i][1] + -5*XTx[i][3] + 1*XTx[i][5];
+ }
+
+ // Store the transformed matrix
+ for (int i = 0, m = 0; i < inner_tile_rows; i++)
+ {
+ for (int j = 0; j < inner_tile_cols; j++, m++)
+ {
+ *(outptr + m*matrix_stride) = U[i][j];
+ }
+ }
+ outptr++;
+ }
+}
+
+} // namespace input_transform
+} // namespace winograd
+} // namespace arm_conv
+
+#endif // ! __aarch64__
diff --git a/src/core/NEON/kernels/convolution/winograd/input_transforms/sve_fp32_6x6.cpp b/src/core/NEON/kernels/convolution/winograd/input_transforms/sve_fp32_6x6.cpp
new file mode 100644
index 0000000000..a2f096f489
--- /dev/null
+++ b/src/core/NEON/kernels/convolution/winograd/input_transforms/sve_fp32_6x6.cpp
@@ -0,0 +1,361 @@
+/*
+ * Copyright (c) 2022 ARM Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#if __aarch64__ && defined(ARM_COMPUTE_ENABLE_SVE)
+#include <cstddef>
+
+namespace arm_conv {
+namespace winograd {
+namespace input_transform {
+
+void sve_fp32_6x6(
+ const unsigned int num_channels,
+ const float *input,
+ const size_t input_row_stride,
+ const size_t input_col_stride,
+ float *output,
+ const size_t output_col_stride
+)
+{
+ const float B_values[4] = { 1.0f, 2.0f, 4.0f, 5.0f };
+ long long_channels = num_channels;
+
+ // Generated by armasmgen (February 04th, 2021)
+ __asm__ __volatile__(
+ "fmov z16.s, #4.0\n"
+ "ptrue p1.b\n"
+ "ld1rqw { z2.s }, p1/Z, [%x[B_values]]\n"
+ "add x16, %x[input_row_0], %x[input_row_stride], LSL #2\n"
+ "add x15, %x[output_row_0], %x[output_row_stride], LSL #2\n"
+ "add x14, %x[input_row_0], %x[input_row_stride], LSL #3\n"
+ "add x13, %x[output_row_0], %x[output_row_stride], LSL #3\n"
+ "add x12, x14, %x[input_row_stride], LSL #2\n"
+ "add x11, x13, %x[output_row_stride], LSL #2\n"
+ "add x10, %x[input_row_0], %x[input_row_stride], LSL #4\n"
+ "add x9, %x[output_row_0], %x[output_row_stride], LSL #4\n"
+ "add x28, x10, %x[input_row_stride], LSL #2\n"
+ "add x27, x9, %x[output_row_stride], LSL #2\n"
+ "lsl x26, %x[input_col_1_stride], #0x1\n"
+ "lsl x25, %x[output_col_1_stride], #0x1\n"
+ "add x24, x26, %x[input_col_1_stride]\n"
+ "add x23, x25, %x[output_col_1_stride]\n"
+ "lsl x22, %x[input_col_1_stride], #0x2\n"
+ "lsl x21, %x[output_col_1_stride], #0x2\n"
+ "add x20, x22, %x[input_col_1_stride]\n"
+ "add x19, x21, %x[output_col_1_stride]\n"
+ "whilelt p0.s, XZR, %x[num_channels]\n"
+ "beq 2f\n"
+ "1:" // channel_loop
+ "ld1w { z31.s }, p0/Z, [%x[input_row_0]]\n"
+ "decw %x[num_channels]\n"
+ "ld1w { z28.s }, p0/Z, [%x[input_row_0], %x[input_col_1_stride], LSL #2]\n"
+ "fmul z13.s, z28.s, z2.s[1]\n"
+ "ld1w { z27.s }, p0/Z, [%x[input_row_0], x26, LSL #2]\n"
+ "ld1w { z11.s }, p0/Z, [%x[input_row_0], x24, LSL #2]\n"
+ "fneg z13.s, p1/M, z13.s\n"
+ "ld1w { z7.s }, p0/Z, [%x[input_row_0], x22, LSL #2]\n"
+ "fsub z15.s, z7.s, z27.s\n"
+ "fmad z31.s, p1/M, z16.s, z7.s\n"
+ "ld1w { z3.s }, p0/Z, [%x[input_row_0], x20, LSL #2]\n"
+ "fmla z13.s, z11.s, z2.s[1]\n"
+ "ld1w { z12.s }, p0/Z, [x14]\n"
+ "incb %x[input_row_0]\n"
+ "fmls z31.s, z27.s, z2.s[3]\n"
+ "ld1w { z14.s }, p0/Z, [x14, %x[input_col_1_stride], LSL #2]\n"
+ "fsub z25.s, z15.s, z13.s\n"
+ "fadd z8.s, z13.s, z15.s\n"
+ "ld1w { z24.s }, p0/Z, [x14, x26, LSL #2]\n"
+ "fmsb z27.s, p1/M, z16.s, z7.s\n"
+ "ld1w { z22.s }, p0/Z, [x14, x24, LSL #2]\n"
+ "fmul z7.s, z28.s, z2.s[2]\n"
+ "ld1w { z1.s }, p0/Z, [x14, x22, LSL #2]\n"
+ "fsub z15.s, z1.s, z24.s\n"
+ "fneg z7.s, p1/M, z7.s\n"
+ "ld1w { z20.s }, p0/Z, [x14, x20, LSL #2]\n"
+ "fadd z7.s, z7.s, z11.s\n"
+ "ld1w { z29.s }, p0/Z, [x10]\n"
+ "incb x14\n"
+ "fmad z28.s, p1/M, z16.s, z3.s\n"
+ "ld1w { z10.s }, p0/Z, [x10, %x[input_col_1_stride], LSL #2]\n"
+ "fmad z12.s, p1/M, z16.s, z1.s\n"
+ "ld1w { z18.s }, p0/Z, [x10, x26, LSL #2]\n"
+ "fmul z13.s, z14.s, z2.s[1]\n"
+ "ld1w { z19.s }, p0/Z, [x10, x24, LSL #2]\n"
+ "fadd z17.s, z7.s, z27.s\n"
+ "ld1w { z9.s }, p0/Z, [x10, x22, LSL #2]\n"
+ "fsub z27.s, z27.s, z7.s\n"
+ "fmls z28.s, z11.s, z2.s[3]\n"
+ "ld1w { z21.s }, p0/Z, [x10, x20, LSL #2]\n"
+ "incb x10\n"
+ "fmls z12.s, z24.s, z2.s[3]\n"
+ "fneg z13.s, p1/M, z13.s\n"
+ "fmla z13.s, z22.s, z2.s[1]\n"
+ "fsub z30.s, z15.s, z13.s\n"
+ "fadd z4.s, z13.s, z15.s\n"
+ "fmsb z24.s, p1/M, z16.s, z1.s\n"
+ "fsub z15.s, z9.s, z18.s\n"
+ "fmul z1.s, z14.s, z2.s[2]\n"
+ "fmad z14.s, p1/M, z16.s, z20.s\n"
+ "fmad z29.s, p1/M, z16.s, z9.s\n"
+ "fmul z13.s, z10.s, z2.s[1]\n"
+ "fneg z1.s, p1/M, z1.s\n"
+ "fadd z1.s, z1.s, z22.s\n"
+ "fmls z14.s, z22.s, z2.s[3]\n"
+ "fmls z29.s, z18.s, z2.s[3]\n"
+ "fadd z5.s, z1.s, z24.s\n"
+ "fsub z24.s, z24.s, z1.s\n"
+ "fneg z13.s, p1/M, z13.s\n"
+ "fmla z13.s, z19.s, z2.s[1]\n"
+ "fsub z23.s, z15.s, z13.s\n"
+ "fadd z11.s, z13.s, z15.s\n"
+ "fmsb z18.s, p1/M, z16.s, z9.s\n"
+ "fmul z9.s, z10.s, z2.s[2]\n"
+ "fmad z10.s, p1/M, z16.s, z21.s\n"
+ "fmad z31.s, p1/M, z16.s, z29.s\n"
+ "fmad z8.s, p1/M, z16.s, z11.s\n"
+ "fneg z9.s, p1/M, z9.s\n"
+ "fadd z9.s, z9.s, z19.s\n"
+ "fmls z10.s, z19.s, z2.s[3]\n"
+ "fmls z31.s, z12.s, z2.s[3]\n"
+ "st1w { z31.s }, p0, [%x[output_row_0]]\n"
+ "fadd z26.s, z9.s, z18.s\n"
+ "fsub z18.s, z18.s, z9.s\n"
+ "fmls z8.s, z4.s, z2.s[3]\n"
+ "fmad z25.s, p1/M, z16.s, z23.s\n"
+ "fmad z28.s, p1/M, z16.s, z10.s\n"
+ "fmad z17.s, p1/M, z16.s, z26.s\n"
+ "fmad z27.s, p1/M, z16.s, z18.s\n"
+ "fmls z25.s, z30.s, z2.s[3]\n"
+ "fmls z28.s, z14.s, z2.s[3]\n"
+ "fmls z17.s, z5.s, z2.s[3]\n"
+ "st1w { z17.s }, p0, [%x[output_row_0], %x[output_col_1_stride], LSL #2]\n"
+ "fmls z27.s, z24.s, z2.s[3]\n"
+ "st1w { z27.s }, p0, [%x[output_row_0], x25, LSL #2]\n"
+ "st1w { z8.s }, p0, [%x[output_row_0], x23, LSL #2]\n"
+ "st1w { z25.s }, p0, [%x[output_row_0], x21, LSL #2]\n"
+ "st1w { z28.s }, p0, [%x[output_row_0], x19, LSL #2]\n"
+ "incb %x[output_row_0]\n"
+ "ld1w { z19.s }, p0/Z, [x16]\n"
+ "ld1w { z7.s }, p0/Z, [x16, %x[input_col_1_stride], LSL #2]\n"
+ "fmul z13.s, z7.s, z2.s[1]\n"
+ "ld1w { z6.s }, p0/Z, [x16, x26, LSL #2]\n"
+ "ld1w { z27.s }, p0/Z, [x16, x24, LSL #2]\n"
+ "fneg z13.s, p1/M, z13.s\n"
+ "ld1w { z25.s }, p0/Z, [x16, x22, LSL #2]\n"
+ "fsub z15.s, z25.s, z6.s\n"
+ "fmad z19.s, p1/M, z16.s, z25.s\n"
+ "ld1w { z20.s }, p0/Z, [x16, x20, LSL #2]\n"
+ "fmla z13.s, z27.s, z2.s[1]\n"
+ "ld1w { z0.s }, p0/Z, [x12]\n"
+ "incb x16\n"
+ "fmls z19.s, z6.s, z2.s[3]\n"
+ "ld1w { z31.s }, p0/Z, [x12, %x[input_col_1_stride], LSL #2]\n"
+ "fsub z8.s, z15.s, z13.s\n"
+ "fadd z28.s, z13.s, z15.s\n"
+ "ld1w { z1.s }, p0/Z, [x12, x26, LSL #2]\n"
+ "fmsb z6.s, p1/M, z16.s, z25.s\n"
+ "ld1w { z21.s }, p0/Z, [x12, x24, LSL #2]\n"
+ "fmul z25.s, z7.s, z2.s[2]\n"
+ "ld1w { z22.s }, p0/Z, [x12, x22, LSL #2]\n"
+ "fsub z15.s, z22.s, z1.s\n"
+ "fneg z25.s, p1/M, z25.s\n"
+ "ld1w { z17.s }, p0/Z, [x12, x20, LSL #2]\n"
+ "fadd z25.s, z25.s, z27.s\n"
+ "incb x12\n"
+ "fmad z7.s, p1/M, z16.s, z20.s\n"
+ "fmad z0.s, p1/M, z16.s, z22.s\n"
+ "fmul z13.s, z31.s, z2.s[1]\n"
+ "fadd z3.s, z25.s, z6.s\n"
+ "fsub z6.s, z6.s, z25.s\n"
+ "fmls z7.s, z27.s, z2.s[3]\n"
+ "fmls z0.s, z1.s, z2.s[3]\n"
+ "fneg z13.s, p1/M, z13.s\n"
+ "fmla z13.s, z21.s, z2.s[1]\n"
+ "fsub z9.s, z15.s, z13.s\n"
+ "fadd z27.s, z13.s, z15.s\n"
+ "fmsb z1.s, p1/M, z16.s, z22.s\n"
+ "fsub z15.s, z29.s, z12.s\n"
+ "fmul z22.s, z31.s, z2.s[2]\n"
+ "fmad z31.s, p1/M, z16.s, z17.s\n"
+ "fmul z13.s, z19.s, z2.s[1]\n"
+ "fmsb z12.s, p1/M, z16.s, z29.s\n"
+ "fneg z22.s, p1/M, z22.s\n"
+ "fadd z22.s, z22.s, z21.s\n"
+ "fmls z31.s, z21.s, z2.s[3]\n"
+ "fneg z13.s, p1/M, z13.s\n"
+ "fadd z25.s, z22.s, z1.s\n"
+ "fsub z1.s, z1.s, z22.s\n"
+ "fmla z13.s, z0.s, z2.s[1]\n"
+ "fmul z29.s, z19.s, z2.s[2]\n"
+ "fadd z22.s, z13.s, z15.s\n"
+ "st1w { z22.s }, p0, [x11]\n"
+ "fneg z29.s, p1/M, z29.s\n"
+ "fsub z22.s, z15.s, z13.s\n"
+ "fadd z29.s, z29.s, z0.s\n"
+ "st1w { z22.s }, p0, [x9]\n"
+ "fadd z22.s, z29.s, z12.s\n"
+ "fsub z15.s, z26.s, z5.s\n"
+ "fmul z13.s, z3.s, z2.s[1]\n"
+ "fsub z12.s, z12.s, z29.s\n"
+ "fmsb z5.s, p1/M, z16.s, z26.s\n"
+ "fmul z26.s, z3.s, z2.s[2]\n"
+ "fneg z13.s, p1/M, z13.s\n"
+ "fmla z13.s, z25.s, z2.s[1]\n"
+ "fneg z26.s, p1/M, z26.s\n"
+ "fadd z26.s, z26.s, z25.s\n"
+ "fadd z21.s, z13.s, z15.s\n"
+ "st1w { z21.s }, p0, [x11, %x[output_col_1_stride], LSL #2]\n"
+ "fsub z21.s, z15.s, z13.s\n"
+ "fmul z13.s, z6.s, z2.s[1]\n"
+ "fneg z13.s, p1/M, z13.s\n"
+ "st1w { z21.s }, p0, [x9, %x[output_col_1_stride], LSL #2]\n"
+ "fadd z21.s, z26.s, z5.s\n"
+ "fsub z15.s, z18.s, z24.s\n"
+ "fmla z13.s, z1.s, z2.s[1]\n"
+ "fsub z5.s, z5.s, z26.s\n"
+ "fmsb z24.s, p1/M, z16.s, z18.s\n"
+ "fmul z18.s, z6.s, z2.s[2]\n"
+ "fadd z20.s, z13.s, z15.s\n"
+ "st1w { z20.s }, p0, [x11, x25, LSL #2]\n"
+ "fneg z18.s, p1/M, z18.s\n"
+ "fsub z20.s, z15.s, z13.s\n"
+ "fadd z18.s, z18.s, z1.s\n"
+ "st1w { z20.s }, p0, [x9, x25, LSL #2]\n"
+ "fadd z20.s, z18.s, z24.s\n"
+ "fsub z15.s, z11.s, z4.s\n"
+ "fmul z13.s, z28.s, z2.s[1]\n"
+ "fsub z24.s, z24.s, z18.s\n"
+ "fmsb z4.s, p1/M, z16.s, z11.s\n"
+ "fmul z11.s, z28.s, z2.s[2]\n"
+ "fneg z13.s, p1/M, z13.s\n"
+ "fmla z13.s, z27.s, z2.s[1]\n"
+ "fneg z11.s, p1/M, z11.s\n"
+ "fadd z11.s, z11.s, z27.s\n"
+ "fadd z26.s, z13.s, z15.s\n"
+ "st1w { z26.s }, p0, [x11, x23, LSL #2]\n"
+ "fsub z26.s, z15.s, z13.s\n"
+ "fmul z13.s, z8.s, z2.s[1]\n"
+ "fneg z13.s, p1/M, z13.s\n"
+ "st1w { z26.s }, p0, [x9, x23, LSL #2]\n"
+ "fadd z26.s, z11.s, z4.s\n"
+ "fsub z15.s, z23.s, z30.s\n"
+ "fmla z13.s, z9.s, z2.s[1]\n"
+ "fsub z4.s, z4.s, z11.s\n"
+ "fmsb z30.s, p1/M, z16.s, z23.s\n"
+ "fmul z23.s, z8.s, z2.s[2]\n"
+ "fadd z18.s, z13.s, z15.s\n"
+ "st1w { z18.s }, p0, [x11, x21, LSL #2]\n"
+ "fneg z23.s, p1/M, z23.s\n"
+ "fsub z18.s, z15.s, z13.s\n"
+ "fadd z23.s, z23.s, z9.s\n"
+ "st1w { z18.s }, p0, [x9, x21, LSL #2]\n"
+ "fadd z18.s, z23.s, z30.s\n"
+ "fsub z15.s, z10.s, z14.s\n"
+ "fmul z13.s, z7.s, z2.s[1]\n"
+ "fsub z30.s, z30.s, z23.s\n"
+ "fmsb z14.s, p1/M, z16.s, z10.s\n"
+ "fmul z10.s, z7.s, z2.s[2]\n"
+ "fneg z13.s, p1/M, z13.s\n"
+ "fmla z13.s, z31.s, z2.s[1]\n"
+ "fneg z10.s, p1/M, z10.s\n"
+ "fadd z10.s, z10.s, z31.s\n"
+ "fadd z17.s, z13.s, z15.s\n"
+ "st1w { z17.s }, p0, [x11, x19, LSL #2]\n"
+ "fsub z17.s, z15.s, z13.s\n"
+ "incb x11\n"
+ "st1w { z17.s }, p0, [x9, x19, LSL #2]\n"
+ "fadd z17.s, z10.s, z14.s\n"
+ "fsub z14.s, z14.s, z10.s\n"
+ "st1w { z22.s }, p0, [x15]\n"
+ "incb x9\n"
+ "st1w { z12.s }, p0, [x13]\n"
+ "st1w { z21.s }, p0, [x15, %x[output_col_1_stride], LSL #2]\n"
+ "st1w { z5.s }, p0, [x13, %x[output_col_1_stride], LSL #2]\n"
+ "st1w { z20.s }, p0, [x15, x25, LSL #2]\n"
+ "st1w { z24.s }, p0, [x13, x25, LSL #2]\n"
+ "st1w { z26.s }, p0, [x15, x23, LSL #2]\n"
+ "st1w { z4.s }, p0, [x13, x23, LSL #2]\n"
+ "st1w { z18.s }, p0, [x15, x21, LSL #2]\n"
+ "st1w { z30.s }, p0, [x13, x21, LSL #2]\n"
+ "st1w { z17.s }, p0, [x15, x19, LSL #2]\n"
+ "incb x15\n"
+ "st1w { z14.s }, p0, [x13, x19, LSL #2]\n"
+ "incb x13\n"
+ "ld1w { z23.s }, p0/Z, [x28]\n"
+ "ld1w { z22.s }, p0/Z, [x28, %x[input_col_1_stride], LSL #2]\n"
+ "fmul z13.s, z22.s, z2.s[1]\n"
+ "ld1w { z21.s }, p0/Z, [x28, x26, LSL #2]\n"
+ "ld1w { z20.s }, p0/Z, [x28, x24, LSL #2]\n"
+ "fneg z13.s, p1/M, z13.s\n"
+ "ld1w { z26.s }, p0/Z, [x28, x22, LSL #2]\n"
+ "fsub z15.s, z26.s, z21.s\n"
+ "fmad z23.s, p1/M, z16.s, z26.s\n"
+ "ld1w { z18.s }, p0/Z, [x28, x20, LSL #2]\n"
+ "fmla z13.s, z20.s, z2.s[1]\n"
+ "incb x28\n"
+ "fmls z23.s, z21.s, z2.s[3]\n"
+ "fsub z17.s, z15.s, z13.s\n"
+ "fadd z30.s, z13.s, z15.s\n"
+ "fmsb z21.s, p1/M, z16.s, z26.s\n"
+ "fmul z26.s, z22.s, z2.s[2]\n"
+ "fmad z22.s, p1/M, z16.s, z18.s\n"
+ "fmad z19.s, p1/M, z16.s, z23.s\n"
+ "fmad z28.s, p1/M, z16.s, z30.s\n"
+ "fneg z26.s, p1/M, z26.s\n"
+ "fadd z26.s, z26.s, z20.s\n"
+ "fmls z22.s, z20.s, z2.s[3]\n"
+ "fmls z19.s, z0.s, z2.s[3]\n"
+ "st1w { z19.s }, p0, [x27]\n"
+ "fadd z23.s, z26.s, z21.s\n"
+ "fsub z21.s, z21.s, z26.s\n"
+ "fmls z28.s, z27.s, z2.s[3]\n"
+ "fmad z8.s, p1/M, z16.s, z17.s\n"
+ "fmad z7.s, p1/M, z16.s, z22.s\n"
+ "fmad z3.s, p1/M, z16.s, z23.s\n"
+ "fmad z6.s, p1/M, z16.s, z21.s\n"
+ "fmls z8.s, z9.s, z2.s[3]\n"
+ "fmls z7.s, z31.s, z2.s[3]\n"
+ "fmls z3.s, z25.s, z2.s[3]\n"
+ "st1w { z3.s }, p0, [x27, %x[output_col_1_stride], LSL #2]\n"
+ "fmls z6.s, z1.s, z2.s[3]\n"
+ "st1w { z6.s }, p0, [x27, x25, LSL #2]\n"
+ "st1w { z28.s }, p0, [x27, x23, LSL #2]\n"
+ "st1w { z8.s }, p0, [x27, x21, LSL #2]\n"
+ "st1w { z7.s }, p0, [x27, x19, LSL #2]\n"
+ "incb x27\n"
+ "whilelt p0.s, XZR, %x[num_channels]\n"
+ "bne 1b\n"
+ "2:" // channel_loop_end
+
+ : [input_row_0] "+&r" (input), [num_channels] "+&r" (long_channels), [output_row_0] "+&r" (output)
+ : [B_values] "r" (B_values), [input_col_1_stride] "r" ((long) input_col_stride), [input_row_stride] "r" ((long) input_row_stride), [output_col_1_stride] "r" ((long) output_col_stride), [output_row_stride] "r" (6 * (long) output_col_stride)
+ : "cc", "memory", "p0", "p1", "x9", "x10", "x11", "x12", "x13", "x14", "x15", "x16", "x19", "x20", "x21", "x22", "x23", "x24", "x25", "x26", "x27", "x28", "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7", "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15", "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23", "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31"
+ );
+}
+
+} // namespace input_transform
+} // namespace winograd
+} // namespace arm_conv
+
+#endif // __aarch64__ && defined(ARM_COMPUTE_ENABLE_SVE)
diff --git a/src/core/NEON/kernels/convolution/winograd/input_transforms_fp16.cpp b/src/core/NEON/kernels/convolution/winograd/input_transforms_fp16.cpp
new file mode 100644
index 0000000000..35d61fa94d
--- /dev/null
+++ b/src/core/NEON/kernels/convolution/winograd/input_transforms_fp16.cpp
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2022 Arm Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#if defined(__aarch64__) && defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
+
+#include "input_transform.hpp"
+#include "winograd_implementations.hpp"
+
+#include <memory>
+#include <string>
+
+namespace arm_conv {
+namespace winograd {
+namespace input_transform {
+
+void a64_fp16_6x6(unsigned int, const __fp16 *, size_t, size_t, __fp16 *, size_t);
+
+#define IMPL(HEIGHT, WIDTH, FUNC, DRIVER) new Transform ## DRIVER <__fp16, __fp16>(#FUNC, HEIGHT, WIDTH, FUNC)
+
+static const TransformImplementation<__fp16> transforms_fp16[] = {
+ { IMPL(6, 6, a64_fp16_6x6, Unpadded) },
+ { nullptr },
+};
+
+template <>
+const TransformImplementation<__fp16> *implementation_list(void)
+{
+ return transforms_fp16;
+}
+
+} // namespace input_transform
+} // namespace winograd
+} // namespace arm_conv
+
+#endif // defined(__aarch64__) && defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
diff --git a/src/core/NEON/kernels/convolution/winograd/input_transforms_fp32.cpp b/src/core/NEON/kernels/convolution/winograd/input_transforms_fp32.cpp
new file mode 100644
index 0000000000..ec4e954f71
--- /dev/null
+++ b/src/core/NEON/kernels/convolution/winograd/input_transforms_fp32.cpp
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2022 Arm Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include "input_transform.hpp"
+#include "winograd_implementations.hpp"
+
+#include <memory>
+#include <string>
+
+namespace arm_conv {
+namespace winograd {
+namespace input_transform {
+
+#if defined(__aarch64__)
+#if defined(ARM_COMPUTE_ENABLE_SVE)
+void sve_fp32_6x6(unsigned int, const float *, size_t, size_t, float *, size_t);
+#endif // defined(ARM_COMPUTE_ENABLE_SVE)
+void a64_fp32_6x6(unsigned int, const float *, size_t, size_t, float *, size_t);
+#else // defined(__aarch64__)
+void arm_fp32_6x6(unsigned int, const float *, size_t, size_t, float *, size_t);
+#endif // defined(__aarch64__)
+void arm_fp32_4x4(unsigned int, const float *, size_t, size_t, float *, size_t);
+void arm_fp32_1x8(unsigned int, const float *, size_t, size_t, float *, size_t);
+
+#define IMPL(HEIGHT, WIDTH, FUNC, DRIVER) new Transform ## DRIVER <float, float>(#FUNC, HEIGHT, WIDTH, FUNC)
+
+static const TransformImplementation<float> transforms_fp32[] = {
+#if defined(__aarch64__)
+#if defined(ARM_COMPUTE_ENABLE_SVE)
+ { IMPL(6, 6, sve_fp32_6x6, Unpadded), MethodConstraints::RequiresSVE },
+#endif // defined(ARM_COMPUTE_ENABLE_SVE)
+ { IMPL(6, 6, a64_fp32_6x6, Unpadded) },
+#else // defined(__aarch64__)
+ { IMPL(6, 6, arm_fp32_6x6, Unpadded) },
+#endif // defined(__aarch64__)
+ { IMPL(4, 4, arm_fp32_4x4, Unpadded) },
+ { IMPL(1, 8, arm_fp32_1x8, Unpadded) },
+ { new TransformUnpadded<float, float>("arm_fp32_1x8", 8, 1, TransformUnpadded<float, float>::get_transposed_kernel(arm_fp32_1x8)) },
+ { nullptr },
+};
+
+template <>
+const TransformImplementation<float> *implementation_list(void)
+{
+ return transforms_fp32;
+}
+
+} // namespace input_transform
+} // namespace winograd
+} // namespace arm_conv
diff --git a/src/core/NEON/kernels/convolution/winograd/output_transform.hpp b/src/core/NEON/kernels/convolution/winograd/output_transform.hpp
new file mode 100644
index 0000000000..5148495608
--- /dev/null
+++ b/src/core/NEON/kernels/convolution/winograd/output_transform.hpp
@@ -0,0 +1,302 @@
+/*
+ * Copyright (c) 2022 Arm Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#pragma once
+
+#include "src/core/NEON/kernels/assembly/winograd.hpp"
+
+#include "src/core/NEON/kernels/arm_conv/addressing.hpp"
+
+#include <algorithm>
+#include <cstring>
+#include <functional>
+#include <limits>
+
+namespace arm_conv {
+namespace winograd {
+namespace output_transform {
+
+/* Driver class for the Winograd output transforms.
+ *
+ * This provides a base implementation which handles iteration over the output
+ * tensor; subclasses are responsible for managing working space and executing
+ * the transform on individual tiles.
+ */
+template <typename TIn, typename TOut=TIn>
+class TransformBase : public ITransform
+{
+ const std::string m_name;
+ const unsigned int m_output_rows, m_output_cols;
+ const unsigned int m_kernel_rows, m_kernel_cols;
+
+ protected:
+ virtual size_t get_working_space_per_thread(const ConvolutionArgs &) const
+ {
+ return 0;
+ }
+
+ virtual void initialise_thread_working_space(const ConvolutionArgs &, void *) const
+ {
+ // Nothing to do
+ }
+
+ virtual void execute_tile(
+ unsigned int n_channels,
+ const TIn *inptr, size_t ld_in_matrix,
+ const TIn *bias,
+ TOut *outptr, size_t ld_out_row, size_t ld_out_col,
+ TOut activation_min, TOut activation_max,
+ unsigned int valid_rows, unsigned int valid_cols,
+ void *working_space
+ ) const = 0;
+
+ void execute_internal(
+ const ConvolutionArgs &args,
+ const TIn *inptr, size_t ld_in_batch, size_t ld_in_matrix, size_t ld_in_row,
+ const TIn *bias,
+ TOut *outptr, size_t ld_out_batch, size_t ld_out_row, size_t ld_out_col,
+ void *working_space, unsigned int thread_id, unsigned int n_threads
+ ) const
+ {
+ // Get the working space for this thread, and initialise it.
+ working_space = reinterpret_cast<char *>(working_space) +
+ this->get_working_space_per_thread(args) * thread_id;
+ this->initialise_thread_working_space(args, working_space);
+
+ // Get the activation values
+ auto activation_min = static_cast<TOut>(-std::numeric_limits<float>::infinity());
+ auto activation_max = static_cast<TOut>(+std::numeric_limits<float>::infinity());
+ switch (args.activation.type)
+ {
+ case arm_gemm::Activation::Type::BoundedReLU:
+ activation_max = static_cast<TOut>(args.activation.param1);
+ // Fall through
+ case arm_gemm::Activation::Type::ReLU:
+ activation_min = static_cast<TOut>(0);
+ break;
+ default:
+ break;
+ }
+
+ // Determine the number of tiles in a row, we use this to get the right
+ // offset into the input data.
+ const auto n_tile_cols = (args.output_shape.cols + this->get_output_cols() - 1) / this->get_output_cols();
+
+ // Execute over all batches
+ for (unsigned int batch = 0; batch < args.n_batches; batch++)
+ {
+ auto inptr_row = inptr + thread_id*n_tile_cols*ld_in_row;
+ auto outptr_row = outptr + thread_id*ld_out_row*this->get_output_rows();
+ inptr += ld_in_batch;
+ outptr += ld_out_batch;
+
+ // Stripe rows of tiles over threads.
+ for (auto out_i = thread_id * this->get_output_rows();
+ out_i < args.output_shape.rows;
+ out_i += n_threads * this->get_output_rows())
+ {
+ auto inptr_tile = inptr_row;
+ auto outptr_tile = outptr_row;
+ inptr_row += n_threads * n_tile_cols * ld_in_row;
+ outptr_row += n_threads * this->get_output_rows() * ld_out_row;
+
+ // Iterate over all columns
+ for (auto out_j = 0u; out_j < args.output_shape.cols;
+ out_j += this->get_output_cols())
+ {
+ // Execute the tile
+ this->execute_tile(
+ args.n_output_channels,
+ inptr_tile, ld_in_matrix,
+ bias,
+ outptr_tile, ld_out_row, ld_out_col,
+ activation_min, activation_max,
+ args.output_shape.rows - out_i, // Number of valid rows remaining
+ args.output_shape.cols - out_j, // Number of valid columns remaining
+ working_space
+ );
+
+ // Progress the pointers
+ inptr_tile += ld_in_row;
+ outptr_tile += this->get_output_cols() * ld_out_col;
+ }
+ }
+ }
+ }
+
+ public:
+ TransformBase(const std::string &name,
+ unsigned int output_rows, unsigned int output_cols,
+ unsigned int kernel_rows, unsigned int kernel_cols)
+ : m_name(name),
+ m_output_rows(output_rows), m_output_cols(output_cols),
+ m_kernel_rows(kernel_rows), m_kernel_cols(kernel_cols)
+ {
+ }
+
+ const std::string &get_name(void) const override { return m_name; }
+
+ unsigned int get_input_rows(void) const override final { return m_kernel_rows + m_output_rows - 1; }
+ unsigned int get_input_cols(void) const override final { return m_kernel_cols + m_output_cols - 1; }
+
+ unsigned int get_output_rows(void) const override final { return m_output_rows; }
+ unsigned int get_output_cols(void) const override final { return m_output_cols; }
+
+ unsigned int get_kernel_rows(void) const override final { return m_kernel_rows; }
+ unsigned int get_kernel_cols(void) const override final { return m_kernel_cols; }
+
+ size_t get_working_space_size(const ConvolutionArgs &args, unsigned int n_threads) const override
+ {
+ return n_threads * this->get_working_space_per_thread(args);
+ }
+
+ void execute(
+ const ConvolutionArgs &args,
+ const void *inptr, size_t ld_in_batch, size_t ld_in_matrix, size_t ld_in_row,
+ const void *bias,
+ void *outptr, size_t ld_out_batch, size_t ld_out_row, size_t ld_out_col,
+ void *working_space, unsigned int thread_id, unsigned int n_threads
+ ) const override
+ {
+ execute_internal(
+ args,
+ reinterpret_cast<const TIn *>(inptr), ld_in_batch, ld_in_matrix, ld_in_row,
+ reinterpret_cast<const TIn *>(bias),
+ reinterpret_cast<TOut *>(outptr), ld_out_batch, ld_out_row, ld_out_col,
+ working_space, thread_id, n_threads
+ );
+ }
+};
+
+template <typename TIn, typename TOut=TIn>
+class TransformUnpadded : public TransformBase<TIn, TOut>
+{
+ using Kernel = std::function<void(
+ unsigned int n_channels,
+ const TIn *inptr, size_t ld_in_matrix,
+ const TIn *bias,
+ TOut *outptr, size_t ld_out_row, size_t ld_out_col,
+ TOut activation_min, TOut activation_max
+ )>;
+ const Kernel m_kernel;
+
+ protected:
+ size_t get_working_space_per_thread(const ConvolutionArgs &args) const override
+ {
+ // We create a buffer the size of the output tile
+ const auto n_output_points = this->get_output_rows() * this->get_output_cols();
+ return sizeof(TOut) * n_output_points * args.n_output_channels;
+ }
+
+ void execute_tile(
+ unsigned int n_channels,
+ const TIn *inptr, size_t ld_in_matrix,
+ const TIn *bias,
+ TOut *outptr, size_t ld_out_row, size_t ld_out_col,
+ TOut activation_min, TOut activation_max,
+ unsigned int valid_rows, unsigned int valid_cols,
+ void *working_space
+ ) const override final
+ {
+ // Get copies of the output tensor parameters
+ auto kernel_outptr = outptr;
+ auto kernel_ld_out_row = ld_out_row, kernel_ld_out_col = ld_out_col;
+
+ // If there's padding on either the left or the right, then we execute the
+ // kernel into the output buffer and then perform a copy.
+ if (valid_rows < this->get_output_rows() ||
+ valid_cols < this->get_output_cols())
+ {
+ // Override the kernel output parameters
+ kernel_outptr = reinterpret_cast<TOut *>(working_space);
+ kernel_ld_out_col = n_channels;
+ kernel_ld_out_row = kernel_ld_out_col * this->get_output_cols();
+ }
+
+ // Execute the kernel
+ m_kernel(
+ n_channels,
+ inptr, ld_in_matrix,
+ bias,
+ kernel_outptr, kernel_ld_out_row, kernel_ld_out_col,
+ activation_min, activation_max
+ );
+
+ // If necessary, copy from the working space into the destination tensor.
+ if (valid_rows < this->get_output_rows() ||
+ valid_cols < this->get_output_cols())
+ {
+ const auto last_row = std::min(valid_rows, this->get_output_rows());
+ const auto last_col = std::min(valid_cols, this->get_output_cols());
+
+ for (auto i = 0u; i < last_row; i++)
+ {
+ auto patch_tile = kernel_outptr;
+ auto out_tile = outptr;
+ kernel_outptr += kernel_ld_out_row;
+ outptr += ld_out_row;
+
+ for (auto j = 0u; j < last_col; j++)
+ {
+ memcpy(out_tile, patch_tile, sizeof(TOut) * n_channels);
+ patch_tile += kernel_ld_out_col;
+ out_tile += ld_out_col;
+ }
+ }
+ }
+ }
+
+ public:
+ TransformUnpadded(const std::string &name,
+ unsigned int output_rows, unsigned int output_cols,
+ unsigned int kernel_rows, unsigned int kernel_cols,
+ const Kernel kernel)
+ : TransformBase<TIn, TOut>(name, output_rows, output_cols, kernel_rows, kernel_cols),
+ m_kernel(kernel)
+ {
+ }
+
+ /* Utility method to get a transposed variant of a kernel, this transposed
+ * version simply calls the original kernel with the output row and column
+ * strides swapped.
+ */
+ static constexpr Kernel get_transposed_kernel(const Kernel &kernel)
+ {
+ return [kernel] (
+ const unsigned int n_channels,
+ const TIn *const inptr, const size_t ld_in_matrix,
+ const TIn *const bias,
+ TOut *const outptr, const size_t ld_out_row, const size_t ld_out_col,
+ const TOut activation_min, const TOut activation_max
+ ) {
+ kernel(n_channels, inptr, ld_in_matrix, bias,
+ outptr, ld_out_col, ld_out_row,
+ activation_min, activation_max);
+ };
+ }
+};
+
+} // namespace output_transform
+} // namespace winograd
+} // namespace arm_conv
diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_4x4_3x3_fp16_fp16_integers.cpp b/src/core/NEON/kernels/convolution/winograd/output_transforms/a64_fp16_4x4_3x3.cpp
index 3c071bdac6..8a2837a125 100644
--- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_4x4_3x3_fp16_fp16_integers.cpp
+++ b/src/core/NEON/kernels/convolution/winograd/output_transforms/a64_fp16_4x4_3x3.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020 Arm Limited.
+ * Copyright (c) 2022 Arm Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -22,25 +22,29 @@
* SOFTWARE.
*/
#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
-#include "arm.hpp"
-#include "output.hpp"
-namespace winograd
-{
+#include <algorithm>
+#include <arm_neon.h>
+#include <cstddef>
+
+namespace arm_conv {
+namespace winograd {
+namespace output_transform {
-template <>
-void winograd::OutputTransform<3, 3, 6, 6, __fp16, __fp16, winograd::WinogradRoots::Integers>::transform_tile(
- const int n_channels,
+void a64_fp16_4x4_3x3(
+ unsigned int n_channels,
const __fp16* inptr,
- const int matrix_stride,
+ const size_t matrix_stride,
const __fp16* bptr,
__fp16* const output,
- const int output_row_stride,
- const int output_col_stride,
+ const size_t output_row_stride,
+ const size_t output_col_stride,
const __fp16 output_min,
const __fp16 output_max
)
{
+ constexpr int output_tile_rows = 4, output_tile_cols = 4;
+
// Construct a map to the output cells
__fp16 *outptrs[output_tile_rows][output_tile_cols];
for (int i = 0; i < output_tile_rows; i++)
@@ -249,7 +253,8 @@ void winograd::OutputTransform<3, 3, 6, 6, __fp16, __fp16, winograd::WinogradRoo
}
}
-template class OutputTransform<3, 3, 6, 6, __fp16, __fp16, winograd::WinogradRoots::Integers>;
+} // namespace output_transform
+} // namespace winograd
+} // namespace arm_conv
-} // namespace winograd
#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_2_7_fp32_fp32_integers.cpp b/src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_1x2_1x7.cpp
index 8e257909a3..1fb1189aa5 100644
--- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_2_7_fp32_fp32_integers.cpp
+++ b/src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_1x2_1x7.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Arm Limited.
+ * Copyright (c) 2022 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -22,42 +22,36 @@
* SOFTWARE.
*/
-#include "arm.hpp"
-#include "output.hpp"
+#include <algorithm>
+#include <cstddef>
+#include <arm_neon.h>
-namespace winograd
-{
+namespace arm_conv {
+namespace winograd {
+namespace output_transform {
-template <>
-void OutputTransform<1, 7, 1, 8, float, float, WinogradRoots::Integers>::transform_tile(
- const int n_channels,
+void arm_fp32_1x2_1x7(
+ unsigned int n_channels,
const float* inptr,
- const int matrix_stride,
+ const size_t matrix_stride,
const float* bptr,
- float* const output,
- const int, // No need to stride across rows
- const int output_col_stride,
+ float *outptr,
+ size_t, // No need to stride across rows
+ const size_t output_col_stride,
const float output_min,
const float output_max
)
{
- // Construct a map to the output cells
- float *outptrs[output_tile_cols];
- for (int j = 0; j < output_tile_cols; j++)
- {
- outptrs[j] = output + j*output_col_stride;
- }
+ constexpr auto inner_tile_cols = 8u, output_tile_cols = 2u;
// For each channel of the output
- int channels_remaining = n_channels;
-#ifdef __arm_any__
- for (; channels_remaining >= 4; channels_remaining -= 4)
+ for (; n_channels >= 4; n_channels -= 4)
{
// Matrices used and computed during this transform
float32x4_t F[inner_tile_cols], f[output_tile_cols], b = vdupq_n_f32(0.0f);
// Read a 1x8 tile in the Winograd domain
- for (int j = 0; j < inner_tile_cols; j++)
+ for (auto j = 0u; j < inner_tile_cols; j++)
{
F[j] = vld1q_f32(inptr + j*matrix_stride);
}
@@ -72,21 +66,21 @@ void OutputTransform<1, 7, 1, 8, float, float, WinogradRoots::Integers>::transfo
b = vld1q_f32(bptr);
bptr += 4;
}
- for (int j = 0; j < output_tile_cols; j++)
+ for (auto j = 0u; j < output_tile_cols; j++)
{
const auto y = vminq_f32(vmaxq_f32(f[j] + b, vdupq_n_f32(output_min)),
vdupq_n_f32(output_max));
- vst1q_f32(outptrs[j], y);
- outptrs[j] += 4;
+ vst1q_f32(outptr + j*output_col_stride, y);
}
+ outptr += 4;
}
- for (; channels_remaining >= 2; channels_remaining -= 2)
+ for (; n_channels >= 2; n_channels -= 2)
{
// Matrices used and computed during this transform
float32x2_t F[inner_tile_cols], f[output_tile_cols], b = vdup_n_f32(0.0f);
// Read a 1x8 tile in the Winograd domain
- for (int j = 0; j < inner_tile_cols; j++)
+ for (auto j = 0u; j < inner_tile_cols; j++)
{
F[j] = vld1_f32(inptr + j*matrix_stride);
}
@@ -101,26 +95,24 @@ void OutputTransform<1, 7, 1, 8, float, float, WinogradRoots::Integers>::transfo
b = vld1_f32(bptr);
bptr += 2;
}
- for (int j = 0; j < output_tile_cols; j++)
+ for (auto j = 0u; j < output_tile_cols; j++)
{
const auto y = vmin_f32(vmax_f32(f[j] + b, vdup_n_f32(output_min)),
vdup_n_f32(output_max));
- vst1_f32(outptrs[j], y);
- outptrs[j] += 2;
+ vst1_f32(outptr + j*output_col_stride, y);
}
+ outptr += 2;
}
-#endif // __arm_any__
- for (; channels_remaining; channels_remaining--)
+ if (n_channels)
{
// Matrices used and computed during this transform
float F[inner_tile_cols], f[output_tile_cols], b = 0.0f;
// Read a 1x8 tile in the Winograd domain
- for (int j = 0; j < inner_tile_cols; j++)
+ for (auto j = 0u; j < inner_tile_cols; j++)
{
F[j] = *(inptr + j*matrix_stride);
}
- inptr++;
f[0] = F[0]*1 + F[1]*1 + F[2]*1 + F[3]*1 + F[4]*1 + F[5]*1 + F[6]*1;
f[1] = F[1]*-1 + F[5]*-3 + F[3]*-2 + F[4]*2 + F[6]*3 + F[2]*1 + F[7]*1;
@@ -130,14 +122,13 @@ void OutputTransform<1, 7, 1, 8, float, float, WinogradRoots::Integers>::transfo
{
b = *(bptr++);
}
- for (int j = 0; j < output_tile_cols; j++)
+ for (auto j = 0u; j < output_tile_cols; j++)
{
- *(outptrs[j]++) = std::max(std::min(f[j] + b, output_max), output_min);
+ *(outptr + j*output_col_stride) = std::max(std::min(f[j] + b, output_max), output_min);
}
}
}
-template class OutputTransform<1, 7, 1, 8, float, float, WinogradRoots::Integers>;
-template class OutputTransform<7, 1, 8, 1, float, float, WinogradRoots::Integers>;
-
+} // namespace output_transform
} // namespace winograd
+} // namespace arm_conv
diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_4_5_fp32_fp32_integers.cpp b/src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_1x4_1x5.cpp
index c35037e143..40fef1188b 100644
--- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_4_5_fp32_fp32_integers.cpp
+++ b/src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_1x4_1x5.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Arm Limited.
+ * Copyright (c) 2022 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -22,42 +22,36 @@
* SOFTWARE.
*/
-#include "output.hpp"
-#include "arm.hpp"
+#include <algorithm>
+#include <cstddef>
+#include <arm_neon.h>
-namespace winograd
-{
+namespace arm_conv {
+namespace winograd {
+namespace output_transform {
-template <>
-void OutputTransform<1, 5, 1, 8, float, float, WinogradRoots::Integers>::transform_tile(
- const int n_channels,
+void arm_fp32_1x4_1x5(
+ unsigned int n_channels,
const float* inptr,
- const int matrix_stride,
+ const size_t matrix_stride,
const float* bptr,
- float* const output,
- const int, // No need to stride across rows
- const int output_col_stride,
+ float *outptr,
+ size_t, // No need to stride across rows
+ const size_t output_col_stride,
const float output_min,
const float output_max
)
{
- // Construct a map to the output cells
- float *outptrs[output_tile_cols];
- for (int j = 0; j < output_tile_cols; j++)
- {
- outptrs[j] = output + j*output_col_stride;
- }
+ constexpr auto inner_tile_cols = 8u, output_tile_cols = 4u;
// For each channel of the output
- int channels_remaining = n_channels;
-#ifdef __arm_any__
- for (; channels_remaining >= 4; channels_remaining -= 4)
+ for (; n_channels >= 4; n_channels -= 4)
{
// Matrices used and computed during this transform
float32x4_t F[inner_tile_cols], f[output_tile_cols], b = vdupq_n_f32(0.0f);
// Read a 1x8 tile in the Winograd domain
- for (int j = 0; j < inner_tile_cols; j++)
+ for (auto j = 0u; j < inner_tile_cols; j++)
{
F[j] = vld1q_f32(inptr + j*matrix_stride);
}
@@ -74,22 +68,22 @@ void OutputTransform<1, 5, 1, 8, float, float, WinogradRoots::Integers>::transfo
b = vld1q_f32(bptr);
bptr += 4;
}
- for (int j = 0; j < output_tile_cols; j++)
+ for (auto j = 0u; j < output_tile_cols; j++)
{
const auto y =
vmaxq_f32(vminq_f32(vaddq_f32(f[j], b), vdupq_n_f32(output_max)),
vdupq_n_f32(output_min));
- vst1q_f32(outptrs[j], y);
- outptrs[j] += 4;
+ vst1q_f32(outptr + j*output_col_stride, y);
}
+ outptr += 4;
}
- for (; channels_remaining >= 2; channels_remaining -= 2)
+ for (; n_channels >= 2; n_channels -= 2)
{
// Matrices used and computed during this transform
float32x2_t F[inner_tile_cols], f[output_tile_cols], b = vdup_n_f32(0.0f);
// Read a 1x8 tile in the Winograd domain
- for (int j = 0; j < inner_tile_cols; j++)
+ for (auto j = 0u; j < inner_tile_cols; j++)
{
F[j] = vld1_f32(inptr + j*matrix_stride);
}
@@ -106,23 +100,22 @@ void OutputTransform<1, 5, 1, 8, float, float, WinogradRoots::Integers>::transfo
b = vld1_f32(bptr);
bptr += 2;
}
- for (int j = 0; j < output_tile_cols; j++)
+ for (auto j = 0u; j < output_tile_cols; j++)
{
const auto y =
vmax_f32(vmin_f32(vadd_f32(f[j], b), vdup_n_f32(output_max)),
vdup_n_f32(output_min));
- vst1_f32(outptrs[j], y);
- outptrs[j] += 2;
+ vst1_f32(outptr + j*output_col_stride, y);
}
+ outptr += 2;
}
-#endif // __arm_any__
- for (; channels_remaining; channels_remaining--)
+ for (; n_channels; n_channels--)
{
// Matrices used and computed during this transform
float F[inner_tile_cols], f[output_tile_cols], b = 0.0f;
// Read a 1x8 tile in the Winograd domain
- for (int j = 0; j < inner_tile_cols; j++)
+ for (auto j = 0u; j < inner_tile_cols; j++)
{
F[j] = *(inptr + j*matrix_stride);
}
@@ -138,15 +131,15 @@ void OutputTransform<1, 5, 1, 8, float, float, WinogradRoots::Integers>::transfo
{
b = *(bptr++);
}
- for (int j = 0; j < output_tile_cols; j++)
+ for (auto j = 0u; j < output_tile_cols; j++)
{
const auto y = std::max(std::min(f[j] + b, output_max), output_min);
- *(outptrs[j]++) = y;
+ *(outptr + j*output_col_stride) = y;
}
+ outptr++;
}
}
-template class OutputTransform<1, 5, 1, 8, float, float, WinogradRoots::Integers>;
-template class OutputTransform<5, 1, 8, 1, float, float, WinogradRoots::Integers>;
-
+} // namespace output_transform
} // namespace winograd
+} // namespace arm_conv
diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_6_3_fp32_fp32_integers.cpp b/src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_1x6_1x3.cpp
index 528cd8c691..8203b579cb 100644
--- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_6_3_fp32_fp32_integers.cpp
+++ b/src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_1x6_1x3.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Arm Limited.
+ * Copyright (c) 2022 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -22,42 +22,37 @@
* SOFTWARE.
*/
-#include "output.hpp"
-#include "arm.hpp"
+#include <algorithm>
+#include <cstddef>
-namespace winograd
-{
+#include <arm_neon.h>
+
+namespace arm_conv {
+namespace winograd {
+namespace output_transform {
-template <>
-void OutputTransform<1, 3, 1, 8, float, float, WinogradRoots::Integers>::transform_tile(
- const int n_channels,
+void arm_fp32_1x6_1x3(
+ unsigned int n_channels,
const float* inptr,
- const int matrix_stride,
+ const size_t matrix_stride,
const float* bptr,
- float* const output,
- const int, // No need to stride across rows
- const int output_col_stride,
+ float *outptr,
+ size_t, // No need to stride across rows
+ const size_t output_col_stride,
const float output_min,
const float output_max
)
{
- // Construct a map to the output cells
- float *outptrs[output_tile_cols];
- for (int j = 0; j < output_tile_cols; j++)
- {
- outptrs[j] = output + j*output_col_stride;
- }
+ constexpr unsigned int inner_tile_cols = 8, output_tile_cols = 6;
// For each channel of the output
- int channels_remaining = n_channels;
-#ifdef __arm_any__
- for (; channels_remaining >= 4; channels_remaining -= 4)
+ for (; n_channels >= 4; n_channels -= 4)
{
// Matrices used and computed during this transform
float32x4_t F[inner_tile_cols], f[output_tile_cols], b = vdupq_n_f32(0.0f);
// Read a 1x8 tile in the Winograd domain
- for (int j = 0; j < inner_tile_cols; j++)
+ for (auto j = 0u; j < inner_tile_cols; j++)
{
F[j] = vld1q_f32(inptr + j*matrix_stride);
}
@@ -76,21 +71,21 @@ void OutputTransform<1, 3, 1, 8, float, float, WinogradRoots::Integers>::transfo
b = vld1q_f32(bptr);
bptr += 4;
}
- for (int j = 0; j < output_tile_cols; j++)
+ for (auto j = 0u; j < output_tile_cols; j++)
{
const auto y = vminq_f32(vmaxq_f32(f[j] + b, vdupq_n_f32(output_min)),
vdupq_n_f32(output_max));
- vst1q_f32(outptrs[j], y);
- outptrs[j] += 4;
+ vst1q_f32(outptr + j*output_col_stride, y);
}
+ outptr += 4;
}
- for (; channels_remaining >= 2; channels_remaining -= 2)
+ for (; n_channels >= 2; n_channels -= 2)
{
// Matrices used and computed during this transform
float32x2_t F[inner_tile_cols], f[output_tile_cols], b = vdup_n_f32(0.0f);
// Read a 1x8 tile in the Winograd domain
- for (int j = 0; j < inner_tile_cols; j++)
+ for (auto j = 0u; j < inner_tile_cols; j++)
{
F[j] = vld1_f32(inptr + j*matrix_stride);
}
@@ -109,22 +104,21 @@ void OutputTransform<1, 3, 1, 8, float, float, WinogradRoots::Integers>::transfo
b = vld1_f32(bptr);
bptr += 2;
}
- for (int j = 0; j < output_tile_cols; j++)
+ for (auto j = 0u; j < output_tile_cols; j++)
{
const auto y = vmin_f32(vmax_f32(f[j] + b, vdup_n_f32(output_min)),
vdup_n_f32(output_max));
- vst1_f32(outptrs[j], y);
- outptrs[j] += 2;
+ vst1_f32(outptr + j*output_col_stride, y);
}
+ outptr += 2;
}
-#endif // __arm_any__
- for (; channels_remaining; channels_remaining--)
+ for (; n_channels; n_channels--)
{
// Matrices used and computed during this transform
float F[inner_tile_cols], f[output_tile_cols], b = 0.0f;
// Read a 1x8 tile in the Winograd domain
- for (int j = 0; j < inner_tile_cols; j++)
+ for (auto j = 0u; j < inner_tile_cols; j++)
{
F[j] = *(inptr + j*matrix_stride);
}
@@ -142,14 +136,14 @@ void OutputTransform<1, 3, 1, 8, float, float, WinogradRoots::Integers>::transfo
{
b = *(bptr++);
}
- for (int j = 0; j < output_tile_cols; j++)
+ for (auto j = 0u; j < output_tile_cols; j++)
{
- *(outptrs[j]++) = std::max(std::min(f[j] + b, output_max), output_min);
+ *(outptr + j*output_col_stride) = std::max(std::min(f[j] + b, output_max), output_min);
}
+ outptr++;
}
}
-template class OutputTransform<1, 3, 1, 8, float, float, WinogradRoots::Integers>;
-template class OutputTransform<3, 1, 8, 1, float, float, WinogradRoots::Integers>;
-
-} // namespace
+} // namespace output_transform
+} // namespace winograd
+} // namespace arm_conv
diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_2x2_3x3_fp32_fp32_integers.cpp b/src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_2x2_3x3.cpp
index 8b0b4707f9..c13a826b4c 100644
--- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_2x2_3x3_fp32_fp32_integers.cpp
+++ b/src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_2x2_3x3.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Arm Limited.
+ * Copyright (c) 2022 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -22,47 +22,38 @@
* SOFTWARE.
*/
-#include "arm.hpp"
-#include "output.hpp"
+#include <algorithm>
+#include <cstddef>
+#include <arm_neon.h>
-namespace winograd
-{
+namespace arm_conv {
+namespace winograd {
+namespace output_transform {
-template <>
-void OutputTransform<3, 3, 4, 4, float, float, WinogradRoots::Integers>::transform_tile(
- const int n_channels,
+void arm_fp32_2x2_3x3(
+ unsigned int n_channels,
const float* inptr,
- const int matrix_stride,
+ const size_t matrix_stride,
const float* bptr,
- float* const output,
- const int output_row_stride,
- const int output_col_stride,
+ float *outptr,
+ const size_t output_row_stride,
+ const size_t output_col_stride,
const float output_min,
const float output_max
)
{
- // Construct a map to the output cells
- float *outptrs[output_tile_rows][output_tile_cols];
- for (int i = 0; i < output_tile_rows; i++)
- {
- for (int j = 0; j < output_tile_cols; j++)
- {
- outptrs[i][j] = output + i*output_row_stride + j*output_col_stride;
- }
- }
+ constexpr auto output_tile_rows = 2u, output_tile_cols = 2u;
// For each channel of the output
- int channels_remaining = n_channels;
-#ifdef __aarch64__
- for (; channels_remaining >= 4; channels_remaining -= 4)
+ for (; n_channels >= 4; n_channels -= 4)
{
// Matrices used and computed during this transform
float32x4_t F[4][4], FZ[4][2], f[2][2], b;
// Read a 4x4 tile in the Winograd domain
- for (int i = 0, m = 0; i < 4; i++)
+ for (auto i = 0u, m = 0u; i < 4; i++)
{
- for (int j = 0; j < 4; j++, m++)
+ for (auto j = 0u; j < 4; j++, m++)
{
F[i][j] = vld1q_f32(inptr + m*matrix_stride);
}
@@ -70,7 +61,7 @@ void OutputTransform<3, 3, 4, 4, float, float, WinogradRoots::Integers>::transfo
inptr += 4;
// Compute the matrix F Z
- for (int i = 0; i < 4; i++)
+ for (auto i = 0u; i < 4; i++)
{
// FZ[i][0] = F[i][0] + F[i][1] + F[i][2];
FZ[i][0] = vaddq_f32(vaddq_f32(F[i][0], F[i][1]), F[i][2]);
@@ -80,7 +71,7 @@ void OutputTransform<3, 3, 4, 4, float, float, WinogradRoots::Integers>::transfo
}
// Compute the output tile f = ZT F Z
- for (int j = 0; j < 2; j++)
+ for (auto j = 0u; j < 2; j++)
{
// f[0][j] = FZ[0][j] + FZ[1][j] + FZ[2][j];
f[0][j] = vaddq_f32(vaddq_f32(FZ[0][j], FZ[1][j]), FZ[2][j]);
@@ -101,29 +92,27 @@ void OutputTransform<3, 3, 4, 4, float, float, WinogradRoots::Integers>::transfo
}
// Write out the output tile
- for (int i = 0; i < output_tile_rows; i++)
+ for (auto i = 0u; i < output_tile_rows; i++)
{
- for (int j = 0; j < output_tile_cols; j++)
+ for (auto j = 0u; j < output_tile_cols; j++)
{
const auto y =
vmaxq_f32(vminq_f32(vaddq_f32(f[i][j], b), vdupq_n_f32(output_max)),
vdupq_n_f32(output_min));
- vst1q_f32(outptrs[i][j], y);
- outptrs[i][j] += 4;
+ vst1q_f32(outptr + i*output_row_stride + j*output_col_stride, y);
}
}
+ outptr += 4;
}
-#endif // __aarch64__
-#ifdef __arm_any__
- for (; channels_remaining >= 2; channels_remaining -= 2)
+ for (; n_channels >= 2; n_channels -= 2)
{
// Matrices used and computed during this transform
float32x2_t F[4][4], FZ[4][2], f[2][2], b;
// Read a 4x4 tile in the Winograd domain
- for (int i = 0, m = 0; i < 4; i++)
+ for (auto i = 0u, m = 0u; i < 4; i++)
{
- for (int j = 0; j < 4; j++, m++)
+ for (auto j = 0u; j < 4; j++, m++)
{
F[i][j] = vld1_f32(inptr + m*matrix_stride);
}
@@ -131,7 +120,7 @@ void OutputTransform<3, 3, 4, 4, float, float, WinogradRoots::Integers>::transfo
inptr += 2;
// Compute the matrix F Z
- for (int i = 0; i < 4; i++)
+ for (auto i = 0u; i < 4; i++)
{
// FZ[i][0] = F[i][0] + F[i][1] + F[i][2];
FZ[i][0] = vadd_f32(vadd_f32(F[i][0], F[i][1]), F[i][2]);
@@ -141,7 +130,7 @@ void OutputTransform<3, 3, 4, 4, float, float, WinogradRoots::Integers>::transfo
}
// Compute the output tile f = ZT F Z
- for (int j = 0; j < 2; j++)
+ for (auto j = 0u; j < 2; j++)
{
// f[0][j] = FZ[0][j] + FZ[1][j] + FZ[2][j];
f[0][j] = vadd_f32(vadd_f32(FZ[0][j], FZ[1][j]), FZ[2][j]);
@@ -162,28 +151,27 @@ void OutputTransform<3, 3, 4, 4, float, float, WinogradRoots::Integers>::transfo
}
// Write out the output tile
- for (int i = 0; i < output_tile_rows; i++)
+ for (auto i = 0u; i < output_tile_rows; i++)
{
- for (int j = 0; j < output_tile_cols; j++)
+ for (auto j = 0u; j < output_tile_cols; j++)
{
const auto y =
vmax_f32(vmin_f32(vadd_f32(f[i][j], b), vdup_n_f32(output_max)),
vdup_n_f32(output_min));
- vst1_f32(outptrs[i][j], y);
- outptrs[i][j] += 2;
+ vst1_f32(outptr + i*output_row_stride + j*output_col_stride, y);
}
}
+ outptr += 2;
}
-#endif // __arm_any__
- for (; channels_remaining; channels_remaining--)
+ for (; n_channels; n_channels--)
{
// Matrices used and computed during this transform
float F[4][4], FZ[4][2], f[2][2], b;
// Read a 4x4 tile in the Winograd domain
- for (int i = 0, m = 0; i < 4; i++)
+ for (auto i = 0u, m = 0u; i < 4; i++)
{
- for (int j = 0; j < 4; j++, m++)
+ for (auto j = 0u; j < 4; j++, m++)
{
F[i][j] = *(inptr + m*matrix_stride);
}
@@ -191,14 +179,14 @@ void OutputTransform<3, 3, 4, 4, float, float, WinogradRoots::Integers>::transfo
inptr++;
// Compute the matrix F Z
- for (int i = 0; i < 4; i++)
+ for (auto i = 0u; i < 4; i++)
{
FZ[i][0] = F[i][0] + F[i][1] + F[i][2];
FZ[i][1] = F[i][1] - F[i][2] - F[i][3];
}
// Compute the output tile f = ZT F Z
- for (int j = 0; j < 2; j++)
+ for (auto j = 0u; j < 2; j++)
{
f[0][j] = FZ[0][j] + FZ[1][j] + FZ[2][j];
f[1][j] = FZ[1][j] - FZ[2][j] - FZ[3][j];
@@ -215,17 +203,18 @@ void OutputTransform<3, 3, 4, 4, float, float, WinogradRoots::Integers>::transfo
}
// Write out the output tile
- for (int i = 0; i < output_tile_rows; i++)
+ for (auto i = 0u; i < output_tile_rows; i++)
{
- for (int j = 0; j < output_tile_cols; j++)
+ for (auto j = 0u; j < output_tile_cols; j++)
{
const auto y = std::max(std::min(f[i][j] + b, output_max), output_min);
- *(outptrs[i][j]++) = y;
+ *(outptr + i*output_row_stride + j*output_col_stride) = y;
}
}
+ outptr++;
}
}
-template class OutputTransform<3, 3, 4, 4, float, float, WinogradRoots::Integers>;
-
-} // namespace
+} // namespace output_transform
+} // namespace winograd
+} // namespace arm_conv
diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_2x2_5x5_fp32_fp32_integers.cpp b/src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_2x2_5x5.cpp
index 3996be1c52..256d049032 100644
--- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_2x2_5x5_fp32_fp32_integers.cpp
+++ b/src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_2x2_5x5.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Arm Limited.
+ * Copyright (c) 2022 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -22,47 +22,38 @@
* SOFTWARE.
*/
-#include "output.hpp"
-#include "arm.hpp"
+#include <algorithm>
+#include <cstddef>
+#include <arm_neon.h>
-namespace winograd
-{
+namespace arm_conv {
+namespace winograd {
+namespace output_transform {
-template <>
-void OutputTransform<5, 5, 6, 6, float, float, WinogradRoots::Integers>::transform_tile(
- const int n_channels,
+void arm_fp32_2x2_5x5(
+ unsigned int n_channels,
const float* inptr,
- const int matrix_stride,
+ const size_t matrix_stride,
const float* bptr,
- float* const output,
- const int output_row_stride,
- const int output_col_stride,
+ float *outptr,
+ const size_t output_row_stride,
+ const size_t output_col_stride,
const float output_min,
const float output_max
)
{
- // Construct a map to the output cells
- float *outptrs[output_tile_rows][output_tile_cols];
- for (int i = 0; i < output_tile_rows; i++)
- {
- for (int j = 0; j < output_tile_cols; j++)
- {
- outptrs[i][j] = output + i*output_row_stride + j*output_col_stride;
- }
- }
+ constexpr auto output_tile_rows = 2u, output_tile_cols = 2u;
// For each channel of the output
- int channels_remaining = n_channels;
-#ifdef __aarch64__
- for (; channels_remaining >= 4; channels_remaining -= 4)
+ for (; n_channels >= 4; n_channels -= 4)
{
// Matrices used and computed during this transform
float32x4_t F[6][6], FZ[6][2], f[2][2], b;
// Read a 6x6 tile in the Winograd domain
- for (int i = 0, m = 0; i < 6; i++)
+ for (auto i = 0u, m = 0u; i < 6; i++)
{
- for (int j = 0; j < 6; j++, m++)
+ for (auto j = 0u; j < 6; j++, m++)
{
F[i][j] = vld1q_f32(inptr + m*matrix_stride);
}
@@ -70,7 +61,7 @@ void OutputTransform<5, 5, 6, 6, float, float, WinogradRoots::Integers>::transfo
inptr += 4;
// Compute the matrix F Z
- for (int i = 0; i < 6; i++)
+ for (auto i = 0u; i < 6; i++)
{
// FZ[i][0] = 1*F[i][0] + 1*F[i][1] + 1*F[i][2] + 1*F[i][3] + 1*F[i][4];
FZ[i][0] = vaddq_f32(vaddq_f32(vaddq_f32(F[i][0], F[i][1]), vaddq_f32(F[i][2], F[i][3])), F[i][4]);
@@ -80,7 +71,7 @@ void OutputTransform<5, 5, 6, 6, float, float, WinogradRoots::Integers>::transfo
}
// Compute the output tile f = ZT F Z
- for (int j = 0; j < 2; j++)
+ for (auto j = 0u; j < 2; j++)
{
// f[0][j] = 1*FZ[0][j] + 1*FZ[1][j] + 1*FZ[2][j] + 1*FZ[3][j] + 1*FZ[4][j];
f[0][j] = vaddq_f32(vaddq_f32(vaddq_f32(FZ[0][j], FZ[1][j]), vaddq_f32(FZ[2][j], FZ[3][j])), FZ[4][j]);
@@ -99,29 +90,27 @@ void OutputTransform<5, 5, 6, 6, float, float, WinogradRoots::Integers>::transfo
{
b = vdupq_n_f32(0.0f);
}
- for (int i = 0; i < output_tile_rows; i++)
+ for (auto i = 0u; i < output_tile_rows; i++)
{
- for (int j = 0; j < output_tile_cols; j++)
+ for (auto j = 0u; j < output_tile_cols; j++)
{
const auto y =
vmaxq_f32(vminq_f32(vaddq_f32(f[i][j], b), vdupq_n_f32(output_max)),
vdupq_n_f32(output_min));
- vst1q_f32(outptrs[i][j], y);
- outptrs[i][j] += 4;
+ vst1q_f32(outptr + i*output_row_stride + j*output_col_stride, y);
}
}
+ outptr += 4;
}
-#endif // __aarch64__
-#ifdef __arm_any__
- for (; channels_remaining >= 2; channels_remaining -= 2)
+ for (; n_channels >= 2; n_channels -= 2)
{
// Matrices used and computed during this transform
float32x2_t F[6][6], FZ[6][2], f[2][2], b;
// Read a 6x6 tile in the Winograd domain
- for (int i = 0, m = 0; i < 6; i++)
+ for (auto i = 0u, m = 0u; i < 6; i++)
{
- for (int j = 0; j < 6; j++, m++)
+ for (auto j = 0u; j < 6; j++, m++)
{
F[i][j] = vld1_f32(inptr + m*matrix_stride);
}
@@ -129,7 +118,7 @@ void OutputTransform<5, 5, 6, 6, float, float, WinogradRoots::Integers>::transfo
inptr += 2;
// Compute the matrix F Z
- for (int i = 0; i < 6; i++)
+ for (auto i = 0u; i < 6; i++)
{
// FZ[i][0] = 1*F[i][0] + 1*F[i][1] + 1*F[i][2] + 1*F[i][3] + 1*F[i][4];
FZ[i][0] = vadd_f32(vadd_f32(vadd_f32(F[i][0], F[i][1]), vadd_f32(F[i][2], F[i][3])), F[i][4]);
@@ -139,7 +128,7 @@ void OutputTransform<5, 5, 6, 6, float, float, WinogradRoots::Integers>::transfo
}
// Compute the output tile f = ZT F Z
- for (int j = 0; j < 2; j++)
+ for (auto j = 0u; j < 2; j++)
{
// f[0][j] = 1*FZ[0][j] + 1*FZ[1][j] + 1*FZ[2][j] + 1*FZ[3][j] + 1*FZ[4][j];
f[0][j] = vadd_f32(vadd_f32(vadd_f32(FZ[0][j], FZ[1][j]), vadd_f32(FZ[2][j], FZ[3][j])), FZ[4][j]);
@@ -158,43 +147,41 @@ void OutputTransform<5, 5, 6, 6, float, float, WinogradRoots::Integers>::transfo
{
b = vdup_n_f32(0.0f);
}
- for (int i = 0; i < output_tile_rows; i++)
+ for (auto i = 0u; i < output_tile_rows; i++)
{
- for (int j = 0; j < output_tile_cols; j++)
+ for (auto j = 0u; j < output_tile_cols; j++)
{
const auto y =
vmax_f32(vmin_f32(vadd_f32(f[i][j], b), vdup_n_f32(output_max)),
vdup_n_f32(output_min));
- vst1_f32(outptrs[i][j], y);
- outptrs[i][j] += 2;
+ vst1_f32(outptr + i*output_row_stride + j*output_col_stride, y);
}
}
+ outptr += 2;
}
-#endif // __arm_any__
- for (; channels_remaining; channels_remaining--)
+ if (n_channels)
{
// Matrices used and computed during this transform
float F[6][6], FZ[6][2], f[2][2], b;
// Read a 6x6 tile in the Winograd domain
- for (int i = 0, m = 0; i < 6; i++)
+ for (auto i = 0u, m = 0u; i < 6; i++)
{
- for (int j = 0; j < 6; j++, m++)
+ for (auto j = 0u; j < 6; j++, m++)
{
F[i][j] = *(inptr + m*matrix_stride);
}
}
- inptr++;
// Compute the matrix F Z
- for (int i = 0; i < 6; i++)
+ for (auto i = 0u; i < 6; i++)
{
FZ[i][0] = 1*F[i][0] + 1*F[i][1] + 1*F[i][2] + 1*F[i][3] + 1*F[i][4];
FZ[i][1] = 1*F[i][1] + -1*F[i][2] + 2*F[i][3] + -2*F[i][4] + 1*F[i][5];
}
// Compute the output tile f = ZT F Z
- for (int j = 0; j < 2; j++)
+ for (auto j = 0u; j < 2; j++)
{
f[0][j] = 1*FZ[0][j] + 1*FZ[1][j] + 1*FZ[2][j] + 1*FZ[3][j] + 1*FZ[4][j];
f[1][j] = 1*FZ[1][j] + -1*FZ[2][j] + 2*FZ[3][j] + -2*FZ[4][j] + 1*FZ[5][j];
@@ -209,17 +196,17 @@ void OutputTransform<5, 5, 6, 6, float, float, WinogradRoots::Integers>::transfo
{
b = 0.0f;
}
- for (int i = 0; i < output_tile_rows; i++)
+ for (auto i = 0u; i < output_tile_rows; i++)
{
- for (int j = 0; j < output_tile_cols; j++)
+ for (auto j = 0u; j < output_tile_cols; j++)
{
const auto y = std::max(std::min(f[i][j] + b, output_max), output_min);
- *(outptrs[i][j]++) = y;
+ *(outptr + i*output_row_stride + j*output_col_stride) = y;
}
}
}
}
-template class OutputTransform<5, 5, 6, 6, float, float, WinogradRoots::Integers>;
-
-} // namespace
+} // namespace output_transform
+} // namespace winograd
+} // namespace arm_conv
diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_4x4_3x3_fp32_fp32_integers.cpp b/src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_4x4_3x3.cpp
index 1eb9b537d2..c35da54eb6 100644
--- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/output_4x4_3x3_fp32_fp32_integers.cpp
+++ b/src/core/NEON/kernels/convolution/winograd/output_transforms/arm_fp32_4x4_3x3.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Arm Limited.
+ * Copyright (c) 2022 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -22,48 +22,38 @@
* SOFTWARE.
*/
-#include "arm.hpp"
-#include "output.hpp"
+#include <algorithm>
+#include <cstddef>
+#include <arm_neon.h>
-namespace winograd
-{
+namespace arm_conv {
+namespace winograd {
+namespace output_transform {
-template <>
-void winograd::OutputTransform<3, 3, 6, 6, float, float, winograd::WinogradRoots::Integers>::transform_tile(
- const int n_channels,
+void arm_fp32_4x4_3x3(
+ unsigned int n_channels,
const float* inptr,
- const int matrix_stride,
+ const size_t matrix_stride,
const float* bptr,
- float* const output,
- const int output_row_stride,
- const int output_col_stride,
+ float *outptr,
+ const size_t output_row_stride,
+ const size_t output_col_stride,
const float output_min,
const float output_max
)
{
- // Construct a map to the output cells
- float *outptrs[output_tile_rows][output_tile_cols];
- for (int i = 0; i < output_tile_rows; i++)
- {
- for (int j = 0; j < output_tile_cols; j++)
- {
- outptrs[i][j] = output + i*output_row_stride + j*output_col_stride;
- }
- }
+ constexpr auto output_tile_rows = 4u, output_tile_cols = 4u;
// For each channel of the output
- int channels_remaining = n_channels;
-
-#ifdef __aarch64__
- for (; channels_remaining >= 4; channels_remaining -= 4)
+ for (; n_channels >= 4; n_channels -= 4)
{
// Matrices used and computed during this transform
float32x4_t F[6][6], FZ[6][4], f[4][4], b;
// Read a 6x6 tile in the Winograd domain
- for (int i = 0, m = 0; i < 6; i++)
+ for (auto i = 0u, m = 0u; i < 6; i++)
{
- for (int j = 0; j < 6; j++, m++)
+ for (auto j = 0u; j < 6; j++, m++)
{
F[i][j] = vld1q_f32(inptr + m*matrix_stride);
}
@@ -71,7 +61,7 @@ void winograd::OutputTransform<3, 3, 6, 6, float, float, winograd::WinogradRoots
inptr += 4;
// Compute the matrix F Z
- for (int i = 0; i < 6; i++)
+ for (auto i = 0u; i < 6; i++)
{
// FZ[i][0] = 1*F[i][0] + 1*F[i][1] + 1*F[i][2] + 1*F[i][3] + 1*F[i][4];
FZ[i][0] = vaddq_f32(vaddq_f32(vaddq_f32(F[i][0], F[i][1]), vaddq_f32(F[i][2], F[i][3])), F[i][4]);
@@ -87,7 +77,7 @@ void winograd::OutputTransform<3, 3, 6, 6, float, float, winograd::WinogradRoots
}
// Compute the output tile f = ZT F Z
- for (int j = 0; j < 4; j++)
+ for (auto j = 0u; j < 4; j++)
{
// f[0][j] = 1*FZ[0][j] + 1*FZ[1][j] + 1*FZ[2][j] + 1*FZ[3][j] + 1*FZ[4][j];
f[0][j] = vaddq_f32(vaddq_f32(vaddq_f32(FZ[0][j], FZ[1][j]), vaddq_f32(FZ[2][j], FZ[3][j])), FZ[4][j]);
@@ -112,29 +102,27 @@ void winograd::OutputTransform<3, 3, 6, 6, float, float, winograd::WinogradRoots
{
b = vdupq_n_f32(0.0f);
}
- for (int i = 0; i < output_tile_rows; i++)
+ for (auto i = 0u; i < output_tile_rows; i++)
{
- for (int j = 0; j < output_tile_cols; j++)
+ for (auto j = 0u; j < output_tile_cols; j++)
{
const auto y =
vmaxq_f32(vminq_f32(vaddq_f32(f[i][j], b), vdupq_n_f32(output_max)),
vdupq_n_f32(output_min));
- vst1q_f32(outptrs[i][j], y);
- outptrs[i][j] += 4;
+ vst1q_f32(outptr + i*output_row_stride + j*output_col_stride, y);
}
}
+ outptr += 4;
}
-#endif // __aarch64__
-#ifdef __arm_any__
- for (; channels_remaining >= 2; channels_remaining -= 2)
+ for (; n_channels >= 2; n_channels -= 2)
{
// Matrices used and computed during this transform
float32x2_t F[6][6], FZ[6][4], f[4][4], b;
// Read a 6x6 tile in the Winograd domain
- for (int i = 0, m = 0; i < 6; i++)
+ for (auto i = 0u, m = 0u; i < 6; i++)
{
- for (int j = 0; j < 6; j++, m++)
+ for (auto j = 0u; j < 6; j++, m++)
{
F[i][j] = vld1_f32(inptr + m*matrix_stride);
}
@@ -142,7 +130,7 @@ void winograd::OutputTransform<3, 3, 6, 6, float, float, winograd::WinogradRoots
inptr += 2;
// Compute the matrix F Z
- for (int i = 0; i < 6; i++)
+ for (auto i = 0u; i < 6; i++)
{
// FZ[i][0] = 1*F[i][0] + 1*F[i][1] + 1*F[i][2] + 1*F[i][3] + 1*F[i][4];
FZ[i][0] = vadd_f32(vadd_f32(vadd_f32(F[i][0], F[i][1]), vadd_f32(F[i][2], F[i][3])), F[i][4]);
@@ -158,7 +146,7 @@ void winograd::OutputTransform<3, 3, 6, 6, float, float, winograd::WinogradRoots
}
// Compute the output tile f = ZT F Z
- for (int j = 0; j < 4; j++)
+ for (auto j = 0u; j < 4; j++)
{
// f[0][j] = 1*FZ[0][j] + 1*FZ[1][j] + 1*FZ[2][j] + 1*FZ[3][j] + 1*FZ[4][j];
f[0][j] = vadd_f32(vadd_f32(vadd_f32(FZ[0][j], FZ[1][j]), vadd_f32(FZ[2][j], FZ[3][j])), FZ[4][j]);
@@ -183,28 +171,27 @@ void winograd::OutputTransform<3, 3, 6, 6, float, float, winograd::WinogradRoots
{
b = vdup_n_f32(0.0f);
}
- for (int i = 0; i < output_tile_rows; i++)
+ for (auto i = 0u; i < output_tile_rows; i++)
{
- for (int j = 0; j < output_tile_cols; j++)
+ for (auto j = 0u; j < output_tile_cols; j++)
{
const auto y =
vmax_f32(vmin_f32(vadd_f32(f[i][j], b), vdup_n_f32(output_max)),
vdup_n_f32(output_min));
- vst1_f32(outptrs[i][j], y);
- outptrs[i][j] += 2;
+ vst1_f32(outptr + i*output_row_stride + j*output_col_stride, y);
}
}
+ outptr += 2;
}
-#endif // __arm_any__
- for (; channels_remaining; channels_remaining--)
+ for (; n_channels; n_channels--)
{
// Matrices used and computed during this transform
float F[6][6], FZ[6][4], f[4][4], b;
// Read a 6x6 tile in the Winograd domain
- for (int i = 0, m = 0; i < 6; i++)
+ for (auto i = 0u, m = 0u; i < 6; i++)
{
- for (int j = 0; j < 6; j++, m++)
+ for (auto j = 0u; j < 6; j++, m++)
{
F[i][j] = *(inptr + m*matrix_stride);
}
@@ -212,7 +199,7 @@ void winograd::OutputTransform<3, 3, 6, 6, float, float, winograd::WinogradRoots
inptr++;
// Compute the matrix F Z
- for (int i = 0; i < 6; i++)
+ for (auto i = 0u; i < 6; i++)
{
FZ[i][0] = 1*F[i][0] + 1*F[i][1] + 1*F[i][2] + 1*F[i][3] + 1*F[i][4];
FZ[i][1] = 1*F[i][1] + -1*F[i][2] + 2*F[i][3] + -2*F[i][4];
@@ -221,7 +208,7 @@ void winograd::OutputTransform<3, 3, 6, 6, float, float, winograd::WinogradRoots
}
// Compute the output tile f = ZT F Z
- for (int j = 0; j < 4; j++)
+ for (auto j = 0u; j < 4; j++)
{
f[0][j] = 1*FZ[0][j] + 1*FZ[1][j] + 1*FZ[2][j] + 1*FZ[3][j] + 1*FZ[4][j];
f[1][j] = 1*FZ[1][j] + -1*FZ[2][j] + 2*FZ[3][j] + -2*FZ[4][j];
@@ -238,17 +225,18 @@ void winograd::OutputTransform<3, 3, 6, 6, float, float, winograd::WinogradRoots
{
b = 0.0f;
}
- for (int i = 0; i < output_tile_rows; i++)
+ for (auto i = 0u; i < output_tile_rows; i++)
{
- for (int j = 0; j < output_tile_cols; j++)
+ for (auto j = 0u; j < output_tile_cols; j++)
{
const auto y = std::max(std::min(f[i][j] + b, output_max), output_min);
- *(outptrs[i][j]++) = y;
+ *(outptr + i*output_row_stride + j*output_col_stride) = y;
}
}
+ outptr++;
}
}
-template class OutputTransform<3, 3, 6, 6, float, float, winograd::WinogradRoots::Integers>;
-
+} // namespace output_transform
} // namespace winograd
+} // namespace arm_conv
diff --git a/src/core/NEON/kernels/convolution/winograd/output_transforms_fp16.cpp b/src/core/NEON/kernels/convolution/winograd/output_transforms_fp16.cpp
new file mode 100644
index 0000000000..c39b1dc083
--- /dev/null
+++ b/src/core/NEON/kernels/convolution/winograd/output_transforms_fp16.cpp
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2022 Arm Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#if defined(__aarch64__) && defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
+
+#include "output_transform.hpp"
+#include "winograd_implementations.hpp"
+
+namespace arm_conv {
+namespace winograd {
+namespace output_transform {
+
+void a64_fp16_4x4_3x3(unsigned int, const __fp16 *, size_t, const __fp16 *, __fp16 *, size_t, size_t, __fp16, __fp16);
+
+#define IMPL(OUT_HEIGHT, OUT_WIDTH, KERN_HEIGHT, KERN_WIDTH, FUNC, DRIVER) \
+ new Transform ## DRIVER <__fp16, __fp16>(#FUNC, OUT_HEIGHT, OUT_WIDTH, KERN_HEIGHT, KERN_WIDTH, FUNC)
+
+
+static const TransformImplementation<__fp16> transforms_fp16[] = {
+ { IMPL(4, 4, 3, 3, a64_fp16_4x4_3x3, Unpadded) },
+ { nullptr }
+};
+
+template <>
+const TransformImplementation<__fp16> *implementation_list(void)
+{
+ return transforms_fp16;
+}
+
+} // namespace output_transform
+} // namespace winograd
+} // namespace arm_conv
+
+#endif // defined(__aarch64__) && defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) \ No newline at end of file
diff --git a/src/core/NEON/kernels/convolution/winograd/output_transforms_fp32.cpp b/src/core/NEON/kernels/convolution/winograd/output_transforms_fp32.cpp
new file mode 100644
index 0000000000..87ad4b2437
--- /dev/null
+++ b/src/core/NEON/kernels/convolution/winograd/output_transforms_fp32.cpp
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2022 Arm Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include "output_transform.hpp"
+#include "winograd_implementations.hpp"
+
+namespace arm_conv {
+namespace winograd {
+namespace output_transform {
+
+void arm_fp32_4x4_3x3(unsigned int, const float *, size_t, const float *, float *, size_t, size_t, float, float);
+void arm_fp32_2x2_3x3(unsigned int, const float *, size_t, const float *, float *, size_t, size_t, float, float);
+void arm_fp32_2x2_5x5(unsigned int, const float *, size_t, const float *, float *, size_t, size_t, float, float);
+void arm_fp32_1x6_1x3(unsigned int, const float *, size_t, const float *, float *, size_t, size_t, float, float);
+void arm_fp32_1x4_1x5(unsigned int, const float *, size_t, const float *, float *, size_t, size_t, float, float);
+void arm_fp32_1x2_1x7(unsigned int, const float *, size_t, const float *, float *, size_t, size_t, float, float);
+
+#define IMPL(OUT_HEIGHT, OUT_WIDTH, KERN_HEIGHT, KERN_WIDTH, FUNC, DRIVER) \
+ new Transform ## DRIVER <float, float>(#FUNC, OUT_HEIGHT, OUT_WIDTH, KERN_HEIGHT, KERN_WIDTH, FUNC)
+
+#define IMPL_T(OUT_HEIGHT, OUT_WIDTH, KERN_HEIGHT, KERN_WIDTH, FUNC, DRIVER) \
+ new Transform ## DRIVER <float, float>(#FUNC, OUT_HEIGHT, OUT_WIDTH, KERN_HEIGHT, KERN_WIDTH, Transform ## DRIVER <float, float>::get_transposed_kernel(FUNC))
+
+static const TransformImplementation<float> transforms_fp32[] = {
+#if defined(__aarch64__)
+#endif // defined(__aarch64__)
+ { IMPL(4, 4, 3, 3, arm_fp32_4x4_3x3, Unpadded) },
+ { IMPL(2, 2, 3, 3, arm_fp32_2x2_3x3, Unpadded) },
+ { IMPL(2, 2, 5, 5, arm_fp32_2x2_5x5, Unpadded) },
+ { IMPL(1, 6, 1, 3, arm_fp32_1x6_1x3, Unpadded) },
+ { IMPL_T(6, 1, 3, 1, arm_fp32_1x6_1x3, Unpadded) },
+ { IMPL(1, 4, 1, 5, arm_fp32_1x4_1x5, Unpadded) },
+ { IMPL_T(4, 1, 5, 1, arm_fp32_1x4_1x5, Unpadded) },
+ { IMPL(1, 2, 1, 7, arm_fp32_1x2_1x7, Unpadded) },
+ { IMPL_T(2, 1, 7, 1, arm_fp32_1x2_1x7, Unpadded) },
+ { nullptr }
+};
+
+template <>
+const TransformImplementation<float> *implementation_list(void)
+{
+ return transforms_fp32;
+}
+
+} // namespace output_transform
+} // namespace winograd
+} // namespace arm_conv
diff --git a/src/core/NEON/kernels/convolution/winograd/weight_transform.hpp b/src/core/NEON/kernels/convolution/winograd/weight_transform.hpp
new file mode 100644
index 0000000000..db0f53df1b
--- /dev/null
+++ b/src/core/NEON/kernels/convolution/winograd/weight_transform.hpp
@@ -0,0 +1,145 @@
+/*
+ * Copyright (c) 2022 Arm Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#pragma once
+
+#include "src/core/NEON/kernels/assembly/winograd.hpp"
+#include <algorithm>
+#include <functional>
+
+namespace arm_conv {
+namespace winograd {
+namespace weight_transform {
+
+/* Driver class for the Winograd weight transforms.
+ */
+template <typename TIn, typename TOut=TIn>
+class Transform : public ITransform
+{
+ using Kernel = std::function<void(
+ unsigned int n_channels, // Number of channels to transform
+ const TIn *inptr, size_t ld_in_row, size_t ld_in_col,
+ TOut *outptr, size_t ld_out_matrix
+ )>;
+
+ const std::string m_name;
+ const unsigned int m_kernel_rows, m_kernel_cols;
+ const unsigned int m_transformed_tile_rows, m_transformed_tile_cols;
+ const Kernel m_kernel;
+
+ void execute_internal(
+ const ConvolutionArgs &args,
+ const TIn *inptr, size_t ld_in_row, size_t ld_in_col, size_t ld_input_channel,
+ TOut *outptr, size_t ld_out_matrix, size_t ld_out_row,
+ unsigned int thread_id, unsigned int n_threads
+ ) const
+ {
+ // Stripe groups of input channels over threads, this should reduce false
+ // sharing of the output matrix.
+ constexpr auto n_input_channels_per_thread = 16u;
+
+ // Get the initial offset for the input and output pointers
+ const auto offset = thread_id * n_input_channels_per_thread;
+ inptr += offset * ld_input_channel;
+ outptr += offset * ld_out_row;
+
+ for (auto start_ic = thread_id * n_input_channels_per_thread;
+ start_ic < args.n_input_channels;
+ start_ic += n_threads * n_input_channels_per_thread)
+ {
+ // Now iterate over the input channels assigned to this thread.
+ const auto end_ic = std::min(args.n_input_channels,
+ start_ic + n_input_channels_per_thread);
+ for (auto ic = start_ic; ic < end_ic; ic++)
+ {
+ m_kernel(args.n_output_channels, inptr, ld_in_row, ld_in_col,
+ outptr, ld_out_matrix);
+ inptr += ld_input_channel;
+ outptr += ld_out_row;
+ }
+
+ // Progress the pointers to the account for the work not performed by
+ // this thread.
+ const auto skip = (n_threads - 1) * n_input_channels_per_thread;
+ inptr += skip * ld_input_channel;
+ outptr += skip * ld_out_row;
+ }
+ }
+
+ public:
+ Transform(
+ const std::string &name,
+ unsigned int kernel_rows, unsigned int kernel_cols,
+ unsigned int transformed_tile_rows, unsigned int transformed_tile_cols,
+ const Kernel kernel
+ )
+ : m_name(name),
+ m_kernel_rows(kernel_rows), m_kernel_cols(kernel_cols),
+ m_transformed_tile_rows(transformed_tile_rows), m_transformed_tile_cols(transformed_tile_cols),
+ m_kernel(kernel)
+ {
+ }
+
+ const std::string &get_name(void) const override { return m_name; }
+
+ unsigned int get_kernel_rows(void) const override { return m_kernel_rows; }
+ unsigned int get_kernel_cols(void) const override { return m_kernel_cols; }
+
+ unsigned int get_transformed_tile_rows(void) const override { return m_transformed_tile_rows; }
+ unsigned int get_transformed_tile_cols(void) const override { return m_transformed_tile_cols; }
+
+ void execute(
+ const ConvolutionArgs &args,
+ const void *inptr, size_t ld_in_row, size_t ld_in_col, size_t ld_input_channel,
+ void *outptr, size_t ld_out_matrix, size_t ld_out_row,
+ unsigned int thread_id, unsigned int n_threads
+ ) const override
+ {
+ execute_internal(
+ args,
+ reinterpret_cast<const TIn *>(inptr), ld_in_row, ld_in_col, ld_input_channel,
+ reinterpret_cast<TOut *>(outptr), ld_out_matrix, ld_out_row,
+ thread_id, n_threads
+ );
+ }
+
+ /* Utility method to get a transposed variant of a kernel, this transposed
+ * version simply calls the original kernel with the input row and column
+ * strides swapped.
+ */
+ static constexpr Kernel get_transposed_kernel(const Kernel &kernel)
+ {
+ return [kernel] (
+ const unsigned int n_channels,
+ const TIn *const inptr, const size_t ld_in_row, const size_t ld_in_col,
+ TOut *const outptr, const size_t ld_out
+ ) {
+ kernel(n_channels, inptr, ld_in_col, ld_in_row, outptr, ld_out);
+ };
+ }
+};
+
+} // namespace weight_transform
+} // namespace winograd
+} // namespace arm_conv
diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_4x4_3x3_fp16_fp16_integers.cpp b/src/core/NEON/kernels/convolution/winograd/weight_transforms/a64_fp16_4x4_3x3.cpp
index 3101865027..0d9a65890e 100644
--- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_4x4_3x3_fp16_fp16_integers.cpp
+++ b/src/core/NEON/kernels/convolution/winograd/weight_transforms/a64_fp16_4x4_3x3.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020 Arm Limited.
+ * Copyright (c) 2022 Arm Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -21,45 +21,26 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
-
-#include "arm.hpp"
-#include "kernel.hpp"
-
-namespace winograd
-{
-
-template <>
-void WeightTransform<3, 3, 6, 6, __fp16, __fp16, WinogradRoots::Integers>::execute(
- const int n_output_channels,
- const int n_input_channels,
- const __fp16* const input, // NOTE: Data in HWIO order
- __fp16* const output,
- const int matrix_stride,
- const int matrix_row_stride
+#if defined(__aarch64__) && defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
+
+#include <cstddef>
+#include <arm_neon.h>
+
+namespace arm_conv {
+namespace winograd {
+namespace weight_transform {
+
+void a64_fp16_4x4_3x3(
+ unsigned int n_channels,
+ const __fp16* inptr, // NOTE: Data in HWIO order
+ const size_t ld_weight_row,
+ const size_t ld_weight_col,
+ __fp16* outptr,
+ const size_t matrix_stride
)
{
- // Get pointers to each cell of the weight tensor
- const auto weight_col_stride = n_input_channels * n_output_channels;
- const auto weight_row_stride = 3 * weight_col_stride;
- const __fp16 *inptrs[3][3];
- for (int i = 0; i < 3; i++)
- {
- for (int j = 0; j < 3; j++)
- {
- inptrs[i][j] = input + i*weight_row_stride + j*weight_col_stride;
- }
- }
-
- // For each input channel
- for (int ic = 0; ic < n_input_channels; ic++)
- {
- __fp16 *outptr = output + ic * matrix_row_stride;
-
- // For each output channel
- int channels_remaining = n_output_channels;
#ifdef __aarch64__
- for (; channels_remaining >= 8; channels_remaining -= 8)
+ for (; n_channels >= 8; n_channels -= 8)
{
// Matrices used and computed in this kernel
float16x8_t w[3][3], Ww[6][3], V[6][6];
@@ -69,8 +50,7 @@ void WeightTransform<3, 3, 6, 6, __fp16, __fp16, WinogradRoots::Integers>::execu
{
for (int j = 0; j < 3; j++)
{
- w[i][j] = vld1q_f16(inptrs[i][j]);
- inptrs[i][j] += 8;
+ w[i][j] = vld1q_f16(inptr + i*ld_weight_row + j*ld_weight_col);
}
}
@@ -128,11 +108,12 @@ void WeightTransform<3, 3, 6, 6, __fp16, __fp16, WinogradRoots::Integers>::execu
vst1q_f16(outptr + m*matrix_stride, V[i][j]);
}
}
+ inptr += 8;
outptr += 8;
}
#endif // __aarch64__
#ifdef __arm_any__
- for (; channels_remaining >= 4; channels_remaining -= 4)
+ for (; n_channels >= 4; n_channels -= 4)
{
// Matrices used and computed in this kernel
float16x4_t w[3][3], Ww[6][3], V[6][6];
@@ -142,8 +123,7 @@ void WeightTransform<3, 3, 6, 6, __fp16, __fp16, WinogradRoots::Integers>::execu
{
for (int j = 0; j < 3; j++)
{
- w[i][j] = vld1_f16(inptrs[i][j]);
- inptrs[i][j] += 4;
+ w[i][j] = vld1_f16(inptr + i*ld_weight_row + j*ld_weight_col);
}
}
@@ -201,59 +181,62 @@ void WeightTransform<3, 3, 6, 6, __fp16, __fp16, WinogradRoots::Integers>::execu
vst1_f16(outptr + m*matrix_stride, V[i][j]);
}
}
+ inptr += 4;
outptr += 4;
}
#endif // __arm_any__
- for (; channels_remaining; channels_remaining--)
+ for (; n_channels; n_channels--)
+ {
+ // Matrices used and computed in this kernel
+ __fp16 w[3][3], Ww[6][3], V[6][6];
+
+ // Read weights
+ for (int i = 0; i < 3; i++)
+ {
+ for (int j = 0; j < 3; j++)
{
- // Matrices used and computed in this kernel
- __fp16 w[3][3], Ww[6][3], V[6][6];
-
- // Read weights
- for (int i = 0; i < 3; i++)
- {
- for (int j = 0; j < 3; j++)
- {
- w[i][j] = *(inptrs[i][j]++);
- }
- }
-
- // Compute the matrix W w
- for (int j = 0; j < 3; j++)
- {
- Ww[0][j] = 6*w[0][j];
- Ww[1][j] = -4*w[0][j] + -4*w[1][j] + -4*w[2][j];
- Ww[2][j] = -4*w[0][j] + 4*w[1][j] + -4*w[2][j];
- Ww[3][j] = 1*w[0][j] + 2*w[1][j] + 4*w[2][j];
- Ww[4][j] = 1*w[0][j] + -2*w[1][j] + 4*w[2][j];
- Ww[5][j] = 24*w[2][j];
- }
-
- // Compute V = W w WT
- for (int i = 0; i < 6; i++)
- {
- V[i][0] = ( 6*Ww[i][0]) / 576.0;
- V[i][1] = (-4*Ww[i][0] + -4*Ww[i][1] + -4*Ww[i][2]) / 576.0;
- V[i][2] = (-4*Ww[i][0] + 4*Ww[i][1] + -4*Ww[i][2]) / 576.0;
- V[i][3] = ( 1*Ww[i][0] + 2*Ww[i][1] + 4*Ww[i][2]) / 576.0;
- V[i][4] = ( 1*Ww[i][0] + -2*Ww[i][1] + 4*Ww[i][2]) / 576.0;
- V[i][5] = (24*Ww[i][2]) / 576.0;
- }
-
- // Store the transformed weights
- for (int i = 0, m = 0; i < 6; i++)
- {
- for (int j = 0; j < 6; j++, m++)
- {
- *(outptr + m*matrix_stride) = V[i][j];
- }
- }
- outptr++;
+ w[i][j] = *(inptr + i*ld_weight_row + j*ld_weight_col);
}
+ }
+
+ // Compute the matrix W w
+ for (int j = 0; j < 3; j++)
+ {
+ Ww[0][j] = 6*w[0][j];
+ Ww[1][j] = -4*w[0][j] + -4*w[1][j] + -4*w[2][j];
+ Ww[2][j] = -4*w[0][j] + 4*w[1][j] + -4*w[2][j];
+ Ww[3][j] = 1*w[0][j] + 2*w[1][j] + 4*w[2][j];
+ Ww[4][j] = 1*w[0][j] + -2*w[1][j] + 4*w[2][j];
+ Ww[5][j] = 24*w[2][j];
+ }
+
+ // Compute V = W w WT
+ for (int i = 0; i < 6; i++)
+ {
+ V[i][0] = ( 6*Ww[i][0]) / 576.0;
+ V[i][1] = (-4*Ww[i][0] + -4*Ww[i][1] + -4*Ww[i][2]) / 576.0;
+ V[i][2] = (-4*Ww[i][0] + 4*Ww[i][1] + -4*Ww[i][2]) / 576.0;
+ V[i][3] = ( 1*Ww[i][0] + 2*Ww[i][1] + 4*Ww[i][2]) / 576.0;
+ V[i][4] = ( 1*Ww[i][0] + -2*Ww[i][1] + 4*Ww[i][2]) / 576.0;
+ V[i][5] = (24*Ww[i][2]) / 576.0;
+ }
+
+ // Store the transformed weights
+ for (int i = 0, m = 0; i < 6; i++)
+ {
+ for (int j = 0; j < 6; j++, m++)
+ {
+ *(outptr + m*matrix_stride) = V[i][j];
+ }
+ }
+
+ inptr++;
+ outptr++;
}
}
-template class WeightTransform<3, 3, 6, 6, __fp16, __fp16, WinogradRoots::Integers>;
+} // namespace weight_transform
+} // namespace winograd
+} // namespace arm_conv
-} // namespace
-#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
+#endif // defined(__aarch64__) && defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
diff --git a/src/core/NEON/kernels/convolution/winograd/weight_transforms/arm_fp32_2x2_3x3.cpp b/src/core/NEON/kernels/convolution/winograd/weight_transforms/arm_fp32_2x2_3x3.cpp
new file mode 100644
index 0000000000..e55bcb632f
--- /dev/null
+++ b/src/core/NEON/kernels/convolution/winograd/weight_transforms/arm_fp32_2x2_3x3.cpp
@@ -0,0 +1,200 @@
+/*
+ * Copyright (c) 2022 ARM Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <cstddef>
+#include <arm_neon.h>
+
+namespace arm_conv {
+namespace winograd {
+namespace weight_transform {
+
+void arm_fp32_2x2_3x3(
+ unsigned int n_channels,
+ const float *inptr, size_t ld_weight_row, size_t ld_weight_col,
+ float *outptr, size_t matrix_stride
+)
+{
+ constexpr auto inner_tile_i = 4u;
+ constexpr auto inner_tile_j = 4u;
+
+#ifdef __aarch64__
+ // For each output channel
+ for (; n_channels >= 4u; n_channels -= 4)
+ {
+ // Matrices used and computed in this kernel
+ float32x4_t w[3][3], Ww[inner_tile_i][3], V[inner_tile_i][inner_tile_j];
+
+ // Read weights
+ for (int i = 0; i < 3; i++)
+ {
+ for (int j = 0; j < 3; j++)
+ {
+ w[i][j] = vld1q_f32(inptr + i*ld_weight_row + j*ld_weight_col);
+ }
+ }
+
+ // Compute the matrix W w
+ for (int j = 0; j < 3; j++)
+ {
+ Ww[0][j] = w[0][j];
+
+ // Ww[1][j] = 0.5*(w[0][j] + w[1][j] + w[2][j]);
+ Ww[1][j] = vmulq_n_f32(vaddq_f32(vaddq_f32(w[0][j], w[1][j]), w[2][j]), 0.5f);
+
+ // Ww[2][j] = 0.5*(w[0][j] - w[1][j] + w[2][j]);
+ Ww[2][j] = vmulq_n_f32(vaddq_f32(vsubq_f32(w[0][j], w[1][j]), w[2][j]), 0.5f);
+
+ Ww[3][j] = w[2][j];
+ }
+
+ // Compute V = W w WT
+ for (auto i = 0u; i < inner_tile_i; i++)
+ {
+ V[i][0] = Ww[i][0];
+
+ // V[i][1] = 0.5*(Ww[i][0] + Ww[i][1] + Ww[i][2]);
+ V[i][1] = vmulq_n_f32(vaddq_f32(vaddq_f32(Ww[i][0], Ww[i][1]), Ww[i][2]), 0.5f);
+
+ // V[i][2] = 0.5*(Ww[i][0] - Ww[i][1] + Ww[i][2]);
+ V[i][2] = vmulq_n_f32(vaddq_f32(vsubq_f32(Ww[i][0], Ww[i][1]), Ww[i][2]), 0.5f);
+
+ V[i][3] = Ww[i][2];
+ }
+
+ // Store the transformed weights
+ for (auto i = 0u, m = 0u; i < inner_tile_i; i++)
+ {
+ for (auto j = 0u; j < inner_tile_j; j++, m++)
+ {
+ vst1q_f32(outptr + m*matrix_stride, V[i][j]);
+ }
+ }
+
+ inptr += 4;
+ outptr += 4;
+ }
+#endif // __aarch64__
+ for (; n_channels >= 2u; n_channels -= 2)
+ {
+ // Matrices used and computed in this kernel
+ float32x2_t w[3][3], Ww[inner_tile_i][3], V[inner_tile_i][inner_tile_j];
+
+ // Read weights
+ for (int i = 0; i < 3; i++)
+ {
+ for (int j = 0; j < 3; j++)
+ {
+ w[i][j] = vld1_f32(inptr + i*ld_weight_row + j*ld_weight_col);
+ }
+ }
+
+ // Compute the matrix W w
+ for (int j = 0; j < 3; j++)
+ {
+ Ww[0][j] = w[0][j];
+
+ // Ww[1][j] = 0.5*(w[0][j] + w[1][j] + w[2][j]);
+ Ww[1][j] = vmul_n_f32(vadd_f32(vadd_f32(w[0][j], w[1][j]), w[2][j]), 0.5f);
+
+ // Ww[2][j] = 0.5*(w[0][j] - w[1][j] + w[2][j]);
+ Ww[2][j] = vmul_n_f32(vadd_f32(vsub_f32(w[0][j], w[1][j]), w[2][j]), 0.5f);
+
+ Ww[3][j] = w[2][j];
+ }
+
+ // Compute V = W w WT
+ for (auto i = 0u; i < inner_tile_i; i++)
+ {
+ V[i][0] = Ww[i][0];
+
+ // V[i][1] = 0.5*(Ww[i][0] + Ww[i][1] + Ww[i][2]);
+ V[i][1] = vmul_n_f32(vadd_f32(vadd_f32(Ww[i][0], Ww[i][1]), Ww[i][2]), 0.5f);
+
+ // V[i][2] = 0.5*(Ww[i][0] - Ww[i][1] + Ww[i][2]);
+ V[i][2] = vmul_n_f32(vadd_f32(vsub_f32(Ww[i][0], Ww[i][1]), Ww[i][2]), 0.5f);
+
+ V[i][3] = Ww[i][2];
+ }
+
+ // Store the transformed weights
+ for (auto i = 0u, m = 0u; i < inner_tile_i; i++)
+ {
+ for (auto j = 0u; j < inner_tile_j; j++, m++)
+ {
+ vst1_f32(outptr + m*matrix_stride, V[i][j]);
+ }
+ }
+
+ inptr += 2;
+ outptr += 2;
+ }
+ for (; n_channels; n_channels--)
+ {
+ // Matrices used and computed in this kernel
+ float w[3][3], Ww[inner_tile_i][3], V[inner_tile_i][inner_tile_j];
+
+ // Read weights
+ for (int i = 0; i < 3; i++)
+ {
+ for (int j = 0; j < 3; j++)
+ {
+ w[i][j] = *(inptr + i*ld_weight_row + j*ld_weight_col);
+ }
+ }
+
+ // Compute the matrix W w
+ for (int j = 0; j < 3; j++)
+ {
+ Ww[0][j] = w[0][j];
+ Ww[1][j] = 0.5*(w[0][j] + w[1][j] + w[2][j]);
+ Ww[2][j] = 0.5*(w[0][j] - w[1][j] + w[2][j]);
+ Ww[3][j] = w[2][j];
+ }
+
+ // Compute V = W w WT
+ for (auto i = 0u; i < inner_tile_i; i++)
+ {
+ V[i][0] = Ww[i][0];
+ V[i][1] = 0.5*(Ww[i][0] + Ww[i][1] + Ww[i][2]);
+ V[i][2] = 0.5*(Ww[i][0] - Ww[i][1] + Ww[i][2]);
+ V[i][3] = Ww[i][2];
+ }
+
+ // Store the transformed weights
+ for (auto i = 0u, m = 0u; i < inner_tile_i; i++)
+ {
+ for (auto j = 0u; j < inner_tile_j; j++, m++)
+ {
+ *(outptr + m*matrix_stride) = V[i][j];
+ }
+ }
+
+ inptr++;
+ outptr++;
+ }
+}
+
+} // namespace weight_transform
+} // namespace winograd
+} // namespace arm_conv
diff --git a/src/core/NEON/kernels/convolution/winograd/weight_transforms/arm_fp32_2x2_5x5.cpp b/src/core/NEON/kernels/convolution/winograd/weight_transforms/arm_fp32_2x2_5x5.cpp
new file mode 100644
index 0000000000..9cdf15a4af
--- /dev/null
+++ b/src/core/NEON/kernels/convolution/winograd/weight_transforms/arm_fp32_2x2_5x5.cpp
@@ -0,0 +1,381 @@
+/*
+ * Copyright (c) 2022 ARM Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <cstddef>
+#include <arm_neon.h>
+
+namespace arm_conv {
+namespace winograd {
+namespace weight_transform {
+
+void arm_fp32_2x2_5x5(
+ unsigned int n_channels,
+ const float *inptr, const size_t ld_weight_row, const size_t ld_weight_col,
+ float *outptr, const size_t matrix_stride
+)
+{
+#ifdef __aarch64__
+ // For each output channel
+ for (; n_channels >= 4; n_channels -= 4)
+ {
+ // Matrices used and computed in this kernel
+ float32x4_t w[5][5], Ww[6][5], V[6][6];
+
+ // Read weights
+ for (int i = 0; i < 5; i++)
+ {
+ for (int j = 0; j < 5; j++)
+ {
+ w[i][j] = vld1q_f32(inptr + i*ld_weight_row + j*ld_weight_col);
+ }
+ }
+
+ // Compute the matrix W w
+ for (int j = 0; j < 5; j++)
+ {
+ // Ww[0][j] = w[0][j]/4.0f;
+ Ww[0][j] = vmulq_n_f32(w[0][j], 1.0f/4.0f);
+
+ // Ww[1][j] = -( w[0][j] + w[1][j] + w[2][j] + w[3][j] + w[4][j])/6.0f;
+ Ww[1][j] = vmulq_n_f32(
+ vaddq_f32(
+ vaddq_f32(
+ vaddq_f32(w[1][j], w[0][j]),
+ vaddq_f32(w[3][j], w[2][j])
+ ),
+ w[4][j]
+ ),
+ -1.0f/6.0f
+ );
+
+ // Ww[2][j] = +(-w[0][j] + w[1][j] - w[2][j] + w[3][j] - w[4][j])/6.0f;
+ // Ww[2][j] = ((w[1][j] - w[0][j]) + (w[3][j] - w[2][j]) - w[4][j])/6.0f;
+ Ww[2][j] = vmulq_n_f32(
+ vsubq_f32(
+ vaddq_f32(
+ vsubq_f32(w[1][j], w[0][j]),
+ vsubq_f32(w[3][j], w[2][j])
+ ),
+ w[4][j]
+ ),
+ 1.0f/6.0f
+ );
+
+ // Ww[3][j] = (w[0][j]/8.0f + w[1][j]/4.0f + w[2][j]/2.0f + w[3][j] + 2*w[4][j])/3.0f;
+ Ww[3][j] = vmulq_n_f32(
+ vmlaq_n_f32(
+ vaddq_f32(
+ vaddq_f32(vmulq_n_f32(w[0][j], 1.0f/8.0f), vmulq_n_f32(w[1][j], 1.0f/4.0f)),
+ vaddq_f32(vmulq_n_f32(w[2][j], 1.0f/2.0f), w[3][j])
+ ),
+ w[4][j], 2.0f
+ ),
+ 1.0f/3.0f
+ );
+
+ // Ww[4][j] = (w[0][j]/8.0f - w[1][j]/4.0f + w[2][j]/2.0f - w[3][j] + 2*w[4][j])/3.0f;
+ Ww[4][j] = vmulq_n_f32(
+ vmlaq_n_f32(
+ vaddq_f32(
+ vsubq_f32(vmulq_n_f32(w[0][j], 1.0f/8.0f), vmulq_n_f32(w[1][j], 1.0f/4.0f)),
+ vsubq_f32(vmulq_n_f32(w[2][j], 1.0f/2.0f), w[3][j])
+ ),
+ w[4][j], 2.0f
+ ),
+ 1.0f/3.0f
+ );
+
+ // Ww[5][j] = w[4][j];
+ Ww[5][j] = w[4][j];
+ }
+
+ // Compute V = W w WT
+ for (int i = 0; i < 6; i++)
+ {
+ // V[i][0] = Ww[i][0]/4.0f;
+ V[i][0] = vmulq_n_f32(Ww[i][0], 1.0f/4.0f);
+
+ // V[i][1] = -( Ww[i][0] + Ww[i][1] + Ww[i][2] + Ww[i][3] + Ww[i][4])/6.0f;
+ V[i][1] = vmulq_n_f32(
+ vaddq_f32(
+ vaddq_f32(
+ vaddq_f32(Ww[i][1], Ww[i][0]),
+ vaddq_f32(Ww[i][3], Ww[i][2])
+ ),
+ Ww[i][4]
+ ),
+ -1.0f/6.0f
+ );
+
+ // V[i][2] = +(-Ww[i][0] + Ww[i][1] - Ww[i][2] + Ww[i][3] - Ww[i][4])/6.0f;
+ // V[i][2] = ((Ww[i][1] - Ww[i][0]) + (Ww[i][3] - Ww[i][2]) - Ww[i][4])/6.0f;
+ V[i][2] = vmulq_n_f32(
+ vsubq_f32(
+ vaddq_f32(
+ vsubq_f32(Ww[i][1], Ww[i][0]),
+ vsubq_f32(Ww[i][3], Ww[i][2])
+ ),
+ Ww[i][4]
+ ),
+ 1.0f/6.0f
+ );
+
+ // V[i][3] = (Ww[i][0]/8.0f + Ww[i][1]/4.0f + Ww[i][2]/2.0f + Ww[i][3] + 2*Ww[i][4])/3.0f;
+ V[i][3] = vmulq_n_f32(
+ vmlaq_n_f32(
+ vaddq_f32(
+ vaddq_f32(vmulq_n_f32(Ww[i][0], 1.0f/8.0f), vmulq_n_f32(Ww[i][1], 1.0f/4.0f)),
+ vaddq_f32(vmulq_n_f32(Ww[i][2], 1.0f/2.0f), Ww[i][3])
+ ),
+ Ww[i][4], 2.0f
+ ),
+ 1.0f/3.0f
+ );
+
+ // V[i][4] = (Ww[i][0]/8.0f - Ww[i][1]/4.0f + Ww[i][2]/2.0f - Ww[i][3] + 2*Ww[i][4])/3.0f;
+ V[i][4] = vmulq_n_f32(
+ vmlaq_n_f32(
+ vaddq_f32(
+ vsubq_f32(vmulq_n_f32(Ww[i][0], 1.0f/8.0f), vmulq_n_f32(Ww[i][1], 1.0f/4.0f)),
+ vsubq_f32(vmulq_n_f32(Ww[i][2], 1.0f/2.0f), Ww[i][3])
+ ),
+ Ww[i][4], 2.0f
+ ),
+ 1.0f/3.0f
+ );
+
+ // V[i][5] = Ww[i][4];
+ V[i][5] = Ww[i][4];
+ }
+
+ // Store the transformed weights
+ for (int i = 0, m = 0; i < 6; i++)
+ {
+ for (int j = 0; j < 6; j++, m++)
+ {
+ vst1q_f32(outptr + m*matrix_stride, V[i][j]);
+ }
+ }
+
+ inptr += 4;
+ outptr += 4;
+ }
+#endif // __aarch64__
+ for (; n_channels >= 2; n_channels -= 2)
+ {
+ // Matrices used and computed in this kernel
+ float32x2_t w[5][5], Ww[6][5], V[6][6];
+
+ // Read weights
+ for (int i = 0; i < 5; i++)
+ {
+ for (int j = 0; j < 5; j++)
+ {
+ w[i][j] = vld1_f32(inptr + i*ld_weight_row + j*ld_weight_col);
+ }
+ }
+
+ // Compute the matrix W w
+ for (int j = 0; j < 5; j++)
+ {
+ // Ww[0][j] = w[0][j]/4.0f;
+ Ww[0][j] = vmul_n_f32(w[0][j], 1.0f/4.0f);
+
+ // Ww[1][j] = -( w[0][j] + w[1][j] + w[2][j] + w[3][j] + w[4][j])/6.0f;
+ Ww[1][j] = vmul_n_f32(
+ vadd_f32(
+ vadd_f32(
+ vadd_f32(w[1][j], w[0][j]),
+ vadd_f32(w[3][j], w[2][j])
+ ),
+ w[4][j]
+ ),
+ -1.0f/6.0f
+ );
+
+ // Ww[2][j] = +(-w[0][j] + w[1][j] - w[2][j] + w[3][j] - w[4][j])/6.0f;
+ // Ww[2][j] = ((w[1][j] - w[0][j]) + (w[3][j] - w[2][j]) - w[4][j])/6.0f;
+ Ww[2][j] = vmul_n_f32(
+ vsub_f32(
+ vadd_f32(
+ vsub_f32(w[1][j], w[0][j]),
+ vsub_f32(w[3][j], w[2][j])
+ ),
+ w[4][j]
+ ),
+ 1.0f/6.0f
+ );
+
+ // Ww[3][j] = (w[0][j]/8.0f + w[1][j]/4.0f + w[2][j]/2.0f + w[3][j] + 2*w[4][j])/3.0f;
+ Ww[3][j] = vmul_n_f32(
+ vmla_n_f32(
+ vadd_f32(
+ vadd_f32(vmul_n_f32(w[0][j], 1.0f/8.0f), vmul_n_f32(w[1][j], 1.0f/4.0f)),
+ vadd_f32(vmul_n_f32(w[2][j], 1.0f/2.0f), w[3][j])
+ ),
+ w[4][j], 2.0f
+ ),
+ 1.0f/3.0f
+ );
+
+ // Ww[4][j] = (w[0][j]/8.0f - w[1][j]/4.0f + w[2][j]/2.0f - w[3][j] + 2*w[4][j])/3.0f;
+ Ww[4][j] = vmul_n_f32(
+ vmla_n_f32(
+ vadd_f32(
+ vsub_f32(vmul_n_f32(w[0][j], 1.0f/8.0f), vmul_n_f32(w[1][j], 1.0f/4.0f)),
+ vsub_f32(vmul_n_f32(w[2][j], 1.0f/2.0f), w[3][j])
+ ),
+ w[4][j], 2.0f
+ ),
+ 1.0f/3.0f
+ );
+
+ // Ww[5][j] = w[4][j];
+ Ww[5][j] = w[4][j];
+ }
+
+ // Compute V = W w WT
+ for (int i = 0; i < 6; i++)
+ {
+ // V[i][0] = Ww[i][0]/4.0f;
+ V[i][0] = vmul_n_f32(Ww[i][0], 1.0f/4.0f);
+
+ // V[i][1] = -( Ww[i][0] + Ww[i][1] + Ww[i][2] + Ww[i][3] + Ww[i][4])/6.0f;
+ V[i][1] = vmul_n_f32(
+ vadd_f32(
+ vadd_f32(
+ vadd_f32(Ww[i][1], Ww[i][0]),
+ vadd_f32(Ww[i][3], Ww[i][2])
+ ),
+ Ww[i][4]
+ ),
+ -1.0f/6.0f
+ );
+
+ // V[i][2] = +(-Ww[i][0] + Ww[i][1] - Ww[i][2] + Ww[i][3] - Ww[i][4])/6.0f;
+ // V[i][2] = ((Ww[i][1] - Ww[i][0]) + (Ww[i][3] - Ww[i][2]) - Ww[i][4])/6.0f;
+ V[i][2] = vmul_n_f32(
+ vsub_f32(
+ vadd_f32(
+ vsub_f32(Ww[i][1], Ww[i][0]),
+ vsub_f32(Ww[i][3], Ww[i][2])
+ ),
+ Ww[i][4]
+ ),
+ 1.0f/6.0f
+ );
+
+ // V[i][3] = (Ww[i][0]/8.0f + Ww[i][1]/4.0f + Ww[i][2]/2.0f + Ww[i][3] + 2*Ww[i][4])/3.0f;
+ V[i][3] = vmul_n_f32(
+ vmla_n_f32(
+ vadd_f32(
+ vadd_f32(vmul_n_f32(Ww[i][0], 1.0f/8.0f), vmul_n_f32(Ww[i][1], 1.0f/4.0f)),
+ vadd_f32(vmul_n_f32(Ww[i][2], 1.0f/2.0f), Ww[i][3])
+ ),
+ Ww[i][4], 2.0f
+ ),
+ 1.0f/3.0f
+ );
+
+ // V[i][4] = (Ww[i][0]/8.0f - Ww[i][1]/4.0f + Ww[i][2]/2.0f - Ww[i][3] + 2*Ww[i][4])/3.0f;
+ V[i][4] = vmul_n_f32(
+ vmla_n_f32(
+ vadd_f32(
+ vsub_f32(vmul_n_f32(Ww[i][0], 1.0f/8.0f), vmul_n_f32(Ww[i][1], 1.0f/4.0f)),
+ vsub_f32(vmul_n_f32(Ww[i][2], 1.0f/2.0f), Ww[i][3])
+ ),
+ Ww[i][4], 2.0f
+ ),
+ 1.0f/3.0f
+ );
+
+ // V[i][5] = Ww[i][4];
+ V[i][5] = Ww[i][4];
+ }
+
+ // Store the transformed weights
+ for (int i = 0, m = 0; i < 6; i++)
+ {
+ for (int j = 0; j < 6; j++, m++)
+ {
+ vst1_f32(outptr + m*matrix_stride, V[i][j]);
+ }
+ }
+
+ inptr += 2;
+ outptr += 2;
+ }
+ for (; n_channels; n_channels--)
+ {
+ // Matrices used and computed in this kernel
+ float w[5][5], Ww[6][5], V[6][6];
+
+ // Read weights
+ for (int i = 0; i < 5; i++)
+ {
+ for (int j = 0; j < 5; j++)
+ {
+ w[i][j] = *(inptr + i*ld_weight_row + j*ld_weight_col);
+ }
+ }
+
+ // Compute the matrix W w
+ for (int j = 0; j < 5; j++)
+ {
+ Ww[0][j] = w[0][j]/4.0f;
+ Ww[1][j] = -( w[0][j] + w[1][j] + w[2][j] + w[3][j] + w[4][j])/6.0f;
+ Ww[2][j] = +(-w[0][j] + w[1][j] - w[2][j] + w[3][j] - w[4][j])/6.0f;
+ Ww[3][j] = (w[0][j]/8.0f + w[1][j]/4.0f + w[2][j]/2.0f + w[3][j] + 2*w[4][j])/3.0f;
+ Ww[4][j] = (w[0][j]/8.0f - w[1][j]/4.0f + w[2][j]/2.0f - w[3][j] + 2*w[4][j])/3.0f;
+ Ww[5][j] = w[4][j];
+ }
+
+ // Compute V = W w WT
+ for (int i = 0; i < 6; i++)
+ {
+ V[i][0] = Ww[i][0]/4.0f;
+ V[i][1] = -( Ww[i][0] + Ww[i][1] + Ww[i][2] + Ww[i][3] + Ww[i][4])/6.0f;
+ V[i][2] = +(-Ww[i][0] + Ww[i][1] - Ww[i][2] + Ww[i][3] - Ww[i][4])/6.0f;
+ V[i][3] = (Ww[i][0]/8.0f + Ww[i][1]/4.0f + Ww[i][2]/2.0f + Ww[i][3] + 2*Ww[i][4])/3.0f;
+ V[i][4] = (Ww[i][0]/8.0f - Ww[i][1]/4.0f + Ww[i][2]/2.0f - Ww[i][3] + 2*Ww[i][4])/3.0f;
+ V[i][5] = Ww[i][4];
+ }
+
+ // Store the transformed weights
+ for (int i = 0, m = 0; i < 6; i++)
+ {
+ for (int j = 0; j < 6; j++, m++)
+ {
+ *(outptr + m*matrix_stride) = V[i][j];
+ }
+ }
+
+ inptr++;
+ outptr++;
+ }
+}
+
+} // namespace weight_transform
+} // namespace winograd
+} // namespace arm_conv
diff --git a/src/core/NEON/kernels/convolution/winograd/weight_transforms/arm_fp32_4x4_3x3.cpp b/src/core/NEON/kernels/convolution/winograd/weight_transforms/arm_fp32_4x4_3x3.cpp
new file mode 100644
index 0000000000..53cfa3d1d4
--- /dev/null
+++ b/src/core/NEON/kernels/convolution/winograd/weight_transforms/arm_fp32_4x4_3x3.cpp
@@ -0,0 +1,236 @@
+/*
+ * Copyright (c) 2022 ARM Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <cstddef>
+#include <arm_neon.h>
+
+namespace arm_conv {
+namespace winograd {
+namespace weight_transform {
+
+void arm_fp32_4x4_3x3(
+ unsigned int n_channels,
+ const float *inptr, const size_t ld_weight_row, const size_t ld_weight_col,
+ float *outptr, const size_t matrix_stride
+)
+{
+#ifdef __aarch64__
+ for (; n_channels >= 4; n_channels -= 4)
+ {
+ // Matrices used and computed in this kernel
+ float32x4_t w[3][3], Ww[6][3], V[6][6];
+
+ // Read weights
+ for (int i = 0; i < 3; i++)
+ {
+ for (int j = 0; j < 3; j++)
+ {
+ w[i][j] = vld1q_f32(inptr + i*ld_weight_row + j*ld_weight_col);
+ }
+ }
+
+ // Compute the matrix W w
+ for (int j = 0; j < 3; j++)
+ {
+ // Ww[0][j] = 6*w[0][j];
+ Ww[0][j] = vmulq_n_f32(w[0][j], 6.0);
+
+ // Ww[1][j] = -4*w[0][j] + -4*w[1][j] + -4*w[2][j];
+ Ww[1][j] = vmulq_n_f32(vaddq_f32(vaddq_f32(w[0][j], w[1][j]), w[2][j]), -4.0);
+
+ // Ww[2][j] = -4*w[0][j] + 4*w[1][j] + -4*w[2][j];
+ Ww[2][j] = vmulq_n_f32(vsubq_f32(vsubq_f32(w[1][j], w[0][j]), w[2][j]), 4.0);
+
+ // Ww[3][j] = 1*w[0][j] + 2*w[1][j] + 4*w[2][j];
+ Ww[3][j] = vmlaq_n_f32(vmlaq_n_f32(w[0][j], w[1][j], 2.0f), w[2][j], 4.0f);
+
+ // Ww[4][j] = 1*w[0][j] + -2*w[1][j] + 4*w[2][j];
+ Ww[4][j] = vmlaq_n_f32(vmlsq_n_f32(w[0][j], w[1][j], 2.0f), w[2][j], 4.0f);
+
+ // Ww[5][j] = 24*w[2][j];
+ Ww[5][j] = vmulq_n_f32(w[2][j], 24.0f);
+ }
+
+ // Compute V = W w WT
+ for (int i = 0; i < 6; i++)
+ {
+ const float recip576 = 1.0f / 576.0f;
+
+ // V[i][0] = 6*Ww[i][0];
+ V[i][0] = vmulq_n_f32(vmulq_n_f32(Ww[i][0], 6.0), recip576);
+
+ // V[i][1] = -4*Ww[i][0] + -4*Ww[i][1] + -4*Ww[i][2];
+ V[i][1] = vmulq_n_f32(vmulq_n_f32(vaddq_f32(vaddq_f32(Ww[i][0], Ww[i][1]), Ww[i][2]), -4.0), recip576);
+
+ // V[i][2] = -4*Ww[i][0] + 4*Ww[i][1] + -4*Ww[i][2];
+ V[i][2] = vmulq_n_f32(vmulq_n_f32(vsubq_f32(vsubq_f32(Ww[i][1], Ww[i][0]), Ww[i][2]), 4.0), recip576);
+
+ // V[i][3] = 1*Ww[i][0] + 2*Ww[i][1] + 4*Ww[i][2];
+ V[i][3] = vmulq_n_f32(vmlaq_n_f32(vmlaq_n_f32(Ww[i][0], Ww[i][1], 2.0f), Ww[i][2], 4.0f), recip576);
+
+ // V[i][4] = 1*Ww[i][0] + -2*Ww[i][1] + 4*Ww[i][2];
+ V[i][4] = vmulq_n_f32(vmlaq_n_f32(vmlsq_n_f32(Ww[i][0], Ww[i][1], 2.0f), Ww[i][2], 4.0f), recip576);
+
+ // V[i][5] = 24*Ww[i][2];
+ V[i][5] = vmulq_n_f32(vmulq_n_f32(Ww[i][2], 24.0f), recip576);
+ }
+
+ // Store the transformed weights
+ for (int i = 0, m = 0; i < 6; i++)
+ {
+ for (int j = 0; j < 6; j++, m++)
+ {
+ vst1q_f32(outptr + m*matrix_stride, V[i][j]);
+ }
+ }
+
+ inptr += 4;
+ outptr += 4;
+ }
+#endif // __aarch64__
+ for (; n_channels >= 2; n_channels -= 2)
+ {
+ // Matrices used and computed in this kernel
+ float32x2_t w[3][3], Ww[6][3], V[6][6];
+
+ // Read weights
+ for (int i = 0; i < 3; i++)
+ {
+ for (int j = 0; j < 3; j++)
+ {
+ w[i][j] = vld1_f32(inptr + i*ld_weight_row + j*ld_weight_col);
+ }
+ }
+
+ // Compute the matrix W w
+ for (int j = 0; j < 3; j++)
+ {
+ // Ww[0][j] = 6*w[0][j];
+ Ww[0][j] = vmul_n_f32(w[0][j], 6.0);
+
+ // Ww[1][j] = -4*w[0][j] + -4*w[1][j] + -4*w[2][j];
+ Ww[1][j] = vmul_n_f32(vadd_f32(vadd_f32(w[0][j], w[1][j]), w[2][j]), -4.0);
+
+ // Ww[2][j] = -4*w[0][j] + 4*w[1][j] + -4*w[2][j];
+ Ww[2][j] = vmul_n_f32(vsub_f32(vsub_f32(w[1][j], w[0][j]), w[2][j]), 4.0);
+
+ // Ww[3][j] = 1*w[0][j] + 2*w[1][j] + 4*w[2][j];
+ Ww[3][j] = vmla_n_f32(vmla_n_f32(w[0][j], w[1][j], 2.0f), w[2][j], 4.0f);
+
+ // Ww[4][j] = 1*w[0][j] + -2*w[1][j] + 4*w[2][j];
+ Ww[4][j] = vmla_n_f32(vmls_n_f32(w[0][j], w[1][j], 2.0f), w[2][j], 4.0f);
+
+ // Ww[5][j] = 24*w[2][j];
+ Ww[5][j] = vmul_n_f32(w[2][j], 24.0f);
+ }
+
+ // Compute V = W w WT
+ for (int i = 0; i < 6; i++)
+ {
+ const float recip576 = 1.0f / 576.0f;
+
+ // V[i][0] = 6*Ww[i][0];
+ V[i][0] = vmul_n_f32(vmul_n_f32(Ww[i][0], 6.0), recip576);
+
+ // V[i][1] = -4*Ww[i][0] + -4*Ww[i][1] + -4*Ww[i][2];
+ V[i][1] = vmul_n_f32(vmul_n_f32(vadd_f32(vadd_f32(Ww[i][0], Ww[i][1]), Ww[i][2]), -4.0), recip576);
+
+ // V[i][2] = -4*Ww[i][0] + 4*Ww[i][1] + -4*Ww[i][2];
+ V[i][2] = vmul_n_f32(vmul_n_f32(vsub_f32(vsub_f32(Ww[i][1], Ww[i][0]), Ww[i][2]), 4.0), recip576);
+
+ // V[i][3] = 1*Ww[i][0] + 2*Ww[i][1] + 4*Ww[i][2];
+ V[i][3] = vmul_n_f32(vmla_n_f32(vmla_n_f32(Ww[i][0], Ww[i][1], 2.0f), Ww[i][2], 4.0f), recip576);
+
+ // V[i][4] = 1*Ww[i][0] + -2*Ww[i][1] + 4*Ww[i][2];
+ V[i][4] = vmul_n_f32(vmla_n_f32(vmls_n_f32(Ww[i][0], Ww[i][1], 2.0f), Ww[i][2], 4.0f), recip576);
+
+ // V[i][5] = 24*Ww[i][2];
+ V[i][5] = vmul_n_f32(vmul_n_f32(Ww[i][2], 24.0f), recip576);
+ }
+
+ // Store the transformed weights
+ for (int i = 0, m = 0; i < 6; i++)
+ {
+ for (int j = 0; j < 6; j++, m++)
+ {
+ vst1_f32(outptr + m*matrix_stride, V[i][j]);
+ }
+ }
+
+ inptr += 2;
+ outptr += 2;
+ }
+ for (; n_channels; n_channels--)
+ {
+ // Matrices used and computed in this kernel
+ float w[3][3], Ww[6][3], V[6][6];
+
+ // Read weights
+ for (int i = 0; i < 3; i++)
+ {
+ for (int j = 0; j < 3; j++)
+ {
+ w[i][j] = *(inptr + i*ld_weight_row + j*ld_weight_col);
+ }
+ }
+
+ // Compute the matrix W w
+ for (int j = 0; j < 3; j++)
+ {
+ Ww[0][j] = 6*w[0][j];
+ Ww[1][j] = -4*w[0][j] + -4*w[1][j] + -4*w[2][j];
+ Ww[2][j] = -4*w[0][j] + 4*w[1][j] + -4*w[2][j];
+ Ww[3][j] = 1*w[0][j] + 2*w[1][j] + 4*w[2][j];
+ Ww[4][j] = 1*w[0][j] + -2*w[1][j] + 4*w[2][j];
+ Ww[5][j] = 24*w[2][j];
+ }
+
+ // Compute V = W w WT
+ for (int i = 0; i < 6; i++)
+ {
+ V[i][0] = ( 6*Ww[i][0]) / 576.0;
+ V[i][1] = (-4*Ww[i][0] + -4*Ww[i][1] + -4*Ww[i][2]) / 576.0;
+ V[i][2] = (-4*Ww[i][0] + 4*Ww[i][1] + -4*Ww[i][2]) / 576.0;
+ V[i][3] = ( 1*Ww[i][0] + 2*Ww[i][1] + 4*Ww[i][2]) / 576.0;
+ V[i][4] = ( 1*Ww[i][0] + -2*Ww[i][1] + 4*Ww[i][2]) / 576.0;
+ V[i][5] = (24*Ww[i][2]) / 576.0;
+ }
+
+ // Store the transformed weights
+ for (int i = 0, m = 0; i < 6; i++)
+ {
+ for (int j = 0; j < 6; j++, m++)
+ {
+ *(outptr + m*matrix_stride) = V[i][j];
+ }
+ }
+
+ inptr++;
+ outptr++;
+ }
+}
+
+} // namespace weight_transform
+} // namespace winograd
+} // namespace arm_conv
diff --git a/src/core/NEON/kernels/convolution/winograd/weight_transforms/cpp_fp32_1x2_1x7.cpp b/src/core/NEON/kernels/convolution/winograd/weight_transforms/cpp_fp32_1x2_1x7.cpp
new file mode 100644
index 0000000000..834f982f37
--- /dev/null
+++ b/src/core/NEON/kernels/convolution/winograd/weight_transforms/cpp_fp32_1x2_1x7.cpp
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2022 ARM Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <cstddef>
+
+namespace arm_conv {
+namespace winograd {
+namespace weight_transform {
+
+void cpp_fp32_1x2_1x7(
+ unsigned int n_channels,
+ const float* inptr, size_t, size_t ld_weight_col,
+ float *outptr, size_t matrix_stride
+)
+{
+ for (; n_channels; n_channels--)
+ {
+ // Matrices used and computed in this kernel
+ float w[7], V[8];
+
+ // Read weights
+ for (int j = 0; j < 7; j++)
+ {
+ w[j] = *(inptr + j*ld_weight_col);
+ }
+
+ // Compute V = w WT
+ V[0] = (w[0]*-1) / 36.0f;
+ V[1] = (w[1]*-1 + w[3]*-1 + w[5]*-1 + w[0]*1 + w[2]*1 + w[4]*1 + w[6]*1) / 48.0f;
+ V[2] = (w[0]*1 + w[1]*1 + w[2]*1 + w[3]*1 + w[4]*1 + w[5]*1 + w[6]*1) / 48.0f;
+ V[3] = (w[0]*-1 + w[6]*-64 + w[4]*-16 + w[2]*-4 + w[1]*2 + w[3]*8 + w[5]*32) / 120.0f;
+ V[4] = (w[0]*-1 + w[6]*-64 + w[5]*-32 + w[4]*-16 + w[3]*-8 + w[2]*-4 + w[1]*-2) / 120.0f;
+ V[5] = (w[5]*-243 + w[3]*-27 + w[1]*-3 + w[2]*9 + w[4]*81 + w[6]*729 + w[0]*1) / 720.0f;
+ V[6] = (w[1]*3 + w[2]*9 + w[3]*27 + w[4]*81 + w[5]*243 + w[6]*729 + w[0]*1) / 720.0f;
+ V[7] = (w[6]*1) / 1.0f;
+
+ // Store the transformed weights
+ for (int j = 0; j < 8; j++)
+ {
+ *(outptr + j*matrix_stride) = V[j];
+ }
+
+ inptr++;
+ outptr++;
+ }
+}
+
+} // namespace output_transform
+} // namespace winograd
+} // namespace arm_conv
diff --git a/src/core/NEON/kernels/convolution/winograd/weight_transforms/cpp_fp32_1x4_1x5.cpp b/src/core/NEON/kernels/convolution/winograd/weight_transforms/cpp_fp32_1x4_1x5.cpp
new file mode 100644
index 0000000000..585fb2516b
--- /dev/null
+++ b/src/core/NEON/kernels/convolution/winograd/weight_transforms/cpp_fp32_1x4_1x5.cpp
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2022 ARM Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <cstddef>
+
+namespace arm_conv {
+namespace winograd {
+namespace weight_transform {
+
+void cpp_fp32_1x4_1x5(
+ unsigned int n_channels,
+ const float *inptr,
+ size_t, // ld_weight_row
+ size_t ld_weight_col,
+ float *outptr,
+ size_t matrix_stride
+)
+{
+ constexpr auto kernel_cols = 5u, inner_tile_cols = 8u;
+
+ // For each output channel
+ for (; n_channels; n_channels--)
+ {
+ // Matrices used and computed in this kernel
+ float w[kernel_cols], V[inner_tile_cols];
+
+ // Read weights
+ for (auto j = 0u; j < kernel_cols; j++)
+ {
+ w[j] = *(inptr + j * ld_weight_col);
+ }
+
+ // Compute V = w WT
+ V[0] = (w[0]*-1) / 36;
+ V[1] = (w[1]*-1 + w[3]*-1 + w[0]*1 + w[2]*1 + w[4]*1) / 48;
+ V[2] = (w[0]*1 + w[1]*1 + w[2]*1 + w[3]*1 + w[4]*1) / 48;
+ V[3] = (w[0]*-1 + w[4]*-16 + w[2]*-4 + w[1]*2 + w[3]*8) / 120;
+ V[4] = (w[0]*-1 + w[4]*-16 + w[3]*-8 + w[2]*-4 + w[1]*-2) / 120;
+ V[5] = (w[3]*-27 + w[1]*-3 + w[2]*9 + w[4]*81 + w[0]*1) / 720;
+ V[6] = (w[1]*3 + w[2]*9 + w[3]*27 + w[4]*81 + w[0]*1) / 720;
+ V[7] = (w[4]*1) / 1;
+
+ // Store the transformed weights
+ for (auto j = 0u; j < inner_tile_cols; j++)
+ {
+ *(outptr + j*matrix_stride) = V[j];
+ }
+
+ inptr++;
+ outptr++;
+ }
+}
+
+} // namespace weight_transform
+} // namespace winograd
+} // namespace arm_conv
diff --git a/src/core/NEON/kernels/convolution/winograd/weight_transforms/cpp_fp32_1x6_1x3.cpp b/src/core/NEON/kernels/convolution/winograd/weight_transforms/cpp_fp32_1x6_1x3.cpp
new file mode 100644
index 0000000000..63754e529c
--- /dev/null
+++ b/src/core/NEON/kernels/convolution/winograd/weight_transforms/cpp_fp32_1x6_1x3.cpp
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2022 ARM Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <cstddef>
+
+namespace arm_conv {
+namespace winograd {
+namespace weight_transform {
+
+void cpp_fp32_1x6_1x3(
+ unsigned int n_channels,
+ const float *inptr, size_t, size_t ld_weight_col,
+ float *outptr, size_t matrix_stride
+)
+{
+ for (; n_channels; n_channels--)
+ {
+ // Matrices used and computed in this kernel
+ float w[3], V[8];
+
+ // Read weights
+ for (int j = 0; j < 3; j++)
+ {
+ w[j] = *(inptr + j * ld_weight_col);
+ }
+
+ // Compute V = w WT
+ V[0] = (w[0]*-1) / 36.0f;
+ V[1] = (w[1]*-1 + w[0]*1 + w[2]*1) / 48.0f;
+ V[2] = (w[0]*1 + w[1]*1 + w[2]*1) / 48.0f;
+ V[3] = (w[0]*-1 + w[2]*-4 + w[1]*2) / 120.0f;
+ V[4] = (w[0]*-1 + w[2]*-4 + w[1]*-2) / 120.0f;
+ V[5] = (w[1]*-3 + w[2]*9 + w[0]*1) / 720.0f;
+ V[6] = (w[1]*3 + w[2]*9 + w[0]*1) / 720.0f;
+ V[7] = (w[2]*1) / 1;
+
+ // Store the transformed weights
+ for (int j = 0; j < 8; j++)
+ {
+ *(outptr + j*matrix_stride) = V[j];
+ }
+
+ inptr++;
+ outptr++;
+ }
+}
+
+} // namespace weight_transform
+} // namespace winograd
+} // namespace arm_conv
diff --git a/src/core/NEON/kernels/convolution/winograd/weight_transforms_fp16.cpp b/src/core/NEON/kernels/convolution/winograd/weight_transforms_fp16.cpp
new file mode 100644
index 0000000000..6c8bbe07cf
--- /dev/null
+++ b/src/core/NEON/kernels/convolution/winograd/weight_transforms_fp16.cpp
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2022 Arm Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#if defined(__aarch64__) && defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
+
+#include "winograd_implementations.hpp"
+#include "weight_transform.hpp"
+
+namespace arm_conv {
+namespace winograd {
+namespace weight_transform {
+
+void *a64_fp16_4x4_3x3(unsigned int, const __fp16 *, size_t, size_t, __fp16 *, size_t);
+
+#define IMPL(KERN_ROWS, KERN_COLS, TRANS_ROWS, TRANS_COLS, KERN) \
+ new Transform<__fp16>(#KERN, KERN_ROWS, KERN_COLS, TRANS_ROWS, TRANS_COLS, KERN)
+
+static const TransformImplementation<__fp16> transforms_fp16[] = {
+ { IMPL(3, 3, 6, 6, a64_fp16_4x4_3x3) },
+ { nullptr }
+};
+
+template <>
+const TransformImplementation<__fp16> *implementation_list(void)
+{
+ return transforms_fp16;
+}
+
+} // namespace weight_transform
+} // namespace winograd
+} // namespace arm_conv
+
+#endif // defined(__aarch64__) && defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
diff --git a/src/core/NEON/kernels/convolution/winograd/weight_transforms_fp32.cpp b/src/core/NEON/kernels/convolution/winograd/weight_transforms_fp32.cpp
new file mode 100644
index 0000000000..63f5fc786c
--- /dev/null
+++ b/src/core/NEON/kernels/convolution/winograd/weight_transforms_fp32.cpp
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2022 Arm Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include "winograd_implementations.hpp"
+#include "weight_transform.hpp"
+
+namespace arm_conv {
+namespace winograd {
+namespace weight_transform {
+
+#if defined(__aarch64__)
+#if defined(ARM_COMPUTE_ENABLE_SVE)
+#endif // defined(ARM_COMPUTE_ENABLE_SVE)
+#endif // defined(__aarch64__)
+void *arm_fp32_4x4_3x3(unsigned int, const float *, size_t, size_t, float *, size_t);
+void *arm_fp32_2x2_3x3(unsigned int, const float *, size_t, size_t, float *, size_t);
+void *arm_fp32_2x2_5x5(unsigned int, const float *, size_t, size_t, float *, size_t);
+void *cpp_fp32_1x6_1x3(unsigned int, const float *, size_t, size_t, float *, size_t);
+void *cpp_fp32_1x4_1x5(unsigned int, const float *, size_t, size_t, float *, size_t);
+void *cpp_fp32_1x2_1x7(unsigned int, const float *, size_t, size_t, float *, size_t);
+
+#define IMPL(KERN_ROWS, KERN_COLS, TRANS_ROWS, TRANS_COLS, KERN) \
+ new Transform<float>(#KERN, KERN_ROWS, KERN_COLS, TRANS_ROWS, TRANS_COLS, KERN)
+
+#define IMPL_T(KERN_ROWS, KERN_COLS, TRANS_ROWS, TRANS_COLS, KERN) \
+ new Transform<float>(#KERN, KERN_ROWS, KERN_COLS, TRANS_ROWS, TRANS_COLS, Transform<float>::get_transposed_kernel(KERN))
+
+static const TransformImplementation<float> transforms_fp32[] = {
+#if defined(__aarch64__)
+#if defined(ARM_COMPUTE_ENABLE_SVE)
+#endif // defined(ARM_COMPUTE_ENABLE_SVE)
+#endif // defined(__aarch64__)
+ { IMPL(3, 3, 6, 6, arm_fp32_4x4_3x3) },
+ { IMPL(3, 3, 4, 4, arm_fp32_2x2_3x3) },
+ { IMPL(5, 5, 6, 6, arm_fp32_2x2_5x5) },
+ { IMPL(1, 3, 1, 8, cpp_fp32_1x6_1x3) },
+ { IMPL_T(3, 1, 8, 1, cpp_fp32_1x6_1x3) },
+ { IMPL(1, 5, 1, 8, cpp_fp32_1x4_1x5) },
+ { IMPL_T(5, 1, 8, 1, cpp_fp32_1x4_1x5) },
+ { IMPL(1, 7, 1, 8, cpp_fp32_1x2_1x7) },
+ { IMPL_T(7, 1, 8, 1, cpp_fp32_1x2_1x7) },
+ { nullptr }
+};
+
+template <>
+const TransformImplementation<float> *implementation_list(void)
+{
+ return transforms_fp32;
+}
+
+} // namespace weight_transform
+} // namespace winograd
+} // namespace arm_conv
diff --git a/src/core/NEON/kernels/convolution/winograd/winograd.cpp b/src/core/NEON/kernels/convolution/winograd/winograd.cpp
deleted file mode 100644
index d556112853..0000000000
--- a/src/core/NEON/kernels/convolution/winograd/winograd.cpp
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- * Copyright (c) 2017-2019 Arm Limited.
- *
- * SPDX-License-Identifier: MIT
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#include <cstring>
-#include "utils.hpp"
-#include "winograd.hpp"
-
-using namespace winograd;
-using array2 = std::pair<unsigned int, unsigned int>;
-
-#define MEMBERFN(RTYPE) \
- template <int output_tile_rows, int output_tile_cols, int kernel_rows, \
- int kernel_cols, WinogradRoots roots> \
- template <typename TOut, typename TIn, typename TGEMMIn, typename TGEMMOut> \
- RTYPE WinogradGEMM<output_tile_rows, output_tile_cols, kernel_rows, \
- kernel_cols, \
- roots>::Convolution<TOut, TIn, TGEMMIn, TGEMMOut>
-
-/** Get the output shape of a convolution. */
-MEMBERFN(array2)
-::get_output_shape(const std::pair<unsigned int, unsigned int> input_shape,
- const bool padding_same) {
- const unsigned int n_rows =
- padding_same ? input_shape.first : input_shape.first - (kernel_rows - 1);
- const unsigned int n_cols = padding_same
- ? input_shape.second
- : input_shape.second - (kernel_cols - 1);
- return {n_rows, n_cols};
-}
-
-/** Get the memory required to store the kernel transformed into the
- * Winograd domain.
- */
-MEMBERFN(size_t)
-::get_kernel_storage_size(const unsigned int n_input_channels,
- const unsigned int n_output_channels) {
- return N_GEMMS * get_kernel_matrix_size(n_input_channels, n_output_channels);
-}
-
-MEMBERFN(size_t)
-::get_input_storage_size(const unsigned int n_batches,
- const unsigned int n_rows, const unsigned int n_cols,
- const unsigned int n_channels,
- const bool same_padding) {
- return N_GEMMS * get_input_matrix_size(n_batches, n_rows, n_cols, n_channels,
- same_padding);
-}
-
-MEMBERFN(size_t)
-::get_output_storage_size(const unsigned int n_batches,
- const unsigned int n_rows, const unsigned int n_cols,
- const unsigned int n_channels) {
- return N_GEMMS *
- get_output_matrix_size(n_batches, n_rows, n_cols, n_channels);
-}
-
-/** Get the memory required to apply a Winograd operator to some input.
- */
-MEMBERFN(size_t)
-::get_working_space_size(const unsigned int n_batches,
- const unsigned int n_rows, const unsigned int n_cols,
- const unsigned int n_input_channels,
- const unsigned int n_output_channels,
- const bool padding_same) {
- const auto output_shape = get_output_shape({n_rows, n_cols}, padding_same);
-
- // Get the memory required to store the matrices
- const size_t matrix_sizes =
- N_GEMMS *
- (get_input_matrix_size(n_batches, n_rows, n_cols, n_input_channels,
- padding_same) +
- get_output_matrix_size(n_batches, output_shape.first,
- output_shape.second, n_output_channels));
- return matrix_sizes;
-}
-
-/* Get the memory required by a single "input" matrix.
- */
-MEMBERFN(size_t)
-::get_input_matrix_size(const unsigned int n_batches, const unsigned int n_rows,
- const unsigned int n_cols,
- const unsigned int n_channels,
- const bool same_padding) {
- return get_input_matrix_stride(n_batches, n_rows, n_cols, n_channels,
- same_padding) *
- sizeof(TGEMMIn);
-}
-
-MEMBERFN(int)
-::get_input_matrix_stride(const unsigned int n_batches, const unsigned int n_rows,
- const unsigned int n_cols,
- const unsigned int n_channels,
- const bool same_padding) {
- const auto output_shape = get_output_shape({n_rows, n_cols}, same_padding);
- const unsigned int tile_rows = iceildiv(output_shape.first, output_tile_rows);
- const unsigned int tile_cols =
- iceildiv(output_shape.second, output_tile_cols);
- const unsigned int M =
- roundup<unsigned int>(n_batches * tile_rows * tile_cols, M_BLOCK);
- const unsigned int K = n_channels;
-
- return M * K;
-}
-
-/* Get the memory required by a single "output" matrix.
- */
-MEMBERFN(size_t)
-::get_output_matrix_size(const unsigned int n_batches,
- const unsigned int n_rows, const unsigned int n_cols,
- const unsigned int n_channels) {
- return get_output_matrix_stride(n_batches, n_rows, n_cols, n_channels) *
- sizeof(TGEMMOut);
-}
-
-MEMBERFN(int)
-::get_output_matrix_stride(const unsigned int n_batches,
- const unsigned int n_rows, const unsigned int n_cols,
- const unsigned int n_channels) {
- // Compute shape for the GEMM
- const int tile_rows = iceildiv(n_rows, output_tile_rows);
- const int tile_cols = iceildiv(n_cols, output_tile_cols);
- const int M = roundup<int>(tile_rows * tile_cols, M_BLOCK);
- const int N = roundup<int>(n_channels, N_BLOCK);
-
- return n_batches * M * N;
-}
-
-
-/* Get the memory required by a single "kernel" matrix.
- */
-MEMBERFN(size_t)
-::get_kernel_matrix_size(const unsigned int n_input_channels,
- const unsigned int n_output_channels) {
- return sizeof(TGEMMIn) *
- get_kernel_matrix_stride(n_input_channels, n_output_channels);
-}
-
-MEMBERFN(int)
-::get_kernel_matrix_stride(const unsigned int n_input_channels,
- const unsigned int n_output_channels) {
- return n_input_channels * roundup<int>(n_output_channels, N_BLOCK);
-}
-
-// Instantiate required implementations
-template class WinogradGEMM<2, 2, 3, 3, WinogradRoots::Integers>::Convolution<float, float, float, float>;
-template class WinogradGEMM<4, 4, 3, 3, WinogradRoots::Integers>::Convolution<float, float, float, float>;
-
-template class WinogradGEMM<1, 6, 1, 3, WinogradRoots::Integers>::Convolution<float, float, float, float>;
-template class WinogradGEMM<6, 1, 3, 1, WinogradRoots::Integers>::Convolution<float, float, float, float>;
-
-template class WinogradGEMM<2, 2, 5, 5, WinogradRoots::Integers>::Convolution<float, float, float, float>;
-
-template class WinogradGEMM<1, 4, 1, 5, WinogradRoots::Integers>::Convolution<float, float, float, float>;
-template class WinogradGEMM<4, 1, 5, 1, WinogradRoots::Integers>::Convolution<float, float, float, float>;
-
-template class WinogradGEMM<1, 2, 1, 7, WinogradRoots::Integers>::Convolution<float, float, float, float>;
-template class WinogradGEMM<2, 1, 7, 1, WinogradRoots::Integers>::Convolution<float, float, float, float>;
-
-#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
-template class WinogradGEMM<4, 4, 3, 3, WinogradRoots::Integers>::Convolution<__fp16, __fp16, __fp16, __fp16>;
-#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
diff --git a/src/core/NEON/kernels/convolution/winograd/winograd.hpp b/src/core/NEON/kernels/convolution/winograd/winograd.hpp
deleted file mode 100644
index ac82e7b7b9..0000000000
--- a/src/core/NEON/kernels/convolution/winograd/winograd.hpp
+++ /dev/null
@@ -1,621 +0,0 @@
-/*
- * Copyright (c) 2017-2019 Arm Limited.
- *
- * SPDX-License-Identifier: MIT
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#pragma once
-
-#include "arm_gemm.hpp"
-
-#include <cstddef>
-#include <utility>
-
-namespace winograd
-{
-
-class ITransform
-{
- public:
- virtual ~ITransform() = default;
-
- /**
- * Get the working space required to perform the transformation.
- *
- * Note, the working space is only required when performing the
- * transformation - hence it can be reused whenever the transformation is
- * not running.
- *
- * @param nthreads The greatest number of threads that will be used to execute the transform.
- * @return Size of working space required in bytes.
- */
- virtual size_t get_working_space_size(unsigned int nthreads=1) const = 0;
-
- /**
- * Set the working space to be used by the transformation.
- *
- * Note, the working space is only required when performing the
- * transformation - hence it can be reused whenever the transformation is
- * not running.
- *
- * @param Pointer to the working space.
- */
- virtual void set_working_space(void *buffer) = 0;
-
- /**
- * Get the window of work a given operator can perform.
- */
- virtual unsigned int get_window() const = 0;
-
- /**
- * Perform work upon a window of the transform.
- */
- virtual void run(unsigned int start, unsigned int stop, unsigned int threadid=0) = 0;
-};
-
-class IInputTransform : public ITransform
-{
- public:
- virtual ~IInputTransform() = default;
-
- /**
- * Set the pointer to the (NHWC-ordered) tensor to be transformed.
- */
- virtual void set_input_tensor(const void *input) = 0;
-
- /**
- * Set the pointer to the (NHWC-ordered) tensor to be transformed.
- * @param col_stride Stride between columns of the tensor, measured in elements (not bytes).
- */
- virtual void set_input_tensor(const void *input, int col_stride) = 0;
-
- /**
- * Set the pointer to the (NHWC-ordered) tensor to be transformed.
- * @param row_stride Stride between rows of the tensor, measured in elements (not bytes).
- * @param col_stride Stride between columns of the tensor, measured in elements (not bytes).
- */
- virtual void set_input_tensor(const void *input, int row_stride, int col_stride) = 0;
-
- /**
- * Set the pointer to the (NHWC-ordered) tensor to be transformed.
- * @param batch_stride Stride between batches of the tensor, measured in elements (not bytes).
- * @param row_stride Stride between rows of the tensor, measured in elements (not bytes).
- * @param col_stride Stride between columns of the tensor, measured in elements (not bytes).
- */
- virtual void set_input_tensor(const void *input, int batch_stride, int row_stride, int col_stride) = 0;
-
- /**
- * Set pointers to the matrices written by the transform.
- * @param matrices Pointer to the start of the first matrix representing the transformed input.
- * @param inter_matrix_stride Stride (in elements) between matrices.
- * @param matrix_row_stride Stride (in elements) between the rows within a single matrix.
- */
- virtual void set_output_matrices(void *matrices, int inter_matrix_stride, int matrix_row_stride) = 0;
-};
-
-class IOutputTransform : public ITransform
-{
- public:
- virtual ~IOutputTransform() = default;
-
- /**
- * Set pointers to the matrices written by the transform.
- * @param matrices Pointer to the start of the first matrix representing the input to the transform.
- * @param inter_matrix_stride Stride (in elements) between matrices.
- * @param matrix_row_stride Stride (in elements) between the rows within a single matrix.
- */
- virtual void set_input_matrices(const void *matrices, int inter_matrix_stride, int matrix_row_stride) = 0;
-
- /**
- * Set pointer to the bias tensor (can be ignored or called with nullptr for no bias.
- */
- virtual void set_bias(const void *bias=nullptr) = 0;
-
- /**
- * Set pointer to the output tensor produced by the transform.
- */
- virtual void set_output_tensor(void *output) = 0;
-
- /**
- * Set pointer to the output tensor produced by the transform.
- * @param col_stride Stride between columns of the tensor, measured in elements (not bytes).
- */
- virtual void set_output_tensor(void *output, int col_stride) = 0;
-
- /**
- * Set pointer to the output tensor produced by the transform.
- * @param row_stride Stride between rows of the tensor, measured in elements (not bytes).
- * @param col_stride Stride between columns of the tensor, measured in elements (not bytes).
- */
- virtual void set_output_tensor(void *output, int row_stride, int col_stride) = 0;
-
- /**
- * Set pointer to the output tensor produced by the transform.
- * @param batch_stride Stride between batches of the tensor, measured in elements (not bytes).
- * @param row_stride Stride between rows of the tensor, measured in elements (not bytes).
- * @param col_stride Stride between columns of the tensor, measured in elements (not bytes).
- */
- virtual void set_output_tensor(void *output, int batch_stride, int row_stride, int col_stride) = 0;
-};
-
-class IWeightTransform : public ITransform
-{
- public:
- virtual ~IWeightTransform() = default;
-
- /** Set pointer to the weight tensor read by the transform. */
- virtual void set_weight_tensor(const void *weights) = 0;
-
- /**
- * Set pointers to the matrices written by the transform.
- * @param matrices Pointer to the start of the first matrix representing the transformed input.
- * @param inter_matrix_stride Stride (in elements) between matrices.
- * @param matrix_row_stride Stride (in elements) between the rows within a single matrix.
- */
- virtual void set_output_matrices(void *matrices, int inter_matrix_stride, int matrix_row_stride) = 0;
-};
-
-enum class WinogradRoots
-{
- Integers,
-};
-
-template <int InnerTileRows, int InnerTileCols, typename TIn, typename TOut, WinogradRoots Roots>
-class InputTransform : public IInputTransform
-{
- public:
- /** Create an InputTransform operator fixed on a given problem and set of
- * pointers.
- */
- InputTransform(
- int kernel_rows, /**< Number of rows in the kernel */
- int kernel_cols, /**< Number of columns in the kernel */
- int n_batches, /**< Number of batches in input tensor. */
- int n_rows, /**< Number of rows in input tensor. */
- int n_cols, /**< Number of columns in input tensor. */
- int n_channels, /**< Number of channels in input tensor. */
- int padding_top, /**< Padding to apply to the top of the image. */
- int padding_left, /**< Padding to apply to the left of the image. */
- int padding_bottom, /**< Padding to apply to the bottom of the image. */
- int padding_right /**< Padding to apply to the right of the image. */
- );
-
- InputTransform(InputTransform&) = delete;
- InputTransform operator=(InputTransform&) = delete;
-
- /** Set pointers to the input tensor read by the transform. */
- void set_input_tensor(const void *input) override;
- void set_input_tensor(const void *input, int col_stride) override;
- void set_input_tensor(const void *input, int row_stride, int col_stride) override;
- void set_input_tensor(const void *input, int batch_stride, int row_stride, int col_stride) override;
-
- /** Set pointers to the matrices written by the transform. */
- void set_output_matrices(void *matrices, int iter_matrix_stride, int matrix_row_stride) override;
-
- /** Get the working space required to perform the transformation. */
- size_t get_working_space_size(unsigned int nthreads=1) const override;
- void set_working_space(void *buffer) override;
-
- /** Get the window of work a given operator can perform. */
- unsigned int get_window() const override;
- static constexpr unsigned int WINDOW_BLOCK = 16; // Base size of window
-
- /** Perform work upon a window of the input. */
- void run(unsigned int start, unsigned int stop, unsigned int threadid=0) override;
-
- protected:
- const int _n_batches, _n_rows, _n_cols, _n_channels;
-
- private:
- void transform_unpadded_tile(
- unsigned int threadid,
- int n_channels,
- TOut *outptr,
- const TIn *inptr
- );
-
- void transform_padded_tile(
- unsigned int threadid,
- int n_channels,
- TOut *outptr,
- const TIn *inptr,
- int padding_top,
- int padding_left,
- int padding_bottom,
- int padding_right
- );
-
- /* Tile implementation */
- static void transform_tile(
- int n_channels, /** @param[in] Number of channels in the tensor. */
- const TIn* inptr_base, /** @param[in] Pointer to the base of the input tile. */
- int input_row_stride, /** @param[in] Stride between rows of the input tensor. */
- int input_col_stride, /** @param[in] Stride between columns of the input tensor. */
- TOut* mptr_base, /** @param[out] Base pointer to transformed input matrices. */
- int matrix_stride /** @param[in] Stride between matrices in the input space. */
- );
-
- /** Get the working space for a thread. */
- void * get_working_space(unsigned int threadid) const;
-
- const TIn* _inptr;
- TOut* _outptr;
-
- const int _overlap_rows, _overlap_cols;
- const int _padding_top, _padding_left, _padding_bottom, _padding_right;
- const int _tiles_M, _tiles_N;
- int _matrix_stride, _matrix_row_stride, _matrix_batch_stride;
- int _in_col_stride, _in_row_stride, _in_batch_stride;
-
- const int _working_space_col_stride, _working_space_row_stride;
- TIn *_working_space;
-};
-
-template <int InnerTileRows, typename TIn, typename TOut, WinogradRoots Roots>
-class InputTransform<InnerTileRows, 1, TIn, TOut, Roots> :
- public InputTransform<1, InnerTileRows, TIn, TOut, Roots>
-{
- using Base = InputTransform<1, InnerTileRows, TIn, TOut, Roots>;
-
- public:
- InputTransform(
- int kernel_rows, /**< Number of rows in the kernel. */
- int kernel_cols, /**< Number of columns in the kernel. */
- int n_batches, /**< Number of batches in input tensor. */
- int n_rows, /**< Number of rows in input tensor. */
- int n_cols, /**< Number of columns in input tensor. */
- int n_channels, /**< Number of channels in input tensor. */
- int padding_top, /**< Padding to apply to the top of the image. */
- int padding_left, /**< Padding to apply to the left of the image. */
- int padding_bottom, /**< Padding to apply to the bottom of the image. */
- int padding_right /**< Padding to apply to the right of the image. */
- );
-
- /** Set pointers to the input tensor read by the transform. */
- void set_input_tensor(const void *input) override;
- void set_input_tensor(const void *input, int col_stride) override;
- void set_input_tensor(const void *input, int row_stride, int col_stride) override;
- void set_input_tensor(const void *input, int batch_stride, int row_stride, int col_stride) override;
-};
-
-template <
- int KernelRows, int KernelCols,
- int InnerTileRows, int InnerTileCols,
- typename TIn, typename TOut,
- WinogradRoots Roots
->
-class OutputTransform : public IOutputTransform
-{
- public:
- OutputTransform(
- int n_batches, /**< Number of batches in output tensor. */
- int n_rows, /**< Number of rows in output tensor. */
- int n_cols, /**< Number of columns in output tensor. */
- int n_channels, /**< Number of channels in output tensor. */
- const arm_gemm::Activation &activation
- );
-
- OutputTransform(OutputTransform&) = delete;
- OutputTransform operator=(OutputTransform&) = delete;
-
- /** Set pointers to the matrices read by the transform. */
- void set_input_matrices(const void *matrices, int iter_matrix_stride, int matrix_row_stride) override;
-
- /** Set pointer to the bias tensor (can be ignored or called with nullptr for no bias */
- void set_bias(const void *bias=nullptr) override;
-
- /** Set pointers to the output tensor written by the transform. */
- void set_output_tensor(void *output) override;
- void set_output_tensor(void *output, int col_stride) override;
- void set_output_tensor(void *output, int row_stride, int col_stride) override;
- void set_output_tensor(void *output, int batch_stride, int row_stride, int col_stride) override;
-
- /** Get the working space required to perform the transformation. */
- size_t get_working_space_size(unsigned int nthreads=1) const override;
- void set_working_space(void *buffer) override;
-
- /** Get the window of work a given operator can perform. */
- unsigned int get_window() const override;
- static constexpr unsigned int WINDOW_BLOCK = 16; // Base size of window
-
- /** Perform work upon a window of the input. */
- void run(unsigned int start, unsigned int stop, unsigned int threadid=0) override;
-
- protected:
- static constexpr int inner_tile_rows = InnerTileRows;
- static constexpr int inner_tile_cols = InnerTileCols;
- static constexpr int output_tile_rows = InnerTileRows - KernelRows + 1;
- static constexpr int output_tile_cols = InnerTileCols - KernelCols + 1;
-
- const int _n_batches, _n_rows, _n_cols, _n_channels;
- const TOut _output_min, _output_max;
-
- private:
- void transform_uncropped_tile(
- unsigned int threadid,
- int n_channels,
- TOut *outptr,
- const TIn *inptr,
- const TOut *biases
- );
-
- void transform_cropped_tile(
- unsigned int threadid,
- int n_channels,
- TOut *outptr,
- const TIn *inptr,
- const TOut *biases,
- int pad_bottom,
- int pad_right
- );
-
- /** Implementation of the tile transformation method. */
- static void transform_tile(
- int n_channels,
- const TIn* matrix_base,
- int matrix_stride,
- const TOut* biases,
- TOut* output,
- int output_row_stride,
- int output_col_stride,
- TOut output_min,
- TOut output_max
- );
-
- /** Get the working space for a thread. */
- void * get_working_space(unsigned int threadid) const;
-
- const TIn* _matrix_base;
- const TOut* _biases;
- int _matrix_stride, _matrix_row_stride, _matrix_batch_stride;
- TOut* _outptr;
- const int _tiles_M, _tiles_N;
- int _out_col_stride, _out_row_stride, _out_batch_stride;
-
- const int _working_space_col_stride, _working_space_row_stride;
- TOut *_working_space;
-};
-
-template <
- int KernelRows,
- int InnerTileRows,
- typename TIn, typename TOut,
- WinogradRoots Roots
->
-class OutputTransform<KernelRows, 1, InnerTileRows, 1, TIn, TOut, Roots> :
- public OutputTransform<1, KernelRows, 1, InnerTileRows, TIn, TOut, Roots>
-{
- using Base = OutputTransform<1, KernelRows, 1, InnerTileRows, TIn, TOut, Roots>;
-
- public:
- OutputTransform(
- int n_batches, /**< Number of batches in output tensor. */
- int n_rows, /**< Number of rows in output tensor. */
- int n_cols, /**< Number of columns in output tensor. */
- int n_channels, /**< Number of channels in output tensor. */
- const arm_gemm::Activation &activation
- );
-
- /** Set pointers to the output tensor written by the transform. */
- void set_output_tensor(void *output) override;
- void set_output_tensor(void *output, int col_stride) override;
- void set_output_tensor(void *output, int row_stride, int col_stride) override;
- void set_output_tensor(void *output, int batch_stride, int row_stride, int col_stride) override;
-};
-
-template <
- int KernelRows, int KernelCols,
- int InnerTileRows, int InnerTileCols,
- typename TIn, typename TOut,
- WinogradRoots Roots
->
-class WeightTransform : public IWeightTransform
-{
- public:
- WeightTransform(
- int n_output_channels, /**< Number of output channels in the kernel. */
- int n_input_channels /**< Number of input channels in the kernel. */
- );
-
- WeightTransform(WeightTransform&) = delete;
- WeightTransform operator=(WeightTransform&) = delete;
-
- /** Set pointer to the weight tensor read by the transform. */
- void set_weight_tensor(const void *weights) override;
-
- /** Set pointer to the matrices written by the transform. */
- void set_output_matrices(void *matrices, int inter_matrix_stride, int matrix_row_stride) override;
-
- /** Get the working space required to perform the transformation. */
- size_t get_working_space_size(unsigned int nthreads=1) const override;
- void set_working_space(void *buffer) override;
-
- /** Get the window of work a given operator can perform. */
- unsigned int get_window() const override;
- static constexpr unsigned int WINDOW_BLOCK = 16; // Base size of window
-
- /** Perform work upon a window of the input. */
- void run(unsigned int start, unsigned int stop, unsigned int threadid=0) override;
-
- protected:
- static const int kernel_rows = KernelRows;
- static const int kernel_cols = KernelCols;
- static const int inner_tile_rows = InnerTileRows;
- static const int inner_tile_cols = InnerTileCols;
-
- private:
- /** Apply the transform to a tensor. */
- static void execute(
- int n_output_channels,
- int n_input_channels,
- const TIn* input,
- TOut* output,
- int matrix_stride,
- int matrix_row_stride
- );
-
- const int _n_output_channels, _n_input_channels;
- TOut *_matrices;
- int _matrix_stride, _matrix_row_stride;
- const TIn *_weights;
-};
-
-template <int KernelRows, int InnerTileRows, typename TIn, typename TOut, WinogradRoots Roots>
-class WeightTransform<KernelRows, 1, InnerTileRows, 1, TIn, TOut, Roots> :
- public WeightTransform<1, KernelRows, 1, InnerTileRows, TIn, TOut, Roots>
-{
- public:
- using WeightTransform<1, KernelRows, 1, InnerTileRows, TIn, TOut, Roots>::WeightTransform;
-};
-
-template <int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols, WinogradRoots Roots>
-class WinogradGEMM
-{
- public:
- // Information about the specific Winograd instance
- static constexpr int output_tile_rows = OutputTileRows;
- static constexpr int output_tile_cols = OutputTileCols;
- static constexpr int kernel_rows = KernelRows;
- static constexpr int kernel_cols = KernelCols;
- static constexpr int inner_tile_rows = output_tile_rows + kernel_rows - 1;
- static constexpr int inner_tile_cols = output_tile_cols + kernel_cols - 1;
- static constexpr int N_GEMMS = inner_tile_rows * inner_tile_cols;
-
- /** Transform weights from the spatial to the Winograd domain. */
- template <typename TIn, typename TOut>
- using WeightsTransform = WeightTransform<
- KernelRows, KernelCols, inner_tile_rows, inner_tile_cols,
- TIn, TOut, Roots
- >;
-
- /** Transform input feature maps from the spatial to the Winograd domain.
- */
- template <typename TIn, typename TOut>
- using InputTransform = InputTransform<
- inner_tile_rows, inner_tile_cols, TIn, TOut, Roots
- >;
-
- /** Transform output feature maps from the Winograd to the spatial domain.
- */
- template <typename TIn, typename TOut>
- using OutputTransform = OutputTransform<
- KernelRows, KernelCols, inner_tile_rows, inner_tile_cols,
- TIn, TOut, Roots
- >;
-
- /** Perform a convolution.
- */
- template <typename TOut, typename TIn, typename TInGEMM=TIn, typename TOutGEMM=TOut>
- class Convolution
- {
- public:
- // Information about the typed Winograd instance
- typedef TOut OutputType;
- typedef TOutGEMM GemmOutputType;
- typedef TInGEMM GemmInputType;
- typedef TIn InputType;
-
- /** Get the output shape of a convolution. */
- static std::pair<unsigned int, unsigned int> get_output_shape(
- const std::pair<unsigned int, unsigned int> input_shape,
- bool padding_same);
-
- /** Get the memory required to store the kernel transformed into the
- * Winograd domain.
- */
- static size_t get_kernel_storage_size(unsigned int n_input_channels,
- unsigned int n_output_channels);
-
- /** Get the memory required to store the input tensor transformed into
- * the Winograd domain.
- */
- static size_t get_input_storage_size(
- unsigned int n_batches, // Number of batches
- unsigned int n_rows, // Number of input rows
- unsigned int n_cols, // Number of input columns
- unsigned int n_channels, // Number of input channels
- bool padding_same);
-
- /** Get the memory required to store the output tensor in the Winograd
- * domain.
- */
- static size_t get_output_storage_size(
- unsigned int n_batches, // Number of batches
- unsigned int n_rows, // Number of output rows
- unsigned int n_cols, // Number of output columns
- unsigned int n_channels // Number of output channels
- );
-
- /** Get the memory required to apply a Winograd operator to some input.
- */
- static size_t get_working_space_size(
- unsigned int n_batches,
- unsigned int n_rows, // Number of input rows
- unsigned int n_cols, // Number of input columns
- unsigned int n_input_channels, // Number of input channels
- unsigned int n_output_channels, // Number of output channels
- bool padding_same);
-
- /* Get the memory required by a single "input" matrix.
- */
- static size_t get_input_matrix_size(
- unsigned int n_batches, // Number of batches
- unsigned int n_rows, // Number of input rows
- unsigned int n_cols, // Number of input columns
- unsigned int n_channels, // Number of input channels
- bool padding_same);
-
- static int get_input_matrix_stride(
- unsigned int n_batches, // Number of batches
- unsigned int n_rows, // Number of input rows
- unsigned int n_cols, // Number of input columns
- unsigned int n_channels, // Number of input channels
- bool padding_same);
-
- /* Get the memory required by a single "output" matrix.
- */
- static size_t get_output_matrix_size(
- unsigned int n_batches, // Number of batches
- unsigned int n_rows, // Number of output rows
- unsigned int n_cols, // Number of output columns
- unsigned int n_channels // Number of output channels
- );
-
- static int get_output_matrix_stride(
- unsigned int n_batches, // Number of batches
- unsigned int n_rows, // Number of output rows
- unsigned int n_cols, // Number of output columns
- unsigned int n_channels // Number of output channels
- );
-
- /* Get the memory required by a single "kernel" matrix.
- */
- static size_t get_kernel_matrix_size(unsigned int n_input_channels,
- unsigned int n_output_channels);
- static int get_kernel_matrix_stride(unsigned int n_input_channels,
- unsigned int n_output_channels);
-
- static constexpr int M_BLOCK = 4; /** Size of block used by GEMM. */
- static constexpr int N_BLOCK = 16; /** Size of block used by GEMM. */
- };
-};
-
-} // namespace winograd
diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_fp16.cpp b/src/core/NEON/kernels/convolution/winograd/winograd_fp16.cpp
new file mode 100644
index 0000000000..e1ad9e458d
--- /dev/null
+++ b/src/core/NEON/kernels/convolution/winograd/winograd_fp16.cpp
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2022 Arm Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#if defined(__aarch64__) && defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
+
+#include "winograd_implementations.hpp"
+
+namespace arm_conv {
+namespace winograd {
+
+template bool get_implementation<__fp16>(
+ WinogradImpl &,
+ const CPUInfo *,
+ const ConvolutionArgs &,
+ int max_threads,
+ bool fast_mode,
+ const WinogradConfig *,
+ const arm_gemm::GemmConfig *
+);
+
+} // namespace winograd
+} // namespace arm_conv
+
+#endif // defined(__aarch64__) && defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_fp32.cpp b/src/core/NEON/kernels/convolution/winograd/winograd_fp32.cpp
new file mode 100644
index 0000000000..b92de1dde7
--- /dev/null
+++ b/src/core/NEON/kernels/convolution/winograd/winograd_fp32.cpp
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2022 Arm Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include "winograd_implementations.hpp"
+
+namespace arm_conv {
+namespace winograd {
+
+template bool get_implementation<float>(
+ WinogradImpl &,
+ const CPUInfo *,
+ const ConvolutionArgs &,
+ int max_threads,
+ bool fast_mode,
+ const WinogradConfig *,
+ const arm_gemm::GemmConfig *
+);
+
+} // namespace winograd
+} // namespace arm_conv
diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_implementations.hpp b/src/core/NEON/kernels/convolution/winograd/winograd_implementations.hpp
new file mode 100644
index 0000000000..a23cb1d6b3
--- /dev/null
+++ b/src/core/NEON/kernels/convolution/winograd/winograd_implementations.hpp
@@ -0,0 +1,332 @@
+/*
+ * Copyright (c) 2022 Arm Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#pragma once
+
+#include "src/core/NEON/kernels/assembly/winograd.hpp"
+#include <memory>
+#include <string>
+
+namespace arm_conv {
+namespace winograd {
+
+enum class MethodConstraints
+{
+ None,
+ RequiresSVE = 0x1,
+ RequiresSVE2 = 0x2,
+ RequiresSME = 0x4,
+ RequiresSME2 = 0x8,
+};
+
+constexpr inline bool operator!(const MethodConstraints &c)
+{
+ return c == MethodConstraints::None;
+}
+
+constexpr inline MethodConstraints operator|(const MethodConstraints &a, const MethodConstraints &b)
+{
+ return static_cast<MethodConstraints>(static_cast<unsigned int>(a) | static_cast<unsigned int>(b));
+}
+
+constexpr inline MethodConstraints operator&(const MethodConstraints &a, const MethodConstraints &b)
+{
+ return static_cast<MethodConstraints>(static_cast<unsigned int>(a) & static_cast<unsigned int>(b));
+}
+
+inline bool constraints_met(const MethodConstraints &c, const CPUInfo *ci, const ConvolutionArgs &, const WinogradConfig *)
+{
+ return (
+ (!(c & MethodConstraints::RequiresSVE) || (ci->has_sve())) &&
+ (!(c & MethodConstraints::RequiresSVE2) || (ci->has_sve2())) &&
+ (!(c & MethodConstraints::RequiresSME) || (ci->has_sme())) &&
+ (!(c & MethodConstraints::RequiresSME2) || (ci->has_sme2()))
+ // Add further constraints here
+ );
+}
+
+namespace weight_transform {
+
+template <typename TIn, typename TOut=TIn>
+struct TransformImplementation
+{
+ std::unique_ptr<const ITransform> transform;
+ MethodConstraints constraints;
+
+ TransformImplementation(const ITransform *transform, const MethodConstraints &constraints = MethodConstraints::None)
+ : transform(transform), constraints(constraints)
+ {
+ }
+};
+
+template <typename TIn, typename TOut=TIn>
+const TransformImplementation<TIn, TOut> *implementation_list(void);
+
+} // namespace weight_transform
+
+namespace input_transform
+{
+
+template <typename TIn, typename TOut=TIn>
+struct TransformImplementation
+{
+ std::unique_ptr<const ITransform> transform;
+ MethodConstraints constraints;
+
+ TransformImplementation(const ITransform *transform, const MethodConstraints &constraints = MethodConstraints::None)
+ : transform(transform), constraints(constraints)
+ {
+ }
+};
+
+template <typename TIn, typename TOut=TIn>
+const TransformImplementation<TIn, TOut> *implementation_list(void);
+
+} // namespace input_transform
+
+namespace output_transform
+{
+
+template <typename TIn, typename TOut=TIn>
+struct TransformImplementation
+{
+ std::unique_ptr<const ITransform> transform;
+ MethodConstraints constraints;
+
+ TransformImplementation(const ITransform *transform, const MethodConstraints &constraints = MethodConstraints::None)
+ : transform(transform), constraints(constraints)
+ {
+ }
+};
+
+template <typename TIn, typename TOut=TIn>
+const TransformImplementation<TIn, TOut> *implementation_list(void);
+
+} // namespace output_transform
+
+namespace{
+
+template <typename T>
+constexpr T iceildiv(T num, T den)
+{
+ return (num + den - 1) / den;
+}
+
+template <typename T>
+constexpr T iroundup(T num, T den)
+{
+ return den * iceildiv(num, den);
+}
+
+}
+
+template <typename TWeight, typename TWinogradIn>
+inline std::vector<const weight_transform::ITransform *> get_weight_transforms(
+ const CPUInfo *ci, const ConvolutionArgs &conv_args, const WinogradConfig *cfg
+)
+{
+ // Get target inner tile size
+ const auto target_inner_tile_rows = cfg->output_rows == 0 ? 0 : (conv_args.kernel_shape.rows + cfg->output_rows - 1);
+ const auto target_inner_tile_cols = cfg->output_cols == 0 ? 0 : (conv_args.kernel_shape.cols + cfg->output_cols - 1);
+
+ std::vector<const weight_transform::ITransform *> weight_transforms;
+ for (auto impl = weight_transform::implementation_list<TWeight, TWinogradIn>();
+ impl->transform.get() != nullptr; impl++)
+ {
+ // If this transform supports the requested kernel size, then add it to the
+ // list of weight transforms.
+ if (
+ constraints_met(impl->constraints, ci, conv_args, cfg) &&
+ impl->transform->get_kernel_rows() == conv_args.kernel_shape.rows &&
+ impl->transform->get_kernel_cols() == conv_args.kernel_shape.cols &&
+ (target_inner_tile_rows == 0 || target_inner_tile_rows == impl->transform->get_transformed_tile_rows()) &&
+ (target_inner_tile_cols == 0 || target_inner_tile_cols == impl->transform->get_transformed_tile_cols()) &&
+ (cfg->weight_transform_filter == "" || std::strstr(impl->transform->get_name().c_str(), cfg->weight_transform_filter.c_str()))
+ )
+ {
+ weight_transforms.push_back(impl->transform.get());
+ }
+ }
+
+ return weight_transforms;
+}
+
+template <typename TIn, typename TWinogradIn>
+inline std::vector<const input_transform::ITransform *> get_input_transforms(
+ const CPUInfo *ci, const ConvolutionArgs &conv_args, const WinogradConfig *cfg
+)
+{
+ // Get target inner tile size
+ const auto target_inner_tile_rows = cfg->output_rows == 0 ? 0 : (conv_args.kernel_shape.rows + cfg->output_rows - 1);
+ const auto target_inner_tile_cols = cfg->output_cols == 0 ? 0 : (conv_args.kernel_shape.cols + cfg->output_cols - 1);
+
+ std::vector<const input_transform::ITransform *> input_transforms;
+ for (auto impl = input_transform::implementation_list<TIn, TWinogradIn>();
+ impl->transform.get() != nullptr; impl++)
+ {
+ if(
+ constraints_met(impl->constraints, ci, conv_args, cfg) &&
+ (target_inner_tile_rows == 0 || target_inner_tile_rows == impl->transform->get_input_rows()) &&
+ (target_inner_tile_cols == 0 || target_inner_tile_cols == impl->transform->get_input_cols()) &&
+ (cfg->input_transform_filter == "" || std::strstr(impl->transform->get_name().c_str(), cfg->input_transform_filter.c_str()))
+ )
+ {
+ input_transforms.push_back(impl->transform.get());
+ }
+ }
+
+ return input_transforms;
+}
+
+template <typename TWinogradOut, typename TOut>
+inline std::vector<const output_transform::ITransform *> get_output_transforms(
+ const CPUInfo *ci, const ConvolutionArgs &conv_args, const WinogradConfig *cfg
+)
+{
+ std::vector<const output_transform::ITransform *> output_transforms;
+ for (auto impl = output_transform::implementation_list<TWinogradOut, TOut>();
+ impl->transform.get() != nullptr; impl++)
+ {
+ if(
+ constraints_met(impl->constraints, ci, conv_args, cfg) &&
+ impl->transform->get_kernel_rows() == conv_args.kernel_shape.rows &&
+ impl->transform->get_kernel_cols() == conv_args.kernel_shape.cols &&
+ (cfg->output_rows == 0 || cfg->output_rows == impl->transform->get_output_rows()) &&
+ (cfg->output_cols == 0 || cfg->output_cols == impl->transform->get_output_cols()) &&
+ (cfg->output_transform_filter == "" || std::strstr(impl->transform->get_name().c_str(), cfg->output_transform_filter.c_str()))
+ )
+ {
+ output_transforms.push_back(impl->transform.get());
+ }
+ }
+
+ return output_transforms;
+}
+
+template <typename TIn, typename TWeight, typename TOut, typename TWinogradIn, typename TWinogradOut>
+bool get_implementation(
+ WinogradImpl &dest, // Destination for the selected implementation
+ const CPUInfo *ci,
+ const ConvolutionArgs &conv_args,
+ int max_threads,
+ bool fast_mode,
+ const WinogradConfig *cfg,
+ const arm_gemm::GemmConfig *gemm_cfg
+)
+{
+ // Get vectors of valid weight, input and output transforms; then select the
+ // combination which produces the biggest output tile.
+ const auto weight_transforms = get_weight_transforms<TWeight, TWinogradIn>(ci, conv_args, cfg);
+ const auto input_transforms = get_input_transforms<TIn, TWinogradIn>(ci, conv_args, cfg);
+ const auto output_transforms = get_output_transforms<TWinogradOut, TOut>(ci, conv_args, cfg);
+
+ // Now attempt to select a complete set of Winograd transformations which can
+ // solve the problem. Work backwards from the output transform to find
+ // matching input implementations.
+ bool success = false;
+ for (auto output_transform = output_transforms.cbegin();
+ !success && output_transform != output_transforms.cend();
+ output_transform++)
+ {
+ // Look for matching weight transforms, if we find one then we look for
+ // matching input transforms.
+ for (auto weight_transform = weight_transforms.cbegin();
+ !success && weight_transform != weight_transforms.cend();
+ weight_transform++)
+ {
+ // If this weight transform is compatible, then look for a matching input
+ // transform
+ if ((*output_transform)->get_input_rows() == (*weight_transform)->get_transformed_tile_rows() &&
+ (*output_transform)->get_input_cols() == (*weight_transform)->get_transformed_tile_cols())
+ {
+ for (auto input_transform = input_transforms.cbegin();
+ !success && input_transform != input_transforms.cend();
+ input_transform++)
+ {
+ // If the input transform is suitable, then set the configuration and
+ // indicate success.
+ if ((*input_transform)->get_input_rows() == (*output_transform)->get_input_rows() &&
+ (*input_transform)->get_input_cols() == (*output_transform)->get_input_cols())
+ {
+ dest.output_transform = *output_transform;
+ dest.input_transform = *input_transform;
+ dest.weight_transform = *weight_transform;
+ success = true;
+ }
+ }
+ }
+ }
+ }
+
+ if (!success)
+ {
+ return false;
+ }
+
+ // If we're able to construct the Winograd elements, then specify the GEMM
+ // arguments required to perform the multiply-accumulate step of the
+ // convolution.
+ const auto n_output_row_tiles = iceildiv(conv_args.output_shape.rows, dest.output_transform->get_output_rows());
+ const auto n_output_col_tiles = iceildiv(conv_args.output_shape.cols, dest.output_transform->get_output_cols());
+ const auto n_output_patches = n_output_row_tiles * n_output_col_tiles;
+
+ const int n_multis = dest.input_transform->get_input_rows() *
+ dest.input_transform->get_input_cols();
+
+ dest.gemm_args.reset(new arm_gemm::GemmArgs(
+ ci,
+ n_output_patches, // M
+ conv_args.n_output_channels, // N
+ conv_args.n_input_channels, // K
+ 1, // K-sections
+ conv_args.n_batches, // # Batches
+ n_multis,
+ false, // Indirect input
+ {}, // No activation
+ max_threads,
+ fast_mode,
+ gemm_cfg
+ ));
+
+ // Also provide hints for the Winograd memory layout
+ auto &ws = dest.winograd_spec;
+ ws.weight_ld_row = iroundup(conv_args.n_output_channels, 4u);
+ ws.weight_ld_matrix = conv_args.n_input_channels * ws.weight_ld_row;
+ ws.weight_matrix_size_bytes = n_multis * ws.weight_ld_matrix * sizeof(TWinogradIn);
+
+ ws.input_ld_row = iroundup(conv_args.n_input_channels, 4u);
+ ws.input_ld_matrix = iroundup(n_output_patches, 4u) * ws.input_ld_row;
+ ws.input_ld_batch = n_multis * ws.input_ld_matrix;
+ ws.input_matrix_size_bytes = conv_args.n_batches * ws.input_ld_batch * sizeof(TWinogradIn);
+
+ ws.output_ld_row = ws.weight_ld_row;
+ ws.output_ld_matrix = n_output_patches * ws.output_ld_row;
+ ws.output_ld_batch = n_multis * ws.output_ld_matrix;
+ ws.output_matrix_size_bytes = conv_args.n_batches * ws.output_ld_batch * sizeof(TWinogradOut);
+
+ return true;
+}
+
+} // namespace winograd
+} // namespace arm_conv
diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_layer.hpp b/src/core/NEON/kernels/convolution/winograd/winograd_layer.hpp
deleted file mode 100644
index 52ff7b3798..0000000000
--- a/src/core/NEON/kernels/convolution/winograd/winograd_layer.hpp
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- * Copyright (c) 2017-2019 Arm Limited.
- *
- * SPDX-License-Identifier: MIT
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#pragma once
-#include "arm_gemm_local.hpp"
-#include "arm_gemm.hpp"
-#include "winograd.hpp"
-
-namespace winograd
-{
-
-
-class IWinogradConvolutionLayer
-{
- public:
- virtual ~IWinogradConvolutionLayer() = default;
-
- virtual unsigned int weight_transform_get_window(void) const = 0;
- virtual void weight_transform_run(unsigned int start, unsigned int stop) = 0;
-
- virtual IInputTransform& input_transform(void) = 0; // Expose the input transform
- virtual IOutputTransform& output_transform(void) = 0; // Expose the output transform
- virtual arm_gemm::IGemmCommon *gemm(void) = 0; // Expose the underlying GEMM
-};
-
-/** Example of how to construct an ACL-like interface.
- *
- * Use `get_weight_storage_size`, `get_input_storage_size` and
- * `get_output_storage_size` to allocate memory for the convolution engine.
- * Then create a `WinogradConvolutionLayer`.
- *
- * Initialise the weights using `weights_transform.run(...)`.
- *
- * For each inference:
- * 1. Transform the inputs to the Winograd domain using `input_transform.run(...)`
- * 2. Perform a number of GEMMs using `gemms.run(...)`
- * 3. Transform the output to the spatial domain using `output_transform.run(...)`
- */
-template <int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols,
- typename TIn, typename TInGEMM, typename TOutGEMM, typename TOut,
- WinogradRoots Roots>
-class WinogradConvolutionLayer : public IWinogradConvolutionLayer
-{
- public:
- using WinogradBase = winograd::WinogradGEMM<OutputTileRows, OutputTileCols, KernelRows, KernelCols, Roots>;
- using WeightsTransform = typename WinogradBase::template WeightsTransform<TIn, TInGEMM>;
- using InputTransform = typename WinogradBase::template InputTransform<TIn, TInGEMM>;
- using WinogradConv = typename WinogradBase::template Convolution<TOut, TIn, TInGEMM, TOutGEMM>;
- using OutputTransform = typename WinogradBase::template OutputTransform<TOutGEMM, TOut>;
-
- private:
- static constexpr int InnerTileRows = OutputTileRows + KernelRows - 1;
- static constexpr int InnerTileCols = OutputTileCols + KernelCols - 1;
- static constexpr int N_GEMMS = InnerTileRows * InnerTileCols;
-
- const int _n_output_rows, _n_output_cols;
- const int _kernel_matrix_stride, _kernel_matrix_row_stride;
- const int _input_matrix_stride, _input_matrix_row_stride;
- const int _output_matrix_stride, _output_matrix_row_stride;
- const int _tile_rows, _tile_cols;
- const int _m, _k, _n;
-
- WeightsTransform weights_transform; /** Operator to transform weights to Winograd domain. */
- InputTransform _input_transform; /** Operator to transform input to Winograd domain. */
- const arm_gemm::GemmArgs gemm_args;
- arm_gemm::UniqueGemmCommon<TInGEMM, TOutGEMM> gemms; /** Operator to perform multiple GEMMs. */
- OutputTransform _output_transform; /** Operator to transform output from Winograd domain. */
-
- public:
-
- /** Determine how much memory (in units of TIn) to allocate for the
- * transformed weights.
- */
- static unsigned int get_weight_storage_size(
- const int n_output_channels, /** Number of output feature maps. */
- const int n_input_channels /** Number of input feature maps. */
- );
-
- static unsigned int get_weight_stride(
- const int n_output_channels, /** Number of output feature maps. */
- const int n_input_channels /** Number of input feature maps. */
- );
-
- static unsigned int get_weight_multi_stride(
- const int n_output_channels, /** Number of output feature maps. */
- const int n_input_channels /** Number of input feature maps. */
- );
-
- /** Determine how much memory (in units of TIn) to allocate for the
- * transformed input.
- */
- static unsigned int get_input_storage_size(
- const int n_batches, /** Number of batches in the input tensor. */
- const int n_channels, /** Number of feature maps in the input tensor. */
- const int n_rows, /** Number of rows in each feature map. */
- const int n_cols, /** Number of columns in each feature map. */
- const bool same_padding /** Use "SAME" padding, otherwise use "VALID". */
- );
-
- /** Get the row stride for the A matrix in the Winograd domain. */
- static unsigned int get_input_stride(
- const int n_batches, /** Number of batches in the input tensor. */
- const int n_channels, /** Number of feature maps in the input tensor. */
- const int n_rows, /** Number of rows in each feature map. */
- const int n_cols, /** Number of columns in each feature map. */
- const bool same_padding /** Use "SAME" padding, otherwise use "VALID". */
- );
-
- /** Get the stride between A matrices in the Winograd domain. */
- static unsigned int get_input_multi_stride(
- const int n_batches, /** Number of batches in the input tensor. */
- const int n_channels, /** Number of feature maps in the input tensor. */
- const int n_rows, /** Number of rows in each feature map. */
- const int n_cols, /** Number of columns in each feature map. */
- const bool same_padding /** Use "SAME" padding, otherwise use "VALID". */
- );
-
- /** Determine how much memory (in units of TOut) to allocate for the
- * (Winograd domain) output.
- */
- static unsigned int get_output_storage_size(
- const int n_batches, /** Number of batches in the output tensor. */
- const int n_rows, /** Number of rows in each feature map of the input tensor. */
- const int n_cols, /** Number of columns in each feature map of the input tensor. */
- const int n_output_channels, /** Number of feature maps in the output tensor. */
- const bool same_padding /** Use "SAME" padding, otherwise use "VALID". */
- );
-
- static unsigned int get_output_stride(
- const int n_batches, /** Number of batches in the output tensor. */
- const int n_rows, /** Number of rows in each feature map of the input tensor. */
- const int n_cols, /** Number of columns in each feature map of the input tensor. */
- const int n_output_channels, /** Number of feature maps in the output tensor. */
- const bool same_padding /** Use "SAME" padding, otherwise use "VALID". */
- );
-
- static unsigned int get_output_multi_stride(
- const int n_batches, /** Number of batches in the output tensor. */
- const int n_rows, /** Number of rows in each feature map of the input tensor. */
- const int n_cols, /** Number of columns in each feature map of the input tensor. */
- const int n_output_channels, /** Number of feature maps in the output tensor. */
- const bool same_padding /** Use "SAME" padding, otherwise use "VALID". */
- );
-
- /** Get the shape (rows, cols) of a feature map of the output tensor. */
- static std::pair<int, int> get_output_feature_map_shape(
- const int n_input_rows, /** Number of rows in the input feature map. */
- const int n_input_cols, /** Number of columns in the input feature map. */
- const bool same_padding /** Use "SAME" padding, otherwise use "VALID". */
- );
-
- /** Create a new Winograd convolution layer.
- */
- WinogradConvolutionLayer(
- const CPUInfo &cpuinfo, /** Describes CPU properties. */
- const int n_threads, /** Maximum number of threads used to execute the convolution. */
- const int n_batches, /** Number of batches in the input and output tensors. */
- const int n_input_channels, /** Number of feature maps in a batch of the input tensor. */
- const int n_input_rows, /** Number of rows in a feature map of the input tensor. */
- const int n_input_cols, /** Number of columns in a feature map of the input tensor. */
- const int n_output_channels, /** Number of feature maps in the output tensor. */
- const bool same_padding, /** Use "SAME" padding, otherwise use "VALID". */
- const arm_gemm::Activation &activation,
- const TIn* const weights, /** Pointer to weight tensor in spatial domain. Must be ordered as "Height x Rows x Input Feature Maps x Output Feature Maps. */
- TInGEMM* const weights_storage, /** Pointer to storage for weight tensor in the Winograd domain. Must be at least the size returned by `get_weight_storage_size`. */
- const TIn* const input, /** Pointer to NHWC ordered input tensor, in the spatial domain. */
- TInGEMM* const winograd_input, /** Pointer to working space for the input tensor in the Winograd domain. Must be at least the size returned by `get_input_storage_size`. */
- const TOut* const biases, /** Pointer to biases vector. Pass nullptr if no bias is provided. */
- TOut* const output, /** Pointer to NHWC ordered output tensor, in the spatial domain. */
- TOutGEMM* const winograd_output, /** Pointer to working space for the output tensor in the Winograd domain. Must be at least the size returned by `get_output_storage_size`. */
- const bool pretranspose_B=true, /** Hint that the B matrix can be pretransposed. */
- arm_gemm::GemmConfig *gemm_cfg=nullptr /** Pointer to GEMM configuration. */
- );
-
- /* Utility methods for interacting with the layer. */
- unsigned int weight_transform_get_window(void) const;
- void weight_transform_run(const unsigned int start, const unsigned int stop);
-
- IInputTransform& input_transform(void);
- IOutputTransform& output_transform(void);
-
- /* Get a pointer to the GEMM underlying the Winograd transform. */
- arm_gemm::IGemmCommon *gemm(void);
-};
-
-}
diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/input.hpp b/src/core/NEON/kernels/convolution/winograd/winograd_transforms/input.hpp
deleted file mode 100644
index c0f50beb2c..0000000000
--- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/input.hpp
+++ /dev/null
@@ -1,268 +0,0 @@
-/*
- * Copyright (c) 2017-2019 Arm Limited.
- *
- * SPDX-License-Identifier: MIT
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#pragma once
-
-#include <algorithm>
-
-#include "padding.hpp"
-#include "utils.hpp"
-#include "winograd.hpp"
-
-#define MEMBERFN(RTYPE) template <\
- int InnerTileRows, int InnerTileCols,\
- typename TIn, typename TOut, WinogradRoots Roots\
-> RTYPE InputTransform<InnerTileRows, InnerTileCols, TIn, TOut, Roots>
-
-
-#define Nx1MEMBERFN(RTYPE) template <\
- int InnerTileRows, typename TIn, typename TOut, WinogradRoots Roots\
-> RTYPE InputTransform<InnerTileRows, 1, TIn, TOut, Roots>
-
-namespace winograd
-{
-
-MEMBERFN()::InputTransform(
- const int kernel_rows,
- const int kernel_cols,
- const int n_batches,
- const int n_rows,
- const int n_cols,
- const int n_channels,
- const int padding_top,
- const int padding_left,
- const int padding_bottom,
- const int padding_right
-) : _n_batches(n_batches), _n_rows(n_rows), _n_cols(n_cols), _n_channels(n_channels),
- _inptr(nullptr), _outptr(nullptr),
- _overlap_rows(kernel_rows - 1), _overlap_cols(kernel_cols - 1),
- _padding_top(padding_top), _padding_left(padding_left), _padding_bottom(padding_bottom), _padding_right(padding_right),
- _tiles_M(iceildiv(padding_top + n_rows + padding_bottom - kernel_rows + 1, InnerTileRows - kernel_rows + 1)),
- _tiles_N(iceildiv(padding_left + n_cols + padding_right - kernel_cols + 1, InnerTileCols - kernel_cols + 1)),
- _matrix_stride(0), _matrix_row_stride(0), _matrix_batch_stride(0),
- _in_col_stride(0), _in_row_stride(0), _in_batch_stride(0),
- _working_space_col_stride(n_channels),
- _working_space_row_stride(InnerTileCols * _working_space_col_stride),
- _working_space(nullptr)
-{
-}
-
-MEMBERFN(void)::set_input_tensor(const void* const inptr)
-{
- set_input_tensor(inptr, _n_channels);
-}
-
-MEMBERFN(void)::set_input_tensor(const void* const inptr, const int ldcol)
-{
- set_input_tensor(inptr, _n_cols * ldcol, ldcol);
-}
-
-MEMBERFN(void)::set_input_tensor(const void* const inptr, const int ldrow, const int ldcol)
-{
- set_input_tensor(inptr, _n_rows * ldrow, ldrow, ldcol);
-}
-
-MEMBERFN(void)::set_input_tensor(const void* const inptr, const int ldbatch, const int ldrow, const int ldcol)
-{
- _inptr = static_cast<const TIn *>(inptr);
- _in_batch_stride = ldbatch;
- _in_row_stride = ldrow;
- _in_col_stride = ldcol;
-}
-
-MEMBERFN(void)::set_output_matrices(void * const mptr, const int ldmatrix, const int ldrow)
-{
- _outptr = static_cast<TOut *>(mptr);
- _matrix_stride = ldmatrix;
- _matrix_row_stride = ldrow;
- _matrix_batch_stride = _tiles_M * _tiles_N * ldrow;
-}
-
-Nx1MEMBERFN()::InputTransform(
- const int kernel_rows,
- const int kernel_cols,
- const int n_batches,
- const int n_rows,
- const int n_cols,
- const int n_channels,
- const int padding_top,
- const int padding_left,
- const int padding_bottom,
- const int padding_right
-) : InputTransform<1, InnerTileRows, TIn, TOut, Roots>::InputTransform(
- /* Transpose rows and columns */
- kernel_cols, kernel_rows, n_batches, n_cols, n_rows, n_channels,
- padding_left, padding_top, padding_right, padding_bottom
- )
-{
-}
-
-Nx1MEMBERFN(void)::set_input_tensor(const void* const inptr)
-{
- set_input_tensor(inptr, this->_n_channels);
-}
-
-Nx1MEMBERFN(void)::set_input_tensor(const void* const inptr, const int ldcol)
-{
- set_input_tensor(inptr, this->_n_cols * ldcol, ldcol);
-}
-
-Nx1MEMBERFN(void)::set_input_tensor(const void* const inptr, const int ldrow, const int ldcol)
-{
- set_input_tensor(inptr, this->_n_rows * ldrow, ldrow, ldcol);
-}
-
-Nx1MEMBERFN(void)::set_input_tensor(const void* const inptr, const int ldbatch, const int ldrow, const int ldcol)
-{
- // Transpose row and column strides
- Base::set_input_tensor(inptr, ldbatch, ldcol, ldrow);
-}
-
-MEMBERFN(size_t)::get_working_space_size(const unsigned int nthreads) const
-{
- return sizeof(TIn) * InnerTileRows * _working_space_row_stride * nthreads;
-}
-
-MEMBERFN(void)::set_working_space(void * const buffer)
-{
- _working_space = static_cast<TIn *>(buffer);
-}
-
-MEMBERFN(unsigned int)::get_window(void) const
-{
- return iceildiv(_n_channels, WINDOW_BLOCK);
-}
-
-MEMBERFN(void)::run(
- const unsigned int start,
- const unsigned int stop,
- const unsigned int threadid
-)
-{
- // Determine the channels on which to work
- if (start >= get_window())
- {
- return; // No work to do beyond the end of the window
- }
- const unsigned int start_channel = start * WINDOW_BLOCK;
- const unsigned int stop_channel = std::min<unsigned int>(_n_channels , stop * WINDOW_BLOCK);
- const unsigned int n_channels = stop_channel - start_channel;
-
- // Loop over batches
- for (int batch = 0; batch < _n_batches; batch++)
- {
- const TIn* const inptr_batch = _inptr + start_channel + batch*_in_batch_stride;
- TOut* const outptr_batch = _outptr + start_channel + batch*_matrix_batch_stride;
-
- // Loop over rows of tiles
- for (int tile_i = 0; tile_i < _tiles_M; tile_i++)
- {
- // Compute the starting and ending row of pixels within the row of tiles,
- // hence compute the padding to apply to the top and bottom of each tile.
- const int row_top = tile_i * (InnerTileRows - _overlap_rows) - _padding_top;
- const int row_bottom = row_top + InnerTileRows;
- const int row_pad_top = std::max(0, _padding_top - tile_i * (InnerTileRows - _overlap_rows));
- const int row_pad_bottom = std::max(0, row_bottom - _n_rows);
-
- // Get a pointer to the start of the row.
- const int row_offset = std::min(0, row_pad_top - _padding_top);
- const TIn* const inptr_row = inptr_batch + _in_row_stride*(row_offset + tile_i*(InnerTileRows - _overlap_rows));
- TOut* const outptr_row = outptr_batch + tile_i*_tiles_N*_matrix_row_stride;
-
- // Loop over tiles within the row
- for (int tile_j = 0; tile_j < _tiles_N; tile_j++)
- {
- // Compute the starting and ending column of pixels within the tile,
- // hence compute the padding to apply to the left and right of the
- // tile.
- const int tile_left = tile_j * (InnerTileCols - _overlap_cols) - _padding_left;
- const int tile_right = tile_left + InnerTileCols;
- const int tile_pad_left = std::max(0, _padding_left - tile_j * (InnerTileCols - _overlap_cols));
- const int tile_pad_right = std::max(0, tile_right - _n_cols);
-
- // Get a pointer to the start of the tile.
- const int col_offset = std::min(0, tile_pad_left - _padding_left);
- const TIn* const inptr_tile = inptr_row + _in_col_stride*(col_offset + tile_j*(InnerTileCols - _overlap_cols));
- TOut* const outptr_tile = outptr_row + tile_j * _matrix_row_stride;
-
- // Transform the tile, applying padding if necessary.
- if (row_pad_top || tile_pad_left || row_pad_bottom || tile_pad_right)
- {
- transform_padded_tile(
- threadid, n_channels, outptr_tile, inptr_tile,
- row_pad_top, tile_pad_left, row_pad_bottom, tile_pad_right
- );
- }
- else
- {
- transform_unpadded_tile(threadid, n_channels, outptr_tile, inptr_tile);
- }
- }
- }
- }
-}
-
-MEMBERFN(void)::transform_unpadded_tile(
- const unsigned int /* threadid unused */,
- const int n_channels,
- TOut * const outptr,
- const TIn * const inptr
-)
-{
- transform_tile(
- n_channels, inptr, _in_row_stride, _in_col_stride, outptr, _matrix_stride
- );
-}
-
-MEMBERFN(void)::transform_padded_tile(
- const unsigned int threadid,
- const int n_channels,
- TOut * const outptr,
- const TIn * const inptr,
- const int padding_top,
- const int padding_left,
- const int padding_bottom,
- const int padding_right
-)
-{
- padding::copy_and_pad_tile(
- InnerTileRows, InnerTileCols, n_channels,
- inptr, _in_row_stride, _in_col_stride,
- static_cast<TIn *>(get_working_space(threadid)), _working_space_row_stride, _working_space_col_stride,
- padding_top, padding_left, padding_bottom, padding_right
- );
-
- transform_tile(
- n_channels, static_cast<const TIn *>(get_working_space(threadid)),
- _working_space_row_stride, _working_space_col_stride,
- outptr, _matrix_stride
- );
-}
-
-MEMBERFN(void *)::get_working_space(const unsigned int threadid) const
-{
- return _working_space + InnerTileRows * _working_space_row_stride * threadid;
-}
-
-} // namespace winograd
diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_4x4_fp16_fp16_integers.cpp b/src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_4x4_fp16_fp16_integers.cpp
deleted file mode 100644
index 5e6ac97121..0000000000
--- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/input_4x4_fp16_fp16_integers.cpp
+++ /dev/null
@@ -1,257 +0,0 @@
-/*
- * Copyright (c) 2020 Arm Limited.
- *
- * SPDX-License-Identifier: MIT
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
-
-#include "input.hpp"
-#include "arm.hpp"
-
-namespace winograd
-{
-
-template <>
-void InputTransform<4, 4, __fp16, __fp16, WinogradRoots::Integers>::transform_tile(
- const int n_channels,
- const __fp16* const input_base,
- const int input_row_stride,
- const int input_col_stride,
- __fp16* outptr,
- const int matrix_stride
-)
-{
- constexpr int inner_tile_rows = 4, inner_tile_cols = 4;
-
- // Get pointers into the input tile
- const __fp16 *x_ptrs[inner_tile_rows][inner_tile_cols];
- for (int i = 0, xi = 0; i < inner_tile_rows; i++, xi++)
- {
- // Get a pointer into the row
- const __fp16* const row_ptr = input_base + xi*input_row_stride;
-
- for (int j = 0, xj = 0; j < inner_tile_cols; j++, xj++)
- {
- x_ptrs[i][j] = row_ptr + xj*input_col_stride;
- }
- }
-
- // Matrices used/computed in this kernel.
- __fp16 x[inner_tile_rows][inner_tile_cols];
- __fp16 XTx[inner_tile_rows][inner_tile_cols];
- __fp16 U[inner_tile_rows][inner_tile_cols];
-
- for (int i = 0; i < inner_tile_rows; i++)
- {
- for (int j = 0; j < inner_tile_cols; j++)
- {
- x[i][j] = XTx[i][j] = 0.0f;
- }
- }
-
- // Perform the Winograd input transformation for each channel in the input
- // tensor.
- int channels_remaining = n_channels;
-#ifdef __aarch64__
- for (; channels_remaining >= 8; channels_remaining -= 8)
- {
- // Matrices used/computed in this kernel.
- float16x8_t x[inner_tile_rows][inner_tile_cols];
- float16x8_t XTx[inner_tile_rows][inner_tile_cols];
- float16x8_t U[inner_tile_rows][inner_tile_cols];
-
- for (int i = 0; i < inner_tile_rows; i++)
- {
- for (int j = 0; j < inner_tile_cols; j++)
- {
- x[i][j] = vdupq_n_f16(0.0f);
- XTx[i][j] = vdupq_n_f16(0.0f);
- }
- }
-
- // Load x
- for (int i = 0; i < inner_tile_rows; i++)
- {
- for (int j = 0; j < inner_tile_cols; j++)
- {
- x[i][j] = vld1q_f16(x_ptrs[i][j]);
- x_ptrs[i][j] += 8;
- }
- }
-
- // Compute XT . x
- for (int j = 0; j < inner_tile_cols; j++)
- {
- // XTx[0][j] = x[0][j] - x[2][j];
- XTx[0][j] = vsubq_f16(x[0][j], x[2][j]);
-
- // XTx[1][j] = x[1][j] + x[2][j];
- XTx[1][j] = vaddq_f16(x[1][j], x[2][j]);
-
- // XTx[2][j] = x[2][j] - x[1][j];
- XTx[2][j] = vsubq_f16(x[2][j], x[1][j]);
-
- // XTx[3][j] = x[1][j] - x[3][j];
- XTx[3][j] = vsubq_f16(x[1][j], x[3][j]);
- }
-
- // Compute U = XT . x . X
- for (int i = 0; i < inner_tile_rows; i++)
- {
- // U[i][0] = XTx[i][0] - XTx[i][2];
- U[i][0] = vsubq_f16(XTx[i][0], XTx[i][2]);
-
- // U[i][1] = XTx[i][1] + XTx[i][2];
- U[i][1] = vaddq_f16(XTx[i][1], XTx[i][2]);
-
- // U[i][2] = XTx[i][2] - XTx[i][1];
- U[i][2] = vsubq_f16(XTx[i][2], XTx[i][1]);
-
- // U[i][3] = XTx[i][1] - XTx[i][3];
- U[i][3] = vsubq_f16(XTx[i][1], XTx[i][3]);
- }
-
- // Store the transformed matrix
- for (int i = 0, m = 0; i < inner_tile_rows; i++)
- {
- for (int j = 0; j < inner_tile_cols; j++, m++)
- {
- vst1q_f16(outptr + m*matrix_stride, U[i][j]);
- }
- }
- outptr += 8;
- }
-#endif // __aarch64__
-#ifdef __arm_any__
- for (; channels_remaining >= 4; channels_remaining -= 4)
- {
- // Matrices used/computed in this kernel.
- float16x4_t x[inner_tile_rows][inner_tile_cols];
- float16x4_t XTx[inner_tile_rows][inner_tile_cols];
- float16x4_t U[inner_tile_rows][inner_tile_cols];
-
- for (int i = 0; i < inner_tile_rows; i++)
- {
- for (int j = 0; j < inner_tile_cols; j++)
- {
- x[i][j] = vdup_n_f16(0.0f);
- XTx[i][j] = vdup_n_f16(0.0f);
- }
- }
-
- // Load x
- for (int i = 0; i < inner_tile_rows; i++)
- {
- for (int j = 0; j < inner_tile_cols; j++)
- {
- x[i][j] = vld1_f16(x_ptrs[i][j]);
- x_ptrs[i][j] += 4;
- }
- }
-
- // Compute XT . x
- for (int j = 0; j < inner_tile_cols; j++)
- {
- // XTx[0][j] = x[0][j] - x[2][j];
- XTx[0][j] = vsub_f16(x[0][j], x[2][j]);
-
- // XTx[1][j] = x[1][j] + x[2][j];
- XTx[1][j] = vadd_f16(x[1][j], x[2][j]);
-
- // XTx[2][j] = x[2][j] - x[1][j];
- XTx[2][j] = vsub_f16(x[2][j], x[1][j]);
-
- // XTx[3][j] = x[1][j] - x[3][j];
- XTx[3][j] = vsub_f16(x[1][j], x[3][j]);
- }
-
- // Compute U = XT . x . X
- for (int i = 0; i < inner_tile_rows; i++)
- {
- // U[i][0] = XTx[i][0] - XTx[i][2];
- U[i][0] = vsub_f16(XTx[i][0], XTx[i][2]);
-
- // U[i][1] = XTx[i][1] + XTx[i][2];
- U[i][1] = vadd_f16(XTx[i][1], XTx[i][2]);
-
- // U[i][2] = XTx[i][2] - XTx[i][1];
- U[i][2] = vsub_f16(XTx[i][2], XTx[i][1]);
-
- // U[i][3] = XTx[i][1] - XTx[i][3];
- U[i][3] = vsub_f16(XTx[i][1], XTx[i][3]);
- }
-
- // Store the transformed matrix
- for (int i = 0, m = 0; i < inner_tile_rows; i++)
- {
- for (int j = 0; j < inner_tile_cols; j++, m++)
- {
- vst1_f16(outptr + m*matrix_stride, U[i][j]);
- }
- }
- outptr += 4;
- }
-#endif // __arm_any__
- for (; channels_remaining; channels_remaining--)
- {
- // Load x
- for (int i = 0; i < inner_tile_rows; i++)
- {
- for (int j = 0; j < inner_tile_cols; j++)
- {
- x[i][j] = *(x_ptrs[i][j]++);
- }
- }
-
- // Compute XT . x
- for (int j = 0; j < inner_tile_cols; j++)
- {
- XTx[0][j] = x[0][j] - x[2][j];
- XTx[1][j] = x[1][j] + x[2][j];
- XTx[2][j] = x[2][j] - x[1][j];
- XTx[3][j] = x[1][j] - x[3][j];
- }
-
- // Compute U = XT . x . X
- for (int i = 0; i < inner_tile_rows; i++)
- {
- U[i][0] = XTx[i][0] - XTx[i][2];
- U[i][1] = XTx[i][1] + XTx[i][2];
- U[i][2] = XTx[i][2] - XTx[i][1];
- U[i][3] = XTx[i][1] - XTx[i][3];
- }
-
- // Store the transformed matrix
- for (int i = 0, m = 0; i < inner_tile_rows; i++)
- {
- for (int j = 0; j < inner_tile_cols; j++, m++)
- {
- *(outptr + m*matrix_stride) = U[i][j];
- }
- }
- outptr++;
- }
-}
-
-template class InputTransform<4, 4, __fp16, __fp16, WinogradRoots::Integers>;
-
-} // namespace
-#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/kernel.hpp b/src/core/NEON/kernels/convolution/winograd/winograd_transforms/kernel.hpp
deleted file mode 100644
index 27d20811d6..0000000000
--- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/kernel.hpp
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright (c) 2019 Arm Limited.
- *
- * SPDX-License-Identifier: MIT
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#pragma once
-#include "winograd.hpp"
-using namespace winograd;
-
-#define MEMBERFN(RTYPE) template <\
- int KernelRows, int KernelCols, int InnerTileRows, int InnerTileCols, typename TIn, typename TOut, WinogradRoots Roots\
-> RTYPE WeightTransform<KernelRows, KernelCols, InnerTileRows, InnerTileCols, TIn, TOut, Roots>
-
-MEMBERFN()::WeightTransform(
- const int n_output_channels,
- const int n_input_channels
-) : _n_output_channels(n_output_channels), _n_input_channels(n_input_channels),
- _matrices(nullptr), _matrix_stride(0), _matrix_row_stride(0), _weights(nullptr)
-{
-
-}
-
-MEMBERFN(void)::set_weight_tensor(const void * const weights)
-{
- _weights = static_cast<const TIn *>(weights);
-}
-
-MEMBERFN(void)::set_output_matrices(void * const mptr, const int ldmatrix, const int ldrow)
-{
- _matrices = static_cast<TOut *>(mptr);
- _matrix_stride = ldmatrix;
- _matrix_row_stride = ldrow;
-}
-
-MEMBERFN(size_t)::get_working_space_size(unsigned int) const
-{
- return 0;
-}
-
-MEMBERFN(void)::set_working_space(void *)
-{
-}
-
-MEMBERFN(unsigned int)::get_window(void) const
-{
- // TODO When the weights transform supports multithreading, return the number
- // of output channels. For now we return 1 to indicate that the weights must
- // be transformed as a single block.
- // return n_output_channels;
- return 1;
-}
-
-MEMBERFN(void)::run(const unsigned int, const unsigned int, unsigned int)
-{
- execute(
- _n_output_channels, _n_input_channels, _weights,
- _matrices, _matrix_stride, _matrix_row_stride
- );
-}
diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/output.hpp b/src/core/NEON/kernels/convolution/winograd/winograd_transforms/output.hpp
deleted file mode 100644
index c1fb559b1d..0000000000
--- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/output.hpp
+++ /dev/null
@@ -1,252 +0,0 @@
-/*
- * Copyright (c) 2017-2019 Arm Limited.
- *
- * SPDX-License-Identifier: MIT
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#pragma once
-
-#include <algorithm>
-#include "winograd.hpp"
-#include "padding.hpp"
-#include "utils.hpp"
-
-#define MEMBERFN(RTYPE) template<\
- int KernelRows, int KernelCols, int InnerTileRows, int InnerTileCols,\
- typename TIn, typename TOut, WinogradRoots Roots\
-> RTYPE OutputTransform<KernelRows, KernelCols, InnerTileRows, InnerTileCols, TIn, TOut, Roots>
-
-#define Nx1MEMBERFN(RTYPE) template<\
- int KernelRows, int InnerTileRows, typename TIn, typename TOut, WinogradRoots Roots\
-> RTYPE OutputTransform<KernelRows, 1, InnerTileRows, 1, TIn, TOut, Roots>
-
-namespace winograd
-{
-
-MEMBERFN()
-::OutputTransform(const int n_batches, const int n_rows, const int n_cols,
- const int n_channels, const arm_gemm::Activation &activation)
- : _n_batches(n_batches), _n_rows(n_rows), _n_cols(n_cols),
- _n_channels(n_channels),
- _output_min((activation.type == arm_gemm::Activation::Type::ReLU ||
- activation.type == arm_gemm::Activation::Type::BoundedReLU)
- ? static_cast<TOut>(0.0f) : TypeBounds<TOut>::lower()),
- _output_max((activation.type == arm_gemm::Activation::Type::BoundedReLU)
- ? static_cast<TOut>(activation.param1) : TypeBounds<TOut>::upper()),
- _matrix_base(nullptr), _biases(nullptr), _matrix_stride(0),
- _matrix_row_stride(0), _matrix_batch_stride(0), _outptr(nullptr),
- _tiles_M(iceildiv(n_rows, output_tile_rows)),
- _tiles_N(iceildiv(n_cols, output_tile_cols)), _out_col_stride(0),
- _out_row_stride(0), _out_batch_stride(0),
- _working_space_col_stride(n_channels),
- _working_space_row_stride(output_tile_cols * _working_space_col_stride),
- _working_space(nullptr) {}
-
-MEMBERFN(void)::set_input_matrices(const void * const mptr, const int ldmatrix, const int ldrow)
-{
- _matrix_base = static_cast<const TIn *>(mptr);
- _matrix_stride = ldmatrix;
- _matrix_row_stride = ldrow;
- _matrix_batch_stride = _tiles_M * _tiles_N * ldrow;
-}
-
-MEMBERFN(void)::set_bias(const void * const bias)
-{
- _biases = static_cast<const TOut *>(bias);
-}
-
-MEMBERFN(void)::set_output_tensor(void * const outptr)
-{
- set_output_tensor(outptr, _n_channels);
-}
-
-MEMBERFN(void)::set_output_tensor(void * const outptr, const int ldcol)
-{
- set_output_tensor(outptr, _n_cols * ldcol, ldcol);
-}
-
-MEMBERFN(void)::set_output_tensor(void * const outptr, const int ldrow, const int ldcol)
-{
- set_output_tensor(outptr, _n_rows * ldrow, ldrow, ldcol);
-}
-
-MEMBERFN(void)::set_output_tensor(void * const outptr, const int ldbatch, const int ldrow, const int ldcol)
-{
- _outptr = static_cast<TOut *>(outptr);
- _out_batch_stride = ldbatch;
- _out_row_stride = ldrow;
- _out_col_stride = ldcol;
-}
-
-Nx1MEMBERFN()::OutputTransform(
- const int n_batches,
- const int n_rows,
- const int n_cols,
- const int n_channels,
- const arm_gemm::Activation &activation
-) : OutputTransform<1, KernelRows, 1, InnerTileRows, TIn, TOut, Roots>::OutputTransform(
- n_batches, n_cols, n_rows, n_channels, activation /* Transpose rows and columns */
- )
-{
-}
-
-Nx1MEMBERFN(void)::set_output_tensor(void * const outptr)
-{
- set_output_tensor(outptr, this->_n_channels);
-}
-
-Nx1MEMBERFN(void)::set_output_tensor(void * const outptr, const int ldcol)
-{
- set_output_tensor(outptr, this->_n_cols * ldcol, ldcol);
-}
-
-Nx1MEMBERFN(void)::set_output_tensor(void * const outptr, const int ldrow, const int ldcol)
-{
- set_output_tensor(outptr, this->_n_rows * ldrow, ldrow, ldcol);
-}
-
-Nx1MEMBERFN(void)::set_output_tensor(void * const outptr, const int ldbatch, const int ldrow, const int ldcol)
-{
- // Transpose rows and columns
- Base::set_output_tensor(outptr, ldbatch, ldcol, ldrow);
-}
-
-MEMBERFN(size_t)::get_working_space_size(const unsigned int nthreads) const
-{
- return sizeof(TOut) * output_tile_rows * _working_space_row_stride * nthreads;
-}
-
-MEMBERFN(void)::set_working_space(void * const buffer)
-{
- _working_space = static_cast<TOut *>(buffer);
-}
-
-MEMBERFN(unsigned int)::get_window(void) const
-{
- return iceildiv(_n_channels, WINDOW_BLOCK);
-}
-
-MEMBERFN(void)::run(
- const unsigned int start,
- const unsigned int stop,
- const unsigned int threadid
-)
-{
- // Determine the channels on which to work
- if (start >= get_window())
- {
- return; // No work to do beyond the end of the window
- }
- const unsigned int start_channel = start * WINDOW_BLOCK;
- const unsigned int stop_channel = std::min<unsigned int>(_n_channels, stop * WINDOW_BLOCK);
- const unsigned int n_channels = stop_channel - start_channel;
-
- const auto matrix_tile_col_stride = _matrix_row_stride;
- const auto matrix_tile_row_stride = _tiles_N * matrix_tile_col_stride;
-
- const TOut* const bptr = (_biases == nullptr) ? nullptr : _biases + start_channel;
-
- // Loop over batches
- for (int batch = 0; batch < _n_batches; batch++)
- {
- const TIn* const matrix_batch = _matrix_base + start_channel + batch * _matrix_batch_stride;
- TOut* const outptr_batch = _outptr + start_channel + batch * _out_batch_stride;
-
- for (int tile_i = 0; tile_i < _tiles_M; tile_i++)
- {
- // Compute properties of the row of output tiles
- const int row_pad_bottom = std::max(0, (tile_i + 1)*output_tile_rows - _n_rows);
- const TIn* const matrix_tile_row = matrix_batch + tile_i * matrix_tile_row_stride;
- TOut* const outptr_row = outptr_batch + tile_i * output_tile_rows * _out_row_stride;
-
- for (int tile_j = 0; tile_j < _tiles_N; tile_j++)
- {
- // Compute property of this specific tile
- const int tile_pad_right = std::max(0, (tile_j + 1)*output_tile_cols - _n_cols);
- const TIn* const matrix_tile = matrix_tile_row + tile_j * matrix_tile_col_stride;
- TOut* const outptr_tile = outptr_row + tile_j * output_tile_cols * _out_col_stride;
-
- // Perform the transformation
- if (row_pad_bottom || tile_pad_right)
- {
- transform_cropped_tile(
- threadid, n_channels, outptr_tile, matrix_tile, bptr,
- row_pad_bottom, tile_pad_right
- );
- }
- else
- {
- transform_uncropped_tile(
- threadid, n_channels, outptr_tile, matrix_tile, bptr
- );
- }
- }
- }
- }
-}
-
-MEMBERFN(void)::transform_uncropped_tile(
- const unsigned int /* threadid unused */,
- const int n_channels,
- TOut * const outptr,
- const TIn * const inptr,
- const TOut * const biases
-)
-{
- transform_tile(
- n_channels, inptr, _matrix_stride, biases,
- outptr, _out_row_stride, _out_col_stride,
- _output_min, _output_max
- );
-}
-
-MEMBERFN(void)::transform_cropped_tile(
- const unsigned int threadid,
- const int n_channels,
- TOut * const outptr,
- const TIn * const inptr,
- const TOut * const biases,
- const int pad_bottom,
- const int pad_right
-)
-{
- // Transform into working space and then copy the relevant section out.
- TOut *wsptr = static_cast<TOut *>(get_working_space(threadid));
- transform_tile(
- n_channels, inptr, _matrix_stride, biases,
- wsptr, _working_space_row_stride, _working_space_col_stride,
- _output_min, _output_max
- );
-
- padding::crop_and_copy_tile(
- output_tile_rows, output_tile_cols, n_channels,
- wsptr, _working_space_row_stride, _working_space_col_stride,
- outptr, _out_row_stride, _out_col_stride,
- 0u, 0u, pad_bottom, pad_right
- );
-}
-
-MEMBERFN(void *)::get_working_space(const unsigned int threadid) const
-{
- return _working_space + output_tile_rows * _working_space_row_stride * threadid;
-}
-
-} // namespace winograd
diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_2_7_fp32_fp32_integers.cpp b/src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_2_7_fp32_fp32_integers.cpp
deleted file mode 100644
index 2ee377ceca..0000000000
--- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_2_7_fp32_fp32_integers.cpp
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright (c) 2019 Arm Limited.
- *
- * SPDX-License-Identifier: MIT
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#include "arm.hpp"
-#include "kernel.hpp"
-
-namespace winograd
-{
-
-template <>
-void WeightTransform<1, 7, 1, 8, float, float, WinogradRoots::Integers>::execute(
- const int n_output_channels,
- const int n_input_channels,
- const float* const input, // NOTE: Data in HWIO order
- float* const output,
- const int matrix_stride,
- const int matrix_row_stride
-)
-{
- // Get pointers to each cell of the weight tensor
- const auto weight_col_stride = n_input_channels * n_output_channels;
- const float *inptrs[kernel_cols];
- for (int j = 0; j < kernel_cols; j++)
- {
- inptrs[j] = input + j*weight_col_stride;
- }
-
- // For each input channel
- for (int ic = 0; ic < n_input_channels; ic++)
- {
- float *outptr = output + ic * matrix_row_stride;
-
- // For each output channel
- int channels_remaining = n_output_channels;
- for (; channels_remaining; channels_remaining--)
- {
- // Matrices used and computed in this kernel
- float w[kernel_cols], V[inner_tile_cols];
-
- // Read weights
- for (int j = 0; j < kernel_cols; j++)
- {
- w[j] = *(inptrs[j]++);
- }
-
- // Compute V = w WT
- V[0] = (w[0]*-1) / 36.0f;
- V[1] = (w[1]*-1 + w[3]*-1 + w[5]*-1 + w[0]*1 + w[2]*1 + w[4]*1 + w[6]*1) / 48.0f;
- V[2] = (w[0]*1 + w[1]*1 + w[2]*1 + w[3]*1 + w[4]*1 + w[5]*1 + w[6]*1) / 48.0f;
- V[3] = (w[0]*-1 + w[6]*-64 + w[4]*-16 + w[2]*-4 + w[1]*2 + w[3]*8 + w[5]*32) / 120.0f;
- V[4] = (w[0]*-1 + w[6]*-64 + w[5]*-32 + w[4]*-16 + w[3]*-8 + w[2]*-4 + w[1]*-2) / 120.0f;
- V[5] = (w[5]*-243 + w[3]*-27 + w[1]*-3 + w[2]*9 + w[4]*81 + w[6]*729 + w[0]*1) / 720.0f;
- V[6] = (w[1]*3 + w[2]*9 + w[3]*27 + w[4]*81 + w[5]*243 + w[6]*729 + w[0]*1) / 720.0f;
- V[7] = (w[6]*1) / 1.0f;
-
- // Store the transformed weights
- for (int j = 0; j < inner_tile_cols; j++)
- {
- *(outptr + j*matrix_stride) = V[j];
- }
- outptr++;
- }
- }
-}
-
-template class WeightTransform<1, 7, 1, 8, float, float, WinogradRoots::Integers>;
-template class WeightTransform<7, 1, 8, 1, float, float, WinogradRoots::Integers>;
-
-} // namespace winograd
diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_2x2_3x3_fp32_fp32_integers.cpp b/src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_2x2_3x3_fp32_fp32_integers.cpp
deleted file mode 100644
index 3fde4a7a6b..0000000000
--- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_2x2_3x3_fp32_fp32_integers.cpp
+++ /dev/null
@@ -1,220 +0,0 @@
-/*
- * Copyright (c) 2019 Arm Limited.
- *
- * SPDX-License-Identifier: MIT
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#include "arm.hpp"
-#include "kernel.hpp"
-
-namespace winograd
-{
-
-template <>
-void WeightTransform<3, 3, 4, 4, float, float, WinogradRoots::Integers>::execute(
- const int n_output_channels,
- const int n_input_channels,
- const float* const input,
- float* const output,
- const int matrix_stride,
- const int matrix_row_stride
-)
-{
- constexpr int inner_tile_i = 4;
- constexpr int inner_tile_j = 4;
-
- // Get pointers to each cell of the weight tensor
- const auto weight_col_stride = n_input_channels * n_output_channels;
- const auto weight_row_stride = 3 * weight_col_stride;
- const float *inptrs[3][3];
- for (int i = 0; i < 3; i++)
- {
- for (int j = 0; j < 3; j++)
- {
- inptrs[i][j] = input + i*weight_row_stride + j*weight_col_stride;
- }
- }
-
- // For each input channel
- for (int ic = 0; ic < n_input_channels; ic++)
- {
- float *outptr = output + ic * matrix_row_stride;
-
- // For each output channel
- int channels_remaining = n_output_channels;
-#ifdef __aarch64__
- for (; channels_remaining >= 4; channels_remaining -= 4)
- {
- // Matrices used and computed in this kernel
- float32x4_t w[3][3], Ww[inner_tile_i][3], V[inner_tile_i][inner_tile_j];
-
- // Read weights
- for (int i = 0; i < 3; i++)
- {
- for (int j = 0; j < 3; j++)
- {
- w[i][j] = vld1q_f32(inptrs[i][j]);
- inptrs[i][j] += 4;
- }
- }
-
- // Compute the matrix W w
- for (int j = 0; j < 3; j++)
- {
- Ww[0][j] = w[0][j];
-
- // Ww[1][j] = 0.5*(w[0][j] + w[1][j] + w[2][j]);
- Ww[1][j] = vmulq_n_f32(vaddq_f32(vaddq_f32(w[0][j], w[1][j]), w[2][j]), 0.5f);
-
- // Ww[2][j] = 0.5*(w[0][j] - w[1][j] + w[2][j]);
- Ww[2][j] = vmulq_n_f32(vaddq_f32(vsubq_f32(w[0][j], w[1][j]), w[2][j]), 0.5f);
-
- Ww[3][j] = w[2][j];
- }
-
- // Compute V = W w WT
- for (int i = 0; i < inner_tile_i; i++)
- {
- V[i][0] = Ww[i][0];
-
- // V[i][1] = 0.5*(Ww[i][0] + Ww[i][1] + Ww[i][2]);
- V[i][1] = vmulq_n_f32(vaddq_f32(vaddq_f32(Ww[i][0], Ww[i][1]), Ww[i][2]), 0.5f);
-
- // V[i][2] = 0.5*(Ww[i][0] - Ww[i][1] + Ww[i][2]);
- V[i][2] = vmulq_n_f32(vaddq_f32(vsubq_f32(Ww[i][0], Ww[i][1]), Ww[i][2]), 0.5f);
-
- V[i][3] = Ww[i][2];
- }
-
- // Store the transformed weights
- for (int i = 0, m = 0; i < inner_tile_i; i++)
- {
- for (int j = 0; j < inner_tile_j; j++, m++)
- {
- vst1q_f32(outptr + m*matrix_stride, V[i][j]);
- }
- }
- outptr += 4;
- }
-#endif // __aarch64__
-#ifdef __arm_any__
- for (; channels_remaining >= 2; channels_remaining -= 2)
- {
- // Matrices used and computed in this kernel
- float32x2_t w[3][3], Ww[inner_tile_i][3], V[inner_tile_i][inner_tile_j];
-
- // Read weights
- for (int i = 0; i < 3; i++)
- {
- for (int j = 0; j < 3; j++)
- {
- w[i][j] = vld1_f32(inptrs[i][j]);
- inptrs[i][j] += 2;
- }
- }
-
- // Compute the matrix W w
- for (int j = 0; j < 3; j++)
- {
- Ww[0][j] = w[0][j];
-
- // Ww[1][j] = 0.5*(w[0][j] + w[1][j] + w[2][j]);
- Ww[1][j] = vmul_n_f32(vadd_f32(vadd_f32(w[0][j], w[1][j]), w[2][j]), 0.5f);
-
- // Ww[2][j] = 0.5*(w[0][j] - w[1][j] + w[2][j]);
- Ww[2][j] = vmul_n_f32(vadd_f32(vsub_f32(w[0][j], w[1][j]), w[2][j]), 0.5f);
-
- Ww[3][j] = w[2][j];
- }
-
- // Compute V = W w WT
- for (int i = 0; i < inner_tile_i; i++)
- {
- V[i][0] = Ww[i][0];
-
- // V[i][1] = 0.5*(Ww[i][0] + Ww[i][1] + Ww[i][2]);
- V[i][1] = vmul_n_f32(vadd_f32(vadd_f32(Ww[i][0], Ww[i][1]), Ww[i][2]), 0.5f);
-
- // V[i][2] = 0.5*(Ww[i][0] - Ww[i][1] + Ww[i][2]);
- V[i][2] = vmul_n_f32(vadd_f32(vsub_f32(Ww[i][0], Ww[i][1]), Ww[i][2]), 0.5f);
-
- V[i][3] = Ww[i][2];
- }
-
- // Store the transformed weights
- for (int i = 0, m = 0; i < inner_tile_i; i++)
- {
- for (int j = 0; j < inner_tile_j; j++, m++)
- {
- vst1_f32(outptr + m*matrix_stride, V[i][j]);
- }
- }
- outptr += 2;
- }
-#endif // __arm_any__
- for (; channels_remaining; channels_remaining--)
- {
- // Matrices used and computed in this kernel
- float w[3][3], Ww[inner_tile_i][3], V[inner_tile_i][inner_tile_j];
-
- // Read weights
- for (int i = 0; i < 3; i++)
- {
- for (int j = 0; j < 3; j++)
- {
- w[i][j] = *(inptrs[i][j]++);
- }
- }
-
- // Compute the matrix W w
- for (int j = 0; j < 3; j++)
- {
- Ww[0][j] = w[0][j];
- Ww[1][j] = 0.5*(w[0][j] + w[1][j] + w[2][j]);
- Ww[2][j] = 0.5*(w[0][j] - w[1][j] + w[2][j]);
- Ww[3][j] = w[2][j];
- }
-
- // Compute V = W w WT
- for (int i = 0; i < inner_tile_i; i++)
- {
- V[i][0] = Ww[i][0];
- V[i][1] = 0.5*(Ww[i][0] + Ww[i][1] + Ww[i][2]);
- V[i][2] = 0.5*(Ww[i][0] - Ww[i][1] + Ww[i][2]);
- V[i][3] = Ww[i][2];
- }
-
- // Store the transformed weights
- for (int i = 0, m = 0; i < inner_tile_i; i++)
- {
- for (int j = 0; j < inner_tile_j; j++, m++)
- {
- *(outptr + m*matrix_stride) = V[i][j];
- }
- }
- outptr++;
- }
- }
-}
-
-template class WeightTransform<3, 3, 4, 4, float, float, WinogradRoots::Integers>;
-
-} // namespace
diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_2x2_5x5_fp32_fp32_integers.cpp b/src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_2x2_5x5_fp32_fp32_integers.cpp
deleted file mode 100644
index 26ab56f24e..0000000000
--- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_2x2_5x5_fp32_fp32_integers.cpp
+++ /dev/null
@@ -1,401 +0,0 @@
-/*
- * Copyright (c) 2019 Arm Limited.
- *
- * SPDX-License-Identifier: MIT
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#include "arm.hpp"
-#include "kernel.hpp"
-
-namespace winograd
-{
-
-template <>
-void WeightTransform<5, 5, 6, 6, float, float, WinogradRoots::Integers>::execute(
- const int n_output_channels,
- const int n_input_channels,
- const float* const input,
- float* const output,
- const int matrix_stride,
- const int matrix_row_stride
-)
-{
- // Get pointers to each cell of the weight tensor
- const auto weight_col_stride = n_input_channels * n_output_channels;
- const auto weight_row_stride = 5 * weight_col_stride;
- const float *inptrs[5][5];
- for (int i = 0; i < 5; i++)
- {
- for (int j = 0; j < 5; j++)
- {
- inptrs[i][j] = input + i*weight_row_stride + j*weight_col_stride;
- }
- }
-
- // For each input channel
- for (int ic = 0; ic < n_input_channels; ic++)
- {
- float *outptr = output + ic * matrix_row_stride;
-
- // For each output channel
- int channels_remaining = n_output_channels;
-#ifdef __aarch64__
- for (; channels_remaining >= 4; channels_remaining -= 4)
- {
- // Matrices used and computed in this kernel
- float32x4_t w[5][5], Ww[6][5], V[6][6];
-
- // Read weights
- for (int i = 0; i < 5; i++)
- {
- for (int j = 0; j < 5; j++)
- {
- w[i][j] = vld1q_f32(inptrs[i][j]);
- inptrs[i][j] += 4;
- }
- }
-
- // Compute the matrix W w
- for (int j = 0; j < 5; j++)
- {
- // Ww[0][j] = w[0][j]/4.0f;
- Ww[0][j] = vmulq_n_f32(w[0][j], 1.0f/4.0f);
-
- // Ww[1][j] = -( w[0][j] + w[1][j] + w[2][j] + w[3][j] + w[4][j])/6.0f;
- Ww[1][j] = vmulq_n_f32(
- vaddq_f32(
- vaddq_f32(
- vaddq_f32(w[1][j], w[0][j]),
- vaddq_f32(w[3][j], w[2][j])
- ),
- w[4][j]
- ),
- -1.0f/6.0f
- );
-
- // Ww[2][j] = +(-w[0][j] + w[1][j] - w[2][j] + w[3][j] - w[4][j])/6.0f;
- // Ww[2][j] = ((w[1][j] - w[0][j]) + (w[3][j] - w[2][j]) - w[4][j])/6.0f;
- Ww[2][j] = vmulq_n_f32(
- vsubq_f32(
- vaddq_f32(
- vsubq_f32(w[1][j], w[0][j]),
- vsubq_f32(w[3][j], w[2][j])
- ),
- w[4][j]
- ),
- 1.0f/6.0f
- );
-
- // Ww[3][j] = (w[0][j]/8.0f + w[1][j]/4.0f + w[2][j]/2.0f + w[3][j] + 2*w[4][j])/3.0f;
- Ww[3][j] = vmulq_n_f32(
- vmlaq_n_f32(
- vaddq_f32(
- vaddq_f32(vmulq_n_f32(w[0][j], 1.0f/8.0f), vmulq_n_f32(w[1][j], 1.0f/4.0f)),
- vaddq_f32(vmulq_n_f32(w[2][j], 1.0f/2.0f), w[3][j])
- ),
- w[4][j], 2.0f
- ),
- 1.0f/3.0f
- );
-
- // Ww[4][j] = (w[0][j]/8.0f - w[1][j]/4.0f + w[2][j]/2.0f - w[3][j] + 2*w[4][j])/3.0f;
- Ww[4][j] = vmulq_n_f32(
- vmlaq_n_f32(
- vaddq_f32(
- vsubq_f32(vmulq_n_f32(w[0][j], 1.0f/8.0f), vmulq_n_f32(w[1][j], 1.0f/4.0f)),
- vsubq_f32(vmulq_n_f32(w[2][j], 1.0f/2.0f), w[3][j])
- ),
- w[4][j], 2.0f
- ),
- 1.0f/3.0f
- );
-
- // Ww[5][j] = w[4][j];
- Ww[5][j] = w[4][j];
- }
-
- // Compute V = W w WT
- for (int i = 0; i < 6; i++)
- {
- // V[i][0] = Ww[i][0]/4.0f;
- V[i][0] = vmulq_n_f32(Ww[i][0], 1.0f/4.0f);
-
- // V[i][1] = -( Ww[i][0] + Ww[i][1] + Ww[i][2] + Ww[i][3] + Ww[i][4])/6.0f;
- V[i][1] = vmulq_n_f32(
- vaddq_f32(
- vaddq_f32(
- vaddq_f32(Ww[i][1], Ww[i][0]),
- vaddq_f32(Ww[i][3], Ww[i][2])
- ),
- Ww[i][4]
- ),
- -1.0f/6.0f
- );
-
- // V[i][2] = +(-Ww[i][0] + Ww[i][1] - Ww[i][2] + Ww[i][3] - Ww[i][4])/6.0f;
- // V[i][2] = ((Ww[i][1] - Ww[i][0]) + (Ww[i][3] - Ww[i][2]) - Ww[i][4])/6.0f;
- V[i][2] = vmulq_n_f32(
- vsubq_f32(
- vaddq_f32(
- vsubq_f32(Ww[i][1], Ww[i][0]),
- vsubq_f32(Ww[i][3], Ww[i][2])
- ),
- Ww[i][4]
- ),
- 1.0f/6.0f
- );
-
- // V[i][3] = (Ww[i][0]/8.0f + Ww[i][1]/4.0f + Ww[i][2]/2.0f + Ww[i][3] + 2*Ww[i][4])/3.0f;
- V[i][3] = vmulq_n_f32(
- vmlaq_n_f32(
- vaddq_f32(
- vaddq_f32(vmulq_n_f32(Ww[i][0], 1.0f/8.0f), vmulq_n_f32(Ww[i][1], 1.0f/4.0f)),
- vaddq_f32(vmulq_n_f32(Ww[i][2], 1.0f/2.0f), Ww[i][3])
- ),
- Ww[i][4], 2.0f
- ),
- 1.0f/3.0f
- );
-
- // V[i][4] = (Ww[i][0]/8.0f - Ww[i][1]/4.0f + Ww[i][2]/2.0f - Ww[i][3] + 2*Ww[i][4])/3.0f;
- V[i][4] = vmulq_n_f32(
- vmlaq_n_f32(
- vaddq_f32(
- vsubq_f32(vmulq_n_f32(Ww[i][0], 1.0f/8.0f), vmulq_n_f32(Ww[i][1], 1.0f/4.0f)),
- vsubq_f32(vmulq_n_f32(Ww[i][2], 1.0f/2.0f), Ww[i][3])
- ),
- Ww[i][4], 2.0f
- ),
- 1.0f/3.0f
- );
-
- // V[i][5] = Ww[i][4];
- V[i][5] = Ww[i][4];
- }
-
- // Store the transformed weights
- for (int i = 0, m = 0; i < 6; i++)
- {
- for (int j = 0; j < 6; j++, m++)
- {
- vst1q_f32(outptr + m*matrix_stride, V[i][j]);
- }
- }
- outptr += 4;
- }
-#endif // __aarch64__
-#ifdef __arm_any__
- for (; channels_remaining >= 2; channels_remaining -= 2)
- {
- // Matrices used and computed in this kernel
- float32x2_t w[5][5], Ww[6][5], V[6][6];
-
- // Read weights
- for (int i = 0; i < 5; i++)
- {
- for (int j = 0; j < 5; j++)
- {
- w[i][j] = vld1_f32(inptrs[i][j]);
- inptrs[i][j] += 2;
- }
- }
-
- // Compute the matrix W w
- for (int j = 0; j < 5; j++)
- {
- // Ww[0][j] = w[0][j]/4.0f;
- Ww[0][j] = vmul_n_f32(w[0][j], 1.0f/4.0f);
-
- // Ww[1][j] = -( w[0][j] + w[1][j] + w[2][j] + w[3][j] + w[4][j])/6.0f;
- Ww[1][j] = vmul_n_f32(
- vadd_f32(
- vadd_f32(
- vadd_f32(w[1][j], w[0][j]),
- vadd_f32(w[3][j], w[2][j])
- ),
- w[4][j]
- ),
- -1.0f/6.0f
- );
-
- // Ww[2][j] = +(-w[0][j] + w[1][j] - w[2][j] + w[3][j] - w[4][j])/6.0f;
- // Ww[2][j] = ((w[1][j] - w[0][j]) + (w[3][j] - w[2][j]) - w[4][j])/6.0f;
- Ww[2][j] = vmul_n_f32(
- vsub_f32(
- vadd_f32(
- vsub_f32(w[1][j], w[0][j]),
- vsub_f32(w[3][j], w[2][j])
- ),
- w[4][j]
- ),
- 1.0f/6.0f
- );
-
- // Ww[3][j] = (w[0][j]/8.0f + w[1][j]/4.0f + w[2][j]/2.0f + w[3][j] + 2*w[4][j])/3.0f;
- Ww[3][j] = vmul_n_f32(
- vmla_n_f32(
- vadd_f32(
- vadd_f32(vmul_n_f32(w[0][j], 1.0f/8.0f), vmul_n_f32(w[1][j], 1.0f/4.0f)),
- vadd_f32(vmul_n_f32(w[2][j], 1.0f/2.0f), w[3][j])
- ),
- w[4][j], 2.0f
- ),
- 1.0f/3.0f
- );
-
- // Ww[4][j] = (w[0][j]/8.0f - w[1][j]/4.0f + w[2][j]/2.0f - w[3][j] + 2*w[4][j])/3.0f;
- Ww[4][j] = vmul_n_f32(
- vmla_n_f32(
- vadd_f32(
- vsub_f32(vmul_n_f32(w[0][j], 1.0f/8.0f), vmul_n_f32(w[1][j], 1.0f/4.0f)),
- vsub_f32(vmul_n_f32(w[2][j], 1.0f/2.0f), w[3][j])
- ),
- w[4][j], 2.0f
- ),
- 1.0f/3.0f
- );
-
- // Ww[5][j] = w[4][j];
- Ww[5][j] = w[4][j];
- }
-
- // Compute V = W w WT
- for (int i = 0; i < 6; i++)
- {
- // V[i][0] = Ww[i][0]/4.0f;
- V[i][0] = vmul_n_f32(Ww[i][0], 1.0f/4.0f);
-
- // V[i][1] = -( Ww[i][0] + Ww[i][1] + Ww[i][2] + Ww[i][3] + Ww[i][4])/6.0f;
- V[i][1] = vmul_n_f32(
- vadd_f32(
- vadd_f32(
- vadd_f32(Ww[i][1], Ww[i][0]),
- vadd_f32(Ww[i][3], Ww[i][2])
- ),
- Ww[i][4]
- ),
- -1.0f/6.0f
- );
-
- // V[i][2] = +(-Ww[i][0] + Ww[i][1] - Ww[i][2] + Ww[i][3] - Ww[i][4])/6.0f;
- // V[i][2] = ((Ww[i][1] - Ww[i][0]) + (Ww[i][3] - Ww[i][2]) - Ww[i][4])/6.0f;
- V[i][2] = vmul_n_f32(
- vsub_f32(
- vadd_f32(
- vsub_f32(Ww[i][1], Ww[i][0]),
- vsub_f32(Ww[i][3], Ww[i][2])
- ),
- Ww[i][4]
- ),
- 1.0f/6.0f
- );
-
- // V[i][3] = (Ww[i][0]/8.0f + Ww[i][1]/4.0f + Ww[i][2]/2.0f + Ww[i][3] + 2*Ww[i][4])/3.0f;
- V[i][3] = vmul_n_f32(
- vmla_n_f32(
- vadd_f32(
- vadd_f32(vmul_n_f32(Ww[i][0], 1.0f/8.0f), vmul_n_f32(Ww[i][1], 1.0f/4.0f)),
- vadd_f32(vmul_n_f32(Ww[i][2], 1.0f/2.0f), Ww[i][3])
- ),
- Ww[i][4], 2.0f
- ),
- 1.0f/3.0f
- );
-
- // V[i][4] = (Ww[i][0]/8.0f - Ww[i][1]/4.0f + Ww[i][2]/2.0f - Ww[i][3] + 2*Ww[i][4])/3.0f;
- V[i][4] = vmul_n_f32(
- vmla_n_f32(
- vadd_f32(
- vsub_f32(vmul_n_f32(Ww[i][0], 1.0f/8.0f), vmul_n_f32(Ww[i][1], 1.0f/4.0f)),
- vsub_f32(vmul_n_f32(Ww[i][2], 1.0f/2.0f), Ww[i][3])
- ),
- Ww[i][4], 2.0f
- ),
- 1.0f/3.0f
- );
-
- // V[i][5] = Ww[i][4];
- V[i][5] = Ww[i][4];
- }
-
- // Store the transformed weights
- for (int i = 0, m = 0; i < 6; i++)
- {
- for (int j = 0; j < 6; j++, m++)
- {
- vst1_f32(outptr + m*matrix_stride, V[i][j]);
- }
- }
- outptr += 2;
- }
-#endif // __arm_any__
- for (; channels_remaining; channels_remaining--)
- {
- // Matrices used and computed in this kernel
- float w[5][5], Ww[6][5], V[6][6];
-
- // Read weights
- for (int i = 0; i < 5; i++)
- {
- for (int j = 0; j < 5; j++)
- {
- w[i][j] = *(inptrs[i][j]++);
- }
- }
-
- // Compute the matrix W w
- for (int j = 0; j < 5; j++)
- {
- Ww[0][j] = w[0][j]/4.0f;
- Ww[1][j] = -( w[0][j] + w[1][j] + w[2][j] + w[3][j] + w[4][j])/6.0f;
- Ww[2][j] = +(-w[0][j] + w[1][j] - w[2][j] + w[3][j] - w[4][j])/6.0f;
- Ww[3][j] = (w[0][j]/8.0f + w[1][j]/4.0f + w[2][j]/2.0f + w[3][j] + 2*w[4][j])/3.0f;
- Ww[4][j] = (w[0][j]/8.0f - w[1][j]/4.0f + w[2][j]/2.0f - w[3][j] + 2*w[4][j])/3.0f;
- Ww[5][j] = w[4][j];
- }
-
- // Compute V = W w WT
- for (int i = 0; i < 6; i++)
- {
- V[i][0] = Ww[i][0]/4.0f;
- V[i][1] = -( Ww[i][0] + Ww[i][1] + Ww[i][2] + Ww[i][3] + Ww[i][4])/6.0f;
- V[i][2] = +(-Ww[i][0] + Ww[i][1] - Ww[i][2] + Ww[i][3] - Ww[i][4])/6.0f;
- V[i][3] = (Ww[i][0]/8.0f + Ww[i][1]/4.0f + Ww[i][2]/2.0f + Ww[i][3] + 2*Ww[i][4])/3.0f;
- V[i][4] = (Ww[i][0]/8.0f - Ww[i][1]/4.0f + Ww[i][2]/2.0f - Ww[i][3] + 2*Ww[i][4])/3.0f;
- V[i][5] = Ww[i][4];
- }
-
- // Store the transformed weights
- for (int i = 0, m = 0; i < 6; i++)
- {
- for (int j = 0; j < 6; j++, m++)
- {
- *(outptr + m*matrix_stride) = V[i][j];
- }
- }
- outptr++;
- }
- }
-}
-
-template class WeightTransform<5, 5, 6, 6, float, float, WinogradRoots::Integers>;
-
-} // namespace winograd
diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_4_5_fp32_fp32_integers.cpp b/src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_4_5_fp32_fp32_integers.cpp
deleted file mode 100644
index eeda274453..0000000000
--- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_4_5_fp32_fp32_integers.cpp
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright (c) 2019 Arm Limited.
- *
- * SPDX-License-Identifier: MIT
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#include "arm.hpp"
-#include "kernel.hpp"
-
-namespace winograd
-{
-
-template <>
-void WeightTransform<1, 5, 1, 8, float, float, WinogradRoots::Integers>::execute(
- const int n_output_channels,
- const int n_input_channels,
- const float* const input, // NOTE: Data in HWIO order
- float* const output,
- const int matrix_stride,
- const int matrix_row_stride
-)
-{
- // Get pointers to each cell of the weight tensor
- const auto weight_col_stride = n_input_channels * n_output_channels;
- const float *inptrs[kernel_cols];
- for (int j = 0; j < kernel_cols; j++)
- {
- inptrs[j] = input + j*weight_col_stride;
- }
-
- // For each input channel
- for (int ic = 0; ic < n_input_channels; ic++)
- {
- float *outptr = output + ic * matrix_row_stride;
-
- // For each output channel
- int channels_remaining = n_output_channels;
- for (; channels_remaining; channels_remaining--)
- {
- // Matrices used and computed in this kernel
- float w[kernel_cols], V[inner_tile_cols];
-
- // Read weights
- for (int j = 0; j < kernel_cols; j++)
- {
- w[j] = *(inptrs[j]++);
- }
-
- // Compute V = w WT
- V[0] = (w[0]*-1) / 36;
- V[1] = (w[1]*-1 + w[3]*-1 + w[0]*1 + w[2]*1 + w[4]*1) / 48;
- V[2] = (w[0]*1 + w[1]*1 + w[2]*1 + w[3]*1 + w[4]*1) / 48;
- V[3] = (w[0]*-1 + w[4]*-16 + w[2]*-4 + w[1]*2 + w[3]*8) / 120;
- V[4] = (w[0]*-1 + w[4]*-16 + w[3]*-8 + w[2]*-4 + w[1]*-2) / 120;
- V[5] = (w[3]*-27 + w[1]*-3 + w[2]*9 + w[4]*81 + w[0]*1) / 720;
- V[6] = (w[1]*3 + w[2]*9 + w[3]*27 + w[4]*81 + w[0]*1) / 720;
- V[7] = (w[4]*1) / 1;
-
- // Store the transformed weights
- for (int j = 0; j < inner_tile_cols; j++)
- {
- *(outptr + j*matrix_stride) = V[j];
- }
- outptr++;
- }
- }
-}
-
-template class WeightTransform<1, 5, 1, 8, float, float, WinogradRoots::Integers>;
-template class WeightTransform<5, 1, 8, 1, float, float, WinogradRoots::Integers>;
-
-} // namespace winograd
diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_4x4_3x3_fp32_fp32_integers.cpp b/src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_4x4_3x3_fp32_fp32_integers.cpp
deleted file mode 100644
index 7c2c718bd5..0000000000
--- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_4x4_3x3_fp32_fp32_integers.cpp
+++ /dev/null
@@ -1,257 +0,0 @@
-/*
- * Copyright (c) 2019 Arm Limited.
- *
- * SPDX-License-Identifier: MIT
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#include "arm.hpp"
-#include "kernel.hpp"
-
-namespace winograd
-{
-
-template <>
-void WeightTransform<3, 3, 6, 6, float, float, WinogradRoots::Integers>::execute(
- const int n_output_channels,
- const int n_input_channels,
- const float* const input, // NOTE: Data in HWIO order
- float* const output,
- const int matrix_stride,
- const int matrix_row_stride
-)
-{
- // Get pointers to each cell of the weight tensor
- const auto weight_col_stride = n_input_channels * n_output_channels;
- const auto weight_row_stride = 3 * weight_col_stride;
- const float *inptrs[3][3];
- for (int i = 0; i < 3; i++)
- {
- for (int j = 0; j < 3; j++)
- {
- inptrs[i][j] = input + i*weight_row_stride + j*weight_col_stride;
- }
- }
-
- // For each input channel
- for (int ic = 0; ic < n_input_channels; ic++)
- {
- float *outptr = output + ic * matrix_row_stride;
-
- // For each output channel
- int channels_remaining = n_output_channels;
-#ifdef __aarch64__
- for (; channels_remaining >= 4; channels_remaining -= 4)
- {
- // Matrices used and computed in this kernel
- float32x4_t w[3][3], Ww[6][3], V[6][6];
-
- // Read weights
- for (int i = 0; i < 3; i++)
- {
- for (int j = 0; j < 3; j++)
- {
- w[i][j] = vld1q_f32(inptrs[i][j]);
- inptrs[i][j] += 4;
- }
- }
-
- // Compute the matrix W w
- for (int j = 0; j < 3; j++)
- {
- // Ww[0][j] = 6*w[0][j];
- Ww[0][j] = vmulq_n_f32(w[0][j], 6.0);
-
- // Ww[1][j] = -4*w[0][j] + -4*w[1][j] + -4*w[2][j];
- Ww[1][j] = vmulq_n_f32(vaddq_f32(vaddq_f32(w[0][j], w[1][j]), w[2][j]), -4.0);
-
- // Ww[2][j] = -4*w[0][j] + 4*w[1][j] + -4*w[2][j];
- Ww[2][j] = vmulq_n_f32(vsubq_f32(vsubq_f32(w[1][j], w[0][j]), w[2][j]), 4.0);
-
- // Ww[3][j] = 1*w[0][j] + 2*w[1][j] + 4*w[2][j];
- Ww[3][j] = vmlaq_n_f32(vmlaq_n_f32(w[0][j], w[1][j], 2.0f), w[2][j], 4.0f);
-
- // Ww[4][j] = 1*w[0][j] + -2*w[1][j] + 4*w[2][j];
- Ww[4][j] = vmlaq_n_f32(vmlsq_n_f32(w[0][j], w[1][j], 2.0f), w[2][j], 4.0f);
-
- // Ww[5][j] = 24*w[2][j];
- Ww[5][j] = vmulq_n_f32(w[2][j], 24.0f);
- }
-
- // Compute V = W w WT
- for (int i = 0; i < 6; i++)
- {
- const float recip576 = 1.0f / 576.0f;
-
- // V[i][0] = 6*Ww[i][0];
- V[i][0] = vmulq_n_f32(vmulq_n_f32(Ww[i][0], 6.0), recip576);
-
- // V[i][1] = -4*Ww[i][0] + -4*Ww[i][1] + -4*Ww[i][2];
- V[i][1] = vmulq_n_f32(vmulq_n_f32(vaddq_f32(vaddq_f32(Ww[i][0], Ww[i][1]), Ww[i][2]), -4.0), recip576);
-
- // V[i][2] = -4*Ww[i][0] + 4*Ww[i][1] + -4*Ww[i][2];
- V[i][2] = vmulq_n_f32(vmulq_n_f32(vsubq_f32(vsubq_f32(Ww[i][1], Ww[i][0]), Ww[i][2]), 4.0), recip576);
-
- // V[i][3] = 1*Ww[i][0] + 2*Ww[i][1] + 4*Ww[i][2];
- V[i][3] = vmulq_n_f32(vmlaq_n_f32(vmlaq_n_f32(Ww[i][0], Ww[i][1], 2.0f), Ww[i][2], 4.0f), recip576);
-
- // V[i][4] = 1*Ww[i][0] + -2*Ww[i][1] + 4*Ww[i][2];
- V[i][4] = vmulq_n_f32(vmlaq_n_f32(vmlsq_n_f32(Ww[i][0], Ww[i][1], 2.0f), Ww[i][2], 4.0f), recip576);
-
- // V[i][5] = 24*Ww[i][2];
- V[i][5] = vmulq_n_f32(vmulq_n_f32(Ww[i][2], 24.0f), recip576);
- }
-
- // Store the transformed weights
- for (int i = 0, m = 0; i < 6; i++)
- {
- for (int j = 0; j < 6; j++, m++)
- {
- vst1q_f32(outptr + m*matrix_stride, V[i][j]);
- }
- }
- outptr += 4;
- }
-#endif // __aarch64__
-#ifdef __arm_any__
- for (; channels_remaining >= 2; channels_remaining -= 2)
- {
- // Matrices used and computed in this kernel
- float32x2_t w[3][3], Ww[6][3], V[6][6];
-
- // Read weights
- for (int i = 0; i < 3; i++)
- {
- for (int j = 0; j < 3; j++)
- {
- w[i][j] = vld1_f32(inptrs[i][j]);
- inptrs[i][j] += 2;
- }
- }
-
- // Compute the matrix W w
- for (int j = 0; j < 3; j++)
- {
- // Ww[0][j] = 6*w[0][j];
- Ww[0][j] = vmul_n_f32(w[0][j], 6.0);
-
- // Ww[1][j] = -4*w[0][j] + -4*w[1][j] + -4*w[2][j];
- Ww[1][j] = vmul_n_f32(vadd_f32(vadd_f32(w[0][j], w[1][j]), w[2][j]), -4.0);
-
- // Ww[2][j] = -4*w[0][j] + 4*w[1][j] + -4*w[2][j];
- Ww[2][j] = vmul_n_f32(vsub_f32(vsub_f32(w[1][j], w[0][j]), w[2][j]), 4.0);
-
- // Ww[3][j] = 1*w[0][j] + 2*w[1][j] + 4*w[2][j];
- Ww[3][j] = vmla_n_f32(vmla_n_f32(w[0][j], w[1][j], 2.0f), w[2][j], 4.0f);
-
- // Ww[4][j] = 1*w[0][j] + -2*w[1][j] + 4*w[2][j];
- Ww[4][j] = vmla_n_f32(vmls_n_f32(w[0][j], w[1][j], 2.0f), w[2][j], 4.0f);
-
- // Ww[5][j] = 24*w[2][j];
- Ww[5][j] = vmul_n_f32(w[2][j], 24.0f);
- }
-
- // Compute V = W w WT
- for (int i = 0; i < 6; i++)
- {
- const float recip576 = 1.0f / 576.0f;
-
- // V[i][0] = 6*Ww[i][0];
- V[i][0] = vmul_n_f32(vmul_n_f32(Ww[i][0], 6.0), recip576);
-
- // V[i][1] = -4*Ww[i][0] + -4*Ww[i][1] + -4*Ww[i][2];
- V[i][1] = vmul_n_f32(vmul_n_f32(vadd_f32(vadd_f32(Ww[i][0], Ww[i][1]), Ww[i][2]), -4.0), recip576);
-
- // V[i][2] = -4*Ww[i][0] + 4*Ww[i][1] + -4*Ww[i][2];
- V[i][2] = vmul_n_f32(vmul_n_f32(vsub_f32(vsub_f32(Ww[i][1], Ww[i][0]), Ww[i][2]), 4.0), recip576);
-
- // V[i][3] = 1*Ww[i][0] + 2*Ww[i][1] + 4*Ww[i][2];
- V[i][3] = vmul_n_f32(vmla_n_f32(vmla_n_f32(Ww[i][0], Ww[i][1], 2.0f), Ww[i][2], 4.0f), recip576);
-
- // V[i][4] = 1*Ww[i][0] + -2*Ww[i][1] + 4*Ww[i][2];
- V[i][4] = vmul_n_f32(vmla_n_f32(vmls_n_f32(Ww[i][0], Ww[i][1], 2.0f), Ww[i][2], 4.0f), recip576);
-
- // V[i][5] = 24*Ww[i][2];
- V[i][5] = vmul_n_f32(vmul_n_f32(Ww[i][2], 24.0f), recip576);
- }
-
- // Store the transformed weights
- for (int i = 0, m = 0; i < 6; i++)
- {
- for (int j = 0; j < 6; j++, m++)
- {
- vst1_f32(outptr + m*matrix_stride, V[i][j]);
- }
- }
- outptr += 2;
- }
-#endif // __arm_any__
- for (; channels_remaining; channels_remaining--)
- {
- // Matrices used and computed in this kernel
- float w[3][3], Ww[6][3], V[6][6];
-
- // Read weights
- for (int i = 0; i < 3; i++)
- {
- for (int j = 0; j < 3; j++)
- {
- w[i][j] = *(inptrs[i][j]++);
- }
- }
-
- // Compute the matrix W w
- for (int j = 0; j < 3; j++)
- {
- Ww[0][j] = 6*w[0][j];
- Ww[1][j] = -4*w[0][j] + -4*w[1][j] + -4*w[2][j];
- Ww[2][j] = -4*w[0][j] + 4*w[1][j] + -4*w[2][j];
- Ww[3][j] = 1*w[0][j] + 2*w[1][j] + 4*w[2][j];
- Ww[4][j] = 1*w[0][j] + -2*w[1][j] + 4*w[2][j];
- Ww[5][j] = 24*w[2][j];
- }
-
- // Compute V = W w WT
- for (int i = 0; i < 6; i++)
- {
- V[i][0] = ( 6*Ww[i][0]) / 576.0;
- V[i][1] = (-4*Ww[i][0] + -4*Ww[i][1] + -4*Ww[i][2]) / 576.0;
- V[i][2] = (-4*Ww[i][0] + 4*Ww[i][1] + -4*Ww[i][2]) / 576.0;
- V[i][3] = ( 1*Ww[i][0] + 2*Ww[i][1] + 4*Ww[i][2]) / 576.0;
- V[i][4] = ( 1*Ww[i][0] + -2*Ww[i][1] + 4*Ww[i][2]) / 576.0;
- V[i][5] = (24*Ww[i][2]) / 576.0;
- }
-
- // Store the transformed weights
- for (int i = 0, m = 0; i < 6; i++)
- {
- for (int j = 0; j < 6; j++, m++)
- {
- *(outptr + m*matrix_stride) = V[i][j];
- }
- }
- outptr++;
- }
- }
-}
-
-template class WeightTransform<3, 3, 6, 6, float, float, WinogradRoots::Integers>;
-
-} // namespace
diff --git a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_6_3_fp32_fp32_integers.cpp b/src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_6_3_fp32_fp32_integers.cpp
deleted file mode 100644
index 9b42224eaf..0000000000
--- a/src/core/NEON/kernels/convolution/winograd/winograd_transforms/weights_6_3_fp32_fp32_integers.cpp
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright (c) 2019 Arm Limited.
- *
- * SPDX-License-Identifier: MIT
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#include "arm.hpp"
-#include "kernel.hpp"
-
-namespace winograd
-{
-
-template <>
-void WeightTransform<1, 3, 1, 8, float, float, WinogradRoots::Integers>::execute(
- const int n_output_channels,
- const int n_input_channels,
- const float* const input, // NOTE: Data in HWIO order
- float* const output,
- const int matrix_stride,
- const int matrix_row_stride
-)
-{
- // Get pointers to each cell of the weight tensor
- const auto weight_col_stride = n_input_channels * n_output_channels;
- const float *inptrs[3];
- for (int j = 0; j < 3; j++)
- {
- inptrs[j] = input + j*weight_col_stride;
- }
-
- // For each input channel
- for (int ic = 0; ic < n_input_channels; ic++)
- {
- float *outptr = output + ic * matrix_row_stride;
-
- // For each output channel
- int channels_remaining = n_output_channels;
- for (; channels_remaining; channels_remaining--)
- {
- // Matrices used and computed in this kernel
- float w[3], V[inner_tile_cols];
-
- // Read weights
- for (int j = 0; j < 3; j++)
- {
- w[j] = *(inptrs[j]++);
- }
-
- // Compute V = w WT
- V[0] = (w[0]*-1) / 36.0f;
- V[1] = (w[1]*-1 + w[0]*1 + w[2]*1) / 48.0f;
- V[2] = (w[0]*1 + w[1]*1 + w[2]*1) / 48.0f;
- V[3] = (w[0]*-1 + w[2]*-4 + w[1]*2) / 120.0f;
- V[4] = (w[0]*-1 + w[2]*-4 + w[1]*-2) / 120.0f;
- V[5] = (w[1]*-3 + w[2]*9 + w[0]*1) / 720.0f;
- V[6] = (w[1]*3 + w[2]*9 + w[0]*1) / 720.0f;
- V[7] = (w[2]*1) / 1;
-
- // Store the transformed weights
- for (int j = 0; j < inner_tile_cols; j++)
- {
- *(outptr + j*matrix_stride) = V[j];
- }
- outptr++;
- }
- }
-}
-
-template class WeightTransform<1, 3, 1, 8, float, float, WinogradRoots::Integers>;
-template class WeightTransform<3, 1, 8, 1, float, float, WinogradRoots::Integers>;
-
-} // namespace
diff --git a/src/cpu/kernels/CpuWinogradConv2dKernel.cpp b/src/cpu/kernels/CpuWinogradConv2dKernel.cpp
index 803af09a67..818d878119 100644
--- a/src/cpu/kernels/CpuWinogradConv2dKernel.cpp
+++ b/src/cpu/kernels/CpuWinogradConv2dKernel.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2021 Arm Limited.
+ * Copyright (c) 2017-2022 Arm Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -21,531 +21,95 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-#include "src/cpu/kernels/CpuWinogradConv2dKernel.h"
-
-#include "arm_compute/core/Error.h"
-#include "arm_compute/core/Helpers.h"
-#include "arm_compute/core/ITensor.h"
-#include "arm_compute/core/TensorInfo.h"
-#include "arm_compute/core/Validate.h"
-#include "arm_compute/core/Window.h"
-#include "arm_compute/core/utils/misc/ShapeCalculator.h"
-#include "src/core/NEON/kernels/convolution/common/utils.hpp"
-#include "src/core/NEON/kernels/convolution/winograd/winograd_layer.hpp"
-#include "src/core/helpers/AutoConfiguration.h"
-#include "src/core/helpers/WindowHelpers.h"
-#include <memory>
+#include "src/cpu/kernels/CpuWinogradConv2dKernel.h"
namespace arm_compute
{
namespace cpu
{
-//Batched Gemms
-
-namespace
-{
-inline bool is_kernel_size_supported(DataType data_type, Size2D size)
+CpuWinogradConv2dTransformInputKernel::CpuWinogradConv2dTransformInputKernel(arm_conv::winograd::WinogradImpl &w_impl, arm_conv::ConvolutionArgs &_c_args, uint32_t nthreads)
+ : _winograd_impl{ w_impl }, _conv_args{ _c_args }, _nthreads{ nthreads }
{
- const std::array<Size2D, 8> f32_support = { { Size2D(1, 3), Size2D(3, 1), Size2D(5, 5), Size2D(3, 3), Size2D(1, 5), Size2D(5, 1), Size2D(7, 1), Size2D(1, 7) } };
- const std::array<Size2D, 8> f16_support = { { Size2D(3, 3) } };
-
- switch(data_type)
- {
- case DataType::F16:
- return std::end(f16_support) != std::find(std::begin(f16_support), std::end(f16_support), size);
- case DataType::F32:
- return std::end(f32_support) != std::find(std::begin(f32_support), std::end(f32_support), size);
- default:
- return false;
- }
}
-Status validate_arguments_winograd_weight_trans(const ITensorInfo *input, const ITensorInfo *output, const WinogradInfo &winograd_info)
+void CpuWinogradConv2dTransformInputKernel::run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info)
{
- ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input);
- ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(output);
- ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::F16, DataType::F32);
+ ARM_COMPUTE_UNUSED(window);
+ const ITensor *input_nhwc = tensors.get_const_tensor(TensorType::ACL_SRC);
+ const ITensor *winograd_input_transform = tensors.get_const_tensor(TensorType::ACL_DST);
+ const ITensor *workspace = tensors.get_const_tensor(TensorType::ACL_INT);
- const size_t idx_width = get_data_layout_dimension_index(input->data_layout(), DataLayoutDimension::WIDTH);
- const size_t idx_height = get_data_layout_dimension_index(input->data_layout(), DataLayoutDimension::HEIGHT);
- const auto input_width = input->dimension(idx_width);
- const auto input_height = input->dimension(idx_height);
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(!is_kernel_size_supported(input->data_type(), Size2D(input_width, input_height)),
- "Only 1x3, 3x1, 1x5, 5x1, 7x1, 1x7, 3x3 and 5x5 kernels are supported");
- ARM_COMPUTE_RETURN_ERROR_ON(input->num_dimensions() > 4);
- const Size2D &output_tile = winograd_info.output_tile_size;
- const std::array<Size2D, 8> supported_tile_sizes = { { Size2D(2U, 2U), Size2D(4U, 4U), Size2D(1U, 6U), Size2D(6U, 1U), Size2D(4, 1), Size2D(1, 4), Size2D(2, 1), Size2D(1, 2) } };
- ARM_COMPUTE_RETURN_ERROR_ON(std::end(supported_tile_sizes) == std::find(std::begin(supported_tile_sizes), std::end(supported_tile_sizes), output_tile));
+ const unsigned int width_idx = 1;
+ const unsigned int height_idx = 2;
+ const unsigned int batch_idx = 3;
+ int element_size_in_bytes = input_nhwc->info()->element_size();
+ const auto src_strides = input_nhwc->info()->strides_in_bytes();
- // Checks performed when output is configured
- if(output->total_size() != 0)
- {
- const TensorInfo tensor_info_output = input->clone()->set_tensor_shape(arm_compute::misc::shape_calculator::compute_winograd_filter_transform_shape(*input, winograd_info));
+ const size_t input_row_stride = src_strides[height_idx] / element_size_in_bytes;
+ const size_t input_col_stride = src_strides[width_idx] / element_size_in_bytes;
+ const size_t input_batch_stride = src_strides[batch_idx] / element_size_in_bytes;
+ const auto input_nhwc_ptr = reinterpret_cast<const void *>(input_nhwc->buffer() + input_nhwc->info()->offset_first_element_in_bytes());
+ auto win_transf_ptr = reinterpret_cast<void *>(winograd_input_transform->buffer() + winograd_input_transform->info()->offset_first_element_in_bytes());
- ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(output, &tensor_info_output);
- ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
- }
-
- return Status{};
+ _winograd_impl.input_transform->execute(
+ _conv_args,
+ input_nhwc_ptr,
+ input_batch_stride,
+ input_row_stride,
+ input_col_stride,
+ win_transf_ptr,
+ _winograd_impl.winograd_spec,
+ workspace->buffer(),
+ info.thread_id,
+ _nthreads);
}
-std::pair<Status, Window> validate_and_configure_window_winograd_weight_trans(ITensorInfo *input, ITensorInfo *output, const WinogradInfo &winograd_info)
+CpuWinogradConv2dTransformOutputKernel::CpuWinogradConv2dTransformOutputKernel(arm_conv::winograd::WinogradImpl &w_impl, arm_conv::ConvolutionArgs &_c_args, uint32_t nthreads)
+ : _winograd_impl{ w_impl }, _conv_args{ _c_args }, _nthreads{ nthreads }
{
- // Output tensor auto inizialitation if not yet initialized
- auto_init_if_empty(*output, input->clone()->set_tensor_shape(arm_compute::misc::shape_calculator::compute_winograd_filter_transform_shape(*input, winograd_info)));
- const Window win = calculate_max_window(*input, Steps(), true /* skip border*/);
- return std::make_pair(Status{}, win);
}
-Status validate_arguments_winograd_input_trans(const ITensorInfo *input, const ITensorInfo *output, const WinogradInfo &winograd_info)
+// Inherited methods overridden:
+void CpuWinogradConv2dTransformOutputKernel::run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info)
{
- const Size2D &kernel_dims = winograd_info.kernel_size;
- const PadStrideInfo &conv_info = winograd_info.convolution_info;
- ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input);
- ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(output);
- ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::F16, DataType::F32);
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(conv_info.stride().first != 1 || conv_info.stride().second != 1, "Winograd input transform only supports unit strides");
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(!is_kernel_size_supported(input->data_type(), Size2D(kernel_dims.width, kernel_dims.height)),
- "Only 1x3, 3x1, 3x3 and 5x5 kernels are supported");
-
- // Validate configured output
- if(output->total_size() != 0)
- {
- const TensorShape output_shape = misc::shape_calculator::compute_winograd_input_transform_shape(*input, winograd_info);
+ ARM_COMPUTE_UNUSED(window);
+ const ITensor *dst_nhwc = tensors.get_const_tensor(TensorType::ACL_DST);
+ const ITensor *winograd_output_transform = tensors.get_const_tensor(TensorType::ACL_SRC_0);
+ const ITensor *biases = tensors.get_const_tensor(TensorType::ACL_SRC_1);
+ const ITensor *workspace = tensors.get_tensor(TensorType::ACL_INT);
- ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS(output->tensor_shape(), output_shape);
- ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
- }
-
- return Status{};
-}
+ const unsigned int width_idx = 1;
+ const unsigned int height_idx = 2;
+ const unsigned int batch_idx = 3;
+ const int element_size_in_bytes = dst_nhwc->info()->element_size();
+ const auto dst_strides = dst_nhwc->info()->strides_in_bytes();
-std::pair<Status, Window> validate_and_configure_window_winograd_input_trans(ITensorInfo *input, ITensorInfo *output, const WinogradInfo &winograd_info)
-{
- const TensorShape output_shape = misc::shape_calculator::compute_winograd_input_transform_shape(*input, winograd_info);
- // Output auto inizialitation if not yet initialized
- auto_init_if_empty(*output, input->clone()->set_tensor_shape(output_shape));
- return std::make_pair(Status{}, calculate_max_window(*input, Steps(), true));
-}
-
-Status validate_arguments_winograd_output_trans(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const WinogradInfo &winograd_info)
-{
- const PadStrideInfo &conv_info = winograd_info.convolution_info;
- const Size2D kernel_dims = winograd_info.kernel_size;
-
- // Number of tiles along the X and Y direction
- const unsigned int num_tiles_x = std::ceil((winograd_info.input_dimensions.x() - (kernel_dims.width - 1) + conv_info.pad_left() + conv_info.pad_right()) / static_cast<float>
- (winograd_info.output_tile_size.width));
- const unsigned int num_tiles_y = std::ceil((winograd_info.input_dimensions.y() - (kernel_dims.height - 1) + conv_info.pad_top() + conv_info.pad_bottom()) / static_cast<float>
- (winograd_info.output_tile_size.height));
- const Size2D num_tiles = Size2D(num_tiles_x, num_tiles_y);
-
- ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input);
- ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(output);
- ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::F16, DataType::F32);
- ARM_COMPUTE_RETURN_ERROR_ON(input->dimension(1) != num_tiles.area());
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(!is_kernel_size_supported(input->data_type(), Size2D(kernel_dims.width, kernel_dims.height)),
- "Only 1x3, 3x1, 3x3 and 5x5 kernels are supported");
-
- const std::array<unsigned int, 3> supported_gemm_sizes = { { 8U, 16U, 36U } };
- ARM_COMPUTE_RETURN_ERROR_ON(std::end(supported_gemm_sizes) == std::find(std::begin(supported_gemm_sizes), std::end(supported_gemm_sizes), input->dimension(2)));
- ARM_COMPUTE_UNUSED(kernel_dims);
- if(bias != nullptr)
- {
- ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, bias);
- ARM_COMPUTE_RETURN_ERROR_ON(input->dimension(0) != bias->dimension(0));
- ARM_COMPUTE_RETURN_ERROR_ON(bias->num_dimensions() != size_t(1));
- }
-
- // Checks performed when output is configured
- if(output->total_size() != 0)
+ const size_t out_row_stride = dst_strides[height_idx] / element_size_in_bytes;
+ const size_t out_col_stride = dst_strides[width_idx] / element_size_in_bytes;
+ const size_t out_batch_stride = dst_strides[batch_idx] / element_size_in_bytes;
+ const auto wout_transf_ptr = reinterpret_cast<const void *>(winograd_output_transform->buffer() + winograd_output_transform->info()->offset_first_element_in_bytes());
+ auto dst_nhwc_ptr = reinterpret_cast<void *>(dst_nhwc->buffer() + dst_nhwc->info()->offset_first_element_in_bytes());
+ void *biases_data_ptr = nullptr;
+ if(biases != nullptr)
{
- const TensorInfo tensor_info_output = input->clone()->set_tensor_shape(arm_compute::misc::shape_calculator::compute_winograd_output_transform_shape(*input, winograd_info));
- ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(output, &tensor_info_output);
- ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
+ biases_data_ptr = reinterpret_cast<void *>(biases->buffer() + biases->info()->offset_first_element_in_bytes());
}
- return Status{};
-}
-
-std::pair<Status, Window> validate_and_configure_window_winograd_output_trans(ITensorInfo *input, ITensorInfo *output, const WinogradInfo &winograd_info)
-{
- // Output tensor auto initialization if not yet initialized
- auto_init_if_empty(*output, input->clone()->set_tensor_shape(arm_compute::misc::shape_calculator::compute_winograd_output_transform_shape(*input, winograd_info)));
-
- return std::make_pair(Status{}, calculate_max_window(*input, Steps(), true));
-}
-} // namespace
-
-Status ICpuWinogradConv2dTransformWeightsKernel::validate(const ITensorInfo *input, const ITensorInfo *weights)
-{
- ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::F16, DataType::F32);
- ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, weights);
- const DataLayout data_layout = input->data_layout();
- const unsigned int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
- const unsigned int height_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(!is_kernel_size_supported(input->data_type(), Size2D(weights->dimension(width_idx), weights->dimension(height_idx))),
- "Only 1x3, 3x1, 3x3 and 5x5 kernels are supported");
- ARM_COMPUTE_RETURN_ERROR_ON(weights->num_dimensions() > 4);
- return Status{};
-}
-
-template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
-unsigned int CpuWinogradConv2dTransformWeightsKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::get_weight_storage_size(int num_output_channels, int num_input_channels) const
-{
- const KernelShape shape(num_output_channels, KernelRows, KernelCols, num_input_channels);
- // WinogradConv returns the size in bytes, we divide by `sizeof(T)` to express that in units of T
- return static_cast<unsigned int>(WinogradConv::get_kernel_storage_size(num_input_channels, num_output_channels) / sizeof(T));
-}
-
-template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
-CpuWinogradConv2dTransformWeightsKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::CpuWinogradConv2dTransformWeightsKernel()
- : _transform(nullptr), _num_output_channels(0), _matrix_stride(0)
-{
-}
-
-template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
-int CpuWinogradConv2dTransformWeightsKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::get_matrix_stride(int num_output_channels, int num_input_channels) const
-{
- return WinogradConv::get_kernel_matrix_stride(num_input_channels, num_output_channels);
-}
-
-#ifndef DOXYGEN_SKIP_THIS
-template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
-void CpuWinogradConv2dTransformWeightsKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::configure(
- const ITensorInfo *weights_hwio,
- ITensorInfo *output,
- const int matrix_stride, /** Stride across matrices in the output. */
- const int num_output_channels, /** Number of filters. */
- const int num_input_channels) /** Number of channels in each filter. */
-{
- ARM_COMPUTE_UNUSED(weights_hwio, output);
-
- _transform = std::make_unique<WeightsTransform>(num_output_channels, num_input_channels);
- _num_output_channels = num_output_channels;
- _matrix_stride = matrix_stride;
-
- Window win;
- auto win_last = _transform->get_window();
- win.set(Window::DimX, Window::Dimension(0, win_last, 1));
- ICpuKernel::configure(win);
-}
-#endif /* DOXYGEN_SKIP_THIS */
-
-template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
-void CpuWinogradConv2dTransformWeightsKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info)
-{
- ARM_COMPUTE_UNUSED(info);
- ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
- ARM_COMPUTE_ERROR_ON(tensors.empty());
-
- const size_t fst = window.x().start();
- const size_t lst = window.x().end();
-
- const ITensor *weights_hwio = tensors.get_const_tensor(TensorType::ACL_SRC);
- ITensor *output = tensors.get_tensor(TensorType::ACL_DST);
-
- _transform->set_weight_tensor(weights_hwio->buffer());
- const int matrix_row_stride = roundup(_num_output_channels, WinogradConv::N_BLOCK);
- _transform->set_output_matrices(output->buffer(), _matrix_stride, matrix_row_stride);
- _transform->set_working_space(output->buffer());
-
- _transform->run(fst, lst);
-}
-
-template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
-bool CpuWinogradConv2dTransformWeightsKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::is_parallelisable() const
-{
- return false;
-}
-
-template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
-Status CpuWinogradConv2dTransformWeightsKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::validate(const ITensorInfo *input, const ITensorInfo *output,
- const WinogradInfo &winograd_info)
-{
- ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments_winograd_weight_trans(input, output, winograd_info));
- ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window_winograd_weight_trans(input->clone().get(), output->clone().get(), winograd_info).first);
- return Status{};
-}
-
-template class CpuWinogradConv2dTransformWeightsKernel<float, 2, 2, 3, 3>;
-template class CpuWinogradConv2dTransformWeightsKernel<float, 4, 4, 3, 3>;
-template class CpuWinogradConv2dTransformWeightsKernel<float, 2, 2, 5, 5>;
-template class CpuWinogradConv2dTransformWeightsKernel<float, 1, 6, 1, 3>;
-template class CpuWinogradConv2dTransformWeightsKernel<float, 6, 1, 3, 1>;
-
-template class CpuWinogradConv2dTransformWeightsKernel<float, 1, 4, 1, 5>;
-template class CpuWinogradConv2dTransformWeightsKernel<float, 4, 1, 5, 1>;
-template class CpuWinogradConv2dTransformWeightsKernel<float, 1, 2, 1, 7>;
-template class CpuWinogradConv2dTransformWeightsKernel<float, 2, 1, 7, 1>;
-
-#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
-template class CpuWinogradConv2dTransformWeightsKernel<__fp16, 4, 4, 3, 3>;
-#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
-
-// Input transform
-
-template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
-unsigned int CpuWinogradConv2dTransformInputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::get_input_storage_size(
- int num_batches, /* Number of batches in the input tensor. */
- int num_channels, /* Number of feature maps in the input tensor. */
- int num_rows, /* Number of rows in each feature map. */
- int num_cols, /* Number of columns in each feature map. */
- bool same_padding /* Use "SAME" padding, otherwise use "VALID". */
-) const
-{
- // Construct shapes for the input and kernel tensors.
- const Tensor4DShape input_shape(num_batches, num_rows, num_cols, num_channels);
- const KernelShape kern_shape(1, KernelRows, KernelCols, num_channels);
- // Return the size, converted into units of TIn
- return static_cast<unsigned int>(WinogradConv::get_input_storage_size(num_batches, num_rows, num_cols, num_channels, same_padding) / sizeof(T));
-}
-
-template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
-unsigned int CpuWinogradConv2dTransformInputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::get_working_space_size(unsigned int num_threads) const
-{
- return _transform->get_working_space_size(num_threads);
-}
-
-template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
-int CpuWinogradConv2dTransformInputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::get_matrix_stride(
- int num_batches, /* Number of batches in the input tensor. */
- int num_channels, /* Number of feature maps in the input tensor. */
- int num_rows, /* Number of rows in each feature map. */
- int num_cols, /* Number of columns in each feature map. */
- bool same_padding /* Use "SAME" padding, otherwise use "VALID". */) const
-{
- return WinogradConv::get_input_matrix_stride(num_batches, num_rows, num_cols, num_channels, same_padding);
-}
-
-template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
-CpuWinogradConv2dTransformInputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::CpuWinogradConv2dTransformInputKernel()
- : _transform(nullptr), _num_channels(0), _matrix_stride(0)
-{
-}
-
-template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
-void CpuWinogradConv2dTransformInputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::configure(
- const ITensorInfo *input_nhwc,
- const int num_batches, /* Number of batches in input tensor. */
- const int num_rows, /* Number of rows in input tensor. */
- const int num_cols, /* Number of columns in input tensor. */
- const int num_channels, /* Number of channels in input tensor. */
- const PaddingType padding, /* Padding type. */
- ITensorInfo *output, /* Base of output matrices. */
- const int matrix_stride, /* Stride between output matrices. */
- ITensorInfo *workspace)
-{
- ARM_COMPUTE_UNUSED(input_nhwc, output, matrix_stride, workspace);
-
- _num_channels = num_channels;
- _matrix_stride = matrix_stride;
-
- const int padding_top = (padding == PADDING_SAME) ? (KernelRows - 1) / 2 : 0;
- const int padding_left = (padding == PADDING_SAME) ? (KernelCols - 1) / 2 : 0;
- const int padding_bottom = (padding == PADDING_SAME) ? iceildiv(KernelRows - 1, 2) : 0;
- const int padding_right = (padding == PADDING_SAME) ? iceildiv(KernelCols - 1, 2) : 0;
-
- _transform = std::make_unique<InputTransform>(
- KernelRows,
- KernelCols,
- num_batches,
- num_rows,
- num_cols,
- num_channels,
- padding_top, /**< Padding to apply to the top of the image. */
- padding_left, /**< Padding to apply to the left of the image. */
- padding_bottom, /**< Padding to apply to the bottom of the image. */
- padding_right /**< Padding to apply to the right of the image. */
- );
-
- Window win;
- auto win_last = _transform->get_window();
- win.set(Window::DimX, Window::Dimension(0, win_last, 1));
- ICpuKernel::configure(win);
-}
-
-template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
-void CpuWinogradConv2dTransformInputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info)
-{
- ARM_COMPUTE_UNUSED(info);
- ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
- ARM_COMPUTE_ERROR_ON(tensors.empty());
-
- const ITensor *input_nhwc = tensors.get_const_tensor(TensorType::ACL_SRC);
- const ITensor *workspace = tensors.get_const_tensor(TensorType::ACL_INT);
- ITensor *output = tensors.get_tensor(TensorType::ACL_DST);
-
- const int element_size_in_bytes = input_nhwc->info()->element_size();
- const int input_col_stride = input_nhwc->info()->strides_in_bytes().y() / element_size_in_bytes;
- const int input_row_stride = input_nhwc->info()->strides_in_bytes().z() / element_size_in_bytes;
- const int input_batch_stride = input_nhwc->info()->strides_in_bytes()[3] / element_size_in_bytes;
- const auto input_nhwc_ptr = reinterpret_cast<const T *>(input_nhwc->buffer() + input_nhwc->info()->offset_first_element_in_bytes());
- auto output_ptr = reinterpret_cast<T *>(output->buffer() + output->info()->offset_first_element_in_bytes());
- ARM_COMPUTE_ERROR_ON_NULLPTR(output_ptr);
-
- _transform->set_input_tensor(input_nhwc_ptr, input_batch_stride, input_row_stride, input_col_stride);
- _transform->set_output_matrices(output_ptr, _matrix_stride, _num_channels);
-
- _transform->set_working_space(workspace->buffer());
-
- // The code below cannot be moved to configure because biases hasn't been allocated at that point
- const size_t fst = window.x().start();
- const size_t lst = window.x().end();
- _transform->run(fst, lst, info.thread_id);
-}
-
-template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
-Status CpuWinogradConv2dTransformInputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::validate(const ITensorInfo *input, const ITensorInfo *output,
- const WinogradInfo &winograd_info)
-{
- ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments_winograd_input_trans(input, output, winograd_info));
- ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window_winograd_input_trans(input->clone().get(), output->clone().get(), winograd_info).first);
-
- return Status{};
-}
-
-template class CpuWinogradConv2dTransformInputKernel<float, 2, 2, 3, 3>;
-template class CpuWinogradConv2dTransformInputKernel<float, 4, 4, 3, 3>;
-template class CpuWinogradConv2dTransformInputKernel<float, 2, 2, 5, 5>;
-template class CpuWinogradConv2dTransformInputKernel<float, 1, 6, 1, 3>;
-template class CpuWinogradConv2dTransformInputKernel<float, 6, 1, 3, 1>;
-
-template class CpuWinogradConv2dTransformInputKernel<float, 1, 4, 1, 5>;
-template class CpuWinogradConv2dTransformInputKernel<float, 4, 1, 5, 1>;
-template class CpuWinogradConv2dTransformInputKernel<float, 1, 2, 1, 7>;
-template class CpuWinogradConv2dTransformInputKernel<float, 2, 1, 7, 1>;
-
-#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
-template class CpuWinogradConv2dTransformInputKernel<__fp16, 4, 4, 3, 3>;
-#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
-// Output transform
-
-template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
-unsigned int CpuWinogradConv2dTransformOutputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::get_output_storage_size(
- int num_batches, /* Number of batches in the output tensor. */
- int num_rows, /* Number of rows in each feature map of the input tensor. */
- int num_cols, /* Number of columns in each feature map of the input tensor. */
- int num_output_channels /* Number of feature maps in the output tensor. */
-) const
-{
- // Construct shapes for the input and kernel tensors.
- const Tensor4DShape input_shape(num_batches, num_rows, num_cols, 1);
- const KernelShape kern_shape(num_output_channels, KernelRows, KernelCols, 1);
- // Return the size, converted into units of TOut
- return static_cast<unsigned int>(
- WinogradConv::get_output_storage_size(num_batches, num_rows, num_cols, num_output_channels) / sizeof(T));
-}
-
-template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
-CpuWinogradConv2dTransformOutputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::CpuWinogradConv2dTransformOutputKernel()
- : _transform(nullptr), _matrix_stride(0), _matrix_row_stride(0)
-{
+ // Output transform
+ _winograd_impl.output_transform->execute(
+ _conv_args,
+ wout_transf_ptr,
+ _winograd_impl.winograd_spec,
+ biases_data_ptr,
+ dst_nhwc_ptr,
+ out_batch_stride,
+ out_row_stride,
+ out_col_stride,
+ workspace->buffer(),
+ info.thread_id,
+ _nthreads);
}
-template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
-unsigned int CpuWinogradConv2dTransformOutputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::get_working_space_size(unsigned int num_threads) const
-{
- return _transform->get_working_space_size(num_threads);
-}
-
-template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
-int CpuWinogradConv2dTransformOutputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::get_matrix_stride(
- int num_batches, /* Number of batches in the output tensor. */
- int num_rows, /* Number of rows in each feature map of the input tensor. */
- int num_cols, /* Number of columns in each feature map of the input tensor. */
- int num_output_channels /* Number of feature maps in the output tensor. */
-) const
-{
- return WinogradConv::get_output_matrix_stride(num_batches, num_rows, num_cols, num_output_channels);
-}
-
-template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
-std::pair<unsigned int, unsigned int> CpuWinogradConv2dTransformOutputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::get_output_shape(
- int num_rows, /* Number of rows in each feature map of the input tensor. */
- int num_cols, /* Number of columns in each feature map of the input tensor. */
- bool padding_same) const
-{
- return WinogradConv::get_output_shape(std::make_pair<unsigned int, unsigned int>(num_rows, num_cols), padding_same);
-}
-
-template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
-void CpuWinogradConv2dTransformOutputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::configure(
- const ITensorInfo *biases,
- const ITensorInfo *transformed_output,
- const int matrix_stride,
- ITensorInfo *output_nhwc,
- const int num_batches,
- const int num_rows,
- const int num_cols,
- const int num_channels,
- ITensorInfo *workspace,
- const arm_gemm::Activation &activation)
-{
- ARM_COMPUTE_UNUSED(biases, transformed_output, output_nhwc, num_batches, num_rows, num_cols, workspace, activation);
-
- _matrix_stride = matrix_stride;
- _matrix_row_stride = roundup(num_channels, WinogradConv::N_BLOCK);
-
- // We don't have the biases buffer at this stage as it hasn't been allocated, we pass in nullptr OutputTransform is only used here to compute the window
- _transform = std::make_unique<OutputTransform>(num_batches, num_rows, num_cols, num_channels, activation);
- Window win;
- auto win_last = _transform->get_window();
- win.set(Window::DimX, Window::Dimension(0, win_last, 1));
-
- ICpuKernel::configure(win);
-}
-
-template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
-void CpuWinogradConv2dTransformOutputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info)
-{
- ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
- ARM_COMPUTE_ERROR_ON(tensors.empty());
-
- const ITensor *biases = tensors.get_const_tensor(TensorType::ACL_SRC_0);
- const ITensor *transformed_output = tensors.get_const_tensor(TensorType::ACL_SRC_1);
- ITensor *workspace = tensors.get_tensor(TensorType::ACL_INT);
- ITensor *dst_nhwc = tensors.get_tensor(TensorType::ACL_DST);
-
- const int out_batch_stride = dst_nhwc->info()->strides_in_bytes()[3] / sizeof(T);
- const int out_row_stride = dst_nhwc->info()->strides_in_bytes()[2] / sizeof(T);
- const int out_col_stride = dst_nhwc->info()->strides_in_bytes()[1] / sizeof(T);
-
- _transform->set_input_matrices(transformed_output->buffer(), _matrix_stride, _matrix_row_stride);
- _transform->set_bias((biases ? reinterpret_cast<T *>(biases->buffer() + biases->info()->offset_first_element_in_bytes()) : nullptr));
- _transform->set_output_tensor(dst_nhwc->buffer() + dst_nhwc->info()->offset_first_element_in_bytes(), out_batch_stride, out_row_stride, out_col_stride);
- _transform->set_working_space(workspace->buffer());
-
- // The code below cannot be moved to configure because biases hasn't been allocated at that point
- const size_t fst = window.x().start();
- const size_t lst = window.x().end();
- _transform->run(fst, lst, info.thread_id);
-}
-
-template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
-Status CpuWinogradConv2dTransformOutputKernel<T, OutputTileRows, OutputTileCols, KernelRows, KernelCols>::validate(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output,
- const WinogradInfo &winograd_info)
-{
- ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments_winograd_output_trans(input, (bias != nullptr ? bias->clone().get() : nullptr), output, winograd_info));
- ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window_winograd_output_trans(input->clone().get(), output->clone().get(), winograd_info).first);
-
- return Status{};
-}
-
-template class CpuWinogradConv2dTransformOutputKernel<float, 2, 2, 3, 3>;
-template class CpuWinogradConv2dTransformOutputKernel<float, 4, 4, 3, 3>;
-template class CpuWinogradConv2dTransformOutputKernel<float, 2, 2, 5, 5>;
-template class CpuWinogradConv2dTransformOutputKernel<float, 1, 6, 1, 3>;
-template class CpuWinogradConv2dTransformOutputKernel<float, 6, 1, 3, 1>;
-
-template class CpuWinogradConv2dTransformOutputKernel<float, 1, 4, 1, 5>;
-template class CpuWinogradConv2dTransformOutputKernel<float, 4, 1, 5, 1>;
-template class CpuWinogradConv2dTransformOutputKernel<float, 1, 2, 1, 7>;
-template class CpuWinogradConv2dTransformOutputKernel<float, 2, 1, 7, 1>;
-
-#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
-template class CpuWinogradConv2dTransformOutputKernel<__fp16, 4, 4, 3, 3>;
-#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
} // namespace cpu
-} // namespace arm_compute
+} // namespace arm_compute \ No newline at end of file
diff --git a/src/cpu/kernels/CpuWinogradConv2dKernel.h b/src/cpu/kernels/CpuWinogradConv2dKernel.h
index 6909216d94..0170dcae22 100644
--- a/src/cpu/kernels/CpuWinogradConv2dKernel.h
+++ b/src/cpu/kernels/CpuWinogradConv2dKernel.h
@@ -24,550 +24,79 @@
#ifndef ARM_COMPUTE_CPUWINOGRADCONV2DKERNEL_H
#define ARM_COMPUTE_CPUWINOGRADCONV2DKERNEL_H
-#include "src/core/NEON/kernels/convolution/common/convolution.hpp"
+#include "arm_compute/core/Helpers.h"
+#include "arm_compute/core/ITensor.h"
+#include "arm_compute/core/ITensorPack.h"
+#include "arm_compute/core/Steps.h"
+#include "arm_compute/core/TensorInfo.h"
+#include "arm_compute/runtime/Tensor.h"
+#include "src/core/NEON/kernels/assembly/winograd.hpp"
#include "src/core/NEON/kernels/convolution/common/tensor.hpp"
#include "src/cpu/ICpuKernel.h"
-#include "src/core/NEON/kernels/convolution/winograd/winograd_layer.hpp"
-
namespace arm_compute
{
namespace cpu
{
-/** Interface for the kernel to perform Winograd input transform. */
-class ICpuWinogradConv2dTransformInputKernel : public ICpuKernel<ICpuWinogradConv2dTransformInputKernel>
-{
-public:
- /** Get the working space required to perform the transformation.
- *
- * Note, the working space is only required when performing the
- * transformation - hence it can be reused whenever the transformation is
- * not running.
- *
- * @param num_threads The greatest number of threads that will be used to execute the transform.
- * @return Size of working space required in bytes.
- */
- virtual unsigned int get_working_space_size(unsigned int num_threads) const = 0;
-
- /** Determine how much memory (in units of TIn) to allocate for the
- * transformed input.
- *
- * @param[in] num_batches Number of batches in the input tensor.
- * @param[in] num_channels Number of feature maps in the input tensor.
- * @param[in] num_rows Number of rows in each feature map.
- * @param[in] num_cols Number of columns in each feature map.
- * @param[in] same_padding Use "SAME" padding, otherwise use "VALID".
- *
- * @return Storage size (in units of TIn) required.
- */
- virtual unsigned int get_input_storage_size(int num_batches, int num_channels, int num_rows, int num_cols, bool same_padding) const = 0;
-
- /** Gets the stride between matrices in the input worspace
- *
- * @param[in] num_batches Number of batches in the input tensor.
- * @param[in] num_channels Number of feature maps in the input tensor.
- * @param[in] num_rows Number of rows in each feature map.
- * @param[in] num_cols Number of columns in each feature map.
- * @param[in] same_padding Use "SAME" padding, otherwise use "VALID".
- *
- * @return Stride expressed in bytes.
- */
- virtual int get_matrix_stride(int num_batches, int num_channels, int num_rows, int num_cols, bool same_padding) const = 0;
-
- /** Configure the output transform kernel.
- *
- * @param[in] input_nhwc Input tensor in NHWC data layout format.
- * @param[in] num_batches Number of batches in input tensor.
- * @param[in] num_rows Number of rows in input tensor.
- * @param[in] num_cols Number of columns in input tensor.
- * @param[in] num_channels Number of channels in input tensor.
- * @param[in] padding Padding type.
- * @param[out] output Base of output matrices.
- * @param[in] matrix_stride Stride between output matrices.
- * @param[in] workspace Tensor to be used as the working space during the computation.
- */
- virtual void configure(const ITensorInfo *input_nhwc, const int num_batches, const int num_rows, const int num_cols, const int num_channels,
- const PaddingType padding, ITensorInfo *output, const int matrix_stride, ITensorInfo *workspace) = 0;
-
- /** Destructor */
- virtual ~ICpuWinogradConv2dTransformInputKernel()
- {
- }
-};
-
-/** Kernel to perform Winograd input transform. */
-template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
-class CpuWinogradConv2dTransformInputKernel : public ICpuWinogradConv2dTransformInputKernel
+class CpuWinogradConv2dTransformInputKernel final : public ICpuKernel<CpuWinogradConv2dTransformInputKernel>
{
public:
/** Prevent instances of this class from being copied (As this class contains pointers) */
CpuWinogradConv2dTransformInputKernel(const CpuWinogradConv2dTransformInputKernel &) = delete;
+
/** Prevent instances of this class from being copied (As this class contains pointers) */
CpuWinogradConv2dTransformInputKernel &operator=(const CpuWinogradConv2dTransformInputKernel &) = delete;
- /** Allow instances of this class to be moved */
- CpuWinogradConv2dTransformInputKernel(CpuWinogradConv2dTransformInputKernel &&) = default;
- /** Allow instances of this class to be moved */
- CpuWinogradConv2dTransformInputKernel &operator=(CpuWinogradConv2dTransformInputKernel &&) = default;
- /** Default destructor */
- ~CpuWinogradConv2dTransformInputKernel() = default;
- /** Determine how much memory (in units of TIn) to allocate for the
- * transformed input.
- *
- * @param[in] num_batches Number of batches in the input tensor.
- * @param[in] num_channels Number of feature maps in the input tensor.
- * @param[in] num_rows Number of rows in each feature map.
- * @param[in] num_cols Number of columns in each feature map.
- * @param[in] same_padding Use "SAME" padding, otherwise use "VALID".
- *
- * @return Storage size (in units of TIn) required.
- */
- unsigned int get_input_storage_size(
- int num_batches,
- int num_channels,
- int num_rows,
- int num_cols,
- bool same_padding) const override;
+ /** Prevent instances of this class from being moved it contains references.*/
+ CpuWinogradConv2dTransformInputKernel(CpuWinogradConv2dTransformInputKernel &&) = delete;
- /** Get the working space required to perform the transformation.
- *
- * Note, the working space is only required when performing the
- * transformation - hence it can be reused whenever the transformation is
- * not running.
- *
- * @param[in] num_threads The greatest number of threads that will be used to execute the transform.
- *
- * @return Size of working space required in bytes.
- */
- unsigned int get_working_space_size(unsigned int num_threads) const override;
+ /** Prevent instances of this class from being moved it contains references.*/
+ CpuWinogradConv2dTransformInputKernel &operator=(CpuWinogradConv2dTransformInputKernel &&) = delete;
- /** Gets the stride between matrices in the input worspace
- *
- * @param[in] num_batches Number of batches in the input tensor.
- * @param[in] num_channels Number of feature maps in the input tensor.
- * @param[in] num_rows Number of rows in each feature map.
- * @param[in] num_cols Number of columns in each feature map.
- * @param[in] same_padding Use "SAME" padding, otherwise use "VALID".
- *
- * @return Stride expressed in bytes.
- */
- int get_matrix_stride(
- int num_batches,
- int num_channels,
- int num_rows,
- int num_cols,
- bool same_padding) const override;
+ CpuWinogradConv2dTransformInputKernel(arm_conv::winograd::WinogradImpl &w_impl, arm_conv::ConvolutionArgs &_c_args, uint32_t nthreads);
- /** Default constructor */
- CpuWinogradConv2dTransformInputKernel();
+ // Inherited methods overridden:
+ void run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override;
const char *name() const override
{
return "CpuWinogradConv2dTransformInputKernel";
}
- /** Configure the output transform kernel.
- *
- * @param[in] input_nhwc Input tensor. Data types supported: F16/F32. Layout supported NHWC.
- * @param[in] num_batches Number of batches in input tensor.
- * @param[in] num_rows Number of rows in input tensor.
- * @param[in] num_cols Number of columns in input tensor.
- * @param[in] num_channels Number of channels in input tensor.
- * @param[in] padding Padding type.
- * @param[out] output Base of output matrices.
- * @param[in] matrix_stride Stride between output matrices.
- * @param[in] workspace Tensor to be used as the working space during the computation.
- */
- void configure(
- const ITensorInfo *input_nhwc,
- const int num_batches,
- const int num_rows,
- const int num_cols,
- const int num_channels,
- const PaddingType padding,
- ITensorInfo *output,
- const int matrix_stride,
- ITensorInfo *workspace) override;
-
- // Inherited methods overridden:
- void run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override;
-
- /** Winograd base kernel */
- using WinogradBase = winograd::WinogradGEMM<OutputTileRows, OutputTileCols, KernelRows, KernelCols, winograd::WinogradRoots::Integers>;
- /** Winograd convolution kernel */
- using WinogradConv = typename WinogradBase::template Convolution<T, T>;
-
- /** Static function to check if given info will lead to a valid configuration of @ref CpuWinogradConv2dTransformInputKernel
- *
- * @param[in] input First tensor input info. Data types supported: F16/F32.
- * @param[in] output Output tensor info. Data types supported: same as @p input.
- * @param[in] winograd_info Contains Winograd's information described in @ref WinogradInfo
- *
- * @return a status
- */
- static Status validate(const ITensorInfo *input, const ITensorInfo *output, const WinogradInfo &winograd_info);
-
private:
- using InputTransform = typename WinogradBase::template InputTransform<T, T>;
-
- std::unique_ptr<InputTransform> _transform{ nullptr };
- int _num_channels; /**< Number of channels in input tensor. */
- int _matrix_stride; /**< Stride between output matrices. */
+ arm_conv::winograd::WinogradImpl &_winograd_impl;
+ arm_conv::ConvolutionArgs &_conv_args;
+ uint32_t _nthreads;
};
-
-/** Interface for the kernel to perform Winograd output transform. */
-class ICpuWinogradConv2dTransformOutputKernel : public ICpuKernel<ICpuWinogradConv2dTransformOutputKernel>
-{
-public:
- /** Get the working space required to perform the transformation.
- *
- * Note, the working space is only required when performing the
- * transformation - hence it can be reused whenever the transformation is
- * not running.
- *
- * @param[in] num_threads The greatest number of threads that will be used to execute the transform.
- *
- * @return Size of working space required in bytes.
- */
- virtual unsigned int get_working_space_size(unsigned int num_threads) const = 0;
-
- /** Determine how much memory (in units of TOut) to allocate for the
- * (Winograd domain) output.
- *
- * @param[in] num_batches Number of batches in the output tensor.
- * @param[in] num_rows Number of rows in each feature map of the input tensor.
- * @param[in] num_cols Number of columns in each feature map of the input tensor.
- * @param[in] num_output_channels Number of feature maps in the output tensor.
- *
- * @return Storage size (in units of TOut) required.
- */
- virtual unsigned int get_output_storage_size(int num_batches, int num_rows, int num_cols, int num_output_channels) const = 0;
-
- /** Gets the stride between matrices in the output worspace
- *
- * @param[in] num_batches Number of batches in the output tensor.
- * @param[in] num_rows Number of rows in each feature map of the input tensor.
- * @param[in] num_cols Number of columns in each feature map of the input tensor.
- * @param[in] num_output_channels Number of feature maps in the output tensor.
- *
- * @return Stride expressed in bytes.
- */
- virtual int get_matrix_stride(int num_batches, int num_rows, int num_cols, int num_output_channels) const = 0;
-
- /** Get the output shape of a convolution.
- *
- * @param[in] num_rows Number of rows in each feature map of the input tensor.
- * @param[in] num_cols Number of columns in each feature map of the input tensor.
- * @param[in] padding_same True if padding is SAME, false otherwise
- *
- * @return Shape of the output tensor
- */
- virtual std::pair<unsigned int, unsigned int> get_output_shape(
- int num_rows, /* Number of rows in each feature map of the input tensor. */
- int num_cols, /* Number of columns in each feature map of the input tensor. */
- bool padding_same /* True if padding is SAME, false otherwise */
- ) const = 0;
-
- /** Configure the output transform kernel.
- *
- * @param[in] biases Pointer to the biases tensor.
- * @param[in] transformed_output Pointer to working space for the output tensor in the Winograd domain.
- * @param[in] matrix_stride Output matrix stride, can be computed with winograd::WinogradGEMM<2, 2, 3, 3>::Convolution<float, float>::get_output_matrix_stride()
- * @param[out] output_nhwc Pointer to a tensor in NHWC data layout ordered output tensor, in the spatial domain.
- * @param[in] num_batches Number of batches in the input tensor.
- * @param[in] num_rows Number of rows in output tensor.
- * @param[in] num_cols Number of columns in output tensor.
- * @param[in] num_channels Number of feature maps in the output tensor.
- * @param[in] workspace Tensor to be used as the working space during the computation.
- * @param[in] activation Activation to be used
- */
- virtual void configure(
- const ITensorInfo *biases,
- const ITensorInfo *transformed_output,
- const int matrix_stride,
- ITensorInfo *output_nhwc,
- const int num_batches,
- const int num_rows,
- const int num_cols,
- const int num_channels,
- ITensorInfo *workspace,
- const arm_gemm::Activation &activation) = 0;
-
- virtual ~ICpuWinogradConv2dTransformOutputKernel()
- {
- }
-};
-
-/** Kernel to perform Winograd output transform. */
-template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
-class CpuWinogradConv2dTransformOutputKernel : public ICpuWinogradConv2dTransformOutputKernel
+class CpuWinogradConv2dTransformOutputKernel : public ICpuKernel<CpuWinogradConv2dTransformOutputKernel>
{
public:
- const char *name() const override
- {
- return "CpuWinogradConv2dTransformOutputKernel";
- }
- /** Constructor */
- CpuWinogradConv2dTransformOutputKernel();
-
/** Prevent instances of this class from being copied (As this class contains pointers) */
CpuWinogradConv2dTransformOutputKernel(const CpuWinogradConv2dTransformOutputKernel &) = delete;
+
/** Prevent instances of this class from being copied (As this class contains pointers) */
CpuWinogradConv2dTransformOutputKernel &operator=(const CpuWinogradConv2dTransformOutputKernel &) = delete;
- /** Allow instances of this class to be moved */
- CpuWinogradConv2dTransformOutputKernel(CpuWinogradConv2dTransformOutputKernel &&) = default;
- /** Allow instances of this class to be moved */
- CpuWinogradConv2dTransformOutputKernel &operator=(CpuWinogradConv2dTransformOutputKernel &&) = default;
- /** Default destructor */
- ~CpuWinogradConv2dTransformOutputKernel() = default;
-
- // Inherited methods overridden:
- /** Determine how much memory (in units of TOut) to allocate for the
- * (Winograd domain) output.
- *
- * @param[in] num_batches Number of batches in the output tensor.
- * @param[in] num_rows Number of rows in each feature map of the input tensor.
- * @param[in] num_cols Number of columns in each feature map of the input tensor.
- * @param[in] num_output_channels Number of feature maps in the output tensor.
- *
- * @return Storage size (in units of TOut) required.
- */
- unsigned int get_output_storage_size(int num_batches, int num_rows, int num_cols, int num_output_channels) const override;
- /** Gets the stride between matrices in the output worspace
- *
- * @param[in] num_batches Number of batches in the output tensor.
- * @param[in] num_rows Number of rows in each feature map of the input tensor.
- * @param[in] num_cols Number of columns in each feature map of the input tensor.
- * @param[in] num_output_channels Number of feature maps in the output tensor.
- *
- * @return Stride expressed in bytes.
- */
- int get_matrix_stride(int num_batches, int num_rows, int num_cols, int num_output_channels) const override;
- /** Get the output shape of a convolution.
- *
- * @param[in] num_rows Number of rows in each feature map of the input tensor.
- * @param[in] num_cols Number of columns in each feature map of the input tensor.
- * @param[in] padding_same True if padding is SAME, false otherwise
- *
- * @return Shape of the output tensor
- */
- std::pair<unsigned int, unsigned int> get_output_shape(
- int num_rows, /* Number of rows in each feature map of the input tensor. */
- int num_cols, /* Number of columns in each feature map of the input tensor. */
- bool padding_same) const override;
+ /** Prevent instances of this class from being moved it contains references.*/
+ CpuWinogradConv2dTransformOutputKernel(CpuWinogradConv2dTransformOutputKernel &&) = delete;
- /** Get the working space required to perform the transformation.
- *
- * Note, the working space is only required when performing the
- * transformation - hence it can be reused whenever the transformation is
- * not running.
- *
- * @param[in] num_threads The greatest number of threads that will be used to execute the transform.
- *
- * @return Size of working space required in bytes.
- */
- unsigned int get_working_space_size(unsigned int num_threads) const override;
+ /** Prevent instances of this class from being moved it contains references.*/
+ CpuWinogradConv2dTransformOutputKernel &operator=(CpuWinogradConv2dTransformOutputKernel &&) = delete;
- /** Configure the output transform kernel.
- *
- * @param[in] biases Pointer to the biases tensor.
- * @param[in] transformed_output Pointer to working space for the output tensor in the Winograd domain.
- * @param[in] matrix_stride Output matrix stride, can be computed with winograd::WinogradGEMM<2, 2, 3, 3>::Convolution<float, float>::get_output_matrix_stride()
- * @param[out] output_nhwc Pointer to a tensor with NHWC data layout, in the spatial domain.
- * @param[in] num_batches Number of batches in the input tensor.
- * @param[in] num_rows Number of rows in output tensor.
- * @param[in] num_cols Number of columns in output tensor.
- * @param[in] num_channels Number of feature maps in the output tensor.
- * @param[in] workspace Tensor to be used as the working space during the computation.
- * @param[in] activation Activation to be used
- */
- void configure(
- const ITensorInfo *biases,
- const ITensorInfo *transformed_output,
- const int matrix_stride,
- ITensorInfo *output_nhwc,
- const int num_batches,
- const int num_rows,
- const int num_cols,
- const int num_channels,
- ITensorInfo *workspace,
- const arm_gemm::Activation &activation) override;
+ CpuWinogradConv2dTransformOutputKernel(arm_conv::winograd::WinogradImpl &w_impl, arm_conv::ConvolutionArgs &_c_args, uint32_t nthreads);
+ // Inherited methods overridden:
void run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override;
- /** Static function to check if given info will lead to a valid configuration of @ref CpuWinogradConv2dTransformOutputKernel
- *
- * @param[in] input Source tensor info with shape [C, N, 16, batches] or [C, N, 36, batches]. Data types supported: F16/F32.
- * @param[in] bias Biases tensor info. Shared biases supported. Biases are 1D tensor with dimensions [OFM]. It can be a nullptr. Data type supported: as @p input
- * @param[in] output Destination tensor info with shape [output_convolved_dims.width, output_convolved_dims.height, C, batches]. Data type supported: same as @p input
- * @param[in] winograd_info Contains Winograd's information described in @ref WinogradInfo
- *
- * @return a status
- */
- static Status validate(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const WinogradInfo &winograd_info);
-
-private:
- using WinogradBase = winograd::WinogradGEMM<OutputTileRows, OutputTileCols, KernelRows, KernelCols, winograd::WinogradRoots::Integers>;
- using WinogradConv = typename WinogradBase::template Convolution<T, T>;
- using OutputTransform = typename WinogradBase::template OutputTransform<T, T>;
-
- std::unique_ptr<OutputTransform> _transform{ nullptr };
- int _matrix_stride;
- int _matrix_row_stride;
-};
-
-/** Interface for the kernel to perform Winograd weights transform. */
-class ICpuWinogradConv2dTransformWeightsKernel : public ICpuKernel<ICpuWinogradConv2dTransformWeightsKernel>
-{
-public:
- /** Prevent instances of this class from being copied (As this class contains pointers) */
- ICpuWinogradConv2dTransformWeightsKernel(const ICpuWinogradConv2dTransformWeightsKernel &) = default;
- /** Prevent instances of this class from being copied (As this class contains pointers) */
- ICpuWinogradConv2dTransformWeightsKernel &operator=(const ICpuWinogradConv2dTransformWeightsKernel &) = default;
- /** Allow instances of this class to be moved */
- ICpuWinogradConv2dTransformWeightsKernel(ICpuWinogradConv2dTransformWeightsKernel &&) = default;
- /** Allow instances of this class to be moved */
- ICpuWinogradConv2dTransformWeightsKernel &operator=(ICpuWinogradConv2dTransformWeightsKernel &&) = default;
-
- ICpuWinogradConv2dTransformWeightsKernel()
- {
- }
- virtual ~ICpuWinogradConv2dTransformWeightsKernel()
- {
- }
- /** Determine how much memory (in units of T) to allocate for the
- * transformed weights.
- *
- * @param[in] num_output_channels Number of output feature maps.
- * @param[in] num_input_channels Number of input feature maps.
- *
- * @return Storage size (in units of T) required.
- */
- virtual unsigned int get_weight_storage_size(int num_output_channels, int num_input_channels) const = 0;
- /** Gets the stride between matrices in the kernel worspace
- *
- * @param[in] num_output_channels Number of output feature maps.
- * @param[in] num_input_channels Number of input feature maps.
- *
- * @return Stride expressed in bytes.
- */
- virtual int get_matrix_stride(int num_output_channels, int num_input_channels) const = 0;
-
- /** Configure the weights transform kernel.
- *
- * @param[in] weights_hwio Pointer to the weights tensor info
- * @param[out] output Pointer to working space for the output tensor in the Winograd domain.
- * @param[in] matrix_stride Stride across matrices in the output workspace.
- * @param[in] num_output_channels Number of filters.
- * @param[in] num_input_channels Number of channels in each filter.
- */
-
- virtual void configure(const ITensorInfo *weights_hwio, ITensorInfo *output, const int matrix_stride, const int num_output_channels, const int num_input_channels) = 0;
-
- /** Static function to check if given info will lead to a valid configuration of @ref CpuWinogradConv2dTransformWeightsKernel
- *
- * @param[in] input First tensor input info. Data types supported: F16/F32.
- * @param[in] weights Weights tensor info. Data types supported: same as @p input.
- *
- * @return a status
- */
- static Status validate(const ITensorInfo *input, const ITensorInfo *weights);
-};
-
-/** Kernel to perform Winograd weights transform. */
-template <typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
-class CpuWinogradConv2dTransformWeightsKernel final : public ICpuWinogradConv2dTransformWeightsKernel
-{
-public:
- /** Prevent instances of this class from being copied (As this class contains pointers) */
- CpuWinogradConv2dTransformWeightsKernel(const CpuWinogradConv2dTransformWeightsKernel &) = delete;
- /** Prevent instances of this class from being copied (As this class contains pointers) */
- CpuWinogradConv2dTransformWeightsKernel &operator=(const CpuWinogradConv2dTransformWeightsKernel &) = delete;
- /** Allow instances of this class to be moved */
- CpuWinogradConv2dTransformWeightsKernel(CpuWinogradConv2dTransformWeightsKernel &&) = default;
- /** Allow instances of this class to be moved */
- CpuWinogradConv2dTransformWeightsKernel &operator=(CpuWinogradConv2dTransformWeightsKernel &&) = default;
- /** Default destructor */
- ~CpuWinogradConv2dTransformWeightsKernel() = default;
-
- /** Default constructor. */
- CpuWinogradConv2dTransformWeightsKernel();
const char *name() const override
{
- return "CpuWinogradConv2dTransformWeightsKernel";
+ return "CpuWinogradConv2dTransformOutputKernel";
}
- /** Static function to check if given info will lead to a valid configuration of @ref CpuWinogradConv2dTransformWeightsKernel
- *
- * @param[in] input Source tensor info. The input is a 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM] (NCHW data layout).
- * kernel_x must be 3 and equal to kernel_y. Data types supported: F16/F32.
- * @param[in] output Destination tensor info. The output is a 3D tensor with dimensions [OFM, IFM, 16] or [OFM, IFM, 36]. Data type supported: same as @p input
- * @param[in] winograd_info Contains Winograd's information described in @ref WinogradInfo
- *
- * @return a status
- */
- static Status validate(const ITensorInfo *input, const ITensorInfo *output, const WinogradInfo &winograd_info);
-
- // Inherited methods overridden:
-
-#ifndef DOXYGEN_SKIP_THIS
- /** Configure the weights transform kernel.
- *
- * @param[in] weights_hwio Pointer to the weights tensor info
- * @param[out] output Pointer to working space for the output tensor in the Winograd domain.
- * @param[in] matrix_stride Stride across matrices in the output workspace.
- * @param[in] num_output_channels Number of filters.
- * @param[in] num_input_channels Number of channels in each filter.
- */
- void configure(const ITensorInfo *weights_hwio, ITensorInfo *output, const int matrix_stride, const int num_output_channels, const int num_input_channels) override;
-#endif /* DOXYGEN_SKIP_THIS */
-
- /** Determine how much memory (in units of T) to allocate for the
- * transformed weights.
- *
- * @param[in] num_output_channels Number of output feature maps.
- * @param[in] num_input_channels Number of input feature maps.
- *
- * @return Storage size (in units of T) required.
- */
- unsigned int get_weight_storage_size(int num_output_channels, int num_input_channels) const override;
-
- /** Gets the stride between matrices in the input worspace
- *
- * @param[in] num_output_channels Number of output feature maps.
- * @param[in] num_input_channels Number of input feature maps.
- *
- * @return Stride expressed in bytes.
- */
- int get_matrix_stride(int num_output_channels, int num_input_channels) const override;
- void run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override;
- bool is_parallelisable() const override;
-
private:
- using WinogradBase = winograd::WinogradGEMM<OutputTileRows, OutputTileCols, KernelRows, KernelCols, winograd::WinogradRoots::Integers>;
- using WinogradConv = typename WinogradBase::template Convolution<T, T>;
- using WeightsTransform = typename WinogradBase::template WeightsTransform<T, T>;
-
- std::unique_ptr<WeightsTransform> _transform{ nullptr };
- int _num_output_channels;
- int _matrix_stride;
-};
-
-/** Kernel to perform Winograd. */
-template <typename TIn, typename TOut, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
-class CpuWinogradConv2dConfiguration
-{
-public:
- /** Winograd base kernel */
- using WinogradBase = winograd::WinogradGEMM<OutputTileRows, OutputTileCols, KernelRows, KernelCols, winograd::WinogradRoots::Integers>;
- /** Winograd convolution kernel */
-
- using WinogradConv = typename WinogradBase::template Convolution<TIn, TOut>;
-
- using TransformInputKernel = CpuWinogradConv2dTransformInputKernel<TIn, OutputTileRows, OutputTileCols, KernelRows, KernelCols>;
- using TransformWeightsKernel = CpuWinogradConv2dTransformWeightsKernel<TIn, OutputTileRows, OutputTileCols, KernelRows, KernelCols>;
- using TransformOutputKernel = CpuWinogradConv2dTransformOutputKernel<TOut, OutputTileRows, OutputTileCols, KernelRows, KernelCols>;
+ arm_conv::winograd::WinogradImpl &_winograd_impl;
+ const arm_conv::ConvolutionArgs &_conv_args;
+ uint32_t _nthreads;
};
} // namespace cpu
diff --git a/src/cpu/kernels/assembly/arm_gemm.hpp b/src/cpu/kernels/assembly/arm_gemm.hpp
index 9920b863d9..247cb1d470 100644
--- a/src/cpu/kernels/assembly/arm_gemm.hpp
+++ b/src/cpu/kernels/assembly/arm_gemm.hpp
@@ -143,12 +143,12 @@ struct GemmArgs
{
public:
const CPUInfo *_ci;
- unsigned int _Msize;
- unsigned int _Nsize;
- unsigned int _Ksize;
+ unsigned int _Msize; // num of tiles
+ unsigned int _Nsize; // output channels
+ unsigned int _Ksize; // input channels
unsigned int _Ksections;
unsigned int _nbatches;
- unsigned int _nmulti;
+ unsigned int _nmulti; // n_gemms to be performed
bool _indirect_input;
Activation _act;
int _maxthreads;
diff --git a/src/cpu/operators/CpuWinogradConv2d.cpp b/src/cpu/operators/CpuWinogradConv2d.cpp
index dcc18ce8fa..7be2d6d230 100644
--- a/src/cpu/operators/CpuWinogradConv2d.cpp
+++ b/src/cpu/operators/CpuWinogradConv2d.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021 Arm Limited.
+ * Copyright (c) 2021-2022 Arm Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -31,19 +31,19 @@
#include "arm_compute/runtime/NEON/NEScheduler.h"
#include "src/common/utils/Log.h"
#include "src/core/CPP/Validate.h"
+#include "src/core/NEON/kernels/assembly/winograd.hpp"
+#include "src/core/NEON/kernels/convolution/common/tensor.hpp"
#include "src/core/NEON/kernels/convolution/common/utils.hpp"
-#include "src/core/NEON/kernels/convolution/winograd/winograd.hpp"
#include "src/core/helpers/MemoryHelpers.h"
+#include "src/core/helpers/WindowHelpers.h"
+#include "src/core/utils/AssemblyUtils.h"
#include "src/cpu/kernels/CpuWinogradConv2dKernel.h"
+#include "src/cpu/kernels/assembly/arm_gemm.hpp"
#include "src/cpu/operators/CpuActivation.h"
#include "src/cpu/operators/CpuPermute.h"
-#include "src/cpu/operators/CpuWinogradConv2d.h"
#include "src/cpu/utils/CpuAuxTensorHandler.h"
-
#include "support/Cast.h"
-#include <set>
-
namespace arm_compute
{
namespace cpu
@@ -53,174 +53,20 @@ using namespace arm_compute::utils::cast;
namespace
{
-arm_gemm::Activation arm_gemm_activation_from_acl_activation(const ActivationLayerInfo &act_info)
-{
- switch(act_info.activation())
- {
- case ActivationLayerInfo::ActivationFunction::RELU:
- {
- return arm_gemm::Activation(arm_gemm::Activation::Type::ReLU, act_info.a(), act_info.b());
- }
- case ActivationLayerInfo::ActivationFunction::BOUNDED_RELU:
- {
- return arm_gemm::Activation(arm_gemm::Activation::Type::BoundedReLU, act_info.a(), act_info.b());
- }
- default:
- {
- return arm_gemm::Activation(arm_gemm::Activation::Type::None);
- }
- }
-}
-
-inline Status validate_kernel_3x3(const Size2D input_dims, const ITensorInfo *src, const TensorInfo *input0, const TensorInfo *input1, const TensorInfo *batched_mm_output,
- const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *dst, const WinogradInfo &winograd_info, const ActivationLayerInfo &act_info)
-{
- ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(src);
- ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(src, 1, DataType::F16, DataType::F32);
-
- if(src->data_type() == DataType::F32)
- {
- if(input_dims.width > 4 && input_dims.height > 4)
- {
- ARM_COMPUTE_RETURN_ON_ERROR((CpuWinogradConv2dTransformInputKernel<float, 4, 4, 3, 3>::validate(src, input0, winograd_info)));
- ARM_COMPUTE_RETURN_ON_ERROR((CpuWinogradConv2dTransformWeightsKernel<float, 4, 4, 3, 3>::validate(weights, input1, winograd_info)));
- ARM_COMPUTE_RETURN_ON_ERROR((CpuWinogradConv2dTransformOutputKernel<float, 4, 4, 3, 3>::validate(batched_mm_output, biases, dst, winograd_info)));
- }
- else
- {
- ARM_COMPUTE_RETURN_ON_ERROR((CpuWinogradConv2dTransformInputKernel<float, 2, 2, 3, 3>::validate(src, input0, winograd_info)));
- ARM_COMPUTE_RETURN_ON_ERROR((CpuWinogradConv2dTransformWeightsKernel<float, 2, 2, 3, 3>::validate(weights, input1, winograd_info)));
- ARM_COMPUTE_RETURN_ON_ERROR((CpuWinogradConv2dTransformOutputKernel<float, 2, 2, 3, 3>::validate(batched_mm_output, biases, dst, winograd_info)));
- }
- }
-#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
- else if(src->data_type() == DataType::F16)
- {
- ARM_COMPUTE_RETURN_ON_ERROR((CpuWinogradConv2dTransformInputKernel<__fp16, 4, 4, 3, 3>::validate(src, input0, winograd_info)));
- ARM_COMPUTE_RETURN_ON_ERROR((CpuWinogradConv2dTransformWeightsKernel<__fp16, 4, 4, 3, 3>::validate(weights, input1, winograd_info)));
- ARM_COMPUTE_RETURN_ON_ERROR((CpuWinogradConv2dTransformOutputKernel<__fp16, 4, 4, 3, 3>::validate(batched_mm_output, biases, dst, winograd_info)));
- }
-#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
-
- if(act_info.enabled())
- {
- CpuActivation::validate(dst, nullptr, act_info);
- }
- return Status{};
-}
-
-inline Status validate_kernel_5x5(const ITensorInfo *src, const TensorInfo *input0, const TensorInfo *input1, const TensorInfo *batched_mm_output,
- const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *dst, const WinogradInfo &winograd_info, const ActivationLayerInfo &act_info)
-{
- ARM_COMPUTE_RETURN_ON_ERROR((CpuWinogradConv2dTransformInputKernel<float, 2, 2, 5, 5>::validate(src, input0, winograd_info)));
- ARM_COMPUTE_RETURN_ON_ERROR((CpuWinogradConv2dTransformWeightsKernel<float, 2, 2, 5, 5>::validate(weights, input1, winograd_info)));
- ARM_COMPUTE_RETURN_ON_ERROR((CpuWinogradConv2dTransformOutputKernel<float, 2, 2, 5, 5>::validate(batched_mm_output, biases, dst, winograd_info)));
- if(act_info.enabled())
- {
- CpuActivation::validate(dst, nullptr, act_info);
- }
- return Status{};
-}
-
-inline Status validate_kernel_3x1(const ITensorInfo *src, const TensorInfo *input0, const TensorInfo *input1, const TensorInfo *batched_mm_output,
- const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *dst, const WinogradInfo &winograd_info, const ActivationLayerInfo &act_info)
-{
- ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(src, 1, DataType::F32);
- ARM_COMPUTE_RETURN_ON_ERROR((CpuWinogradConv2dTransformInputKernel<float, 1, 6, 1, 3>::validate(src, input0, winograd_info)));
- ARM_COMPUTE_RETURN_ON_ERROR((CpuWinogradConv2dTransformWeightsKernel<float, 1, 6, 1, 3>::validate(weights, input1, winograd_info)));
- ARM_COMPUTE_RETURN_ON_ERROR((CpuWinogradConv2dTransformOutputKernel<float, 1, 6, 1, 3>::validate(batched_mm_output, biases, dst, winograd_info)));
- if(act_info.enabled())
- {
- CpuActivation::validate(dst, nullptr, act_info);
- }
- return Status{};
-}
-
-inline Status validate_kernel_1x3(const ITensorInfo *src, const TensorInfo *input0, const TensorInfo *input1, const TensorInfo *batched_mm_output,
- const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *dst, const WinogradInfo &winograd_info, const ActivationLayerInfo &act_info)
-{
- ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(src, 1, DataType::F32);
- ARM_COMPUTE_RETURN_ON_ERROR((CpuWinogradConv2dTransformInputKernel<float, 6, 1, 3, 1>::validate(src, input0, winograd_info)));
- ARM_COMPUTE_RETURN_ON_ERROR((CpuWinogradConv2dTransformWeightsKernel<float, 6, 1, 3, 1>::validate(weights, input1, winograd_info)));
- ARM_COMPUTE_RETURN_ON_ERROR((CpuWinogradConv2dTransformOutputKernel<float, 6, 1, 3, 1>::validate(batched_mm_output, biases, dst, winograd_info)));
-
- if(act_info.enabled())
- {
- CpuActivation::validate(dst, nullptr, act_info);
- }
- return Status{};
-}
-
-inline Status validate_kernel_5x1(const ITensorInfo *src, const TensorInfo *input0, const TensorInfo *input1, const TensorInfo *batched_mm_output,
- const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *dst, const WinogradInfo &winograd_info, const ActivationLayerInfo &act_info)
-{
- ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(src, 1, DataType::F32);
- ARM_COMPUTE_RETURN_ON_ERROR((CpuWinogradConv2dTransformInputKernel<float, 1, 4, 1, 5>::validate(src, input0, winograd_info)));
- ARM_COMPUTE_RETURN_ON_ERROR((CpuWinogradConv2dTransformWeightsKernel<float, 1, 4, 1, 5>::validate(weights, input1, winograd_info)));
- ARM_COMPUTE_RETURN_ON_ERROR((CpuWinogradConv2dTransformOutputKernel<float, 1, 4, 1, 5>::validate(batched_mm_output, biases, dst, winograd_info)));
- if(act_info.enabled())
- {
- CpuActivation::validate(dst, nullptr, act_info);
- }
- return Status{};
-}
-inline Status validate_kernel_1x5(const ITensorInfo *src, const TensorInfo *input0, const TensorInfo *input1, const TensorInfo *batched_mm_output,
- const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *dst, const WinogradInfo &winograd_info, const ActivationLayerInfo &act_info)
-{
- ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(src, 1, DataType::F32);
- ARM_COMPUTE_RETURN_ON_ERROR((CpuWinogradConv2dTransformInputKernel<float, 4, 1, 5, 1>::validate(src, input0, winograd_info)));
- ARM_COMPUTE_RETURN_ON_ERROR((CpuWinogradConv2dTransformWeightsKernel<float, 4, 1, 5, 1>::validate(weights, input1, winograd_info)));
- ARM_COMPUTE_RETURN_ON_ERROR((CpuWinogradConv2dTransformOutputKernel<float, 4, 1, 5, 1>::validate(batched_mm_output, biases, dst, winograd_info)));
- if(act_info.enabled())
- {
- CpuActivation::validate(dst, nullptr, act_info);
- }
- return Status{};
-}
-
-inline Status validate_kernel_7x1(const ITensorInfo *src, const TensorInfo *input0, const TensorInfo *input1, const TensorInfo *batched_mm_output,
- const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *dst, const WinogradInfo &winograd_info, const ActivationLayerInfo &act_info)
-{
- ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(src, 1, DataType::F32);
- ARM_COMPUTE_RETURN_ON_ERROR((CpuWinogradConv2dTransformInputKernel<float, 1, 2, 1, 7>::validate(src, input0, winograd_info)));
- ARM_COMPUTE_RETURN_ON_ERROR((CpuWinogradConv2dTransformWeightsKernel<float, 1, 2, 1, 7>::validate(weights, input1, winograd_info)));
- ARM_COMPUTE_RETURN_ON_ERROR((CpuWinogradConv2dTransformOutputKernel<float, 1, 2, 1, 7>::validate(batched_mm_output, biases, dst, winograd_info)));
- if(act_info.enabled())
- {
- CpuActivation::validate(dst, nullptr, act_info);
- }
- return Status{};
-}
-
-inline Status validate_kernel_1x7(const ITensorInfo *src, const TensorInfo *input0, const TensorInfo *input1, const TensorInfo *batched_mm_output,
- const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *dst, const WinogradInfo &winograd_info, const ActivationLayerInfo &act_info)
+inline Tensor4DShape internal_get_shape(const ITensorInfo *in)
{
- ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(src, 1, DataType::F32);
- ARM_COMPUTE_RETURN_ON_ERROR((CpuWinogradConv2dTransformInputKernel<float, 2, 1, 7, 1>::validate(src, input0, winograd_info)));
- ARM_COMPUTE_RETURN_ON_ERROR((CpuWinogradConv2dTransformWeightsKernel<float, 2, 1, 7, 1>::validate(weights, input1, winograd_info)));
- ARM_COMPUTE_RETURN_ON_ERROR((CpuWinogradConv2dTransformOutputKernel<float, 2, 1, 7, 1>::validate(batched_mm_output, biases, dst, winograd_info)));
-
- if(act_info.enabled())
- {
- CpuActivation::validate(dst, nullptr, act_info);
- }
- return Status{};
-}
-
-inline Tensor4DShape internal_get_input_shape(const ITensorInfo *src)
-{
- const DataLayout data_layout = src->data_layout();
- const int in_width = src->dimension(get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH));
- const int in_height = src->dimension(get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT));
- const int in_channels = src->dimension(get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL));
- const int in_batches = src->dimension(3);
+ const DataLayout data_layout = in->data_layout();
+ const int in_width = in->dimension(get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH));
+ const int in_height = in->dimension(get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT));
+ const int in_channels = in->dimension(get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL));
+ const int in_batches = in->dimension(get_data_layout_dimension_index(data_layout, DataLayoutDimension::BATCHES));
return Tensor4DShape{ in_batches, in_height, in_width, in_channels };
}
Status validate_arguments(const ITensorInfo *src, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *dst, const PadStrideInfo &conv_info)
{
- ARM_COMPUTE_UNUSED(dst);
+ ARM_COMPUTE_UNUSED(dst, weights);
ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(src);
ARM_COMPUTE_RETURN_ERROR_ON_MSG(conv_info.stride().first != 1 || conv_info.stride().second != 1, "Winograd layer only supports unit strides.");
@@ -229,108 +75,85 @@ Status validate_arguments(const ITensorInfo *src, const ITensorInfo *weights, co
ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(src, biases);
ARM_COMPUTE_RETURN_ERROR_ON(biases->num_dimensions() > 1);
}
- return ICpuWinogradConv2dTransformWeightsKernel::validate(src, weights);
+ ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(src, 1, DataType::F16, DataType::F32);
+ ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(src, weights);
+ return Status{};
}
-Size2D winograd_output_tile(const Size2D &input_dims, const Size2D &kernel_dims, DataType data_type)
+
+bool get_winograd_kernel_implementation(const ITensorInfo *src, const ITensorInfo *weights, const ITensorInfo *dst,
+ const PadStrideInfo &conv_info, const ActivationLayerInfo &act_info, bool enable_fast_math,
+ arm_conv::winograd::WinogradImpl *winograd_impl, std::unique_ptr<arm_conv::ConvolutionArgs> &conv_args)
{
- Size2D output_tile = Size2D{};
- if(kernel_dims == Size2D(3U, 3U))
- {
- output_tile = (input_dims.width <= 4 || input_dims.height <= 4) ? Size2D(2U, 2U) : Size2D(4U, 4U);
- if(data_type == DataType::F16)
- {
- output_tile = Size2D(4U, 4U);
- }
- }
- else if(kernel_dims == Size2D(5U, 5U))
- {
- output_tile = Size2D(2U, 2U);
- }
- else if(kernel_dims == Size2D(1U, 3U))
- {
- output_tile = Size2D(1U, 6U);
- }
- else if(kernel_dims == Size2D(3U, 1U))
- {
- output_tile = Size2D(6U, 1U);
- }
- else if(kernel_dims == Size2D(1U, 5U))
- {
- output_tile = Size2D(1U, 4U);
- }
- else if(kernel_dims == Size2D(5U, 1U))
- {
- output_tile = Size2D(4U, 1U);
- }
- else if(kernel_dims == Size2D(7U, 1U))
+ arm_conv::winograd::WinogradConfig winograd_cfg;
+ arm_gemm::GemmConfig cfg;
+
+ const DataType data_type = src->data_type();
+ Tensor4DShape in_shape{ internal_get_shape(src) };
+ Tensor4DShape out_shape{ internal_get_shape(dst) };
+ Tensor4DShape kernel_shape{ internal_get_shape(weights) };
+ uint32_t nthreads = NEScheduler::get().num_threads();
+ // Get configuration arguments for Winograd
+ winograd_cfg.output_rows = 0;
+ winograd_cfg.output_cols = 0;
+ conv_args = std::make_unique<arm_conv::ConvolutionArgs>(
+ in_shape.n_batches,
+ arm_conv::Shape2D{ static_cast<uint32_t>(in_shape.n_rows), static_cast<uint32_t>(in_shape.n_cols) },
+ in_shape.n_channels,
+ conv_info.pad_top(),
+ conv_info.pad_left(),
+ arm_conv::Shape2D{ static_cast<uint32_t>(out_shape.n_rows), static_cast<uint32_t>(out_shape.n_cols) },
+ out_shape.n_channels,
+ arm_conv::Shape2D{ static_cast<uint32_t>(kernel_shape.n_rows), static_cast<uint32_t>(kernel_shape.n_cols) },
+ assembly_utils::map_to_arm_gemm_activation(act_info));
+
+ bool success = false;
+ if(data_type == DataType::F32)
{
- output_tile = Size2D(2U, 1U);
+ success = arm_conv::winograd::get_implementation<float>(
+ *winograd_impl, &CPUInfo::get(), *conv_args, nthreads, enable_fast_math, &winograd_cfg, nullptr);
}
- else if(kernel_dims == Size2D(1U, 7U))
+#if defined(__aarch64__) && defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
+ else if(data_type == DataType::F16)
{
- output_tile = Size2D(1U, 2U);
+ success = arm_conv::winograd::get_implementation<__fp16>(
+ *winograd_impl, &CPUInfo::get(), *conv_args, nthreads, enable_fast_math, &winograd_cfg, nullptr);
}
- return output_tile;
-}
-
-bool check_support_fast_math(const Size2D &output_tile, const Size2D &kernel_size, DataType data_type)
-{
- // Check if we want to configure a Winograd configuration which requires fast math
- using WinogradConfiguration = std::pair<std::pair<int, int>, std::pair<int, int>>;
-
- const std::vector<WinogradConfiguration> fast_math_winograd_f16 =
- {
- WinogradConfiguration(std::pair<int, int>(4, 4), std::pair<int, int>(3, 3))
- };
-
- const std::vector<WinogradConfiguration> fast_math_winograd_f32 =
- {
- WinogradConfiguration(std::pair<int, int>(2, 2), std::pair<int, int>(5, 5)),
- WinogradConfiguration(std::pair<int, int>(4, 4), std::pair<int, int>(5, 5))
- };
-
- auto p = std::make_pair(std::pair<int, int>(output_tile.width, output_tile.height),
- std::pair<int, int>(kernel_size.width, kernel_size.height));
-
- switch(data_type)
+#endif // defined(__aarch64__) && defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
+ else
{
- case DataType::F16:
- return std::find(fast_math_winograd_f16.begin(), fast_math_winograd_f16.end(), p) != fast_math_winograd_f16.end();
- case DataType::F32:
- return std::find(fast_math_winograd_f32.begin(), fast_math_winograd_f32.end(), p) != fast_math_winograd_f32.end();
- default:
- return false;
+ success = false;
}
+ return success;
}
-
inline bool fuse_function_supported(const ActivationLayerInfo &act_info)
{
return act_info.activation() == ActivationLayerInfo::ActivationFunction::RELU || act_info.activation() == ActivationLayerInfo::ActivationFunction::BOUNDED_RELU;
}
-
} // namespace
CpuWinogradConv2d::CpuWinogradConv2d()
+
: _gemm_function(std::make_unique<CpuGemm>()),
_activation_func(std::make_unique<CpuActivation>()),
+ _transform_input_kernel(nullptr),
+ _transform_output_kernel(nullptr),
_permute_input(std::make_unique<CpuPermute>()),
_permute_output(std::make_unique<CpuPermute>()),
_permute_weights(std::make_unique<CpuPermute>()),
- _transform_input_kernel(nullptr),
- _transform_weights_kernel(nullptr),
- _transform_output_kernel(nullptr),
- _data_layout(),
_aux_mem(AuxTensorIdx::Count),
- _input_nhwc(),
- _output_nhwc(),
+ _conv_args{ nullptr },
+ _winograd_impl{},
+ _data_layout(),
+ _winograd_transformed_input{},
+ _winograd_transformed_output{},
+ _winograd_transformed_weights{},
_input_workspace(),
- _kernel_storage(),
_output_workspace(),
- _input_transformed(),
- _output_transformed(),
_weights_hwio(),
- _run_activation(false),
- _is_prepared(false)
+ _input_nhwc(),
+ _output_nhwc(),
+ _is_prepared{ false },
+ _run_activation{ false }
{
}
@@ -342,464 +165,199 @@ void CpuWinogradConv2d::configure(const ITensorInfo *src, const ITensorInfo *wei
ARM_COMPUTE_ERROR_ON_NULLPTR(src, weights, dst);
ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(src, weights, biases, dst, conv_info));
ARM_COMPUTE_LOG_PARAMS(src, weights, biases, dst, conv_info, act_info, enable_fast_math);
-
- // Get indices for the width and height
- _data_layout = src->data_layout();
- const unsigned int width_idx = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::WIDTH);
- const unsigned int height_idx = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::HEIGHT);
- const unsigned int channel_idx = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::CHANNEL);
-
- const Size2D input_dims = Size2D(src->dimension(width_idx), src->dimension(height_idx));
- const Size2D kernel_size = Size2D(weights->dimension(width_idx), weights->dimension(height_idx));
- const DataType data_type = src->data_type();
- const Size2D output_tile = winograd_output_tile(input_dims, kernel_size, data_type);
-
- // Check if the Winograd configuration requires fast math
- if(!enable_fast_math)
- {
- ARM_COMPUTE_ERROR_ON_MSG(check_support_fast_math(output_tile, kernel_size, data_type),
- "This Winograd configuration requires enable_fast_math=true");
- }
-
- _is_prepared = false;
-
- std::unique_ptr<ICpuWinogradConv2dTransformInputKernel> transform_input_kernel;
- std::unique_ptr<ICpuWinogradConv2dTransformWeightsKernel> transform_weights_kernel;
- std::unique_ptr<ICpuWinogradConv2dTransformOutputKernel> transform_output_kernel;
-
- int n_gemms = 1;
- int N_BLOCK = 1; // Size of block used by GEMM.
- if(data_type == DataType::F32)
- {
- if(kernel_size == Size2D(3, 3))
+ ARM_COMPUTE_UNUSED(biases);
+ const DataType data_type = src->data_type();
+ uint32_t nthreads = NEScheduler::get().num_threads();
+ _data_layout = src->data_layout();
+ const Tensor4DShape kernel_shape{ internal_get_shape(weights) };
+
+ bool success = get_winograd_kernel_implementation(src, weights, dst, conv_info, act_info, enable_fast_math, &_winograd_impl, _conv_args);
+
+ ARM_COMPUTE_EXIT_ON_MSG_VAR(!success, "Unsupported kernel size: %d x %d.\n", kernel_shape.n_rows, kernel_shape.n_cols);
+ ARM_COMPUTE_LOG_MSG_WITH_FORMAT_ACL(arm_compute::logging::LogLevel::INFO, "Using input transform: %s\n", _winograd_impl.input_transform->get_name().c_str());
+ ARM_COMPUTE_LOG_MSG_WITH_FORMAT_ACL(arm_compute::logging::LogLevel::INFO, "Using weight transform: %s\n", _winograd_impl.input_transform->get_name().c_str());
+ ARM_COMPUTE_LOG_MSG_WITH_FORMAT_ACL(arm_compute::logging::LogLevel::INFO, "Using output transform: %s\n", _winograd_impl.input_transform->get_name().c_str());
+
+ const bool has_impl = ((_winograd_impl.input_transform != nullptr) && (_winograd_impl.output_transform != nullptr) && (_winograd_impl.gemm_args != nullptr));
+ if(has_impl)
+ {
+ // Determine how much working space is required, allocate it.
+ const size_t input_workspace_size = _winograd_impl.input_transform->get_working_space_size(*_conv_args, nthreads);
+ const size_t output_workspace_size = _winograd_impl.output_transform->get_working_space_size(*_conv_args, nthreads);
+
+ TensorInfo input_workspace_info(TensorShape(input_workspace_size), 1, DataType::U8);
+ TensorInfo output_workspace_info(TensorShape(output_workspace_size), 1, DataType::U8);
+ _input_workspace = input_workspace_info;
+ _output_workspace = output_workspace_info;
+
+ const auto &wds = _winograd_impl.winograd_spec;
+
+ // Preparing winograd transformed input tensor
+ const size_t data_type_size = src->element_size();
+ const uint32_t m = _winograd_impl.gemm_args->_Msize; // Total number of tiles
+ const uint32_t k = _winograd_impl.gemm_args->_Ksize; // Input channels
+ const uint32_t n = _winograd_impl.gemm_args->_Nsize; // Output channels
+ const uint32_t n_gemms = _winograd_impl.gemm_args->_nmulti;
+ const uint32_t n_batches = _winograd_impl.gemm_args->_nbatches;
+ constexpr size_t storage_alignment = 64;
+
+ const TensorShape a_shape(k, m, n_batches, n_gemms);
+ Strides a_strides(data_type_size);
+ a_strides.set(1, data_type_size * _winograd_impl.winograd_spec.input_ld_row);
+ a_strides.set(2, data_type_size * _winograd_impl.winograd_spec.input_ld_batch);
+ a_strides.set(3, data_type_size * _winograd_impl.winograd_spec.input_ld_matrix);
+
+ const TensorShape b_shape(n, k, n_gemms);
+ Strides b_strides(data_type_size);
+ b_strides.set(1, data_type_size * _winograd_impl.winograd_spec.weight_ld_row);
+ b_strides.set(2, data_type_size * _winograd_impl.winograd_spec.weight_ld_matrix);
+
+ const TensorShape d_shape(n, m, n_batches, n_gemms);
+ Strides d_strides(data_type_size);
+ d_strides.set(1, data_type_size * _winograd_impl.winograd_spec.output_ld_row);
+ d_strides.set(2, data_type_size * _winograd_impl.winograd_spec.output_ld_batch);
+ d_strides.set(3, data_type_size * _winograd_impl.winograd_spec.output_ld_matrix);
+
+ TensorInfo a_info{};
+ TensorInfo b_info{};
+ TensorInfo d_info{};
+ a_info.init(a_shape, 1, data_type, a_strides, 0, wds.input_matrix_size_bytes);
+ b_info.init(b_shape, 1, data_type, b_strides, 0, wds.weight_matrix_size_bytes);
+ d_info.init(d_shape, 1, data_type, d_strides, 0, wds.output_matrix_size_bytes);
+
+ _winograd_transformed_input = a_info;
+ _winograd_transformed_weights = b_info;
+ _winograd_transformed_output = d_info;
+
+ PermutationVector weights_permutation_vector(3U, 0U, 1U, 2U);
+
+ // Configure the kernel to transform the input tensor from NCHW -> NHWC
+ if(_data_layout == DataLayout::NCHW)
{
- if(src->dimension(width_idx) > 4 && src->dimension(height_idx) > 4)
- {
- using config = CpuWinogradConv2dConfiguration<float, float, 4, 4, 3, 3>;
- transform_input_kernel = std::make_unique<config::TransformInputKernel>();
- transform_weights_kernel = std::make_unique<config::TransformWeightsKernel>();
- transform_output_kernel = std::make_unique<config::TransformOutputKernel>();
- n_gemms = config::WinogradBase::N_GEMMS;
- N_BLOCK = config::WinogradConv::N_BLOCK;
- }
- else
- {
- using config = CpuWinogradConv2dConfiguration<float, float, 2, 2, 3, 3>;
- transform_input_kernel = std::make_unique<config::TransformInputKernel>();
- transform_weights_kernel = std::make_unique<config::TransformWeightsKernel>();
- transform_output_kernel = std::make_unique<config::TransformOutputKernel>();
- n_gemms = config::WinogradBase::N_GEMMS;
- N_BLOCK = config::WinogradConv::N_BLOCK;
- }
+ _permute_input->configure(src, &_input_nhwc, PermutationVector(2U, 0U, 1U));
+ weights_permutation_vector = PermutationVector(3U, 2U, 0U, 1U);
}
- else if(kernel_size == Size2D(5, 5))
- {
- using config = CpuWinogradConv2dConfiguration<float, float, 2, 2, 5, 5>;
- transform_input_kernel = std::make_unique<config::TransformInputKernel>();
- transform_weights_kernel = std::make_unique<config::TransformWeightsKernel>();
- transform_output_kernel = std::make_unique<config::TransformOutputKernel>();
- n_gemms = config::WinogradBase::N_GEMMS;
- N_BLOCK = config::WinogradConv::N_BLOCK;
- }
- else if(kernel_size == Size2D(1, 3))
- {
- using config = CpuWinogradConv2dConfiguration<float, float, 6, 1, 3, 1>;
- transform_input_kernel = std::make_unique<config::TransformInputKernel>();
- transform_weights_kernel = std::make_unique<config::TransformWeightsKernel>();
- transform_output_kernel = std::make_unique<config::TransformOutputKernel>();
- n_gemms = config::WinogradBase::N_GEMMS;
- N_BLOCK = config::WinogradConv::N_BLOCK;
- }
- else if(kernel_size == Size2D(3, 1))
- {
- using config = CpuWinogradConv2dConfiguration<float, float, 1, 6, 1, 3>;
- transform_input_kernel = std::make_unique<config::TransformInputKernel>();
- transform_weights_kernel = std::make_unique<config::TransformWeightsKernel>();
- transform_output_kernel = std::make_unique<config::TransformOutputKernel>();
- n_gemms = config::WinogradBase::N_GEMMS;
- N_BLOCK = config::WinogradConv::N_BLOCK;
- }
- else if(kernel_size == Size2D(1, 5))
- {
- using config = CpuWinogradConv2dConfiguration<float, float, 4, 1, 5, 1>;
- transform_input_kernel = std::make_unique<config::TransformInputKernel>();
- transform_weights_kernel = std::make_unique<config::TransformWeightsKernel>();
- transform_output_kernel = std::make_unique<config::TransformOutputKernel>();
- n_gemms = config::WinogradBase::N_GEMMS;
- N_BLOCK = config::WinogradConv::N_BLOCK;
- }
- else if(kernel_size == Size2D(5, 1))
- {
- using config = CpuWinogradConv2dConfiguration<float, float, 1, 4, 1, 5>;
- transform_input_kernel = std::make_unique<config::TransformInputKernel>();
- transform_weights_kernel = std::make_unique<config::TransformWeightsKernel>();
- transform_output_kernel = std::make_unique<config::TransformOutputKernel>();
- n_gemms = config::WinogradBase::N_GEMMS;
- N_BLOCK = config::WinogradConv::N_BLOCK;
- }
- else if(kernel_size == Size2D(1, 7))
- {
- using config = CpuWinogradConv2dConfiguration<float, float, 2, 1, 7, 1>;
- transform_input_kernel = std::make_unique<config::TransformInputKernel>();
- transform_weights_kernel = std::make_unique<config::TransformWeightsKernel>();
- transform_output_kernel = std::make_unique<config::TransformOutputKernel>();
- n_gemms = config::WinogradBase::N_GEMMS;
- N_BLOCK = config::WinogradConv::N_BLOCK;
- }
- else if(kernel_size == Size2D(7, 1))
- {
- using config = CpuWinogradConv2dConfiguration<float, float, 1, 2, 1, 7>;
- transform_input_kernel = std::make_unique<config::TransformInputKernel>();
- transform_weights_kernel = std::make_unique<config::TransformWeightsKernel>();
- transform_output_kernel = std::make_unique<config::TransformOutputKernel>();
- n_gemms = config::WinogradBase::N_GEMMS;
- N_BLOCK = config::WinogradConv::N_BLOCK;
- }
- else
+
+ // 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]
+ _permute_weights->configure(weights, &_weights_hwio, weights_permutation_vector);
+
+ // Reorder the convoluted output to ACL's ordering NCHW
+ if(_data_layout == DataLayout::NCHW)
{
- ARM_COMPUTE_ERROR("Not supported.");
+ // configure and allocate dst tensor to be used to convert from winograd domain to spatial domain when calling to reshape_output()
+ TensorInfo info(TensorShape(dst->dimension(2), dst->dimension(0),
+ dst->dimension(1), dst->dimension(3)),
+ 1, dst->data_type());
+ _output_nhwc = info;
+ _permute_output->configure(&_output_nhwc, dst, PermutationVector(1U, 2U, 0U));
}
- }
-#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
- else if(data_type == DataType::F16)
- {
- if(kernel_size == Size2D(3, 3))
+
+ // Configure GEMM function
+ _gemm_function->configure(&_winograd_transformed_input, &_winograd_transformed_weights, nullptr, &_winograd_transformed_output, 1.0f, 0.f);
+
+ //Configure Activation Layer
+ _run_activation = act_info.enabled() && !fuse_function_supported(act_info);
+ if(_run_activation)
{
- using config = CpuWinogradConv2dConfiguration<__fp16, __fp16, 4, 4, 3, 3>;
- transform_input_kernel = std::make_unique<config::TransformInputKernel>();
- transform_weights_kernel = std::make_unique<config::TransformWeightsKernel>();
- transform_output_kernel = std::make_unique<config::TransformOutputKernel>();
- n_gemms = config::WinogradBase::N_GEMMS;
- N_BLOCK = config::WinogradConv::N_BLOCK;
+ _activation_func->configure(dst, nullptr, act_info);
}
- else
+
+ auto asm_mem_req = _gemm_function->workspace();
+ _aux_mem[GemmWorkspace] = asm_mem_req[GemmWorkspace];
+ _aux_mem[Pretranspose] = asm_mem_req[Pretranspose];
+ _aux_mem[InterleavedLHS] = asm_mem_req[InterleavedLHS];
+ _aux_mem[TransposedRHS] = asm_mem_req[TransposedRHS];
+ _aux_mem[TempResult] = asm_mem_req[TempResult];
+
+ // Request temporary memory. Overlap memory needed for Input/Output transformations as they run on different non-overlapping time-steps.
+ _aux_mem[TransformedInput] = MemoryInfo(offset_int_vec(TransformedInput), MemoryLifetime::Temporary, wds.input_matrix_size_bytes, storage_alignment);
+ _aux_mem[TransformedOutput] = MemoryInfo(offset_int_vec(TransformedOutput), MemoryLifetime::Temporary, wds.output_matrix_size_bytes, storage_alignment);
+ _aux_mem[WorkspaceIO] = MemoryInfo(offset_int_vec(WorkspaceIO), MemoryLifetime::Temporary, std::max(input_workspace_size, output_workspace_size));
+ _aux_mem[PermutedWeights] = MemoryInfo(offset_int_vec(PermutedWeights), MemoryLifetime::Prepare, _weights_hwio.total_size());
+ _aux_mem[TransformedWeights] = MemoryInfo(offset_int_vec(TransformedWeights), MemoryLifetime::Persistent, wds.weight_matrix_size_bytes, storage_alignment);
+ if(_data_layout == DataLayout::NCHW)
{
- ARM_COMPUTE_ERROR("Not supported.");
+ _aux_mem[PermutedInput].merge(offset_int_vec(PermutedInput), src->total_size());
+ _aux_mem[PermutedOutput].merge(offset_int_vec(PermutedOutput), dst->total_size());
}
}
-#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
- else
- {
- ARM_COMPUTE_ERROR("Not supported.");
- }
-
- const PaddingType use_padding_type = (conv_info.pad_top() != 0u || conv_info.pad_left() != 0) ? PADDING_SAME : PADDING_VALID;
- const bool use_same_padding = use_padding_type == PADDING_SAME;
-
- // Get convolved dimensions
- const int in_channels = src->dimension(channel_idx);
- const int out_channels = dst->dimension(channel_idx);
-
- const Tensor4DShape in_shape(internal_get_input_shape(src));
- const size_t data_type_size = src->element_size();
- // Get the memory required to instantiate a new Winograd operator.
- constexpr size_t storage_alignment = 64;
-
- // Kernel Storage
- const size_t kernel_storage_size = transform_weights_kernel->get_weight_storage_size(out_channels, in_channels) * data_type_size;
-
- // Input storage
- const size_t input_storage_size = transform_input_kernel->get_input_storage_size(in_shape.n_batches, in_shape.n_channels, in_shape.n_rows, in_shape.n_cols, use_same_padding) * data_type_size;
-
- // Output storage
- const size_t output_storage_size = transform_output_kernel->get_output_storage_size(in_shape.n_batches, in_shape.n_rows, in_shape.n_cols, out_channels) * data_type_size;
- const int kernel_matrix_stride = transform_weights_kernel->get_matrix_stride(out_channels, in_channels);
- const int output_matrix_stride = transform_output_kernel->get_matrix_stride(in_shape.n_batches, in_shape.n_rows, in_shape.n_cols, out_channels);
- const auto output_shape = transform_output_kernel->get_output_shape(in_shape.n_rows, in_shape.n_cols, use_padding_type == PADDING_SAME);
- const int input_matrix_stride = transform_input_kernel->get_matrix_stride(in_shape.n_batches, in_channels, in_shape.n_rows, in_shape.n_cols, use_padding_type == PADDING_SAME);
-
- // Configure GEMM
- const int tile_rows = iceildiv(output_shape.first, output_tile.height);
- const int tile_cols = iceildiv(output_shape.second, output_tile.width);
- const int m = in_shape.n_batches * tile_rows * tile_cols;
- const int k = in_shape.n_channels;
- const int n = out_channels;
- const int kernel_matrix_row_stride = roundup(out_channels, N_BLOCK);
- const int output_matrix_row_stride = kernel_matrix_row_stride;
-
- TensorShape a_shape(k, m, 1, n_gemms);
- Strides a_strides(data_type_size);
- a_strides.set(1, a_strides[0] * k);
- //a_strides.set(2, data_type_size * input_matrix_stride / n_gemms); FIXME: This is the real batch size, but RSH's code crashes if it's not 0.
- a_strides.set(2, 0);
- a_strides.set(3, data_type_size * input_matrix_stride);
-
- TensorShape b_shape(n, k, n_gemms);
- Strides b_strides(data_type_size);
- b_strides.set(1, data_type_size * kernel_matrix_row_stride);
- b_strides.set(2, data_type_size * kernel_matrix_stride);
-
- TensorShape d_shape(n, m, 1, n_gemms);
- Strides d_strides(data_type_size);
- d_strides.set(1, data_type_size * output_matrix_row_stride);
- //d_strides.set(2, data_type_size * output_matrix_stride / n_gemms); FIXME: This is the real batch size, but RSH's code crashes if it's not 0.
- d_strides.set(2, 0);
- d_strides.set(3, data_type_size * output_matrix_stride);
-
- TensorInfo a_info{};
- TensorInfo b_info{};
- TensorInfo d_info{};
- a_info.init(a_shape, 1, data_type, a_strides, 0, input_storage_size);
- b_info.init(b_shape, 1, data_type, b_strides, 0, kernel_storage_size);
- d_info.init(d_shape, 1, data_type, d_strides, 0, output_storage_size);
-
- _input_transformed = a_info;
- _kernel_storage = b_info;
- _output_transformed = d_info;
-
- const ITensorInfo *input_to_use = src;
- ITensorInfo *output_to_use = dst;
- PermutationVector weights_permutation_vector(3U, 0U, 1U, 2U);
- const unsigned int max_num_threads = NEScheduler::get().num_threads();
-
- // Configure the kernel to transform the input tensor from NCHW -> NHWC
- if(_data_layout == DataLayout::NCHW)
- {
- _permute_input->configure(src, &_input_nhwc, PermutationVector(2U, 0U, 1U));
- input_to_use = &_input_nhwc;
- weights_permutation_vector = PermutationVector(3U, 2U, 0U, 1U);
- }
-
- // Configure input transform kernel
- transform_input_kernel->configure(input_to_use, in_shape.n_batches, in_shape.n_rows, in_shape.n_cols, in_shape.n_channels, use_padding_type,
- &_input_transformed, input_matrix_stride, &_input_workspace);
- const size_t input_workspace_size = transform_input_kernel->get_working_space_size(max_num_threads);
- TensorInfo input_workspace_info(TensorShape(input_workspace_size), 1, DataType::U8);
- _input_workspace = input_workspace_info;
-
- // 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]
- _permute_weights->configure(weights, &_weights_hwio, weights_permutation_vector);
- transform_weights_kernel->configure(&_weights_hwio, &_kernel_storage, kernel_matrix_stride, out_channels, in_channels);
-
- // Configure GEMM function
- _gemm_function->configure(&_input_transformed, &_kernel_storage, nullptr, &_output_transformed, 1.0f, 0.f);
-
- // Configure output transform function
- // The biases tensor has not been allocated at this point in time, the output transform will add the biases to the final result in the run() method
- if(_data_layout == DataLayout::NCHW)
- {
- // configure and allocate dst tensor to be used to convert from winograd domain to spatial domain when calling to reshape_output()
- TensorInfo info(TensorShape(dst->dimension(2), dst->dimension(0),
- dst->dimension(1), dst->dimension(3)),
- 1, dst->data_type());
- _output_nhwc = info;
- output_to_use = &_output_nhwc;
- }
- const arm_gemm::Activation activation = arm_gemm_activation_from_acl_activation(act_info);
-
- transform_output_kernel->configure(biases,
- &_output_transformed,
- output_matrix_stride,
- output_to_use,
- in_shape.n_batches,
- output_shape.first,
- output_shape.second,
- out_channels,
- &_output_workspace,
- activation);
-
- const size_t output_workspace_size = transform_output_kernel->get_working_space_size(max_num_threads);
- TensorInfo output_workspace_info(TensorShape(output_workspace_size), 1, DataType::U8);
- _output_workspace = output_workspace_info;
-
- // Reorder the convoluted output to ACL's ordering NCHW
- if(_data_layout == DataLayout::NCHW)
- {
- _permute_output->configure(&_output_nhwc, dst, PermutationVector(1U, 2U, 0U));
- }
-
- _transform_input_kernel = std::move(transform_input_kernel);
- _transform_weights_kernel = std::move(transform_weights_kernel);
- _transform_output_kernel = std::move(transform_output_kernel);
-
- //Configure Activation Layer
- _run_activation = act_info.enabled() && !fuse_function_supported(act_info);
- if(_run_activation)
- {
- _activation_func->configure(dst, nullptr, act_info);
- }
-
- auto asm_mem_req = _gemm_function->workspace();
- _aux_mem[GemmWorkspace] = asm_mem_req[GemmWorkspace];
- _aux_mem[Pretranspose] = asm_mem_req[Pretranspose];
- _aux_mem[InterleavedLHS] = asm_mem_req[InterleavedLHS];
- _aux_mem[TransposedRHS] = asm_mem_req[TransposedRHS];
- _aux_mem[TempResult] = asm_mem_req[TempResult];
-
- // Request temporary memory. Overlap memory needed for Input/Output transformations as they run on different non-overlapping time-steps.
- _aux_mem[TransformedInput] = MemoryInfo(offset_int_vec(TransformedInput), MemoryLifetime::Temporary, input_storage_size, storage_alignment);
- _aux_mem[TransformedOutput] = MemoryInfo(offset_int_vec(TransformedOutput), MemoryLifetime::Temporary, output_storage_size, storage_alignment);
- _aux_mem[WorkspaceIO] = MemoryInfo(offset_int_vec(WorkspaceIO), MemoryLifetime::Temporary, std::max(input_workspace_size, output_workspace_size));
- _aux_mem[PermutedWeights] = MemoryInfo(offset_int_vec(PermutedWeights), MemoryLifetime::Prepare, _weights_hwio.total_size());
- _aux_mem[TransformedWeights] = MemoryInfo(offset_int_vec(TransformedWeights), MemoryLifetime::Persistent, kernel_storage_size, storage_alignment);
- if(_data_layout == DataLayout::NCHW)
- {
- _aux_mem[PermutedInput].merge(offset_int_vec(PermutedInput), src->total_size());
- _aux_mem[PermutedOutput].merge(offset_int_vec(PermutedOutput), dst->total_size());
- }
}
-
Status CpuWinogradConv2d::validate(const ITensorInfo *src, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *dst,
const PadStrideInfo &conv_info, const ActivationLayerInfo &act_info, bool enable_fast_math)
{
ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(src, weights, dst);
ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(src, weights, biases, dst, conv_info));
- // Get indices for the width and height
- const size_t idx_width = get_data_layout_dimension_index(src->data_layout(), DataLayoutDimension::WIDTH);
- const size_t idx_height = get_data_layout_dimension_index(src->data_layout(), DataLayoutDimension::HEIGHT);
+ const Tensor4DShape kernel_shape{ internal_get_shape(weights) };
+ arm_conv::winograd::WinogradImpl winograd_impl{};
- // Input shape, kernel size and output tile
- const Size2D input_dims = Size2D(src->dimension(idx_width), src->dimension(idx_height));
- const Size2D kernel_size = Size2D(weights->dimension(idx_width), weights->dimension(idx_height));
- const DataType data_type = src->data_type();
- const Size2D output_tile = winograd_output_tile(input_dims, kernel_size, data_type);
+ std::unique_ptr<arm_conv::ConvolutionArgs> conv_args;
+ const bool success = get_winograd_kernel_implementation(src, weights, dst, conv_info, act_info, enable_fast_math, &winograd_impl, conv_args);
- // Check if the Winograd configuration requires fast math
- if(!enable_fast_math)
- {
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(check_support_fast_math(output_tile, kernel_size, data_type),
- "This Winograd configuration requires enable_fast_math=true");
- }
-
- const WinogradInfo winograd_info = WinogradInfo(output_tile,
- kernel_size,
- input_dims,
- conv_info,
- src->data_layout());
-
- // Validate input transform
- const TensorShape input0_shape = misc::shape_calculator::compute_winograd_input_transform_shape(*src, winograd_info);
- const TensorInfo input0 = src->clone()->set_tensor_shape(input0_shape);
- // Validate filter transform
- const TensorShape input1_shape = misc::shape_calculator::compute_winograd_filter_transform_shape(*weights, winograd_info);
- const TensorInfo input1 = weights->clone()->set_tensor_shape(input1_shape);
- // Validate batched matrix multiply
- TensorShape batched_mm_output_shape = input0.tensor_shape();
- batched_mm_output_shape[0] = input1.tensor_shape()[0];
- const TensorInfo batched_mm_output = input0.clone()->set_tensor_shape(batched_mm_output_shape);
-
- if(kernel_size == Size2D(3, 3))
- {
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(conv_info.pad_top() != 0u && conv_info.pad_top() != 1, "Only SAME or VALID padding supported");
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(conv_info.pad_bottom() != 0u && conv_info.pad_bottom() != 1, "Only SAME or VALID padding supported");
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(conv_info.pad_left() != 0u && conv_info.pad_left() != 1, "Only SAME or VALID padding supported");
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(conv_info.pad_right() != 0u && conv_info.pad_right() != 1, "Only SAME or VALID padding supported");
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(conv_info.pad_right() != conv_info.pad_left(), "Only SAME or VALID padding supported");
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(conv_info.pad_top() != conv_info.pad_bottom(), "Only SAME or VALID padding supported");
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(conv_info.pad_top() != conv_info.pad_left(), "Only SAME or VALID padding supported");
- return validate_kernel_3x3(input_dims, src, &input0, &input1, &batched_mm_output, weights, biases, dst, winograd_info, act_info);
- }
- else if(kernel_size == Size2D(5, 5))
- {
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(conv_info.pad_top() != 0u && conv_info.pad_top() != 2, "Only SAME or VALID padding supported");
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(conv_info.pad_left() != 0u && conv_info.pad_left() != 2, "Only SAME or VALID padding supported");
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(conv_info.pad_bottom() != 0u && conv_info.pad_bottom() != 2, "Only SAME or VALID padding supported");
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(conv_info.pad_right() != 0u && conv_info.pad_right() != 2, "Only SAME or VALID padding supported");
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(conv_info.pad_right() != conv_info.pad_left(), "Only SAME or VALID padding supported");
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(conv_info.pad_top() != conv_info.pad_bottom(), "Only SAME or VALID padding supported");
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(conv_info.pad_top() != conv_info.pad_left(), "Only SAME or VALID padding supported");
- return validate_kernel_5x5(src, &input0, &input1, &batched_mm_output, weights, biases, dst, winograd_info, act_info);
- }
- if(kernel_size == Size2D(3, 1))
- {
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(conv_info.pad_left() != 0u && conv_info.pad_left() != 1, "Only SAME or VALID padding supported");
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(conv_info.pad_right() != 0u && conv_info.pad_right() != 1, "Only SAME or VALID padding supported");
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(conv_info.pad_top() != 0u && conv_info.pad_bottom() != 0, "Only SAME or VALID padding supported");
- return validate_kernel_3x1(src, &input0, &input1, &batched_mm_output, weights, biases, dst, winograd_info, act_info);
- }
- else if(kernel_size == Size2D(1, 3))
- {
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(conv_info.pad_top() != 0u && conv_info.pad_top() != 1, "Only SAME or VALID padding supported");
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(conv_info.pad_bottom() != 0u && conv_info.pad_bottom() != 1, "Only SAME or VALID padding supported");
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(conv_info.pad_left() != 0u && conv_info.pad_right() != 0, "Only SAME or VALID padding supported");
- return validate_kernel_1x3(src, &input0, &input1, &batched_mm_output, weights, biases, dst, winograd_info, act_info);
- }
- else if(kernel_size == Size2D(5, 1))
- {
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(conv_info.pad_left() != 0u && conv_info.pad_left() != 2, "Only SAME or VALID padding supported");
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(conv_info.pad_right() != 0u && conv_info.pad_right() != 2, "Only SAME or VALID padding supported");
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(conv_info.pad_top() != 0u && conv_info.pad_bottom() != 0, "Only SAME or VALID padding supported");
- return validate_kernel_5x1(src, &input0, &input1, &batched_mm_output, weights, biases, dst, winograd_info, act_info);
- }
- else if(kernel_size == Size2D(1, 5))
- {
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(conv_info.pad_top() != 0u && conv_info.pad_top() != 2, "Only SAME or VALID padding supported");
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(conv_info.pad_bottom() != 0u && conv_info.pad_bottom() != 2, "Only SAME or VALID padding supported");
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(conv_info.pad_left() != 0u && conv_info.pad_right() != 0, "Only SAME or VALID padding supported");
- return validate_kernel_1x5(src, &input0, &input1, &batched_mm_output, weights, biases, dst, winograd_info, act_info);
- }
- else if(kernel_size == Size2D(7, 1))
- {
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(conv_info.pad_left() != 0u && conv_info.pad_left() != 3, "Only SAME or VALID padding supported");
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(conv_info.pad_right() != 0u && conv_info.pad_right() != 3, "Only SAME or VALID padding supported");
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(conv_info.pad_top() != 0u && conv_info.pad_bottom() != 0, "Only SAME or VALID padding supported");
- return validate_kernel_7x1(src, &input0, &input1, &batched_mm_output, weights, biases, dst, winograd_info, act_info);
- }
- else if(kernel_size == Size2D(1, 7))
- {
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(conv_info.pad_top() != 0u && conv_info.pad_top() != 3, "Only SAME or VALID padding supported");
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(conv_info.pad_bottom() != 0u && conv_info.pad_bottom() != 3, "Only SAME or VALID padding supported");
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(conv_info.pad_left() != 0u && conv_info.pad_right() != 0, "Only SAME or VALID padding supported");
- return validate_kernel_1x7(src, &input0, &input1, &batched_mm_output, weights, biases, dst, winograd_info, act_info);
- }
- else
- {
- ARM_COMPUTE_RETURN_ERROR_MSG("Kernel shape not supported");
- }
+ ARM_COMPUTE_RETURN_ERROR_ON_MSG_VAR(success == false, "Unsupported kernel size: %d x %d.\n", kernel_shape.n_rows, kernel_shape.n_cols);
+ ARM_COMPUTE_LOG_MSG_WITH_FORMAT_ACL(arm_compute::logging::LogLevel::INFO, "Using input transform: %s\n", winograd_impl.input_transform->get_name().c_str());
+ ARM_COMPUTE_LOG_MSG_WITH_FORMAT_ACL(arm_compute::logging::LogLevel::INFO, "Using weight transform: %s\n", winograd_impl.input_transform->get_name().c_str());
+ ARM_COMPUTE_LOG_MSG_WITH_FORMAT_ACL(arm_compute::logging::LogLevel::INFO, "Using output transform: %s\n", winograd_impl.input_transform->get_name().c_str());
+ return Status{};
}
void CpuWinogradConv2d::run(ITensorPack &tensors)
{
prepare(tensors);
+ auto src = tensors.get_const_tensor(ACL_SRC_0);
+ auto biases = tensors.get_const_tensor(ACL_SRC_2);
+ auto output = tensors.get_tensor(ACL_DST);
+ Window win;
- auto a = tensors.get_const_tensor(ACL_SRC_0);
- auto c = tensors.get_const_tensor(ACL_SRC_2);
- auto d = tensors.get_tensor(ACL_DST);
+ const uint32_t nthreads = NEScheduler::get().num_threads();
+ // The Winograd transform implementation does fine-grain threading inside the transforms. Just pass thread_id and nthreads.
+ win.set(Window::DimX, Window::Dimension(0, nthreads, 1));
+
+ // Wrap the winograd-domain tensorInfos created in configuration in tensors and allocate the required memory.
CpuAuxTensorHandler input_nhwc(offset_int_vec(PermutedInput), _input_nhwc, tensors, true);
- CpuAuxTensorHandler input_transformed(offset_int_vec(TransformedInput), _input_transformed, tensors, true);
+ CpuAuxTensorHandler winograd_input_transformed(offset_int_vec(TransformedInput), _winograd_transformed_input, tensors, true);
CpuAuxTensorHandler input_workspace(offset_int_vec(WorkspaceIO), _input_workspace, tensors, true);
-
- const bool is_nchw = _data_layout == DataLayout::NCHW;
+ const bool is_nchw = _data_layout == DataLayout::NCHW;
if(is_nchw)
{
//Bring channels to the front as Winograd code expects the tensor to be in the format NHWC
- ITensorPack pack{ { ACL_SRC, a }, { ACL_DST, input_nhwc.get() } };
+ ITensorPack pack{ { ACL_SRC, src }, { ACL_DST, input_nhwc.get() } };
_permute_input->run(pack);
}
- // Transform input tensor to the winograd domain
- ITensorPack transform_input_pack{ { ACL_SRC, is_nchw ? input_nhwc.get() : a }, { ACL_DST, input_transformed.get() }, { ACL_INT, input_workspace.get() } };
- NEScheduler::get().schedule_op(_transform_input_kernel.get(), Window::DimX, _transform_input_kernel->window(), transform_input_pack);
+ CpuAuxTensorHandler winograd_output_transformed(offset_int_vec(TransformedOutput), _winograd_transformed_output, tensors, true);
+ CpuAuxTensorHandler output_workspace(offset_int_vec(WorkspaceIO), _output_workspace, tensors, true);
+ CpuAuxTensorHandler output_nhwc(offset_int_vec(PermutedOutput), _output_nhwc, tensors, true);
+
+ ITensorPack transform_input_pack{ { ACL_SRC, is_nchw ? input_nhwc.get() : src }, { ACL_DST, winograd_input_transformed.get() }, { ACL_INT, input_workspace.get() } };
+ _transform_input_kernel = std::make_unique<CpuWinogradConv2dTransformInputKernel>(_winograd_impl, *_conv_args, nthreads);
- CpuAuxTensorHandler output_transformed(offset_int_vec(TransformedOutput), _output_transformed, tensors, true);
- CpuAuxTensorHandler weights_transformed(offset_int_vec(TransformedWeights), _kernel_storage, tensors, true);
+ NEScheduler::get().schedule_op(_transform_input_kernel.get(), Window::DimX, win, transform_input_pack);
+
+ CpuAuxTensorHandler winograd_weights_transformed(offset_int_vec(TransformedWeights), _winograd_transformed_weights, tensors, true);
// Run 16 GEMMs in multiple threads, each kernel runs one or more GEMMs
ITensorPack gemm_pack = tensors;
- gemm_pack.add_const_tensor(ACL_SRC, input_transformed.get());
- gemm_pack.add_const_tensor(ACL_SRC_1, weights_transformed.get());
+ gemm_pack.add_const_tensor(ACL_SRC, winograd_input_transformed.get());
+ gemm_pack.add_const_tensor(ACL_SRC_1, winograd_weights_transformed.get());
gemm_pack.add_const_tensor(ACL_BIAS, nullptr);
- gemm_pack.add_tensor(ACL_DST, output_transformed.get());
+ gemm_pack.add_tensor(ACL_DST, winograd_output_transformed.get());
_gemm_function->run(gemm_pack);
- // Transform output tensor to the spatial domain
- CpuAuxTensorHandler output_workspace(offset_int_vec(WorkspaceIO), _output_workspace, tensors, true);
- CpuAuxTensorHandler output_nhwc(offset_int_vec(PermutedOutput), _output_nhwc, tensors, true);
- ITensorPack transform_output_pack{ { ACL_SRC_0, c }, { ACL_SRC_1, output_transformed.get() }, { ACL_DST, is_nchw ? output_nhwc.get() : d }, { ACL_INT, output_workspace.get() } };
- NEScheduler::get().schedule_op(_transform_output_kernel.get(), Window::DimX, _transform_output_kernel->window(), transform_output_pack);
-
+ // Output transform
+ _transform_output_kernel = std::make_unique<CpuWinogradConv2dTransformOutputKernel>(_winograd_impl, *_conv_args, nthreads);
+ ITensorPack transform_output_pack{ { ACL_SRC_0, winograd_output_transformed.get() }, { ACL_DST, is_nchw ? output_nhwc.get() : output }, { ACL_SRC_1, biases }, { ACL_INT, output_workspace.get() } };
+ NEScheduler::get().schedule_op(_transform_output_kernel.get(), Window::DimX, win, transform_output_pack);
if(is_nchw)
{
// Reorder the convoluted output to ACL's ordering NCHW
- ITensorPack pack{ { ACL_SRC, output_nhwc.get() }, { ACL_DST, d } };
+ ITensorPack pack{ { ACL_SRC, output_nhwc.get() }, { ACL_DST, output } };
_permute_output->run(pack);
}
-
if(_run_activation)
{
- ITensorPack pack{ { ACL_SRC, d }, { ACL_DST, d } };
+ ITensorPack pack{ { ACL_SRC, output }, { ACL_DST, output } };
_activation_func->run(pack);
}
}
@@ -808,34 +366,54 @@ void CpuWinogradConv2d::prepare(ITensorPack &tensors)
{
if(!_is_prepared)
{
- // Permute weights
const ITensor *weights = tensors.get_const_tensor(ACL_SRC_1);
ITensor *weights_aux = utils::cast::polymorphic_cast<ITensor *>(tensors.get_tensor(offset_int_vec(PermutedWeights)));
- ARM_COMPUTE_ERROR_ON_NULLPTR(weights, weights_aux);
CpuAuxTensorHandler permuted_weights(_weights_hwio, *weights_aux);
ITensorPack permute_tensors{ { ACL_SRC, weights }, { ACL_DST, permuted_weights.get() } };
_permute_weights->run(permute_tensors);
+ const int element_size_in_bytes = permuted_weights.get()->info()->element_size();
+ // Weights were in OHWI format, before being permuted "permuted_weights" to be in HWIO format.
+ const unsigned int height_idx = 3; // H in HWIO
+ const unsigned int width_idx = 2; // W in HWIO
+ const unsigned int channel_idx = 1; // I in HWIO
- // Transform weights
+ const int permuted_weight_row_stride = permuted_weights.get()->info()->strides_in_bytes()[height_idx] / element_size_in_bytes;
+ const int permuted_weight_col_stride = permuted_weights.get()->info()->strides_in_bytes()[width_idx] / element_size_in_bytes;
+ const int permuted_weight_channel_stride = permuted_weights.get()->info()->strides_in_bytes()[channel_idx] / element_size_in_bytes;
+
+ // Wrap the winograd-domain transformed weight TensorInfo in Auxiliary tensor and allocate the required memory.
ITensor *weights_transf = utils::cast::polymorphic_cast<ITensor *>(tensors.get_tensor(offset_int_vec(TransformedWeights)));
ARM_COMPUTE_ERROR_ON_NULLPTR(weights_transf);
-
- CpuAuxTensorHandler transformed_weights(_kernel_storage, *weights_transf);
- ITensorPack transform_tensors{ { ACL_SRC, permuted_weights.get() }, { ACL_DST, transformed_weights.get() } };
- NEScheduler::get().schedule_op(_transform_weights_kernel.get(), Window::DimX, _transform_weights_kernel->window(), transform_tensors);
-
+ CpuAuxTensorHandler winograd_transformed_weights(_winograd_transformed_weights, *weights_transf);
+
+ const void *permuted_weights_ptr;
+ void *win_wght_transf_ptr;
+
+ permuted_weights_ptr = reinterpret_cast<const void *>(permuted_weights.get()->buffer() + permuted_weights.get()->info()->offset_first_element_in_bytes());
+ win_wght_transf_ptr = reinterpret_cast<void *>(winograd_transformed_weights.get()->buffer() + winograd_transformed_weights.get()->info()->offset_first_element_in_bytes());
+
+ // Prepare Weights
+ _winograd_impl.weight_transform->execute(
+ *_conv_args,
+ permuted_weights_ptr,
+ permuted_weight_row_stride,
+ permuted_weight_col_stride,
+ permuted_weight_channel_stride,
+ win_wght_transf_ptr,
+ _winograd_impl.winograd_spec,
+ 0, 1 // Thread 1 of 1
+ );
ITensorPack gemm_pack = tensors;
- gemm_pack.add_const_tensor(ACL_SRC_1, transformed_weights.get());
+ gemm_pack.add_const_tensor(ACL_SRC_1, winograd_transformed_weights.get());
_gemm_function->prepare(gemm_pack);
-
- _is_prepared = true;
+ _is_prepared = 1;
}
}
-
experimental::MemoryRequirements CpuWinogradConv2d::workspace() const
{
return _aux_mem;
}
+
} // namespace cpu
-} // namespace arm_compute \ No newline at end of file
+} // namespace arm_compute
diff --git a/src/cpu/operators/CpuWinogradConv2d.h b/src/cpu/operators/CpuWinogradConv2d.h
index 0abd110f73..e0df34e2db 100644
--- a/src/cpu/operators/CpuWinogradConv2d.h
+++ b/src/cpu/operators/CpuWinogradConv2d.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021 Arm Limited.
+ * Copyright (c) 2021-2022 Arm Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -29,6 +29,7 @@
#include "src/core/common/Macros.h"
#include "src/cpu/ICpuOperator.h"
#include "src/cpu/kernels/CpuWinogradConv2dKernel.h"
+#include "src/cpu/kernels/assembly/gemm_common.hpp"
#include "src/cpu/operators/CpuActivation.h"
#include "src/cpu/operators/CpuGemm.h"
#include "src/cpu/operators/CpuPermute.h"
@@ -59,13 +60,13 @@ public:
* |F16 |F16 |F16 |F16 |
* |F32 |F32 |F32 |F32 |
*
- * @param[in] src Source tensor info. 3 lower dimensions represent a single input [width, height, IFM],
+ * @param[in] src Source tensor Info. 3 lower dimensions represent a single input [width, height, IFM],
* while every optional dimension from 4 and above represent a batch of inputs.
* Data types supported: F16/F32.
- * @param[in] weights Weights tensor info. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM]. Data type supported: Same as @p input.
+ * @param[in] weights Weights tensor Info. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM]. Data type supported: Same as @p input.
* Currently only 3x3 and 5x5 kernels are supported.
- * @param[in] biases Biases tensor info. Shared biases supported. Biases are 1D tensor with dimensions [OFM]. Data type supported: Same as @p weights.
- * @param[out] dst Destination tensor info. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs.
+ * @param[in] biases Biases tensor Info. Shared biases supported. Biases are 1D tensor with dimensions [OFM]. Data type supported: Same as @p weights.
+ * @param[out] dst Destination tensor Info. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs.
* Data types supported: Same as @p input.
* @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo. Currently only unit strides are supported.
* @param[in] act_info (Optional) Activation layer information in case of a fused activation.
@@ -107,28 +108,27 @@ private:
PermutedOutput = TransformedInput,
Count = 10
};
-
- std::unique_ptr<CpuGemm> _gemm_function;
- std::unique_ptr<CpuActivation> _activation_func;
- std::unique_ptr<CpuPermute> _permute_input;
- std::unique_ptr<CpuPermute> _permute_output;
- std::unique_ptr<CpuPermute> _permute_weights;
- std::unique_ptr<ICPPKernel> _transform_input_kernel;
- std::unique_ptr<ICPPKernel> _transform_weights_kernel;
- std::unique_ptr<ICPPKernel> _transform_output_kernel;
-
- DataLayout _data_layout;
- experimental::MemoryRequirements _aux_mem{ Count };
- TensorInfo _input_nhwc;
- TensorInfo _output_nhwc;
- TensorInfo _input_workspace;
- TensorInfo _kernel_storage;
- TensorInfo _output_workspace;
- TensorInfo _input_transformed;
- TensorInfo _output_transformed;
- TensorInfo _weights_hwio;
- bool _run_activation;
- bool _is_prepared;
+ std::unique_ptr<CpuGemm> _gemm_function;
+ std::unique_ptr<CpuActivation> _activation_func;
+ std::unique_ptr<ICPPKernel> _transform_input_kernel;
+ std::unique_ptr<ICPPKernel> _transform_output_kernel;
+ std::unique_ptr<CpuPermute> _permute_input;
+ std::unique_ptr<CpuPermute> _permute_output;
+ std::unique_ptr<CpuPermute> _permute_weights;
+ experimental::MemoryRequirements _aux_mem{ Count };
+ std::unique_ptr<arm_conv::ConvolutionArgs> _conv_args; // Make it unique ptr because this type does not have a default constructor
+ arm_conv::winograd::WinogradImpl _winograd_impl;
+ DataLayout _data_layout;
+ TensorInfo _winograd_transformed_input;
+ TensorInfo _winograd_transformed_output;
+ TensorInfo _winograd_transformed_weights;
+ TensorInfo _input_workspace;
+ TensorInfo _output_workspace;
+ TensorInfo _weights_hwio;
+ TensorInfo _input_nhwc;
+ TensorInfo _output_nhwc;
+ bool _is_prepared;
+ bool _run_activation;
};
} // namespace cpu
} // namespace arm_compute
diff --git a/src/runtime/NEON/functions/NEWinogradConvolutionLayer.cpp b/src/runtime/NEON/functions/NEWinogradConvolutionLayer.cpp
index f0c153d4f4..a8eded29ff 100644
--- a/src/runtime/NEON/functions/NEWinogradConvolutionLayer.cpp
+++ b/src/runtime/NEON/functions/NEWinogradConvolutionLayer.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2021 Arm Limited.
+ * Copyright (c) 2017-2022 Arm Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -34,7 +34,6 @@
#include "src/cpu/operators/CpuWinogradConv2d.h"
#include "src/core/NEON/kernels/convolution/common/utils.hpp"
-#include "src/core/NEON/kernels/convolution/winograd/winograd.hpp"
namespace arm_compute
{