Skip to content

Fix FastIntDiv tparam - #8299

Merged
rapids-bot[bot] merged 1 commit into
NVIDIA:mainfrom
aamijar:fix-FastIntDiv-tparam
Jun 29, 2026
Merged

Fix FastIntDiv tparam#8299
rapids-bot[bot] merged 1 commit into
NVIDIA:mainfrom
aamijar:fix-FastIntDiv-tparam

Conversation

@aamijar

@aamijar aamijar commented Jun 29, 2026

Copy link
Copy Markdown
Member

Add explicit template parameters for FastIntDiv, follow up to NVIDIA/raft#3059.

@aamijar
aamijar requested a review from a team as a code owner June 29, 2026 16:00
@aamijar
aamijar requested review from lowener and viclafargue June 29, 2026 16:00
@aamijar aamijar changed the title Fix FastIntDiv tparam Fix FastIntDiv tparam Jun 29, 2026
@aamijar aamijar added non-breaking Non-breaking change bug Something isn't working labels Jun 29, 2026
@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved consistency in soft clustering calculations, helping selected-cluster counts and distance handling behave more reliably.
    • Updated kernel parameter handling to better match the expected value type, reducing the risk of type-related issues during GPU execution.
    • Refreshed copyright year ranges.

Walkthrough

FastIntDiv template instantiations in the HDBSCAN soft clustering kernel declarations and call sites are made explicit by changing FastIntDiv to FastIntDiv<value_idx>, with matching static_cast<value_idx> at call sites. The copyright year is also updated to 2026.

Changes

FastIntDiv explicit template parameter typing

Layer / File(s) Summary
merge_height_kernel parameter type fix
cpp/src/hdbscan/detail/kernels/soft_clustering.cuh
Both overloads change the n parameter from raft::util::FastIntDiv to raft::util::FastIntDiv<value_idx>; copyright year updated to 2026.
Call-site FastIntDiv<value_idx> construction
cpp/src/hdbscan/detail/soft_clustering.cuh
reduction_op divisor and both merge_height_kernel launches updated to construct FastIntDiv<value_idx> with explicit static_cast<value_idx>(n_selected_clusters).

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly reflects the main change: making the FastIntDiv template parameter explicit.
Description check ✅ Passed The description is directly related to the changeset and matches the stated FastIntDiv template update.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cpp/src/hdbscan/detail/soft_clustering.cuh`:
- Around line 175-183: Guard the narrowing of n_selected_clusters before
launching merge_height_kernel and the other affected entry point in
soft_clustering.cuh: both currently pass a size_t through static_cast<value_idx>
for the kernel count and FastIntDiv divisor, which can truncate large values and
break indexing. Replace the unchecked cast with
ML::narrow_cast<value_idx>(n_selected_clusters) at the call sites (or widen the
API if value_idx cannot safely hold the full range), and use the narrowed value
consistently for the launch arguments in merge_height_kernel and the
corresponding second launch site.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 0c1bb20f-834c-462b-8037-faa97ee25d71

📥 Commits

Reviewing files that changed from the base of the PR and between 2c1989f and 9132224.

📒 Files selected for processing (2)
  • cpp/src/hdbscan/detail/kernels/soft_clustering.cuh
  • cpp/src/hdbscan/detail/soft_clustering.cuh

Comment on lines +175 to +183
merge_height_kernel<<<n_blocks, tpb, 0, stream>>>(
merge_heights,
lambdas,
index_into_children,
parents,
m,
static_cast<value_idx>(n_selected_clusters),
raft::util::FastIntDiv<value_idx>(static_cast<value_idx>(n_selected_clusters)),
selected_clusters);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

HIGH: Guard the size_tvalue_idx cast before these launches.

Both entry points take n_selected_clusters as size_t, but the new launch arguments narrow it with static_cast<value_idx> for both the kernel count and the FastIntDiv divisor. If that count ever exceeds value_idx, the kernel sees a truncated divisor/count and its row/column indexing becomes invalid.

Suggested fix
+  auto n_selected_clusters_idx = ML::narrow_cast<value_idx>(n_selected_clusters);
   merge_height_kernel<<<n_blocks, tpb, 0, stream>>>(
     merge_heights,
     lambdas,
     ...
-    static_cast<value_idx>(n_selected_clusters),
-    raft::util::FastIntDiv<value_idx>(static_cast<value_idx>(n_selected_clusters)),
+    n_selected_clusters_idx,
+    raft::util::FastIntDiv<value_idx>(n_selected_clusters_idx),
     selected_clusters);

As per path instructions, host-side count/dimension narrowing must use ML::narrow_cast<...>(...) or widen the API.

Also applies to: 281-291

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cpp/src/hdbscan/detail/soft_clustering.cuh` around lines 175 - 183, Guard the
narrowing of n_selected_clusters before launching merge_height_kernel and the
other affected entry point in soft_clustering.cuh: both currently pass a size_t
through static_cast<value_idx> for the kernel count and FastIntDiv divisor,
which can truncate large values and break indexing. Replace the unchecked cast
with ML::narrow_cast<value_idx>(n_selected_clusters) at the call sites (or widen
the API if value_idx cannot safely hold the full range), and use the narrowed
value consistently for the launch arguments in merge_height_kernel and the
corresponding second launch site.

Source: Path instructions

@jcrist jcrist left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

:shipit:

@jcrist

jcrist commented Jun 29, 2026

Copy link
Copy Markdown
Member

/merge

@rapids-bot
rapids-bot Bot merged commit 637161b into NVIDIA:main Jun 29, 2026
112 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working CUDA/C++ non-breaking Non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants