From 099a851538a2c7907196a3e59a1e3a3ee2a593d7 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Thu, 1 Jun 2017 22:41:09 -0400 Subject: [PATCH 1/5] cltypes: Rename types,type_to_scalar_and_count -> vec_... --- pyopencl/array.py | 6 ++++++ pyopencl/cltypes.py | 18 +++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/pyopencl/array.py b/pyopencl/array.py index 9ee94a15..08f7cc8b 100644 --- a/pyopencl/array.py +++ b/pyopencl/array.py @@ -69,6 +69,12 @@ class VecLookupWarner(object): warn("pyopencl.array.vec is deprecated. " "Please use pyopencl.cltypes for OpenCL vector and scalar types", DeprecationWarning, 2) + + if name == "types": + name = "vec_types" + elif name == "type_to_scalar_and_count": + name = "vec_type_to_scalar_and_count" + return getattr(cltypes, name) diff --git a/pyopencl/cltypes.py b/pyopencl/cltypes.py index c8ff35c3..d1ba79f3 100644 --- a/pyopencl/cltypes.py +++ b/pyopencl/cltypes.py @@ -46,7 +46,6 @@ double = np.float64 # {{{ vector types - def _create_vector_types(): _mapping = [(k, globals()[k]) for k in ['char', 'uchar', 'short', 'ushort', 'int', @@ -55,10 +54,10 @@ def _create_vector_types(): def set_global(key, val): globals()[key] = val - field_names = ["x", "y", "z", "w"] + vec_types = {} + vec_type_to_scalar_and_count = {} - set_global('types', {}) - set_global('type_to_scalar_and_count', {}) + field_names = ["x", "y", "z", "w"] counts = [2, 3, 4, 8, 16] @@ -119,9 +118,14 @@ def _create_vector_types(): set_global("zeros_" + name, eval("lambda: filled_%s(0)" % (name))) set_global("ones_" + name, eval("lambda: filled_%s(1)" % (name))) - globals()['types'][np.dtype(base_type), count] = dtype - globals()['type_to_scalar_and_count'][dtype] = np.dtype(base_type), count + vec_types[np.dtype(base_type), count] = dtype + vec_type_to_scalar_and_count[dtype] = np.dtype(base_type), count + return vec_types, vec_type_to_scalar_and_count + + +vec_types, vec_type_to_scalar_and_count = _create_vector_types() -_create_vector_types() # }}} + +# vim: foldmethod=marker -- GitLab From 4238a0c4d388ea90a4ac8c98cb26022881e98abb Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Thu, 1 Jun 2017 22:41:25 -0400 Subject: [PATCH 2/5] Fix a few references to 'vec' --- pyopencl/tools.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pyopencl/tools.py b/pyopencl/tools.py index c7bd5ed0..5efdfdb0 100644 --- a/pyopencl/tools.py +++ b/pyopencl/tools.py @@ -454,8 +454,8 @@ class _CDeclList: if dtype in self.declared_dtypes: return - from pyopencl.array import vec - if dtype in vec.type_to_scalar_and_count: + import pyopencl.cltypes + if dtype in pyopencl.cltypes.vec_type_to_scalar_and_count: return for name, field_data in sorted(six.iteritems(dtype.fields)): @@ -658,8 +658,8 @@ def dtype_to_c_struct(device, dtype): if dtype.fields is None: return "" - from pyopencl.array import vec - if dtype in vec.type_to_scalar_and_count: + import pyopencl.cltypes + if dtype in pyopencl.cltypes.vec_type_to_scalar_and_count: # Vector types are built-in. Don't try to redeclare those. return "" -- GitLab From cf951cb6d7958627a1d9e2dd5bb754801148c5ff Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Thu, 1 Jun 2017 23:54:51 -0400 Subject: [PATCH 3/5] Fix vec references in clrandom --- pyopencl/clrandom.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pyopencl/clrandom.py b/pyopencl/clrandom.py index 225705c2..a30ffaf9 100644 --- a/pyopencl/clrandom.py +++ b/pyopencl/clrandom.py @@ -63,6 +63,7 @@ for some documentation if you're planning on using Random123 directly. import pyopencl as cl import pyopencl.array as cl_array +import pyopencl.cltypes as cltypes from pyopencl.tools import first_arg_dependent_memoize from pytools import memoize_method @@ -218,13 +219,13 @@ class RanluxGenerator(object): bits = 32 c_type = "float" rng_expr = "(shift + scale * gen)" - elif dtype == cl_array.vec.float2: + elif dtype == cltypes.float2: bits = 32 c_type = "float" rng_expr = "(shift + scale * gen)" size_multiplier = 2 arg_dtype = np.float32 - elif dtype in [cl_array.vec.float3, cl_array.vec.float4]: + elif dtype in [cltypes.float3, cltypes.float4]: bits = 32 c_type = "float" rng_expr = "(shift + scale * gen)" @@ -475,9 +476,9 @@ class Random123GeneratorBase(object): for dist in ["normal", "uniform"] for cmp_dtype in [ np.float32, - cl.array.vec.float2, - cl.array.vec.float3, - cl.array.vec.float4, + cltypes.float2, + cltypes.float3, + cltypes.float4, ]]: c_type = "float" scale_const = "((float) %r)" % (1/2**32) @@ -493,7 +494,7 @@ class Random123GeneratorBase(object): counter_multiplier = 1 arg_dtype = np.float32 try: - _, size_multiplier = cl.array.vec.type_to_scalar_and_count[dtype] + _, size_multiplier = cltypes.vec_type_to_scalar_and_count[dtype] except KeyError: pass -- GitLab From dec967d5531edf5cd23b1312ae0801a0e6a9c0c2 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Thu, 1 Jun 2017 23:56:58 -0400 Subject: [PATCH 4/5] Fix vec references in test_array --- test/test_array.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/test_array.py b/test/test_array.py index 2c27e77f..4c418903 100644 --- a/test/test_array.py +++ b/test/test_array.py @@ -32,6 +32,7 @@ import pytest import pyopencl as cl import pyopencl.array as cl_array +import pyopencl.cltypes as cltypes import pyopencl.tools as cl_tools from pyopencl.tools import ( # noqa pytest_generate_tests_for_pyopencl as pytest_generate_tests) @@ -194,12 +195,12 @@ def test_vector_fill(ctx_factory): context = ctx_factory() queue = cl.CommandQueue(context) - a_gpu = cl_array.Array(queue, 100, dtype=cl_array.vec.float4) - a_gpu.fill(cl_array.vec.make_float4(0.0, 0.0, 1.0, 0.0)) + a_gpu = cl_array.Array(queue, 100, dtype=cltypes.float4) + a_gpu.fill(cltypes.make_float4(0.0, 0.0, 1.0, 0.0)) a = a_gpu.get() - assert a.dtype == cl_array.vec.float4 + assert a.dtype == cltypes.float4 - a_gpu = cl_array.zeros(queue, 100, dtype=cl_array.vec.float4) + a_gpu = cl_array.zeros(queue, 100, dtype=cltypes.float4) def test_absrealimag(ctx_factory): -- GitLab From 21f318afd7c836c5ce1b49048244474cced702a9 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Thu, 1 Jun 2017 23:57:46 -0400 Subject: [PATCH 5/5] Fix vec references in test_wrapper --- test/test_wrapper.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/test_wrapper.py b/test/test_wrapper.py index a281e310..9f0eb864 100644 --- a/test/test_wrapper.py +++ b/test/test_wrapper.py @@ -30,6 +30,7 @@ import pytest import pyopencl as cl import pyopencl.array as cl_array +import pyopencl.cltypes as cltypes import pyopencl.clrandom from pyopencl.tools import ( # noqa pytest_generate_tests_for_pyopencl as pytest_generate_tests) @@ -561,8 +562,8 @@ def test_vector_args(ctx_factory): { dest[get_global_id(0)] = x; } """).build() - x = cl_array.vec.make_float4(1, 2, 3, 4) - dest = np.empty(50000, cl_array.vec.float4) + x = cltypes.make_float4(1, 2, 3, 4) + dest = np.empty(50000, cltypes.float4) mf = cl.mem_flags dest_buf = cl.Buffer(context, mf.READ_WRITE | mf.COPY_HOST_PTR, hostbuf=dest) -- GitLab