diff --git a/kernel_tuner/utils/directives.py b/kernel_tuner/utils/directives.py index 733942035..3d7fca06f 100644 --- a/kernel_tuner/utils/directives.py +++ b/kernel_tuner/utils/directives.py @@ -219,12 +219,16 @@ def parse_size(size: Any, preprocessor: list = None, dimensions: dict = None) -> except ValueError: # If size cannot be natively converted to an int, we try to derive it from the preprocessor if preprocessor is not None: - if "," in size: - ret_size = 1 - for dimension in size.split(","): - ret_size *= find_size_in_preprocessor(dimension, preprocessor) - else: - ret_size = find_size_in_preprocessor(size, preprocessor) + try: + if "," in size: + ret_size = 1 + for dimension in size.split(","): + ret_size *= find_size_in_preprocessor(dimension, preprocessor) + else: + ret_size = find_size_in_preprocessor(size, preprocessor) + except TypeError: + # preprocessor is available but does not contain the dimensions + pass # If size cannot be natively converted, nor retrieved from the preprocessor, we check user provided values if dimensions is not None: if size in dimensions.keys(): diff --git a/test/utils/test_directives.py b/test/utils/test_directives.py index 0c1f16aec..530faa68b 100644 --- a/test/utils/test_directives.py +++ b/test/utils/test_directives.py @@ -78,6 +78,7 @@ def test_parse_size(): assert parse_size("m", ["#define size 512\n"], {"n": 32}) is None assert parse_size("rows,cols", dimensions={"rows": 16, "cols": 8}) == 128 assert parse_size("n_rows,n_cols", ["#define n_cols 16\n", "#define n_rows 32\n"]) == 512 + assert parse_size("rows,cols", [], dimensions={"rows": 16, "cols": 8}) == 128 def test_wrap_timing():