Consider the following simple class
classdef A < handle
properties
M;
end
methods
function obj= A(m)
obj.M=m;
end
function foo(obj)
Array = linspace(0,obj.M,100);
arrayfun(@obj.bar,Array);
end
function foo2(obj)
Array = gpuArray.linspace(0,obj.M,100);
arrayfun(@obj.bar,Array);
end
function y = bar(obj,x)
y = x^2/obj.M;
end
end
end
Now a run
>>
a=A(1);
>>
a.foo();
>>
a.foo2();Error using gpuArray/arrayfun Function passed as first input argument contains unsupported 'MCOS' language feature 'CLASSDEF'. For more information see Tips and Restrictions.
Error in A/foo2 (line 20) arrayfun(@obj.bar,Array);
Notice that foo()
and foo2()
are the same function with the only exception, foo2()
is supposed to run the GPU version of arrayfun
.
Is there any workaround or trick to make foo2()
above working, i.e. class method run on GPU? Consider bar()
cannot be static or so as it supposed to use class properties.