Skip to content

Commit

Permalink
Added total time collection for imported KTT runs, moved special 'tun…
Browse files Browse the repository at this point in the history
…er' keyto strategy to avoid invalidating caches
  • Loading branch information
fjwillemsen committed Apr 23, 2024
1 parent bb801c1 commit 4c869df
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 28 deletions.
2 changes: 0 additions & 2 deletions src/autotuning_methodology/caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ 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 @@ -62,7 +61,6 @@ 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: 1 addition & 3 deletions src/autotuning_methodology/experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ 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 @@ -198,7 +197,6 @@ 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 @@ -215,7 +213,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][tuner_name][strategy_name] = results_description
results_descriptions[gpu_name][kernel_name][strategy_name] = results_description

return experiment, strategies, results_descriptions

Expand Down
45 changes: 22 additions & 23 deletions src/autotuning_methodology/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ def tune(
kernel,
kernel_name: str,
device_name: str,
tuner_name: str,
strategy: dict,
tune_options: dict,
profiling: bool,
Expand All @@ -137,7 +136,6 @@ 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 the autotuning framework.
profiling: whether profiling statistics should be collected.
Expand Down Expand Up @@ -189,7 +187,7 @@ def import_from_KTT():
"""Import a KTT output file."""
# import the file
assert import_runs_path.exists() and import_runs_path.is_dir()
expected_filename = f"f~'ktt'k~'{kernel_name}'s~'{strategy}'r~{run_number}"
expected_filename = f"t~'ktt'k~'{kernel_name}'s~'{strategy['strategy']}'r~{run_number}.json"
matching_runs: list[dict] = list()
for file in import_runs_path.iterdir():
if file.name == expected_filename:
Expand Down Expand Up @@ -217,8 +215,13 @@ def import_from_KTT():
results = list()
run_metadata: dict = run["Metadata"]
run_results: list[dict] = run["Results"]
timeunit = timeunit_mapping[run_metadata["TimeUnit"].lower()]
timeunit = timeunit_mapping[str(run_metadata["TimeUnit"]).lower()]
total_time_ms = 0
for config_attempt in run_results:
# add to total time
total_duration = config_attempt.get("TotalDuration", 0)
total_overhead = config_attempt.get("TotalOverhead", 0)
total_time_ms += total_duration + total_overhead

# convert the times data
times_runtimes = []
Expand All @@ -230,10 +233,8 @@ def import_from_KTT():
times_search_algorithm = config_attempt.get("SearcherOverhead", 0)
times_validation = config_attempt.get("ValidationOverhead", 0)
times_framework = config_attempt.get("DataMovementOverhead", 0)
times_benchmark = config_attempt.get("TotalDuration", 0)
times_compilation = (
config_attempt.get("TotalOverhead", 0) - times_search_algorithm - times_validation - times_framework
)
times_benchmark = total_duration
times_compilation = total_overhead - times_search_algorithm - times_validation - times_framework

# convert the configuration data
configuration = dict()
Expand All @@ -243,7 +244,7 @@ def import_from_KTT():
# assemble the converted data
converted = {
"configuration": configuration,
"invalidity": status_mapping[config_attempt["Status"]],
"invalidity": status_mapping[str(config_attempt["Status"]).lower()],
"correctness": 1,
"measurements": [
{
Expand All @@ -263,25 +264,24 @@ def import_from_KTT():
},
}
results.append(converted)

# print(strategy)
return metadata, results

total_start_time = python_time.perf_counter()
warnings.simplefilter("ignore", UserWarning)
if tuner_name.lower() == "kerneltuner" or tuner_name is None:
return metadata, results, round(total_time_ms)

strategy_name = str(strategy["name"]).lower()
if strategy_name.startswith("ktt_"):
metadata, results, total_time_ms = import_from_KTT()
elif strategy_name.startswith("kerneltuner_") or True:
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()
elif tuner_name.lower() == "ktt":
metadata, results = import_from_KTT()
warnings.simplefilter("default", UserWarning)
total_end_time = python_time.perf_counter()
total_time_ms = round((total_end_time - total_start_time) * 1000)
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)
raise ValueError(f"Invalid autotuning framework '{strategy_name}'")
# be careful not to rely on total_time_ms when profiling, because it will include profiling time
return metadata, results, total_time_ms

Expand Down Expand Up @@ -342,7 +342,6 @@ 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 4c869df

Please sign in to comment.