problems with @arrayfun on GPU

1 回表示 (過去 30 日間)
christian Velasquez Javier
christian Velasquez Javier 2022 年 8 月 2 日
回答済み: Joss Knight 2022 年 8 月 8 日
Hi,
I am starting to using the arrafun function with GPU capabilities (I have an NVIDIA GeForce GTX 1650 with Max-Q Design).
I am following jsut the example from matlab website
R1 = rand(2,5,4,"gpuArray");
R2 = rand(2,1,4,3,"gpuArray");
R3 = rand(1,5,4,3,"gpuArray");
R = arrayfun(@(x,y,z)(x+y.*z),R1,R2,R3);
The code above runs perfectly in the Command Window, but if I want to run this from an script or live-script I get the following error:
Index exceeds the number of array elements. Index must not exceed 0.
Some hint what is happening?
  4 件のコメント
Walter Roberson
Walter Roberson 2022 年 8 月 2 日
What name did you use for the script?
christian Velasquez Javier
christian Velasquez Javier 2022 年 8 月 2 日
Hi Walter, I used newd.m as name
I've just realized what is the problem. Apparently arrayfun for gpuArrays works in an script .m but not in a .mlx. Moreover, to run in the script scope you need to run the whole script (F5), because when I tried to run a especific section (Ctrl+Enter) the code gives an error

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

採用された回答

Joss Knight
Joss Knight 2022 年 8 月 8 日
This is a bug. I have reported it. Thanks for finding it!
In the meantime, you can work around the issue by using a local function rather than an anonymous function.
R1 = rand(2,5,4,"gpuArray");
R2 = rand(2,1,4,3,"gpuArray");
R3 = rand(1,5,4,3,"gpuArray");
R = arrayfun(@iFunc,R1,R2,R3);
function w = iFunc(x,y,z)
w = x+y.*z;
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGPU Computing についてさらに検索

タグ

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by