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 --- .../src/verify/verify_reduce_product.cc | 33 +++++++--------------- 1 file changed, 10 insertions(+), 23 deletions(-) (limited to 'reference_model/src/verify/verify_reduce_product.cc') 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 -bool validateData(const double* ref, - const OutDtype* imp, - const std::vector& shape, - const ReduceProductVerifyInfo& cfg) +template +double calcErrorBound(double referenceValue, double boundsValue, const void* cfgPtr) { - const size_t T = static_cast(numElements(shape)); - TOSA_REF_REQUIRE(T > 0, "[RP] Invalid shape for reference tensor"); + const auto cfg = reinterpret_cast(cfgPtr); + unused(boundsValue); - for (size_t i = 0; i < T; ++i) - { - double errBound = - std::abs(ref[i]) * (std::pow(1 + std::pow(2, -AccPrecision::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::normal_frac - 1), cfg->n) - 1); } } // namespace @@ -62,17 +46,20 @@ bool verifyReduceProduct(const CTensor* referenceTensor, const double* refData = reinterpret_cast(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(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); } case tosa_datatype_fp16_t: { const auto* impData = reinterpret_cast(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); } default: WARNING("[Verifier][RP] Data-type not supported."); -- cgit v1.2.1