11 const std::string& outputName,
13 const std::vector<int32_t>& shape,
14 int32_t scale_multiplier,
20 TosaSerializationOperator** op,
21 TosaSerializationTensor** tensor)
28 std::vector<int32_t> multipliers{scale_multiplier};
29 std::vector<int32_t> shifts{scale_shift};
30 TosaRescaleAttribute attribute(input_zp,
39 *op =
new TosaSerializationOperator(Op_RESCALE, Attribute_RescaleAttribute, &attribute, {inputName}, {outputName});
42 throw armnn::Exception(
"CreateRescaleTosaOperator: failed to created operator");
44 if (tensor !=
nullptr)
47 *tensor =
new TosaSerializationTensor(outputName, shape, output_type, {});
50 throw armnn::Exception(
"CreateRescaleTosaOperator: failed to created tensor");
56 const std::string& outputName,
58 const std::vector<int32_t>& shape,
64 TosaSerializationOperator** op,
65 TosaSerializationTensor** tensor)
70 auto GetScaleParams = [](
double scale,
double& m, int32_t& n)
75 double lastErr = 1e06;
77 const int32_t numExponents = 62;
78 const double start = 1.0;
79 const double end = 2.0;
82 for (int32_t i = 0; i < numExponents; ++i)
84 double exp = 1.0 / (1 << i);
85 double currentM = scale / exp;
86 if ((currentM >= start) && (currentM < end))
88 double value = currentM * exp;
89 double err = std::abs(scale - value);
101 auto GetMultiplierShiftByScale = [GetScaleParams](
bool scale32,
double scale, int32_t& multiplier, int32_t& shift)
106 GetScaleParams(scale, m, n);
108 multiplier = (scale32) ? (1 << 30) *
static_cast<int32_t
>(m) : (1 << 14) *
static_cast<int32_t
>(m);
109 shift = (scale32) ? (30 + n) : (14 + n);
114 GetMultiplierShiftByScale(scale32, scale, multiplier, shift);
116 input_zp, output_zp, double_round, scale32, op, tensor);
120 const std::string& outputName,
122 const std::vector<int32_t>& shape,
125 TosaSerializationOperator** op,
126 TosaSerializationTensor** tensor)
129 output_scale, 0, output_zp,
true,
true, op, tensor);