Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 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 | #ifndef __ARM_COMPUTE_GRAPH_CONVOLUTION_LAYER_H__ |
| 25 | #define __ARM_COMPUTE_GRAPH_CONVOLUTION_LAYER_H__ |
| 26 | |
| 27 | #include "arm_compute/graph/INode.h" |
Georgios Pinitas | 6f669f0 | 2017-09-26 12:32:57 +0100 | [diff] [blame] | 28 | #include "arm_compute/graph/SubTensor.h" |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 29 | #include "arm_compute/graph/Tensor.h" |
| 30 | #include "arm_compute/graph/Types.h" |
Georgios Pinitas | 6f669f0 | 2017-09-26 12:32:57 +0100 | [diff] [blame] | 31 | #include "arm_compute/runtime/IFunction.h" |
| 32 | |
| 33 | #include <memory> |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 34 | |
| 35 | namespace arm_compute |
| 36 | { |
| 37 | namespace graph |
| 38 | { |
| 39 | /** Convolution layer node */ |
Georgios Pinitas | 6f669f0 | 2017-09-26 12:32:57 +0100 | [diff] [blame] | 40 | class ConvolutionLayer final : public INode |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 41 | { |
| 42 | public: |
| 43 | /** Default Constructor |
| 44 | * |
| 45 | * @param[in] conv_width Convolution width |
| 46 | * @param[in] conv_height Convolution height |
| 47 | * @param[in] ofm Output feature map |
| 48 | * @param[in] weights Weights of the convolution layer |
| 49 | * @param[in] biases Bias of the convolution layer |
| 50 | * @param[in] conv_info Convolution information |
Georgios Pinitas | 6f669f0 | 2017-09-26 12:32:57 +0100 | [diff] [blame] | 51 | * @param[in] num_groups (Optional) Number of groups, default = 1 |
| 52 | * @param[in] weights_info (Optional) Weights information |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 53 | */ |
| 54 | template <typename AccessorTypeWeights, typename AccessorTypeBiases> |
Georgios Pinitas | 6f669f0 | 2017-09-26 12:32:57 +0100 | [diff] [blame] | 55 | ConvolutionLayer(unsigned int conv_width, |
| 56 | unsigned int conv_height, |
| 57 | unsigned int ofm, |
| 58 | AccessorTypeWeights &&weights, |
| 59 | AccessorTypeBiases &&biases, |
| 60 | const PadStrideInfo conv_info, |
| 61 | unsigned int num_groups = 1, |
| 62 | const WeightsInfo weights_info = WeightsInfo()) |
| 63 | : _conv_width(conv_width), |
| 64 | _conv_height(conv_height), |
| 65 | _ofm(ofm), |
| 66 | _weights(std::move(weights)), |
| 67 | _biases(std::move(biases)), |
| 68 | _conv_info(std::move(conv_info)), |
| 69 | _num_groups(num_groups), |
| 70 | _weights_info(std::move(weights_info)), |
| 71 | _is(nullptr), |
| 72 | _os(nullptr), |
| 73 | _ws(nullptr), |
| 74 | _bs(nullptr) |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 75 | { |
| 76 | } |
| 77 | |
| 78 | // Inherited methods overriden: |
| 79 | std::unique_ptr<arm_compute::IFunction> instantiate_node(Hint hint, ITensor *input, ITensor *output) override; |
| 80 | void print_info() override; |
| 81 | |
| 82 | private: |
Georgios Pinitas | 6f669f0 | 2017-09-26 12:32:57 +0100 | [diff] [blame] | 83 | /** Instantiates a non-grouped convolution |
| 84 | * |
| 85 | * @param[in] conv_method_hint Hint that specifies which convolution layer method to use |
| 86 | * |
| 87 | * @return Convolution function |
| 88 | */ |
| 89 | std::unique_ptr<arm_compute::IFunction> instantiate_convolution(ConvolutionMethodHint conv_method_hint); |
| 90 | /** Instantiates a grouped convolution |
| 91 | * |
| 92 | * @param[in] conv_method_hint Hint that specifies which convolution layer method to use |
| 93 | * |
| 94 | * @return Grouped Convolution function |
| 95 | */ |
| 96 | std::unique_ptr<arm_compute::IFunction> instantiate_grouped_convolution(ConvolutionMethodHint conv_method_hint); |
| 97 | |
| 98 | private: |
| 99 | unsigned int _conv_width; /**< Convolution width */ |
| 100 | unsigned int _conv_height; /**< Convolution height */ |
| 101 | unsigned int _ofm; /**< Output feature maps */ |
| 102 | Tensor _weights; /**< Weights tensor */ |
| 103 | Tensor _biases; /**< Biases tensor */ |
| 104 | const PadStrideInfo _conv_info; /**< Convolution layer information */ |
| 105 | unsigned int _num_groups; /**< Number of groups */ |
| 106 | const WeightsInfo _weights_info; /**< Convolution layer weights information */ |
| 107 | |
| 108 | std::unique_ptr<SubTensor[]> _is; /**< Input tensor sub-tensors used for grouped convolution */ |
| 109 | std::unique_ptr<SubTensor[]> _os; /**< Output tensor sub-tensors used for grouped convolution */ |
| 110 | std::unique_ptr<SubTensor[]> _ws; /**< Weights tensor sub-tensors used for grouped convolution */ |
| 111 | std::unique_ptr<SubTensor[]> _bs; /**< Biases tensor sub-tensors used for grouped convolution */ |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 112 | }; |
| 113 | } // namespace graph |
| 114 | } // namespace arm_compute |
| 115 | #endif /* __ARM_COMPUTE_GRAPH_CONVOLUTION_LAYER_H__ */ |