Quadratic programming for GPU computing

18 visualizaciones (últimos 30 días)
rokP
rokP el 23 de Jun. de 2019
Comentada: Joss Knight el 6 de Jul. de 2019
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.

Respuestas (1)

Matt J
Matt J el 23 de Jun. de 2019
Editada: Matt J el 23 de Jun. de 2019
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 comentarios
Matt J
Matt J el 23 de Jun. de 2019
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 el 6 de Jul. de 2019
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Nonlinear Optimization en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by