Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 1 | /* |
Pablo Tello | 9ceebbe | 2018-01-10 16:44:13 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 ARM Limited. |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +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 | #ifndef __ARM_COMPUTE_NEWINOGRADLAYER_H__ |
| 25 | #define __ARM_COMPUTE_NEWINOGRADLAYER_H__ |
| 26 | |
| 27 | #include "arm_compute/runtime/IFunction.h" |
| 28 | |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 29 | #include "arm_compute/core/NEON/INEKernel.h" |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 30 | #include "arm_compute/core/Types.h" |
Pablo Tello | 02541fb | 2017-12-15 09:48:59 +0000 | [diff] [blame] | 31 | #include "arm_compute/runtime/CPP/functions/CPPPermute.h" |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 32 | #include "arm_compute/runtime/MemoryGroup.h" |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 33 | #include "arm_compute/runtime/NEON/functions/NEActivationLayer.h" |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 34 | #include "arm_compute/runtime/Tensor.h" |
| 35 | |
| 36 | #include <memory> |
| 37 | |
| 38 | namespace arm_compute |
| 39 | { |
| 40 | class ITensor; |
| 41 | /** Basic function to simulate a convolution layer. This function calls the following NEON kernels: |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 42 | * -# @ref NEWinogradLayerTransformWeightsKernel (executed only once in the first call to the run() method ) |
| 43 | * -# @ref NEWinogradLayerTransformInputKernel |
| 44 | * -# @ref NEWinogradLayerTransformOutputKernel |
| 45 | * -# @ref NEWinogradLayerBatchedGEMMKernel |
| 46 | * -# @ref CPPPermute (three times: weights, input and output) |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 47 | */ |
| 48 | class NEWinogradLayer : public IFunction |
| 49 | { |
| 50 | public: |
| 51 | /** Constructor */ |
| 52 | NEWinogradLayer(std::shared_ptr<IMemoryManager> memory_manager = nullptr); |
| 53 | |
| 54 | /** Set the input and output tensors. |
| 55 | * |
| 56 | * @param[in] input Source tensor. 3 lower dimensions represent a single input [width, height, IFM], |
| 57 | * while every optional dimension from 4 and above represent a batch of inputs. |
| 58 | * Data types supported: F32. |
| 59 | * @param[in] weights Weights tensor. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM]. Data type supported: Same as @p input. |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 60 | * Currently only 3x3 and 5x5 kernels are supported. |
Pablo Tello | d6ca478 | 2018-01-23 09:36:04 +0000 | [diff] [blame] | 61 | * @param[in] biases Biases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM]. Data type supported: Same as @p weights. |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 62 | * @param[out] output Destination tensor. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs. |
| 63 | * Data types supported: Same as @p input. |
| 64 | * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo. Currently only unit strides are supported. |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 65 | * @param[in] act_info (Optional) Activation layer information in case of a fused activation. |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 66 | */ |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 67 | void configure(const ITensor *input, const ITensor *weights, const ITensor *biases, ITensor *output, const PadStrideInfo &conv_info, const ActivationLayerInfo &act_info = ActivationLayerInfo()); |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 68 | |
| 69 | // Inherited methods overridden: |
| 70 | void run() override; |
| 71 | |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 72 | /** Static function to check if given info will lead to a valid configuration of @ref NEGEMMConvolutionLayer |
| 73 | * |
| 74 | * @param[in] input Source tensor. 3 lower dimensions represent a single input [width, height, IFM], |
| 75 | * while every optional dimension from 4 and above represent a batch of inputs. |
| 76 | * Data types supported: F32. |
| 77 | * @param[in] weights Weights tensor. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM]. Data type supported:Same as @p input. |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 78 | * Currently only 3x3 and 5x5 kernels are supported. |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 79 | * @param[in] biases Biases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM]. Data type supported: Same as @p weights. |
| 80 | * @param[in] output Destination tensor. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs. |
| 81 | * Data types supported: Same as @p input. |
| 82 | * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo. Currently only unit strides are supported. |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 83 | * @param[in] act_info (Optional) Activation layer information in case of a fused activation. |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 84 | * |
| 85 | * @return a status |
| 86 | */ |
Vidhya Sudhan Loganathan | 3ca9786 | 2018-04-23 08:20:04 +0100 | [diff] [blame] | 87 | static Status validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info, |
| 88 | const ActivationLayerInfo &act_info = ActivationLayerInfo()); |
Isabella Gottardi | 6acc6ad | 2018-02-02 17:19:18 +0000 | [diff] [blame] | 89 | |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 90 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 91 | NEWinogradLayer(const NEWinogradLayer &) = delete; |
| 92 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 93 | NEWinogradLayer &operator=(const NEWinogradLayer &) = delete; |
| 94 | |
| 95 | private: |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 96 | MemoryGroup _memory_group; |
| 97 | std::unique_ptr<INEKernel> _batched_gemm_kernel; |
| 98 | std::unique_ptr<INEKernel> _transform_input_kernel; |
| 99 | std::unique_ptr<INEKernel> _transform_output_kernel; |
| 100 | std::unique_ptr<INEKernel> _transform_weights_kernel; |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 101 | NEActivationLayer _activationlayer_function; |
Pablo Tello | f6c572c | 2018-02-14 12:47:30 +0000 | [diff] [blame] | 102 | |
Pablo Tello | 52140b4 | 2018-01-30 14:48:11 +0000 | [diff] [blame] | 103 | CPPPermute _permute_input; |
| 104 | CPPPermute _permute_weights; |
| 105 | CPPPermute _permute_output; |
| 106 | Tensor _input_workspace; |
| 107 | Tensor _output_workspace; |
| 108 | Tensor _kernel_storage; |
| 109 | Tensor _input_nhwc; |
| 110 | Tensor _output_nhwc; |
| 111 | Tensor _weights_hwio; |
| 112 | const ITensor *_input; |
| 113 | const ITensor *_weights; |
| 114 | ITensor *_output; |
| 115 | bool _reshaped_kernel; |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 116 | bool _is_activationlayer_enabled; |
Pablo Tello | 8951933 | 2017-11-17 11:52:36 +0000 | [diff] [blame] | 117 | }; |
| 118 | } |
| 119 | #endif /* __ARM_COMPUTE_NEWINOGRADLAYER_H__ */ |