Skip to content

Fix per-mol line search race - #355

Merged
scal444 merged 1 commit into
NVIDIA-BioNeMo:mainfrom
scal444:fix/permol-linesearch-converged-race
Oct 2, 2026
Merged

scal444 merged 1 commit into
NVIDIA-BioNeMo:mainfrom
scal444:fix/permol-linesearch-converged-race

Conversation

@scal444

@scal444 scal444 commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

This was not a correctness issue (luckily) but a performance one. Each thread in the block was writing to the same location, so if there was an exit condition from thread 0, sometimes it would be written, sometimes it wouldn't be, and the loop would continue unnecessarily.

I thought this would be drastic (1/128 chance of correct write), but apparently when all threads write the same location, the compiler aliases it to thread 0 per warp, so correct write was more like 1/4 chance.

lineSearchPostEnergy computes the line-search verdict on thread 0 only and
returns false on every other thread, but every thread of the block assigned
its return value to the shared lineSearchConverged flag. The 127 false
stores raced the single true store, so a converged line search was often
recorded as not converged. The loop then re-evaluated the energy at the
same trial step (lambda is unchanged on the converged path), reached the
same verdict and raced again, until a true store happened to survive or
MAX_LINESEARCH_ITERS was reached. The accepted step is the same either way,
but each lost verdict costs a full energy evaluation.

Only thread 0 now writes the flag; the existing barrier publishes it.
@greptile-apps

greptile-apps Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[High risk] Fixes synchronization in GPU kernel line search loop.

The PR appears safe to merge.

Summary

The PR makes thread 0 the sole writer of the per-molecule line-search convergence flag, preventing other threads from overwriting its verdict.

Reviews (1) · Last reviewed commit: "Fix racy line-search convergence flag in..."

@scal444
scal444 requested a review from evasnow1992 October 1, 2026 22:56
@scal444

scal444 commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator Author

This actually has a serious perf boost in-kernel for some cases.

@scal444

scal444 commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator Author

I've got separate WIP for the flaky tests

@evasnow1992 evasnow1992 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you for the fix! Verified locally. Glad it was only impact performance not correctness.

@scal444
scal444 merged commit e19551c into NVIDIA-BioNeMo:main Oct 2, 2026
14 of 15 checks passed
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.

2 participants