Michele Di Giorgio | d556d7b | 2020-10-27 10:56:31 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2021 Arm Limited. |
| 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
| 24 | |
| 25 | // This can only be built if the target/compiler supports FP16 arguments. |
| 26 | #ifdef __ARM_FP16_ARGS |
| 27 | |
| 28 | #include "arm_gemm_local.hpp" |
| 29 | |
| 30 | #include "pooling_implementation.hpp" |
| 31 | #include "pooling_depthfirst.hpp" |
| 32 | #include "pooling_depthfirst_generic.hpp" |
| 33 | |
| 34 | #include "kernels/cpp_nhwc_1x1_stride_any_depthfirst.hpp" |
| 35 | #if defined(__aarch64__) |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame^] | 36 | #if defined(ARM_COMPUTE_ENABLE_SVE) |
Michele Di Giorgio | d556d7b | 2020-10-27 10:56:31 +0000 | [diff] [blame] | 37 | #include "kernels/sve_fp16_nhwc_max_2x2_s1_output2x2_depthfirst.hpp" |
| 38 | #include "kernels/sve_fp16_nhwc_avg_3x3_s1_output2x2_depthfirst.hpp" |
| 39 | #include "kernels/sve_fp16_nhwc_avg_generic_depthfirst.hpp" |
| 40 | #include "kernels/sve_fp16_nhwc_max_generic_depthfirst.hpp" |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame^] | 41 | #endif // defined(ARM_COMPUTE_ENABLE_SVE) |
Michele Di Giorgio | d556d7b | 2020-10-27 10:56:31 +0000 | [diff] [blame] | 42 | #include "kernels/a64_fp16_nhwc_max_2x2_s1_output2x2_depthfirst.hpp" |
| 43 | #include "kernels/a64_fp16_nhwc_avg_3x3_s1_output2x2_depthfirst.hpp" |
| 44 | #include "kernels/a64_fp16_nhwc_avg_generic_depthfirst.hpp" |
| 45 | #include "kernels/a64_fp16_nhwc_max_generic_depthfirst.hpp" |
| 46 | #endif // defined(__aarch64__) |
| 47 | |
| 48 | namespace arm_conv { |
| 49 | namespace pooling { |
| 50 | |
| 51 | namespace |
| 52 | { |
| 53 | template <class Strategy> |
| 54 | bool is_supported(const PoolingArgs &args, const Nothing &) |
| 55 | { |
| 56 | return ((args.pool_type == Strategy::pooling_type()) && |
| 57 | (args.pool_window.rows == Strategy::pool_rows()) && |
| 58 | (args.pool_window.cols == Strategy::pool_cols()) && |
| 59 | (args.pool_stride.rows == Strategy::stride_rows()) && |
| 60 | (args.pool_stride.cols == Strategy::stride_cols())); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | static const PoolingImplementation<__fp16, __fp16> pooling_fp16_methods[] = { |
| 65 | { |
| 66 | PoolingMethod::DEPTHFIRST, |
| 67 | "cpp_fp16_nhwc_1x1_stride_any_depthfirst", |
| 68 | [] (const PoolingArgs &args, const Nothing &) -> bool { |
| 69 | return args.pool_window.rows == 1 && args.pool_window.cols == 1; |
| 70 | }, |
| 71 | nullptr, |
| 72 | [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<__fp16, __fp16> * { |
| 73 | return new PoolingDepthfirstGeneric<cpp_nhwc_1x1_stride_any_depthfirst<__fp16>>(args); |
| 74 | }, |
| 75 | }, |
| 76 | #if defined(__aarch64__) |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame^] | 77 | #if defined(ARM_COMPUTE_ENABLE_SVE) |
Michele Di Giorgio | d556d7b | 2020-10-27 10:56:31 +0000 | [diff] [blame] | 78 | { |
| 79 | PoolingMethod::DEPTHFIRST, |
| 80 | "sve_fp16_nhwc_max_2x2_s1_output2x2_depthfirst", |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame^] | 81 | [] (const PoolingArgs &args, const Nothing &unused) -> bool { |
| 82 | return args.cpu_info->has_sve() && is_supported<sve_fp16_nhwc_max_2x2_s1_output2x2_depthfirst>(args, unused); |
| 83 | }, |
Michele Di Giorgio | d556d7b | 2020-10-27 10:56:31 +0000 | [diff] [blame] | 84 | nullptr, |
| 85 | [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<__fp16, __fp16> * { |
| 86 | return new PoolingDepthfirst<sve_fp16_nhwc_max_2x2_s1_output2x2_depthfirst>(args); |
| 87 | }, |
| 88 | }, |
| 89 | { |
| 90 | PoolingMethod::DEPTHFIRST, |
| 91 | "sve_fp16_nhwc_avg_3x3_s1_output2x2_depthfirst", |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame^] | 92 | [] (const PoolingArgs &args, const Nothing &unused) -> bool { |
| 93 | return args.cpu_info->has_sve() && is_supported<sve_fp16_nhwc_avg_3x3_s1_output2x2_depthfirst>(args, unused); |
| 94 | }, |
Michele Di Giorgio | d556d7b | 2020-10-27 10:56:31 +0000 | [diff] [blame] | 95 | nullptr, |
| 96 | [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<__fp16, __fp16> * { |
| 97 | return new PoolingDepthfirst<sve_fp16_nhwc_avg_3x3_s1_output2x2_depthfirst>(args); |
| 98 | }, |
| 99 | }, |
| 100 | { |
| 101 | PoolingMethod::DEPTHFIRST, |
| 102 | "sve_fp16_nhwc_avg_generic_depthfirst", |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame^] | 103 | [] (const PoolingArgs &args, const Nothing &) -> bool { return args.cpu_info->has_sve() && args.pool_type == PoolingType::AVERAGE; }, |
Michele Di Giorgio | d556d7b | 2020-10-27 10:56:31 +0000 | [diff] [blame] | 104 | nullptr, |
| 105 | [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<__fp16, __fp16> * { |
| 106 | return new PoolingDepthfirstGeneric<sve_fp16_nhwc_avg_generic_depthfirst>(args); |
| 107 | }, |
| 108 | }, |
| 109 | { |
| 110 | PoolingMethod::DEPTHFIRST, |
| 111 | "sve_fp16_nhwc_max_generic_depthfirst", |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame^] | 112 | [] (const PoolingArgs &args, const Nothing &) -> bool { return args.cpu_info->has_sve() && args.pool_type == PoolingType::MAX; }, |
Michele Di Giorgio | d556d7b | 2020-10-27 10:56:31 +0000 | [diff] [blame] | 113 | nullptr, |
| 114 | [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<__fp16, __fp16> * { |
| 115 | return new PoolingDepthfirstGeneric<sve_fp16_nhwc_max_generic_depthfirst>(args); |
| 116 | }, |
| 117 | }, |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame^] | 118 | #endif // defined(ARM_COMPUTE_ENABLE_SVE) |
Michele Di Giorgio | d556d7b | 2020-10-27 10:56:31 +0000 | [diff] [blame] | 119 | #if defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) |
| 120 | { |
| 121 | PoolingMethod::DEPTHFIRST, |
| 122 | "a64_fp16_nhwc_max_2x2_s1_output2x2_depthfirst", |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame^] | 123 | [] (const PoolingArgs &args, const Nothing &unused) -> bool { |
| 124 | return args.cpu_info->has_fp16() && is_supported<a64_fp16_nhwc_max_2x2_s1_output2x2_depthfirst>(args, unused); |
| 125 | }, |
Michele Di Giorgio | d556d7b | 2020-10-27 10:56:31 +0000 | [diff] [blame] | 126 | nullptr, |
| 127 | [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<__fp16, __fp16> * { |
| 128 | return new PoolingDepthfirst<a64_fp16_nhwc_max_2x2_s1_output2x2_depthfirst>(args); |
| 129 | }, |
| 130 | }, |
| 131 | { |
| 132 | PoolingMethod::DEPTHFIRST, |
| 133 | "a64_fp16_nhwc_avg_3x3_s1_output2x2_depthfirst", |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame^] | 134 | [] (const PoolingArgs &args, const Nothing &unused) -> bool { |
| 135 | return args.cpu_info->has_fp16() && is_supported<a64_fp16_nhwc_avg_3x3_s1_output2x2_depthfirst>(args, unused); |
| 136 | }, |
Michele Di Giorgio | d556d7b | 2020-10-27 10:56:31 +0000 | [diff] [blame] | 137 | nullptr, |
| 138 | [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<__fp16, __fp16> * { |
| 139 | return new PoolingDepthfirst<a64_fp16_nhwc_avg_3x3_s1_output2x2_depthfirst>(args); |
| 140 | }, |
| 141 | }, |
| 142 | { |
| 143 | PoolingMethod::DEPTHFIRST, |
| 144 | "a64_fp16_nhwc_avg_generic_depthfirst", |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame^] | 145 | [] (const PoolingArgs &args, const Nothing &) -> bool { return args.cpu_info->has_fp16() && args.pool_type == PoolingType::AVERAGE; }, |
Michele Di Giorgio | d556d7b | 2020-10-27 10:56:31 +0000 | [diff] [blame] | 146 | nullptr, |
| 147 | [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<__fp16, __fp16> * { |
| 148 | return new PoolingDepthfirstGeneric<a64_fp16_nhwc_avg_generic_depthfirst>(args); |
| 149 | }, |
| 150 | }, |
| 151 | { |
| 152 | PoolingMethod::DEPTHFIRST, |
| 153 | "a64_fp16_nhwc_max_generic_depthfirst", |
Michalis Spyrou | 20fca52 | 2021-06-07 14:23:57 +0100 | [diff] [blame^] | 154 | [] (const PoolingArgs &args, const Nothing &) -> bool { return args.cpu_info->has_fp16() && args.pool_type == PoolingType::MAX; }, |
Michele Di Giorgio | d556d7b | 2020-10-27 10:56:31 +0000 | [diff] [blame] | 155 | nullptr, |
| 156 | [] (const PoolingArgs &args, const Nothing &) -> PoolingCommon<__fp16, __fp16> * { |
| 157 | return new PoolingDepthfirstGeneric<a64_fp16_nhwc_max_generic_depthfirst>(args); |
| 158 | }, |
| 159 | }, |
| 160 | #endif // defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) |
| 161 | #endif // defined(__aarch64__) |
| 162 | { PoolingMethod::DEFAULT, "", nullptr, nullptr, nullptr }, // End of list |
| 163 | }; |
| 164 | |
| 165 | template <> |
| 166 | const PoolingImplementation<__fp16, __fp16> *pooling_implementation_list() |
| 167 | { |
| 168 | return pooling_fp16_methods; |
| 169 | } |
| 170 | |
| 171 | template UniquePoolingCommon<__fp16, __fp16> pooling(const PoolingArgs &, const Nothing &); |
| 172 | |
| 173 | } // namespace pooling |
| 174 | } // namespace arm_conv |
| 175 | |
| 176 | #endif // __ARM_FP16_ARGS |