Skip to content

Dry Run Protocol - #2961

Merged
rapids-bot[bot] merged 120 commits into
NVIDIA:mainfrom
achirkin:fea-dry-run-protocol
Aug 28, 2026
Merged

rapids-bot[bot] merged 120 commits into
NVIDIA:mainfrom
achirkin:fea-dry-run-protocol

Conversation

@achirkin

@achirkin achirkin commented Feb 20, 2026

Copy link
Copy Markdown
Contributor

The dry run protocol defines a mechanism to simulate the execution of algorithms to get a precise estimate of the memory requirements for a real execution with the same parameters.

#include <raft/util/dry_run_memory_resource.hpp>

raft::resources res;
// auto my_function(const raft::resources& res, my_args...);
auto stats = raft::util::dry_run_execute(res, my_function, my_args...);
// stats.device_global  – peak device memory (bytes)

This PR:

  • Introduces new infrastructure: raft::util::dry_run_execute, raft::dry_run_resources, and resource::get_dry_run_flag to let callers estimate peak memory usage of any RAFT algorithm without executing GPU work.
  • Makes all public functions across all raft namespaces dry-run compliant: allocations are always visible to the tracker; CUDA work is skipped.
  • Adds a small user guide (docs/source/dry_run_protocol.md)

Note for reviewers
The PR contains a lot of small tedious changes to cover all of raft library and the tests components.
Please start reading at docs/source updates to learn more about the topic and the principles guiding these changes.

…mory

Introduce a dry-run execution framework that replaces device and host
memory resources with lightweight fake allocators to measure peak memory
usage without holding real memory.

New files:
- dry_run_memory_resource.hpp: dry_run_allocator (lock-free bump
  allocator), dry_run_device_memory_resource, dry_run_host_memory_resource,
  dry_run_resource_manager (RAII), and dry_run_execute() helper.
- dry_run_flag.hpp: boolean dry-run flag as a raft resource, allowing
  algorithms to skip kernel execution during profiling.
- tests/util/dry_run_memory_resource.cpp: unit tests.

The dry_run_allocator probes the upstream once to obtain a base address,
then atomically bumps a pointer for each allocation — no mutex, no map,
no real memory held after the initial probe.
…pinned_memory_resource

Add pinned and managed resources to the raft::resources handle to make it possible to customize / temporarily replace these resources
@achirkin achirkin self-assigned this Feb 20, 2026
@achirkin
achirkin requested review from a team as code owners February 20, 2026 12:30
@achirkin achirkin added feature request New feature or request breaking Breaking change labels Feb 20, 2026
@achirkin achirkin moved this to In Progress in Unstructured Data Processing Feb 20, 2026
Merges Remove deprecated headers (NVIDIA#2939). Conflict resolutions:
- rsvd.cuh: Use new mdspan-based raft::matrix::sqrt and reciprocal APIs
  (they have internal dry-run guards); kept cudaMemsetAsync guard
- svd.cuh: Use raft::matrix::weighted_sqrt (has internal dry-run guard)
- matrix.cuh: Accept deletion (deprecated, removed in main)

Co-authored-by: Cursor <cursoragent@cursor.com>

@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.

LGTM, thanks!

Comment on lines +43 to +44
int getUniquelabels(
bool dry_run, rmm::device_uvector<value_t>& unique, value_t* y, size_t n, cudaStream_t stream)

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.

Why add the dry_run as a first argument, and not at the end, defaulted to false?
This would spare having a second version of that function just below

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is to be very explicit in the detail namespace. At some point we should gradually refactor raft to always pass raft::resources handle everywhere and remove the need to have this argument at all.

@achirkin
achirkin dismissed huuanhhuyn’s stale review August 28, 2026 12:54

The review comments were addressed, but the reviewer is out of the office to approve the changes.

@bdice bdice 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.

One request for CMake, no comments on CI. Approved.

Comment thread cpp/tests/CMakeLists.txt Outdated
@achirkin

Copy link
Copy Markdown
Contributor Author

/merge

@rapids-bot
rapids-bot Bot merged commit 3a306e5 into NVIDIA:main Aug 28, 2026
84 checks passed
alexfallin added a commit to alexfallin/raft_mst_imp that referenced this pull request Sep 10, 2026
… mst() overload

- Merge upstream main (dry run protocol NVIDIA#2961)
- mst_solve: fold the stream argument into a handle copy; launch on the
  resources; replace thrust::sequence/cudaMemsetAsync with
  raft::linalg::map_offset; resource::sync_stream; dry-run guards
- Replace local atomic and word load/store helpers with
  raft/util/device_atomics.cuh primitives and new raft::ldg_ca/stg_wb in
  raft/util/device_loads_stores.cuh
- Gate RAFT_MST_HAS_CAS128 on host __int128; validate offsets[v] == e;
  shared mst_row_of helper
- New handle-only mst() overload; deprecate the stream-taking overload
- Tests: DryRunCompliance (exact dry-run accounting),
  DeprecatedStreamOverload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature request New feature or request non-breaking Non-breaking change

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

7 participants