Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sorting subset of buffer #784

Open
cdeterman opened this issue May 22, 2018 · 6 comments
Open

Sorting subset of buffer #784

cdeterman opened this issue May 22, 2018 · 6 comments
Labels

Comments

@cdeterman
Copy link

Not sure of a mailing list so I hope posting a use question here is appropriate. I have been able to use boost::compute::sort successfully on a general OpenCL buffer. However, I am often dealing with 'padded' buffers that are interpreted as matrices (row-wise storage). For example, the matrix

8 2 7
6 5 4
1 3 9

Is actually stored as

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

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
@jszuppe
Copy link
Contributor

jszuppe commented May 22, 2018

If the padding is constant, then you should be able to develop something similar to strided_iterator, which would jump over the padding to the next row (and ignore column padding). I don't see a way to do this using included fancy iterators.

@cdeterman
Copy link
Author

@jszuppe any thoughts on how to actually use strided_iterator to that effect? My understanding, from what I can see in the test examples here is that it takes every 'x' element (e.g. second, third, etc.).

@jszuppe
Copy link
Contributor

jszuppe commented May 22, 2018

I meant you would have to implement your own iterator class similar to strided iterator.

@cdeterman
Copy link
Author

cdeterman commented May 23, 2018

@jszuppe Are there any guidelines for how to approach this or should I just try to adapt from strided_iterator.hpp? This would be my first attempt at contributing to boost compute.

@jszuppe
Copy link
Contributor

jszuppe commented May 28, 2018

I think strided_iterator.hpp is a good starting point. You need to change index expression. I don't have much free time to show you how to do it. Maybe I'll find a moment this week.

@elwongest
Copy link

I know this question has been asked a long time ago, but having just got to using this very cool library, maybe this will help.
If your strided buffer is in host memory, you can move it to an "unstrided" device vector by using enqueue_write_buffer_rect instead of copy. You can "restride" it back to the host using enqueue_read_buffer_rect.
I use these for pixel format conversion in and out of FFmpeg AVFrames

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants