3

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

4

2 回答 2

2

不幸的是,R2012b 中的 Parallel Computing Toolbox 不支持此功能。arrayfun 的 gpuArray 版本目前不支持将常量数据绑定到匿名函数句柄。Arrayfun 参数必须直接传递,并且必须都是标量或相同大小。

如果您可以绑定常量参数,接下来您会发现当前无法对它们进行索引(或对它们执行任何非标量操作)。

也许您可以使用支持的例程(例如 CONV2 或 FILTER2)来构建您的算法。

于 2012-11-06T07:24:35.063 回答
0

这是一个非常古老的帖子,但由于我正在努力解决类似的问题,我想分享我对此的发现:

如果你把你的调用arrayfun放在一个函数中,你也许可以将这个analyze函数实现为一个可以访问你的常量数组的嵌套函数。但是,这可能需要在重写代码时付出相当大的努力,因为在嵌套analyze函数中,您不能将任何完整数组传递给任何其他函数,这意味着您必须以仅使用常量的单个索引数组条目的方式重写所有内容数组,例如在数组上的 for 循环中。因此,诸如 etc. 之类的所有函数调用都size将不起作用,应该移到外面analyze(至少我正在使用的 Matlab2015b 是这种情况)。这是如何完成的示例(不是我的):

https://devblogs.nvidia.com/high-performance-matlab-gpu-acceleration/

最好的,

汉斯-马丁

于 2019-04-26T12:45:45.707 回答