inducer / inducer/pycuda

2D GPUArray negative step slice

Open
#121 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
2.1k
Forks
298
Avg merge
4m
Merged PRs (30d)
1

Description

I've a 2D image and I need to flip it on either first or second axis. I tried to do it with a negative step slice, but it fails:

``` python
import pycuda
import pycuda.autoinit
from pycuda import gpuarray
print pycuda.VERSION

ary = gpuarray.arange(9).reshape(3,3)
print ary.get(), ary[::-1, :].get()
```

```
(2016, 1, 2)
[[0 1 2]
[3 4 5]
[6 7 8]]
---------------------------------------------------------------------------
OverflowError Traceback (most recent call last)
in ()
5
6 ary = gpuarray.arange(9).reshape(3,3)
----> 7 print ary.get(), ary[::-1, :].get()

/opt/anaconda2/lib/python2.7/site-packages/pycuda/gpuarray.pyc in get(self, ary, pagelocked, async, stream)
269
270 if self.size:
--> 271 _memcpy_discontig(ary, self, async=async, stream=stream)
272 return ary
273

/opt/anaconda2/lib/python2.7/site-packages/pycuda/gpuarray.pyc in _memcpy_discontig(dst, src, async, stream)
1216 copy.width_in_bytes = src.dtype.itemsize*shape[0]
1217
-> 1218 copy.src_pitch = src_strides[1]
1219 copy.dst_pitch = dst_strides[1]
1220 copy.height = shape[1]

OverflowError: can't convert negative value to unsigned
```

Is there another a way to reverse on a single axis without writing a custom kernel?
I saw method [`.reverse()`](https://github.com/inducer/pycuda/blob/master/pycuda/gpuarray.py#L648) but, beside not being present in the [docs](https://documen.tician.de/pycuda/array.html#pycuda.gpuarray.GPUArray), it treats array as one-dimensional.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.