How to create a sequence of numbers on the GPU

4 ビュー (過去 30 日間)
David Parks
David Parks 2016 年 1 月 21 日
編集済み: David Parks 2016 年 1 月 21 日
I want to do the follow in a new GPU Array, efficiently:
myarray = 1:100000
gpuArray(1:100000) works of course, but if I'm not wrong it's creating the large array in main memory then moving the whole thing to the GPU. I would expect that I can create the sequence of numbers on the GPU directly more efficiently, as I can do with many random numbers.

採用された回答

Edric Ellis
Edric Ellis 2016 年 1 月 21 日
The direct equivalent is to use gpuArray.colon, like so:
myarray = gpuArray.colon(1,100000);
More here in the doc about building gpuArrays.
  1 件のコメント
David Parks
David Parks 2016 年 1 月 21 日
編集済み: David Parks 2016 年 1 月 21 日
Aha! Didn't see that one, thanks! Looks like it performs nearly the same as linspace, maybe 4ish percent faster.
>> tic; for i = 1:100000; gpuArray.linspace(1,100000,100000); end; toc;
Elapsed time is 9.975085 seconds.
>> tic; for i = 1:100000; gpuArray.colon(1,100000); end; toc;
Elapsed time is 9.486463 seconds.
Doesn't look like I can go back and edit the accepted answer after the fact, drat.

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

その他の回答 (1 件)

David Parks
David Parks 2016 年 1 月 21 日
Found it.
gpuArray.linspace(1,1000,1000);
>> tic; for i = 1:10000; gpuArray(1:100000); end; toc;
Elapsed time is 2.737965 seconds.
>> tic; for i = 1:10000; gpuArray.linspace(1,100000,100000); end; toc;
Elapsed time is 0.916697 seconds.

カテゴリ

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

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by