From 9410435c326f6a39908e04a42ba2afc196415d5a Mon Sep 17 00:00:00 2001 From: Matt Wala <wala1@illinois.edu> Date: Fri, 25 Jan 2019 22:51:23 -0600 Subject: [PATCH] Fix a few legitimate looking issues --- pyopencl/__init__.py | 4 +-- pyopencl/array.py | 5 ++- pyopencl/characterize/performance.py | 6 ++-- pyopencl/clrandom.py | 12 +++++++ pyopencl/elementwise.py | 50 ---------------------------- pyopencl/scan.py | 7 ++++ pyopencl/tools.py | 3 ++ test/test_array.py | 2 +- test/test_clrandom.py | 4 +-- 9 files changed, 32 insertions(+), 61 deletions(-) diff --git a/pyopencl/__init__.py b/pyopencl/__init__.py index 179000d3..5d2976c4 100644 --- a/pyopencl/__init__.py +++ b/pyopencl/__init__.py @@ -1967,8 +1967,8 @@ def svm_empty_like(ctx, flags, ary, alignment=None): else: raise ValueError("array is neither C- nor Fortran-contiguous") - return svm_empty(ctx, ary.shape, ary.dtype, order, - flags=flags, alignment=alignment) + return svm_empty(ctx, flags, ary.shape, ary.dtype, order, + alignment=alignment) def csvm_empty(ctx, shape, dtype, order="C", alignment=None): diff --git a/pyopencl/array.py b/pyopencl/array.py index a4a5f4cf..69a9f81b 100644 --- a/pyopencl/array.py +++ b/pyopencl/array.py @@ -2280,9 +2280,8 @@ def multi_put(arrays, dest_indices, dest_shape=None, out=None, queue=None, vec_count = len(arrays) if out is None: - out = [Array(queue, dest_shape, a_dtype, - allocator=a_allocator, queue=queue) - for i in range(vec_count)] + out = [Array(queue, dest_shape, a_dtype, allocator=a_allocator) + for _ in range(vec_count)] else: if a_dtype != single_valued(o.dtype for o in out): raise TypeError("arrays and out must have the same dtype") diff --git a/pyopencl/characterize/performance.py b/pyopencl/characterize/performance.py index f3f2d894..f0c76907 100644 --- a/pyopencl/characterize/performance.py +++ b/pyopencl/characterize/performance.py @@ -50,15 +50,15 @@ class WallTimer(Timer): def start(self): from time import time self.queue.finish() - self.start = time() + self.start_time = time() def stop(self): from time import time self.queue.finish() - self.end = time() + self.end_time = time() def get_elapsed(self): - return self.end-self.start + return self.end_time-self.start_time def _get_time(queue, f, timer_factory=None, desired_duration=0.1, diff --git a/pyopencl/clrandom.py b/pyopencl/clrandom.py index decab716..96acce1f 100644 --- a/pyopencl/clrandom.py +++ b/pyopencl/clrandom.py @@ -424,6 +424,18 @@ class Random123GeneratorBase(object): .. automethod:: normal """ + @property + def header_name(self): + raise NotImplementedError + + @property + def generator_name(self): + raise NotImplementedError + + @property + def key_length(self): + raise NotImplementedError + def __init__(self, context, key=None, counter=None, seed=None): int32_info = np.iinfo(np.int32) from random import Random diff --git a/pyopencl/elementwise.py b/pyopencl/elementwise.py index 0e35df43..cbd8d746 100644 --- a/pyopencl/elementwise.py +++ b/pyopencl/elementwise.py @@ -484,56 +484,6 @@ def get_copy_kernel(context, dtype_dest, dtype_src): name="copy") -@context_dependent_memoize -def get_linear_combination_kernel(summand_descriptors, - dtype_z): - # TODO: Port this! - raise NotImplementedError - - from pyopencl.tools import dtype_to_ctype - from pyopencl.elementwise import \ - VectorArg, ScalarArg, get_elwise_module - - args = [] - preamble = [] - loop_prep = [] - summands = [] - tex_names = [] - - for i, (is_gpu_scalar, scalar_dtype, vector_dtype) in \ - enumerate(summand_descriptors): - if is_gpu_scalar: - preamble.append( - "texture <%s, 1, cudaReadModeElementType> tex_a%d;" - % (dtype_to_ctype(scalar_dtype, with_fp_tex_hack=True), i)) - args.append(VectorArg(vector_dtype, "x%d" % i, with_offset=True)) - tex_names.append("tex_a%d" % i) - loop_prep.append( - "%s a%d = fp_tex1Dfetch(tex_a%d, 0)" - % (dtype_to_ctype(scalar_dtype), i, i)) - else: - args.append(ScalarArg(scalar_dtype, "a%d" % i)) - args.append(VectorArg(vector_dtype, "x%d" % i, with_offset=True)) - - summands.append("a%d*x%d[i]" % (i, i)) - - args.append(VectorArg(dtype_z, "z", with_offset=True)) - args.append(ScalarArg(np.uintp, "n")) - - mod = get_elwise_module(args, - "z[i] = " + " + ".join(summands), - "linear_combination", - preamble="\n".join(preamble), - loop_prep=";\n".join(loop_prep)) - - func = mod.get_function("linear_combination") - tex_src = [mod.get_texref(tn) for tn in tex_names] - func.prepare("".join(arg.struct_char for arg in args), - (1, 1, 1), texrefs=tex_src) - - return func, tex_src - - def complex_dtype_to_name(dtype): if dtype == np.complex128: return "cdouble" diff --git a/pyopencl/scan.py b/pyopencl/scan.py index 30a657d8..71460f25 100644 --- a/pyopencl/scan.py +++ b/pyopencl/scan.py @@ -1137,6 +1137,9 @@ class _GenericScanKernelBase(object): # }}} + def finish_setup(self): + raise NotImplementedError + generic_scan_kernel_cache = WriteOncePersistentDict( "pyopencl-generated-scan-kernel-cache-v1", @@ -1726,6 +1729,10 @@ class _LegacyScanKernelBase(GenericScanKernel): output_statement=self.ary_output_statement, options=options, preamble=preamble, devices=devices) + @property + def ary_output_statement(self): + raise NotImplementedError + def __call__(self, input_ary, output_ary=None, allocator=None, queue=None): allocator = allocator or input_ary.allocator queue = queue or input_ary.queue or output_ary.queue diff --git a/pyopencl/tools.py b/pyopencl/tools.py index 369fb272..5b7b78d9 100644 --- a/pyopencl/tools.py +++ b/pyopencl/tools.py @@ -899,6 +899,9 @@ class KernelTemplateBase(object): def get_renderer(self, type_aliases, var_values, context=None, options=[]): return _TemplateRenderer(self, type_aliases, var_values) + def build_inner(self, context, *args, **kwargs): + raise NotImplementedError + def build(self, context, *args, **kwargs): """Provide caching for an :meth:`build_inner`.""" diff --git a/test/test_array.py b/test/test_array.py index 3f2aa3fa..d7274c68 100644 --- a/test/test_array.py +++ b/test/test_array.py @@ -1008,7 +1008,7 @@ def test_event_management(ctx_factory): from pyopencl.clrandom import rand as clrand x = clrand(queue, (5, 10), dtype=np.float32) - assert len(x.events) == 1, len(x._events) + assert len(x.events) == 1, len(x.events) x.finish() diff --git a/test/test_clrandom.py b/test/test_clrandom.py index 0cd572d0..b6b2094e 100644 --- a/test/test_clrandom.py +++ b/test/test_clrandom.py @@ -78,5 +78,5 @@ if __name__ == "__main__": if len(sys.argv) > 1: exec(sys.argv[1]) else: - import py.test - py.test.cmdline.main([__file__]) + from pytest import main + main([__file__]) -- GitLab