Giorgio Arena | 657bdb3 | 2018-04-26 18:52:01 +0100 | [diff] [blame] | 1 | /* |
Michalis Spyrou | 1a569a3 | 2019-09-10 17:20:34 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2019 ARM Limited. |
Giorgio Arena | 657bdb3 | 2018-04-26 18:52:01 +0100 | [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 | */ |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_NECONVERTFULLYCONNECTEDWEIGHTS_H |
| 25 | #define ARM_COMPUTE_NECONVERTFULLYCONNECTEDWEIGHTS_H |
Giorgio Arena | 657bdb3 | 2018-04-26 18:52:01 +0100 | [diff] [blame] | 26 | |
| 27 | #include "arm_compute/core/NEON/kernels/NEConvertFullyConnectedWeightsKernel.h" |
| 28 | #include "arm_compute/runtime/IFunction.h" |
Michalis Spyrou | 1a569a3 | 2019-09-10 17:20:34 +0100 | [diff] [blame] | 29 | #include "arm_compute/runtime/ITransformWeights.h" |
Giorgio Arena | 657bdb3 | 2018-04-26 18:52:01 +0100 | [diff] [blame] | 30 | #include "arm_compute/runtime/NEON/NEScheduler.h" |
Michalis Spyrou | 1a569a3 | 2019-09-10 17:20:34 +0100 | [diff] [blame] | 31 | #include "arm_compute/runtime/Tensor.h" |
Giorgio Arena | 657bdb3 | 2018-04-26 18:52:01 +0100 | [diff] [blame] | 32 | |
| 33 | namespace arm_compute |
| 34 | { |
| 35 | class ITensor; |
| 36 | |
| 37 | /** Basic function to run @ref NEConvertFullyConnectedWeightsKernel. */ |
| 38 | class NEConvertFullyConnectedWeights : public IFunction |
| 39 | { |
| 40 | public: |
| 41 | /** Default constructor */ |
| 42 | NEConvertFullyConnectedWeights(); |
| 43 | /** Initialize the function. |
| 44 | * |
Vidhya Sudhan Loganathan | f4cb81b | 2018-07-04 15:13:14 +0100 | [diff] [blame] | 45 | * @param[in] input Source weights tensor to convert. Must be 2 dimensional. Data types supported: U8/S8/QASYMM8/U16/S16/U32/S32/F16/F32. |
Giorgio Arena | 657bdb3 | 2018-04-26 18:52:01 +0100 | [diff] [blame] | 46 | * @param[out] output The converted weights tensor. Shape and Data Type: Same as @p input. |
Georgios Pinitas | 7d66a8e | 2018-07-17 12:28:42 +0100 | [diff] [blame] | 47 | * @param[in] original_input_shape Shape of the original input tensor (the one entering fully connected layer). |
Giorgio Arena | 657bdb3 | 2018-04-26 18:52:01 +0100 | [diff] [blame] | 48 | * @param[in] data_layout The data layout the weights have been trained in. |
| 49 | */ |
| 50 | void configure(const ITensor *input, ITensor *output, const TensorShape &original_input_shape, DataLayout data_layout); |
| 51 | /** Static function to check if given info will lead to a valid configuration of @ref NEConvertFullyConnectedWeights |
| 52 | * |
Vidhya Sudhan Loganathan | f4cb81b | 2018-07-04 15:13:14 +0100 | [diff] [blame] | 53 | * @param[in] input Source weights tensor info to convert. Must be 2 dimensional. Data types supported: U8/S8/QASYMM8/U16/S16/U32/S32/F16/F32. |
Giorgio Arena | 657bdb3 | 2018-04-26 18:52:01 +0100 | [diff] [blame] | 54 | * @param[in] output The converted weights tensor info. Shape and Data Type: Same as @p input. |
Georgios Pinitas | 7d66a8e | 2018-07-17 12:28:42 +0100 | [diff] [blame] | 55 | * @param[in] original_input_shape Shape of the original input tensor (the one entering fully connected layer). |
Giorgio Arena | 657bdb3 | 2018-04-26 18:52:01 +0100 | [diff] [blame] | 56 | * @param[in] data_layout The data layout the weights have been trained in. |
Michalis Spyrou | 1a569a3 | 2019-09-10 17:20:34 +0100 | [diff] [blame] | 57 | * |
| 58 | * @return A Status |
Giorgio Arena | 657bdb3 | 2018-04-26 18:52:01 +0100 | [diff] [blame] | 59 | */ |
| 60 | static Status validate(const ITensorInfo *input, const ITensorInfo *output, const TensorShape &original_input_shape, DataLayout data_layout); |
| 61 | |
| 62 | // Inherited methods overriden: |
| 63 | void run() override; |
| 64 | |
| 65 | private: |
| 66 | NEConvertFullyConnectedWeightsKernel _kernel; |
| 67 | }; |
Michalis Spyrou | 1a569a3 | 2019-09-10 17:20:34 +0100 | [diff] [blame] | 68 | |
| 69 | namespace weights_transformations |
| 70 | { |
| 71 | /** Basic function to run @ref NEConvertFullyConnectedWeightsKernel. */ |
| 72 | class NEConvertFullyConnectedWeightsManaged : public ITransformWeights |
| 73 | { |
| 74 | public: |
| 75 | void run() override |
| 76 | { |
| 77 | _output.allocator()->allocate(); |
| 78 | _func.run(); |
| 79 | _reshape_run = true; |
| 80 | } |
| 81 | |
| 82 | void release() override |
| 83 | { |
| 84 | _output.allocator()->free(); |
| 85 | } |
| 86 | |
| 87 | ITensor *get_weights() override |
| 88 | { |
| 89 | return &_output; |
| 90 | } |
| 91 | |
| 92 | uint32_t uid() override |
| 93 | { |
| 94 | return _uid; |
| 95 | } |
| 96 | |
| 97 | void configure(const ITensor *input, const TensorShape &original_input_shape, DataLayout data_layout) |
| 98 | { |
| 99 | _func.configure(input, &_output, original_input_shape, data_layout); |
| 100 | } |
| 101 | |
| 102 | private: |
| 103 | static constexpr uint32_t _uid = 0x4; |
| 104 | Tensor _output{}; |
| 105 | NEConvertFullyConnectedWeights _func{}; |
| 106 | }; |
| 107 | } // namespace weights_transformations |
| 108 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 109 | #endif /* ARM_COMPUTE_NECONVERTFULLYCONNECTEDWEIGHTS_H */ |