Why GPU performance is worse than CPU for this code?

3 ビュー (過去 30 日間)
King Fisher
King Fisher 2011 年 11 月 27 日
clear all
close all
tic
t=9999;
X = rand( t, 'single' );
G = gpuArray( X );
isequal( gather( G ), X ) % returns true
classUnderlying( G ) % returns 'single'
G2 = G .* G
toc
tic
X = rand( t, 'single' );
G1 = X;
G3 = G1 .* G1 ;
toc
The execution time of GPU is less than CPu i5. Would anybody answer it?
  1 件のコメント
Jan
Jan 2011 年 11 月 27 日
About "clear all" see: http://www.mathworks.com/matlabcentral/answers/16484-good-programming-practice#answer_22301
Please decide, if the "GPU performance is worse than CPU", or if "the execution time of GPU is less than CPU".

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

採用された回答

Walter Roberson
Walter Roberson 2011 年 11 月 27 日
There is a lot of overhead for sending data to a GPU. It is only faster for sufficiently big matrices.
Also, in the first one you are including the "isequal" and the "classUnderlying" in the timing, neither of which is needed for the computation. It is not fair to time different sets of activities.
  1 件のコメント
King Fisher
King Fisher 2011 年 11 月 27 日
You are right, I was unfair :)

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

その他の回答 (2 件)

Jan
Jan 2011 年 11 月 27 日
Please try this:
X = rand(1e3, 1e3, 'single' );
G = gpuArray( X );
G2 = G;
tic
for i = 1:100
G2 = G2 .* G;
end
toc
tic
G = X;
G2 = X;
for i = 1:100
G2 = G2 .* G;
end
toc

cdarling
cdarling 2012 年 2 月 19 日
there is a possibility that your GPU supports parallel.gpu.GPUArray.rand(), and it would be much faster if you construct random numbers within GPU, instead of generate and copy them into GPU

カテゴリ

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