Skip to content

Commit 5ec2d60

Browse files
committed
Merge remote-tracking branch 'origin/hyperparametertuning_custom_strategies' into constrained_optimization_tunable
2 parents 27226a9 + 3c293a1 commit 5ec2d60

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

kernel_tuner/interface.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,9 @@ def tune_kernel_T1(
910910
adjusted_strategy_options = {k:v for k, v in strategy_options.items() if k not in filter_keys}
911911
optimizer_instance = optimizer_class(**adjusted_strategy_options)
912912
strategy = OptAlgWrapper(optimizer_instance)
913+
if "constraint_aware" not in strategy_options and hasattr(optimizer_instance, "constraint_aware"):
914+
# if the optimizer has a constraint_aware attribute, set it in the strategy options
915+
strategy_options["constraint_aware"] = optimizer_instance.constraint_aware
913916

914917
# set the cache path
915918
if cache_filepath is None and "SimulationInput" in kernelspec:

kernel_tuner/runners/simulation.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33
from collections import namedtuple
44
from time import perf_counter
5+
from warnings import warn
56

67
from kernel_tuner import util
78
from kernel_tuner.runners.runner import Runner
@@ -127,8 +128,26 @@ def run(self, parameter_space, tuning_options):
127128
results.append(result)
128129
continue
129130

130-
# if the element is not in the cache, raise an error
131-
check = util.check_restrictions(tuning_options.restrictions, dict(zip(tuning_options['tune_params'].keys(), element)), True)
131+
# if the configuration is not in the cache and not within restrictions, simulate an InvalidConfig with warning
132+
params_dict = dict(zip(tuning_options['tune_params'].keys(), element))
133+
check = util.check_restrictions(tuning_options.restrictions, params_dict, True)
134+
if not check:
135+
result = params_dict
136+
result['compile_time'] = 0
137+
result['verification_time'] = 0
138+
result['benchmark_time'] = 0
139+
result['strategy_time'] = self.last_strategy_time
140+
141+
total_time = 1000 * (perf_counter() - self.start_time)
142+
self.start_time = perf_counter()
143+
result['framework_time'] = total_time - self.last_strategy_time
144+
145+
result[tuning_options.objective] = util.InvalidConfig()
146+
results.append(result)
147+
warn(f"Configuration {element} not in cache, does not pass restrictions. Will be treated as an InvalidConfig, but make sure you are evaluating the correct cache file.")
148+
continue
149+
150+
# if the configuration is not in the cache and passes restrictions, return a ValueError
132151
err_string = f"kernel configuration {element} not in cache, does {'' if check else 'not '}pass extra restriction check ({check})"
133152
logging.debug(err_string)
134153
raise ValueError(f"{err_string} - in simulation mode, all configurations must be present in the cache")

kernel_tuner/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def check_stop_criterion(to: dict) -> float:
201201
StopCriterionReached: if the max_fevals is reached or time limit is exceeded.
202202
203203
Returns:
204-
float: fraction of budget spent.
204+
float: fraction of budget spent. If both max_fevals and time_limit are set, it returns the fraction of time.
205205
"""
206206
if "max_fevals" in to:
207207
if len(to.unique_results) >= to.max_fevals:

0 commit comments

Comments
 (0)