thrust icon indicating copy to clipboard operation
thrust copied to clipboard

Strided Iterators and 'Skip' Iterators

Open cdeterman opened this issue 7 years ago • 5 comments
trafficstars

Is there anything equivalent in Thrust that corresponds to the strided_iterator found in boost compute? On the same topic of operating on specific elements of a buffer, is there a way to operator on 'padded' objects? Note, I also have this same question posted in boost compute For example, take the row-wise padded matrix:

8 2 7 0 0 0
6 5 4 0 0 0
1 3 9 0 0 0 

So the internal flat buffer would be

8 2 7 0 0 0 6 5 4 0 0 0 1 3 9 0 0 0

As an example, how could I use sort on just the 'non-padded' elements?

Likewise, the column wise may also be padded (less common but might as well include here)

8 2 7 0 0 0
6 5 4 0 0 0
1 3 9 0 0 0 
0 0 0 0 0 0
0 0 0 0 0 0 
0 0 0 0 0 0

cdeterman avatar May 23 '18 15:05 cdeterman

I think it only exists as an example: https://github.com/thrust/thrust/blob/master/examples/strided_range.cu

henryiii avatar May 23 '18 15:05 henryiii

@henryiii thanks, I wonder why it hasn't been formally added in to thrust. Any additional thoughts regarding the 'padding' problem?

cdeterman avatar May 23 '18 15:05 cdeterman

This falls into the broader category of "multi-dimensional" support, I think, although a skip iterator could be useful for a linear sequence.

We don't have a firm design for what we're going to do in this space. But, I imagine we'll eventually want a family of strided iterators.

Note, however, that traditionally such iterators have all sorts of performance problems.

SEE ALSO: https://www.youtube.com/watch?v=EVGenON6p9g SEE ALSO: https://github.com/brycelelbach/mditerator SEE ALSO: https://github.com/brycelelbach/mdspan SEE ALSO: wg21.link/P0009

brycelelbach avatar May 29 '18 14:05 brycelelbach

@brycelelbach @allisonvacanti there have been several times where I've wanted something very simple like this for linear sequences. I don't think we need a full on md-span or multi-dimensional iterator for something this simple. Similarly, I've wanted a counting_iterator that takes a "step" value.

I imagine these would look something like this:

template <typename InputIterator, typename Stride>
auto make_strided_iterator(InputIterator it, Stride stride);

template <typename Incrementable>
auto make_counting_iterator(Incremenetable begin, Incrementable step);

jrhemstad avatar Oct 28 '21 22:10 jrhemstad

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1899r0.pdf

Equivalent for ranges.

jrhemstad avatar Feb 03 '22 15:02 jrhemstad