How can I accelerate this function with GPU arrayfun

Hi,
I want to accelerate a function like below with GPU. The real code is too complex so I put a simplified version here.
The main problem of this code is at the 5th line of nestedFcn: Indexing is not supported.
And the 1st line of nestedFcn : The size and shape for all variables must be the same. Variable 'test2' differs from 'test'.
Is there any way to do that?
% code
function gtest
Np=10;
test = zeros(Np);
test(1,1)=1;
E = rand(1,Np);
gpuVector = gpuArray.colon(1, Np);
function out = nestedFcn(k)
test2 = test*acos(E(k));
temp = rdivide(1,(rand()-test2));
% need a diag function below
for i_d=1:Np
out(i_d,1) = temp(i_d,i_d);
end
end
% Call arrayfun.
arrayfun(@nestedFcn, gpuVector)
end

1 件のコメント

Viraj Gandhi
Viraj Gandhi 2022 年 12 月 28 日
Hey, I have the same problem. Could you find a solution?

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGPU Computing についてさらに検索

製品

タグ

質問済み:

2018 年 8 月 8 日

コメント済み:

2022 年 12 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by