diff options
author | Jeremy Johnson <jeremy.johnson@arm.com> | 2024-01-03 17:07:44 +0000 |
---|---|---|
committer | Eric Kunze <eric.kunze@arm.com> | 2024-01-08 21:40:41 +0000 |
commit | bd801960c958db85ae4092d1350ffbd383c3f77c (patch) | |
tree | e3fa9e3d2a817b75a4c13b663b46e776a3c766e0 /reference_model/src/verify | |
parent | d80ea5e11e5f92e0f7c08afeba74cb7d1719987b (diff) | |
download | reference_model-bd801960c958db85ae4092d1350ffbd383c3f77c.tar.gz |
Main Compliance: REDUCE_PRODUCT support
Update and fix REDUCE_PRODUCT compliance verify lib support.
Added compliance test generation with data range to not cause infs.
Signed-off-by: Jeremy Johnson <jeremy.johnson@arm.com>
Change-Id: I3b3004c6caa80d97e330a6393f435f5270b56e21
Diffstat (limited to 'reference_model/src/verify')
-rw-r--r-- | reference_model/src/verify/verifiers.h | 7 | ||||
-rw-r--r-- | reference_model/src/verify/verify_entry.cc | 2 | ||||
-rw-r--r-- | reference_model/src/verify/verify_reduce_product.cc | 78 | ||||
-rw-r--r-- | reference_model/src/verify/verify_utils.cc | 1 |
4 files changed, 42 insertions, 46 deletions
diff --git a/reference_model/src/verify/verifiers.h b/reference_model/src/verify/verifiers.h index 152cd6a..6830115 100644 --- a/reference_model/src/verify/verifiers.h +++ b/reference_model/src/verify/verifiers.h @@ -45,11 +45,12 @@ bool verifyExact(const CTensor* referenceTensor, const CTensor* implementationTe /// /// \param referenceTensor Reference tensor /// \param implementationTensor Implementation resulting tensor -/// \param m Number of manisa bits in the floating point representation -/// \param n Number of elements in the product +/// \param rpInfo Reduce-product verification meta-data /// /// \return True if compliant else false -bool verifyReduceProduct(const CTensor* referenceTensor, const CTensor* implementationTensor, uint64_t m, uint64_t n); +bool verifyReduceProduct(const CTensor* referenceTensor, + const CTensor* implementationTensor, + const ReduceProductVerifyInfo& rpInfo); /// \brief Perform ULP result verification /// diff --git a/reference_model/src/verify/verify_entry.cc b/reference_model/src/verify/verify_entry.cc index 2b318d1..afc5916 100644 --- a/reference_model/src/verify/verify_entry.cc +++ b/reference_model/src/verify/verify_entry.cc @@ -35,7 +35,7 @@ bool verify(const CTensor* ref, const CTensor* refBnd, const CTensor* imp, const return verifyExact(ref, imp); } case VerifyMode::ReduceProduct: { - return verifyReduceProduct(ref, imp, cfg.reduceProductInfo.m, cfg.reduceProductInfo.n); + return verifyReduceProduct(ref, imp, cfg.reduceProductInfo); } case VerifyMode::Ulp: { return verifyULP(ref, imp, cfg.ulpInfo); diff --git a/reference_model/src/verify/verify_reduce_product.cc b/reference_model/src/verify/verify_reduce_product.cc index 625e2cf..5306ef7 100644 --- a/reference_model/src/verify/verify_reduce_product.cc +++ b/reference_model/src/verify/verify_reduce_product.cc @@ -1,5 +1,5 @@ -// Copyright (c) 2023, ARM Limited. +// Copyright (c) 2023-2024, ARM Limited. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -19,64 +19,60 @@ #include "verifiers.h" #include "verify/verify_utils.h" -namespace +namespace TosaReference { -auto calculateError(uint64_t M, uint64_t N) +namespace { - return std::pow(1 + std::pow(2, -static_cast<int64_t>(M) - 1), N) - 1; -} - -template <typename FP> -auto calculateTolerance(uint64_t M, uint64_t N, FP value) +template <typename OutDtype> +bool validateData(const double* ref, + const OutDtype* imp, + const std::vector<int32_t>& shape, + const ReduceProductVerifyInfo& cfg) { - return std::abs(value) * calculateError(M, N); + const size_t T = static_cast<size_t>(numElements(shape)); + TOSA_REF_REQUIRE(T > 0, "[RP] Invalid shape for reference tensor"); + + 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(T, shape); + WARNING("[Verifier][RP] Location %s", positionToString(pos).c_str()); + return false; + } + } + return true; } } // namespace -namespace TosaReference -{ - -bool verifyReduceProduct(const CTensor* referenceTensor, const CTensor* implementationTensor, uint64_t m, uint64_t n) +bool verifyReduceProduct(const CTensor* referenceTensor, + const CTensor* implementationTensor, + const ReduceProductVerifyInfo& rpInfo) { // Validate that tensors are provided TOSA_REF_REQUIRE(referenceTensor != nullptr, "[RP] Reference tensor is missing"); TOSA_REF_REQUIRE(implementationTensor != nullptr, "[RP] Implementation tensor is missing"); - // Get number of elements - const auto elementCount = - numElements(std::vector<int32_t>(referenceTensor->shape, referenceTensor->shape + referenceTensor->num_dims)); - TOSA_REF_REQUIRE(elementCount > 0, "[RP] Invalid shape for reference tensor"); + const std::vector<int32_t> refShape(referenceTensor->shape, referenceTensor->shape + referenceTensor->num_dims); + + const double* refData = reinterpret_cast<const double*>(referenceTensor->data); + TOSA_REF_REQUIRE(refData != nullptr, "[RP] Missing data for reference"); switch (implementationTensor->data_type) { case tosa_datatype_fp32_t: { - const auto* refData = reinterpret_cast<const float*>(referenceTensor->data); - TOSA_REF_REQUIRE(refData != nullptr, "[RP] Missing data for reference"); - const auto* impData = reinterpret_cast<const float*>(implementationTensor->data); TOSA_REF_REQUIRE(impData != nullptr, "[RP] Missing data for implementation"); - - return std::equal(refData, std::next(refData, elementCount), impData, std::next(impData, elementCount), - [m, n](const auto& referenceValue, const auto& implementationValue) { - // Result overflows must be set to zero of the correct sign. - if (std::isinf(implementationValue)) - { - return implementationValue == referenceValue; - } - - // Result underflows must be set to a zero of the correct sign. - if (implementationValue == 0.f || implementationValue == -0.f) - { - return implementationValue == referenceValue; - } - - // Otherwise we are in the normal range. - const auto absoulteError = (referenceValue < implementationValue) - ? implementationValue - referenceValue - : referenceValue - implementationValue; - return absoulteError <= calculateTolerance(m, n, implementationValue); - }); + return validateData(refData, impData, refShape, rpInfo); + } + 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); } default: WARNING("[Verifier][RP] Data-type not supported."); diff --git a/reference_model/src/verify/verify_utils.cc b/reference_model/src/verify/verify_utils.cc index 5ce646c..6f53c63 100644 --- a/reference_model/src/verify/verify_utils.cc +++ b/reference_model/src/verify/verify_utils.cc @@ -66,7 +66,6 @@ void from_json(const nlohmann::json& j, DotProductVerifyInfo& dotProductInfo) void from_json(const nlohmann::json& j, ReduceProductVerifyInfo& reduceProduceInfo) { - j.at("m").get_to(reduceProduceInfo.m); j.at("n").get_to(reduceProduceInfo.n); } |