Freddie Liardet | d216f57 | 2021-08-03 15:57:32 +0100 | [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 "arm_gemm.hpp" |
| 26 | #include "src/core/NEON/kernels/arm_gemm/utils.hpp" |
| 27 | #include "src/core/NEON/kernels/assembly/depthwise.hpp" |
| 28 | #include <cstdint> |
| 29 | #include <cstring> |
| 30 | |
| 31 | using namespace arm_gemm; |
| 32 | |
| 33 | size_t generic_get_packed_size( |
| 34 | const VLType vec_type, |
| 35 | const unsigned int acc_depth, |
| 36 | const unsigned int kernel_rows, |
| 37 | const unsigned int kernel_cols, |
| 38 | const unsigned int n_input_channels |
| 39 | ); |
| 40 | |
| 41 | void generic_pack( |
| 42 | const VLType vec_type, |
| 43 | const unsigned int acc_depth, |
| 44 | const unsigned int kernel_rows, |
| 45 | const unsigned int kernel_cols, |
| 46 | const unsigned int n_channels, |
| 47 | void *_outptr, |
| 48 | const void *_weights, |
| 49 | size_t ld_weight_col, |
| 50 | size_t ld_weight_row |
| 51 | ); |
| 52 | |
| 53 | #define ADD_IMPLEMENTATION(ARCH, TYPENAME, TYPE, VEC_TYPE, ACC_DEPTH, KERN_ROWS, KERN_COLS) \ |
| 54 | struct interleave_ ## ARCH ## _ ## TYPENAME ## _ ## KERN_ROWS ## x ## KERN_COLS ## _mla \ |
| 55 | { \ |
| 56 | static size_t get_packed_size(const DepthwiseArgs &args); \ |
| 57 | static void pack_parameters( \ |
| 58 | unsigned int n_channels, void *outptr, \ |
| 59 | const TYPE *weights, size_t ld_weight_col, size_t ld_weight_row \ |
| 60 | ); \ |
| 61 | }; \ |
| 62 | \ |
| 63 | size_t interleave_ ## ARCH ## _ ## TYPENAME ## _ ## KERN_ROWS ## x ## KERN_COLS ## _mla::get_packed_size(const DepthwiseArgs &args) \ |
| 64 | { \ |
| 65 | return generic_get_packed_size(VLType::VEC_TYPE, ACC_DEPTH, KERN_ROWS, KERN_COLS, args.input_channels); \ |
| 66 | } \ |
| 67 | \ |
| 68 | void interleave_ ## ARCH ## _ ## TYPENAME ## _ ## KERN_ROWS ## x ## KERN_COLS ## _mla::pack_parameters(unsigned int n_channels, void *outptr, \ |
| 69 | const TYPE *weights, size_t ld_weight_col, size_t ld_weight_row) \ |
| 70 | { \ |
| 71 | generic_pack(VLType::VEC_TYPE, ACC_DEPTH, KERN_ROWS, KERN_COLS, n_channels, outptr, weights, ld_weight_col, ld_weight_row); \ |
| 72 | } |