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