From bb54e4e40b7b08c509e234cd91ebd3087af66c23 Mon Sep 17 00:00:00 2001 From: Giorgio Arena Date: Thu, 5 Apr 2018 17:20:34 +0100 Subject: COMPMID-797 Integrate Mobilenet QASYMM8 with new graph. Change-Id: I4df63ec2f4eb27a8a6eec2bea27741bf8dec6910 Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/126966 Tested-by: Jenkins Reviewed-by: Anthony Barbier --- arm_compute/graph/GraphBuilder.h | 9 ++- arm_compute/graph/TensorDescriptor.h | 18 +++--- arm_compute/graph/TypePrinter.h | 8 +++ arm_compute/graph/backends/ValidateHelpers.h | 18 ++++-- arm_compute/graph/frontend/Layers.h | 82 +++++++++++++++----------- arm_compute/graph/nodes/ConvolutionLayerNode.h | 8 ++- 6 files changed, 89 insertions(+), 54 deletions(-) (limited to 'arm_compute/graph') diff --git a/arm_compute/graph/GraphBuilder.h b/arm_compute/graph/GraphBuilder.h index e01cfb1bc6..bbbbefbcbb 100644 --- a/arm_compute/graph/GraphBuilder.h +++ b/arm_compute/graph/GraphBuilder.h @@ -109,13 +109,17 @@ public: * @param[in] method (Optional) Convolution method to use * @param[in] weights_accessor (Optional) Accessor of the weights node data * @param[in] bias_accessor (Optional) Accessor of the bias node data + * @param[in] weights_quant_info (Optional) Weights quantization info + * @param[in] out_quant_info (Optional) Output quantization info * * @return Node ID of the created node, EmptyNodeID in case of error */ static NodeID add_convolution_node(Graph &g, NodeParams params, NodeIdxPair input, Size2D kernel_spatial_extend, unsigned int depth, PadStrideInfo conv_info, unsigned int num_groups = 1, ConvolutionMethod method = ConvolutionMethod::DEFAULT, - ITensorAccessorUPtr weights_accessor = nullptr, ITensorAccessorUPtr bias_accessor = nullptr); + ITensorAccessorUPtr weights_accessor = nullptr, ITensorAccessorUPtr bias_accessor = nullptr, + const QuantizationInfo weights_quant_info = QuantizationInfo(), + const QuantizationInfo out_quant_info = QuantizationInfo()); /** Adds a depth concatenate node to the graph * * @param[in] g Graph to add the node to @@ -135,13 +139,14 @@ public: * @param[in] method (Optional) Convolution method to use * @param[in] weights_accessor (Optional) Accessor of the weights node data * @param[in] bias_accessor (Optional) Accessor of the bias node data + * @param[in] quant_info (Optional) Weights quantization info * * @return Node ID of the created node, EmptyNodeID in case of error */ static NodeID add_depthwise_convolution_node(Graph &g, NodeParams params, NodeIdxPair input, Size2D kernel_spatial_extend, PadStrideInfo conv_info, DepthwiseConvolutionMethod method = DepthwiseConvolutionMethod::DEFAULT, - ITensorAccessorUPtr weights_accessor = nullptr, ITensorAccessorUPtr bias_accessor = nullptr); + ITensorAccessorUPtr weights_accessor = nullptr, ITensorAccessorUPtr bias_accessor = nullptr, const QuantizationInfo quant_info = QuantizationInfo()); /** Adds an element-wise layer node to the graph * * @param[in] g Graph to add the node to diff --git a/arm_compute/graph/TensorDescriptor.h b/arm_compute/graph/TensorDescriptor.h index fc0095e3b9..785c493cbc 100644 --- a/arm_compute/graph/TensorDescriptor.h +++ b/arm_compute/graph/TensorDescriptor.h @@ -37,18 +37,20 @@ struct TensorDescriptor final TensorDescriptor() = default; /** Constructor * - * @param[in] tensor_shape Tensor shape - * @param[in] tensor_data_type Tensor data type - * @param[in] tensor_target Target to allocate the tensor for + * @param[in] tensor_shape Tensor shape + * @param[in] tensor_data_type Tensor data type + * @param[in] tensor_quant_info Tensor quantization info + * @param[in] tensor_target Target to allocate the tensor for */ - TensorDescriptor(TensorShape tensor_shape, DataType tensor_data_type, Target tensor_target = Target::UNSPECIFIED) - : shape(tensor_shape), data_type(tensor_data_type), target(tensor_target) + TensorDescriptor(TensorShape tensor_shape, DataType tensor_data_type, QuantizationInfo tensor_quant_info = QuantizationInfo(), Target tensor_target = Target::UNSPECIFIED) + : shape(tensor_shape), data_type(tensor_data_type), quant_info(tensor_quant_info), target(tensor_target) { } - TensorShape shape{}; /**< Tensor shape */ - DataType data_type{ DataType::UNKNOWN }; /**< Data type */ - Target target{ Target::UNSPECIFIED }; /**< Target */ + TensorShape shape{}; /**< Tensor shape */ + DataType data_type{ DataType::UNKNOWN }; /**< Data type */ + QuantizationInfo quant_info{}; /**< Quantization info */ + Target target{ Target::UNSPECIFIED }; /**< Target */ }; } // namespace graph } // namespace arm_compute diff --git a/arm_compute/graph/TypePrinter.h b/arm_compute/graph/TypePrinter.h index d9bc8376bd..ed578307b5 100644 --- a/arm_compute/graph/TypePrinter.h +++ b/arm_compute/graph/TypePrinter.h @@ -308,6 +308,14 @@ inline ::std::ostream &operator<<(::std::ostream &os, const PadStrideInfo &pad_s return os; } + +/** Formatted output of the QuantizationInfo type. */ +inline ::std::ostream &operator<<(::std::ostream &os, const QuantizationInfo &quantization_info) +{ + os << "Scale:" << quantization_info.scale << "~" + << "Offset:" << quantization_info.offset; + return os; +} } // namespace graph } // namespace arm_compute #endif /* __ARM_COMPUTE_GRAPH_TYPE_PRINTER_H__ */ diff --git a/arm_compute/graph/backends/ValidateHelpers.h b/arm_compute/graph/backends/ValidateHelpers.h index ca01295d15..68a718ab97 100644 --- a/arm_compute/graph/backends/ValidateHelpers.h +++ b/arm_compute/graph/backends/ValidateHelpers.h @@ -70,12 +70,18 @@ Status validate_convolution_layer(ConvolutionLayerNode &node) ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1); // Extract IO and info - arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0)); - arm_compute::ITensorInfo *weights = get_backing_tensor_info(node.input(1)); - arm_compute::ITensorInfo *biases = get_backing_tensor_info(node.input(2)); - arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0)); - const PadStrideInfo conv_info = node.convolution_info(); - const ConvolutionMethod conv_algorithm = node.convolution_method(); + arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0)); + arm_compute::ITensorInfo *weights = get_backing_tensor_info(node.input(1)); + arm_compute::ITensorInfo *biases = get_backing_tensor_info(node.input(2)); + arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0)); + + if(is_data_type_quantized_asymmetric(input->data_type())) + { + biases->set_data_type(DataType::S32); + } + + const PadStrideInfo conv_info = node.convolution_info(); + const ConvolutionMethod conv_algorithm = node.convolution_method(); // Validate function Status status{}; diff --git a/arm_compute/graph/frontend/Layers.h b/arm_compute/graph/frontend/Layers.h index 22133b8376..2e7c50e6da 100644 --- a/arm_compute/graph/frontend/Layers.h +++ b/arm_compute/graph/frontend/Layers.h @@ -160,28 +160,34 @@ class ConvolutionLayer final : public ILayer public: /** Construct a convolution layer. * - * @param[in] conv_width Convolution width. - * @param[in] conv_height Convolution height. - * @param[in] ofm Output feature map. - * @param[in] weights Accessor to get kernel weights from. - * @param[in] bias Accessor to get kernel bias from. - * @param[in] conv_info Padding and stride information. - * @param[in] num_groups (Optional) Number of groups. Default: 1. + * @param[in] conv_width Convolution width. + * @param[in] conv_height Convolution height. + * @param[in] ofm Output feature map. + * @param[in] weights Accessor to get kernel weights from. + * @param[in] bias Accessor to get kernel bias from. + * @param[in] conv_info Padding and stride information. + * @param[in] num_groups (Optional) Number of groups. Default: 1. + * @param[in] weights_quant_info (Optional) Weights quantization information + * @param[in] out_quant_info (Optional) Output quantization info */ - ConvolutionLayer(unsigned int conv_width, - unsigned int conv_height, - unsigned int ofm, - ITensorAccessorUPtr weights, - ITensorAccessorUPtr bias, - PadStrideInfo conv_info, - unsigned int num_groups = 1) + ConvolutionLayer(unsigned int conv_width, + unsigned int conv_height, + unsigned int ofm, + ITensorAccessorUPtr weights, + ITensorAccessorUPtr bias, + PadStrideInfo conv_info, + unsigned int num_groups = 1, + const QuantizationInfo weights_quant_info = QuantizationInfo(), + const QuantizationInfo out_quant_info = QuantizationInfo()) : _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)) + _bias(std::move(bias)), + _weights_quant_info(std::move(weights_quant_info)), + _out_quant_info(std::move(out_quant_info)) { } @@ -192,17 +198,19 @@ public: return GraphBuilder::add_convolution_node(s.graph(), common_params, input, Size2D(_conv_width, _conv_height), _ofm, _conv_info, _num_groups, s.hints().convolution_method_hint, - std::move(_weights), std::move(_bias)); + std::move(_weights), std::move(_bias), std::move(_weights_quant_info), std::move(_out_quant_info)); } private: - unsigned int _conv_width; - unsigned int _conv_height; - unsigned int _ofm; - const PadStrideInfo _conv_info; - unsigned int _num_groups; - ITensorAccessorUPtr _weights; - ITensorAccessorUPtr _bias; + unsigned int _conv_width; + unsigned int _conv_height; + unsigned int _ofm; + const PadStrideInfo _conv_info; + unsigned int _num_groups; + ITensorAccessorUPtr _weights; + ITensorAccessorUPtr _bias; + const QuantizationInfo _weights_quant_info; + const QuantizationInfo _out_quant_info; }; /** Depthwise Convolution Layer */ @@ -216,17 +224,20 @@ public: * @param[in] weights Accessor to get kernel weights from. * @param[in] bias Accessor to get kernel bias from. * @param[in] conv_info Padding and stride information. + * @param[in] quant_info (Optional) Quantization info used for weights */ - DepthwiseConvolutionLayer(unsigned int conv_width, - unsigned int conv_height, - ITensorAccessorUPtr weights, - ITensorAccessorUPtr bias, - PadStrideInfo conv_info) + DepthwiseConvolutionLayer(unsigned int conv_width, + unsigned int conv_height, + ITensorAccessorUPtr weights, + ITensorAccessorUPtr bias, + PadStrideInfo conv_info, + const QuantizationInfo quant_info = QuantizationInfo()) : _conv_width(conv_width), _conv_height(conv_height), _conv_info(std::move(conv_info)), _weights(std::move(weights)), - _bias(std::move(bias)) + _bias(std::move(bias)), + _quant_info(std::move(quant_info)) { } @@ -237,15 +248,16 @@ public: 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)); + std::move(_weights), std::move(_bias), std::move(_quant_info)); } private: - unsigned int _conv_width; - unsigned int _conv_height; - const PadStrideInfo _conv_info; - ITensorAccessorUPtr _weights; - ITensorAccessorUPtr _bias; + unsigned int _conv_width; + unsigned int _conv_height; + const PadStrideInfo _conv_info; + ITensorAccessorUPtr _weights; + ITensorAccessorUPtr _bias; + const QuantizationInfo _quant_info; }; /** Flatten Layer */ diff --git a/arm_compute/graph/nodes/ConvolutionLayerNode.h b/arm_compute/graph/nodes/ConvolutionLayerNode.h index 70fefbeeab..d029895609 100644 --- a/arm_compute/graph/nodes/ConvolutionLayerNode.h +++ b/arm_compute/graph/nodes/ConvolutionLayerNode.h @@ -36,10 +36,11 @@ class ConvolutionLayerNode final : public INode public: /** Constructor * - * @param[in] info Convolution layer attributes - * @param[in] method (Optional) Convolution method to use + * @param[in] info Convolution layer attributes + * @param[in] method (Optional) Convolution method to use + * @param[in] out_quant_info (Optional) Output quantization info */ - ConvolutionLayerNode(PadStrideInfo info, ConvolutionMethod method = ConvolutionMethod::DEFAULT); + ConvolutionLayerNode(PadStrideInfo info, ConvolutionMethod method = ConvolutionMethod::DEFAULT, QuantizationInfo out_quant_info = QuantizationInfo()); /** Sets the convolution layer method to use * * @param[in] method Method to use for convolution @@ -78,6 +79,7 @@ public: private: PadStrideInfo _info; ConvolutionMethod _method; + QuantizationInfo _out_quant_info; }; } // namespace graph } // namespace arm_compute -- cgit v1.2.1