Skip to content
Open
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
45 changes: 25 additions & 20 deletions kernel_tuner/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,23 +721,19 @@ def tune_kernel(
logging.debug("device_options: %s", util.get_config_string(device_options))

# check whether the selected strategy and options are valid
# (a falsy strategy means the default brute_force strategy is used)
strategy = strategy or "brute_force"
strategy_string = strategy
if strategy:
if strategy in strategy_map:
strategy = strategy_map[strategy]
else:
# check for user-defined strategy
if hasattr(strategy, "tune") and callable(strategy.tune):
# user-defined strategy
pass
else:
raise ValueError(f"Unkown strategy {strategy}, must be one of: {', '.join(list(strategy_map.keys()))}")

# ensure strategy_options is an Options object
tuning_options.strategy_options = Options(strategy_options or {})
# if no strategy selected
if strategy in strategy_map:
strategy = strategy_map[strategy]
elif hasattr(strategy, "tune") and callable(strategy.tune):
# user-defined strategy
pass
else:
strategy = strategy_map["brute_force"]
raise ValueError(f"Unkown strategy {strategy}, must be one of: {', '.join(list(strategy_map.keys()))}")

# ensure strategy_options is an Options object
tuning_options.strategy_options = Options(strategy_options or {})

# select the runner for this job based on input
tuning_options.simulated_time = 0
Expand All @@ -754,12 +750,21 @@ def tune_kernel(

runner = SimulationRunner(kernelsource, kernel_options, device_options, iterations, observers)
elif parallel:
# Avoid using multiple workers on strategies not supporting parallelism
if strategy not in _STRATEGY_PARALLEL:
parallel = 1
from kernel_tuner.runners.parallel import ParallelRunner
if parallel is True:
# Number of workers not given explicitly: let ParallelRunner decide,
# unless the chosen strategy does not support parallelism.
num_workers = None
if strategy_string not in _STRATEGY_PARALLEL:
logging.warning(
"chosen strategy (%s) does not support parallelism, number of parallel workers set to one",
strategy_string,
)
num_workers = 1
else:
# Number of workers given explicitly: always honor the request.
num_workers = parallel

num_workers = None if parallel is True else parallel
from kernel_tuner.runners.parallel import ParallelRunner
runner = ParallelRunner(
kernelsource, kernel_options, device_options, tuning_options, iterations, observers, num_workers=num_workers
)
Expand Down
2 changes: 1 addition & 1 deletion kernel_tuner/runners/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@

def run(self, parameter_space, tuning_options) -> List[Optional[dict]]:
metrics = tuning_options.metrics
objective = tuning_options.objective

Check warning on line 312 in kernel_tuner/runners/parallel.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the unused local variable "objective".

See more on https://sonarcloud.io/project/issues?id=KernelTuner_kernel_tuner&issues=AaCFXGk1cTp7cyTD_YJy&open=AaCFXGk1cTp7cyTD_YJy&pullRequest=401

jobs = [] # Jobs that need to be executed
results = [] # Results that will be returned at the end
Expand Down Expand Up @@ -358,7 +358,7 @@
) / 1000

# only compute metrics on configs that have not errored
if not isinstance(result.get(objective), ErrorConfig):
if "__error__" not in result:
result = process_metrics(result, metrics)
else:
logging.error(
Expand Down
Loading