From d6d3aff0bb366f4a6ff1fb5be3fd9d275dbd9c8a Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Tue, 9 Feb 2021 18:20:38 -0600 Subject: [PATCH 1/2] Check contiguity of arrays in GPUArray.fill (closes gh-265) --- pycuda/gpuarray.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pycuda/gpuarray.py b/pycuda/gpuarray.py index 97630e3b..a1a3f3f3 100644 --- a/pycuda/gpuarray.py +++ b/pycuda/gpuarray.py @@ -627,6 +627,10 @@ class GPUArray: def fill(self, value, stream=None): """fills the array with the specified value""" + if not self.flags.forc: + raise RuntimeError( + "only contiguous arrays may be used as arguments to this operation") + func = elementwise.get_fill_kernel(self.dtype) func.prepared_async_call( self._grid, self._block, stream, value, self.gpudata, self.mem_size @@ -650,8 +654,7 @@ class GPUArray: ): if not self.flags.forc: raise RuntimeError( - "only contiguous arrays may " "be used as arguments to this operation" - ) + "only contiguous arrays may be used as arguments to this operation") if self.dtype == np.float64 and allow_double_hack: if channels != 1: -- GitLab From d563ec583204aaa94008e89bd594c8179a0109a5 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Tue, 9 Feb 2021 18:36:41 -0600 Subject: [PATCH 2/2] Fix test_zeros_like_etc to not use fill on non-contig arrays --- test/test_gpuarray.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/test_gpuarray.py b/test/test_gpuarray.py index fb6a20fc..fc7b6736 100644 --- a/test/test_gpuarray.py +++ b/test/test_gpuarray.py @@ -1192,6 +1192,9 @@ class TestGPUArray: contig = arr.flags.c_contiguous or arr.flags.f_contiguous + if not contig: + continue + # Output matches order of input. # Non-contiguous becomes C-contiguous new_z = func(arr, order="A") -- GitLab