Go to the source code of this file.
|
void | CreateRescaleTosaOperator (const std::string &inputName, const std::string &outputName, DType output_type, const std::vector< int32_t > &shape, int32_t scale_multiplier, int32_t scale_shift, int32_t input_zp, int32_t output_zp, bool double_round, bool scale32, TosaSerializationOperator **op, TosaSerializationTensor **tensor) |
|
void | CreateRescaleTosaOperator (const std::string &inputName, const std::string &outputName, DType output_type, const std::vector< int32_t > &shape, double scale, int32_t input_zp, int32_t output_zp, bool double_round, bool scale32, TosaSerializationOperator **op, TosaSerializationTensor **tensor) |
|
void | CreateFromInt32RescaleTosaOperator (const std::string &inputName, const std::string &outputName, DType output_type, const std::vector< int32_t > &shape, double output_scale, int32_t output_zp, TosaSerializationOperator **op, TosaSerializationTensor **tensor) |
|
◆ CreateFromInt32RescaleTosaOperator()
void CreateFromInt32RescaleTosaOperator |
( |
const std::string & |
inputName, |
|
|
const std::string & |
outputName, |
|
|
DType |
output_type, |
|
|
const std::vector< int32_t > & |
shape, |
|
|
double |
output_scale, |
|
|
int32_t |
output_zp, |
|
|
TosaSerializationOperator ** |
op, |
|
|
TosaSerializationTensor ** |
tensor |
|
) |
| |
|
inline |
◆ CreateRescaleTosaOperator() [1/2]
void CreateRescaleTosaOperator |
( |
const std::string & |
inputName, |
|
|
const std::string & |
outputName, |
|
|
DType |
output_type, |
|
|
const std::vector< int32_t > & |
shape, |
|
|
double |
scale, |
|
|
int32_t |
input_zp, |
|
|
int32_t |
output_zp, |
|
|
bool |
double_round, |
|
|
bool |
scale32, |
|
|
TosaSerializationOperator ** |
op, |
|
|
TosaSerializationTensor ** |
tensor |
|
) |
| |
|
inline |
Definition at line 55 of file TosaRescaleOperatorUtils.hpp.
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);
References CreateRescaleTosaOperator().
◆ CreateRescaleTosaOperator() [2/2]
void CreateRescaleTosaOperator |
( |
const std::string & |
inputName, |
|
|
const std::string & |
outputName, |
|
|
DType |
output_type, |
|
|
const std::vector< int32_t > & |
shape, |
|
|
int32_t |
scale_multiplier, |
|
|
int32_t |
scale_shift, |
|
|
int32_t |
input_zp, |
|
|
int32_t |
output_zp, |
|
|
bool |
double_round, |
|
|
bool |
scale32, |
|
|
TosaSerializationOperator ** |
op, |
|
|
TosaSerializationTensor ** |
tensor |
|
) |
| |
|
inline |
Definition at line 10 of file TosaRescaleOperatorUtils.hpp.
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");
Referenced by CreateFromInt32RescaleTosaOperator(), and CreateRescaleTosaOperator().