fix invalid load - #876
Merged
Merged
Conversation
sunqm
approved these changes
Aug 27, 2026
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
Fix an out-of-bounds read in
md_j_1dm_kernelwhen the finalijtile contains fewer pairs than CUDA lanes.Problem
The one-density MD J kernel loaded
pair_ij_loc[task_ij]before checking whethertask_ijrepresented a valid pair. Tail lanes are required to participate in the block-wide reduction and synchronization, but they do not correspond to realijtasks.The issue was observed for H2O+ with def2-TZVP in the
(fd|ps)quartet:npairs_ij = 2threadsx = 8tilex = 32This leaves lanes
tx=2..7without corresponding pairs. Although the finalatomicAddwas already guarded bytask_ij < npairs_ij, thepair_ij_loclookup occurred before that guard.The resulting value was normally discarded, so numerical results could remain correct. Whether the read produced a CUDA memory error depended on GPU architecture, compiler optimization, and allocation layout. The error was observed on an A100 but remained latent on another GPU.
Add a focused H2O+/def2-TZVP regression that:
selects the one-density kernel by combining the UKS spin densities;
exercises the observed (fd|ps) partial tile;
bypasses CuPy's memory pool so memory checkers can observe the actual allocation boundary;
verifies the resulting Coulomb matrix against the CPU reference.
A temporary unconditional device assertion before the original lookup confirmed that the test reaches the invalid tail lanes. The test failed with cudaErrorAssert before the fix and passed after guarding the lookup.