Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve code quality of cache file related functions #240

Merged
merged 1 commit into from
Jan 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions kernel_tuner/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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(),
Expand Down
Loading