aboutsummaryrefslogtreecommitdiff
path: root/arm_compute/graph2/frontend
diff options
context:
space:
mode:
Diffstat (limited to 'arm_compute/graph2/frontend')
-rw-r--r--arm_compute/graph2/frontend/ILayer.h46
-rw-r--r--arm_compute/graph2/frontend/IStream.h93
-rw-r--r--arm_compute/graph2/frontend/IStreamOperators.h90
-rw-r--r--arm_compute/graph2/frontend/Layers.h410
-rw-r--r--arm_compute/graph2/frontend/Stream.h88
-rw-r--r--arm_compute/graph2/frontend/SubStream.h75
-rw-r--r--arm_compute/graph2/frontend/Types.h68
7 files changed, 870 insertions, 0 deletions
diff --git a/arm_compute/graph2/frontend/ILayer.h b/arm_compute/graph2/frontend/ILayer.h
new file mode 100644
index 0000000000..fee0b37e64
--- /dev/null
+++ b/arm_compute/graph2/frontend/ILayer.h
@@ -0,0 +1,46 @@
+/*
+ * 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_GRAPH2_ILAYER_H__
+#define __ARM_COMPUTE_GRAPH2_ILAYER_H__
+
+namespace arm_compute
+{
+namespace graph2
+{
+namespace frontend
+{
+// Forward declarations
+class IStream;
+
+/** ILayer interface **/
+class ILayer
+{
+public:
+ virtual ~ILayer() = default;
+ virtual NodeID create_layer(IStream &s) = 0;
+};
+} // namespace frontend
+} // namespace graph2
+} // namespace arm_compute
+#endif /* __ARM_COMPUTE_GRAPH2_ILAYER_H__ */
diff --git a/arm_compute/graph2/frontend/IStream.h b/arm_compute/graph2/frontend/IStream.h
new file mode 100644
index 0000000000..110be5230d
--- /dev/null
+++ b/arm_compute/graph2/frontend/IStream.h
@@ -0,0 +1,93 @@
+/*
+ * 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_GRAPH2_ISTREAM_H__
+#define __ARM_COMPUTE_GRAPH2_ISTREAM_H__
+
+#include "arm_compute/graph2/frontend/Types.h"
+
+namespace arm_compute
+{
+namespace graph2
+{
+// Forward declarations
+class Graph;
+
+namespace frontend
+{
+// Forward declarations
+class ILayer;
+
+/** Stream interface **/
+class IStream
+{
+public:
+ virtual ~IStream() = default;
+ /** Adds a layer to the stream
+ *
+ * @param[in] layer Layer to add
+ */
+ virtual void add_layer(ILayer &layer) = 0;
+ /** Returns the underlying graph
+ *
+ * @return Underlying graph
+ */
+ virtual Graph &graph() = 0;
+ /** Returns the underlying graph
+ *
+ * @return Underlying graph
+ */
+ virtual const Graph &graph() const = 0;
+ /** Returns the tail node of the Stream
+ *
+ * @return Tail Node ID
+ */
+ NodeID tail_node()
+ {
+ return _tail_node;
+ }
+ /** Returns the stream hints that are currently used
+ *
+ * @return Stream hints
+ */
+ StreamHints &hints()
+ {
+ return _hints;
+ }
+ /** Forwards tail of stream to a given nid
+ *
+ * @param[in] nid NodeID of the updated tail node
+ */
+ void forward_tail(NodeID nid)
+ {
+ _tail_node = (nid != NullTensorID) ? nid : _tail_node;
+ }
+
+protected:
+ StreamHints _hints = {}; /**< Execution and algorithmic hints */
+ NodeID _tail_node = { EmptyNodeID }; /**< NodeID pointing to the last(tail) node of the graph */
+};
+} // namespace frontend
+} // namespace graph2
+} // namespace arm_compute
+#endif /* __ARM_COMPUTE_GRAPH2_ISTREAM_H__ */
diff --git a/arm_compute/graph2/frontend/IStreamOperators.h b/arm_compute/graph2/frontend/IStreamOperators.h
new file mode 100644
index 0000000000..1798e4a4ab
--- /dev/null
+++ b/arm_compute/graph2/frontend/IStreamOperators.h
@@ -0,0 +1,90 @@
+/*
+ * 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_GRAPH2_ISTREAM_OPERATORS_H__
+#define __ARM_COMPUTE_GRAPH2_ISTREAM_OPERATORS_H__
+
+#include "arm_compute/graph2/frontend/IStream.h"
+#include "arm_compute/graph2/frontend/Types.h"
+
+namespace arm_compute
+{
+namespace graph2
+{
+namespace frontend
+{
+// Forward declarations
+class ILayer;
+
+/** Overloaded stream operator to add a node to the graph
+ *
+ * @param[in, out] s Stream to add the tensor
+ * @param[in] layer Layer to be added
+ *
+ * @return Updated stream
+ */
+inline IStream &operator<<(IStream &s, ILayer &&layer)
+{
+ s.add_layer(layer);
+ return s;
+}
+/** Overloaded stream operator to provide a target hint to the graph
+ *
+ * @param[in, out] s Stream to provide the hint to
+ * @param[in] target_hint Target hint to be considered
+ *
+ * @return Updated stream
+ */
+inline IStream &operator<<(IStream &s, Target target_hint)
+{
+ s.hints().target_hint = target_hint;
+ return s;
+}
+/** Overloaded stream operator to provide a convolution method hint to the graph
+ *
+ * @param[in, out] s Stream to provide the hint to
+ * @param[in] convolution_method_hint Convolution method hint to be considered
+ *
+ * @return Updated stream
+ */
+inline IStream &operator<<(IStream &s, ConvolutionMethod convolution_method_hint)
+{
+ s.hints().convolution_method_hint = convolution_method_hint;
+ return s;
+}
+/** Overloaded stream operator to provide a depthwise convolution method hint to the graph
+ *
+ * @param[in, out] s Stream to provide the hint to
+ * @param[in] depthwise_convolution_method_hint Depthwise Convolution method hint to be considered
+ *
+ * @return Updated stream
+ */
+inline IStream &operator<<(IStream &s, DepthwiseConvolutionMethod depthwise_convolution_method_hint)
+{
+ s.hints().depthwise_convolution_method_hint = depthwise_convolution_method_hint;
+ return s;
+}
+} // namespace frontend
+} // namespace graph2
+} // namespace arm_compute
+#endif /* __ARM_COMPUTE_GRAPH2_ISTREAM_OPERATORS_H__ */
diff --git a/arm_compute/graph2/frontend/Layers.h b/arm_compute/graph2/frontend/Layers.h
new file mode 100644
index 0000000000..40274a4769
--- /dev/null
+++ b/arm_compute/graph2/frontend/Layers.h
@@ -0,0 +1,410 @@
+/*
+ * 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_GRAPH2_LAYERS_H__
+#define __ARM_COMPUTE_GRAPH2_LAYERS_H__
+
+#include "arm_compute/graph2/GraphBuilder.h"
+#include "arm_compute/graph2/Types.h"
+#include "arm_compute/graph2/frontend/ILayer.h"
+#include "arm_compute/graph2/frontend/IStream.h"
+#include "arm_compute/graph2/frontend/SubStream.h"
+
+#include "arm_compute/core/utils/misc/Utility.h"
+
+#include <memory>
+#include <string>
+
+namespace arm_compute
+{
+namespace graph2
+{
+namespace frontend
+{
+/** Input Layer */
+class InputLayer final : public ILayer
+{
+public:
+ InputLayer(TensorDescriptor desc, ITensorAccessorUPtr accessor)
+ : _desc(desc), _accessor(std::move(accessor))
+ {
+ }
+
+ NodeID create_layer(IStream &s) override
+ {
+ NodeParams common_params = { "", s.hints().target_hint };
+ return GraphBuilder::add_input_node(s.graph(), common_params, _desc, std::move(_accessor));
+ }
+
+private:
+ TensorDescriptor _desc;
+ ITensorAccessorUPtr _accessor;
+};
+
+/** Output Layer */
+class OutputLayer final : public ILayer
+{
+public:
+ OutputLayer(ITensorAccessorUPtr accessor)
+ : _accessor(std::move(accessor))
+ {
+ }
+
+ NodeID create_layer(IStream &s) override
+ {
+ NodeParams common_params = { "", s.hints().target_hint };
+ NodeIdxPair input = { s.tail_node(), 0 };
+ return GraphBuilder::add_output_node(s.graph(), common_params, input, std::move(_accessor));
+ }
+
+private:
+ ITensorAccessorUPtr _accessor;
+};
+
+/** Activation Layer */
+class ActivationLayer final : public ILayer
+{
+public:
+ ActivationLayer(ActivationLayerInfo act_info)
+ : _act_info(act_info)
+ {
+ }
+
+ NodeID create_layer(IStream &s) override
+ {
+ NodeParams common_params = { "", s.hints().target_hint };
+ NodeIdxPair input = { s.tail_node(), 0 };
+ return GraphBuilder::add_activation_node(s.graph(), common_params, input, _act_info);
+ }
+
+private:
+ ActivationLayerInfo _act_info;
+};
+
+/** Batchnormalization Layer */
+class BatchNormalizationLayer final : public ILayer
+{
+public:
+ BatchNormalizationLayer(ITensorAccessorUPtr mean,
+ ITensorAccessorUPtr var,
+ ITensorAccessorUPtr gamma = nullptr,
+ ITensorAccessorUPtr beta = nullptr,
+ float epsilon = 0.001f)
+ : _mean(std::move(mean)), _var(std::move(var)), _gamma(std::move(gamma)), _beta(std::move(beta)), _epsilon(epsilon)
+ {
+ }
+
+ NodeID create_layer(IStream &s) override
+ {
+ ARM_COMPUTE_ERROR_ON(_mean == nullptr);
+ ARM_COMPUTE_ERROR_ON(_var == nullptr);
+
+ NodeParams common_params = { "", s.hints().target_hint };
+ NodeIdxPair input = { s.tail_node(), 0 };
+ return GraphBuilder::add_batch_normalization_node(s.graph(), common_params, input, _epsilon,
+ std::move(_mean), std::move(_var), std::move(_beta), std::move(_gamma));
+ }
+
+private:
+ ITensorAccessorUPtr _mean;
+ ITensorAccessorUPtr _var;
+ ITensorAccessorUPtr _gamma;
+ ITensorAccessorUPtr _beta;
+ float _epsilon;
+};
+
+/** Convolution Layer */
+class ConvolutionLayer final : public ILayer
+{
+public:
+ ConvolutionLayer(unsigned int conv_width,
+ unsigned int conv_height,
+ unsigned int ofm,
+ ITensorAccessorUPtr weights,
+ ITensorAccessorUPtr bias,
+ PadStrideInfo conv_info,
+ unsigned int num_groups = 1)
+ : _conv_width(conv_width),
+ _conv_height(conv_height),
+ _ofm(ofm),
+ _conv_info(std::move(conv_info)),
+ _num_groups(num_groups),
+ _weights(std::move(weights)),
+ _bias(std::move(bias))
+ {
+ }
+
+ NodeID create_layer(IStream &s) override
+ {
+ ARM_COMPUTE_UNUSED(_num_groups);
+ NodeIdxPair input = { s.tail_node(), 0 };
+ NodeParams common_params = { "", s.hints().target_hint };
+ return GraphBuilder::add_convolution_node(s.graph(), common_params, input,
+ Size2D(_conv_width, _conv_height), _ofm, _conv_info,
+ s.hints().convolution_method_hint,
+ std::move(_weights), std::move(_bias));
+ }
+
+private:
+ unsigned int _conv_width;
+ unsigned int _conv_height;
+ unsigned int _ofm;
+ const PadStrideInfo _conv_info;
+ unsigned int _num_groups;
+ ITensorAccessorUPtr _weights;
+ ITensorAccessorUPtr _bias;
+};
+
+/** Depthwise Convolution Layer */
+class DepthwiseConvolutionLayer final : public ILayer
+{
+public:
+ DepthwiseConvolutionLayer(unsigned int conv_width,
+ unsigned int conv_height,
+ ITensorAccessorUPtr weights,
+ ITensorAccessorUPtr bias,
+ PadStrideInfo conv_info)
+ : _conv_width(conv_width),
+ _conv_height(conv_height),
+ _conv_info(std::move(conv_info)),
+ _weights(std::move(weights)),
+ _bias(std::move(bias))
+ {
+ }
+
+ NodeID create_layer(IStream &s) override
+ {
+ NodeIdxPair input = { s.tail_node(), 0 };
+ NodeParams common_params = { "", s.hints().target_hint };
+ return GraphBuilder::add_depthwise_convolution_node(s.graph(), common_params,
+ input, Size2D(_conv_width, _conv_height), _conv_info,
+ s.hints().depthwise_convolution_method_hint,
+ std::move(_weights), std::move(_bias));
+ }
+
+private:
+ unsigned int _conv_width;
+ unsigned int _conv_height;
+ const PadStrideInfo _conv_info;
+ ITensorAccessorUPtr _weights;
+ ITensorAccessorUPtr _bias;
+};
+
+/** Flatten Layer */
+class FlattenLayer final : public ILayer
+{
+public:
+ FlattenLayer()
+ {
+ }
+
+ NodeID create_layer(IStream &s) override
+ {
+ NodeParams common_params = { "", s.hints().target_hint };
+ NodeIdxPair input = { s.tail_node(), 0 };
+ return GraphBuilder::add_flatten_node(s.graph(), common_params, input);
+ }
+};
+
+/** Fully Connected Layer */
+class FullyConnectedLayer final : public ILayer
+{
+public:
+ FullyConnectedLayer(unsigned int num_outputs,
+ ITensorAccessorUPtr weights,
+ ITensorAccessorUPtr bias)
+ : _num_outputs(num_outputs), _weights(std::move(weights)), _bias(std::move(bias))
+ {
+ }
+
+ NodeID create_layer(IStream &s) override
+ {
+ NodeParams common_params = { "", s.hints().target_hint };
+ NodeIdxPair input = { s.tail_node(), 0 };
+ return GraphBuilder::add_fully_connected_layer(s.graph(), common_params, input, _num_outputs,
+ std::move(_weights), std::move(_bias));
+ }
+
+private:
+ unsigned int _num_outputs;
+ ITensorAccessorUPtr _weights;
+ ITensorAccessorUPtr _bias;
+};
+
+/** Normalization Layer */
+class NormalizationLayer final : public ILayer
+{
+public:
+ NormalizationLayer(NormalizationLayerInfo norm_info)
+ : _norm_info(norm_info)
+ {
+ }
+
+ NodeID create_layer(IStream &s) override
+ {
+ NodeParams common_params = { "", s.hints().target_hint };
+ NodeIdxPair input = { s.tail_node(), 0 };
+ return GraphBuilder::add_normalization_node(s.graph(), common_params, input, _norm_info);
+ }
+
+private:
+ NormalizationLayerInfo _norm_info;
+};
+
+/** Pooling Layer */
+class PoolingLayer final : public ILayer
+{
+public:
+ PoolingLayer(PoolingLayerInfo pool_info)
+ : _pool_info(pool_info)
+ {
+ }
+
+ NodeID create_layer(IStream &s) override
+ {
+ NodeParams common_params = { "", s.hints().target_hint };
+ NodeIdxPair input = { s.tail_node(), 0 };
+ return GraphBuilder::add_pooling_node(s.graph(), common_params, input, _pool_info);
+ }
+
+private:
+ PoolingLayerInfo _pool_info;
+};
+
+/** Reshape Layer */
+class ReshapeLayer final : public ILayer
+{
+public:
+ ReshapeLayer(TensorShape shape)
+ : _shape(shape)
+ {
+ }
+
+ NodeID create_layer(IStream &s) override
+ {
+ NodeParams common_params = { "", s.hints().target_hint };
+ NodeIdxPair input = { s.tail_node(), 0 };
+ return GraphBuilder::add_reshape_node(s.graph(), common_params, input, _shape);
+ }
+
+private:
+ TensorShape _shape;
+};
+
+/** Softmax Layer */
+class SoftmaxLayer final : public ILayer
+{
+public:
+ SoftmaxLayer(float beta = 1.0f)
+ : _beta(beta)
+ {
+ }
+
+ NodeID create_layer(IStream &s) override
+ {
+ NodeParams common_params = { "", s.hints().target_hint };
+ NodeIdxPair input = { s.tail_node(), 0 };
+ return GraphBuilder::add_softmax_node(s.graph(), common_params, input, _beta);
+ }
+
+private:
+ float _beta;
+};
+
+/** Branch Layer */
+class BranchLayer final : public ILayer
+{
+public:
+ /** Default Constructor
+ *
+ * @param[in] merge_method Branch merging method
+ * @param[in] sub_stream1 First graph branch
+ * @param[in] sub_stream2 Second graph branch
+ * @param[in] rest_sub_streams Rest sub-graph branches
+ */
+ template <typename... Ts>
+ BranchLayer(BranchMergeMethod merge_method, SubStream &&sub_stream1, SubStream &&sub_stream2, Ts &&... rest_sub_streams)
+ : _branch_merge_method(merge_method), _sub_streams()
+ {
+ _sub_streams.push_back(arm_compute::support::cpp14::make_unique<SubStream>(std::move(sub_stream1)));
+ _sub_streams.push_back(arm_compute::support::cpp14::make_unique<SubStream>(std::move(sub_stream2)));
+
+ utility::for_each([&](SubStream && sub_stream)
+ {
+ _sub_streams.push_back(arm_compute::support::cpp14::make_unique<SubStream>(std::move(sub_stream)));
+ },
+ std::move(rest_sub_streams)...);
+ }
+ /** Default Constructor
+ *
+ * @param[in] sub_stream Sub-stream
+ */
+ template <typename... Ts>
+ BranchLayer(SubStream &&sub_stream)
+ : _branch_merge_method(BranchMergeMethod::DEPTH_CONCATENATE), _sub_streams()
+ {
+ _sub_streams.push_back(arm_compute::support::cpp14::make_unique<SubStream>(std::move(sub_stream)));
+ }
+ NodeID create_layer(IStream &s) override
+ {
+ NodeID nid = EmptyNodeID;
+ NodeParams common_params = { "", s.hints().target_hint };
+ if(_sub_streams.size() == 1 && _sub_streams.at(0) != nullptr)
+ {
+ nid = _sub_streams[0]->tail_node();
+ }
+ else if(_branch_merge_method == BranchMergeMethod::DEPTH_CONCATENATE)
+ {
+ // Collect tail nodes and perform DepthConcatenate
+ std::vector<NodeIdxPair> nodes;
+ for(auto &ss : _sub_streams)
+ {
+ if(ss && (ss->tail_node() != EmptyNodeID))
+ {
+ const auto tail_node = s.graph().node(ss->tail_node());
+ if(tail_node != nullptr && tail_node->type() != NodeType::Output)
+ {
+ nodes.push_back({ ss->tail_node(), 0 });
+ }
+ }
+ }
+ nid = GraphBuilder::add_depth_concatenate_node(s.graph(), common_params, nodes);
+ }
+ else
+ {
+ ARM_COMPUTE_ERROR_ON(_sub_streams.size() != 2);
+ NodeIdxPair input0 = { _sub_streams[0]->tail_node(), 0 };
+ NodeIdxPair input1 = { _sub_streams[1]->tail_node(), 0 };
+ nid = GraphBuilder::add_elementwise_node(s.graph(), common_params, input0, input1, EltwiseOperation::ADD);
+ }
+ return nid;
+ }
+
+private:
+ BranchMergeMethod _branch_merge_method;
+ std::vector<std::unique_ptr<SubStream>> _sub_streams;
+};
+} // namespace frontend
+} // namespace graph2
+} // namespace arm_compute
+#endif /* __ARM_COMPUTE_GRAPH2_LAYERS_H__ */
diff --git a/arm_compute/graph2/frontend/Stream.h b/arm_compute/graph2/frontend/Stream.h
new file mode 100644
index 0000000000..6100975958
--- /dev/null
+++ b/arm_compute/graph2/frontend/Stream.h
@@ -0,0 +1,88 @@
+/*
+ * 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_GRAPH2_STREAM_H__
+#define __ARM_COMPUTE_GRAPH2_STREAM_H__
+
+#include "arm_compute/graph2/frontend/IStream.h"
+#include "arm_compute/graph2/frontend/IStreamOperators.h"
+#include "arm_compute/graph2/frontend/Types.h"
+
+#include "arm_compute/graph2/Graph.h"
+#include "arm_compute/graph2/GraphContext.h"
+#include "arm_compute/graph2/GraphManager.h"
+
+namespace arm_compute
+{
+namespace graph2
+{
+namespace frontend
+{
+// Forward Declarations
+class ILayer;
+
+/** Stream frontend class to construct simple graphs in a stream fashion */
+class Stream final : public IStream
+{
+public:
+ /** Constructor
+ *
+ * @param[in] id Stream id
+ * @param[in] name Stream name
+ */
+ Stream(size_t id, std::string name);
+ /** Prevent instances of this class from being copied (As this class contains pointers) */
+ Stream(const Stream &) = delete;
+ /** Default move constructor */
+ Stream(Stream &&) = default;
+ /** Prevent instances of this class from being copied (As this class contains pointers) */
+ Stream &operator=(const Stream &) = delete;
+ /** Default move assignment operator */
+ Stream &operator=(Stream &&) = default;
+ /** Finalizes the stream for an execution target
+ *
+ * @note enable_tuning only works if the target is OpenCL.
+ * @note tuning increases the execution time of first run of the graph
+ *
+ * @param[in] target Execution target
+ * @param[in] enable_tuning (Optional) Enables the tuning interface. Defaults to false
+ * @param[in] enable_memory_management (Optional) Enables the memory management interface. Defaults to false
+ */
+ void finalize(Target target, bool enable_tuning = false, bool enable_memory_management = false);
+ /** Executes the stream **/
+ void run();
+
+ // Inherited overridden methods
+ void add_layer(ILayer &layer) override;
+ Graph &graph() override;
+ const Graph &graph() const override;
+
+private:
+ GraphManager _manager; /**< Graph manager */
+ GraphContext _ctx; /**< Graph context to use */
+ Graph _g; /**< Internal graph representation of the stream */
+};
+} // namespace frontend
+} // namespace graph2
+} // namespace arm_compute
+#endif /* __ARM_COMPUTE_GRAPH2_STREAM_H__ */ \ No newline at end of file
diff --git a/arm_compute/graph2/frontend/SubStream.h b/arm_compute/graph2/frontend/SubStream.h
new file mode 100644
index 0000000000..dee09b76ea
--- /dev/null
+++ b/arm_compute/graph2/frontend/SubStream.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_GRAPH2_SUB_STREAM_H__
+#define __ARM_COMPUTE_GRAPH2_SUB_STREAM_H__
+
+#include "arm_compute/graph2/frontend/IStream.h"
+#include "arm_compute/graph2/frontend/IStreamOperators.h"
+#include "arm_compute/graph2/frontend/Types.h"
+
+#include <memory>
+#include <vector>
+
+namespace arm_compute
+{
+namespace graph2
+{
+// Forward declarations
+class Graph;
+
+namespace frontend
+{
+// Forward declarations
+class ILayer;
+
+/** Sub stream class*/
+class SubStream final : public IStream
+{
+public:
+ /** Default Constructor
+ *
+ * @param[in] s Parent stream
+ */
+ SubStream(IStream &s);
+ /** Prevent instances of this class from being copied (As this class contains pointers) */
+ SubStream(const SubStream &) = delete;
+ /** Default move constructor */
+ SubStream(SubStream &&) = default;
+ /** Prevent instances of this class from being copied (As this class contains pointers) */
+ SubStream &operator=(const SubStream &) = delete;
+ /** Default move assignment operator */
+ SubStream &operator=(SubStream &&) = default;
+
+ // Inherited overridden methods
+ void add_layer(ILayer &layer) override;
+ Graph &graph() override;
+ const Graph &graph() const override;
+
+private:
+ IStream &_s; /**< Parent stream (assume that the lifetime of the parent is longer) */
+};
+} // namespace frontend
+} // namespace graph2
+} // namespace arm_compute
+#endif /* __ARM_COMPUTE_GRAPH2_SUB_STREAM_H__ */
diff --git a/arm_compute/graph2/frontend/Types.h b/arm_compute/graph2/frontend/Types.h
new file mode 100644
index 0000000000..234b998126
--- /dev/null
+++ b/arm_compute/graph2/frontend/Types.h
@@ -0,0 +1,68 @@
+/*
+ * 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_GRAPH2_STREAM_TYPES_H__
+#define __ARM_COMPUTE_GRAPH2_STREAM_TYPES_H__
+
+#include "arm_compute/graph2/Types.h"
+
+namespace arm_compute
+{
+namespace graph2
+{
+namespace frontend
+{
+// Import types for graph
+using graph2::DataType;
+using graph2::TensorShape;
+
+using graph2::ActivationLayerInfo;
+using graph2::NormalizationLayerInfo;
+using graph2::NormType;
+using graph2::PadStrideInfo;
+using graph2::PoolingLayerInfo;
+using graph2::PoolingType;
+using graph2::Target;
+using graph2::ConvolutionMethod;
+using graph2::DepthwiseConvolutionMethod;
+using graph2::TensorDescriptor;
+using graph2::DimensionRoundingType;
+
+/** Branch layer merging method */
+enum class BranchMergeMethod
+{
+ DEPTH_CONCATENATE, /**< Concatenate across depth */
+ ADD /**< Adds the results of each stream */
+};
+
+/** Hints that can be passed to the stream to expose parameterization */
+struct StreamHints
+{
+ Target target_hint = { Target::UNSPECIFIED }; /**< Target execution hint */
+ ConvolutionMethod convolution_method_hint = { ConvolutionMethod::DEFAULT }; /**< Convolution method hint */
+ DepthwiseConvolutionMethod depthwise_convolution_method_hint = { DepthwiseConvolutionMethod::DEFAULT }; /**< Depthwise Convolution method hint */
+};
+} // namespace frontend
+} // namespace graph2
+} // namespace arm_compute
+#endif /* __ARM_COMPUTE_GRAPH2_STREAM_TYPES_H__ */ \ No newline at end of file