aboutsummaryrefslogtreecommitdiff
path: root/reference_model/src/verify
diff options
context:
space:
mode:
authorJack Frankland <jack.frankland@arm.com>2023-09-13 11:03:50 +0100
committerEric Kunze <eric.kunze@arm.com>2023-09-28 18:28:07 +0000
commitaafc8508398180835781605dd9229d4a6087af1f (patch)
tree57a65c17c83ff1b4eb8d07446e3abd0537e4d947 /reference_model/src/verify
parentf0348ea4206a7e02497515ffb6d88546e0121cc7 (diff)
downloadreference_model-aafc8508398180835781605dd9229d4a6087af1f.tar.gz
feat: Add exact verifier
Add a verifier to check that tensor results match exactly. Add a unit test to check the behavior of this new verifier. Change-Id: I9b80a6d57640fec67c6be80a97b3af484aeb935e Signed-off-by: Jack Frankland <jack.frankland@arm.com>
Diffstat (limited to 'reference_model/src/verify')
-rw-r--r--reference_model/src/verify/verifiers.h8
-rw-r--r--reference_model/src/verify/verify_dot_product.cc9
-rw-r--r--reference_model/src/verify/verify_entry.cc4
-rw-r--r--reference_model/src/verify/verify_exact.cc53
-rw-r--r--reference_model/src/verify/verify_utils.h7
5 files changed, 71 insertions, 10 deletions
diff --git a/reference_model/src/verify/verifiers.h b/reference_model/src/verify/verifiers.h
index afd50bf..177eeaf 100644
--- a/reference_model/src/verify/verifiers.h
+++ b/reference_model/src/verify/verifiers.h
@@ -33,6 +33,14 @@ bool verifyDotProduct(const CTensor* ref,
const CTensor* imp,
const DotProductVerifyInfo& dpInfo);
+/// \brief Perform exact result verification
+///
+/// \param referenceTensor Reference tensor
+/// \param implementationTensor Implementation resulting tensor
+///
+/// \return True if compliant else false
+bool verifyExact(const CTensor* referenceTensor, const CTensor* implementationTensor);
+
}; // namespace TosaReference
#endif // VERIFIERS_H_
diff --git a/reference_model/src/verify/verify_dot_product.cc b/reference_model/src/verify/verify_dot_product.cc
index 0b05c92..a96befa 100644
--- a/reference_model/src/verify/verify_dot_product.cc
+++ b/reference_model/src/verify/verify_dot_product.cc
@@ -20,13 +20,6 @@
#include <optional>
#include <type_traits>
-#define TOSA_REF_REQUIRE(COND, MESSAGE) \
- if (!(COND)) \
- { \
- WARNING(MESSAGE); \
- return false; \
- }
-
namespace TosaReference
{
namespace
@@ -139,5 +132,3 @@ bool verifyDotProduct(const CTensor* ref, const CTensor* refBnd, const CTensor*
}
} // namespace TosaReference
-
-#undef TOSA_REF_REQUIRE \ No newline at end of file
diff --git a/reference_model/src/verify/verify_entry.cc b/reference_model/src/verify/verify_entry.cc
index 80ca916..1c48354 100644
--- a/reference_model/src/verify/verify_entry.cc
+++ b/reference_model/src/verify/verify_entry.cc
@@ -30,7 +30,9 @@ bool verify(const CTensor* ref, const CTensor* refBnd, const CTensor* imp, const
{
case VerifyMode::DotProduct: {
return verifyDotProduct(ref, refBnd, imp, cfg.dotProductInfo);
- break;
+ }
+ case VerifyMode::Exact: {
+ return verifyExact(ref, imp);
}
default: {
WARNING("unsupported verification mode.");
diff --git a/reference_model/src/verify/verify_exact.cc b/reference_model/src/verify/verify_exact.cc
new file mode 100644
index 0000000..7fde5bb
--- /dev/null
+++ b/reference_model/src/verify/verify_exact.cc
@@ -0,0 +1,53 @@
+// Copyright (c) 2023, ARM Limited.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "func_debug.h"
+#include "verifiers.h"
+#include <cmath>
+
+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");
+
+ // 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");
+
+ 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");
+ const auto* impData = reinterpret_cast<const float*>(implementationTensor->data);
+ TOSA_REF_REQUIRE(impData != nullptr, "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)
+ : (referenceValue == implementationValue);
+ });
+ }
+ default:
+ WARNING("data-type not supported.");
+ break;
+ }
+
+ return false;
+}
+} // namespace TosaReference
diff --git a/reference_model/src/verify/verify_utils.h b/reference_model/src/verify/verify_utils.h
index 6e51e3e..3a527da 100644
--- a/reference_model/src/verify/verify_utils.h
+++ b/reference_model/src/verify/verify_utils.h
@@ -23,6 +23,13 @@
#include <optional>
#include <vector>
+#define TOSA_REF_REQUIRE(COND, MESSAGE) \
+ if (!(COND)) \
+ { \
+ WARNING(MESSAGE); \
+ return false; \
+ }
+
namespace TosaReference
{