diff --git a/pyopencl/array.py b/pyopencl/array.py index 35267b978147eb09782e1e7f6f14df228186122c..e7a441e8743cfda776149e347db29d48e722c004 100644 --- a/pyopencl/array.py +++ b/pyopencl/array.py @@ -50,8 +50,7 @@ class vec: def _create_vector_types(): field_names = ["x", "y", "z", "w"] - name_to_dtype = {} - dtype_to_name = {} + from pyopencl.tools import register_dtype counts = [2, 3, 4, 8, 16] for base_name, base_type in [ @@ -78,8 +77,7 @@ def _create_vector_types(): formats=[base_type]*count, titles=titles)) - name_to_dtype[name] = dtype - dtype_to_name[dtype] = name + register_dtype(dtype, name) setattr(vec, name, dtype) @@ -92,9 +90,6 @@ def _create_vector_types(): % (my_field_names_defaulted, my_field_names), dict(array=np.array, my_dtype=dtype)))) - vec._dtype_to_c_name = dtype_to_name - vec._c_name_to_dtype = name_to_dtype - _create_vector_types() # }}} diff --git a/pyopencl/compyte b/pyopencl/compyte index 52aecae2c0019caa81342ab79b47f60601a6a1b1..4118040aa50b5a7ef9b50d4b6b9f20fb1c764781 160000 --- a/pyopencl/compyte +++ b/pyopencl/compyte @@ -1 +1 @@ -Subproject commit 52aecae2c0019caa81342ab79b47f60601a6a1b1 +Subproject commit 4118040aa50b5a7ef9b50d4b6b9f20fb1c764781 diff --git a/pyopencl/tools.py b/pyopencl/tools.py index bce2111f1164551832743c16d8357997c464ad63..29b1c700fd2b001fcd30743c41371312dbf02739 100644 --- a/pyopencl/tools.py +++ b/pyopencl/tools.py @@ -33,6 +33,11 @@ import numpy as np from decorator import decorator import pyopencl as cl +from pyopencl.compyte.dtypes import ( + register_dtype, _fill_dtype_registry, + dtype_to_ctype) + +_fill_dtype_registry(respect_windows=True) @@ -175,51 +180,8 @@ def pytest_generate_tests_for_pyopencl(metafunc): -# {{{ C code generation helpers ----------------------------------------------- -def dtype_to_ctype(dtype): - if dtype is None: - raise ValueError("dtype may not be None") - - dtype = np.dtype(dtype) - if dtype == np.int64: - return "long" - elif dtype == np.uint64: - return "unsigned long" - elif dtype == np.int32: - return "int" - elif dtype == np.uint32: - return "unsigned int" - elif dtype == np.int16: - return "short int" - elif dtype == np.uint16: - return "short unsigned int" - elif dtype == np.int8: - return "signed char" - elif dtype == np.uint8: - return "unsigned char" - elif dtype == np.bool: - return "bool" - elif dtype == np.float32: - return "float" - elif dtype == np.float64: - return "double" - elif dtype == np.complex64: - return "complex float" - elif dtype == np.complex128: - return "complex double" - else: - import pyopencl.array as cl_array - try: - return cl_array.vec._dtype_to_c_name[dtype] - except KeyError: - raise ValueError, "unable to map dtype '%s'" % dtype - -# }}} - - - +# {{{ C argument lists -# {{{ C argument lists -------------------------------------------------------- class Argument: def __init__(self, dtype, name): self.dtype = np.dtype(dtype) @@ -245,59 +207,12 @@ class ScalarArg(Argument): def parse_c_arg(c_arg): c_arg = (c_arg - .replace("const", "") - .replace("volatile", "") .replace("__global", "") .replace("__local", "") .replace("__constant", "")) - # process and remove declarator - import re - decl_re = re.compile(r"(\**)\s*([_a-zA-Z0-9]+)(\s*\[[ 0-9]*\])*\s*$") - decl_match = decl_re.search(c_arg) - - if decl_match is None: - raise ValueError("couldn't parse C declarator '%s'" % c_arg) - - name = decl_match.group(2) - - if decl_match.group(1) or decl_match.group(3) is not None: - arg_class = VectorArg - else: - arg_class = ScalarArg - - tp = c_arg[:decl_match.start()] - tp = " ".join(tp.split()) - - type_re = re.compile(r"^([a-z0-9 ]+)$") - type_match = type_re.match(tp) - if not type_match: - raise RuntimeError("type '%s' did not match expected shape of type" - % tp) - - tp = type_match.group(1) - - if tp == "float": dtype = np.float32 - elif tp == "double": dtype = np.float64 - elif tp in ["int", "signed int"]: dtype = np.int32 - elif tp in ["unsigned", "unsigned int"]: dtype = np.uint32 - elif tp in ["long", "long int"]: dtype = np.int64 - elif tp in ["unsigned long", "unsigned long int", "long unsigned int"]: - dtype = np.uint64 - elif tp in ["short", "short int"]: dtype = np.int16 - elif tp in ["unsigned short", "unsigned short int", "short unsigned int"]: - dtype = np.uint16 - elif tp in ["char", "signed char"]: dtype = np.int8 - elif tp in ["unsigned char"]: dtype = np.uint8 - elif tp in ["bool"]: dtype = np.bool - else: - import pyopencl.array as cl_array - try: - dtype = cl_array.vec._c_name_to_dtype[tp] - except KeyError: - raise ValueError("unknown type '%s'" % tp) - - return arg_class(dtype, name) + from pyopencl.compyte.dtypes import parse_c_arg_backend + return parse_c_arg_backend(c_arg, ScalarArg, VectorArg) # }}}