Skip to content

Use cuda::std::bit_cast in stats minmax instead of hand-rolled helper - #3095

Merged
rapids-bot[bot] merged 3 commits into
NVIDIA:mainfrom
says1117:use-cuda-std-bit-cast-in-minmax
Jul 29, 2026
Merged

Use cuda::std::bit_cast in stats minmax instead of hand-rolled helper#3095
rapids-bot[bot] merged 3 commits into
NVIDIA:mainfrom
says1117:use-cuda-std-bit-cast-in-minmax

Conversation

@says1117

Copy link
Copy Markdown
Contributor

Description

raft::stats::detail (in stats/detail/minmax.cuh) carried a local, memcpy-based
bit_cast helper with a TODO to switch to the standard facility "once we adopt
C++20 or libcu++ adds it." libcu++ now ships cuda::std::bit_cast (<cuda/std/bit>),
which works in host and device code, so this PR uses it directly and removes the
hand-rolled helper.

Changes

  • Delete the local bit_cast template and its TODO.
  • Add #include <cuda/std/bit>.
  • Use cuda::std::bit_cast at the four encode/decode call sites.

No functional or numerical behavior change — cuda::std::bit_cast is a drop-in
replacement for the previous memcpy-based reinterpretation (same size/trivially-
copyable requirements), now sourced from libcu++.

Testing

No new tests are required; this is a non-functional refactor covered by the existing
suite. Verified locally:

  • STATS_TEST builds clean.
  • All 56 MinMaxTests cases pass (28 MinMaxTestF + 28 MinMaxTestD).

The minmax encode/decode helpers used a local memcpy-based bit_cast with a TODO to switch to the standard facility once libcu++ provided it. libcu++ now ships cuda::std::bit_cast (cuda/std/bit), so use it directly and drop the custom helper.

Verified: STATS_TEST builds clean; all 56 minmax tests pass.
@copy-pr-bot

copy-pr-bot Bot commented Jul 28, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 6771d188-ff25-4591-b98f-067055b6988f

📥 Commits

Reviewing files that changed from the base of the PR and between 53f4df1 and 4ca058f.

📒 Files selected for processing (1)
  • cpp/include/raft/stats/detail/minmax.cuh
🚧 Files skipped from review as they are similar to previous changes (1)
  • cpp/include/raft/stats/detail/minmax.cuh

📝 Walkthrough

Summary by CodeRabbit

  • Refactor
    • Updated floating-point min/max numeric handling to use standard bit reinterpretation utilities.
    • Simplified the encode/decode process for float/double while keeping the same encoded-value semantics for min/max comparisons.
    • Adjusted related helper logic to maintain compatibility with existing atomic comparison behavior.

Walkthrough

The min/max statistics header replaces its local bit-cast helper with cuda::std::bit_cast, updates floating-point encoding and decoding calls, and preserves the existing sign-adjustment logic.

Changes

Min/max bit-cast migration

Layer / File(s) Summary
Replace local bit-cast helper
cpp/include/raft/stats/detail/minmax.cuh
Adds CUDA bit-cast and integer type includes, removes the local memcpy-based helper, and updates the copyright notice.
Update encoding and decoding calls
cpp/include/raft/stats/detail/minmax.cuh
Uses cuda::std::bit_cast for float and double conversions, including std::int64_t storage for double values, while retaining sign-flip mapping.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: replacing the hand-rolled bit_cast helper with cuda::std::bit_cast in stats minmax.
Description check ✅ Passed The description is directly related to the code changes and accurately summarizes the refactor and testing.
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.

🧹 Nitpick comments (1)
cpp/include/raft/stats/detail/minmax.cuh (1)

12-19: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Include <cstdint> explicitly for std::int64_t.

Line 41 now directly uses std::int64_t, but this public header does not include <cstdint>. The current build may succeed through transitive CUDA includes; consumers should not depend on that.

Proposed fix
 `#include` <cuda/std/bit>
+#include <cstdint>
 
 `#include` <limits>

Also applies to: 41-41

🤖 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/include/raft/stats/detail/minmax.cuh` around lines 12 - 19, Explicitly
include the standard <cstdint> header in the minmax header before its direct use
of std::int64_t, alongside the existing includes. Do not rely on transitive CUDA
or other includes.
🤖 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.

Nitpick comments:
In `@cpp/include/raft/stats/detail/minmax.cuh`:
- Around line 12-19: Explicitly include the standard <cstdint> header in the
minmax header before its direct use of std::int64_t, alongside the existing
includes. Do not rely on transitive CUDA or other includes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 11602e27-6bf0-419d-bc7d-bdca7dc92010

📥 Commits

Reviewing files that changed from the base of the PR and between aa9a6d5 and 53f4df1.

📒 Files selected for processing (1)
  • cpp/include/raft/stats/detail/minmax.cuh

The header uses std::int64_t directly but relied on transitive CUDA includes for it. Include <cstdint> explicitly so consumers don't depend on that. Addresses CodeRabbit review feedback on PR NVIDIA#3095.
@divyegala divyegala added improvement Improvement / enhancement to an existing function non-breaking Non-breaking change labels Jul 29, 2026

@divyegala divyegala left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the cleanup!

@divyegala

Copy link
Copy Markdown
Contributor

/ok to test 4ca058f

@divyegala

Copy link
Copy Markdown
Contributor

/merge

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

Labels

improvement Improvement / enhancement to an existing function non-breaking Non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants