diff options
Diffstat (limited to 'arm_compute/graph/nodes')
25 files changed, 773 insertions, 705 deletions
diff --git a/arm_compute/graph/nodes/DequantizationLayer.h b/arm_compute/graph/nodes/ActivationLayerNode.h index f9b7e8af87..985e10a8d8 100644 --- a/arm_compute/graph/nodes/DequantizationLayer.h +++ b/arm_compute/graph/nodes/ActivationLayerNode.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -21,39 +21,40 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#ifndef __ARM_COMPUTE_GRAPH_DEQUANTIZATION_LAYER_H__ -#define __ARM_COMPUTE_GRAPH_DEQUANTIZATION_LAYER_H__ +#ifndef __ARM_COMPUTE_GRAPH_ACTIVATION_LAYER_NODE_H__ +#define __ARM_COMPUTE_GRAPH_ACTIVATION_LAYER_NODE_H__ -#include "arm_compute/graph/GraphContext.h" #include "arm_compute/graph/INode.h" -#include "arm_compute/graph/ITensorObject.h" -#include "arm_compute/graph/Tensor.h" -#include "arm_compute/graph/Types.h" namespace arm_compute { namespace graph { -/** DequantizationLayer layer node */ -class DequantizationLayer final : public INode +/** Activation Layer node */ +class ActivationLayerNode final : public INode { public: - /** Default constructor + /** Constructor * - * @param[in] min_max Min max value tensor + * @param[in] info Activation Layer information */ - template <typename AccessorType> - DequantizationLayer(AccessorType &&min_max) - : _min_max(std::move(min_max)) - { - } + ActivationLayerNode(ActivationLayerInfo info); + /** Activation metadata accessor + * + * @return The activation info of the layer + */ + ActivationLayerInfo activation_info() const; - // Inherited methods overriden: - std::unique_ptr<arm_compute::IFunction> instantiate_node(GraphContext &ctx, ITensorObject *input, ITensorObject *output) override; + // Inherited overridden methods: + Status validate() override; + NodeType type() const override; + bool forward_descriptors() override; + TensorDescriptor configure_output(size_t idx) const override; + void accept(INodeVisitor &v) override; private: - Tensor _min_max; + ActivationLayerInfo _info; }; } // namespace graph } // namespace arm_compute -#endif /* __ARM_COMPUTE_GRAPH_DEQUANTIZATION_LAYER_H__ */ +#endif /* __ARM_COMPUTE_GRAPH_ACTIVATION_LAYER_NODE_H__ */ diff --git a/arm_compute/graph/nodes/BatchNormalizationLayer.h b/arm_compute/graph/nodes/BatchNormalizationLayer.h deleted file mode 100644 index abbf09a54e..0000000000 --- a/arm_compute/graph/nodes/BatchNormalizationLayer.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2017-2018 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef __ARM_COMPUTE_GRAPH_BATCHNORMALIZATION_LAYER_H__ -#define __ARM_COMPUTE_GRAPH_BATCHNORMALIZATION_LAYER_H__ - -#include "arm_compute/graph/GraphContext.h" -#include "arm_compute/graph/INode.h" -#include "arm_compute/graph/ITensorObject.h" -#include "arm_compute/graph/Tensor.h" -#include "arm_compute/graph/Types.h" - -namespace arm_compute -{ -namespace graph -{ -/** BatchNormalization layer node */ -class BatchNormalizationLayer final : public INode -{ -public: - /** Default constructor - * - * @param[in] mean Mean values tensor - * @param[in] var Var values tensor - * @param[in] gamma Gamma values tensor - * @param[in] beta Beta values tensor - * @param[in] epsilon Epsilon value - * @param[in] act_info (Optional) Activation layer information in case of a fused activation. Only RELU, BOUNDED_RELU and LU_BOUNDED_RELU supported. - */ - template <typename AccessorType> - BatchNormalizationLayer(AccessorType &&mean, AccessorType &&var, AccessorType &&gamma, AccessorType &&beta, float epsilon, ActivationLayerInfo act_info = ActivationLayerInfo()) - : _mean(std::move(mean)), _var(std::move(var)), _gamma(std::move(gamma)), _beta(std::move(beta)), _epsilon(epsilon), _act_info(act_info) - { - set_supports_in_place(true); - } - - // Inherited methods overriden: - std::unique_ptr<arm_compute::IFunction> instantiate_node(GraphContext &ctx, ITensorObject *input, ITensorObject *output) override; - -private: - Tensor _mean; - Tensor _var; - Tensor _gamma; - Tensor _beta; - float _epsilon; - ActivationLayerInfo _act_info; -}; -} // namespace graph -} // namespace arm_compute -#endif /* __ARM_COMPUTE_GRAPH_BATCHNORMALIZATION_LAYER_H__ */ diff --git a/arm_compute/graph/nodes/BatchNormalizationLayerNode.h b/arm_compute/graph/nodes/BatchNormalizationLayerNode.h new file mode 100644 index 0000000000..b36d66993b --- /dev/null +++ b/arm_compute/graph/nodes/BatchNormalizationLayerNode.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2018 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef __ARM_COMPUTE_GRAPH_BATCH_NORMALIZATION_LAYER_NODE_H__ +#define __ARM_COMPUTE_GRAPH_BATCH_NORMALIZATION_LAYER_NODE_H__ + +#include "arm_compute/graph/INode.h" + +namespace arm_compute +{ +namespace graph +{ +/** Batch Normalization Layer node */ +class BatchNormalizationLayerNode final : public INode +{ +public: + /** Constructor + * + * @param[in] epsilon (Optional) Epsilon parameter. Defaults to 1.f + * @param[in] fused_activation (Optional) Fused activation layer. Disabled if not specified + */ + BatchNormalizationLayerNode(float epsilon = 1.f, ActivationLayerInfo fused_activation = ActivationLayerInfo()); + /** Epsilon parameter accessor + * + * @return Epsilon parameter + */ + float epsilon() const; + /** Returns fused activation + * + * @return Fused activation + */ + ActivationLayerInfo fused_activation() const; + /** Sets fused activation + * + * @param[in] fused_activation Fused activation to set + */ + void set_fused_activation(ActivationLayerInfo fused_activation); + + // Inherited overridden methods: + Status validate() override; + NodeType type() const override; + bool forward_descriptors() override; + TensorDescriptor configure_output(size_t idx) const override; + void accept(INodeVisitor &v) override; + +private: + float _epsilon; + ActivationLayerInfo _fused_activation; +}; +} // namespace graph +} // namespace arm_compute +#endif /* __ARM_COMPUTE_GRAPH_BATCH_NORMALIZATION_LAYER_NODE_H__ */ diff --git a/arm_compute/graph/nodes/BranchLayer.h b/arm_compute/graph/nodes/BranchLayer.h deleted file mode 100644 index cbc016d043..0000000000 --- a/arm_compute/graph/nodes/BranchLayer.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2017-2018 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef __ARM_COMPUTE_GRAPH_BRANCH_LAYER_H__ -#define __ARM_COMPUTE_GRAPH_BRANCH_LAYER_H__ - -#include "arm_compute/graph/GraphContext.h" -#include "arm_compute/graph/INode.h" -#include "arm_compute/graph/ITensorObject.h" -#include "arm_compute/graph/SubGraph.h" -#include "arm_compute/graph/SubTensor.h" -#include "arm_compute/graph/Types.h" - -#include "arm_compute/core/utils/misc/Utility.h" - -#include <vector> - -namespace arm_compute -{ -namespace graph -{ -/** Branch Layer node */ -class BranchLayer final : public INode -{ -public: - /** Default Constructor - * - * @param[in] merge_method Branch merging method - * @param[in] sub_graph1 First graph branch - * @param[in] sub_graph2 Second graph branch - * @param[in] rest_sub_graphs Rest sub-graph branches - */ - template <typename... Ts> - BranchLayer(BranchMergeMethod merge_method, SubGraph &&sub_graph1, SubGraph &&sub_graph2, Ts &&... rest_sub_graphs) - : _branch_merge_method(merge_method), _sub_graphs() - { - /* TODO:(geopin01) Use traits to make sure variadic arguments are of SubGraph type */ - _sub_graphs.push_back(arm_compute::support::cpp14::make_unique<SubGraph>(std::move(sub_graph1))); - _sub_graphs.push_back(arm_compute::support::cpp14::make_unique<SubGraph>(std::move(sub_graph2))); - - utility::for_each([&](SubGraph && sub_graph) - { - _sub_graphs.push_back(arm_compute::support::cpp14::make_unique<SubGraph>(std::move(sub_graph))); - }, - std::move(rest_sub_graphs)...); - } - /** Default Constructor - * - * @param[in] sub_graph Sub graph - */ - template <typename... Ts> - BranchLayer(SubGraph &&sub_graph) - : _branch_merge_method(BranchMergeMethod::DEPTH_CONCATENATE), _sub_graphs() - { - /* TODO:(geopin01) Use traits to make sure variadic arguments are of SubGraph type */ - _sub_graphs.push_back(arm_compute::support::cpp14::make_unique<SubGraph>(std::move(sub_graph))); - } - - // Inherited methods overriden: - std::unique_ptr<arm_compute::IFunction> instantiate_node(GraphContext &ctx, ITensorObject *input, ITensorObject *output) override; - -private: - BranchMergeMethod _branch_merge_method; - std::vector<std::unique_ptr<SubGraph>> _sub_graphs; -}; -} // namespace graph -} // namespace arm_compute -#endif /* __ARM_COMPUTE_GRAPH_BRANCH_LAYER_H__ */ diff --git a/arm_compute/graph/nodes/FloorLayer.h b/arm_compute/graph/nodes/ConstNode.h index 146e2c16dd..346a3c82e7 100644 --- a/arm_compute/graph/nodes/FloorLayer.h +++ b/arm_compute/graph/nodes/ConstNode.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -21,25 +21,35 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#ifndef __ARM_COMPUTE_GRAPH_FLOOR_LAYER_H__ -#define __ARM_COMPUTE_GRAPH_FLOOR_LAYER_H__ +#ifndef __ARM_COMPUTE_GRAPH_CONST_NODE_H__ +#define __ARM_COMPUTE_GRAPH_CONST_NODE_H__ -#include "arm_compute/graph/GraphContext.h" #include "arm_compute/graph/INode.h" -#include "arm_compute/graph/ITensorObject.h" -#include "arm_compute/graph/Types.h" + namespace arm_compute { namespace graph { -/** Floor layer node */ -class FloorLayer final : public INode +/** Const node */ +class ConstNode final : public INode { public: - // Inherited methods overriden: - std::unique_ptr<arm_compute::IFunction> instantiate_node(GraphContext &ctx, ITensorObject *input, ITensorObject *output) override; -}; + /** Constructor + * + * @param[in] desc Tensor descriptor + */ + ConstNode(TensorDescriptor desc); + // Inherited overridden methods: + Status validate() override; + NodeType type() const override; + bool forward_descriptors() override; + TensorDescriptor configure_output(size_t idx) const override; + void accept(INodeVisitor &v) override; + +private: + TensorDescriptor _desc; +}; } // namespace graph } // namespace arm_compute -#endif /* __ARM_COMPUTE_GRAPH_FLOOR_LAYER_H__ */ +#endif /* __ARM_COMPUTE_GRAPH_CONST_NODE_H__ */ diff --git a/arm_compute/graph/nodes/ConvolutionLayer.h b/arm_compute/graph/nodes/ConvolutionLayer.h deleted file mode 100644 index 1806190971..0000000000 --- a/arm_compute/graph/nodes/ConvolutionLayer.h +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (c) 2017-2018 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef __ARM_COMPUTE_GRAPH_CONVOLUTION_LAYER_H__ -#define __ARM_COMPUTE_GRAPH_CONVOLUTION_LAYER_H__ - -#include "arm_compute/graph/GraphContext.h" -#include "arm_compute/graph/INode.h" -#include "arm_compute/graph/ITensorObject.h" -#include "arm_compute/graph/SubTensor.h" -#include "arm_compute/graph/Tensor.h" -#include "arm_compute/graph/Types.h" -#include "arm_compute/runtime/IFunction.h" - -#include <memory> - -namespace arm_compute -{ -namespace graph -{ -/** Convolution layer node */ -class ConvolutionLayer final : public INode -{ -public: - /** Default Constructor - * - * @param[in] conv_width Convolution width - * @param[in] conv_height Convolution height - * @param[in] ofm Output feature map - * @param[in] weights Weights of the convolution layer - * @param[in] biases Bias of the convolution layer - * @param[in] conv_info Convolution information - * @param[in] num_groups (Optional) Number of groups, default = 1 - * @param[in] weights_info (Optional) Weights information - * @param[in] weights_quant_info (Optional) Weights quantization information - * @param[in] out_quant_info (Optional) Output quantization info - */ - template <typename AccessorTypeWeights, typename AccessorTypeBiases> - ConvolutionLayer(unsigned int conv_width, - unsigned int conv_height, - unsigned int ofm, - AccessorTypeWeights &&weights, - AccessorTypeBiases &&biases, - const PadStrideInfo conv_info, - unsigned int num_groups = 1, - const WeightsInfo weights_info = WeightsInfo(), - const QuantizationInfo weights_quant_info = QuantizationInfo(), - const QuantizationInfo out_quant_info = QuantizationInfo()) - : _conv_width(conv_width), - _conv_height(conv_height), - _ofm(ofm), - _weights(std::move(weights)), - _biases(std::move(biases)), - _conv_info(std::move(conv_info)), - _num_groups(num_groups), - _weights_info(std::move(weights_info)), - _weights_quant_info(std::move(weights_quant_info)), - _out_quant_info(std::move(out_quant_info)), - _is(nullptr), - _os(nullptr), - _ws(nullptr), - _bs(nullptr) - { - } - - // Inherited methods overriden: - std::unique_ptr<arm_compute::IFunction> instantiate_node(GraphContext &ctx, ITensorObject *input, ITensorObject *output) override; - -private: - /** Instantiates a non-grouped convolution - * - * @param[in] input Input tensor - * @param[in] output Output tensor - * @param[in] conv_method_hint Hint that specifies which convolution layer method to use - * - * @return Convolution function - */ - std::unique_ptr<arm_compute::IFunction> instantiate_convolution(ITensor *input, ITensor *output, ConvolutionMethodHint conv_method_hint); - /** Instantiates a grouped convolution - * - * @param[in] input Input tensor - * @param[in] output Output tensor - * @param[in] conv_method_hint Hint that specifies which convolution layer method to use - * - * @return Grouped Convolution function - */ - std::unique_ptr<arm_compute::IFunction> instantiate_grouped_convolution(ITensor *input, ITensor *output, ConvolutionMethodHint conv_method_hint); - -private: - unsigned int _conv_width; /**< Convolution width */ - unsigned int _conv_height; /**< Convolution height */ - unsigned int _ofm; /**< Output feature maps */ - Tensor _weights; /**< Weights tensor */ - Tensor _biases; /**< Biases tensor */ - const PadStrideInfo _conv_info; /**< Convolution layer information */ - unsigned int _num_groups; /**< Number of groups */ - const WeightsInfo _weights_info; /**< Convolution layer weights information */ - const QuantizationInfo _weights_quant_info; /**< Output quantization information */ - const QuantizationInfo _out_quant_info; /**< Output quantization information */ - - std::unique_ptr<SubTensor[]> _is; /**< Input tensor sub-tensors used for grouped convolution */ - std::unique_ptr<SubTensor[]> _os; /**< Output tensor sub-tensors used for grouped convolution */ - std::unique_ptr<SubTensor[]> _ws; /**< Weights tensor sub-tensors used for grouped convolution */ - std::unique_ptr<SubTensor[]> _bs; /**< Biases tensor sub-tensors used for grouped convolution */ -}; -} // namespace graph -} // namespace arm_compute -#endif /* __ARM_COMPUTE_GRAPH_CONVOLUTION_LAYER_H__ */ diff --git a/arm_compute/graph/nodes/ConvolutionLayerNode.h b/arm_compute/graph/nodes/ConvolutionLayerNode.h new file mode 100644 index 0000000000..70fefbeeab --- /dev/null +++ b/arm_compute/graph/nodes/ConvolutionLayerNode.h @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2018 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef __ARM_COMPUTE_GRAPH_CONVOLUTION_LAYER_NODE_H__ +#define __ARM_COMPUTE_GRAPH_CONVOLUTION_LAYER_NODE_H__ + +#include "arm_compute/graph/INode.h" + +namespace arm_compute +{ +namespace graph +{ +/** Convolution Layer node */ +class ConvolutionLayerNode final : public INode +{ +public: + /** Constructor + * + * @param[in] info Convolution layer attributes + * @param[in] method (Optional) Convolution method to use + */ + ConvolutionLayerNode(PadStrideInfo info, ConvolutionMethod method = ConvolutionMethod::DEFAULT); + /** Sets the convolution layer method to use + * + * @param[in] method Method to use for convolution + */ + void set_convolution_method(ConvolutionMethod method); + /** Convolution layer method accessor + * + * @note This is an indication on which convolution layer implementation to use, + * if it fails to be created the library's heuristic approach will be used + * + * @return Convolution layer method do be used by the node + */ + ConvolutionMethod convolution_method() const; + /** Convolution metadata accessor + * + * @return Convolution information + */ + PadStrideInfo convolution_info() const; + /** Computes convolution output shape + * + * @param[in] input_shape Input shape + * @param[in] weights_shape Weights shape + * @param[in] info Convolution operation attributes + * + * @return Output shape + */ + static TensorShape compute_output_shape(TensorShape input_shape, TensorShape weights_shape, PadStrideInfo info); + + // Inherited overridden methods: + Status validate() override; + NodeType type() const override; + bool forward_descriptors() override; + TensorDescriptor configure_output(size_t idx) const override; + void accept(INodeVisitor &v) override; + +private: + PadStrideInfo _info; + ConvolutionMethod _method; +}; +} // namespace graph +} // namespace arm_compute +#endif /* __ARM_COMPUTE_GRAPH_CONVOLUTION_LAYER_NODE_H__ */ diff --git a/arm_compute/graph/nodes/DepthConcatenateLayerNode.h b/arm_compute/graph/nodes/DepthConcatenateLayerNode.h new file mode 100644 index 0000000000..cb309f38c1 --- /dev/null +++ b/arm_compute/graph/nodes/DepthConcatenateLayerNode.h @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2018 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef __ARM_COMPUTE_GRAPH_DEPTH_CONCATENATE_LAYER_NODE_H__ +#define __ARM_COMPUTE_GRAPH_DEPTH_CONCATENATE_LAYER_NODE_H__ + +#include "arm_compute/graph/INode.h" + +namespace arm_compute +{ +namespace graph +{ +/** Depth Concatenation Layer node */ +class DepthConcatenateLayerNode final : public INode +{ +public: + /** Constructor + * + * @param[in] total_nodes Number of nodes that will get concatenated + */ + DepthConcatenateLayerNode(unsigned int total_nodes); + /** Computes depth concatenations output shape + * + * @param input_shapes Shapes of the inputs + * + * @return Expected output shape + */ + static TensorShape compute_output_shape(const std::vector<TensorShape> &input_shapes); + /** Disables or not the depth concatenate node + * + * @warning This is used when depth concatenate is performed with sub-tensors, + * where this node is used as a placeholder. + * + * @param[in] is_enabled If true a backend function is created to perform the depth concatenation (involves copying), + * while if false, no function is created and we assume that subtensors are properly set to simulate + * a no copy operation. + */ + void set_enabled(bool is_enabled); + /** Enabled parameter accessor + * + * @return True if a backend function is to be created else false + */ + bool is_enabled() const; + + // Inherited overridden methods: + Status validate() override; + NodeType type() const override; + bool forward_descriptors() override; + TensorDescriptor configure_output(size_t idx) const override; + void accept(INodeVisitor &v) override; + +private: + unsigned int _total_nodes; + bool _is_enabled; +}; +} // namespace graph +} // namespace arm_compute +#endif /* __ARM_COMPUTE_GRAPH_DEPTH_CONCATENATE_LAYER_NODE_H__ */ diff --git a/arm_compute/graph/nodes/DepthwiseConvolutionLayer.h b/arm_compute/graph/nodes/DepthwiseConvolutionLayer.h deleted file mode 100644 index 2d4bd1e0c2..0000000000 --- a/arm_compute/graph/nodes/DepthwiseConvolutionLayer.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2017-2018 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef __ARM_COMPUTE_GRAPH_DEPTHWISE_CONVOLUTION_LAYER_H__ -#define __ARM_COMPUTE_GRAPH_DEPTHWISE_CONVOLUTION_LAYER_H__ - -#include "arm_compute/graph/GraphContext.h" -#include "arm_compute/graph/INode.h" -#include "arm_compute/graph/ITensorObject.h" -#include "arm_compute/graph/SubTensor.h" -#include "arm_compute/graph/Tensor.h" -#include "arm_compute/graph/Types.h" -#include "arm_compute/runtime/IFunction.h" - -#include <memory> - -namespace arm_compute -{ -namespace graph -{ -/** Convolution layer node */ -class DepthwiseConvolutionLayer final : public INode -{ -public: - /** Default constructor - * - * @param[in] conv_width Convolution width - * @param[in] conv_height Convolution height - * @param[in] weights Weights values tensor - * @param[in] biases Biases values tensor - * @param[in] conv_info Convolution info - * @param[in] opt3x3 (Optional) If true executes DepthwiseConvolutionLayer3x3 - * @param[in] quant_info (Optional) Quantization info used for weights - */ - template <typename AccessorType> - DepthwiseConvolutionLayer(unsigned int conv_width, unsigned int conv_height, AccessorType &&weights, AccessorType &&biases, const PadStrideInfo conv_info, bool opt3x3 = true, - const QuantizationInfo quant_info = QuantizationInfo()) - : _conv_width(conv_width), _conv_height(conv_height), _weights(std::move(weights)), _biases(std::move(biases)), _conv_info(conv_info), _opt3x3(opt3x3), _quant_info(std::move(quant_info)) - { - } - - // Inherited methods overriden: - std::unique_ptr<arm_compute::IFunction> instantiate_node(GraphContext &ctx, ITensorObject *input, ITensorObject *output) override; - -private: - unsigned int _conv_width; - unsigned int _conv_height; - Tensor _weights; - Tensor _biases; - const PadStrideInfo _conv_info; - bool _opt3x3; - const QuantizationInfo _quant_info; -}; -} // namespace graph -} // namespace arm_compute -#endif /* __ARM_COMPUTE_GRAPH_DEPTHWISE_CONVOLUTION_LAYER_H__ */ diff --git a/arm_compute/graph/nodes/DepthwiseConvolutionLayerNode.h b/arm_compute/graph/nodes/DepthwiseConvolutionLayerNode.h new file mode 100644 index 0000000000..b4cf9b4d03 --- /dev/null +++ b/arm_compute/graph/nodes/DepthwiseConvolutionLayerNode.h @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2018 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef __ARM_COMPUTE_GRAPH_DEPTHWISE_CONVOLUTION_LAYER_NODE_H__ +#define __ARM_COMPUTE_GRAPH_DEPTHWISE_CONVOLUTION_LAYER_NODE_H__ + +#include "arm_compute/graph/INode.h" + +namespace arm_compute +{ +namespace graph +{ +/** Depthwise Convolution Layer node */ +class DepthwiseConvolutionLayerNode final : public INode +{ +public: + /** Constructor + * + * @param[in] info Convolution layer attributes + * @param[in] method Depthwise convolution method to use + */ + DepthwiseConvolutionLayerNode(PadStrideInfo info, DepthwiseConvolutionMethod method = DepthwiseConvolutionMethod::DEFAULT); + /** Sets the depthwise convolution method to use + * + * @param[in] method Depthwise convolution method to use + */ + void set_depthwise_convolution_method(DepthwiseConvolutionMethod method); + /** Depthwise convolution layer method accessor + * + * @note This is an indication on which depthwise implementation to use, + * if it fails to be created the generic approach will be used + * + * @return Depthwise convolution layer method do be used by the node + */ + DepthwiseConvolutionMethod depthwise_convolution_method() const; + /** Convolution metadata accessor + * + * @return Convolution information + */ + PadStrideInfo convolution_info() const; + /** Computes depthwise convolution output shape + * + * @param[in] input_shape Input shape + * @param[in] weights_shape Weights shape + * @param[in] info Convolution operation attributes + * + * @return Output shape + */ + static TensorShape compute_output_shape(TensorShape input_shape, TensorShape weights_shape, PadStrideInfo info); + + // Inherited overridden methods: + Status validate() override; + NodeType type() const override; + bool forward_descriptors() override; + TensorDescriptor configure_output(size_t idx) const override; + void accept(INodeVisitor &v) override; + +private: + PadStrideInfo _info; + DepthwiseConvolutionMethod _method; +}; +} // namespace graph +} // namespace arm_compute +#endif /* __ARM_COMPUTE_GRAPH_DEPTHWISE_CONVOLUTION_LAYER_NODE_H__ */ diff --git a/arm_compute/graph/nodes/L2NormalizeLayer.h b/arm_compute/graph/nodes/EltwiseLayerNode.h index a423306bd2..9da88d75b5 100644 --- a/arm_compute/graph/nodes/L2NormalizeLayer.h +++ b/arm_compute/graph/nodes/EltwiseLayerNode.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -21,36 +21,40 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#ifndef __ARM_COMPUTE_GRAPH_L2NORMALIZE_LAYER_H__ -#define __ARM_COMPUTE_GRAPH_L2NORMALIZE_LAYER_H__ +#ifndef __ARM_COMPUTE_GRAPH_ELTWISE_LAYER_NODE_H__ +#define __ARM_COMPUTE_GRAPH_ELTWISE_LAYER_NODE_H__ -#include "arm_compute/graph/GraphContext.h" #include "arm_compute/graph/INode.h" -#include "arm_compute/graph/ITensorObject.h" -#include "arm_compute/graph/Types.h" namespace arm_compute { namespace graph { -/** L2NormalizeLayer layer node */ -class L2NormalizeLayer final : public INode +/** Eltwise Layer node */ +class EltwiseLayerNode final : public INode { public: - /** Default Constructor + /** Constructor * - * @param[in] axis Dimension along which to reduce. - * @param[in] epsilon Lower bound value for the normalization. + * @param[in] op Element-wise operation to perform */ - explicit L2NormalizeLayer(unsigned int axis, float epsilon); + EltwiseLayerNode(EltwiseOperation op); + /** Eltwise operation accessor + * + * @return Eltwise operation that is to be performed by the node + */ + EltwiseOperation eltwise_operation() const; - // Inherited methods overriden: - std::unique_ptr<arm_compute::IFunction> instantiate_node(GraphContext &ctx, ITensorObject *input, ITensorObject *output) override; + // Inherited overridden methods: + Status validate() override; + NodeType type() const override; + bool forward_descriptors() override; + TensorDescriptor configure_output(size_t idx) const override; + void accept(INodeVisitor &v) override; private: - unsigned int _axis; - float _epsilon; + EltwiseOperation _op; }; } // namespace graph } // namespace arm_compute -#endif /* __ARM_COMPUTE_GRAPH_L2NORMALIZE_LAYER_H__ */ +#endif /* __ARM_COMPUTE_GRAPH_ELTWISE_LAYER_NODE_H__ */ diff --git a/arm_compute/graph/nodes/FlattenLayer.h b/arm_compute/graph/nodes/FlattenLayerNode.h index c5f51a2b3e..f0dde1fab1 100644 --- a/arm_compute/graph/nodes/FlattenLayer.h +++ b/arm_compute/graph/nodes/FlattenLayerNode.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -21,25 +21,29 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#ifndef __ARM_COMPUTE_GRAPH_FLATTEN_LAYER_H__ -#define __ARM_COMPUTE_GRAPH_FLATTEN_LAYER_H__ +#ifndef __ARM_COMPUTE_GRAPH_FLATTEN_LAYER_NODE_H__ +#define __ARM_COMPUTE_GRAPH_FLATTEN_LAYER_NODE_H__ -#include "arm_compute/graph/GraphContext.h" #include "arm_compute/graph/INode.h" -#include "arm_compute/graph/ITensorObject.h" -#include "arm_compute/graph/Types.h" namespace arm_compute { namespace graph { -/** Flatten layer node */ -class FlattenLayer final : public INode +/** Flatten Layer node */ +class FlattenLayerNode final : public INode { public: - // Inherited methods overriden: - std::unique_ptr<arm_compute::IFunction> instantiate_node(GraphContext &ctx, ITensorObject *input, ITensorObject *output) override; + /** Default Constructor */ + FlattenLayerNode(); + + // Inherited overridden methods: + Status validate() override; + NodeType type() const override; + bool forward_descriptors() override; + TensorDescriptor configure_output(size_t idx) const override; + void accept(INodeVisitor &v) override; }; } // namespace graph } // namespace arm_compute -#endif /* __ARM_COMPUTE_GRAPH_FLATTEN_LAYER_H__ */ +#endif /* __ARM_COMPUTE_GRAPH_FLATTEN_LAYER_NODE_H__ */ diff --git a/arm_compute/graph/nodes/FullyConnectedLayer.h b/arm_compute/graph/nodes/FullyConnectedLayer.h deleted file mode 100644 index 270676a6b5..0000000000 --- a/arm_compute/graph/nodes/FullyConnectedLayer.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2017 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef __ARM_COMPUTE_GRAPH_FULLY_CONNECTED_LAYER_H__ -#define __ARM_COMPUTE_GRAPH_FULLY_CONNECTED_LAYER_H__ - -#include "arm_compute/graph/GraphContext.h" -#include "arm_compute/graph/INode.h" -#include "arm_compute/graph/ITensorObject.h" -#include "arm_compute/graph/Tensor.h" -#include "arm_compute/graph/Types.h" - -namespace arm_compute -{ -namespace graph -{ -/** Fully connected layer node */ -class FullyConnectedLayer final : public INode -{ -public: - /** Default constructor - * - * @param[in] num_neurons Number of neurons - * @param[in] weights Weights of the fully connected layer - * @param[in] biases Biases of the fully connected layer - */ - template <typename AccessorTypeWeights, typename AccessorTypeBiases> - FullyConnectedLayer(unsigned int num_neurons, AccessorTypeWeights &&weights, AccessorTypeBiases &&biases) - : _num_neurons(num_neurons), _weights(std::move(weights)), _biases(std::move(biases)) - { - } - - // Inherited methods overriden: - std::unique_ptr<arm_compute::IFunction> instantiate_node(GraphContext &ctx, ITensorObject *input, ITensorObject *output) override; - - // Inherited methods overriden: -private: - unsigned int _num_neurons; /**< Number of neurons */ - Tensor _weights; /**< Weights tensor */ - Tensor _biases; /**< Biases tensor */ -}; -} // namespace graph -} // namespace arm_compute -#endif /* __ARM_COMPUTE_GRAPH_FULLY_CONNECTED_LAYER_H__ */ diff --git a/arm_compute/graph/nodes/FullyConnectedLayerNode.h b/arm_compute/graph/nodes/FullyConnectedLayerNode.h new file mode 100644 index 0000000000..166751b8fa --- /dev/null +++ b/arm_compute/graph/nodes/FullyConnectedLayerNode.h @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2018 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef __ARM_COMPUTE_GRAPH_FULLY_CONNECTED_LAYER_NODE_H__ +#define __ARM_COMPUTE_GRAPH_FULLY_CONNECTED_LAYER_NODE_H__ + +#include "arm_compute/graph/INode.h" + +namespace arm_compute +{ +namespace graph +{ +/** Fully Connected Layer node */ +class FullyConnectedLayerNode final : public INode +{ +public: + /** Constructor + * + * @param[in] num_outputs Number of neurons in the layer + */ + FullyConnectedLayerNode(unsigned int num_outputs); + /** Computes weights shape + * + * @warning Works for inputs with 1D batch space + * + * @param[in] input_shape Input shape + * @param[in] num_outputs Number of output neurons + * + * @return Weights shape + */ + static TensorShape compute_weights_shape(TensorShape input_shape, unsigned int num_outputs); + /** Computes fully connected layer output shape + * + * @warning Works for inputs with 1D batch space + * + * @param[in] input_shape Input shape + * @param[in] num_outputs Number of output neurons + * + * @return Output shape + */ + static TensorShape compute_output_shape(TensorShape input_shape, unsigned int num_outputs); + + // Inherited overridden methods: + Status validate() override; + NodeType type() const override; + bool forward_descriptors() override; + TensorDescriptor configure_output(size_t idx) const override; + void accept(INodeVisitor &v) override; + +private: + unsigned int _num_outputs; +}; +} // namespace graph +} // namespace arm_compute +#endif /* __ARM_COMPUTE_GRAPH_FULLY_CONNECTED_LAYER_NODE_H__ */ diff --git a/arm_compute/graph/nodes/InputNode.h b/arm_compute/graph/nodes/InputNode.h new file mode 100644 index 0000000000..cacea95ab8 --- /dev/null +++ b/arm_compute/graph/nodes/InputNode.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2018 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef __ARM_COMPUTE_GRAPH_INPUT_NODE_H__ +#define __ARM_COMPUTE_GRAPH_INPUT_NODE_H__ + +#include "arm_compute/graph/INode.h" + +namespace arm_compute +{ +namespace graph +{ +/** Input Layer node */ +class InputNode final : public INode +{ +public: + /** Constructor + * + * @param[in] desc Tensor descriptor + */ + InputNode(TensorDescriptor desc); + + // Inherited overridden methods: + Status validate() override; + NodeType type() const override; + bool forward_descriptors() override; + TensorDescriptor configure_output(size_t idx) const override; + void accept(INodeVisitor &v) override; + +private: + TensorDescriptor _desc; +}; +} // namespace graph +} // namespace arm_compute +#endif /* __ARM_COMPUTE_GRAPH_INPUT_NODE_H__ */ diff --git a/arm_compute/graph/nodes/Nodes.h b/arm_compute/graph/nodes/Nodes.h new file mode 100644 index 0000000000..c39546c6bd --- /dev/null +++ b/arm_compute/graph/nodes/Nodes.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2018 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef __ARM_COMPUTE_GRAPH_NODES_H__ +#define __ARM_COMPUTE_GRAPH_NODES_H__ + +#include "arm_compute/graph/nodes/ActivationLayerNode.h" +#include "arm_compute/graph/nodes/BatchNormalizationLayerNode.h" +#include "arm_compute/graph/nodes/ConstNode.h" +#include "arm_compute/graph/nodes/ConvolutionLayerNode.h" +#include "arm_compute/graph/nodes/DepthConcatenateLayerNode.h" +#include "arm_compute/graph/nodes/DepthwiseConvolutionLayerNode.h" +#include "arm_compute/graph/nodes/EltwiseLayerNode.h" +#include "arm_compute/graph/nodes/FlattenLayerNode.h" +#include "arm_compute/graph/nodes/FullyConnectedLayerNode.h" +#include "arm_compute/graph/nodes/InputNode.h" +#include "arm_compute/graph/nodes/NormalizationLayerNode.h" +#include "arm_compute/graph/nodes/OutputNode.h" +#include "arm_compute/graph/nodes/PoolingLayerNode.h" +#include "arm_compute/graph/nodes/ReshapeLayerNode.h" +#include "arm_compute/graph/nodes/SoftmaxLayerNode.h" +#include "arm_compute/graph/nodes/SplitLayerNode.h" + +#endif /* __ARM_COMPUTE_GRAPH_NODES_H__ */ diff --git a/arm_compute/graph/nodes/SoftmaxLayer.h b/arm_compute/graph/nodes/NodesFwd.h index b5d1bc53fd..b90cb5c308 100644 --- a/arm_compute/graph/nodes/SoftmaxLayer.h +++ b/arm_compute/graph/nodes/NodesFwd.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -21,24 +21,31 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#ifndef __ARM_COMPUTE_GRAPH_SOFTMAX_LAYER_H__ -#define __ARM_COMPUTE_GRAPH_SOFTMAX_LAYER_H__ +#ifndef __ARM_COMPUTE_GRAPH_NODES_FWD_H__ +#define __ARM_COMPUTE_GRAPH_NODES_FWD_H__ -#include "arm_compute/graph/GraphContext.h" -#include "arm_compute/graph/INode.h" -#include "arm_compute/graph/ITensorObject.h" -#include "arm_compute/graph/Types.h" namespace arm_compute { namespace graph { -/** Softmax layer node */ -class SoftmaxLayer final : public INode -{ -public: - // Inherited methods overriden: - std::unique_ptr<arm_compute::IFunction> instantiate_node(GraphContext &ctx, ITensorObject *input, ITensorObject *output) override; -}; +// Forward declarations +class INode; +class ActivationLayerNode; +class BatchNormalizationLayerNode; +class ConstNode; +class ConvolutionLayerNode; +class DepthConcatenateLayerNode; +class DepthwiseConvolutionLayerNode; +class EltwiseLayerNode; +class FlattenLayerNode; +class FullyConnectedLayerNode; +class InputNode; +class NormalizationLayerNode; +class OutputNode; +class PoolingLayerNode; +class ReshapeLayerNode; +class SoftmaxLayerNode; +class SplitLayerNode; } // namespace graph } // namespace arm_compute -#endif /* __ARM_COMPUTE_GRAPH_SOFTMAX_LAYER_H__ */ +#endif /* __ARM_COMPUTE_GRAPH_NODES_FWD_H__ */ diff --git a/arm_compute/graph/nodes/NormalizationLayer.h b/arm_compute/graph/nodes/NormalizationLayerNode.h index e1c45094d8..34dc3ccf8f 100644 --- a/arm_compute/graph/nodes/NormalizationLayer.h +++ b/arm_compute/graph/nodes/NormalizationLayerNode.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -21,34 +21,40 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#ifndef __ARM_COMPUTE_GRAPH_NORMALIZATION_LAYER_H__ -#define __ARM_COMPUTE_GRAPH_NORMALIZATION_LAYER_H__ +#ifndef __ARM_COMPUTE_GRAPH_NORMALIZATION_LAYER_NODE_H__ +#define __ARM_COMPUTE_GRAPH_NORMALIZATION_LAYER_NODE_H__ -#include "arm_compute/graph/GraphContext.h" #include "arm_compute/graph/INode.h" -#include "arm_compute/graph/ITensorObject.h" -#include "arm_compute/graph/Types.h" namespace arm_compute { namespace graph { -/** Normalization layer node */ -class NormalizationLayer final : public INode +/** Normalization Layer node */ +class NormalizationLayerNode final : public INode { public: - /** Default Constructor + /** Constructor * - * @param[in] norm_info Normalization layer information + * @param[in] norm_info Normalization Layer information */ - explicit NormalizationLayer(const NormalizationLayerInfo norm_info); + NormalizationLayerNode(NormalizationLayerInfo norm_info); + /** Normalization info accessor + * + * @return Normalization layer info + */ + NormalizationLayerInfo normalization_info() const; - // Inherited methods overriden: - std::unique_ptr<arm_compute::IFunction> instantiate_node(GraphContext &ctx, ITensorObject *input, ITensorObject *output) override; + // Inherited overridden methods: + Status validate() override; + NodeType type() const override; + bool forward_descriptors() override; + TensorDescriptor configure_output(size_t idx) const override; + void accept(INodeVisitor &v) override; private: - const NormalizationLayerInfo _norm_info; /**< Normalization layer information */ + NormalizationLayerInfo _info; }; } // namespace graph } // namespace arm_compute -#endif /* __ARM_COMPUTE_GRAPH_NORMALIZATION_LAYER_H__ */ +#endif /* __ARM_COMPUTE_GRAPH_NORMALIZATION_LAYER_NODE_H__ */ diff --git a/arm_compute/graph/nodes/QuantizationLayer.h b/arm_compute/graph/nodes/OutputNode.h index a3ef02530e..46988cf969 100644 --- a/arm_compute/graph/nodes/QuantizationLayer.h +++ b/arm_compute/graph/nodes/OutputNode.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -21,25 +21,29 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#ifndef __ARM_COMPUTE_GRAPH_QUANTIZATION_LAYER_H__ -#define __ARM_COMPUTE_GRAPH_QUANTIZATION_LAYER_H__ +#ifndef __ARM_COMPUTE_GRAPH_OUTPUT_NODE_H__ +#define __ARM_COMPUTE_GRAPH_OUTPUT_NODE_H__ -#include "arm_compute/graph/GraphContext.h" #include "arm_compute/graph/INode.h" -#include "arm_compute/graph/ITensorObject.h" -#include "arm_compute/graph/Types.h" namespace arm_compute { namespace graph { -/** Quantization layer node */ -class QuantizationLayer final : public INode +/** Output Layer node */ +class OutputNode final : public INode { public: - // Inherited methods overriden: - std::unique_ptr<arm_compute::IFunction> instantiate_node(GraphContext &ctx, ITensorObject *input, ITensorObject *output) override; + /** Default Constructor */ + OutputNode(); + + // Inherited overridden methods: + Status validate() override; + NodeType type() const override; + bool forward_descriptors() override; + TensorDescriptor configure_output(size_t idx) const override; + void accept(INodeVisitor &v) override; }; } // namespace graph } // namespace arm_compute -#endif /* __ARM_COMPUTE_GRAPH_QUANTIZATION_LAYER_H__ */ +#endif /* __ARM_COMPUTE_GRAPH_OUTPUT_NODE_H__ */ diff --git a/arm_compute/graph/nodes/PoolingLayer.h b/arm_compute/graph/nodes/PoolingLayer.h deleted file mode 100644 index 5c45bc04ed..0000000000 --- a/arm_compute/graph/nodes/PoolingLayer.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2017 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef __ARM_COMPUTE_GRAPH_POOLING_LAYER_H__ -#define __ARM_COMPUTE_GRAPH_POOLING_LAYER_H__ - -#include "arm_compute/graph/GraphContext.h" -#include "arm_compute/graph/INode.h" -#include "arm_compute/graph/ITensorObject.h" -#include "arm_compute/graph/Types.h" - -namespace arm_compute -{ -namespace graph -{ -/** Pooling layer node */ -class PoolingLayer final : public INode -{ -public: - /** Default Constructor - * - * @param pool_info Pooling layer information - */ - PoolingLayer(const PoolingLayerInfo pool_info); - - // Inherited methods overriden: - std::unique_ptr<arm_compute::IFunction> instantiate_node(GraphContext &ctx, ITensorObject *input, ITensorObject *output) override; - -private: - const PoolingLayerInfo _pool_info; /**< Pooling layer information */ -}; -} // namespace graph -} // namespace arm_compute -#endif /* __ARM_COMPUTE_GRAPH_POOLING_LAYER_H__ */ diff --git a/arm_compute/graph/nodes/DepthConvertLayer.h b/arm_compute/graph/nodes/PoolingLayerNode.h index 03bf9b7ed5..e250eb247a 100644 --- a/arm_compute/graph/nodes/DepthConvertLayer.h +++ b/arm_compute/graph/nodes/PoolingLayerNode.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -21,38 +21,48 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#ifndef __ARM_COMPUTE_GRAPH_DEPTHCONVERT_LAYER_H__ -#define __ARM_COMPUTE_GRAPH_DEPTHCONVERT_LAYER_H__ +#ifndef __ARM_COMPUTE_GRAPH_POOLING_LAYER_NODE_H__ +#define __ARM_COMPUTE_GRAPH_POOLING_LAYER_NODE_H__ -#include "arm_compute/graph/GraphContext.h" #include "arm_compute/graph/INode.h" -#include "arm_compute/graph/ITensorObject.h" -#include "arm_compute/graph/Types.h" namespace arm_compute { namespace graph { -/** DepthConvertLayer layer node */ -class DepthConvertLayer final : public INode +/** Pooling Layer node */ +class PoolingLayerNode final : public INode { public: - /** Default constructor + /** Constructor * - * @param[in] policy Convertion policy - * @param[in] shift Shift value - * @param[in] output_datatype Output datatype + * @param[in] pool_info Pooling Layer information */ - DepthConvertLayer(const ConvertPolicy policy, uint32_t shift, DataType output_datatype); + PoolingLayerNode(PoolingLayerInfo pool_info); + /** Pooling metadata accessor + * + * @return Pooling Layer info + */ + PoolingLayerInfo pooling_info() const; + /** Computes pooling output shape + * + * @param[in] input_shape Input shape + * @param[in] info Pooling operation attributes + * + * @return Output shape + */ + static TensorShape compute_output_shape(TensorShape input_shape, PoolingLayerInfo info); - // Inherited methods overriden: - std::unique_ptr<arm_compute::IFunction> instantiate_node(GraphContext &ctx, ITensorObject *input, ITensorObject *output) override; + // Inherited overridden methods: + Status validate() override; + NodeType type() const override; + bool forward_descriptors() override; + TensorDescriptor configure_output(size_t idx) const override; + void accept(INodeVisitor &v) override; private: - const ConvertPolicy _policy; - uint32_t _shift; - DataType _output_datatype; + PoolingLayerInfo _info; }; } // namespace graph } // namespace arm_compute -#endif /* __ARM_COMPUTE_GRAPH_DEPTHCONVERT_LAYER_H__ */ +#endif /* __ARM_COMPUTE_GRAPH_POOLING_LAYER_NODE_H__ */ diff --git a/arm_compute/graph/nodes/ReshapeLayer.h b/arm_compute/graph/nodes/ReshapeLayerNode.h index b727d33a2c..ded344e041 100644 --- a/arm_compute/graph/nodes/ReshapeLayer.h +++ b/arm_compute/graph/nodes/ReshapeLayerNode.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -21,34 +21,35 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#ifndef __ARM_COMPUTE_GRAPH_RESHAPE_LAYER_H__ -#define __ARM_COMPUTE_GRAPH_RESHAPE_LAYER_H__ +#ifndef __ARM_COMPUTE_GRAPH_RESHAPE_LAYER_NODE_H__ +#define __ARM_COMPUTE_GRAPH_RESHAPE_LAYER_NODE_H__ -#include "arm_compute/graph/GraphContext.h" #include "arm_compute/graph/INode.h" -#include "arm_compute/graph/ITensorObject.h" -#include "arm_compute/graph/Types.h" namespace arm_compute { namespace graph { -/** Reshape layer node */ -class ReshapeLayer final : public INode +/** Reshape Layer node */ +class ReshapeLayerNode final : public INode { public: - /** Default constructor + /** Constructor * - * @param[in] shape Output shape + * @param[in] shape Reshaped tensor shape */ - ReshapeLayer(const TensorShape shape); + ReshapeLayerNode(TensorShape shape); - // Inherited methods overriden: - std::unique_ptr<arm_compute::IFunction> instantiate_node(GraphContext &ctx, ITensorObject *input, ITensorObject *output) override; + // Inherited overridden methods: + Status validate() override; + NodeType type() const override; + bool forward_descriptors() override; + TensorDescriptor configure_output(size_t idx) const override; + void accept(INodeVisitor &v) override; private: TensorShape _shape; }; } // namespace graph } // namespace arm_compute -#endif /* __ARM_COMPUTE_GRAPH_RESHAPE_LAYER_H__ */ +#endif /* __ARM_COMPUTE_GRAPH_RESHAPE_LAYER_NODE_H__ */ diff --git a/arm_compute/graph/nodes/ResidualLayer.h b/arm_compute/graph/nodes/ResidualLayer.h deleted file mode 100644 index 27e0501739..0000000000 --- a/arm_compute/graph/nodes/ResidualLayer.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2017-2018 ARM Limited. - * - * SPDX-License-Identifier: MIT - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef __ARM_COMPUTE_GRAPH_RESIDUAL_LAYER_H__ -#define __ARM_COMPUTE_GRAPH_RESIDUAL_LAYER_H__ - -#include "arm_compute/graph/GraphContext.h" -#include "arm_compute/graph/INode.h" -#include "arm_compute/graph/ITensorObject.h" -#include "arm_compute/graph/SubGraph.h" -#include "arm_compute/graph/Types.h" - -#include "arm_compute/core/utils/misc/Utility.h" - -#include <vector> - -namespace arm_compute -{ -namespace graph -{ -/** Branch Layer node */ -class ResidualLayer final : public INode -{ -public: - /** Default Constructor - * - * @param[in] sub_graph1 First graph branch - * @param[in] sub_graph2 Second graph branch - */ - template <typename... Ts> - ResidualLayer(SubGraph &&sub_graph1, SubGraph &&sub_graph2) - : _sub_graphs() - { - _sub_graphs.push_back(arm_compute::support::cpp14::make_unique<SubGraph>(std::move(sub_graph1))); - _sub_graphs.push_back(arm_compute::support::cpp14::make_unique<SubGraph>(std::move(sub_graph2))); - } - /** Default Constructor - * - * @param[in] sub_graph Sub graph - */ - template <typename... Ts> - ResidualLayer(SubGraph &&sub_graph) - : _sub_graphs() - { - _sub_graphs.push_back(arm_compute::support::cpp14::make_unique<SubGraph>(std::move(sub_graph))); - } - - // Inherited methods overriden: - std::unique_ptr<arm_compute::IFunction> instantiate_node(GraphContext &ctx, ITensorObject *input, ITensorObject *output) override; - -private: - std::vector<std::unique_ptr<SubGraph>> _sub_graphs; -}; -} // namespace graph -} // namespace arm_compute -#endif /* __ARM_COMPUTE_GRAPH_RESIDUAL_LAYER_H__ */ diff --git a/arm_compute/graph/nodes/ActivationLayer.h b/arm_compute/graph/nodes/SoftmaxLayerNode.h index bc619a8df9..8b716047ff 100644 --- a/arm_compute/graph/nodes/ActivationLayer.h +++ b/arm_compute/graph/nodes/SoftmaxLayerNode.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -21,34 +21,40 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#ifndef __ARM_COMPUTE_GRAPH_ACTIVATION_LAYER_H__ -#define __ARM_COMPUTE_GRAPH_ACTIVATION_LAYER_H__ +#ifndef __ARM_COMPUTE_GRAPH_SOFTMAX_LAYER_NODE_H__ +#define __ARM_COMPUTE_GRAPH_SOFTMAX_LAYER_NODE_H__ -#include "arm_compute/graph/GraphContext.h" #include "arm_compute/graph/INode.h" -#include "arm_compute/graph/ITensorObject.h" -#include "arm_compute/graph/Types.h" namespace arm_compute { namespace graph { -/** Activation Layer node */ -class ActivationLayer final : public INode +/** Softmax Layer node */ +class SoftmaxLayerNode final : public INode { public: - /** Default Constructor + /** Constructor * - * @param[in] activation_info Activation layer info + * @param[in] beta (Optional) Beta parameter. Defaults to 1 */ - ActivationLayer(const ActivationLayerInfo activation_info); + SoftmaxLayerNode(float beta = 1.f); + /** Beta parameter accessor + * + * @return Beta parameter + */ + float beta() const; - // Inherited methods overriden: - std::unique_ptr<arm_compute::IFunction> instantiate_node(GraphContext &ctx, ITensorObject *input, ITensorObject *output) override; + // Inherited overridden methods: + Status validate() override; + NodeType type() const override; + bool forward_descriptors() override; + TensorDescriptor configure_output(size_t idx) const override; + void accept(INodeVisitor &v) override; private: - const ActivationLayerInfo _activation_info; /**< Activation layer info */ + float _beta; }; } // namespace graph } // namespace arm_compute -#endif /* __ARM_COMPUTE_GRAPH_ACTIVATION_LAYER_H__ */ +#endif /* __ARM_COMPUTE_GRAPH_SOFTMAX_LAYER_NODE_H__ */ diff --git a/arm_compute/graph/nodes/SplitLayerNode.h b/arm_compute/graph/nodes/SplitLayerNode.h new file mode 100644 index 0000000000..923b3d1fa6 --- /dev/null +++ b/arm_compute/graph/nodes/SplitLayerNode.h @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2018 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef __ARM_COMPUTE_GRAPH_SPLIT_LAYER_NODE_H__ +#define __ARM_COMPUTE_GRAPH_SPLIT_LAYER_NODE_H__ + +#include "arm_compute/graph/INode.h" + +#include <tuple> + +namespace arm_compute +{ +namespace graph +{ +/** Split Layer node */ +class SplitLayerNode final : public INode +{ +public: + /** Default Constructor + * + * @param[in] num_splits Number of splits + * @param[in] axis (Optional) Axis to split on. Supported axis >= 2. Defaults to 0 + */ + SplitLayerNode(unsigned int num_splits, unsigned int axis = 0); + /** Computes split layer output shape + * + * @param[in] input_shape Shape of the input + * @param[in] num_splits Number of splits + * @param[in] axis Axis to perform the split on + * @param[in] idx Index of the split + * + * @return A pair with the shape of the split and the starting coordinates + */ + static std::pair<TensorShape, Coordinates> compute_output_shape(TensorShape input_shape, unsigned int num_splits, unsigned int axis, unsigned int idx); + /** Number of splits accessor + * + * @return Number of splits + */ + unsigned int num_splits() const; + /** Split axis accessor + * + * @return Split axis + */ + unsigned int axis() const; + + // Inherited overridden methods: + Status validate() override; + NodeType type() const override; + bool forward_descriptors() override; + TensorDescriptor configure_output(size_t idx) const override; + void accept(INodeVisitor &v) override; + +private: + unsigned int _num_splits; + unsigned int _axis; +}; +} // namespace graph +} // namespace arm_compute +#endif /* __ARM_COMPUTE_GRAPH_SPLIT_LAYER_NODE_H__ */ |