From b60af20a8d55d2328bc78419f5a007e498bbd23f Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner <inform@tiker.net> Date: Sun, 24 Apr 2011 02:34:36 -0400 Subject: [PATCH] Check for contiguity in array operations. --- pyopencl/array.py | 3 +++ pyopencl/elementwise.py | 4 ++++ pyopencl/reduction.py | 4 ++++ pyopencl/scan.py | 8 ++++++++ 4 files changed, 19 insertions(+) diff --git a/pyopencl/array.py b/pyopencl/array.py index 38eabdb3..981e5f24 100644 --- a/pyopencl/array.py +++ b/pyopencl/array.py @@ -151,6 +151,9 @@ def elwise_kernel_runner(kernel_getter): actual_args = [] for arg in args: if isinstance(arg, Array): + if not arg.flags.forc: + raise RuntimeError("only contiguous arrays may " + "be used as arguments to this operation") actual_args.append(arg.data) else: actual_args.append(arg) diff --git a/pyopencl/elementwise.py b/pyopencl/elementwise.py index 6bcdc004..8e77fb80 100644 --- a/pyopencl/elementwise.py +++ b/pyopencl/elementwise.py @@ -142,6 +142,10 @@ class ElementwiseKernel: invocation_args = [] for arg, arg_descr in zip(args, self.arguments): if isinstance(arg_descr, VectorArg): + if not arg.flags.forc: + raise RuntimeError("ElementwiseKernel cannot " + "deal with non-contiguous arrays") + vectors.append(arg) invocation_args.append(arg.data) else: diff --git a/pyopencl/reduction.py b/pyopencl/reduction.py index 11d2e410..31e29b93 100644 --- a/pyopencl/reduction.py +++ b/pyopencl/reduction.py @@ -291,6 +291,10 @@ class ReductionKernel: from pyopencl.tools import VectorArg for arg, arg_tp in zip(args, stage_inf.arg_types): if isinstance(arg_tp, VectorArg): + if not arg.flags.forc: + raise RuntimeError("ReductionKernel cannot " + "deal with non-contiguous arrays") + vectors.append(arg) invocation_args.append(arg.data) else: diff --git a/pyopencl/scan.py b/pyopencl/scan.py index ee6f74fe..24d14569 100644 --- a/pyopencl/scan.py +++ b/pyopencl/scan.py @@ -442,6 +442,10 @@ if _CL_MODE: if input_ary.shape != output_ary.shape: raise ValueError("input and output must have the same shape") + if not input_ary.flags.forc: + raise RuntimeError("ScanKernel cannot " + "deal with non-contiguous arrays") + n, = input_ary.shape if not n: @@ -542,6 +546,10 @@ else: if input_ary.shape != output_ary.shape: raise ValueError("input and output must have the same shape") + if not input_ary.flags.forc: + raise RuntimeError("ScanKernel cannot " + "deal with non-contiguous arrays") + n, = input_ary.shape if not n: -- GitLab