diff --git a/CHANGELOG.md b/CHANGELOG.md index c7a05c4d..65940368 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). ## Unreleased +- Fixed `run_kernel` with Julia kernels when `grid_div_x/y/z` are passed as Julia vectors. +- `block_size_names` can be passed as a tuple, and the list passed in is no longer modified. ## [1.6.0] - 2026-11-13 - Extended Julia functionality: diff --git a/kernel_tuner/interface.py b/kernel_tuner/interface.py index ebd43ed9..666f1134 100644 --- a/kernel_tuner/interface.py +++ b/kernel_tuner/interface.py @@ -683,7 +683,7 @@ def tune_kernel( block_size_names = util.check_block_size_params_names_list(block_size_names, tune_params) # ensure there is always at least three names - util.append_default_block_size_names(block_size_names) + block_size_names = util.append_default_block_size_names(block_size_names) # if Julia, infer the Julia backend from the kernelsource if kernelsource.lang.upper() == "JULIA": @@ -976,9 +976,12 @@ def run_kernel( params = util.julia_list_of_pairs_to_dict(params) # convert scalars without explicit types to numpy scalars arguments = [numpy.array(a)[()] if numpy.isscalar(a) else a for a in arguments] + grid_div_x = util.possible_julia_vector_to_list(grid_div_x) + grid_div_y = util.possible_julia_vector_to_list(grid_div_y) + grid_div_z = util.possible_julia_vector_to_list(grid_div_z) block_size_names = util.possible_julia_vector_to_list(block_size_names) # ensure there is always at least three names - util.append_default_block_size_names(block_size_names) + block_size_names = util.append_default_block_size_names(block_size_names) _check_user_input(kernel_name, kernelsource, arguments, block_size_names) diff --git a/kernel_tuner/util.py b/kernel_tuner/util.py index 1af6f89e..04346da7 100644 --- a/kernel_tuner/util.py +++ b/kernel_tuner/util.py @@ -408,7 +408,7 @@ def check_tune_params_list(tune_params, observers, simulation_mode=False): def check_block_size_names(block_size_names): if block_size_names is not None: # do some type checks for the user input - if not isinstance(block_size_names, list): + if not isinstance(block_size_names, (list, tuple)): raise ValueError("block_size_names should be a list of strings!", block_size_names, type(block_size_names)) if len(block_size_names) > 3: raise ValueError("block_size_names should not contain more than 3 names!", block_size_names) @@ -421,11 +421,14 @@ def check_block_size_names(block_size_names): def append_default_block_size_names(block_size_names): + """Returns the block size names as a new list, padded with the default names to at least three names. + + Any sequence is accepted (e.g. a tuple, or a Julia vector), and the one passed in is not modified. + """ if block_size_names is None: - return - for i, name in enumerate(default_block_size_names): - if len(block_size_names) < i + 1: - block_size_names.append(name) + return None + block_size_names = list(block_size_names) + return block_size_names + default_block_size_names[len(block_size_names) :] def check_block_size_params_names_list(block_size_names, tune_params): diff --git a/pyproject.toml b/pyproject.toml index ef9abdef..815de8a8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api" [project] name = "kernel_tuner" description = "An easy to use CUDA/OpenCL kernel tuner in Python" -version = "1.6.0" # adhere to PEP440 versioning: https://packaging.python.org/en/latest/guides/distributing-packages-using-setuptools/#id55 +version = "1.6.1" # adhere to PEP440 versioning: https://packaging.python.org/en/latest/guides/distributing-packages-using-setuptools/#id55 readme = "README.md" license = "Apache-2.0" authors = [ @@ -162,4 +162,4 @@ select = [ "D", # pydocstyle, ] [tool.ruff.lint.pydocstyle] -convention = "google" \ No newline at end of file +convention = "google" diff --git a/test/test_util_functions.py b/test/test_util_functions.py index 28c14f3e..b10ea316 100644 --- a/test/test_util_functions.py +++ b/test/test_util_functions.py @@ -532,6 +532,18 @@ def test_check_tune_params_list3(): check_tune_params_list(tune_params, []) +def test_append_default_block_size_names(): + assert append_default_block_size_names(None) is None + assert append_default_block_size_names([]) == ["block_size_x", "block_size_y", "block_size_z"] + # a tuple is accepted as well, and the names passed in are not modified + names = ("bx",) + assert append_default_block_size_names(names) == ["bx", "block_size_y", "block_size_z"] + names = ["bx", "by"] + assert append_default_block_size_names(names) == ["bx", "by", "block_size_z"] + assert names == ["bx", "by"] + assert append_default_block_size_names(["bx", "by", "bz", "bw"]) == ["bx", "by", "bz", "bw"] + + def test_check_block_size_params_names_list(): def test_warnings(function, args, number, warning_type): with warnings.catch_warnings(record=True) as w: