Skip to content

Share reactive Voronoi assignments and add an optional CUDA backend - #1645

Open
Zhang-pchao wants to merge 2 commits into
plumed:masterfrom
Zhang-pchao:performance/reactive-voronoi-upstream
Open

Zhang-pchao wants to merge 2 commits into
plumed:masterfrom
Zhang-pchao:performance/reactive-voronoi-upstream

Conversation

@Zhang-pchao

Copy link
Copy Markdown
Contributor

When several reactive Voronoi CVs use the same centers and assigned atoms, each action currently rebuilds the same geometry and performs its own soft assignment. This PR lets compatible coordination, distance and position actions reuse that work. It also adds an optional FP64 CUDA library for the assignment and its derivatives. The scalar reductions, including the center-pair distance sum, still run on the host. This builds on #1442.

Using the backends
UNITS LENGTH=A
q: VORONOI_COORDINATION CENTERS=1,2 ASSIGNED=3,4 KAPPA=5 REFERENCE=1 POWER=2 BACKEND=CPU
d: VORONOI_DISTANCE CENTERS=1,2 ASSIGNED=3,4 KAPPA=5 REFERENCE=1 GROUP1=1,2 BACKEND=CPU
PRINT ARG=q,d FILE=COLVAR

BACKEND=CPU is the default and shares compatible work. Add NO_SHARE for independent CPU evaluation. To test the GPU, change both actions to BACKEND=CUDA. This requires the optional library and reports an error if CUDA is unavailable or the input is unsupported. BACKEND=AUTO uses CUDA when supported and falls back to CPU otherwise. CUDA supports one MPI rank with axis-aligned orthorhombic PBC or NOPBC. The plugin README covers the build and the optional CUDA_LIBRARY override.

For buffered assignments, append NLIST NL_CUTOFF=6 NL_STRIDE=10 NL_SKIN=0.5 to both actions. In this example the cutoff and skin are in Å. The stride sets the scheduled rebuild interval in steps, and the skin allows earlier rebuilds when atoms or the box move. Both backends use the same CPU-built candidate list and apply the same cutoff. Check CVs and bias forces against full assignments when choosing the cutoff.

Performance

These short DPMD benchmarks use full assignments on one V100 with one MPI rank and one host evaluation thread. All three modes use the same GPU potential and start from the same restart and OPES state. The independent CPU column uses NO_SHARE. Each time is the median of two launches with 1,000 timed steps each. Speedups use the unrounded times.

System Independent CPU (ms/step) Shared CPU (ms/step) CUDA CV (ms/step) Shared vs. independent CUDA vs. shared
58 waters 1.784 1.659 1.215 1.08× 1.37×
464 waters 52.021 45.497 3.754 1.14× 12.12×
1044 waters 261.496 229.712 12.614 1.14× 18.21×
2088 waters 1311.350 1187.994 44.381 1.10× 26.77×
Glycine + 54 waters 2.358 1.750 1.503 1.35× 1.16×
Glycine + 554 waters 80.299 35.908 2.163 2.24× 16.60×
Glycine + 1000 waters 261.333 117.758 3.135 2.22× 37.57×
Glycine + 2000 waters 1414.079 599.405 5.315 2.36× 112.77×

The larger water systems are periodic replicas, and the larger glycine systems are restrained droplets. The center-pair distance sum remains on the CPU and grows faster for the all-water selections in these benchmarks.

In a separate 58-water OPES run on one RTX 3090, both backends completed 500 ps. Mean step time went from 2.506 to 1.713 ms (1.46×). Host-side work and the number of retained pairs affect the speedup. With buffered lists on the smallest systems, shared CPU can be just as fast.

Validation

Six focused native regressions and the CPU-only and CUDA driver suites passed. Coverage includes cache invalidation, CPU/CUDA values and derivatives, automatic fallback, and neighbor-list rebuilds. The cell finite-difference test also exercises the corrected periodic image in the direct triclinic virial of VORONOI_POSITION.

I'd appreciate feedback on the BACKEND interface and how best to run the optional CUDA checks alongside the standard CPU tests.

Target release

2.11 (current master)

Type of contribution
  • Changes to code or documentation in the core or within the default modules
Copyright
  • I agree to transfer the copyright of the code I have written to the PLUMED developers or to the author of the code I am modifying.
Tests
  • Added native regression tests and optional CUDA driver checks.
  • All GitHub Actions regtests passed.

other->useCellList_==useCellList_) {
shared_=other->shared_;
++shared_->consumers;
shared_->mixedKappa=shared_->mixedKappa || shared_->firstKappa!=kappa_;
@codecov

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.29915% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.98%. Comparing base (422109d) to head (f697b5a).

Files with missing lines Patch % Lines
src/colvar/ReactiveVoronoi.cpp 96.75% 6 Missing ⚠️
src/colvar/ReactiveVoronoiCuda.h 89.79% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1645      +/-   ##
==========================================
+ Coverage   88.96%   88.98%   +0.02%     
==========================================
  Files         652      653       +1     
  Lines       81934    82139     +205     
==========================================
+ Hits        72890    73095     +205     
  Misses       9044     9044              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@carlocamilloni

Copy link
Copy Markdown
Member

Cool! One question, how does the cuda plugin interact with the others? Can you run it together with the coordination one and the same input?
Please also fix the codeql issue.

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

3 participants