blob: 5b98f5c1b1aacb8fdb14e77bc33220f4f6b20651 [file] [log] [blame]
Georgios Pinitas7021ef02023-08-22 08:25:57 +01001
2// Copyright (c) 2023, ARM Limited.
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16#ifndef VERIFY_UTILS_H_
17#define VERIFY_UTILS_H_
18
19#include "dtype.h"
20#include "types.h"
21
22#include <cstdint>
23#include <optional>
24#include <vector>
25
Jack Franklandaafc8502023-09-13 11:03:50 +010026#define TOSA_REF_REQUIRE(COND, MESSAGE) \
27 if (!(COND)) \
28 { \
Jeremy Johnsonbb0935f2023-09-14 16:43:48 +010029 WARNING("tosa verifier: " MESSAGE "."); \
Jack Franklandaafc8502023-09-13 11:03:50 +010030 return false; \
31 }
32
Georgios Pinitas7021ef02023-08-22 08:25:57 +010033namespace TosaReference
34{
35
36// Name alias
37using CTensor = tosa_tensor_t;
38
39/// \brief Supported verification modes
40enum class VerifyMode
41{
42 Exact,
43 Ulp,
44 DotProduct,
45 ReduceProduct,
Jeremy Johnsonbb0935f2023-09-14 16:43:48 +010046 FpSpecial,
47 Round
Georgios Pinitas7021ef02023-08-22 08:25:57 +010048};
49
50/// \brief ULP verification meta-data
51struct UlpInfo
52{
53 UlpInfo() = default;
54
Jack Frankland62737b12023-09-13 15:47:48 +010055 uint64_t ulp;
Georgios Pinitas7021ef02023-08-22 08:25:57 +010056};
57
58/// \brief Dot-product verification meta-data
59struct DotProductVerifyInfo
60{
61 DotProductVerifyInfo() = default;
62
Georgios Pinitas7021ef02023-08-22 08:25:57 +010063 int32_t s;
64 int32_t ks;
65};
66
67/// \brief Verification meta-data
68struct VerifyConfig
69{
70 VerifyConfig() = default;
71
72 VerifyMode mode;
Jeremy Johnsonbb0935f2023-09-14 16:43:48 +010073 DType dataType;
Georgios Pinitas7021ef02023-08-22 08:25:57 +010074 UlpInfo ulpInfo;
75 DotProductVerifyInfo dotProductInfo;
76};
77
78/// \brief Parse the verification config for a tensor when given in JSON form
79std::optional<VerifyConfig> parseVerifyConfig(const char* tensorName, const char* configJson);
80
81/// \brief Extract number of total elements
82int64_t numElements(const std::vector<int32_t>& shape);
83
84/// \brief Map API data-type to DType
85DType mapToDType(tosa_datatype_t dataType);
86
87}; // namespace TosaReference
88
89#endif // VERIFY_UTILS_H_