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