Quadratic programming for GPU computing

조회 수: 18 (최근 30일)
rokP
rokP 2019년 6월 23일
댓글: Joss Knight 2019년 7월 6일
Is anybody aware of script that solves a quadratic programming or nonlinear problem written for GPUs? It would be great to have sth similar to fsolve, lsqnonlin or fmin(un)con.

답변 (1개)

Matt J
Matt J 2019년 6월 23일
편집: Matt J 2019년 6월 23일
You are free to use gpuArray variables within your objective function, and in constraint functions in the case of fmincon. Unfortunately, you are required to ensure that inputs and outputs of these functions are CPU variables, and so you must do CPU/GPU transfers at the beginning and end of each call, killing a lot of the potential speed-up of the GPU. I have pointed out this weakness to Matlab staff and was told they would look into an enhancement.
Still, you can keep any large fixed data like matrices on the GPU throughout the optimization, and that will reduce the overhead. In the example below, I was able to get a 30% acceleration on the GPU using this approach, for sufficiently large problem size, N. Note that I would never normally recommend that you use the nonlinear constraint function in fmincon to implement linear constraints. In this case, though, it is a necessary workaround to get them implemented on the GPU.
function test
N=10000; %problem size
H=eye(N);
Aeq0=ones(1,N); %CPU copy
Aeq=Aeq0;
beq=1;
options=optimoptions(@fmincon,'Display','off','SpecifyObjectiveGradient',true,...
'SpecifyConstraintGradient',true);
x0=5*rand(N,1)+10;
%% Run on CPU
objfun=@(x) objective(x,H);
confun=@(x) linconFAKE(x,Aeq0,Aeq,beq);
tic;
fmincon(objfun,x0,[],[],[],[],[],[],confun,options);
toc
%Elapsed time is 18.771326 seconds.
%% Run on GPU
[H,Aeq,beq]=deal(gpuArray(H), gpuArray(Aeq), gpuArray(beq));
objfun=@(x) objective(x,H);
confun=@(x) linconFAKE(x,Aeq0,Aeq,beq);
tic;
fmincon(objfun,x0,[],[],[],[],[],[],confun,options);
toc
%Elapsed time is 12.546122 seconds.
end
function [f,g]=objective(x,H)
g=H*x(:);
f=(x.'*g)/2;
f=gather(f);
if nargout>1
g=gather(g);
end
end
function [c,ceq,g,geq]=linconFAKE(x,Aeq0,Aeq,beq)
c=[];
ceq=gather(Aeq*x-beq);
if nargout>2
g=[];
geq=Aeq0(:); %Use CPU copy
end
end
  댓글 수: 2
Matt J
Matt J 2019년 6월 23일
rokP's reply moved here:
Thanks for the info and sharing your problem. I am using scalars within the objective function, so would not gain anything by the suggested setup. I tried to modify the function LMFsolve from file exchange to work on GPU, but there are bunch of funcs (feval, diag, any,...) that are not supported for GpGPU computing. I hope Mathworks fix it. I'll go and try it on py and openCL.
Joss Knight
Joss Knight 2019년 7월 6일
I'm reading your comment out of context, but I can respond that DIAG and ANY do support gpuArray inputs. So does feval of course, depending on what function you're evaluating.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Nonlinear Optimization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by