Efficient self-referential loop using GPU

조회 수: 1 (최근 30일)
Damiano Capocci
Damiano Capocci 2018년 2월 25일
댓글: Damiano Capocci 2018년 2월 27일
I have lots of problems using for in GPU computing becuse it take a huge amount of time (as u know). My kind of loop is particular because the step n depends from n-1 n-2 .... n-m. Here is the code which gives the idea of problem:
len_1=100000;
len_2=8;
X=zeros([1,len_1]);
X(1)= 1;
for k=1:len_1
for p=0:min(k-1,len_2)
X(k+1)=X(k+1)+j(p+1)*X(k-p)
end
end
For CPU is all ok but if I put
X=gpuArray(X);
I have trouble with time. I tried using arrayfun but thre is no way to realize the "previous-steps-dependence". So please help me.

답변 (1개)

Chandani Madnani
Chandani Madnani 2018년 2월 27일
What is 'j' in this line X(k+1)=X(k+1)+j(p+1)*X(k-p) ? What is the exact code that you have tried ? Any error messages while using gpuArray ?
  댓글 수: 1
Damiano Capocci
Damiano Capocci 2018년 2월 27일
Thank you for the answer:
1) j is an usual vector. Here on this ask i've written this kind of code but the second for can be omitted using the convolution because that operation is a convolution (in fact i realize a convlution using ifft(fft(X)*fft(j)).
2)I don't receive an error message but the amount of time required for the process is huge! So i want to try an other way to do this.
However this is the new version of the core code:
for k=1:len-1
X(k+1,l)=rem(abs(sum(ifft(fft(j(1:min(size_j:k))).*fft(X(k-min(k-1,step):k))'))),m);
end

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 GPU Computing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by