Skip to content

Commit 8336cd0

Browse files
committed
Fixed a logic bug in parsing multidimensional sizes, and added a test to catch the bug.
1 parent 7fcabad commit 8336cd0

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

kernel_tuner/utils/directives.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,16 @@ def parse_size(size: Any, preprocessor: list = None, dimensions: dict = None) ->
219219
except ValueError:
220220
# If size cannot be natively converted to an int, we try to derive it from the preprocessor
221221
if preprocessor is not None:
222-
if "," in size:
223-
ret_size = 1
224-
for dimension in size.split(","):
225-
ret_size *= find_size_in_preprocessor(dimension, preprocessor)
226-
else:
227-
ret_size = find_size_in_preprocessor(size, preprocessor)
222+
try:
223+
if "," in size:
224+
ret_size = 1
225+
for dimension in size.split(","):
226+
ret_size *= find_size_in_preprocessor(dimension, preprocessor)
227+
else:
228+
ret_size = find_size_in_preprocessor(size, preprocessor)
229+
except TypeError:
230+
# preprocessor is available but does not contain the dimensions
231+
pass
228232
# If size cannot be natively converted, nor retrieved from the preprocessor, we check user provided values
229233
if dimensions is not None:
230234
if size in dimensions.keys():

test/utils/test_directives.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def test_parse_size():
7878
assert parse_size("m", ["#define size 512\n"], {"n": 32}) is None
7979
assert parse_size("rows,cols", dimensions={"rows": 16, "cols": 8}) == 128
8080
assert parse_size("n_rows,n_cols", ["#define n_cols 16\n", "#define n_rows 32\n"]) == 512
81+
assert parse_size("rows,cols", [], dimensions={"rows": 16, "cols": 8}) == 128
8182

8283

8384
def test_wrap_timing():

0 commit comments

Comments
 (0)