Skip to content

Commit 0e4facc

Browse files
committed
Raise an exception if the time budget is exceeded before the actual tuning starts
1 parent 5c5ff1a commit 0e4facc

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

kernel_tuner/interface.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,9 +682,16 @@ def tune_kernel(
682682
if verbose:
683683
print(f"Searchspace has {searchspace.size} configurations after restrictions.")
684684

685-
# call the strategy to execute the tuning process
686-
tuning_options["start_time"] = perf_counter()
685+
# register the times and raise an exception if the budget is exceeded
687686
tuning_options["startup_time"] = perf_counter() - start_overhead_time
687+
if tuning_options["startup_time"] > tuning_options["time_limit"]:
688+
raise RuntimeError(
689+
f"The startup time of the tuning process ({tuning_options["startup_time"]} seconds) has exceeded the time limit ({tuning_options["time_limit"]} seconds). "
690+
"Please increase the time limit or decrease the size of the search space."
691+
)
692+
tuning_options["start_time"] = perf_counter()
693+
694+
# call the strategy to execute the tuning process
688695
results = strategy.tune(searchspace, runner, tuning_options)
689696
env = runner.get_environment(tuning_options)
690697

kernel_tuner/util.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,6 @@ def check_stop_criterion(to):
195195
if "max_fevals" in to and len(to.unique_results) >= to.max_fevals:
196196
raise StopCriterionReached("max_fevals reached")
197197
if "time_limit" in to and (((time.perf_counter() - to.start_time) + (to.simulated_time * 1e-3) + to.startup_time) > to.time_limit):
198-
if to.startup_time > to.time_limit:
199-
raise RuntimeError(f"Time budget of {to.time_limit} seconds was already exceeded during startup ({to.startup_time} seconds).")
200198
raise StopCriterionReached("time limit exceeded")
201199

202200

0 commit comments

Comments
 (0)