Georgios Pinitas | 7021ef0 | 2023-08-22 08:25:57 +0100 | [diff] [blame] | 1 | |
| 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 Frankland | aafc850 | 2023-09-13 11:03:50 +0100 | [diff] [blame] | 26 | #define TOSA_REF_REQUIRE(COND, MESSAGE) \ |
| 27 | if (!(COND)) \ |
| 28 | { \ |
Jeremy Johnson | bb0935f | 2023-09-14 16:43:48 +0100 | [diff] [blame^] | 29 | WARNING("tosa verifier: " MESSAGE "."); \ |
Jack Frankland | aafc850 | 2023-09-13 11:03:50 +0100 | [diff] [blame] | 30 | return false; \ |
| 31 | } |
| 32 | |
Georgios Pinitas | 7021ef0 | 2023-08-22 08:25:57 +0100 | [diff] [blame] | 33 | namespace TosaReference |
| 34 | { |
| 35 | |
| 36 | // Name alias |
| 37 | using CTensor = tosa_tensor_t; |
| 38 | |
| 39 | /// \brief Supported verification modes |
| 40 | enum class VerifyMode |
| 41 | { |
| 42 | Exact, |
| 43 | Ulp, |
| 44 | DotProduct, |
| 45 | ReduceProduct, |
Jeremy Johnson | bb0935f | 2023-09-14 16:43:48 +0100 | [diff] [blame^] | 46 | FpSpecial, |
| 47 | Round |
Georgios Pinitas | 7021ef0 | 2023-08-22 08:25:57 +0100 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | /// \brief ULP verification meta-data |
| 51 | struct UlpInfo |
| 52 | { |
| 53 | UlpInfo() = default; |
| 54 | |
Jack Frankland | 62737b1 | 2023-09-13 15:47:48 +0100 | [diff] [blame] | 55 | uint64_t ulp; |
Georgios Pinitas | 7021ef0 | 2023-08-22 08:25:57 +0100 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | /// \brief Dot-product verification meta-data |
| 59 | struct DotProductVerifyInfo |
| 60 | { |
| 61 | DotProductVerifyInfo() = default; |
| 62 | |
Georgios Pinitas | 7021ef0 | 2023-08-22 08:25:57 +0100 | [diff] [blame] | 63 | int32_t s; |
| 64 | int32_t ks; |
| 65 | }; |
| 66 | |
| 67 | /// \brief Verification meta-data |
| 68 | struct VerifyConfig |
| 69 | { |
| 70 | VerifyConfig() = default; |
| 71 | |
| 72 | VerifyMode mode; |
Jeremy Johnson | bb0935f | 2023-09-14 16:43:48 +0100 | [diff] [blame^] | 73 | DType dataType; |
Georgios Pinitas | 7021ef0 | 2023-08-22 08:25:57 +0100 | [diff] [blame] | 74 | UlpInfo ulpInfo; |
| 75 | DotProductVerifyInfo dotProductInfo; |
| 76 | }; |
| 77 | |
| 78 | /// \brief Parse the verification config for a tensor when given in JSON form |
| 79 | std::optional<VerifyConfig> parseVerifyConfig(const char* tensorName, const char* configJson); |
| 80 | |
| 81 | /// \brief Extract number of total elements |
| 82 | int64_t numElements(const std::vector<int32_t>& shape); |
| 83 | |
| 84 | /// \brief Map API data-type to DType |
| 85 | DType mapToDType(tosa_datatype_t dataType); |
| 86 | |
| 87 | }; // namespace TosaReference |
| 88 | |
| 89 | #endif // VERIFY_UTILS_H_ |