1+ """ This module contains utility functions for operations on files, mostly JSON cache files """
2+
13import os
24import json
35import subprocess
68from importlib .metadata import requires , version , PackageNotFoundError
79from packaging .requirements import Requirement
810
9- from jsonschema import validate
10-
1111from kernel_tuner import util
1212
1313schema_dir = os .path .dirname (os .path .realpath (__file__ )) + "/schema"
@@ -45,6 +45,13 @@ def get_configuration_validity(objective) -> str:
4545 return errorstring
4646
4747
48+ def filename_ensure_json_extension (filename : str ) -> str :
49+ """ Check if the filename has a .json extension, if not, add it """
50+ if filename [- 5 :] != ".json" :
51+ filename += ".json"
52+ return filename
53+
54+
4855def store_output_file (output_filename , results , tune_params , objective = "time" ):
4956 """ Store the obtained auto-tuning results in a JSON output file
5057
@@ -63,8 +70,7 @@ def store_output_file(output_filename, results, tune_params, objective="time"):
6370 :type objective: string
6471
6572 """
66- if output_filename [- 5 :] != ".json" :
67- output_filename += ".json"
73+ output_filename = filename_ensure_json_extension (output_filename )
6874
6975 timing_keys = [
7076 "compile_time" , "benchmark_time" , "framework_time" , "strategy_time" ,
@@ -171,8 +177,7 @@ def store_metadata_file(metadata_filename, target="nvidia"):
171177 :type target: string
172178
173179 """
174- if metadata_filename [- 5 :] != ".json" :
175- metadata_filename += ".json"
180+ metadata_filename = filename_ensure_json_extension (metadata_filename )
176181 metadata = {}
177182
178183 # lshw only works on Linux, this intentionally raises a FileNotFoundError when ran on systems that do not have it
0 commit comments