Reputation: 111
I'm performing Otsu's method (link https://en.wikipedia.org/wiki/Otsu%27s_method) in order to determine how many black pixels are in the raw frame. I'm trying to optimize process and I want to do it with OpenCL. Is there any way to pass the single variable to OpenCL kernel and increment it, instead of passing the whole buffer when it's not necessary?
Upvotes: 4
Views: 475
Reputation: 6343
The problem you want to solve is very much like a global reduction. While you could use a single output variable and atomic read/modify/write access, it would be very slow (due to contention on the atomic) unless the thing you are counting is very sparse (not the case here). So you should use the same techniques used for reduction, which is to do partial sums in parallel, and then merge those together. Google for "OpenCL reduction" and you'll find some great examples, such as this one: https://developer.amd.com/resources/articles-whitepapers/opencl-optimization-case-study-simple-reductions/
Upvotes: 6