Skip to content

Move buffers into decision_forest, to avoid triggering copy constructor - #196

Merged
chyunsu3 merged 1 commit into
rapidsai:mainfrom
chyunsu3:fix_buffer_move
Aug 13, 2026
Merged

Move buffers into decision_forest, to avoid triggering copy constructor#196
chyunsu3 merged 1 commit into
rapidsai:mainfrom
chyunsu3:fix_buffer_move

Conversation

@chyunsu3

@chyunsu3 chyunsu3 commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Currently, buffer arguments to decision_forest are passed to member variables without std::move, triggering the copy constructor. This behavior is not intended, since the arguments are all rvalues (&&).

The extra buffer copies are problematic because the copy constructor uses the default stream. If the initial host-to-device copy occurs on a non-default stream, then the copy construction is unordered with respect to the host-to-device copy (i.e. may occur before or after). So the forest model may end up with garbage value.

Fix. Ensure that the buffer arguments are moved into the decision_forest. This way, we do not make extra copies after the initial host-to-device copy.

I found this bug while working on #193, since it was using a non-default stream.

@chyunsu3
chyunsu3 requested a review from a team as a code owner August 13, 2026 08:11
@chyunsu3 chyunsu3 added improvement Improves an existing functionality non-breaking Introduces a non-breaking change labels Aug 13, 2026
@chyunsu3 chyunsu3 changed the title Move buffers instead of copying, to preserve stream assignment Move buffers into decision_forest, to avoid copying Aug 13, 2026
@chyunsu3 chyunsu3 changed the title Move buffers into decision_forest, to avoid copying Move buffers into decision_forest, to avoid trigger copy constructor Aug 13, 2026
@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • Performance
    • Improved model and forest construction efficiency by reducing unnecessary data copying.
    • Preserved existing validation and device initialization behavior while transferring ownership more efficiently.

Walkthrough

The constructors now move forest buffers and variants into owned members. Validation and device initialization use the transferred buffers.

Changes

Forest construction

Layer / File(s) Summary
Decision forest buffer ownership
cpp/include/nvforest/decision_forest.hpp
The constructor move-initializes forest buffers. Validation and device initialization use the stored members.
Forest model variant ownership
cpp/include/nvforest/forest_model.hpp
The constructor move-constructs decision_forest_ from the supplied variant.

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

Mergeability Score: ⚪ Minimal · up to e70da

The change moves rvalue buffers into the model to avoid unintended copies and preserve stream ordering. The PR is merge-ready after normal checks; updating the public ownership documentation remains a minor follow-up.

Possibly related PRs

Suggested labels: improvement

Suggested reviewers: csadorf, ramitchell

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly identifies the main change: moving buffers into decision_forest to avoid unintended copies.
Description check ✅ Passed The description accurately explains the copy issue, stream-ordering risk, and move-based fix.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

coderabbitai[bot]

This comment was marked as resolved.

@chyunsu3 chyunsu3 changed the title Move buffers into decision_forest, to avoid trigger copy constructor Move buffers into decision_forest, to avoid triggering copy constructor Aug 13, 2026
@chyunsu3 chyunsu3 mentioned this pull request Aug 13, 2026
7 tasks
@chyunsu3
chyunsu3 merged commit bfc77ff into rapidsai:main Aug 13, 2026
69 checks passed
@chyunsu3
chyunsu3 deleted the fix_buffer_move branch August 13, 2026 13:29
rapids-bot Bot pushed a commit that referenced this pull request Sep 8, 2026
Extracted from #193
~~Requires #196 for the CI to pass.~~ 

- [x] Remove RAFT and RMM from CMake config
- [x] Remove the use of `raft::handle_t` and `nvforest::handle_t` and use CUDA streams directly
- [x] Use `cuda::buffer` instead of `rmm::device_buffer`. Since `cuda::buffer` requires NVCC to build, we need to use PIMPL with type erasure.
- [x] Fix all gtests
- [x] Update the Python layer
- [x] Add test coverage for using stream with wrong device.

Authors:
  - Philip Hyunsu Cho (https://github.com/chyunsu3)

Approvers:
  - Bradley Dice (https://github.com/bdice)
  - Simon Adorf (https://github.com/csadorf)

URL: #195
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CUDA/C++ improvement Improves an existing functionality non-breaking Introduces a non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants