Skip to content

Commit

Permalink
Add test balloon for custom type array kernels
Browse files Browse the repository at this point in the history
  • Loading branch information
inducer committed Aug 17, 2016
1 parent 40dda54 commit e499c28
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pyopencl/elementwise.py
Expand Up @@ -36,7 +36,7 @@
import pyopencl as cl
from pytools import memoize_method
from pyopencl.tools import (dtype_to_ctype, VectorArg, ScalarArg,
KernelTemplateBase)
KernelTemplateBase, dtype_to_c_struct)


# {{{ elementwise kernel code generator
Expand Down Expand Up @@ -740,6 +740,7 @@ def get_fill_kernel(context, dtype):
"tp": dtype_to_ctype(dtype),
},
"z[i] = a",
preamble=dtype_to_c_struct(context.devices[0], dtype),
name="fill")


Expand Down
3 changes: 3 additions & 0 deletions pyopencl/tools.py
Expand Up @@ -646,6 +646,9 @@ def calc_field_type():

@memoize
def dtype_to_c_struct(device, dtype):
if dtype.fields is None:
return ""

matched_dtype, c_decl = match_dtype_to_c_struct(
device, dtype_to_ctype(dtype), dtype)

Expand Down
29 changes: 29 additions & 0 deletions test/test_array.py
Expand Up @@ -260,6 +260,35 @@ def test_custom_type_zeros(ctx_factory):

assert np.array_equal(np.zeros(n, dtype), z)


def test_custom_type_fill(ctx_factory):
context = ctx_factory()
queue = cl.CommandQueue(context)

from pyopencl.characterize import has_struct_arg_count_bug
if has_struct_arg_count_bug(queue.device):
pytest.skip("device has LLVM arg counting bug")

dtype = np.dtype([
("cur_min", np.int32),
("cur_max", np.int32),
("pad", np.int32),
])

from pyopencl.tools import get_or_register_dtype, match_dtype_to_c_struct

name = "mmc_type"
dtype, c_decl = match_dtype_to_c_struct(queue.device, name, dtype)
dtype = get_or_register_dtype(name, dtype)

n = 1000
z_dev = cl.array.empty(queue, n, dtype=dtype)
z_dev.fill(np.zeros((), dtype))

z = z_dev.get()

assert np.array_equal(np.zeros(n, dtype), z)

# }}}


Expand Down

0 comments on commit e499c28

Please sign in to comment.