Discussion:
[PyCUDA] Slice generates RuntimeError: only contiguous arrays may be used as arguments to this operation
Bruce Labitt
2014-09-13 19:44:01 UTC
Permalink
I'm trying to port an FDTD code to pycuda and have run into a problem. The
error occurs when using slices.

Known error?

All variables are gpuarray. Fails in main time loop.

In [4]: run fdtd_pycuda.py
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
/usr/lib/python2.7/dist-packages/IPython/utils/py3compat.pyc in
execfile(fname, *where)
202 else:
203 filename = fname
--> 204 __builtin__.execfile(filename, *where)

/home/bruce/FDTD/fdtd_pycuda.py in <module>()
554
555 bx[1:ie_tot,:,:] = D1hx[1:ie_tot,:,:] * bx[1:ie_tot,:,:] -
D2hx[1:ie_tot,:,:] * \
--> 556 ( ( ez[1:ie_tot, 1:jh_tot, :] - ez[1:ie_tot, 0:je_tot,
:]) - ( ey[1:ie_tot,:,1:kh_tot] - ey[1:ie_tot,:,0:ke_tot] ) ) / delta
557 """
558 above line generates RunTimeError: only contiguous arrays
may be used as arguments to this operation

/usr/local/lib/python2.7/dist-packages/pycuda-2014.1-py2.7-linux-x86_64.egg/pycuda/gpuarray.pyc
in __sub__(self, other)
425 if isinstance(other, GPUArray):
426 result = self._new_like_me(_get_common_dtype(self,
other))
--> 427 return self._axpbyz(1, other, -1, result)
428 else:
429 if other == 0:

/usr/local/lib/python2.7/dist-packages/pycuda-2014.1-py2.7-linux-x86_64.egg/pycuda/gpuarray.pyc
in _axpbyz(self, selffac, other, otherfac, out, add_timer, stream)
308 assert self.shape == other.shape
309 if not self.flags.forc or not other.flags.forc:
--> 310 raise RuntimeError("only contiguous arrays may "
311 "be used as arguments to this operation")
312

RuntimeError: only contiguous arrays may be used as arguments to this
operation


Evaluating the following generates the RuntimeError.

In [17]: ( ey[1:ie_tot,:,1:kh_tot] - ey[1:ie_tot,:,0:ke_tot] )
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-17-1c6dfb98d933> in <module>()
----> 1 ( ey[1:ie_tot,:,1:kh_tot] - ey[1:ie_tot,:,0:ke_tot] )

/usr/local/lib/python2.7/dist-packages/pycuda-2014.1-py2.7-linux-x86_64.egg/pycuda/gpuarray.pyc
in __sub__(self, other)
425 if isinstance(other, GPUArray):
426 result = self._new_like_me(_get_common_dtype(self,
other))
--> 427 return self._axpbyz(1, other, -1, result)
428 else:
429 if other == 0:

/usr/local/lib/python2.7/dist-packages/pycuda-2014.1-py2.7-linux-x86_64.egg/pycuda/gpuarray.pyc
in _axpbyz(self, selffac, other, otherfac, out, add_timer, stream)
308 assert self.shape == other.shape
309 if not self.flags.forc or not other.flags.forc:
--> 310 raise RuntimeError("only contiguous arrays may "
311 "be used as arguments to this operation")
312

RuntimeError: only contiguous arrays may be used as arguments to this
operation

ey.shape = (111, 110, 111)
kh_tot = 111
ke_tot = 110

Shapes are appropriate.

Work arounds for slices? Straight numpy implementation works fine.

Thanks,
Bruce
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.tiker.net/pipermail/pycuda/attachments/20140913/8414133b/attachment.html>
Andreas Kloeckner
2014-09-17 16:57:31 UTC
Permalink
Post by Bruce Labitt
I'm trying to port an FDTD code to pycuda and have run into a problem. The
error occurs when using slices.
Known error?
All variables are gpuarray. Fails in main time loop.
In [4]: run fdtd_pycuda.py
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
/usr/lib/python2.7/dist-packages/IPython/utils/py3compat.pyc in
execfile(fname, *where)
203 filename = fname
--> 204 __builtin__.execfile(filename, *where)
/home/bruce/FDTD/fdtd_pycuda.py in <module>()
554
555 bx[1:ie_tot,:,:] = D1hx[1:ie_tot,:,:] * bx[1:ie_tot,:,:] -
D2hx[1:ie_tot,:,:] * \
--> 556 ( ( ez[1:ie_tot, 1:jh_tot, :] - ez[1:ie_tot, 0:je_tot,
:]) - ( ey[1:ie_tot,:,1:kh_tot] - ey[1:ie_tot,:,0:ke_tot] ) ) / delta
557 """
558 above line generates RunTimeError: only contiguous arrays
may be used as arguments to this operation
/usr/local/lib/python2.7/dist-packages/pycuda-2014.1-py2.7-linux-x86_64.egg/pycuda/gpuarray.pyc
in __sub__(self, other)
426 result = self._new_like_me(_get_common_dtype(self,
other))
--> 427 return self._axpbyz(1, other, -1, result)
/usr/local/lib/python2.7/dist-packages/pycuda-2014.1-py2.7-linux-x86_64.egg/pycuda/gpuarray.pyc
in _axpbyz(self, selffac, other, otherfac, out, add_timer, stream)
308 assert self.shape == other.shape
--> 310 raise RuntimeError("only contiguous arrays may "
311 "be used as arguments to this operation")
312
RuntimeError: only contiguous arrays may be used as arguments to this
operation
Evaluating the following generates the RuntimeError.
In [17]: ( ey[1:ie_tot,:,1:kh_tot] - ey[1:ie_tot,:,0:ke_tot] )
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-17-1c6dfb98d933> in <module>()
----> 1 ( ey[1:ie_tot,:,1:kh_tot] - ey[1:ie_tot,:,0:ke_tot] )
/usr/local/lib/python2.7/dist-packages/pycuda-2014.1-py2.7-linux-x86_64.egg/pycuda/gpuarray.pyc
in __sub__(self, other)
426 result = self._new_like_me(_get_common_dtype(self,
other))
--> 427 return self._axpbyz(1, other, -1, result)
/usr/local/lib/python2.7/dist-packages/pycuda-2014.1-py2.7-linux-x86_64.egg/pycuda/gpuarray.pyc
in _axpbyz(self, selffac, other, otherfac, out, add_timer, stream)
308 assert self.shape == other.shape
--> 310 raise RuntimeError("only contiguous arrays may "
311 "be used as arguments to this operation")
312
RuntimeError: only contiguous arrays may be used as arguments to this
operation
ey.shape = (111, 110, 111)
kh_tot = 111
ke_tot = 110
Shapes are appropriate.
Work arounds for slices? Straight numpy implementation works fine.
None yet. I'd appreciate patches, but for now the linear algebra
functionality in PyCUDA only works on contiguous arrays.

Andreas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 810 bytes
Desc: not available
URL: <http://lists.tiker.net/pipermail/pycuda/attachments/20140917/36bf2287/attachment.sig>
Loading...