From 62f19373aebfe4473138949ae69b451fb886cdcc Mon Sep 17 00:00:00 2001 From: Luca Colagrande Date: Fri, 15 Sep 2023 17:27:20 +0200 Subject: [PATCH] util/sim: Log errors caught by IPC verification framework --- sw/blas/axpy/verify.py | 3 +++ util/sim/verification.py | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/sw/blas/axpy/verify.py b/sw/blas/axpy/verify.py index 02cb15975b..80b195ff9c 100755 --- a/sw/blas/axpy/verify.py +++ b/sw/blas/axpy/verify.py @@ -42,6 +42,9 @@ def main(): z_golden = golden_model(a, x, y) relative_err = np.absolute((z_golden - z_actual) / z_golden) fail = np.any(relative_err > ERR_THRESHOLD) + if (fail): + verification.dump_results_to_csv([z_golden, z_actual, relative_err], + Path.cwd() / 'axpy_results.csv') return int(fail) diff --git a/util/sim/verification.py b/util/sim/verification.py index 9878ef62ac..04594a51c3 100644 --- a/util/sim/verification.py +++ b/util/sim/verification.py @@ -7,6 +7,8 @@ import sys import argparse +import numpy as np +import csv from elf import Elf from pathlib import Path @@ -60,3 +62,19 @@ def simulate(sim_bin, snitch_bin, log, output_uids, symbols_bin=None): sim.finish(wait_for_sim=True) return raw_outputs + + +# Takes a set of Numpy arrays (of the same shape), flattens them, zips them +# and dumps them to a CSV file. Arrays may for example be: golden results, actual +# results, absolute errors and relative errors. +def dump_results_to_csv(results, path): + # Flatten and zip arrays + flattened = [arr.flatten() for arr in results] + zipped = np.column_stack(flattened) + # Write row-by-row to CSV file + with open(path, 'w') as csv_file: + csv_writer = csv.writer(csv_file) + for row in zipped: + csv_writer.writerow(row) + # Print path where results were written + print(f"Wrote results to {path}")