Line |
Branch |
Exec |
Source |
1 |
|
|
// |
2 |
|
|
// SPDX-FileCopyrightText: Copyright 2024-2025 Arm Limited and/or its affiliates <open-source-office@arm.com> |
3 |
|
|
// |
4 |
|
|
// SPDX-License-Identifier: Apache-2.0 |
5 |
|
|
// |
6 |
|
|
|
7 |
|
|
#pragma once |
8 |
|
|
|
9 |
|
|
#include <cstddef> |
10 |
|
|
#include <cstdint> |
11 |
|
|
#include <functional> |
12 |
|
|
|
13 |
|
|
namespace kai::test { |
14 |
|
|
|
15 |
|
|
/// Data type. |
16 |
|
|
enum class DataType : uint16_t { |
17 |
|
|
// Encoding: |
18 |
|
|
// |
19 |
|
|
// 15 0 |
20 |
|
|
// +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ |
21 |
|
|
// | i | s | q | a | RES0 | bits | |
22 |
|
|
// +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ |
23 |
|
|
// |
24 |
|
|
// (RES0: reserved, filled with 0s) |
25 |
|
|
// |
26 |
|
|
// Fields: |
27 |
|
|
// |
28 |
|
|
// * i: integer (1) or floating-point (0). |
29 |
|
|
// * s: signed (1) or unsigned (0). |
30 |
|
|
// * q: |
31 |
|
|
// - Integer (i): quantized (1) or non-quantized (0). |
32 |
|
|
// - Floating-point (!i): brain (1) or binary (0). |
33 |
|
|
// * a: |
34 |
|
|
// - Quantized (i && q): asymmetric (1) or symmetric (0). |
35 |
|
|
// - Otherwise: RES0. |
36 |
|
|
// * bits: size in bits. |
37 |
|
|
|
38 |
|
|
UNKNOWN = 0, ///< No data. |
39 |
|
|
|
40 |
|
|
FP32 = 0b0'1'0'0'0000'00100000, ///< Single-precision floating-point. |
41 |
|
|
FP16 = 0b0'1'0'0'0000'00010000, ///< Half-precision floating-point. |
42 |
|
|
|
43 |
|
|
BF16 = 0b0'1'1'0'0000'00010000, ///< Half-precision brain floating-point. |
44 |
|
|
|
45 |
|
|
I32 = 0b1'1'0'0'0000'00100000, ///< 32-bit signed integer. |
46 |
|
|
|
47 |
|
|
QAI8 = 0b1'1'1'1'0000'00001000, ///< 8-bit signed asymmetric quantized. |
48 |
|
|
|
49 |
|
|
QSU4 = 0b1'0'1'0'0000'00000100, ///< 4-bit unsigned symmetric quantized. |
50 |
|
|
QSI4 = 0b1'1'1'0'0000'00000100, ///< 4-bit signed symmetric quantized. |
51 |
|
|
}; |
52 |
|
|
|
53 |
|
|
/// Gets the size in bits of the specified data type. |
54 |
|
|
/// |
55 |
|
|
/// @param[in] dt The data type. |
56 |
|
|
/// |
57 |
|
|
/// @return The size in bits. |
58 |
|
|
[[nodiscard]] size_t data_type_size_in_bits(DataType dt); |
59 |
|
|
|
60 |
|
|
/// Gets a value indicating whether the data type is integral. |
61 |
|
|
/// |
62 |
|
|
/// @param[in] dt The data type. |
63 |
|
|
/// |
64 |
|
|
/// @return `true` if the data type is integral. |
65 |
|
|
[[nodiscard]] bool data_type_is_integral(DataType dt); |
66 |
|
|
|
67 |
|
|
/// Gets a value indicating whether the data type is floating-point. |
68 |
|
|
/// |
69 |
|
|
/// @param[in] dt The data type. |
70 |
|
|
/// |
71 |
|
|
/// @return `true` if the data type is floating-point. |
72 |
|
|
[[nodiscard]] bool data_type_is_float(DataType dt); |
73 |
|
|
|
74 |
|
|
/// Gets a value indicating whether the data type is binary floating-point. |
75 |
|
|
/// |
76 |
|
|
/// Binary floating point are `half`, `float`, `double`. |
77 |
|
|
/// |
78 |
|
|
/// @param[in] dt The data type. |
79 |
|
|
/// |
80 |
|
|
/// @return `true` if the data type is binary floating-point. |
81 |
|
|
[[nodiscard]] bool data_type_is_float_fp(DataType dt); |
82 |
|
|
|
83 |
|
|
/// Gets a value indicating whether the data type is brain floating-point. |
84 |
|
|
/// |
85 |
|
|
/// Binary floating point are `bfloat16`. |
86 |
|
|
/// |
87 |
|
|
/// @param[in] dt The data type. |
88 |
|
|
/// |
89 |
|
|
/// @return `true` if the data type is brain floating-point. |
90 |
|
|
[[nodiscard]] bool data_type_is_float_bf(DataType dt); |
91 |
|
|
|
92 |
|
|
/// Gets a value indicating whether the data type is signed. |
93 |
|
|
/// |
94 |
|
|
/// @param[in] dt The data type. |
95 |
|
|
/// |
96 |
|
|
/// @return `true` if the data type is signed. |
97 |
|
|
[[nodiscard]] bool data_type_is_signed(DataType dt); |
98 |
|
|
|
99 |
|
|
/// Gets a value indicating whether the data type is quantized. |
100 |
|
|
/// |
101 |
|
|
/// @param[in] dt The data type. |
102 |
|
|
/// |
103 |
|
|
/// @return `true` if the data type is quantized. |
104 |
|
|
[[nodiscard]] bool data_type_is_quantized(DataType dt); |
105 |
|
|
|
106 |
|
|
/// Gets a value indicating whether the data type is asymmetric quantized. |
107 |
|
|
/// |
108 |
|
|
/// @param[in] dt The data type. |
109 |
|
|
/// |
110 |
|
|
/// @return `true` if the data type is asymmetric quantized. |
111 |
|
|
[[nodiscard]] bool data_type_is_quantized_asymm(DataType dt); |
112 |
|
|
|
113 |
|
|
} // namespace kai::test |
114 |
|
|
|
115 |
|
|
template <> |
116 |
|
|
struct std::hash<kai::test::DataType> { |
117 |
|
361251 |
size_t operator()(const kai::test::DataType& dt) const { |
118 |
|
|
using DT = std::underlying_type_t<kai::test::DataType>; |
119 |
|
361251 |
return std::hash<DT>{}(static_cast<DT>(dt)); |
120 |
|
|
} |
121 |
|
|
}; |
122 |
|
|
|