| 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 | |
| 11 | #include "test/common/buffer.hpp" |
| 12 | #include "test/common/data_type.hpp" |
| 13 | #include "test/nextgen/functions/round.hpp" |
| 14 | #include "test/nextgen/harness/tensor.hpp" |
| 15 | #include "test/nextgen/quantization/quantizer.hpp" |
| 16 | |
| 17 | namespace kai::test { |
| 18 | |
| 19 | /// Symmetric linear quantizer. |
| 20 | class SymmLinearQuantizer : public Quantizer { |
| 21 | public: |
| 22 | /// Creates a new symmetric linear quantizer. |
| 23 | /// |
| 24 | /// @param[in] qdata_dtype The quantized data type. |
| 25 | /// @param[in] qscale_dtype The quantization scale data type. |
| 26 | /// @param[in] qdata_round_mode The rounding mode to calculate quantized data. |
| 27 | /// @param[in] block_height The quantization block height (0 if it's full height). |
| 28 | /// @param[in] block_width The quantization block width (0 if it's full width). |
| 29 | SymmLinearQuantizer( |
| 30 | DataType qdata_dtype, DataType qscale_dtype, RoundMode qdata_round_mode, size_t block_height, |
| 31 | size_t block_width) : |
| 32 | m_qdata_dtype(qdata_dtype), |
| 33 | m_qscale_dtype(qscale_dtype), |
| 34 | m_qdata_round_mode(qdata_round_mode), |
| 35 | m_block_height(block_height), |
| 36 | m_block_width(block_width) { |
| 37 | } |
| 38 | |
| 39 | void dynamic_quantize( |
| 40 | DataType fp_dtype, Shape shape, Span<const std::byte> fp_data, Tensor& qdata, Tensor& qscale, |
| 41 | Tensor& qzp) const override; |
| 42 | [[nodiscard]] Buffer dequantize( |
| 43 | DataType fp_dtype, Shape shape, Span<const std::byte> qdata, Span<const std::byte> qscale, |
| 44 | Span<const std::byte> qzp) const override; |
| 45 | [[nodiscard]] std::string uid() const override; |
| 46 | |
| 47 | private: |
| 48 | DataType m_qdata_dtype; |
| 49 | DataType m_qscale_dtype; |
| 50 | |
| 51 | RoundMode m_qdata_round_mode; |
| 52 | |
| 53 | size_t m_block_height; |
| 54 | size_t m_block_width; |
| 55 | }; |
| 56 | |
| 57 | } // namespace kai::test |