From 08965d35f728d93d8b215753b4b270a422fe39c9 Mon Sep 17 00:00:00 2001 From: Jeremy Johnson Date: Mon, 19 Feb 2024 13:57:21 +0000 Subject: 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 Change-Id: Ib903faf36f784cacae91edab61d8e489461a727c --- reference_model/src/verify/verify_abs_error.cc | 61 +++++++++++--------------- 1 file changed, 26 insertions(+), 35 deletions(-) (limited to 'reference_model/src/verify/verify_abs_error.cc') diff --git a/reference_model/src/verify/verify_abs_error.cc b/reference_model/src/verify/verify_abs_error.cc index 5005dcf..a7b7bc2 100644 --- a/reference_model/src/verify/verify_abs_error.cc +++ b/reference_model/src/verify/verify_abs_error.cc @@ -26,59 +26,50 @@ namespace TosaReference namespace { -template -bool validateData(const double* ref, - const double* bnd, - const OutDtype* imp, - const std::vector& shape, - const AbsErrorVerifyInfo& cfg) +template +double calcErrorBound(double referenceValue, double boundsValue, const void* cfgPtr) { - const size_t T = static_cast(numElements(shape)); - TOSA_REF_REQUIRE(T > 0, "[AE] Invalid shape for reference tensor"); + const auto cfg = reinterpret_cast(cfgPtr); - for (size_t i = 0; i < T; ++i) + double valBound = std::abs(referenceValue) * boundsValue; + if (cfg->lowerBound > 0) { - double valBound = std::abs(ref[i]) * bnd[i]; - if (cfg.lowerBound > 0) - { - valBound = std::max(cfg.lowerBound, valBound); - } - double errBound = exp2(-AccPrecision::normal_frac) * valBound; - bool valid = tosaCheckFloatBound(imp[i], ref[i], errBound); - if (!valid) - { - auto pos = indexToPosition(i, shape); - WARNING("[Verifier][AE] Location %s", positionToString(pos).c_str()); - return false; - } + valBound = std::max(cfg->lowerBound, valBound); } - return true; + return exp2(-AccPrecision::normal_frac) * valBound; } } // namespace -bool verifyAbsError(const CTensor* ref, const CTensor* refBnd, const CTensor* imp, const AbsErrorVerifyInfo& aeInfo) + +bool verifyAbsError(const CTensor* referenceTensor, + const CTensor* boundsTensor, + const CTensor* implementationTensor, + const AbsErrorVerifyInfo& aeInfo) { // Validate that tensors are provided - TOSA_REF_REQUIRE(ref != nullptr, "[AE] Reference tensor is missing"); - TOSA_REF_REQUIRE(refBnd != nullptr, "[AE] Reference bounds tensor is missing"); - TOSA_REF_REQUIRE(imp != nullptr, "[AE] Implementation tensor is missing"); + TOSA_REF_REQUIRE(referenceTensor != nullptr, "[AE] Reference tensor is missing"); + TOSA_REF_REQUIRE(boundsTensor != nullptr, "[AE] Reference bounds tensor is missing"); + TOSA_REF_REQUIRE(implementationTensor != nullptr, "[AE] Implementation tensor is missing"); - const std::vector refShape(ref->shape, ref->shape + ref->num_dims); + const std::vector refShape(referenceTensor->shape, referenceTensor->shape + referenceTensor->num_dims); - const double* refData = reinterpret_cast(ref->data); - const double* refBndData = reinterpret_cast(refBnd->data); + const double* refData = reinterpret_cast(referenceTensor->data); + const double* refBndData = reinterpret_cast(boundsTensor->data); TOSA_REF_REQUIRE(refData != nullptr && refBndData != nullptr, "[AE] Missing data for reference or bounds tensors"); - switch (imp->data_type) + const std::string modeStr = "AE"; + + switch (implementationTensor->data_type) { case tosa_datatype_fp32_t: { - const auto* impData = reinterpret_cast(imp->data); + const auto* impData = reinterpret_cast(implementationTensor->data); TOSA_REF_REQUIRE(impData != nullptr, "[AE] Missing data for implementation"); - return validateData(refData, refBndData, impData, refShape, aeInfo); + return validateData(refData, refBndData, impData, refShape, modeStr, &aeInfo, &calcErrorBound); } case tosa_datatype_fp16_t: { - const auto* impData = reinterpret_cast(imp->data); + const auto* impData = reinterpret_cast(implementationTensor->data); TOSA_REF_REQUIRE(impData != nullptr, "[AE] Missing data for implementation"); - return validateData(refData, refBndData, impData, refShape, aeInfo); + return validateData(refData, refBndData, impData, refShape, modeStr, &aeInfo, + &calcErrorBound); } default: WARNING("[Verifier][AE] Data-type not supported."); -- cgit v1.2.1