diff options
author | Jeremy Johnson <jeremy.johnson@arm.com> | 2024-02-19 13:57:21 +0000 |
---|---|---|
committer | Eric Kunze <eric.kunze@arm.com> | 2024-02-26 16:20:32 +0000 |
commit | 08965d35f728d93d8b215753b4b270a422fe39c9 (patch) | |
tree | 41a520e5f83d3c5bfa9db559bfc500753ba95bb4 /reference_model/src/verify/verify_reduce_product.cc | |
parent | e4c89eb171272c1bc28c188aeb8363009674ba86 (diff) | |
download | reference_model-08965d35f728d93d8b215753b4b270a422fe39c9.tar.gz |
Verifier - change to output largest error deviance
Add general validateData function used by ABS_ERROR, ULP,
RELATIVE and REDUCE_PRODUCT to find and output largest deviance
from the error bounds.
Clean up naming inconsistencies bewteen verify modes.
Signed-off-by: Jeremy Johnson <jeremy.johnson@arm.com>
Change-Id: Ib903faf36f784cacae91edab61d8e489461a727c
Diffstat (limited to 'reference_model/src/verify/verify_reduce_product.cc')
-rw-r--r-- | reference_model/src/verify/verify_reduce_product.cc | 33 |
1 files changed, 10 insertions, 23 deletions
diff --git a/reference_model/src/verify/verify_reduce_product.cc b/reference_model/src/verify/verify_reduce_product.cc index 0e58892..a8aaa53 100644 --- a/reference_model/src/verify/verify_reduce_product.cc +++ b/reference_model/src/verify/verify_reduce_product.cc @@ -21,31 +21,15 @@ namespace TosaReference { - namespace { -template <typename OutDtype> -bool validateData(const double* ref, - const OutDtype* imp, - const std::vector<int32_t>& shape, - const ReduceProductVerifyInfo& cfg) +template <typename OutType> +double calcErrorBound(double referenceValue, double boundsValue, const void* cfgPtr) { - const size_t T = static_cast<size_t>(numElements(shape)); - TOSA_REF_REQUIRE(T > 0, "[RP] Invalid shape for reference tensor"); + const auto cfg = reinterpret_cast<const ReduceProductVerifyInfo*>(cfgPtr); + unused(boundsValue); - for (size_t i = 0; i < T; ++i) - { - double errBound = - std::abs(ref[i]) * (std::pow(1 + std::pow(2, -AccPrecision<OutDtype>::normal_frac - 1), cfg.n) - 1); - bool valid = tosaCheckFloatBound(imp[i], ref[i], errBound); - if (!valid) - { - auto pos = indexToPosition(i, shape); - WARNING("[Verifier][RP] Location %s", positionToString(pos).c_str()); - return false; - } - } - return true; + return std::abs(referenceValue) * (std::pow(1 + std::pow(2, -AccPrecision<OutType>::normal_frac - 1), cfg->n) - 1); } } // namespace @@ -62,17 +46,20 @@ bool verifyReduceProduct(const CTensor* referenceTensor, const double* refData = reinterpret_cast<const double*>(referenceTensor->data); TOSA_REF_REQUIRE(refData != nullptr, "[RP] Missing data for reference"); + const std::string modeStr = "RP"; + switch (implementationTensor->data_type) { case tosa_datatype_fp32_t: { const auto* impData = reinterpret_cast<const float*>(implementationTensor->data); TOSA_REF_REQUIRE(impData != nullptr, "[RP] Missing data for implementation"); - return validateData(refData, impData, refShape, rpInfo); + return validateData(refData, nullptr, impData, refShape, modeStr, &rpInfo, &calcErrorBound<float>); } case tosa_datatype_fp16_t: { const auto* impData = reinterpret_cast<const half_float::half*>(implementationTensor->data); TOSA_REF_REQUIRE(impData != nullptr, "[RP] Missing data for implementation"); - return validateData(refData, impData, refShape, rpInfo); + return validateData(refData, nullptr, impData, refShape, modeStr, &rpInfo, + &calcErrorBound<half_float::half>); } default: WARNING("[Verifier][RP] Data-type not supported."); |