问题描述
我正在使用 matlab GPU函数arrayfun
和gpuArray
对象进行计算,以对我函数中gpuArray
变量的元素执行逐元素函数:
I am using matlab GPU computing with function arrayfun
and a gpuArray
object to do element-wise function on elements of the gpuArray
variable on my function:
[ output ] = MyFunc( element, SharedMatrix )
//
// Process element with Shared Matrix
//
end
我的代码如下:
SharedMatrix = magic(5000); %Large Memory Object
SharedMatrix = gpuArray(SharedMatrix);
elements = magic(5);
gpuElements = gpuArray(elements );
//Error on next line, SharedMatrix object must be a scaler.
result = arrayfun(@MyFunc,gpuElements,SharedMatrix);
我听说全局变量不能用于 GPU计算.
I've heard that global variables can't be used in GPU computing.
是否可以使用arrayfun
来做到这一点?
Is there a way to do so with arrayfun
?
推荐答案
arrayfun
当前要求所有输入都具有兼容的大小(或标量),并且处理以元素方式进行.
arrayfun
currently require all inputs to be compatible sizes (or scalars), and the processing is done in an elementwise manner.
此外,Matlab中的Parallel Computing Toolbox
不支持Global Variables
,因此无法使用Parallel Computing Toolbox
完成.
Also, Parallel Computing Toolbox
in Matlab don't support Global Variables
, So it can't be done using the Parallel Computing Toolbox
.
这篇关于Matlab GPU arrayfun共享变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!