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

16 次查看(过去 30 天)
I define a simple function of summation.m as follows:
--------------------------------------------
function out = summation(a, b, c, d)
out = a+b+c+d;
--------------------------------------------
Then, I run the following code:
--------------------------------------------
R1 = gpuArray.rand(10,10);
R2 = gpuArray.rand(10,10);
R3 = gpuArray.rand(10,10);
f = @(a,b,c)summation( a, b, c, 5);
R = arrayfun(f,R1,R2,R3);
--------------------------------------------
This works fine. However, if I change the function handle as
--------------------------------------------
R1 = gpuArray.rand(10,10);
R2 = gpuArray.rand(10,10);
R3 = gpuArray.rand(10,10);
*_d = 5;_*
f = @(a,b,c)summation( a, b, c, *_d_* );
R = arrayfun(f,R1,R2,R3);
--------------------------------------------
I get the error message "Error using gpuArray/arrayfun Use of functional workspace is not supported." Is there a way to resolve this issue? I would like to resolve this so that I can use GPU in the case that d is either a vector or a matrix.

回答(1 个)

Jill Reese
Jill Reese 2013-12-30
As of the latest MATLAB release (R2013b) arrayfun on the GPU does not support anonymous functions that have been created using variables from the existing MATLAB workspace. This is the meaning of the error message you have encountered.
Unless I am missing something, you should not need to create your function handle using your variable, d. Arrayfun on the GPU supports scalar expansion so d can be a scalar, a vector, or a matrix as long as its dimensions are either the same as your R1, R2, and R3 variables or the dimension is 1. So for the dimensions you mention above, d can be passed into the arrayfun call in the same way as R1, R2, and R3 and the call will succeed if d has size 1 x 1, 10 x 1, 1 x 10, or 10 x 10. Does this not work for you?

类别

Help CenterFile Exchange 中查找有关 GPU Computing 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by