Fix GPU precision issue in coulombic long-range kernels by replacing ucl_rsqrt(r2inv) with ucl_sqrt(rsq)#3
Draft
Fix GPU precision issue in coulombic long-range kernels by replacing ucl_rsqrt(r2inv) with ucl_sqrt(rsq)#3
Conversation
…_sqrt(rsq) Co-authored-by: ndtrung81 <5666572+ndtrung81@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix bug reported in issue #4712
Fix GPU precision issue in coulombic long-range kernels by replacing ucl_rsqrt(r2inv) with ucl_sqrt(rsq)
Oct 21, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes a systematic precision bug in GPU coulombic long-range pair styles that was causing incorrect results in single and mixed precision modes. The issue was reported in lammps#4712 for
born/coul/long/gpubut affects all GPU-accelerated coulombic long-range pair styles.Problem
The GPU kernels were computing the interatomic distance
rusing an indirect two-step approach:While mathematically correct (
1/sqrt(1/rsq) = sqrt(rsq)), this compounds approximation errors:1/rsqrsqrt(...)In single/mixed precision modes, especially with fast math optimizations (e.g., OpenCL's
native_rsqrt()), these compounded errors result in significant precision loss.Solution
Replace with direct computation:
This change:
Changes
Updated 15 GPU kernel files (29 total instances):
lal_born_coul_long.cu(2 instances - primary fix for "Out of range atoms" for the GPU accelerated BORN/COUL/LONG/CS/GPU pair_style lammps/lammps#4712)lal_born_coul_wolf.cu,lal_born_coul_wolf_cs.culal_buck_coul_long.cu,lal_charmm_long.culal_coul_long.cu,lal_coul_long_cs.cu,lal_coul_slater_long.culal_dipole_long_lj.cu,lal_lj_class2_long.culal_lj_coul_long.cu,lal_lj_coul_long_soft.culal_lj_coul_msm.cu,lal_lj_spica_long.cu,lal_lj_tip4p_long.cuAll changes follow the identical pattern:
Impact
born/coul/long/gpugave incorrect results in non-double-precision modesAffected Pair Styles
All GPU-accelerated coulombic long-range pair styles:
born/coul/long,born/coul/wolf(and cs variants)buck/coul/long,charmm/coul/longcoul/long(and cs variant),coul/slater/longdipole/long/lj,lj/class2/longlj/coul/long,lj/coul/long/soft,lj/coul/msmlj/spica/long,lj/tip4p/longFixes lammps#4712
Original prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.