sparse in cuda matlab shows bad performance

This question is simple
I understand that MATLAB solves sparse linear equations by multi wavefront method on CPU
like sparse_a Is a sparse b is a full vector then x can be computed by x=sparse_a\b
is there any method to let matlab compute sparse in gpu?
gpu_sparse_a=gpuArray(sparse_a ) b_gpu=gpuArray(b)
and then x=gpu_sparse_a\b_gpu
result shows that gpu compute sparse slower than cpu....why?is sparse in cpu transfer into gpu actually become a full matrix?

5 件のコメント

俊凯 王
俊凯 王 2021 年 11 月 5 日
C=sparse(hang_combine,lie_combine,value_combine);
C_gpu=gpuArray(C);
f_gpu=gpuArray(f);
u_gpu=C_gpu\f_gpu;
code like this ,why is this slower than cpu ? in cpu,just u=C\f
Matt J
Matt J 2021 年 11 月 5 日
編集済み: Matt J 2021 年 11 月 5 日
Is it slower? What proof/demonstration of that do you have for us?
俊凯 王
俊凯 王 2021 年 11 月 5 日
clc;clear;
cpp_parallel_mine=[];
matlab_serial=[];
time=0;
nonzero_per_row=20;
ii=[];
jj=[];
M=40*40;
N=M;
nonzero=nonzero_per_row*M;
for i=1:1:M
jj_apend=randperm(N,nonzero_per_row);
ii_apend=repmat((i), 1, nonzero_per_row);
ii=[ii,ii_apend];
jj=[jj,jj_apend];
end
row_max=max(ii);
col_max=max(jj);
sr=jj;
cpu_sparse=sparse(ii,jj,sr,row_max,col_max);
b=randi([100,200],M,1);
tic
x=cpu_sparse\b;
disp("cpu sparse solver")
toc
gpu_sparse=gpuArray(cpu_sparse);
b_gpu=gpuArray(b);
tic
x_gpu=gpu_sparse\b_gpu;
disp("gpu sparse solver");
toc
俊凯 王
俊凯 王 2021 年 11 月 5 日
easy code,randi sparse in cpu and gpu,if you run in matlab ,performance shows different,if M is larger ,Greater efficiency gap
俊凯 王
俊凯 王 2021 年 11 月 5 日
編集済み: 俊凯 王 2021 年 11 月 5 日
and i wonder if the sparse solver on the CPU uses a multi-core CPU

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

 採用された回答

Joss Knight
Joss Knight 2021 年 11 月 6 日

0 投票

It is often slower. The problem is that sparse factorizations create dense matrices...basically, it's hard to parallelize.
We generally advise to use the sparse iterative solvers, generally with preconditioners, instead. These are typically faster on GPU and CPU. Look for gmres, cgs, pcg and so on.

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGPU Computing についてさらに検索

質問済み:

2021 年 11 月 5 日

回答済み:

2021 年 11 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by