Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strategy of solving many SOCPs with GPU #31

Open
yifei-liu-stat opened this issue Jan 27, 2021 · 13 comments
Open

Strategy of solving many SOCPs with GPU #31

yifei-liu-stat opened this issue Jan 27, 2021 · 13 comments

Comments

@yifei-liu-stat
Copy link

Hi,

Suppose I want to solve a sequence (a lot) of SOCPs of small or moderate size, would you recommend utilizing GPU? I can solve a single SOCP with SCS solver (called from cvxpy) with option "gpu=True", but running with GPU seems slower than running with CPU in my case (small-size SOCP). Maybe the cost of transferring data to GPU prevails. Now if I want to solve a sequence of them, then the cost of running with GPU would be much higher than the cost of running with CPU, do you have any suggestions on that?

Thank you

@bodono
Copy link
Owner

bodono commented Jan 31, 2021

The first thing is to make sure you have the latest GPU version which includes this commit which provides about 10x speedup. The other tricks would be to use warm-starting if the problems are closely related and to use the ability of cvxpy to parse the problem once and reuse it so you only pay cvxpy's cost once.

@yifei-liu-stat
Copy link
Author

I have tried to parse the problem with cvxpy.parameter() and matrix-form constraints, and they indeed provided efficiency!

On checking whether I have the latest GPU version installed, what is the difference between using setup.py and the commit you provided? I followed the gpu-version installation on scs-python:

git clone --recursive https://github.com/bodono/scs-python.git
cd scs-python
python setup.py install --scs --gpu

If there is no difference, how should I check whether I have the latest GPU version? If there is a difference, how should I use the file private.c to install the newest gpu-version scs (kind of confused on using that file)? Thanks for your help!

@bodono
Copy link
Owner

bodono commented Jan 31, 2021

OK in the scs-python directory there is an scs directory that contains the C code. cd into that directory and do a git pull, that will bring you up to the latest commit (you can make sure you see that commit in the logs by doing git log and looking for it). Then cd back up to scs-python and run the usual python setup.py install --scs --gpu.

Let me know if that makes it faster for you, hopefully should be a big speedup!

@yifei-liu-stat
Copy link
Author

yifei-liu-stat commented Jan 31, 2021

Yeah, it helped me to some extent. I was wondering why git clone didn't incorporate the latest commit on that file you mentioned. Also, do you have an available test demo where GPU can accelerate a lot? In my case, It only improved a bit, and I want to check my installation with a suitable demo. Thank you!

@bodono
Copy link
Owner

bodono commented Feb 2, 2021

The speedup depends a lot on the data structure and sparsity. You can use nvidia-smi to see how much your GPU is being used, if it's mostly idle then either it's not installed correctly or the data pattern isn't yielding much speedup.

@h-vetinari
Copy link
Contributor

The first thing is to make sure you have the latest GPU version which includes this commit which provides about 10x speedup.

Hey, I'm (co-)maintaining the conda-forge feedstock for scs, and I didn't know that CUDA is supported. That's awesome, I'll try to add GPU builds to conda-forge as well.

Looking at your quote, it sounds like it'd make a lot of sense to have a new release that includes the commit you mention? Do you have any plans to cut a new release, or would you be able to do that?

@bodono
Copy link
Owner

bodono commented Apr 12, 2021

Oh awesome, yes it would be great to get the gpu build into the conda package, thanks!

I will cut a new github release, do you also need a new pypi release?

@h-vetinari
Copy link
Contributor

I will cut a new github release, do you also need a new pypi release?

Cool thanks! Either is fine.

Are there some GPU-specific tests? Feel free to chime in in conda-forge/scs-feedstock#21 as well. 🙃

@bodono
Copy link
Owner

bodono commented Apr 12, 2021

Ok, I cut a new SCS github release and a new Pypi release (v2.1.3).

@h-vetinari
Copy link
Contributor

@h-vetinari: Are there some GPU-specific tests?

@bodono: just checking in quickly - I'd like to make sure we're not pushing out packages that don't work, but cannot find anything in this repo that would explicitly exercise the GPU paths.

The CI in conda-forge/scs-feedstock#21 runs through without having any GPUs (but I could test the produced artefacts locally with a GPU), so presumably the SCS-code switches behaviour based on whether a GPU is available?

@bodono
Copy link
Owner

bodono commented May 10, 2021

Hi @h-vetinari , thanks again for doing all this work, and sorry for the delay in responding.

This file checks if the gpu path can be imported, and if it can it will test the gpu code.

I think that's all the tests I have for gpus unfortunately. I can probably turn that into a real test, but it won't be for a little while I'm afraid.

@h-vetinari
Copy link
Contributor

Hi @bodono, thanks for the hint; took me a while to get the code to a point where I could verify it runs as desired, and the answer is still: "unsure" - I've added my current progress in #37, please take a look.

@h-vetinari
Copy link
Contributor

There's now a separate issue for GPU tests: #40

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants