From e1347c6554b8ad3a857787f35b83dae6edeb24ea Mon Sep 17 00:00:00 2001 From: =?utf8?q?Shubham=20Gupta/System=20SW=20/SRI-Bangalore/Engineer/?= =?utf8?q?=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Thu, 25 Oct 2018 09:55:44 +0530 Subject: [PATCH] Setting missing quantization info (#3330) This patch will pass scale and offset so as to set quantization info. If required, this quantization info can be used by the operations Signed-off-by: shubham --- runtimes/pure_arm_compute/src/compilation.cc | 150 +++++++++++++++++---------- 1 file changed, 95 insertions(+), 55 deletions(-) diff --git a/runtimes/pure_arm_compute/src/compilation.cc b/runtimes/pure_arm_compute/src/compilation.cc index 7206815..2fcdd8b 100644 --- a/runtimes/pure_arm_compute/src/compilation.cc +++ b/runtimes/pure_arm_compute/src/compilation.cc @@ -2207,10 +2207,12 @@ void Planner::visit(const ::internal::tflite::op::ResizeBilinear::Node &node) // TODO Should move to the place where the operand is handled, if it is possible. // Set Shape Constraints - _builder.addShapeConstr(ofm_index, asTensorInfo(asTensorShape(_ctx.at(ofm_index).shape()), - _ctx.at(ofm_index).type())); - _builder.addShapeConstr(ifm_index, asTensorInfo(asTensorShape(_ctx.at(ifm_index).shape()), - _ctx.at(ifm_index).type())); + _builder.addShapeConstr( + ofm_index, asTensorInfo(asTensorShape(_ctx.at(ofm_index).shape()), _ctx.at(ofm_index).type(), + _ctx.at(ofm_index).scale(), _ctx.at(ofm_index).zeroPoint())); + _builder.addShapeConstr( + ifm_index, asTensorInfo(asTensorShape(_ctx.at(ifm_index).shape()), _ctx.at(ifm_index).type(), + _ctx.at(ifm_index).scale(), _ctx.at(ifm_index).zeroPoint())); struct Param { @@ -2447,14 +2449,18 @@ void Planner::visit(const ::internal::tflite::op::StridedSlice::Node &node) assert(_ctx.at(startData_index).shape().rank() == 1); assert(_ctx.at(endData_index).shape().rank() == 1); assert(_ctx.at(stridesData_index).shape().rank() == 1); - _builder.addShapeConstr(startData_index, - asTensorInfo(asTensorShape(_ctx.at(startData_index).shape()), - _ctx.at(startData_index).type())); + _builder.addShapeConstr( + startData_index, + asTensorInfo(asTensorShape(_ctx.at(startData_index).shape()), _ctx.at(startData_index).type(), + _ctx.at(startData_index).scale(), _ctx.at(startData_index).zeroPoint())); _builder.addShapeConstr(endData_index, asTensorInfo(asTensorShape(_ctx.at(endData_index).shape()), - _ctx.at(endData_index).type())); - _builder.addShapeConstr(stridesData_index, - asTensorInfo(asTensorShape(_ctx.at(endData_index).shape()), - _ctx.at(stridesData_index).type())); + _ctx.at(endData_index).type(), + _ctx.at(endData_index).scale(), + _ctx.at(endData_index).zeroPoint())); + _builder.addShapeConstr( + stridesData_index, + asTensorInfo(asTensorShape(_ctx.at(endData_index).shape()), _ctx.at(stridesData_index).type(), + _ctx.at(stridesData_index).scale(), _ctx.at(stridesData_index).zeroPoint())); // Set initializers for indices data such as order of inputData { @@ -2580,10 +2586,12 @@ void Planner::visit(const ::internal::tflite::op::ReduceMax::Node &node) } } - _builder.addShapeConstr(ofm_index, asTensorInfo(asTensorShape(_ctx.at(ofm_index).shape()), - _ctx.at(ofm_index).type())); - _builder.addShapeConstr(ifm_index, asTensorInfo(asTensorShape(_ctx.at(ifm_index).shape()), - _ctx.at(ifm_index).type())); + _builder.addShapeConstr( + ofm_index, asTensorInfo(asTensorShape(_ctx.at(ofm_index).shape()), _ctx.at(ofm_index).type(), + _ctx.at(ofm_index).scale(), _ctx.at(ofm_index).zeroPoint())); + _builder.addShapeConstr( + ifm_index, asTensorInfo(asTensorShape(_ctx.at(ifm_index).shape()), _ctx.at(ifm_index).type(), + _ctx.at(ifm_index).scale(), _ctx.at(ifm_index).zeroPoint())); std::vector axis; { @@ -3019,10 +3027,12 @@ void Planner::visit(const ::internal::tflite::op::Tanh::Node &node) const ::internal::tflite::operand::Index ifm_index{node.param().ifm_index}; // Set shape constraints - _builder.addShapeConstr(ofm_index, asTensorInfo(asTensorShape(_ctx.at(ofm_index).shape()), - _ctx.at(ofm_index).type())); - _builder.addShapeConstr(ifm_index, asTensorInfo(asTensorShape(_ctx.at(ifm_index).shape()), - _ctx.at(ifm_index).type())); + _builder.addShapeConstr( + ofm_index, asTensorInfo(asTensorShape(_ctx.at(ofm_index).shape()), _ctx.at(ofm_index).type(), + _ctx.at(ofm_index).scale(), _ctx.at(ofm_index).zeroPoint())); + _builder.addShapeConstr( + ifm_index, asTensorInfo(asTensorShape(_ctx.at(ifm_index).shape()), _ctx.at(ifm_index).type(), + _ctx.at(ofm_index).scale(), _ctx.at(ofm_index).zeroPoint())); struct Param { @@ -3168,8 +3178,10 @@ void Planner::visit(const ::internal::tflite::op::Mean::Node &node) _builder.addShapeConstr( ifm_index, asTensorInfo(asTensorShape(_ctx.at(ifm_index).shape()), _ctx.at(ifm_index).type(), _ctx.at(ifm_index).scale(), _ctx.at(ifm_index).zeroPoint())); - _builder.addShapeConstr(axis_index, asTensorInfo(asTensorShape(_ctx.at(axis_index).shape()), - _ctx.at(axis_index).type())); + _builder.addShapeConstr(axis_index, + asTensorInfo(asTensorShape(_ctx.at(axis_index).shape()), + _ctx.at(axis_index).type(), _ctx.at(axis_index).scale(), + _ctx.at(axis_index).zeroPoint())); // TODO keep_dims==0 assert(keep_dims != 0); @@ -3286,23 +3298,37 @@ void Planner::visit(const ::internal::tflite::op::RNN::Node &node) num_units == _ctx.at(hidden_state_out_index).shape().dim(1)); // Set Shape Constraints and TensorInfo - _builder.addShapeConstr(output_index, asTensorInfo(asTensorShape(_ctx.at(output_index).shape()), - _ctx.at(output_index).type())); + _builder.addShapeConstr(output_index, + asTensorInfo(asTensorShape(_ctx.at(output_index).shape()), + _ctx.at(output_index).type(), _ctx.at(output_index).scale(), + _ctx.at(output_index).zeroPoint())); _builder.addShapeConstr(hidden_state_out_index, asTensorInfo(asTensorShape(_ctx.at(hidden_state_out_index).shape()), - _ctx.at(hidden_state_out_index).type())); - _builder.addShapeConstr(input_index, asTensorInfo(asTensorShape(_ctx.at(input_index).shape()), - _ctx.at(input_index).type())); + _ctx.at(hidden_state_out_index).type(), + _ctx.at(hidden_state_out_index).scale(), + _ctx.at(hidden_state_out_index).zeroPoint())); + _builder.addShapeConstr(input_index, + asTensorInfo(asTensorShape(_ctx.at(input_index).shape()), + _ctx.at(input_index).type(), _ctx.at(input_index).scale(), + _ctx.at(input_index).zeroPoint())); _builder.addShapeConstr(weights_index, asTensorInfo(asTensorShape(_ctx.at(weights_index).shape()), - _ctx.at(weights_index).type())); + _ctx.at(weights_index).type(), + _ctx.at(weights_index).scale(), + _ctx.at(weights_index).zeroPoint())); _builder.addShapeConstr(recurrent_weights_index, asTensorInfo(asTensorShape(_ctx.at(recurrent_weights_index).shape()), - _ctx.at(recurrent_weights_index).type())); - _builder.addShapeConstr(bias_index, asTensorInfo(asTensorShape(_ctx.at(bias_index).shape()), - _ctx.at(bias_index).type())); + _ctx.at(recurrent_weights_index).type(), + _ctx.at(recurrent_weights_index).scale(), + _ctx.at(recurrent_weights_index).zeroPoint())); + _builder.addShapeConstr(bias_index, + asTensorInfo(asTensorShape(_ctx.at(bias_index).shape()), + _ctx.at(bias_index).type(), _ctx.at(bias_index).scale(), + _ctx.at(bias_index).zeroPoint())); _builder.addShapeConstr(hidden_state_in_index, asTensorInfo(asTensorShape(_ctx.at(hidden_state_in_index).shape()), - _ctx.at(hidden_state_in_index).type())); + _ctx.at(hidden_state_in_index).type(), + _ctx.at(hidden_state_in_index).scale(), + _ctx.at(hidden_state_in_index).zeroPoint())); // Construct operation parameters struct Param @@ -3428,10 +3454,12 @@ void Planner::visit(const ::internal::tflite::op::Floor::Node &node) const ::internal::tflite::operand::Index ifm_index{node.param().input_index}; // Set shape constraints - _builder.addShapeConstr(ofm_index, asTensorInfo(asTensorShape(_ctx.at(ofm_index).shape()), - _ctx.at(ofm_index).type())); - _builder.addShapeConstr(ifm_index, asTensorInfo(asTensorShape(_ctx.at(ifm_index).shape()), - _ctx.at(ifm_index).type())); + _builder.addShapeConstr( + ofm_index, asTensorInfo(asTensorShape(_ctx.at(ofm_index).shape()), _ctx.at(ofm_index).type(), + _ctx.at(ofm_index).scale(), _ctx.at(ofm_index).zeroPoint())); + _builder.addShapeConstr( + ifm_index, asTensorInfo(asTensorShape(_ctx.at(ifm_index).shape()), _ctx.at(ifm_index).type(), + _ctx.at(ifm_index).scale(), _ctx.at(ifm_index).zeroPoint())); struct Param { @@ -3477,10 +3505,14 @@ void Planner::visit(const ::internal::tflite::op::RSQRT::Node &node) const ::internal::tflite::operand::Index input_index{node.param().input_index}; // Set shape constraints - _builder.addShapeConstr(output_index, asTensorInfo(asTensorShape(_ctx.at(output_index).shape()), - _ctx.at(output_index).type())); - _builder.addShapeConstr(input_index, asTensorInfo(asTensorShape(_ctx.at(input_index).shape()), - _ctx.at(input_index).type())); + _builder.addShapeConstr(output_index, + asTensorInfo(asTensorShape(_ctx.at(output_index).shape()), + _ctx.at(output_index).type(), _ctx.at(output_index).scale(), + _ctx.at(output_index).zeroPoint())); + _builder.addShapeConstr(input_index, + asTensorInfo(asTensorShape(_ctx.at(input_index).shape()), + _ctx.at(input_index).type(), _ctx.at(input_index).scale(), + _ctx.at(input_index).zeroPoint())); struct Param { @@ -4095,10 +4127,12 @@ void Planner::visit(const ::internal::tflite::op::L2Pool2D::Implicit::Node &node assert((ANEURALNETWORKS_PADDING_SAME == padding_type) || (ANEURALNETWORKS_PADDING_VALID == padding_type)); - _builder.addShapeConstr(ofm_index, asTensorInfo(asTensorShape(_ctx.at(ofm_index).shape()), - _ctx.at(ofm_index).type())); - _builder.addShapeConstr(ifm_index, asTensorInfo(asTensorShape(_ctx.at(ifm_index).shape()), - _ctx.at(ifm_index).type())); + _builder.addShapeConstr( + ofm_index, asTensorInfo(asTensorShape(_ctx.at(ofm_index).shape()), _ctx.at(ofm_index).type(), + _ctx.at(ofm_index).scale(), _ctx.at(ofm_index).zeroPoint())); + _builder.addShapeConstr( + ifm_index, asTensorInfo(asTensorShape(_ctx.at(ifm_index).shape()), _ctx.at(ifm_index).type(), + _ctx.at(ifm_index).scale(), _ctx.at(ifm_index).zeroPoint())); struct Param { @@ -4190,10 +4224,12 @@ void Planner::visit(const ::internal::tflite::op::L2Pool2D::Explicit::Node &node const int32_t padding_top = _ctx.at(padding_top_index).asScalar(); const int32_t padding_bottom = _ctx.at(padding_bottom_index).asScalar(); - _builder.addShapeConstr(ofm_index, asTensorInfo(asTensorShape(_ctx.at(ofm_index).shape()), - _ctx.at(ofm_index).type())); - _builder.addShapeConstr(ifm_index, asTensorInfo(asTensorShape(_ctx.at(ifm_index).shape()), - _ctx.at(ifm_index).type())); + _builder.addShapeConstr( + ofm_index, asTensorInfo(asTensorShape(_ctx.at(ofm_index).shape()), _ctx.at(ofm_index).type(), + _ctx.at(ofm_index).scale(), _ctx.at(ofm_index).zeroPoint())); + _builder.addShapeConstr( + ifm_index, asTensorInfo(asTensorShape(_ctx.at(ifm_index).shape()), _ctx.at(ifm_index).type(), + _ctx.at(ifm_index).scale(), _ctx.at(ifm_index).zeroPoint())); // Construct operation parameters struct Param @@ -4639,10 +4675,12 @@ void Planner::visit(const ::internal::tflite::op::Exp::Node &node) const ::internal::tflite::operand::Index ifm_index{node.param().ifm_index}; // Set shape constraints - _builder.addShapeConstr(ofm_index, asTensorInfo(asTensorShape(_ctx.at(ofm_index).shape()), - _ctx.at(ofm_index).type())); - _builder.addShapeConstr(ifm_index, asTensorInfo(asTensorShape(_ctx.at(ifm_index).shape()), - _ctx.at(ifm_index).type())); + _builder.addShapeConstr( + ofm_index, asTensorInfo(asTensorShape(_ctx.at(ofm_index).shape()), _ctx.at(ofm_index).type(), + _ctx.at(ofm_index).scale(), _ctx.at(ofm_index).zeroPoint())); + _builder.addShapeConstr( + ifm_index, asTensorInfo(asTensorShape(_ctx.at(ifm_index).shape()), _ctx.at(ifm_index).type(), + _ctx.at(ifm_index).scale(), _ctx.at(ifm_index).zeroPoint())); struct Param { @@ -4724,10 +4762,12 @@ void Planner::visit(const ::internal::tflite::op::ReduceSum::Node &node) } // Set shape constraints - _builder.addShapeConstr(ofm_index, asTensorInfo(asTensorShape(_ctx.at(ofm_index).shape()), - _ctx.at(ofm_index).type())); - _builder.addShapeConstr(ifm_index, asTensorInfo(asTensorShape(_ctx.at(ifm_index).shape()), - _ctx.at(ifm_index).type())); + _builder.addShapeConstr( + ofm_index, asTensorInfo(asTensorShape(_ctx.at(ofm_index).shape()), _ctx.at(ofm_index).type(), + _ctx.at(ofm_index).scale(), _ctx.at(ofm_index).zeroPoint())); + _builder.addShapeConstr( + ifm_index, asTensorInfo(asTensorShape(_ctx.at(ifm_index).shape()), _ctx.at(ifm_index).type(), + _ctx.at(ifm_index).scale(), _ctx.at(ifm_index).zeroPoint())); uint32_t input_rank = ifm_shape.rank(); std::vector axis; -- 2.7.4