m4rs-mt/ILGPU

[QUESTION]: Help/Orientation/Documentation to use ILGPU.Algorithms

poldap opened this issue · 4 comments

Question

Many of the things I want to do are implemented in ILGPU.Algorithms (reduction, histograms, etc.). However, I find not guidance on how to use them. It is quite hard to parse the samples directly simply reading the code.

Any guidance would be much appreciated.

I see, however, that the functions are annotated with some type of annotation framework, but I find nowhere some API reference or documentation where I can browse that conveniently. Please help?

Environment

No response

Additional context

As an example, trying to use the reduction algorithms already in there to implement the max over an image of floats is proving challenging. Thank you in advance for any help or guidance you can provide.

Hi @poldap, welcome to the ILGPU community. Do you have any specific use cases in mind like fetching a single reduced (aggregated) value back to CPU land, for instance?

Hi @m4rs-mt. Thank you 👍

My goal is to implement a histogram for float32 images. For that, I was trying to reuse the existing sample code for histograms. In order to make it appropriate for floats, I needed to get the minimum and maximum values of the image to make the appropriate binning.

For context, this is all to implement Otsu's automatic thresholding algorithm for images. The fastest algorithm I've found to do that is hybrid (GPU histogram -> CPU threshold selection -> GPU thresholding).

For a beginner like me it is very very hard to understand which implementation of the histogram is present in ILGPU. Is it something efficient as described here, for example? As far as I could parse the core work shoud be done in HistogramWorkKernel, but I cannot tell from there.

Also, I found that there are "launchers" for a Float histogram, but I guess they still need a personalized IComputeSingleBinOperation, which for Float, is kind of hard to implement if it only takes in an Index1D in its ComputeHistogramBin method (can only be done if the data have been previously normalized to lie between 0 and numBins, in which case the same as in the sample for AlgorithmsHistogram for Int works).

Managed to implement Otsu's algorithm for thresholding on Float32 images using the fastest GPU -> CPU -> GPU strategy and leveraging the ILGPU.Algorithms to reduce, histogram, etc.

Feel free to reach out if adding that example somewhere would be attractive to the community. Closing this for now.