使用GPU加速的arrayfun中的匿名函数(Matlab) [英] Usage of anonymous functions in arrayfun with GPU acceleration (Matlab)

查看:1220
本文介绍了使用GPU加速的arrayfun中的匿名函数(Matlab)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是来自Matlab R2012b的Parallel工具箱的新手,想知道最好的方法是克服以下问题。

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).

每个像素输出一个值。

现在我有这个:

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

其中x是dummy-var,image包含图像亮度值的2D矩阵const1 (和其他)是函数常数(例如分析窗口的大小)。 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.

但是,我收到此错误


使用gpuArray / arrayfun时出错
不支持使用功能工作空间。

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

任何想法?

干杯,
Ruben

Cheers, Ruben

推荐答案

R2012b中的并行计算工具箱不支持。 arrayfun的gpuArray版本目前不支持将常量数据绑定到匿名函数句柄。 Arrayfun参数必须直接传递,且必须是标量或大小相同的。

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).

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

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

这篇关于使用GPU加速的arrayfun中的匿名函数(Matlab)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆