Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Usage of anonymous functions in arrayfun with GPU acceleration (Matlab)

I am new to the Parallel toolbox from Matlab R2012b and was wondering what the best way is to overcome the following problem.

I am analyzing the neighbourhood of every pixel in an image. Which is extremely good case for parallelization. However, I can't seem to get it working.

The main catch in the problem is that some "constant" arguments should be passed to the function. So the function should be called for every pixel, however, it also needs to access the surrounding pixels. (Preferable by passing the image as some sort of constant parameter and the coordinates of the pixel to be analyzed).

The output is one value per pixel.

At the moment I have this:

z2 = arrayfun(@(x) analyze(x, image, const1, ...), gpuArray(1:m*n));

Where x is the dummy-var, image a 2D matrix containing the luminance values of the image, const1 (and others) are function-constants (e.g. size of the analyze window). m and n are the size of the dimensions of the image.

However, I get this error

Error using gpuArray/arrayfun Use of functional workspace is not supported.

Any ideas?

Cheers, Ruben

like image 328
RVH Avatar asked Nov 20 '25 07:11

RVH


1 Answers

Unfortunately, this is not supported by Parallel Computing Toolbox in R2012b. The gpuArray version of arrayfun currently does not support binding in the constant data to an anonymous function handle. Arrayfun arguments must be passed directly, and must all either be scalar or the same size.

If you could bind in the constant arguments, you would next discover that you cannot currently index into them (or perform any non-scalar operations on them).

Perhaps you might be able to build up your algorithm using supported routines such as CONV2 or FILTER2.

like image 167
Edric Avatar answered Nov 23 '25 06:11

Edric



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!