How do I construct a complex gpuArray directly on the GPU?

13 ビュー (過去 30 日間)
Kevin
Kevin 2017 年 9 月 12 日
コメント済み: Jacob Lynch August 2018 年 11 月 9 日
I am trying to initialize a complex gpuArray directly on the GPU (i.e. without first creating a complex array in host memory and then copying it over to the device).
So far the only thing I've found that works is:
foo = gpuArray(complex(0));
bar = zeros(4, 1, 'like',foo);
which seems kinda silly. Is there a way to allocate a complex gpuArray directly using something like gpuArray.zeros?

採用された回答

Edric Ellis
Edric Ellis 2017 年 9 月 12 日
None of MATLAB's build methods (the zeros, ones family) build complex arrays, so the nearest you can get is to do something like:
complex(zeros(3, 'gpuArray'))
which never allocates any host memory, and results in a complex gpuArray.
  1 件のコメント
Jacob Lynch August
Jacob Lynch August 2018 年 11 月 9 日
What about elements on the host that need to be transferred to the GPU, like
G = complex( gpuArray(V(:,1)), gpuArray(:,2) );
It seems silly to me to have those two temporary gpuArrays.

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

その他の回答 (1 件)

KSSV
KSSV 2017 年 9 月 12 日
G = gpuArray(rand(10,1)+1i*rand(10,1));
  2 件のコメント
Kevin
Kevin 2017 年 9 月 12 日
Unfortunately, this still allocates memory on the host first and then copies it over to the GPU device. I would like to initialize the array directly on the GPU.
Jacob Lynch August
Jacob Lynch August 2018 年 11 月 9 日
Alternatively:
complex(gpuArray.rand(size,type),gpuArray(size,type))

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by