I am using arrayfun to perform a convolution on a set of images with different kernels. Instead of looping over each kernel, I use array fun. This works fine on a CPU, especially since the anonymous function can access variables from the parent function (e.g. each set of images is the same, but arrayfun runs over an array of kernels).
The problem with doing the same thing with arrayfun on the GPU is:
- arrayfun/gpu doesn't support anonymous functions accessing parent variables, so how do I pass the same static block of data to each evaluation of arrayfun?
- It also doesn't seem to support passing in a single struct or cell containing some common block of data.
Again, this works on a CPU, but how to do this on a GPU in matlab? In the below, images and filts are 3D matrix variables in the parent function, and the arrayfun executed over idx=1:n.
Ac = arrayfun(@(i) convFilts(images, filts, i), b, idx, 'UniformOutput', false);
function A = convFilts(images, filt, idx)
A = convn(images, filt(:,:,idx), 'valid');