Esempio n. 1
0
def _create_vector_types():
    field_names = ["x", "y", "z", "w"]

    from pyopencl.tools import register_dtype

    counts = [2, 3, 4, 8, 16]
    for base_name, base_type in [
        ('char', np.int8),
        ('uchar', np.uint8),
        ('short', np.int16),
        ('ushort', np.uint16),
        ('int', np.int32),
        ('uint', np.uint32),
        ('long', np.int64),
        ('ulong', np.uint64),
        ('float', np.float32),
        ('double', np.float64),
    ]:
        for count in counts:
            name = "%s%d" % (base_name, count)

            titles = field_names[:count]
            if len(titles) < count:
                titles.extend((count - len(titles)) * [None])

            dtype = np.dtype(
                dict(names=["s%d" % i for i in range(count)],
                     formats=[base_type] * count,
                     titles=titles))

            register_dtype(dtype, name)

            setattr(vec, name, dtype)

            my_field_names = ",".join(field_names[:count])
            my_field_names_defaulted = ",".join("%s=0" % fn
                                                for fn in field_names[:count])
            setattr(
                vec, "make_" + name,
                staticmethod(
                    eval(
                        "lambda %s: array((%s), dtype=my_dtype)" %
                        (my_field_names_defaulted, my_field_names),
                        dict(array=np.array, my_dtype=dtype))))
Esempio n. 2
0
def _create_vector_types():
    field_names = ["x", "y", "z", "w"]

    from pyopencl.tools import register_dtype

    counts = [2, 3, 4, 8, 16]
    for base_name, base_type in [
        ("char", np.int8),
        ("uchar", np.uint8),
        ("short", np.int16),
        ("ushort", np.uint16),
        ("int", np.int32),
        ("uint", np.uint32),
        ("long", np.int64),
        ("ulong", np.uint64),
        ("float", np.float32),
        ("double", np.float64),
    ]:
        for count in counts:
            name = "%s%d" % (base_name, count)

            titles = field_names[:count]
            if len(titles) < count:
                titles.extend((count - len(titles)) * [None])

            dtype = np.dtype(dict(names=["s%d" % i for i in range(count)], formats=[base_type] * count, titles=titles))

            register_dtype(dtype, name)

            setattr(vec, name, dtype)

            my_field_names = ",".join(field_names[:count])
            my_field_names_defaulted = ",".join("%s=0" % fn for fn in field_names[:count])
            setattr(
                vec,
                "make_" + name,
                staticmethod(
                    eval(
                        "lambda %s: array((%s), dtype=my_dtype)" % (my_field_names_defaulted, my_field_names),
                        dict(array=np.array, my_dtype=dtype),
                    )
                ),
            )
Esempio n. 3
0
    # larger dtype
    view = a_dev.view(np.complex64)
    assert view.shape == (8, 8) and view.dtype == np.complex64

    # smaller dtype
    view = a_dev.view(np.int16)
    assert view.shape == (8, 32) and view.dtype == np.int16

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

from pyopencl.tools import register_dtype
register_dtype(mmc_dtype, "minmax_collector", alias_ok=True)
register_dtype(mmc_dtype, "minmax_collector", alias_ok=True)

@pytools.test.mark_test.opencl
def test_struct_reduce(ctx_factory):
    context = ctx_factory()
    queue = cl.CommandQueue(context)

    preamble = r"""//CL//
    struct minmax_collector
    {
        int cur_min;
        int cur_max;
        // Workaround for OS X Lion GPU CL. Mystifying.
        int pad;
    };