How can I speed up a custom function that uses the Image Processing Toolbox "normxcorr2" function using GPU Coder in MATLAB R2024a?

I have a custom function that computes the correlation of two input images, and it makes use of the "normxcorr2" Image Processing Toolbox function. The function calls "normxcorr2" many times in a for-loop, and MATLAB Profiler indicates that it is the biggest user of computational resources in my custom function.
My custom function takes 70 seconds to run when my two input images are 5000x5000. If I use a "parfoor" loop, I am able to speed it up, but I would like to get it even faster.
How can I use GPU Coder to speed my custom function up?
Below is the pseudocode for my function:
% ... more code above ...
[m, n] = imageDimensions;
total = m * n;
res = zeros(1, total);
for partition_idx = 1:total
[subImage1, subImage2] = getSubImagesByPartition(image1, image2, partition_idx);
res(i) = normxcorr2(subImage1, subImage2) % part of function that is very slow
end
return res;

 Respuesta aceptada

GPU Coder is not one of the extended capabilities of the "normxcorr2" function, and CUDA kernel code is not generated for it.
In testing an example workflow that replicated your pseudo-code use case, the code generated by GPU Coder was bottlenecked by the machine's CPU, and significant overhead was seen in transfers of data between the CPU and GPU.
While GPU Coder may not be able to directly speed your function up if its performance is constrained by "normxcorr2", the "normxcorr2" function supports GPU Arrays, a feature that is part of the Parallel Computing Toolbox:
By using GPU Arrays, you may be able to improve the performance of your custom function.

Más respuestas (0)

Categorías

Más información sobre Get Started with GPU Coder en Centro de ayuda y File Exchange.

Productos

Versión

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by