Michele Di Giorgio | d02d5ed | 2021-01-22 09:47:04 +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 | #include "src/core/NEON/kernels/arm_gemm/utils.hpp" |
| 26 | |
| 27 | #include <cstdint> |
| 28 | |
| 29 | #pragma once |
| 30 | |
Freddie Liardet | d216f57 | 2021-08-03 15:57:32 +0100 | [diff] [blame^] | 31 | #if __aarch64__ && defined(ARM_COMPUTE_ENABLE_SVE) && defined(__ARM_FP16_ARGS) |
Michele Di Giorgio | d02d5ed | 2021-01-22 09:47:04 +0000 | [diff] [blame] | 32 | |
| 33 | namespace arm_conv { |
| 34 | namespace depthwise { |
| 35 | |
| 36 | void sve_fp16_nhwc_3x3_s1_output2x2_mla_depthfirst_indirect_impl(const __fp16 *const *const, __fp16 *const *const, const void *, unsigned int, const __fp16, const __fp16); |
| 37 | void sve_fp16_nhwc_3x3_s1_output2x2_mla_depthfirst_direct_impl(const unsigned int, const unsigned int, const __fp16 *, int64_t, int64_t, __fp16 *, int64_t, int64_t, const void *, unsigned int, const __fp16, const __fp16); |
| 38 | |
Freddie Liardet | d216f57 | 2021-08-03 15:57:32 +0100 | [diff] [blame^] | 39 | class sve_fp16_nhwc_3x3_s1_output2x2_mla_depthfirst : public IDepthwiseDepthfirstStrategy |
Michele Di Giorgio | d02d5ed | 2021-01-22 09:47:04 +0000 | [diff] [blame] | 40 | { |
Freddie Liardet | d216f57 | 2021-08-03 15:57:32 +0100 | [diff] [blame^] | 41 | private: |
Michele Di Giorgio | d02d5ed | 2021-01-22 09:47:04 +0000 | [diff] [blame] | 42 | typedef void (*indirect_kern_type)(const __fp16 *const *const, __fp16 *const *const, const void *, unsigned int, const __fp16, const __fp16); |
Freddie Liardet | d216f57 | 2021-08-03 15:57:32 +0100 | [diff] [blame^] | 43 | indirect_kern_type m_indirect_kernel = sve_fp16_nhwc_3x3_s1_output2x2_mla_depthfirst_indirect_impl; |
| 44 | |
Michele Di Giorgio | d02d5ed | 2021-01-22 09:47:04 +0000 | [diff] [blame] | 45 | typedef void (*direct_kern_type)(const unsigned int, const unsigned int, const __fp16 *, int64_t, int64_t, __fp16 *, int64_t, int64_t, const void *, unsigned int, const __fp16, const __fp16); |
Freddie Liardet | d216f57 | 2021-08-03 15:57:32 +0100 | [diff] [blame^] | 46 | direct_kern_type m_direct_kernel = sve_fp16_nhwc_3x3_s1_output2x2_mla_depthfirst_direct_impl; |
| 47 | |
| 48 | public: |
| 49 | typedef __fp16 return_type; |
Michele Di Giorgio | d02d5ed | 2021-01-22 09:47:04 +0000 | [diff] [blame] | 50 | |
| 51 | constexpr static arm_gemm::VLType vl_type = arm_gemm::VLType::SVE; |
| 52 | |
| 53 | constexpr static unsigned int kernel_rows = 3; |
| 54 | constexpr static unsigned int kernel_cols = 3; |
| 55 | |
| 56 | constexpr static unsigned int stride_rows = 1; |
| 57 | constexpr static unsigned int stride_cols = 1; |
| 58 | |
| 59 | constexpr static unsigned int output_rows = 2; |
| 60 | constexpr static unsigned int output_cols = 2; |
| 61 | |
| 62 | constexpr static unsigned int input_rows = 4; |
| 63 | constexpr static unsigned int input_cols = 4; |
| 64 | |
Michele Di Giorgio | d02d5ed | 2021-01-22 09:47:04 +0000 | [diff] [blame] | 65 | sve_fp16_nhwc_3x3_s1_output2x2_mla_depthfirst(const CPUInfo *) {} |
Freddie Liardet | d216f57 | 2021-08-03 15:57:32 +0100 | [diff] [blame^] | 66 | |
| 67 | arm_gemm::VLType get_vl_type(void) const override { return vl_type; } |
| 68 | |
| 69 | unsigned int get_kernel_rows(void) const override { return kernel_rows; } |
| 70 | unsigned int get_kernel_cols(void) const override { return kernel_cols; } |
| 71 | |
| 72 | unsigned int get_stride_rows(void) const override { return stride_rows; } |
| 73 | unsigned int get_stride_cols(void) const override { return stride_cols; } |
| 74 | |
| 75 | unsigned int get_output_rows(void) const override { return output_rows; } |
| 76 | unsigned int get_output_cols(void) const override { return output_cols; } |
| 77 | |
| 78 | unsigned int get_input_rows(void) const override { return input_rows; } |
| 79 | unsigned int get_input_cols(void) const override { return input_cols; } |
| 80 | |
| 81 | void indirect_kernel( |
| 82 | const void *const *const input_ptrs, |
| 83 | void *const *const outptrs, |
| 84 | const void *params, |
| 85 | unsigned int n_channels, |
| 86 | const void *activation_min, |
| 87 | const void *activation_max |
| 88 | ) const override |
| 89 | { |
| 90 | m_indirect_kernel( |
| 91 | reinterpret_cast<const __fp16 *const *>(input_ptrs), |
| 92 | reinterpret_cast<__fp16 *const *>(outptrs), |
| 93 | params, n_channels, |
| 94 | *static_cast<const __fp16 *>(activation_min), |
| 95 | *static_cast<const __fp16 *>(activation_max) |
| 96 | ); |
| 97 | } |
| 98 | |
| 99 | void direct_kernel( |
| 100 | const unsigned int n_tile_rows, const unsigned int n_tile_cols, |
| 101 | const void *inptr, int64_t ld_input_row, int64_t ld_input_col, |
| 102 | void *outptr, int64_t ld_output_row, int64_t ld_output_col, |
| 103 | const void *params, unsigned int n_channels, |
| 104 | const void *activation_min, const void *activation_max |
| 105 | ) const override |
| 106 | { |
| 107 | m_direct_kernel( |
| 108 | n_tile_rows, n_tile_cols, |
| 109 | static_cast<const __fp16 *>(inptr), ld_input_row, ld_input_col, |
| 110 | static_cast<__fp16 *>(outptr), ld_output_row, ld_output_col, |
| 111 | params, n_channels, |
| 112 | *static_cast<const __fp16 *>(activation_min), |
| 113 | *static_cast<const __fp16 *>(activation_max) |
| 114 | ); |
| 115 | } |
Michele Di Giorgio | d02d5ed | 2021-01-22 09:47:04 +0000 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | } // namespace depthwise |
| 119 | } // namespace arm_conv |
| 120 | |
Freddie Liardet | d216f57 | 2021-08-03 15:57:32 +0100 | [diff] [blame^] | 121 | #endif // __aarch64__ && defined(ARM_COMPUTE_ENABLE_SVE) && defined(__ARM_FP16_ARGS) |