-
Notifications
You must be signed in to change notification settings - Fork 83
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
GHMC is slow #22
Comments
I've noticed a number of Were you using CUDA or OpenCL here? |
CUDA |
It certainly shouldn't be 3-4 times slower. Yes, it does require the force and energy be computed each timestep, but this shouldn't be 4x slower. One issue is that If we extended the API to add a There might be other hidden issues. |
For now, a viable route would be to adaptively tune the timestep for very high acceptance rates (e.g. 99.999%) with GHMC then lock in that timestep for VVVR. |
Could you give OpenCL a try? @peastman is certainly more familiar with the implementation details, but I believe the CUDA version interprets the various steps to launch kernels on the GPU, while the OpenCL version actually compiles the integrator into a GPU kernel. But I may be wrong---that may have been an older implementation. |
The CUDA and OpenCL versions are nearly identical. Looking at the code, I see several reasons for it to be slower. First, it applies constraints five different times (twice for positions and three times for velocities). The Langevin integrator only applies constraints once. Depending on what sort of constraints your system has, that could have a big impact on speed. Second, it requires two force/energy evaluations per time step. You use the force and energy, so it has to compute them:
Then you modify the positions, so the forces it computed before are no longer valid:
Then you use the force and energy again, so it has to recompute them:
And then you modify the positions yet again, which again invalidates the forces and means they'll have to be recomputed at the start of the next time step:
Anything that modifies the positions invalidates the forces, either addComputePerDof("x", ...), addConstrainPositions(), or potentially addUpdateContextState(). |
Is there something like a "stack" that can be used to cache the old forces, energies, and positions without massive recomputation? |
No, it only caches one set of forces at a time, then throws them out when anything causes them to become invalid. |
@kyleabeauchamp Did you want me to take a stab at speeding this up? Or are you on that? |
I think eventually we should do that. My own work is still at the level of running some basic tests on these things. |
I think the easiest way to speed up our GHMC code is to avoid re-calculating the energy with every timestep. This is easily done by doing |
We can definitely expose the number of steps as a parameter. The acceptance rate falls off with the number of steps, but there is likely an optimal, and there may be other tricks (as you've pointed out) to keep acceptance rates high. Should I submit a PR? |
Let's punt until this project is our top priority. I believe I already have this code written as well. |
Did you experiment with removing the extra velocity/position constraint steps too? I'm really curious why the |
I did not experiment with the constraint steps yet. |
Oh, there's another way to avoid this that doesn't involve doing extra hamiltonian dynamics inside GHMC (which decreases the acceptance rate): Have your |
I think I like the idea of just exposing |
My crude experiments suggest that, for a 4500 atom system, the GHMC integrator is 3 or 4 times slower than Langevin.
Given this slowdown, most users would be more inclined to just reduce their timestep and stick with Langevin. A faster implementation of GHMC might help with that.
The text was updated successfully, but these errors were encountered: