how can I make this code faster on the GPU?

2 ビュー (過去 30 日間)
mona
mona 2014 年 2 月 20 日
コメント済み: Michal 2014 年 3 月 3 日
Hi.. This is my first experiment with GPU. When I tried to compare the executed time between the cpu and gpu work I found that GPU code take long time . I have an INTEL i5 processor and a NVIDIA 'GeForce GT 740M' with ComputeCapability: '3.5' in my computer, and MATLAB 2013a. I used different size of images but I found same result My current code runs significantly faster on the CPU, even without parfor or spmd, than it does on the GPU. how can I make this faster on the GPU?
The following is CPU code
tic
for i=1:4:size(f,1)
for j=1:4:size(f,2)
gg(i,j)=f(i,j);
end
end;toc
Elapsed time is 0.078421 seconds.
The following is GPU code
ff=gpuArray(f);
tic
for i=1:4:size(ff,1)
for j=1:4:size(ff,2)
gg(i,j)=ff(i,j);
end end;toc
Elapsed time is 1.461808 seconds.
  3 件のコメント
Matt J
Matt J 2014 年 2 月 21 日
編集済み: Matt J 2014 年 2 月 21 日
In addition to what the others have told you, tic...toc is not a good way to measure computation time on the GPU. You should use gputimeit().
mona
mona 2014 年 2 月 25 日
@Thomas we try the code on different sizes but we found the same result

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

回答 (2 件)

Anand
Anand 2014 年 2 月 20 日
There is no operation in the above code that can take advantage of the GPU. All you are doing is looping over every 4th pixel serially. The GPU is well-suited to compute-heavy, parallelizable tasks. In order to take advantage of the GPU in MATLAB, you need to either use functions like arrayfun,<http://www.mathworks.com/help/distcomp/bsxfun.html bsxfun> which will work on multiple elements of the array in parallel or functions that are accelerated for the GPU.

Royi Avital
Royi Avital 2014 年 2 月 21 日
Hopefully, next versions of MATLAB will support OpenCL 2.0. When that happens, CPU and GPU will use the same memory space which will remove the Overhead of GPU Computing.
Assuming using CPU's from AMD which includes GPU which share the same memory with the CPU.
  1 件のコメント
Michal
Michal 2014 年 3 月 3 日
OpenCL support at next MATLAB version?? No way!! Mathworks did not express eny intention to support OpenCL in the near future.

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

カテゴリ

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