diff options
Diffstat (limited to 'arm_compute')
-rw-r--r-- | arm_compute/core/utils/misc/Utility.h | 10 | ||||
-rw-r--r-- | arm_compute/graph/GraphBuilder.h | 14 | ||||
-rw-r--r-- | arm_compute/graph/Types.h | 1 | ||||
-rw-r--r-- | arm_compute/graph/frontend/Layers.h | 27 | ||||
-rw-r--r-- | arm_compute/graph/nodes/EltwiseLayerNode.h | 20 |
5 files changed, 70 insertions, 2 deletions
diff --git a/arm_compute/core/utils/misc/Utility.h b/arm_compute/core/utils/misc/Utility.h index 639f2e155d..f30a417a09 100644 --- a/arm_compute/core/utils/misc/Utility.h +++ b/arm_compute/core/utils/misc/Utility.h @@ -164,6 +164,16 @@ std::vector<size_t> sort_indices(const std::vector<T> &v) return idx; } + +inline bool endswith(const std::string &filename, const std::string &suffix) +{ + if(filename.size() < suffix.size()) + { + return false; + } + return std::equal(suffix.rbegin(), suffix.rend(), filename.rbegin()); +} + } // namespace utility } // namespace arm_compute #endif /* __ARM_COMPUTE_MISC_UTILITY_H__ */ diff --git a/arm_compute/graph/GraphBuilder.h b/arm_compute/graph/GraphBuilder.h index aea28eb8d6..04edf673d1 100644 --- a/arm_compute/graph/GraphBuilder.h +++ b/arm_compute/graph/GraphBuilder.h @@ -213,6 +213,20 @@ public: * @return Node ID of the created node, EmptyNodeID in case of error */ static NodeID add_reshape_node(Graph &g, NodeParams params, NodeIdxPair input, TensorShape shape); + /** Adds a scale layer node to the graph + * This layer computes a product of the input with a scale (read from mul_accessor) and it applies an offset (read from add_accessor). + * output = input * mul_w + add_w + * + * @param[in] g Graph to add the layer to + * @param[in] params Common node parameters + * @param[in] input Input to the fully connected layer node as a NodeID-Index pair + * @param[in] mul_accessor (Optional) Accessor of the mul node data + * @param[in] add_accessor (Optional) Accessor of the add node data + * + * @return Node ID of the created node, EmptyNodeID in case of error + */ + static NodeID add_scale_layer(Graph &g, const NodeParams ¶ms, NodeIdxPair input, + ITensorAccessorUPtr mul_accessor = nullptr, ITensorAccessorUPtr add_accessor = nullptr); /** Adds a softmax node to the graph * * @param[in] g Graph to add the node to diff --git a/arm_compute/graph/Types.h b/arm_compute/graph/Types.h index a910610c7a..d4e4f99377 100644 --- a/arm_compute/graph/Types.h +++ b/arm_compute/graph/Types.h @@ -137,6 +137,7 @@ enum class NodeType NormalizationLayer, PoolingLayer, ReshapeLayer, + ScaleLayer, SoftmaxLayer, SplitLayer, diff --git a/arm_compute/graph/frontend/Layers.h b/arm_compute/graph/frontend/Layers.h index d122a7a967..a97684453c 100644 --- a/arm_compute/graph/frontend/Layers.h +++ b/arm_compute/graph/frontend/Layers.h @@ -380,6 +380,33 @@ private: TensorShape _shape; }; +/** Scale Layer */ +class ScaleLayer final : public ILayer +{ +public: + /** Construct a scale layer. + * + * @param[in] mul_w Accessor to get mul weight from. + * @param[in] add_w Accessor to get add weight from. + */ + ScaleLayer(ITensorAccessorUPtr mul_w, + ITensorAccessorUPtr add_w) + : _mul_w(std::move(mul_w)), _add_w(std::move(add_w)) + { + } + + NodeID create_layer(IStream &s) override + { + NodeParams common_params = { name(), s.hints().target_hint }; + NodeIdxPair input = { s.tail_node(), 0 }; + return GraphBuilder::add_scale_layer(s.graph(), common_params, input, std::move(_mul_w), std::move(_add_w)); + } + +private: + ITensorAccessorUPtr _mul_w; + ITensorAccessorUPtr _add_w; +}; + /** Softmax Layer */ class SoftmaxLayer final : public ILayer { diff --git a/arm_compute/graph/nodes/EltwiseLayerNode.h b/arm_compute/graph/nodes/EltwiseLayerNode.h index 5b9fa84bbb..09cbc75b80 100644 --- a/arm_compute/graph/nodes/EltwiseLayerNode.h +++ b/arm_compute/graph/nodes/EltwiseLayerNode.h @@ -36,15 +36,29 @@ class EltwiseLayerNode final : public INode public: /** Constructor * - * @param[in] op Element-wise operation to perform + * @param[in] op Element-wise operation to perform + * @param[in] c_policy (Optional) Convert policy used for the operation + * @param[in] r_policy (Optional) Rounding policy used for the operation */ - EltwiseLayerNode(EltwiseOperation op); + EltwiseLayerNode(EltwiseOperation op, ConvertPolicy c_policy = ConvertPolicy::SATURATE, RoundingPolicy r_policy = RoundingPolicy::TO_ZERO); /** Eltwise operation accessor * * @return Eltwise operation that is to be performed by the node */ EltwiseOperation eltwise_operation() const; + /** Convert policy accessor + * + * @return Convert policy that is used in the node + */ + ConvertPolicy convert_policy() const; + + /** Rounding policy accessor + * + * @return Convert policy that is used in the node + */ + RoundingPolicy rounding_policy() const; + // Inherited overridden methods: NodeType type() const override; bool forward_descriptors() override; @@ -53,6 +67,8 @@ public: private: EltwiseOperation _op; + ConvertPolicy _convert_policy; + RoundingPolicy _rounding_policy; }; } // namespace graph } // namespace arm_compute |