[PyOpenCL] 2d array row-wise and column-wise reduction and scan in pyopencl
lists at informa.tiker.net
Thu Mar 22 08:47:24 PDT 2012
On Thu, 22 Mar 2012 13:37:17 +0100, wrb <wrb at autistici.org> wrote:
> On 03/21/12 at 01:45P, Andreas Kloeckner wrote:
> > For a row-major matrix, row-wise scan is effectively segmented scan,
> > which is a tiny change to the existing scan code that's been on my todo
> > list for a long while. I'll try to get to that soon. And I'd be very
> > surprised if the optimal way to do column-wise scan weren't transpose,
> > row-wise scan, transpose. :)
> That sounds great! Also shame on me for not spotting the row-wise scan
> = segmented scan, I should know about parallel algorithms to realize
> Is there any way I can help? At least with testing perhaps?
Sure, if you'd like to take a crack at this, I'd be more than happy to
help. Here's the story:
The code is in pyopencl/compyte/scan.py
Start from a git checkout.
I'd like to do a few things to that code:
- Allow evaluation of a map before the scan starts, without ever
explicitly storing the map result. Such a map *could* (but wouldn't be
required to) involve widening each entry of the array to a struct that
contains the entry and a segment flag. The map would be fed in as a C
expression (i.e. as a string) and would be allowed to use all the
arguments given to the kernel (same idea as ElementwiseKernel), and it
would have its desired index available in the formal variable 'i'.
- A separate (Boolean-valued) expression (defaulting to None) that
marks segment boundaries, based on array indices and intermediate
- A final expression that manages storing the output. By default, this
just writes the scan result to the output array, but it could also use
the scan result as an index or do other funny business.
Having this should enable us to very easily replicate thrust's zoo of
- remove, remove_if
- unique, unique_by_key
The only tricky bit with segmented scan is correctly managing the
exclusive scan variant.
More information about the PyOpenCL