Loop on gpu

88 ビュー (過去 30 日間)
Mate 2u
Mate 2u 2012 年 3 月 24 日
編集済み: Edric Ellis 2023 年 2 月 3 日
Hi there, for multiple cores on CPU you can use parfor. But for a loop on gpu how can you speed it up?
Any help?

採用された回答

Edric Ellis
Edric Ellis 2012 年 3 月 26 日
編集済み: Edric Ellis 2023 年 2 月 3 日
The nearest equivalent on the GPU is to use arrayfun. This implicitly loops over each element of your input gpuArray, so there's no need for an explicit parfor loop.
Have a look at this demo which shows using a while loop inside a call to arrayfun on the GPU. In this case, the arrayfun call parallelises operations on each element of a large array, and the function running on the GPU includes a for loop.
  2 件のコメント
Maniprakash Reddy Gunturu
Maniprakash Reddy Gunturu 2017 年 11 月 8 日
Answer is so helpful for me but my problem is quite different from the above problem. can you please help me to solve the below problem.
function [s,q]=initial(p,cn)
if cn<5
s=100./cn;
q=s+p;
cn(2,1)=s+2;
else
s=500./cn;
q=s+p;
cn(2,1)=s+4;
end
p=gpuArray([4;5;7;8;7;8;7;2]);
cn=gpuArray([15]);
[s,q]=arrayfun(@initial,p,cn)
my problem is similar to above code. i want to run the above code through "parallel computations using GPU".
my questions are
1. can use "ARRAYFUN" (my inputs (cn,p) have different size) to solve the above problem? i need to get "cn(i+1)" value from s(i).
2. if not how can i solve above problem through "parallel computations using GPU".
AVINABA BISWAS
AVINABA BISWAS 2020 年 5 月 16 日
Yes. I have also the similar situation. Means I have created a function and I want to call this function by using inputs which are already in gpuarray.

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

その他の回答 (0 件)

カテゴリ

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