Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion kernel_tuner/strategies/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ def eval_all(self, xs, check_restrictions=True):
# get numerical return value, taking optimization direction into account
return_value = util.get_result_cost(result,
self.tuning_options.objective,
self.tuning_options.objective_higher_is_better
self.tuning_options.objective_higher_is_better,
self.invalid_return_value
)

if len(return_value) == 1:
Expand Down
4 changes: 2 additions & 2 deletions kernel_tuner/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ def default(self, obj):
return super(NpEncoder, self).default(obj)


def get_result_cost(result: dict, objectives: list[str], objective_higher_is_better: list[bool]) -> list[float]:
def get_result_cost(result: dict, objectives: list[str], objective_higher_is_better: list[bool], invalid_value) -> list[float]:
"""Returns the cost of a result, taking the objective directions into account."""
# return the highest cost for invalid results
if "__error__" in result:
return [sys.float_info.max] * len(objectives)
return [invalid_value] * len(objectives)

cost_vec = list()
for objective, is_maximizer in zip(objectives, objective_higher_is_better):
Expand Down
32 changes: 32 additions & 0 deletions test/strategies/test_dual_annealing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import numpy as np

import kernel_tuner



def test_dual_annealing_gives_warning(recwarn):
""" Uses pytest built-in fixture recwarn to record any warnings this code might throw. """

kernel_tuner.tune_kernel(
kernel_name="foo",
kernel_source="void foo(int) { }",
problem_size=1,
arguments=[np.int32(0)],
tune_params={"block_size_x": range(1, 8)},
strategy="dual_annealing",
restrictions="block_size_x < 4",
)

for warning in recwarn:
# Print the actual Warning object / message string
print(warning.message)

# Print the category (e.g., <class 'UserWarning'>)
print(warning.category)

# Print file and line where it was raised
print(f"Raised at {warning.filename}:{warning.lineno}")

# Test that no warnings are thrown
assert len(recwarn) == 0

Loading