blob: 0afd8044d5f4f315ece06858c7ede1deaaf6b17f [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
Jack Frankland12ee1a72023-09-20 09:08:34 +010067/// \brief reduce-product verification meta-data
68struct ReduceProductVerifyInfo
69{
70 ReduceProductVerifyInfo() = default;
71
72 int64_t m;
73 int64_t n;
74};
75
Georgios Pinitas7021ef02023-08-22 08:25:57 +010076/// \brief Verification meta-data
77struct VerifyConfig
78{
79 VerifyConfig() = default;
80
81 VerifyMode mode;
Jeremy Johnsonbb0935f2023-09-14 16:43:48 +010082 DType dataType;
Georgios Pinitas7021ef02023-08-22 08:25:57 +010083 UlpInfo ulpInfo;
84 DotProductVerifyInfo dotProductInfo;
Jack Frankland12ee1a72023-09-20 09:08:34 +010085 ReduceProductVerifyInfo reduceProductInfo;
Georgios Pinitas7021ef02023-08-22 08:25:57 +010086};
87
88/// \brief Parse the verification config for a tensor when given in JSON form
89std::optional<VerifyConfig> parseVerifyConfig(const char* tensorName, const char* configJson);
90
91/// \brief Extract number of total elements
92int64_t numElements(const std::vector<int32_t>& shape);
93
94/// \brief Map API data-type to DType
95DType mapToDType(tosa_datatype_t dataType);
96
97}; // namespace TosaReference
98
99#endif // VERIFY_UTILS_H_