From f8fbf4f3e62c532e9f31fecbe4595e62e2b44bd6 Mon Sep 17 00:00:00 2001 From: Emil Ohlsson Date: Tue, 22 Apr 2025 11:06:57 +0200 Subject: [PATCH] Reduce noise from comparison This change bundles some cleanup done while doing FP16 IGEMM work. The main change is the reduced output from the comparison function, which instead of printing each differing value on a new line instead bundles them on a per matrix row, with some block description. Also, the output is only printed if there is a mismatch Signed-off-by: Emil Ohlsson --- test/common/compare.cpp | 41 ++++++++++++++++++++++++------ test/common/matmul_test_common.cpp | 6 +++++ test/common/matmul_test_common.hpp | 2 ++ test/reference/quantize.cpp | 4 +++ test/reference/reduce.hpp | 4 +-- 5 files changed, 47 insertions(+), 10 deletions(-) diff --git a/test/common/compare.cpp b/test/common/compare.cpp index b2c58fc1..29d96493 100644 --- a/test/common/compare.cpp +++ b/test/common/compare.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -50,13 +51,17 @@ template bool compare_raw( const void* imp_data, const void* ref_data, const DataFormat& format, size_t full_height, size_t full_width, const Rect& rect, MismatchHandler& handler) { - const auto block_height = format.actual_block_height(full_height); - const auto block_width = format.actual_block_width(full_width); - const auto subblock_height = format.actual_subblock_height(full_height); - const auto subblock_width = format.actual_subblock_width(full_width); + const size_t block_height = format.actual_block_height(full_height); + const size_t block_width = format.actual_block_width(full_width); + const size_t subblock_height = format.actual_subblock_height(full_height); + const size_t subblock_width = format.actual_subblock_width(full_width); size_t idx = 0; + bool block_heading_written = false; + bool subblock_heading_written = false; + bool row_heading_written = false; + std::ostringstream sstream; for (size_t y_block = 0; y_block < full_height; y_block += block_height) { for (size_t x_block = 0; x_block < full_width; x_block += block_width) { for (size_t y_subblock = 0; y_subblock < block_height; y_subblock += subblock_height) { @@ -76,21 +81,41 @@ bool compare_raw( const auto notifying = !in_roi || handler.handle_data(abs_err, rel_err); if (notifying) { - KAI_LOGE( - "Mismatched data at (", y, ", ", x, "): actual = ", imp_value, - ", expected: ", ref_value); + if (!block_heading_written) { + sstream << "block @ (" << y_block << ", " << x_block << "):\n"; + block_heading_written = true; + } + if (!subblock_heading_written) { + sstream << " sub-block @ (" << y_subblock << ", " << x_subblock << "):\n"; + subblock_heading_written = true; + } + if (!row_heading_written) { + sstream << " row=" << y_element << ": "; + row_heading_written = true; + } + sstream << x_element << ", "; } } ++idx; } + if (row_heading_written) { + sstream << "\n"; + } + row_heading_written = false; } + subblock_heading_written = false; } } + block_heading_written = false; } } - return handler.success(full_height * full_width); + const bool success = handler.success(full_height * full_width); + if (!success) { + KAI_LOGE("mismatches:\n", sstream.str()); + } + return success; } /// Compares matrices with per-row bias or per-row quantization. diff --git a/test/common/matmul_test_common.cpp b/test/common/matmul_test_common.cpp index 67b05d0b..91853dea 100644 --- a/test/common/matmul_test_common.cpp +++ b/test/common/matmul_test_common.cpp @@ -6,9 +6,15 @@ #include "matmul_test_common.hpp" +#include #include namespace kai::test { + +std::ostream& operator<<(std::ostream& os, const MatMulShape& shape) { + return os << "[m=" << shape.m << ", n=" << shape.n << ", k=" << shape.k << "]"; +} + void PrintTo(const MatMulTestParams& param, std::ostream* os) { const auto& [method, shape, portion] = param; diff --git a/test/common/matmul_test_common.hpp b/test/common/matmul_test_common.hpp index 3db8b811..030f1787 100644 --- a/test/common/matmul_test_common.hpp +++ b/test/common/matmul_test_common.hpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -39,6 +40,7 @@ private: lhs.n == rhs.n && // lhs.k == rhs.k; } + friend std::ostream& operator<<(std::ostream& os, const MatMulShape& shape); }; /// Value range diff --git a/test/reference/quantize.cpp b/test/reference/quantize.cpp index 025f677b..7a2fb198 100644 --- a/test/reference/quantize.cpp +++ b/test/reference/quantize.cpp @@ -84,6 +84,8 @@ std::vector compute_symmetric_per_block_quantization_info( static_assert(is_integral); static_assert(is_floating_point); + KAI_ASSUME(quant_width != 0); + const auto num_quant_packets_x = round_up_division(width, quant_width); const auto scales_bytes = height * num_quant_packets_x * sizeof(ScaleType); @@ -189,6 +191,8 @@ std::tuple, std::vector> compute_asymmetric_per_bl static_assert(is_floating_point); static_assert(is_integral); + KAI_ASSUME(quant_width != 0); + const auto num_quant_packets_x = round_up_division(width, quant_width); const auto scales_bytes = height * num_quant_packets_x * sizeof(ScaleType); diff --git a/test/reference/reduce.hpp b/test/reference/reduce.hpp index a3ccec7c..449dc57f 100644 --- a/test/reference/reduce.hpp +++ b/test/reference/reduce.hpp @@ -1,5 +1,5 @@ // -// SPDX-FileCopyrightText: Copyright 2024 Arm Limited and/or its affiliates +// SPDX-FileCopyrightText: Copyright 2024-2025 Arm Limited and/or its affiliates // // SPDX-License-Identifier: Apache-2.0 // @@ -25,7 +25,7 @@ enum class ReductionOperator : uint32_t { /// @param[in] src_format Input data format. /// @param[in] height Number of rows. /// @param[in] width Number of columns. -/// @param[in] dst_foramt Output data format. +/// @param[in] dst_format Output data format. /// @param[in] dimension Reduction dimension. /// /// @return The reduced matrix. -- GitLab