I'm writing a CUDA program which will attempt to locate about 35 sub-images, or patterns, within a base image. Each sub-image (pattern) can only exist in a small area (say a 10x10 pixel window) of the base image. The sub-images vary in size from 1000 to 10000 pixels. The base image is 640x480 pixels.
I do this by convolving the sub-image with a sub-section of the base image and if the convolution result is smaller than a threshold, than that is considered a match. I have to do about 100 convolutions per sub-image (since I only check a 10x10 window of allowable positions).
First question: has this been implemented and is it available in Open Source?
Second question: which is the better implementation strategy?
- Coarse-grained: Each CUDA thread does a full convolution of the sub-image within the base image. There is one CUDA thread for each sub-image and position.
- Fine-grained: each CUDA thread computes one component (pixel) of the convolution: so, the CUDA thread multiples a pixel of the sub-image by the appropriate pixel of the base image. Then, use syncblock() to sum these multiples.
UPDATE: I trid both approaches. I think the best method is a variant on method one where I divide the larger sub-images into smaller sub-images. Now all the sub-images are approximately the same size (say, 1024 pixels). Then each CUDA thread does a full convolution for a single position. When done, I send all results to the host, and the host is responsible for putting the intermediate pieces back together (for the sub-images that were divided into smaller pieces). The advantage is that all CUDA threads perform the same amount of work. This seems to be twice as fast as the second approach, which is problematic since the sub-images vary in size.
convolutionSeparableandconvolutionTexturesamples? Why are not using FFTs to perform convolutions (see theconvolutionFFT2Dexample)? Are the matrices too small for FFTs? In that case, approaches for fastly calculating FFTs of small matrices in CUDA could be of interest. Finally, are you considering using dynamic parallelism? For the latter two, have a look at my answer to the Best approach for convolution of multiple small matrices using CUDA. - Vitality