diff options
author | Jeremy Johnson <jeremy.johnson@arm.com> | 2023-10-24 14:45:12 +0100 |
---|---|---|
committer | Eric Kunze <eric.kunze@arm.com> | 2023-10-25 17:47:09 +0000 |
commit | fc5e34e41afc07ea5ed03e3c5d4b5be92bef7fd7 (patch) | |
tree | cbb2556e96ddf1e53dff888e54e76586f46e00fc /reference_model/src/verify | |
parent | fd8c8fe887d49223b4d4c66d38e79d6e4c648fef (diff) | |
download | reference_model-fc5e34e41afc07ea5ed03e3c5d4b5be92bef7fd7.tar.gz |
Improve verfiy and generate library validation
Improved libraries validation to catch unknown values.
Improved verify output to match generate library.
Refactored generate tests to use less code duplication.
Signed-off-by: Jeremy Johnson <jeremy.johnson@arm.com>
Change-Id: I9c38745fbc8e70f46c19ddae6c62ee248d33b5f1
Diffstat (limited to 'reference_model/src/verify')
-rw-r--r-- | reference_model/src/verify/verify_dot_product.cc | 18 | ||||
-rw-r--r-- | reference_model/src/verify/verify_entry.cc | 17 | ||||
-rw-r--r-- | reference_model/src/verify/verify_exact.cc | 12 | ||||
-rw-r--r-- | reference_model/src/verify/verify_reduce_product.cc | 12 | ||||
-rw-r--r-- | reference_model/src/verify/verify_ulp.cc | 12 | ||||
-rw-r--r-- | reference_model/src/verify/verify_utils.cc | 15 | ||||
-rw-r--r-- | reference_model/src/verify/verify_utils.h | 3 |
7 files changed, 50 insertions, 39 deletions
diff --git a/reference_model/src/verify/verify_dot_product.cc b/reference_model/src/verify/verify_dot_product.cc index 39895b1..2a1d273 100644 --- a/reference_model/src/verify/verify_dot_product.cc +++ b/reference_model/src/verify/verify_dot_product.cc @@ -82,7 +82,7 @@ bool validateData(const double* ref, const double* bnd, const AccType* imp, size for (size_t i = 0; i < T; ++i) { auto out_err = validateElement<AccType>(ref[i], bnd[i], imp[i], KS); - TOSA_REF_REQUIRE(out_err, "data required to be zero or error within range"); + TOSA_REF_REQUIRE(out_err, "[DP] Data required to be zero or error within range"); out_err_sum += out_err.value(); out_err_sumsq += out_err.value() * out_err.value(); } @@ -90,10 +90,10 @@ bool validateData(const double* ref, const double* bnd, const AccType* imp, size if (S >= 3 && S <= 5) { // Check error bias magnitude for data sets S which are not positive biased - TOSA_REF_REQUIRE(std::abs(out_err_sum) <= 2 * sqrt(KS * T), "bias magnitude is out of range"); + TOSA_REF_REQUIRE(std::abs(out_err_sum) <= 2 * sqrt(KS * T), "[DP] Bias magnitude is out of range"); } // Check error variance magnitude - TOSA_REF_REQUIRE(out_err_sumsq <= 0.4 * KS * T, "error variance magnitude is out of range"); + TOSA_REF_REQUIRE(out_err_sumsq <= 0.4 * KS * T, "[DP] Error variance magnitude is out of range"); return true; } } // namespace @@ -101,9 +101,9 @@ bool validateData(const double* ref, const double* bnd, const AccType* imp, size bool verifyDotProduct(const CTensor* ref, const CTensor* refBnd, const CTensor* imp, const DotProductVerifyInfo& dpInfo) { // Validate that tensors are provided - TOSA_REF_REQUIRE(ref != nullptr, "reference tensor is missing"); - TOSA_REF_REQUIRE(refBnd != nullptr, "reference bounds tensor is missing"); - TOSA_REF_REQUIRE(imp != nullptr, "implementation tensor is missing"); + TOSA_REF_REQUIRE(ref != nullptr, "[DP] Reference tensor is missing"); + TOSA_REF_REQUIRE(refBnd != nullptr, "[DP] Reference bounds tensor is missing"); + TOSA_REF_REQUIRE(imp != nullptr, "[DP] Implementation tensor is missing"); // Get number of dot-product elements const int64_t T = numElements(std::vector<int32_t>(ref->shape, ref->shape + ref->num_dims)); @@ -111,18 +111,18 @@ bool verifyDotProduct(const CTensor* ref, const CTensor* refBnd, const CTensor* const double* refData = reinterpret_cast<const double*>(ref->data); const double* refBndData = reinterpret_cast<const double*>(refBnd->data); - TOSA_REF_REQUIRE(refData != nullptr && refBndData != nullptr, "missing data for reference or bounds tensors"); + TOSA_REF_REQUIRE(refData != nullptr && refBndData != nullptr, "[DP] Missing data for reference or bounds tensors"); switch (imp->data_type) { case tosa_datatype_fp32_t: { const float* impData = reinterpret_cast<const float*>(imp->data); - TOSA_REF_REQUIRE(impData != nullptr, "missing data for implementation"); + TOSA_REF_REQUIRE(impData != nullptr, "[DP] Missing data for implementation"); return validateData(refData, refBndData, impData, static_cast<size_t>(T), dpInfo); break; } default: { - WARNING("tosa verifier: data-type not supported."); + WARNING("[Verifier][DP] Data-type not supported."); break; } } diff --git a/reference_model/src/verify/verify_entry.cc b/reference_model/src/verify/verify_entry.cc index 1ddd52b..67eb7df 100644 --- a/reference_model/src/verify/verify_entry.cc +++ b/reference_model/src/verify/verify_entry.cc @@ -41,7 +41,7 @@ bool verify(const CTensor* ref, const CTensor* refBnd, const CTensor* imp, const return verifyULP(ref, imp, cfg.ulpInfo.ulp); } default: { - WARNING("tosa verifier: unsupported verification mode."); + WARNING("[Verifier] Unsupported verification mode."); break; } } @@ -60,37 +60,36 @@ extern "C" // Check inputs for nullptr if (!ref || !imp || !config_json) { - WARNING("tosa verifier: one of the inputs is missing."); + WARNING("[Verifier] One of the inputs is missing."); return false; } // Extract verification config if (!ref->name) { - WARNING("tosa verifier: tensor name is not specified."); + WARNING("[Verifier] Tensor name is not specified."); return false; } auto cfg = TosaReference::parseVerifyConfig(ref->name, config_json); if (!cfg) { - WARNING("tosa verifier: invalid json config."); return false; } // Validate shape if (ref->num_dims != imp->num_dims) { - WARNING("tosa verifier: tensors have different number of dimensions."); + WARNING("[Verifier] Tensors have different number of dimensions."); return false; } if (!ref->shape || !imp->shape) { - WARNING("tosa verifier: one of tensors' shape is missing."); + WARNING("[Verifier] One of tensors' shape is missing."); return false; } if (std::vector(ref->shape, ref->shape + ref->num_dims) != std::vector(imp->shape, imp->shape + imp->num_dims)) { - WARNING("tosa verifier: tensors have different shapes."); + WARNING("[Verifier] Tensors have different shapes."); return false; } @@ -99,7 +98,7 @@ extern "C" { if (cfg->dataType != TosaReference::mapToDType(imp->data_type)) { - WARNING("tosa verifier: incorrect tensor data type."); + WARNING("[Verifier] Incorrect tensor data type."); return false; } } @@ -107,7 +106,7 @@ extern "C" { if (ref->data_type != imp->data_type) { - WARNING("tosa verifier: tensors have different data types."); + WARNING("[Verifier] Tensors have different data types."); return false; } } diff --git a/reference_model/src/verify/verify_exact.cc b/reference_model/src/verify/verify_exact.cc index 1a0c44c..4d6c72f 100644 --- a/reference_model/src/verify/verify_exact.cc +++ b/reference_model/src/verify/verify_exact.cc @@ -22,21 +22,21 @@ namespace TosaReference bool verifyExact(const CTensor* referenceTensor, const CTensor* implementationTensor) { // Validate that tensors are provided - TOSA_REF_REQUIRE(referenceTensor != nullptr, "reference tensor is missing"); - TOSA_REF_REQUIRE(implementationTensor != nullptr, "implementation tensor is missing"); + TOSA_REF_REQUIRE(referenceTensor != nullptr, "[E] Reference tensor is missing"); + TOSA_REF_REQUIRE(implementationTensor != nullptr, "[E] 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, "invalid shape for reference tensor"); + TOSA_REF_REQUIRE(elementCount > 0, "[E] Invalid shape for reference tensor"); switch (implementationTensor->data_type) { case tosa_datatype_fp32_t: { const auto* refData = reinterpret_cast<const float*>(referenceTensor->data); - TOSA_REF_REQUIRE(refData != nullptr, "missing data for reference"); + TOSA_REF_REQUIRE(refData != nullptr, "[E] Missing data for reference"); const auto* impData = reinterpret_cast<const float*>(implementationTensor->data); - TOSA_REF_REQUIRE(impData != nullptr, "missing data for implementation"); + TOSA_REF_REQUIRE(impData != nullptr, "[E] Missing data for implementation"); return std::equal(refData, std::next(refData, elementCount), impData, std::next(impData, elementCount), [](const auto& referenceValue, const auto& implementationValue) { return std::isnan(referenceValue) ? std::isnan(implementationValue) @@ -44,7 +44,7 @@ bool verifyExact(const CTensor* referenceTensor, const CTensor* implementationTe }); } default: - WARNING("tosa verifier: data-type not supported."); + WARNING("[Verifier][E] Data-type not supported."); break; } diff --git a/reference_model/src/verify/verify_reduce_product.cc b/reference_model/src/verify/verify_reduce_product.cc index d233b0f..625e2cf 100644 --- a/reference_model/src/verify/verify_reduce_product.cc +++ b/reference_model/src/verify/verify_reduce_product.cc @@ -40,22 +40,22 @@ namespace TosaReference bool verifyReduceProduct(const CTensor* referenceTensor, const CTensor* implementationTensor, uint64_t m, uint64_t n) { // Validate that tensors are provided - TOSA_REF_REQUIRE(referenceTensor != nullptr, "reference tensor is missing"); - TOSA_REF_REQUIRE(implementationTensor != nullptr, "implementation tensor is missing"); + 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, "invalid shape for reference tensor"); + TOSA_REF_REQUIRE(elementCount > 0, "[RP] Invalid shape for reference tensor"); switch (implementationTensor->data_type) { case tosa_datatype_fp32_t: { const auto* refData = reinterpret_cast<const float*>(referenceTensor->data); - TOSA_REF_REQUIRE(refData != nullptr, "missing data for reference"); + TOSA_REF_REQUIRE(refData != nullptr, "[RP] Missing data for reference"); const auto* impData = reinterpret_cast<const float*>(implementationTensor->data); - TOSA_REF_REQUIRE(impData != nullptr, "missing data for implementation"); + 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) { @@ -79,7 +79,7 @@ bool verifyReduceProduct(const CTensor* referenceTensor, const CTensor* implemen }); } default: - WARNING("tosa verifier: data-type not supported."); + WARNING("[Verifier][RP] Data-type not supported."); break; } diff --git a/reference_model/src/verify/verify_ulp.cc b/reference_model/src/verify/verify_ulp.cc index 223bc48..486c0ff 100644 --- a/reference_model/src/verify/verify_ulp.cc +++ b/reference_model/src/verify/verify_ulp.cc @@ -124,28 +124,28 @@ bool tosaCheckULP(float testValue, double referenceValue, int64_t ulpCount) bool verifyULP(const CTensor* referenceTensor, const CTensor* implementationTensor, uint64_t ulp) { // Validate that tensors are provided - TOSA_REF_REQUIRE(referenceTensor != nullptr, "reference tensor is missing"); - TOSA_REF_REQUIRE(implementationTensor != nullptr, "implementation tensor is missing"); + TOSA_REF_REQUIRE(referenceTensor != nullptr, "[ULP] Reference tensor is missing"); + TOSA_REF_REQUIRE(implementationTensor != nullptr, "[ULP] 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, "invalid shape for reference tensor"); + TOSA_REF_REQUIRE(elementCount > 0, "[ULP] Invalid shape for reference tensor"); switch (implementationTensor->data_type) { case tosa_datatype_fp32_t: { const auto* refData = reinterpret_cast<const float*>(referenceTensor->data); - TOSA_REF_REQUIRE(refData != nullptr, "missing data for reference"); + TOSA_REF_REQUIRE(refData != nullptr, "[ULP] Missing data for reference"); const auto* impData = reinterpret_cast<const float*>(implementationTensor->data); - TOSA_REF_REQUIRE(impData != nullptr, "missing data for implementation"); + TOSA_REF_REQUIRE(impData != nullptr, "[ULP] Missing data for implementation"); return std::equal(refData, std::next(refData, elementCount), impData, std::next(impData, elementCount), [ulp](const auto& referenceValue, const auto& implementationValue) { return tosaCheckULP(referenceValue, implementationValue, ulp); }); } default: - WARNING("tosa verifier: data-type not supported."); + WARNING("[Verifier][ULP] Data-type not supported."); break; } diff --git a/reference_model/src/verify/verify_utils.cc b/reference_model/src/verify/verify_utils.cc index 366238b..ee11c41 100644 --- a/reference_model/src/verify/verify_utils.cc +++ b/reference_model/src/verify/verify_utils.cc @@ -25,6 +25,7 @@ namespace tosa NLOHMANN_JSON_SERIALIZE_ENUM(DType, { + { DType::DType_UNKNOWN, "UNKNOWN" }, { DType::DType_BOOL, "BOOL" }, { DType::DType_INT4, "INT4" }, { DType::DType_INT8, "INT8" }, @@ -43,6 +44,7 @@ namespace TosaReference NLOHMANN_JSON_SERIALIZE_ENUM(VerifyMode, { + { VerifyMode::Unknown, "UNKNOWN" }, { VerifyMode::Exact, "EXACT" }, { VerifyMode::Ulp, "ULP" }, { VerifyMode::DotProduct, "DOT_PRODUCT" }, @@ -94,14 +96,23 @@ std::optional<VerifyConfig> parseVerifyConfig(const char* tensorName, const char auto jsonCfg = nlohmann::json::parse(json, nullptr, /* allow exceptions */ false); if (jsonCfg.is_discarded()) + { + WARNING("[Verifier] Invalid json config."); return std::nullopt; + } if (!jsonCfg.contains("tensors")) + { + WARNING("[Verifier] Missing tensors in json config."); return std::nullopt; + } const auto& tensors = jsonCfg["tensors"]; if (!tensors.contains(tensorName)) - return std::nullopt; - + if (!tensors.contains(tensorName)) + { + WARNING("[Verifier] Missing tensor %s in json config.", tensorName); + return std::nullopt; + } const auto& namedTensor = tensors[tensorName]; return namedTensor.get<VerifyConfig>(); } diff --git a/reference_model/src/verify/verify_utils.h b/reference_model/src/verify/verify_utils.h index 0afd804..bbe4b4e 100644 --- a/reference_model/src/verify/verify_utils.h +++ b/reference_model/src/verify/verify_utils.h @@ -26,7 +26,7 @@ #define TOSA_REF_REQUIRE(COND, MESSAGE) \ if (!(COND)) \ { \ - WARNING("tosa verifier: " MESSAGE "."); \ + WARNING("[Verifier]" MESSAGE "."); \ return false; \ } @@ -39,6 +39,7 @@ using CTensor = tosa_tensor_t; /// \brief Supported verification modes enum class VerifyMode { + Unknown, Exact, Ulp, DotProduct, |