kernel_tuner icon indicating copy to clipboard operation
kernel_tuner copied to clipboard

`bayes_opt` crashes when only two values are given for tunable parameter

Open stijnh opened this issue 2 years ago • 0 comments

The following code throws an exception.

import kernel_tuner

source = """
__global__ void foo() {

}
"""

problem_size = 100
args = []
tune_params = dict(
    block_size_x=[1, 64],
    block_size_y=[1, 2, 4, 8, 16, 32, 64],
    block_size_z=[1, 2, 4, 8, 16, 32, 64],
)

kernel_tuner.tune_kernel(
        source,
        "example",
        problem_size,
        args,
        tune_params,
        strategy="bayes_opt",
)

Results in the following error:

Traceback (most recent call last):
  File "test.py", line 23, in <module>
    strategy="bayes_opt",
  File "/home/stijn/miniconda3/lib/python3.7/site-packages/kernel_tuner/interface.py", line 469, in tune_kernel
    results, env = strategy.tune(runner, kernel_options, device_options, tuning_options)
  File "/home/stijn/miniconda3/lib/python3.7/site-packages/kernel_tuner/strategies/bayes_opt.py", line 129, in tune
    bo = BayesianOptimization(parameter_space, removed_tune_params, kernel_options, tuning_options, normalize_dict, denormalize_dict, runner)
  File "/home/stijn/miniconda3/lib/python3.7/site-packages/kernel_tuner/strategies/bayes_opt.py", line 228, in __init__
    self.initial_sample()
  File "/home/stijn/miniconda3/lib/python3.7/site-packages/kernel_tuner/strategies/bayes_opt.py", line 439, in initial_sample
    samples = self.draw_latin_hypercube_samples(self.num_initial_samples)
  File "/home/stijn/miniconda3/lib/python3.7/site-packages/kernel_tuner/strategies/bayes_opt.py", line 424, in draw_latin_hypercube_samples
    param_config = self.normalize_param_config(param_configs[i])
  File "/home/stijn/miniconda3/lib/python3.7/site-packages/kernel_tuner/strategies/bayes_opt.py", line 338, in normalize_param_config
    normalized = tuple(self.normalized_dict[self.param_names[index]][param_value] for index, param_value in enumerate(param_config))
  File "/home/stijn/miniconda3/lib/python3.7/site-packages/kernel_tuner/strategies/bayes_opt.py", line 338, in <genexpr>
    normalized = tuple(self.normalized_dict[self.param_names[index]][param_value] for index, param_value in enumerate(param_config))
KeyError: 9

The number given by KeyError is a random number between 1 and 64. My suspicion is that bayes_opt interprets block_size_x=[1, 64] as range(1, 64) for some reason. Adding more possible values for block_size_x fixes the issue (for example, block_size_x=[1, 64, 128]).

stijnh avatar Apr 20 '22 18:04 stijnh