Skip to content

Commit 5e37358

Browse files
Merge pull request #176 from loostrum/allow_bool_arg
Support boolean datatype in PyCUDA backend.
2 parents 5dd207d + 76109a3 commit 5e37358

File tree

4 files changed

+9
-2
lines changed

4 files changed

+9
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
99
- Support for locked clocks in NVMLObserver
1010
- Support for measuring core voltages using NVML
1111
- Support for custom preprocessor definitions
12+
- Support for boolean scalar arguments in PyCUDA backend
1213

1314
### Changed
1415
- Migrated from github.com/benvanwerkhoven to github.com/KernelTuner

kernel_tuner/pycuda.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ def ready_argument_list(self, arguments):
188188
gpu_args.append(Holder(arg))
189189
else:
190190
gpu_args.append(Holder(arg.cuda()))
191+
# pycuda does not support bool, convert to uint8 instead
192+
elif isinstance(arg, np.bool_):
193+
gpu_args.append(arg.astype(np.uint8))
191194
else: # if not an array, just pass argument along
192195
gpu_args.append(arg)
193196
return gpu_args

kernel_tuner/util.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class StopCriterionReached(Exception):
6060
def check_argument_type(dtype, kernel_argument):
6161
"""check if the numpy.dtype matches the type used in the code"""
6262
types_map = {
63+
"bool": ["bool"],
6364
"uint8": ["uchar", "unsigned char", "uint8_t"],
6465
"int8": ["char", "int8_t"],
6566
"uint16": ["ushort", "unsigned short", "uint16_t"],

test/test_pycuda_functions.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@ def test_ready_argument_list():
1717
size = 1000
1818
a = np.int32(75)
1919
b = np.random.randn(size).astype(np.float32)
20-
c = np.zeros_like(b)
20+
c = np.bool_(True)
21+
d = np.zeros_like(b)
2122

22-
arguments = [c, a, b]
23+
arguments = [d, a, b, c]
2324

2425
dev = kt_pycuda.PyCudaFunctions(0)
2526
gpu_args = dev.ready_argument_list(arguments)
2627

2728
assert isinstance(gpu_args[0], pycuda.driver.DeviceAllocation)
2829
assert isinstance(gpu_args[1], np.int32)
2930
assert isinstance(gpu_args[2], pycuda.driver.DeviceAllocation)
31+
assert isinstance(gpu_args[3], np.uint8)
3032

3133

3234
@skip_if_no_pycuda

0 commit comments

Comments
 (0)