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

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

问题描述

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

输出是每个像素一个值.

The output is one value per pixel.

目前我有这个:

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

其中 x 是虚拟变量,图像包含图像亮度值的 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.

有什么想法吗?

干杯,鲁本

推荐答案

遗憾的是,R2012b 中的 Parallel Computing Toolbox 不支持此功能.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 加速 (Matlab) 在 arrayfun 中使用匿名函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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