KleidiAI Coverage Report


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

test/nextgen/quantization/asymm_linear_quantizer.cpp
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 #include "test/nextgen/quantization/asymm_linear_quantizer.hpp"
8
9 #include <array>
10 #include <cstddef>
11 #include <utility>
12
13 #include "test/common/assert.hpp"
14 #include "test/common/buffer.hpp"
15 #include "test/common/data_type.hpp"
16 #include "test/common/round.hpp"
17 #include "test/common/span.hpp"
18 #include "test/nextgen/common/poly.hpp"
19 #include "test/nextgen/format/plain_format.hpp"
20 #include "test/nextgen/harness/tensor.hpp"
21 #include "test/nextgen/reference/dequantize.hpp"
22 #include "test/nextgen/reference/quantize.hpp"
23
24 namespace kai::test {
25
26 200 void AsymmLinearQuantizer::dynamic_quantize(
27 DataType fp_dtype, Span<const size_t> shape, Span<const std::byte> fp_data, Tensor& qdata, Tensor& qscale,
28 Tensor& qzp) const {
29
1/4
✓ Branch 0 taken 200 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
200 KAI_TEST_ASSERT_MSG(shape.size() == 2, "Only 2D quantization is supported.");
30
31 200 const size_t height = shape.at(0);
32 200 const size_t width = shape.at(1);
33
34
1/2
✓ Branch 0 taken 200 times.
✗ Branch 1 not taken.
200 const size_t block_height = m_block_height != 0 ? m_block_height : height;
35
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 200 times.
200 const size_t block_width = m_block_width != 0 ? m_block_width : width;
36
37 200 const size_t quant_height = round_up_division(height, block_height);
38 200 const size_t quant_width = round_up_division(width, block_width);
39 200 const std::array quant_shape{quant_height, quant_width};
40
41 400 const DynamicQuantizeLinearFn quantize_fn = make_dynamic_asymmetric_quantize_linear(
42 200 fp_dtype, m_qdata_dtype, m_qscale_dtype, m_qzp_dtype, m_qdata_round_mode, m_qzp_round_mode);
43 800 auto [qdata_buffer, qscale_buffer, qzp_buffer] = quantize_fn(height, width, block_height, block_width, fp_data);
44
45
5/10
✓ Branch 0 taken 200 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 200 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 200 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 200 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 200 times.
✗ Branch 9 not taken.
200 qdata.set_shape(shape).set_format(make_poly<PlainFormat>(m_qdata_dtype)).set_data(std::move(qdata_buffer));
46
5/10
✓ Branch 0 taken 200 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 200 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 200 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 200 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 200 times.
✗ Branch 9 not taken.
200 qscale.set_shape(quant_shape).set_format(make_poly<PlainFormat>(m_qscale_dtype)).set_data(std::move(qscale_buffer));
47
5/10
✓ Branch 0 taken 200 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 200 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 200 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 200 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 200 times.
✗ Branch 9 not taken.
200 qzp.set_shape(quant_shape).set_format(make_poly<PlainFormat>(m_qzp_dtype)).set_data(std::move(qzp_buffer));
48 200 }
49
50 200 Buffer AsymmLinearQuantizer::dequantize(
51 DataType fp_dtype, Span<const size_t> shape, Span<const std::byte> qdata, Span<const std::byte> qscale,
52 Span<const std::byte> qzp) const {
53
1/4
✓ Branch 0 taken 200 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
200 KAI_TEST_ASSERT_MSG(shape.size() == 2, "Only 2D quantization is supported.");
54
55 200 const size_t height = shape.at(0);
56 200 const size_t width = shape.at(1);
57
58
1/2
✓ Branch 0 taken 200 times.
✗ Branch 1 not taken.
200 const size_t block_height = m_block_height != 0 ? m_block_height : height;
59
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 200 times.
200 const size_t block_width = m_block_width != 0 ? m_block_width : width;
60
61 200 const DequantizeLinearFn fn = make_dequantize_linear(fp_dtype, m_qdata_dtype, m_qscale_dtype, m_qzp_dtype);
62 200 Buffer fp_data = fn(height, width, block_height, block_width, qdata, qscale, qzp);
63
64 200 return fp_data;
65 200 }
66
67 } // namespace kai::test
68