GPU coordnum - #940
Conversation
8eac9a6 to
6c72b36
Compare
|
Initial performance benchmark of computing selfcoordnum of 718 atoms in NAMD:
Nsys shows that the GPU kernel is still very computationally expensive as its execution time is multiple times of the NB kernel:
I would prefer optimizing the overall calculations in a new PR or #926. Test Colvars configuration: |
|
Performance test of coordnum with Apoa1 The configuration file is
|
4307cb5 to
749cf75
Compare
ef_use_internal_pbc is not used anymore.
746569f to
ec87d1e
Compare
Assisted-by: Claude Code v2.1.222 (Opus 5)
Assisted-by: Claude Code v2.1.222 (Opus 5)
Assisted-by: Claude Code v2.1.222 (Opus 5)
Assisted-by: Claude Code v2.1.222 (Opus 5)
…berGroupToCenterKernel Assisted-by: Claude Code v2.1.222 (Opus 5)
…oupCUDAKernel1 Assisted-by: Claude Code v2.1.222 (Opus 5)
Assisted-by: Claude Code v2.1.222 (Opus 5)
Assisted-by: Claude Code v2.1.222 (Opus 5)
Assisted-by: Claude Code v2.1.222 (Opus 5)
1. Move the copy of lattice information before the copy of atoms 2. Lattice is not GPU-resident for the time being, so we just skip waiting update_lattice before entering the kernels Assisted-by: Claude Code v2.1.222 (Opus 5)
gpu_warp_size Assisted-by: Claude Code v2.1.222 (Opus 5)
Assisted-by: Claude Code v2.1.222 (Opus 5)
This commit also reverts the "pragma unroll" in 9ff3e96.
…ernel1 Assisted-by: Claude Code v2.1.222 (Opus 5)
…GroupsCUDAKernel1
jhenin
left a comment
There was a problem hiding this comment.
Excellent! Just a small question about an API change.
There was a problem hiding this comment.
Pull request overview
Adds CUDA/HIP acceleration for coordination-number CVs, including pairlists, gradients, COM handling, PBC, and NAMD integration.
Changes:
- Implements GPU kernels for coordination-number variants.
- Adds GPU buffers, synchronization, device metadata, and dummy-group handling.
- Integrates kernels into functional-test and NAMD builds.
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/functional_gpu/CMakeLists.txt | Builds coordination-number GPU kernels. |
| src/cuda/colvarcomp_coordnums_kernel.h | Declares GPU coordination APIs. |
| src/cuda/colvarcomp_coordnums_kernel.cu | Implements coordination kernels and pairlists. |
| src/cuda/colvaratoms_kernel.h | Declares weighted-gradient support. |
| src/cuda/colvaratoms_kernel.cu | Implements weighted-gradient kernel. |
| src/colvarproxy.cpp | Logs GPU device details. |
| src/colvarproxy_system.h | Makes boundary retrieval overridable. |
| src/colvarproxy_gpu.h | Exposes GPU warp size. |
| src/colvarproxy_gpu.cpp | Queries GPU warp size. |
| src/colvarmodule.h | Enables integer powers on devices. |
| src/colvarmodule.cpp | Consolidates GPU logging. |
| src/colvarcomp.cpp | Supplies PBC data to GPU CVCs. |
| src/colvarcomp_distances.cpp | Reports GPU RMSD activation. |
| src/colvarcomp_coordnums.h | Adds coordination GPU interfaces. |
| src/colvarcomp_coordnums.cpp | Integrates GPU coordination execution. |
| src/colvaratoms.cpp | Synchronizes dummy positions to GPU. |
| src/colvaratoms_gpu.h | Adds dummy and weighted-gradient APIs. |
| src/colvaratoms_gpu.cpp | Manages new GPU atom buffers. |
| src/colvar_gpu_support.h | Adds HIP device-attribute mappings. |
| namd/cudaglobalmaster/colvarproxy_cudaglobalmaster.C | Synchronizes NAMD lattice updates. |
| namd/cudaglobalmaster/CMakeLists.txt | Builds coordination kernels for NAMD. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
giacomofiorin
left a comment
There was a problem hiding this comment.
Looks great to me! I have some minor comments below, but as far as I'm concerned they can be looked at in later PRs, or not at all.
Please merge as-is if you don't have any further commits.
| // NOTE: Maybe it is better to build tile lists on GPU if we | ||
| // want to exclude non-interacting tiles periodically like NAMD. |
| } | ||
| } | ||
| } | ||
| #if 0 |
There was a problem hiding this comment.
Sorry. I missed this comment when merging. I have removed the commented code in cc0fc16.
| // with a cutoff. However, currently it is unclear to me | ||
| // whether Colvars developers would accept the idea of | ||
| // allowing re-sorting atoms dynamically in atom groups. |
There was a problem hiding this comment.
Well, this sounds like such a change would be up to someone's discretion: it really isn't.
in some variables, e.g. those that depend on reference coordinates, the order of atoms chosen by the user should be handled consistently. For most other variables, the order is immaterial and it would be okay to sort atoms based on any useful criteria!
| @@ -497,10 +493,6 @@ int colvarmodule::parse_global_params(std::string const &conf) | |||
| } | |||
| case colvarproxy_smp::smp_mode_t::gpu: { | |||
| this->log("EXPERIMENTAL GPU parallelism will be used. GPU information:\n"); | |||
There was a problem hiding this comment.
Not sure I would rely on the current order of operation to ensure that the messages in colvarproxy::setup() would be printed right after this.
| if (error_code == COLVARS_OK) { | ||
| cvmodule->log("This CV \"" + name + "\" of type \"" + function_type() + "\" will be calculated on GPU.\n"); | ||
| } | ||
| #endif |
There was a problem hiding this comment.
Nitpick: maybe this can be moved to the base class since you already have two duplicates of this for RMSD and coordNum
There was a problem hiding this comment.
Currently not every CVC has GPU implementation, so I only add logging for those that are already have (like RMSD and coordnum).

This PR should wait for #919 and #938. #919 is necessary for wrapping the distances using the internal PBC function on GPU. This PR is independent from #926.
Regarding the pairlist implementation, the GPU kernels in this PR try to match the CPU pairlist, which is slow for the time being. A better option is to implement at least a NAMD-style GPU pairlist, but since Colvars (i) does not allow atoms in an atom group to be reordered, and (ii) uses only a single cutoff for both the switching function and the pairlist, it is impossible or very diffcult to do so.