KleidiAI Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 2 / 0 / 2
Functions: 100.0% 2 / 0 / 2
Branches: -% 0 / 0 / 0

test/nextgen/quantization/quantizer.hpp
Line Branch Exec Source
1 //
2 // SPDX-FileCopyrightText: Copyright 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
11 #include "test/common/buffer.hpp"
12 #include "test/common/data_type.hpp"
13 #include "test/common/span.hpp"
14 #include "test/nextgen/harness/tensor.hpp"
15
16 namespace kai::test {
17
18 /// Quantizes floating-point data to lower-precision data types.
19 class Quantizer {
20 public:
21 24 Quantizer() = default; ///< Default constructor.
22 24 virtual ~Quantizer() = default; ///< Destructor.
23 Quantizer(const Quantizer&) = delete; ///< No copy constructor.
24 Quantizer& operator=(const Quantizer&) = delete; ///< No copy assignment.
25 Quantizer(Quantizer&&) = default; ///< Move constructor.
26 Quantizer& operator=(Quantizer&&) = default; ///< Move assignment.
27
28 /// Dynamically quantizes the data.
29 ///
30 /// This method determines the quantization information automatically from the input data.
31 ///
32 /// @param[in] fp_dtype The floating-point data type.
33 /// @param[in] shape The size of multidimensional array.
34 /// @param[in] fp_data The floating-point data buffer.
35 /// @param[out] qdata The quantized data.
36 /// @param[out] qscale The quantization scale.
37 /// @param[out] qzp The quantization zero-point.
38 virtual void dynamic_quantize(
39 DataType fp_dtype, Span<const size_t> shape, Span<const std::byte> fp_data, Tensor& qdata, Tensor& qscale,
40 Tensor& qzp) const = 0;
41
42 /// Dequantizes the data.
43 ///
44 /// @param[in] fp_dtype The dequantized data type.
45 /// @param[in] shape The size of multidimensional array.
46 /// @param[in] qdata The quantized data.
47 /// @param[in] qscale The quantization scale.
48 /// @param[in] qzp The quantization zero-point.
49 ///
50 /// @return The dequantized data.
51 [[nodiscard]] virtual Buffer dequantize(
52 DataType fp_dtype, Span<const size_t> shape, Span<const std::byte> qdata, Span<const std::byte> qscale,
53 Span<const std::byte> qzp) const = 0;
54 };
55
56 } // namespace kai::test
57