Filter löschen
Filter löschen

Why numel() is not accepted with a gpuArray

2 Ansichten (letzte 30 Tage)
Song Decn
Song Decn am 14 Sep. 2022
Kommentiert: Song Decn am 18 Sep. 2022
pcGpu = gpuArray(5:100);
r = arrayfun( @numel, pcGpu );
simple line of code above, although numel is supported with gpuArray, I still get following feedback:
Function passed as first input argument contains unsupported or unknown function 'numel'.
For more information see Tips.
Am I doing sth. wrong?
Thanks, Song
  5 Kommentare
Walter Roberson
Walter Roberson am 15 Sep. 2022
Are you applying numel to the entire array, or are you applying numel to each element of an array? When you use arrayfun then by definition the function is passed one element of the array.
arrayfun over a gpuArray does not support anonymous functions with captured variables.
Walter Roberson
Walter Roberson am 15 Sep. 2022
for i = 1:numel(a)
f = pcGpu + i;
end
That overwrites all of f each iteration, so if you could get it to work, the result would be the same as if you had done
i = numel(a);
f = pcGpu + numel(a);
Reminder: you can pass numel(a) in as a parameter.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 15 Sep. 2022
Bearbeitet: Walter Roberson am 15 Sep. 2022
numel is not supported inside any function run on a gpuArray by using arrayfun. The above link lists all supported functions.
Remember that arrayfun on a gpuArray runs all aspects on the gpu. Variables not specifically configured as gpuArray have to be converted to gpuArray internally because the entire function runs on the gpu.
  1 Kommentar
Song Decn
Song Decn am 18 Sep. 2022
Thanks a lot Walter. I learned a lot and now have to rewrite my code now.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu GPU Computing finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by