Aur*_*kus 6 performance matlab cuda matrix linear-algebra
我正在计算方程A*x = B,其中A是矩阵,B是矢量,x是答案(未知)矢量.
硬件规格:Intel i7 3630QM(4核),nVidia GeForce GT 640M(384 CUDA核心)
这是一个例子:
>> A=rand(5000);
>> B=rand(5000,1);
>> Agpu=gpuArray(A);
>> Bgpu=gpuArray(B);
>> tic;A\B;toc;
Elapsed time is 1.382281 seconds.
>> tic;Agpu\Bgpu;toc;
Elapsed time is 4.775395 seconds.
Run Code Online (Sandbox Code Playgroud)
不知何故GPU慢得多......为什么?它在FFT,INV,LU计算中也较慢,这应该与矩阵划分有关.
但是,GPU在矩阵乘法(相同的数据)中要快得多:
>> tic;A*B;toc;
Elapsed time is 0.014700 seconds.
>> tic;Agpu*Bgpu;toc;
Elapsed time is 0.000505 seconds.
Run Code Online (Sandbox Code Playgroud)
主要问题是为什么GPU A\B(mldivide)与CPU相比如此之慢?
更新
当A,B(在CPU上),AA,BB(在GPU上)为rand(5000)时,这里有更多结果:
>> tic;fft(A);toc;
Elapsed time is *0.117189 *seconds.
>> tic;fft(AA);toc;
Elapsed time is 1.062969 seconds.
>> tic;fft(AA);toc;
Elapsed time is 0.542242 seconds.
>> tic;fft(AA);toc;
Elapsed time is *0.229773* seconds.
>> tic;fft(AA);toc;
Run Code Online (Sandbox Code Playgroud)
大胆的时代是稳定的时期.然而GPU几乎慢了两倍.顺便说一句,为什么GPU在前两次尝试中更慢?先编译两次吗?
此外:
>> tic;sin(A);toc;
Elapsed time is *0.121008* seconds.
>> tic;sin(AA);toc;
Elapsed time is 0.020448 seconds.
>> tic;sin(AA);toc;
Elapsed time is 0.157209 seconds.
>> tic;sin(AA);toc;
Elapsed time is *0.000419 *seconds
Run Code Online (Sandbox Code Playgroud)
在两次计算之后,GPU在罪计算中的速度非常快.
那么,为什么GPU在矩阵除法,fft和类似的计算中如此缓慢,尽管它在矩阵乘法和三角函数中如此之快?问题实际上不应该是这样......在所有这些计算中GPU应该更快,因为Matlab已经发布了GPU的重叠函数(mldivide,fft).
请问有人帮我解决这些问题吗?:)
小智 4
请阅读 Matlab 如何计算解。它将帮助您理解为什么 GPU 速度较慢。
我会尝试用几句话说出来。
A*x=b 变为 L*(U*x=y)=b,L*U=A
因此 GPU 时钟比 CPU 慢,并且由于进程无法并行执行,因此 CPU 速度更快。不,除非你想出更好的方法(祝你好运!),否则 GPU 总是会变慢,除非在某些非常特殊的情况下。