From cf5866c2c6fc9a1231b75b4af008b37404b0fca1 Mon Sep 17 00:00:00 2001 From: Ben van Werkhoven Date: Sat, 27 Jan 2024 11:13:05 +0100 Subject: [PATCH] split read cache to reduce complexity --- kernel_tuner/util.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/kernel_tuner/util.py b/kernel_tuner/util.py index 19b29c0f1..6e9cdf5b0 100644 --- a/kernel_tuner/util.py +++ b/kernel_tuner/util.py @@ -1167,8 +1167,9 @@ def process_cache(cache, kernel_options, tuning_options, runner): tuning_options.cache = cached_data["cache"] -def read_cache(cache, open_cache=True): - """Read the cachefile into a dictionary, if open_cache=True prepare the cachefile for appending.""" +def correct_open_cache(cache, open_cache=True): + """ if cache file was not properly closed, pretend it was properly closed """ + with open(cache, "r") as cachefile: filestr = cachefile.read().strip() @@ -1185,6 +1186,13 @@ def read_cache(cache, open_cache=True): with open(cache, "w") as cachefile: cachefile.write(filestr[:-3] + ",") + return filestr + +def read_cache(cache, open_cache=True): + """Read the cachefile into a dictionary, if open_cache=True prepare the cachefile for appending.""" + + filestr = correct_open_cache(cache, open_cache) + error_configs = { "InvalidConfig": InvalidConfig(), "CompilationFailedConfig": CompilationFailedConfig(),