Skip to content

Use PrefetchResourceAdaptor in cuml.accel - #7834

Merged
rapids-bot[bot] merged 3 commits into
NVIDIA:mainfrom
jcrist:cuml-accel-prefetch
Mar 9, 2026
Merged

rapids-bot[bot] merged 3 commits into
NVIDIA:mainfrom
jcrist:cuml-accel-prefetch

Conversation

@jcrist

@jcrist jcrist commented Feb 26, 2026 •

Copy link
Copy Markdown
Member

By default cuml.accel enables a ManagedMemoryResource, which allocates managed memory. While benchmarking some workloads, I've noticed a measurable performance improvement when wrapping this mr with a PrefetchResourceAdaptor. This adaptor schedules a prefetch of memory to the device immediately after allocation. For cuml/cuml.accel workloads this makes sense - we typically allocate an array, then call a kernel to fill it in, before returning it. This also matches some performance advice noted by other teams (and the official CUDA programming guide) that prefetching may be useful when working with managed memory.

This also more closely matches the rmm configuration used by cudf.pandas by default (see here). Note that cudf.pandas also uses a PoolMemoryResource by default, but always enables prefetching of managed memory even without the pool. My intuition is that pooling makes sense when you have many smaller allocations (like might happen with pandas), since it can amortize the upstream allocator cost across calls. cuml workloads typically do fewer and larger allocations, so I don't think investigating pooling is necessary for now.

Fixes #7846.

@jcrist jcrist self-assigned this Feb 26, 2026
@jcrist
jcrist requested a review from a team as a code owner February 26, 2026 18:29
@jcrist
jcrist requested a review from csadorf February 26, 2026 18:29
@jcrist jcrist added improvement Improvement / enhancement to an existing function non-breaking Non-breaking change cuml-accel Issues related to cuml.accel labels Feb 26, 2026
@github-actions github-actions Bot added the Cython / Python Cython or Python issue label Feb 26, 2026
@coderabbitai

coderabbitai Bot commented Feb 26, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Summary by CodeRabbit

  • Refactor

    • Improved GPU memory resource handling during acceleration initialization: more robust detection of existing memory setups to avoid redundant changes, broader recognition of pre-wrapped resources, and a more reliable path to enable pooled + prefetching managed memory for better stability and performance.
  • Tests

    • Added an integration test ensuring SVR handles a zero-support scenario correctly and produces expected constant-target predictions.

Walkthrough

Refactors install() memory-resource handling to detect and treat a PrefetchResourceAdaptor wrapping PoolMemoryResource(ManagedMemoryResource()) as already enabled, skip enabling for non-CUDA resources, and when enabling use PrefetchResourceAdaptor(PoolMemoryResource(ManagedMemoryResource())). Adds a new SVR unit test for zero supports.

Changes

Cohort / File(s) Summary
Memory Resource Handling
python/cuml/cuml/accel/core.py
Adjusts install() checks to recognize PrefetchResourceAdaptor(PoolMemoryResource(ManagedMemoryResource())) as already enabled, skips enabling for non-CudaMemoryResource, and sets resource to PrefetchResourceAdaptor(PoolMemoryResource(ManagedMemoryResource())) when enabling.
SVR Tests
python/cuml/cuml_accel_tests/integration/test_svr.py
Adds test_svr_fit_n_support_0 verifying SVR behavior with an identity input and zero supports (checks intercept_, n_support_, dual_coef_.shape, and predictions).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: introducing PrefetchResourceAdaptor in cuml.accel for managed memory resource wrapping.
Description check ✅ Passed The description is directly related to the changeset, explaining the motivation for wrapping ManagedMemoryResource with PrefetchResourceAdaptor and its performance benefits.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@jcrist

jcrist commented Mar 2, 2026

Copy link
Copy Markdown
Member Author

This is blocked by #7842.

jcrist added 3 commits March 9, 2026 16:48
By default `cuml.accel` enables a `ManagedMemoryResource`, which
allocates managed memory. While benchmarking some workloads, I've
noticed a measurable performance improvement when wrapping this mr with
a `PrefetchResourceAdaptor`. This adaptor schedules a prefetch of memory
to the device immediately after allocation. For `cuml`/`cuml.accel`
workloads this makes sense - we typically allocate an array, then call a
kernel to fill it in, before returning it. This also matches some
performance advice noted by other teams (and the official CUDA
programming guide) that prefetching may be useful when working with
managed memory.

This also more closely matches the rmm configuration used by
`cudf.pandas` by default (though they also use a `PoolMemoryResource` by
default, but always enable prefetching of managed memory even without
the pool). IIUC pooling makes sense when you have many smaller
allocations (like might happen with pandas), since it can amortize the
upstream allocator cost across calls. cuml workloads typically do fewer
and larger allocations, so I don't think investigating also enabling
pooling is necessary for now.
@jcrist
jcrist force-pushed the cuml-accel-prefetch branch from a9c6b31 to 86aeff3 Compare March 9, 2026 22:02

@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 the current code and only fix it if needed.

Inline comments:
In `@python/cuml/cuml_accel_tests/integration/test_svr.py`:
- Around line 82-89: In test_svr_fit_n_support_0 update the assertions to use
tolerance-based float comparisons (e.g., numpy allclose or pytest.approx) for
model.intercept_ and model.predict(X) instead of direct equality, avoid calling
.all() on model.n_support_ (treat it as an int or use np.array(...) then compare
to 0) and keep the shape check for model.dual_coef_ as-is; specifically, replace
exact equality checks on model.intercept_, model.predict(X) with approximate
checks and change the n_support_ assertion to handle scalar or array forms
reliably.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 15b7cf76-3e75-4893-bf35-5fe94263a11c

📥 Commits

Reviewing files that changed from the base of the PR and between a9c6b31 and 86aeff3.

📒 Files selected for processing (2)
  • python/cuml/cuml/accel/core.py
  • python/cuml/cuml_accel_tests/integration/test_svr.py

Comment thread python/cuml/cuml_accel_tests/integration/test_svr.py
@jcrist

jcrist commented Mar 9, 2026

Copy link
Copy Markdown
Member Author

/merge

@rapids-bot
rapids-bot Bot merged commit 60715ad into NVIDIA:main Mar 9, 2026
174 of 176 checks passed
@jcrist
jcrist deleted the cuml-accel-prefetch branch March 9, 2026 23:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cuml-accel Issues related to cuml.accel Cython / Python Cython or Python issue 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.

Use PrefetchResourceAdaptor with managed memory in cuml.accel

4 participants