| 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 | #include <tuple> |
| 11 | |
| 12 | #include "test/common/buffer.hpp" |
| 13 | #include "test/common/data_type.hpp" |
| 14 | #include "test/common/span.hpp" |
| 15 | #include "test/nextgen/functions/round.hpp" |
| 16 | |
| 17 | namespace kai::test { |
| 18 | |
| 19 | /// Dynamically quantizes the data using per-block linear quantization. |
| 20 | /// |
| 21 | /// @param[in] height The height of data matrix. |
| 22 | /// @param[in] width The width of data matrix. |
| 23 | /// @param[in] block_height The height of quantization block. |
| 24 | /// @param[in] block_width The width of quantization block. |
| 25 | /// @param[in] fp_data The floating-point data. |
| 26 | /// @param[out] qdata The quantized data. |
| 27 | /// @param[out] qscale The quantization scale. |
| 28 | /// @param[out] qzp The quantization zero-point. |
| 29 | /// |
| 30 | /// @return The quantized data, scale and zero-point. |
| 31 | using DynamicQuantizeLinearFn = std::tuple<Buffer, Buffer, Buffer> (*)( |
| 32 | size_t height, size_t width, size_t block_height, size_t block_width, Span<const std::byte> fp_data); |
| 33 | |
| 34 | /// Creates a dynamic quantization function using per-block linear asymmetric quantization. |
| 35 | /// |
| 36 | /// @param[in] fp_dtype The data type of dequantized data. |
| 37 | /// @param[in] qdata_dtype The data type of quantized data. |
| 38 | /// @param[in] qscale_dtype The data type of quantization scale. |
| 39 | /// @param[in] qzp_dtype The data type of quantization zero-point. |
| 40 | /// @param[in] qdata_round_mode The rounding mode to calculate the quantized data. |
| 41 | /// @param[in] qzp_round_mode The rounding mode to calculate the quantization zero-point. |
| 42 | /// |
| 43 | /// @return The function pointer. |
| 44 | [[nodiscard]] DynamicQuantizeLinearFn make_dynamic_asymmetric_quantize_linear( |
| 45 | DataType fp_dtype, DataType qdata_dtype, DataType qscale_dtype, DataType qzp_dtype, RoundMode qdata_round_mode, |
| 46 | RoundMode qzp_round_mode); |
| 47 | |
| 48 | /// Creates a dynamic quantization function using per-block linear symmetric quantization. |
| 49 | /// |
| 50 | /// @param[in] fp_dtype The data type of dequantized data. |
| 51 | /// @param[in] qdata_dtype The data type of quantized data. |
| 52 | /// @param[in] qscale_dtype The data type of quantization scale. |
| 53 | /// @param[in] qdata_round_mode The rounding mode to calculate the quantized data. |
| 54 | /// |
| 55 | /// @return The function pointer. |
| 56 | [[nodiscard]] DynamicQuantizeLinearFn make_dynamic_symmetric_quantize_linear( |
| 57 | DataType fp_dtype, DataType qdata_dtype, DataType qscale_dtype, RoundMode qdata_round_mode); |
| 58 | |
| 59 | } // namespace kai::test |