Skip to content

Optimize the switching function of coordnum on GPU - #956

Open
HanatoK wants to merge 8 commits into
Colvars:masterfrom
HanatoK:opt_coordnum_switching_function
Open

Optimize the switching function of coordnum on GPU#956
HanatoK wants to merge 8 commits into
Colvars:masterfrom
HanatoK:opt_coordnum_switching_function

Conversation

@HanatoK

@HanatoK HanatoK commented Aug 20, 2026

Copy link
Copy Markdown
Member

This PR partially supersedes #926 and depends on #955.

This PR changes the template arguments of colvar::coordnum::switching_function and colvar::coordnum::compute_pair_coordnum to accept additional static_en and static_ed as static template parameters for en and ed. If any of static_en and static_ed is zero, then the dynamic en and ed would be used. This PR also instantiates commonly used (en, ed) for the GPU kernels. This PR does not include any CPU optimizations (unlike #926).

@HanatoK HanatoK self-assigned this Aug 20, 2026
@HanatoK

HanatoK commented Aug 20, 2026

Copy link
Copy Markdown
Member Author

In my intial benchmarks, this PR should be almost double the GPU speeds reported in #940 (comment) and #940 (comment).

@HanatoK
HanatoK force-pushed the opt_coordnum_switching_function branch 3 times, most recently from cfc46d0 to 269ffdc Compare September 4, 2026 16:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The valid static exponent pair (2,4) currently causes a compile-time assertion failure.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Optimizes GPU coordination-number switching functions using compile-time exponent specialization.

Changes:

  • Adds static exponent template parameters and optimized power evaluation.
  • Dispatches common (4,8) and (6,12) GPU kernel variants.
  • Improves unsupported-warp error classification.
File summaries
File Description
src/cuda/colvarcomp_coordnums_kernel.cu Selects specialized CUDA/HIP kernels.
src/colvarmodule.h Adds compile-time integer exponentiation.
src/colvarcomp_coordnums.h Implements static switching-function specialization.
Review details

Suppressed comments (1)

src/cuda/colvarcomp_coordnums_kernel.cu:1032

  • The HIP branch has the same diagnostic regression: the new message omits calc_value_coordnum_self_group, leaving only the vague text Unsupported warp size in:. Retain the function name from the prior error message.
    default: return cvmodule->error("Unsupported warp size in: " + cvm::to_str(gpu_warp_size) + "\n", COLVARS_BUG_ERROR);}        \
  • Files reviewed: 3/3 changed files
  • Comments generated: 2
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/colvarcomp_coordnums.h Outdated
Comment thread src/cuda/colvarcomp_coordnums_kernel.cu Outdated
HanatoK and others added 2 commits September 4, 2026 14:04
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@jhenin jhenin changed the title Optimize the switching function of coordnum Optimize the switching function of coordnum on GPU Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants