From 0e244ba9ec85568a4d691feee5dedef78cb165aa Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Tue, 3 Oct 2017 16:47:32 -0500 Subject: [PATCH 1/5] guess_arg_shape: Don't return unknown shape as a tuple --- loopy/kernel/tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loopy/kernel/tools.py b/loopy/kernel/tools.py index 8bdc72d54..15840180b 100644 --- a/loopy/kernel/tools.py +++ b/loopy/kernel/tools.py @@ -1070,7 +1070,7 @@ def guess_var_shape(kernel, var_name): if n_axes == 1: # Leave shape undetermined--we can live with that for 1D. - shape = (None,) + shape = None else: raise LoopyError("cannot determine access range for '%s': " "undetermined index in subscript(s) '%s'" -- GitLab From 63dfc17df74c83f3b9095496aaf8f041deccfb99 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Tue, 3 Oct 2017 16:48:37 -0500 Subject: [PATCH 2/5] Complain about unknown shape axes during code gen --- loopy/kernel/array.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/loopy/kernel/array.py b/loopy/kernel/array.py index 5d4240b9a..9d59c1b0b 100644 --- a/loopy/kernel/array.py +++ b/loopy/kernel/array.py @@ -1073,7 +1073,9 @@ class ArrayBase(ImmutableRecord): if isinstance(dim_tag, FixedStrideArrayDimTag): if array_shape is None: - new_shape_axis = None + raise LoopyError( + "shape of array '%s' not known during code generation" + % self.name) else: new_shape_axis = array_shape[user_axis] -- GitLab From a0de4f699516ab61796caca7c9189b72ddf62190 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Tue, 3 Oct 2017 17:30:29 -0500 Subject: [PATCH 3/5] Reallow unknown shape axes in decl_info --- loopy/kernel/array.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/loopy/kernel/array.py b/loopy/kernel/array.py index 9d59c1b0b..5d4240b9a 100644 --- a/loopy/kernel/array.py +++ b/loopy/kernel/array.py @@ -1073,9 +1073,7 @@ class ArrayBase(ImmutableRecord): if isinstance(dim_tag, FixedStrideArrayDimTag): if array_shape is None: - raise LoopyError( - "shape of array '%s' not known during code generation" - % self.name) + new_shape_axis = None else: new_shape_axis = array_shape[user_axis] -- GitLab From a2a1bc6f7d160194f24cee524c68b3356ecfc9ef Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Tue, 3 Oct 2017 17:35:21 -0500 Subject: [PATCH 4/5] Don't generate allocation code for written arrays with part-unknown shapes --- loopy/target/pyopencl_execution.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/loopy/target/pyopencl_execution.py b/loopy/target/pyopencl_execution.py index 2da25ba39..975c691a7 100644 --- a/loopy/target/pyopencl_execution.py +++ b/loopy/target/pyopencl_execution.py @@ -328,7 +328,8 @@ def generate_arg_setup(gen, kernel, implemented_data_info, options): # {{{ allocate written arrays, if needed if is_written and arg.arg_class in [lp.GlobalArg, lp.ConstantArg] \ - and arg.shape is not None: + and arg.shape is not None \ + and all(si is not None for si in arg.shape): if not isinstance(arg.dtype, NumpyType): raise LoopyError("do not know how to pass arg of type '%s'" -- GitLab From 602282c1940ccfe57a4f6668b8b81fd866dffc09 Mon Sep 17 00:00:00 2001 From: jdsteve2 Date: Tue, 3 Oct 2017 18:59:49 -0500 Subject: [PATCH 5/5] added unknown arg shape test for changes in arg-shape-fixes branch --- test/test_loopy.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/test_loopy.py b/test/test_loopy.py index 563964cf0..2c9425cc7 100644 --- a/test/test_loopy.py +++ b/test/test_loopy.py @@ -518,6 +518,32 @@ def test_arg_guessing_with_reduction(ctx_factory): print(knl) print(lp.CompiledKernel(ctx, knl).get_highlighted_code()) + +def test_unknown_arg_shape(ctx_factory): + ctx = ctx_factory() + from loopy.target.pyopencl import PyOpenCLTarget + from loopy.compiled import CompiledKernel + bsize = [256, 0] + + knl = lp.make_kernel( + "{[i,j]: 0<=i gid = i/256 + start = gid*256 + for j + a[start + j] = a[start + j] + j + end + end + """, + seq_dependencies=True, + name="uniform_l", + target=PyOpenCLTarget(), + assumptions="m<=%d and m>=1 and n mod %d = 0" % (bsize[0], bsize[0])) + + knl = lp.add_and_infer_dtypes(knl, dict(a=np.float32)) + cl_kernel_info = CompiledKernel(ctx, knl).cl_kernel_info(frozenset()) # noqa + # }}} -- GitLab