From 2a07e184f7b359d13aa6cacfdc6431f9b191ef0c Mon Sep 17 00:00:00 2001 From: Anthony Barbier Date: Fri, 4 Aug 2017 18:20:27 +0100 Subject: COMPMID-363 Add Graph library support Change-Id: Ie841419bf65d0e06bdfe0bdd2d8d4e0bb3631e54 Reviewed-on: http://mpd-gerrit.cambridge.arm.com/87931 Reviewed-by: Pablo Tello Tested-by: Kaizen --- arm_compute/graph/CL/CLMap.h | 66 +++++++++++++ arm_compute/graph/CL/CLUnmap.h | 63 ++++++++++++ arm_compute/graph/Graph.h | 132 ++++++++++++++++++++++++++ arm_compute/graph/INode.h | 78 +++++++++++++++ arm_compute/graph/ITensorAccessor.h | 49 ++++++++++ arm_compute/graph/Nodes.h | 33 +++++++ arm_compute/graph/Tensor.h | 127 +++++++++++++++++++++++++ arm_compute/graph/Types.h | 54 +++++++++++ arm_compute/graph/nodes/ActivationLayer.h | 54 +++++++++++ arm_compute/graph/nodes/ConvolutionLayer.h | 71 ++++++++++++++ arm_compute/graph/nodes/FullyConnectedLayer.h | 63 ++++++++++++ arm_compute/graph/nodes/PoolingLayer.h | 54 +++++++++++ arm_compute/graph/nodes/SoftmaxLayer.h | 46 +++++++++ 13 files changed, 890 insertions(+) create mode 100644 arm_compute/graph/CL/CLMap.h create mode 100644 arm_compute/graph/CL/CLUnmap.h create mode 100644 arm_compute/graph/Graph.h create mode 100644 arm_compute/graph/INode.h create mode 100644 arm_compute/graph/ITensorAccessor.h create mode 100644 arm_compute/graph/Nodes.h create mode 100644 arm_compute/graph/Tensor.h create mode 100644 arm_compute/graph/Types.h create mode 100644 arm_compute/graph/nodes/ActivationLayer.h create mode 100644 arm_compute/graph/nodes/ConvolutionLayer.h create mode 100644 arm_compute/graph/nodes/FullyConnectedLayer.h create mode 100644 arm_compute/graph/nodes/PoolingLayer.h create mode 100644 arm_compute/graph/nodes/SoftmaxLayer.h (limited to 'arm_compute/graph') diff --git a/arm_compute/graph/CL/CLMap.h b/arm_compute/graph/CL/CLMap.h new file mode 100644 index 0000000000..a205ebcad1 --- /dev/null +++ b/arm_compute/graph/CL/CLMap.h @@ -0,0 +1,66 @@ +/* + * 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_CLMAP_H__ +#define __ARM_COMPUTE_GRAPH_CLMAP_H__ + +#include "arm_compute/graph/Types.h" +#include "arm_compute/runtime/IFunction.h" + +namespace arm_compute +{ +class CLTensor; + +namespace graph +{ +class Tensor; +/** OpenCL map function */ +class CLMap : public arm_compute::IFunction +{ +public: + /** Constructor + * + * @param[in] tensor Tensor to map + * @param[in] blocking Flag to specify if the map should be blocking or not (defaults to false) + */ + CLMap(Tensor *tensor, bool blocking = false); + /** Prevent instances from being copy constructed */ + CLMap(const CLMap &) = delete; + /** Prevent instances from being copy assigned */ + const CLMap &operator=(const CLMap &) = delete; + /** Allow instances to be move constructed */ + CLMap(CLMap &&) = default; + /** Allow instances to be move assigned */ + CLMap &operator=(CLMap &&) = default; + + // Inherited methods overriden: + void run() override; + +private: + arm_compute::CLTensor *_tensor; /**< Tensor */ + bool _blocking; /**< Blocking flag */ +}; +} // namespace graph +} // namespace arm_compute + +#endif /* __ARM_COMPUTE_GRAPH_CLMAP_H__ */ diff --git a/arm_compute/graph/CL/CLUnmap.h b/arm_compute/graph/CL/CLUnmap.h new file mode 100644 index 0000000000..a72706353b --- /dev/null +++ b/arm_compute/graph/CL/CLUnmap.h @@ -0,0 +1,63 @@ +/* + * 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_CLUNMAP_H__ +#define __ARM_COMPUTE_GRAPH_CLUNMAP_H__ + +#include "arm_compute/graph/Types.h" +#include "arm_compute/runtime/IFunction.h" + +namespace arm_compute +{ +class CLTensor; + +namespace graph +{ +class Tensor; +/** OpenCL un-map function */ +class CLUnmap : public arm_compute::IFunction +{ +public: + /** Constructor + * + * @param[in] tensor Tensor to un-map + */ + CLUnmap(Tensor *tensor); + /** Prevent instances from being copy constructed */ + CLUnmap(const CLUnmap &) = delete; + /** Prevent instances from being copy assigned */ + const CLUnmap &operator=(const CLUnmap &) = delete; + /** Allow instances to be move constructed */ + CLUnmap(CLUnmap &&) = default; + /** Allow instances to be move assigned */ + CLUnmap &operator=(CLUnmap &&) = default; + + // Inherited methods overriden: + void run() override; + +private: + arm_compute::CLTensor *_tensor; /**< Tensor */ +}; +} // namespace graph +} // namespace arm_compute +#endif /* __ARM_COMPUTE_GRAPH_CLUNMAP_H__ */ diff --git a/arm_compute/graph/Graph.h b/arm_compute/graph/Graph.h new file mode 100644 index 0000000000..3c263c2bdd --- /dev/null +++ b/arm_compute/graph/Graph.h @@ -0,0 +1,132 @@ +/* + * 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_GRAPH_H__ +#define __ARM_COMPUTE_GRAPH_GRAPH_H__ + +#include "arm_compute/graph/INode.h" +#include "arm_compute/graph/Tensor.h" +#include "arm_compute/graph/Types.h" +#include "support/ToolchainSupport.h" + +#include + +namespace arm_compute +{ +class IFunction; + +namespace graph +{ +/** Graph class */ +class Graph final +{ +public: + /** Constructor */ + Graph(); + /** Destructor */ + ~Graph(); + /** Prevent instances from being copy constructed */ + Graph(const Graph &) = delete; + /** Prevent instances from being copy assigned */ + const Graph &operator=(const Graph &) = delete; + /** Prevent instances from being move constructed */ + Graph(Graph &&) = delete; + /** Prevent instances from being move assigned */ + Graph &operator=(Graph &&) = delete; + /** Executes the graph */ + void run(); + /** Adds a node to the graph + * + * @param[in] node Node to add + */ + void add_node(std::unique_ptr node); + /** Adds a tensor to the graph + * + * @param[in] tensor Tensor to add + */ + void add_tensor(std::unique_ptr tensor); + /** Sets an execution hint to the graph + * + * @note Hint is propagated to the following node and as per name + * its just a hint/preference to be considered by the graph executor + * + * @param[in] hint execution hint + */ + void set_hint(Hint hint); + /** Manually sets the output of the current node + * + * @param[in] tmp Output info to set + */ + void set_temp(TensorInfo &&tmp); + + /** Sets whether to enable information print out + * + * @param[in] is_enabled Set to true if need info printed out + */ + void set_info_enablement(bool is_enabled); + +private: + class Private; + std::unique_ptr _pimpl; /**< Internal implementation class */ +}; + +/** Overloaded stream operator to add a tensor through its tensor info to the graph + * + * @param[in, out] graph Graph to add the tensor + * @param[in] info Tensor information of the tensor to be added + * + * @return Updated graph + */ +Graph &operator<<(Graph &graph, TensorInfo &&info); +/** Overloaded stream operator to add a tensor to the graph + * + * @param[in, out] graph Graph to add the tensor + * @param[in] tensor Tensor to be added + * + * @return Updated graph + */ +Graph &operator<<(Graph &graph, Tensor &&tensor); +/** Overloaded stream operator to provide an execution hint to the graph + * + * @param[in, out] graph Graph to provide the hint to + * @param[in] hint Execution hint to be considered + * + * @return Updated graph + */ +Graph &operator<<(Graph &graph, Hint hint); +/** Overloaded stream operator to add a node to the graph + * + * @param[in, out] graph Graph to add the tensor + * @param[in] node Node to be added + * + * @return Updated graph + */ +template +Graph &operator<<(Graph &graph, Node node) +{ + graph.add_node(arm_compute::support::cpp14::make_unique(std::move(node))); + return graph; +} +} // namespace graph +} // namespace arm_compute +#endif /* __ARM_COMPUTE_GRAPH_GRAPH_H__ */ diff --git a/arm_compute/graph/INode.h b/arm_compute/graph/INode.h new file mode 100644 index 0000000000..13b5d05f87 --- /dev/null +++ b/arm_compute/graph/INode.h @@ -0,0 +1,78 @@ +/* + * 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_INODE_H__ +#define __ARM_COMPUTE_GRAPH_INODE_H__ + +#include "arm_compute/graph/Types.h" +#include "arm_compute/runtime/IFunction.h" + +#include + +namespace arm_compute +{ +namespace graph +{ +/** Node interface */ +class INode +{ +public: + /** Virtual Destructor */ + virtual ~INode() = default; + /** Interface to be implemented that instantiates the node + * + * @param[in] hint Hint to where the node should be executed + * @param[in] input Input tensor of the node + * @param[in] output Output tensor of the node + */ + virtual std::unique_ptr instantiate_node(Hint hint, ITensor *input, ITensor *output) = 0; + /** Override the existing hint + * + * @note If the input is DONT_CARE then the method has to pick a technology, + * else it can accept the hint or override it (But not with DONT_CARE) + * + * @param[in] hint Hint to be considered + * + * @return The updated hint + */ + Hint override_hint(Hint hint) const; + + virtual void print_info() = 0; + +protected: + /** Interface to be implement that override the hint + * + * @param[in] hint Hint to be considered + * + * @return The updated hint + */ + virtual Hint node_override_hint(Hint hint) const; + +protected: + Hint _hint{ Hint::DONT_CARE }; + ITensor *_input{ nullptr }; + ITensor *_output{ nullptr }; +}; +} // namespace graph +} // namespace arm_compute +#endif /* __ARM_COMPUTE_GRAPH_INODE_H__ */ diff --git a/arm_compute/graph/ITensorAccessor.h b/arm_compute/graph/ITensorAccessor.h new file mode 100644 index 0000000000..d6a254ab73 --- /dev/null +++ b/arm_compute/graph/ITensorAccessor.h @@ -0,0 +1,49 @@ +/* + * 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_ITENSORACCESSOR_H__ +#define __ARM_COMPUTE_GRAPH_ITENSORACCESSOR_H__ + +#include "arm_compute/graph/Types.h" + +namespace arm_compute +{ +namespace graph +{ +/** Tensor accessor interface */ +class ITensorAccessor +{ +public: + /** Default virtual destructor */ + virtual ~ITensorAccessor() = default; + /** Interface to be implemented to access a given tensor + * + * @param[in] tensor Tensor to be accessed + * + * @return True if access is successful else false + */ + virtual bool access_tensor(ITensor &tensor) = 0; +}; +} // namespace graph +} // namespace arm_compute +#endif /* __ARM_COMPUTE_GRAPH_ITENSORACCESSOR_H__ */ diff --git a/arm_compute/graph/Nodes.h b/arm_compute/graph/Nodes.h new file mode 100644 index 0000000000..5e995ac8d1 --- /dev/null +++ b/arm_compute/graph/Nodes.h @@ -0,0 +1,33 @@ +/* + * 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_NODES_H__ +#define __ARM_COMPUTE_GRAPH_NODES_H__ + +#include "arm_compute/graph/nodes/ActivationLayer.h" +#include "arm_compute/graph/nodes/ConvolutionLayer.h" +#include "arm_compute/graph/nodes/FullyConnectedLayer.h" +#include "arm_compute/graph/nodes/PoolingLayer.h" +#include "arm_compute/graph/nodes/SoftmaxLayer.h" + +#endif /* __ARM_COMPUTE_GRAPH_NODES_H__ */ diff --git a/arm_compute/graph/Tensor.h b/arm_compute/graph/Tensor.h new file mode 100644 index 0000000000..0e823ffad0 --- /dev/null +++ b/arm_compute/graph/Tensor.h @@ -0,0 +1,127 @@ +/* + * 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_TENSOR_H__ +#define __ARM_COMPUTE_GRAPH_TENSOR_H__ + +#include "arm_compute/graph/ITensorAccessor.h" +#include "arm_compute/graph/Types.h" +#include "support/ToolchainSupport.h" + +#include + +namespace arm_compute +{ +namespace graph +{ +/** Tensor class */ +class Tensor +{ +public: + /** Constructor + * + * @param[in] info Tensor info to use + */ + Tensor(TensorInfo &&info); + /** Constructor + * + * @param[in] accessor Tensor accessor + */ + template + Tensor(std::unique_ptr accessor) + : _target(Hint::DONT_CARE), _info(), _accessor(std::move(accessor)), _tensor(nullptr) + { + } + /** Constructor + * + * @param[in] accessor Tensor accessor + */ + template + Tensor(AccessorType &&accessor) + : _target(Hint::DONT_CARE), _info(), _accessor(arm_compute::support::cpp14::make_unique(std::forward(accessor))), _tensor(nullptr) + { + } + /** Constructor + * + * @param[in] info Tensor info to use + * @param[in] accessor Tensor accessor + */ + template + Tensor(TensorInfo &&info, AccessorType &&accessor) + : _target(Hint::DONT_CARE), _info(info), _accessor(arm_compute::support::cpp14::make_unique(std::forward(accessor))), _tensor(nullptr) + { + } + /** Default Destructor */ + ~Tensor() = default; + /** Move Constructor + * + * @param[in] src Tensor to move + */ + Tensor(Tensor &&src) noexcept; + + /** Sets the given TensorInfo to the tensor + * + * @param[in] info TensorInfo to set + */ + void set_info(TensorInfo &&info); + /** Calls accessor on tensor + * + * @return True if succeeds else false + */ + bool call_accessor(); + /** Sets target of the tensor + * + * @param[in] target Target where the tensor should be pinned in + * + * @return + */ + ITensor *set_target(Hint target); + /** Returns tensor's TensorInfo + * + * @return TensorInfo of the tensor + */ + const TensorInfo &info() const; + /** Returns a pointer to the internal tensor + * + * @return Tensor + */ + ITensor *tensor(); + /** Allocates and fills the tensor if needed */ + void allocate_and_fill_if_needed(); + /** Allocates the tensor */ + void allocate(); + /** Return the target that this tensor is pinned on + * + * @return Target of the tensor + */ + Hint target() const; + +private: + Hint _target; /**< Target that this tensor is pinned on */ + TensorInfo _info; /**< Tensor metadata */ + std::unique_ptr _accessor; /**< Tensor Accessor */ + std::unique_ptr _tensor; /**< Tensor */ +}; +} // namespace graph +} // namespace arm_compute +#endif /* __ARM_COMPUTE_GRAPH_TENSOR_H__ */ diff --git a/arm_compute/graph/Types.h b/arm_compute/graph/Types.h new file mode 100644 index 0000000000..0b9596d589 --- /dev/null +++ b/arm_compute/graph/Types.h @@ -0,0 +1,54 @@ +/* + * 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_TYPES_H__ +#define __ARM_COMPUTE_GRAPH_TYPES_H__ + +#include "arm_compute/core/ITensor.h" +#include "arm_compute/core/TensorInfo.h" + +namespace arm_compute +{ +namespace graph +{ +using arm_compute::ActivationLayerInfo; +using arm_compute::ITensor; +using arm_compute::TensorInfo; +using arm_compute::DataType; +using arm_compute::TensorShape; +using arm_compute::PadStrideInfo; +using arm_compute::WeightsInfo; +using arm_compute::PoolingLayerInfo; +using arm_compute::PoolingType; + +/**< Execution hint to the graph executor */ +enum class Hint +{ + DONT_CARE, /**< Run node in any device */ + OPENCL, /**< Run node on an OpenCL capable device (GPU) */ + NEON /**< Run node on a NEON capable device */ +}; + +} // namespace graph +} // namespace arm_compute +#endif /*__ARM_COMPUTE_GRAPH_TYPES_H__*/ diff --git a/arm_compute/graph/nodes/ActivationLayer.h b/arm_compute/graph/nodes/ActivationLayer.h new file mode 100644 index 0000000000..c23674e7b6 --- /dev/null +++ b/arm_compute/graph/nodes/ActivationLayer.h @@ -0,0 +1,54 @@ +/* + * 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_ACTIVATION_LAYER_H__ +#define __ARM_COMPUTE_GRAPH_ACTIVATION_LAYER_H__ + +#include "arm_compute/graph/INode.h" +#include "arm_compute/graph/Tensor.h" +#include "arm_compute/graph/Types.h" + +namespace arm_compute +{ +namespace graph +{ +/** Activation Layer node */ +class ActivationLayer : public INode +{ +public: + /** Default Constructor + * + * @param[in] activation_info Activation layer info + */ + ActivationLayer(const ActivationLayerInfo activation_info); + + // Inherited methods overriden: + std::unique_ptr instantiate_node(Hint hint, ITensor *input, ITensor *output) override; + void print_info() override; + +private: + const ActivationLayerInfo _activation_info; /**< Activation layer info */ +}; +} // namespace graph +} // namespace arm_compute +#endif /* __ARM_COMPUTE_GRAPH_ACTIVATION_LAYER_H__ */ diff --git a/arm_compute/graph/nodes/ConvolutionLayer.h b/arm_compute/graph/nodes/ConvolutionLayer.h new file mode 100644 index 0000000000..c0e257bf6a --- /dev/null +++ b/arm_compute/graph/nodes/ConvolutionLayer.h @@ -0,0 +1,71 @@ +/* + * 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_CONVOLUTION_LAYER_H__ +#define __ARM_COMPUTE_GRAPH_CONVOLUTION_LAYER_H__ + +#include "arm_compute/graph/INode.h" +#include "arm_compute/graph/Tensor.h" +#include "arm_compute/graph/Types.h" + +namespace arm_compute +{ +namespace graph +{ +/** Convolution layer node */ +class ConvolutionLayer : 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] weights_info Weights information + */ + template + ConvolutionLayer(unsigned int conv_width, unsigned int conv_height, unsigned int ofm, AccessorTypeWeights &&weights, + AccessorTypeBiases &&biases, const PadStrideInfo &conv_info, const WeightsInfo &weights_info = WeightsInfo()) + : _conv_width(conv_width), _conv_height(conv_height), _ofm(ofm), _weights(std::move(weights)), _biases(std::move(biases)), _conv_info(conv_info), _weights_info(weights_info) + { + } + + // Inherited methods overriden: + std::unique_ptr instantiate_node(Hint hint, ITensor *input, ITensor *output) override; + void print_info() override; + +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 */ + const WeightsInfo &_weights_info; /**< Convolution layer weights information */ +}; +} // namespace graph +} // namespace arm_compute +#endif /* __ARM_COMPUTE_GRAPH_CONVOLUTION_LAYER_H__ */ diff --git a/arm_compute/graph/nodes/FullyConnectedLayer.h b/arm_compute/graph/nodes/FullyConnectedLayer.h new file mode 100644 index 0000000000..3e1fe23b11 --- /dev/null +++ b/arm_compute/graph/nodes/FullyConnectedLayer.h @@ -0,0 +1,63 @@ +/* + * 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/INode.h" +#include "arm_compute/graph/Tensor.h" +#include "arm_compute/graph/Types.h" + +namespace arm_compute +{ +namespace graph +{ +/** Fully connected layer node */ +class FullyConnectedLayer : 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 + 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 instantiate_node(Hint hint, ITensor *input, ITensor *output) override; + void print_info() 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/PoolingLayer.h b/arm_compute/graph/nodes/PoolingLayer.h new file mode 100644 index 0000000000..14e2c6d264 --- /dev/null +++ b/arm_compute/graph/nodes/PoolingLayer.h @@ -0,0 +1,54 @@ +/* + * 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/INode.h" +#include "arm_compute/graph/Tensor.h" +#include "arm_compute/graph/Types.h" + +namespace arm_compute +{ +namespace graph +{ +/** Pooling layer node */ +class PoolingLayer : public INode +{ +public: + /** Default Constructor + * + * @param pool_info Pooling layer information + */ + PoolingLayer(const PoolingLayerInfo pool_info); + + // Inherited methods overriden: + std::unique_ptr instantiate_node(Hint hint, ITensor *input, ITensor *output) override; + void print_info() 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/SoftmaxLayer.h b/arm_compute/graph/nodes/SoftmaxLayer.h new file mode 100644 index 0000000000..1779adae66 --- /dev/null +++ b/arm_compute/graph/nodes/SoftmaxLayer.h @@ -0,0 +1,46 @@ +/* + * 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_SOFTMAX_LAYER_H__ +#define __ARM_COMPUTE_GRAPH_SOFTMAX_LAYER_H__ + +#include "arm_compute/graph/INode.h" +#include "arm_compute/graph/Tensor.h" +#include "arm_compute/graph/Types.h" + +namespace arm_compute +{ +namespace graph +{ +/** Softmax layer node */ +class SoftmaxLayer : public INode +{ +public: + // Inherited methods overriden: + std::unique_ptr instantiate_node(Hint hint, ITensor *input, ITensor *output) override; + void print_info() override; +}; + +} // namespace graph +} // namespace arm_compute +#endif /* __ARM_COMPUTE_GRAPH_SOFTMAX_LAYER_H__ */ -- cgit v1.2.1