Skip to content

Drop constness in raft handle for data_model_view_t (routing) - #1241

Merged
rapids-bot[bot] merged 7 commits into
NVIDIA:mainfrom
nguidotti:fix-handle-constness
May 19, 2026
Merged

Drop constness in raft handle for data_model_view_t (routing)#1241
rapids-bot[bot] merged 7 commits into
NVIDIA:mainfrom
nguidotti:fix-handle-constness

Conversation

@nguidotti

Copy link
Copy Markdown
Contributor

Dropped the const qualifier for the raft::handle_t on the data_model_view_t (routing) due to the recent changes in raft::resources (NVIDIA/raft#3005).

Checklist

  • I am familiar with the Contributing Guidelines.
  • Testing
    • New or existing tests cover these changes
    • Added tests
    • Created an issue to follow-up
    • NA
  • Documentation
    • The documentation is up to date with these changes
    • Added new documentation
    • NA

nguidotti added 2 commits May 19, 2026 15:31
Signed-off-by: Nicolas L. Guidotti <nguidotti@nvidia.com>
…o a recent change in raft.

Signed-off-by: Nicolas L. Guidotti <nguidotti@nvidia.com>
@nguidotti nguidotti self-assigned this May 19, 2026
@nguidotti
nguidotti requested a review from a team as a code owner May 19, 2026 14:56
@nguidotti
nguidotti requested review from Kh4ster and akifcorduk May 19, 2026 14:56
@nguidotti nguidotti added bug Something isn't working breaking Introduces a breaking change labels May 19, 2026
@nguidotti nguidotti added this to the 26.06 milestone May 19, 2026
@nguidotti
nguidotti requested review from hlinsen and removed request for Kh4ster and akifcorduk May 19, 2026 14:56
@nguidotti nguidotti assigned rg20 and unassigned rg20 May 19, 2026
@nguidotti
nguidotti requested a review from rg20 May 19, 2026 14:57
@coderabbitai

coderabbitai Bot commented May 19, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

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: 5bb14429-d837-4964-81c6-2cec1fc258bd

📥 Commits

Reviewing files that changed from the base of the PR and between cba083d and a4740fe.

📒 Files selected for processing (1)
  • RAPIDS_BRANCH
✅ Files skipped from review due to trivial changes (1)
  • RAPIDS_BRANCH

📝 Walkthrough

Walkthrough

Const qualifiers removed from RAFT handle parameters and stored pointer: data_model_view now stores/returns mutable handles; generator helper functions and Cython/pxd bindings take non-const handles; a utilities call site now passes the handle pointer directly.

Changes

Handle constness propagation

Layer / File(s) Summary
Header: data_model_view declaration
cpp/include/cuopt/routing/data_model_view.hpp
Constructor parameter and stored handle_ptr_ change to raft::handle_t*; non-const get_handle_ptr() noexcept added alongside existing const overload.
Implementation: data_model_view definitions
cpp/src/routing/data_model_view.cu
Constructor and get_handle_ptr() definitions updated to accept/return mutable raft::handle_t*.
Generator templates and instantiations
cpp/src/routing/generator/generator.cu, cpp/src/routing/generator/generator.hpp
Multiple dataset and helper generator functions (coordinates, matrices, demands, vehicle types/capacities/breaks/time-windows, service-time, etc.) changed to take raft::handle_t& instead of const&; explicit instantiations and file header years updated.
Cython wrapper, pxd, and utilities usage
cpp/include/cuopt/routing/cython/cython.hpp, cpp/src/routing/utilities/cython.cu, python/cuopt/.../routing_utilities.pxd
call_generate_dataset signature changed to accept raft::handle_t&; pxd extern changed to handle_t&; call_batch_solve/stream assignment updated to pass data_models[i]->get_handle_ptr() pointer directly.
Misc: branch reference
RAPIDS_BRANCH
Branch pointer updated from main to release/26.06.

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels: breaking

Suggested reviewers:

  • tmckayus
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 8.70% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: removing const constness from raft handle in data_model_view_t routing.
Description check ✅ Passed The description explains the reason for the change (raft::resources updates) and references a specific external PR, directly relating to the changeset modifications.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
cpp/src/routing/utilities/cython.cu (1)

111-123: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Reject shared handles before mutating streams in parallel.

This loop changes the CUDA stream on each model's RAFT handle from multiple OpenMP workers. If two data_models alias the same raft::handle_t, the set_cuda_stream/restore sequence races and the solves can run on the wrong stream nondeterministically. Please enforce distinct handles up front or create a per-worker handle copy instead of mutating shared state.

One simple guard before entering the parallel region
+#include <unordered_set>
+
   const std::size_t size = data_models.size();
   std::vector<std::unique_ptr<vehicle_routing_ret_t>> list(size);
+  std::unordered_set<raft::handle_t*> seen_handles;
+  for (auto* data_model : data_models) {
+    cuopt_expects(data_model != nullptr,
+                  error_type_t::ValidationError,
+                  "data_model cannot be null");
+    auto* handle_ptr = data_model->get_handle_ptr();
+    cuopt_expects(handle_ptr != nullptr,
+                  error_type_t::ValidationError,
+                  "data_model handle cannot be null");
+    cuopt_expects(seen_handles.insert(handle_ptr).second,
+                  error_type_t::ValidationError,
+                  "call_batch_solve requires a distinct RAFT handle per data model");
+  }

As per coding guidelines, "Flag missing synchronization causing non-deterministic GPU failures" and "Flag missing input validation at library and server boundaries".

Also applies to: 152-154

🤖 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/routing/utilities/cython.cu` around lines 111 - 123, The loop mutates
each model's RAFT handle CUDA stream (data_models[i]->get_handle_ptr() and
raft::resource::set_cuda_stream) from multiple OpenMP threads, which races if
two data_models alias the same raft::handle_t; before entering the parallel
region, detect if any get_handle_ptr() pointers are duplicated and either (A)
reject/raise an error describing non-unique handles, or (B) create per-worker
raft::handle_t copies (or per-thread handles) and use those local
handles/streams in the parallel loop (use the copied handle in place of
data_models[i]->get_handle_ptr() when calling sync_stream and set_cuda_stream
and restore on the copy), ensuring device_id and stream_pool usage remain
correct; update both the loop starting at the
RAFT_CUDA_TRY(cudaSetDevice(device_id)) block and the similar block at lines
~152-154 to use the same guard/copy strategy.
🤖 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/include/cuopt/routing/data_model_view.hpp`:
- Around line 614-617: The accessor get_handle_ptr on data_model_view_t breaks
const-correctness by returning a mutable raft::handle_t* from a const method;
fix this by providing two overloads: a non-const getter raft::handle_t*
get_handle_ptr() noexcept and a const getter raft::handle_t const*
get_handle_ptr() const noexcept (leave handle_ptr_ as raft::handle_t*
handle_ptr_{nullptr}); update call sites to accept the const-pointer from const
objects or cast only where mutation is intended.

---

Outside diff comments:
In `@cpp/src/routing/utilities/cython.cu`:
- Around line 111-123: The loop mutates each model's RAFT handle CUDA stream
(data_models[i]->get_handle_ptr() and raft::resource::set_cuda_stream) from
multiple OpenMP threads, which races if two data_models alias the same
raft::handle_t; before entering the parallel region, detect if any
get_handle_ptr() pointers are duplicated and either (A) reject/raise an error
describing non-unique handles, or (B) create per-worker raft::handle_t copies
(or per-thread handles) and use those local handles/streams in the parallel loop
(use the copied handle in place of data_models[i]->get_handle_ptr() when calling
sync_stream and set_cuda_stream and restore on the copy), ensuring device_id and
stream_pool usage remain correct; update both the loop starting at the
RAFT_CUDA_TRY(cudaSetDevice(device_id)) block and the similar block at lines
~152-154 to use the same guard/copy strategy.
🪄 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: 76f94c06-143b-464b-88bf-129e6b61b558

📥 Commits

Reviewing files that changed from the base of the PR and between ef4aae7 and 5a6cfab.

📒 Files selected for processing (3)
  • cpp/include/cuopt/routing/data_model_view.hpp
  • cpp/src/routing/data_model_view.cu
  • cpp/src/routing/utilities/cython.cu

Comment thread cpp/include/cuopt/routing/data_model_view.hpp Outdated
Comment thread cpp/include/cuopt/routing/data_model_view.hpp Outdated
@mlubin

mlubin commented May 19, 2026

Copy link
Copy Markdown
Contributor

The breaking tag shouldn't be needed for C++ API changes.

Signed-off-by: Nicolas L. Guidotti <nguidotti@nvidia.com>
@nguidotti nguidotti removed the breaking Introduces a breaking change label May 19, 2026
@nguidotti

Copy link
Copy Markdown
Contributor Author

/ok to test 5ff3738

@nguidotti nguidotti added non-breaking Introduces a non-breaking change P0 labels May 19, 2026
nguidotti added 2 commits May 19, 2026 17:20
Signed-off-by: Nicolas L. Guidotti <nguidotti@nvidia.com>
@nguidotti
nguidotti requested a review from a team as a code owner May 19, 2026 15:31
@nguidotti
nguidotti requested a review from tmckayus May 19, 2026 15:31
@nguidotti

Copy link
Copy Markdown
Contributor Author

/ok to test 35cc92c

@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/routing/generator/generator.hpp`:
- Around line 106-111: The header declaration of generate_vehicle_time_windows
currently includes an unused parameter fleet_order_constraints that is not
present in the implementation or call site; remove the fleet_order_constraints
parameter from the function declaration of generate_vehicle_time_windows (in
generator.hpp) so its signature matches the definition in generator.cu and the
call site, ensuring the template parameters and other arguments (handle, params,
order_info, fleet_size) remain unchanged.
🪄 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: a342b7e9-1b2f-4cbc-9ff5-0eedd0b00a6d

📥 Commits

Reviewing files that changed from the base of the PR and between 5ff3738 and 35cc92c.

📒 Files selected for processing (5)
  • cpp/include/cuopt/routing/cython/cython.hpp
  • cpp/src/routing/generator/generator.cu
  • cpp/src/routing/generator/generator.hpp
  • cpp/src/routing/utilities/cython.cu
  • python/cuopt/cuopt/routing/structure/routing_utilities.pxd

Comment thread cpp/src/routing/generator/generator.hpp
Signed-off-by: Nicolas L. Guidotti <nguidotti@nvidia.com>
* @brief Get raft handle object containing GPU resource objects
* @return Handle object
*/
raft::handle_t* get_handle_ptr() noexcept;

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.

We should add a const overload. Maybe even have

 raft::handle_t const* get_handle_ptr() const noexcept;
 raft::handle_t* get_mutable_handle_ptr() noexcept;

In the future run we can potentially take out the ownership of the handle from data_model_view_t and pass it to solve(&handle, data_model, settings) or have an owning data_model_t

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.

There is a const overload right below. I think the non-const version should be right below it; shouldn't need a different docstring.

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.

Sounds good. I wanted to avoid silent modifications as constness of the handle during solve is a strong assumption.

@mlubin

mlubin commented May 19, 2026

Copy link
Copy Markdown
Contributor

/merge

@rapids-bot
rapids-bot Bot merged commit 60701ac into NVIDIA:main May 19, 2026
97 checks passed
@achirkin

Copy link
Copy Markdown

Many thanks for fixing this and sorry I didn't spot this before!

@nguidotti
nguidotti deleted the fix-handle-constness branch May 21, 2026 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working non-breaking Introduces a non-breaking change P0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants