blob: 1a0c44cae74bee7e7df6ddaf2f959e310e7cc045 [file] [log] [blame]
Jack Franklandaafc8502023-09-13 11:03:50 +01001// Copyright (c) 2023, ARM Limited.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#include "func_debug.h"
16#include "verifiers.h"
17#include <cmath>
18
19namespace TosaReference
20{
21
22bool verifyExact(const CTensor* referenceTensor, const CTensor* implementationTensor)
23{
24 // Validate that tensors are provided
25 TOSA_REF_REQUIRE(referenceTensor != nullptr, "reference tensor is missing");
26 TOSA_REF_REQUIRE(implementationTensor != nullptr, "implementation tensor is missing");
27
28 // Get number of elements
29 const auto elementCount =
30 numElements(std::vector<int32_t>(referenceTensor->shape, referenceTensor->shape + referenceTensor->num_dims));
31 TOSA_REF_REQUIRE(elementCount > 0, "invalid shape for reference tensor");
32
33 switch (implementationTensor->data_type)
34 {
35 case tosa_datatype_fp32_t: {
36 const auto* refData = reinterpret_cast<const float*>(referenceTensor->data);
37 TOSA_REF_REQUIRE(refData != nullptr, "missing data for reference");
38 const auto* impData = reinterpret_cast<const float*>(implementationTensor->data);
39 TOSA_REF_REQUIRE(impData != nullptr, "missing data for implementation");
40 return std::equal(refData, std::next(refData, elementCount), impData, std::next(impData, elementCount),
41 [](const auto& referenceValue, const auto& implementationValue) {
42 return std::isnan(referenceValue) ? std::isnan(implementationValue)
43 : (referenceValue == implementationValue);
44 });
45 }
46 default:
Jeremy Johnsonbb0935f2023-09-14 16:43:48 +010047 WARNING("tosa verifier: data-type not supported.");
Jack Franklandaafc8502023-09-13 11:03:50 +010048 break;
49 }
50
51 return false;
52}
53} // namespace TosaReference