Trying to run my code in GPU
4 ビュー (過去 30 日間)
古いコメントを表示
Hello, I am trying to run my code in GPU. I just installed parallel toolbox. Here is a part of my code:
w=zeros(1000);
A=gpuArray(w);
for z=1:3000
for i = 2:length(A)-1
for n=2:width(A)-1
A(i,n)=(A(i+1,n)+A(i-1,n)+A(i,n+1))+A(i,n-1)/4;
end
z
end
end
I don't think my code is running in GPU because the Task Manager shows GPU is not working.
And the code is running much slower than not running it in GPU.
Can someone help me fix it?
Thanks
2 件のコメント
Rik
2022 年 12 月 9 日
You probably intended to use height instead of length.
Other than that, you didn't define the array A and you're not using the array you created on the GPU, so why exactly did you expect this to work?
It also looks like your final result might be reproducible with a convolution or another array operation, although I'm not entirely certain which one exactly. The fastest loop is of course replacing the loop with array operations.
採用された回答
Matt J
2022 年 12 月 9 日
編集済み: Matt J
2022 年 12 月 9 日
Your code isn't gettng the benefit of the GPU because you are not applying any parallelized functions to your gpuArray, A. In this case, conv2() would be appropriate.
w=zeros(1000);
A=gpuArray(w);
k=[0 1 0;
1 0 1;
0 1 0]/4;
for z=1:3000
A=conv2(A,k,'valid');
end
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で GPU Computing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!