[RFC] Calculate atom groups on GPU#826
Conversation
|
In my benchmarks, when using the GPU code for atom groups, the TRPV1 RMSD simulation is about 5% slower than the CPU code. There are multiple reasons:
|
|
Thanks @HanatoK ! About user control, I think a behavior similar to the current smp flag would be good, that is, enabled by default if the hardware supports it, and can be disabled explicitly. If the value is a string, it opens the possibility for finer control, as you recently did with smp to allow for selecting the parallelization scheme. |
|
I see your point about dependency resolution, and I agree that moving to an explicit AST is better. |
|
At this point, there is only a moderate amount of code dedicated to the optimal alignment in the colvaratoms class. And the orientation CVC is already mostly equivalent to what you describe. So maybe this goal could be achieved by adapting the orientation CVC? |
We could certainly add constraints on when |
Done in 7f36ea2. |
I am not sure. The orientation CVC only gives a quaternion, but the |
That's exactly right! Just stated looking at this new PR yesterday, but I wanted to reply on this point, which is that it would require refactoring of the CVC code that we haven't done yet. I think it's okay if this PR focuses on the basic properties like centers of mass for now. |
This PR implements almost all operations in the atom group class in CUDA, including the calculations of COM and COG, optimal alignment, rotation, and the rotation derivative. If you would like to restructure the CVC code and move the optimal alignment out of the atom group class, I can adapt the GPU code path accordingly. |
|
The tests/functional_gpu/run_colvars_test_cuda.cpp can be compiled with with enabling fit gradients (commenting out Read data: Fit gradients: Apply forces: |
|
There is a race condition and I am still debugging, so I mark this PR as draft. |
edd95cc to
3856e35
Compare
The code PR has been significantly revised to merge many small memset and memcpy nodes into kernels. An updated CUDA graph of reading data is attached: |
4559320 to
12f85b8
Compare
|
The failed tests of the GPU code are: I am still looking into the issues. |
Commit 3703bb1 with also #868 should fix most of the problems except: The custom function does not work because I have not figured out how to add lepton to cmake yet. |
dependencies between CUDA graph nodes instead of the C-style macros
jhenin
left a comment
There was a problem hiding this comment.
Looking good in general!
How does this interact with scripting? I expected it to be incompatible, but there are changes to colvarscript.
This PR should not have any conflicts with scripting, but there's no way to test scripting because the CudaGlobalMaster itself does not support the traditional way of scripting. |
|
I see! Aside from the comment I made, I see no significant obstacles to merging. |
cvm::error may not be available in the construction of colvarproxy, so I have to use std::cerr to avoid potential segfaults.
Just checking that the static proxy pointer is initialized suffices. This reverts commit 8816600.
|
I've pushed a fix that's more satisfactory to me: make log() and error() check before they try to dereference the proxy pointer! Hopefully this avoids dangerous behaviour in other situations. |
giacomofiorin
left a comment
There was a problem hiding this comment.
Looks awesome! Approved following conversation offline.
Hi @giacomofiorin and @jhenin ! This WIP PR is a partial implementation of the plan discussed in #816. This PR only implements the calculation in
cvm::atom_groupin CUDA when the proxy sets the flagsupport_gputo true. The test code is in tests/functional_gpu/run_colvars_test_cuda.cpp. Needless to say, there are many still questions and issues:colvarproxy
What's the best practice to allow a proxy to declare GPU support? Currently this PR uses the(Done,support_gpuflag incolvarproxy_gpufor it but sometimes people may prefer CPU even if the proxy supports GPU. Should we also checksmp, or provide a way to set thesupport_gpuflag from the config file?smp gpuis supported)colvarmodule and colvar
colvar {...}and computes them in a single CUDA graph, and then copies the data to the host memory if necessary. The CVCs andcolvar {...}blocks are computed after that. In other words, the order of computation looks like reverse level order traversal of a tree, which is different from the CPU code. However, the current implementation relies partially on C++ exceptions, and I think it would be better to convertcolvardeps*into an AST (as disscussed in [RFC] Work towards reusable CVCs #700), and move the feature-level dependency resolution into a separate class/functor that traverses the AST.colvaratoms
colvaratomsis too heavy and the optimal alignment should be implemented as a separate CVC, and Colvars should allow referencing it in other CVCs;read_datagraph, butcvm::atom_group::read_total_forcescan be called anywhere from the CVC class, so it is difficult to know if the total forces are required beforehand. Is it possible to know the parents of an atom group requesting total forces inread_dataof the atom group?tests
How can I add tests/functional_gpu/run_colvars_test_cuda.cpp to the cmake tests?How can I compare the results of tests/functional_gpu/run_colvars_test_cuda.cpp with run_colvars_test.cpp?