Skip to content

Commit 75ca654

Browse files
inserted a check for argument types in the interface
1 parent b53812a commit 75ca654

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

kernel_tuner/interface.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ def tune_kernel(kernel_name, kernel_string, problem_size, arguments,
275275
max_threads = dev.max_threads
276276

277277
#move data to GPU
278+
_check_argument_list(arguments)
278279
gpu_args = dev.ready_argument_list(arguments)
279280

280281
#compute cartesian product of all tunable parameters
@@ -519,3 +520,7 @@ def _check_kernel_correctness(dev, func, gpu_args, threads, grid, answer, instan
519520
raise Exception("Error " + instance_string + " failed correctness check")
520521
return correct
521522

523+
def _check_argument_list(args):
524+
for (i, arg) in enumerate(args):
525+
if not isinstance(arg, (numpy.ndarray, numpy.generic)):
526+
raise TypeError("Argument at position " + str(i) + " of type: " + str(type(arg)) + " should be of type numpy.ndarray or numpy scalar")

test/test_interface.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,22 @@ def test_check_kernel_correctness(dev_interface):
117117
assert args[1] == 'gpu_args'
118118
assert dev.memcpy_dtoh.called == 1
119119
assert test
120+
121+
def test_check_argument_list1():
122+
args = [numpy.int32(5), 'blah', numpy.array([1, 2, 3])]
123+
try:
124+
kernel_tuner._check_argument_list(args)
125+
print("Expected a TypeError to be raised")
126+
assert False
127+
except TypeError as e:
128+
print(str(e))
129+
assert "at position 1" in str(e)
130+
except:
131+
print("Expected a TypeError to be raised")
132+
assert False
133+
134+
def test_check_argument_list2():
135+
args = [numpy.int32(5), numpy.float64(4.6), numpy.array([1, 2, 3])]
136+
kernel_tuner._check_argument_list(args)
137+
#test that no exception is raised
138+
assert True

0 commit comments

Comments
 (0)