Repository navigation
Avoid accidental FP64 promotion in t-SNE and HDBSCAN float kernels #8538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
csadorf
merged 5 commits into
NVIDIA:release/26.12
from
maxwbuckley:enh-avoid-fp64-promotion-umap-tsne-hdbscan
Nov 17, 2026
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
013db58
enh: avoid accidental FP64 promotion in UMAP, t-SNE and HDBSCAN kernels
maxwbuckley 90f356d
Apply pre-commit: copyright headers and clang-format
maxwbuckley 636ebb9
tsne: FunctionalSqrt returns value_t and calls sqrt(x)
maxwbuckley 629245f
Revert the UMAP changes, deferring them to a follow-up
maxwbuckley d2b59d0
Merge remote-tracking branch 'origin/release/26.12' into pr8538
maxwbuckley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
enh: avoid accidental FP64 promotion in UMAP, t-SNE and HDBSCAN kernels
Several float kernels in these three algorithms contain unsuffixed double-precision literals (`0.5`, `1e-8`, `pow(x, 2.0 * b)`) or `double` locals. In C++ these silently promote the surrounding float expression to double, so the compiler emits FP64 instructions in kernels that are otherwise entirely single-precision. This costs little on datacenter parts, but consumer GPUs have heavily reduced FP64 throughput (1/64 of FP32 on GeForce Blackwell), so the promoted arithmetic is disproportionately expensive there. Verified by compiling to sm_120 SASS and counting FP64-class opcodes (DADD/DMUL/DFMA/DSETP/MUFU.RCP64H plus F2F/I2F conversions) in kernels whose demangled signature contains no `double`. Across umap.cu, tsne.cu and the hdbscan translation units this drops from 2173 to 12; the remaining 12 are in upstream raft::random Box-Muller code. The `double` instantiations of these same templates are unaffected -- no kernel with `double` in its signature changed its FP64 count. Results are unchanged to float round-off. UMAP and HDBSCAN outputs match to ~1e-8 relative (HDBSCAN membership vectors are bit-identical); t-SNE embeddings have the same scale and structure but are not bit-reproducible against the previous build, since the changed rounding diverges over a long iterative optimisation. One change is a deliberate reduction in working precision: compute_membership_strength_kernel previously accumulated in `double` regardless of `value_t`. It now follows `value_t`, which is what the rest of the fuzzy simplicial set construction already uses. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NbvBYReympEzkFon5cCnFM
- Loading branch information
commit 013db58a19a6921c86ff65fabd29d18bf4ef8d92
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: NVIDIA/cuml
Length of output: 11328
🏁 Script executed:
Repository: NVIDIA/cuml
Length of output: 20214
🏁 Script executed:
Repository: NVIDIA/cuml
Length of output: 10693
🏁 Script executed:
Repository: NVIDIA/cuml
Length of output: 23787
🏁 Script executed:
Repository: NVIDIA/cuml
Length of output: 21114
Preserve
value_tprecision inFunctionalSqrt.When
value_tisdouble,static_cast<float>(x)rounds each force beforesqrtf.thrust::transformwrites the rounded result back to thevalue_tforce buffer, which feedsgrad_normand early stopping. Returnvalue_tand callsqrt(x)instead.🤖 Prompt for AI Agents
Source: Coding guidelines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks — the genericity point is fair, but I don't think this path is reachable today, and I don't believe the PR changes behaviour here.
value_tisfloatat every instantiation of the t-SNE code.TSNE_fitandTSNE_fit_sparseare the only entry points, and both pin it:so
static_cast<float>(x)is a no-op and there is nodoubleforce buffer forgrad_normto read back.It also isn't a change introduced here:
operator()already returnedfloatbefore this PR, so the narrowing was always present — this commit only moves it from after the root to before it, which is identical atfloat. What it does fix is the real promotion: the oldpow(x, 0.5)took thedoubleliteral overload and evaluated in FP64.Happy to switch it to returning
value_tand callingsqrt(x)as a robustness measure if a reviewer would prefer that — atfloatit still selects the float overload, so it costs nothing and keeps the no-FP64 property. Leaving it as-is for now to keep the diff to the promotion fix.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@maxwbuckley, agreed. The current t-SNE entry points instantiatevalue_tasfloatonly. Therefore, the cast is a no-op on every reachable path.FunctionalSqrt::operator()already returnedfloatbefore this change. This PR removes the unintended FP64 evaluation frompow(x, 0.5)without changing reachable behavior. I am withdrawing the finding.🐇
✏️ Learnings added
✅ Review thread resolved.
You are interacting with an AI system.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If that would still have all the benefits of the current route, then that would be my preference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked this with a standalone copy of the functor, applied through
thrust::transformas at line 752 and built with nvcc 13.2 and cuML's--expt-*/-Werror=all-warningsflags. Atvalue_t = float, returningvalue_twithsqrt(x)compiles to exactly the same SASS as the currentsqrtf(static_cast<float>(x))on sm_100 and sm_120, with no FP64 instructions. The pre-PRpow(x, 0.5)produces about 300 FP64 instructions in the same kernels. Adoubleinstantiation of thevalue_tversion also compiles and uses the doublesqrtinstead of narrowing to float. So switching keeps all the benefit of the current version.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 636ebb9:
FunctionalSqrt::operator()now returnsvalue_tand callssqrt(x). I pulled your rebase ontorelease/26.12first, so it sits on top of 90f356d.I checked that it keeps the benefit.
tsne.cubuilt with cuML's flags (-Werror=all-warnings) plus-Xptxas -warn-double-usagefor sm_120, and ptxas reports no double-precision instructions. The same flag does fire on the oldpow(x, 0.5)functor in a standalone test. On 1M floats throughthrust::transform, the new functor's output matches the old one bit for bit, and adoubleinstantiation now uses the doublesqrtrather than narrowing. This agrees with @0z5a's SASS comparison above.@jcrist the new commit needs a fresh
/ok to test 636ebb913966f427fc211286d1d9dbe36aa2458cwhen you have a moment. Thanks for the review and the rebase.🤖 Generated with Claude Code