aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Johnson <jeremy.johnson@arm.com>2023-01-10 14:40:54 +0000
committerJeremy Johnson <jeremy.johnson@arm.com>2023-01-18 09:48:31 +0000
commitdf628d4e2191248387ec5397ca23d618320fc726 (patch)
tree9c450ac9736a8107caa1519c3d461b4e3113ac3e
parent9e94af8f10f0a21a117b3bc7ea42004844fdc3bb (diff)
downloadreference_model-df628d4e2191248387ec5397ca23d618320fc726.tar.gz
Update for RESCALE spec apply_add clarification
Signed-off-by: Jeremy Johnson <jeremy.johnson@arm.com> Change-Id: I6958904c2c8932e9fe03b3092672d62a06e96ee6
-rw-r--r--reference_model/src/ops/type_conversion.cc27
1 files changed, 21 insertions, 6 deletions
diff --git a/reference_model/src/ops/type_conversion.cc b/reference_model/src/ops/type_conversion.cc
index cb57340..f266675 100644
--- a/reference_model/src/ops/type_conversion.cc
+++ b/reference_model/src/ops/type_conversion.cc
@@ -159,8 +159,15 @@ int OpRescale<Rank, InDtype, OutDtype>::eval()
else
scaled = TosaReference::QuantUtil::apply_scale_16(input_zp_shifted, channel_multiplier,
channel_shift);
- scaled = scaled + output_zp;
- OutEigenType out_val = static_cast<OutEigenType>(scaled);
+ int64_t res_in_64 = static_cast<int64_t>(scaled) + output_zp;
+ int64_t i32_max_in_64 = static_cast<int64_t>(std::numeric_limits<int32_t>::max());
+ int64_t i32_min_in_64 = static_cast<int64_t>(std::numeric_limits<int32_t>::min());
+ if (res_in_64 > i32_max_in_64 || res_in_64 < i32_min_in_64)
+ {
+ std::string desc = "scaling result [" + std::to_string(scaled) + "] plus output_zp [" + std::to_string(output_zp) + "] not in i32 range";
+ throw desc;
+ }
+ OutEigenType out_val = static_cast<OutEigenType>(res_in_64);
out_val = std::max<OutEigenType>(out_val, QMin);
out_val = std::min<OutEigenType>(out_val, QMax);
return out_val;
@@ -174,7 +181,7 @@ int OpRescale<Rank, InDtype, OutDtype>::eval()
}
catch (std::string desc)
{
- REQUIRE(false, "OpRescale apply_scale_32/16() fails: %s.", desc.c_str());
+ REQUIRE(false, "OpRescale failure: %s.", desc.c_str());
}
}
else
@@ -193,8 +200,16 @@ int OpRescale<Rank, InDtype, OutDtype>::eval()
else
scaled =
TosaReference::QuantUtil::apply_scale_16(input_zp_shifted, tensor_multiplier, tensor_shift);
- scaled = scaled + output_zp;
- OutEigenType out_val = static_cast<OutEigenType>(scaled);
+ int64_t res_in_64 = static_cast<int64_t>(scaled) + output_zp;
+ int64_t i32_max_in_64 = static_cast<int64_t>(std::numeric_limits<int32_t>::max());
+ int64_t i32_min_in_64 = static_cast<int64_t>(std::numeric_limits<int32_t>::min());
+ if (res_in_64 > i32_max_in_64 || res_in_64 < i32_min_in_64)
+ {
+ std::string desc = "scaling result [" + std::to_string(scaled) + "] plus output_zp [" + std::to_string(output_zp) + "] not in i32 range";
+ throw desc;
+ }
+
+ OutEigenType out_val = static_cast<OutEigenType>(res_in_64);
out_val = std::max<OutEigenType>(out_val, QMin);
out_val = std::min<OutEigenType>(out_val, QMax);
return out_val;
@@ -202,7 +217,7 @@ int OpRescale<Rank, InDtype, OutDtype>::eval()
}
catch (std::string desc)
{
- REQUIRE(false, "OpRescale apply_scale_32/16() fails: %s.", desc.c_str());
+ REQUIRE(false, "OpRescale failure: %s.", desc.c_str());
}
}