Skip to content

Commit

Permalink
Added interface support for additional autotuning frameworks
Browse files Browse the repository at this point in the history
  • Loading branch information
fjwillemsen committed Apr 20, 2024
1 parent 4051e4a commit 7b90e9a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 11 deletions.
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"editor.formatOnType": true,
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": true,
"source.organizeImports": true,
"source.fixAll": "explicit",
"source.organizeImports": "explicit"
}
},
"black-formatter.args": [
Expand Down
7 changes: 7 additions & 0 deletions experiment_files/methodology_paper_evaluation.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"compare_split_times": false
},
"strategy_defaults": {
"tuner": "kerneltuner",
"repeats": 100,
"minimum_number_of_evaluations": 20,
"stochastic": true,
Expand Down Expand Up @@ -71,6 +72,12 @@
"name": "differential_evolution",
"strategy": "diff_evo",
"display_name": "Differential Evolution"
},
{
"name": "ktt_profile_searcher",
"tuner": "KTT",
"strategy": "profile_searcher",
"display_name": "KTT Profile Searcher"
}
]
}
2 changes: 2 additions & 0 deletions src/autotuning_methodology/caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def __init__(
folder_id: str,
kernel_name: str,
device_name: str,
tuner_name: str,
strategy_name: str,
strategy_display_name: str,
stochastic: bool,
Expand Down Expand Up @@ -61,6 +62,7 @@ def __init__(
self.__folder_id = folder_id
self.kernel_name = kernel_name
self.device_name = device_name
self.tuner_name = tuner_name
self.strategy_name = strategy_name
self.strategy_display_name = strategy_display_name
self.stochastic = stochastic
Expand Down
4 changes: 3 additions & 1 deletion src/autotuning_methodology/experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ def execute_experiment(filepath: str, profiling: bool = False) -> tuple[dict, di
print(f" | - optimizing kernel '{kernel_name}'")
results_descriptions[gpu_name][kernel_name] = dict()
for strategy in strategies:
tuner_name: str = strategy["tuner"]
strategy_name: str = strategy["name"]
strategy_display_name: str = strategy["display_name"]
stochastic = strategy["stochastic"]
Expand All @@ -197,6 +198,7 @@ def execute_experiment(filepath: str, profiling: bool = False) -> tuple[dict, di
experiment_folder_id,
kernel_name,
gpu_name,
tuner_name,
strategy_name,
strategy_display_name,
stochastic,
Expand All @@ -213,7 +215,7 @@ def execute_experiment(filepath: str, profiling: bool = False) -> tuple[dict, di
results_description = collect_results(kernel, strategy, results_description, profiling=profiling)

# set the results
results_descriptions[gpu_name][kernel_name][strategy_name] = results_description
results_descriptions[gpu_name][kernel_name][tuner_name][strategy_name] = results_description

return experiment, strategies, results_descriptions

Expand Down
27 changes: 19 additions & 8 deletions src/autotuning_methodology/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def get_results_and_metadata(


def tune(
kernel, kernel_name: str, device_name: str, strategy: dict, tune_options: dict, profiling: bool
kernel, kernel_name: str, device_name: str, tuner_name: str, strategy: dict, tune_options: dict, profiling: bool
) -> tuple[list, list, int]:
"""Tune a program using an optimization algorithm and collect the results.
Expand All @@ -124,9 +124,10 @@ def tune(
kernel: the program (kernel) to tune.
kernel_name: the name of the program to tune.
device_name: the device (GPU) to tune on.
tuner_name: the autotuning framework to use.
strategy: the optimization algorithm to optimize with.
tune_options: a special options dictionary passed along to Kernel Tuner.
profiling: whether profiling statistics must be collected.
tune_options: a special options dictionary passed along to the autotuning framework.
profiling: whether profiling statistics should be collected.
Raises:
ValueError: if tuning fails multiple times in a row.
Expand Down Expand Up @@ -171,13 +172,22 @@ def tune_with_BAT():
"""Interface to tune with the BAT benchmarking suite."""
# TODO integrate with BAT

def import_from_KTT():
"""Import the output files of KTT."""
raise NotImplementedError()

total_start_time = python_time.perf_counter()
warnings.simplefilter("ignore", UserWarning)
try:
metadata, results = tune_with_kerneltuner()
except ValueError:
print("Something went wrong, trying once more.")
metadata, results = tune_with_kerneltuner()
if tuner_name == "kerneltuner" or tuner_name is None:
try:
metadata, results = tune_with_kerneltuner()
except ValueError:
print("Something went wrong, trying once more.")
metadata, results = tune_with_kerneltuner()
elif tuner_name == "KTT":
metadata, results = import_from_KTT()
else:
raise ValueError(f"Invalid autotuning framework '{tuner_name}'")
warnings.simplefilter("default", UserWarning)
total_end_time = python_time.perf_counter()
total_time_ms = round((total_end_time - total_start_time) * 1000)
Expand Down Expand Up @@ -240,6 +250,7 @@ def report_multiple_attempts(rep: int, len_res: int, strategy_repeats: int):
kernel,
results_description.kernel_name,
results_description.device_name,
results_description.tuner_name,
strategy,
tune_options,
profiling,
Expand Down

0 comments on commit 7b90e9a

Please sign in to comment.