Skip to content

Enforce base resource alignment limits#2393

Merged
rapids-bot[bot] merged 2 commits into
rapidsai:mainfrom
bdice:enforce-base-resource-alignment
May 20, 2026
Merged

Enforce base resource alignment limits#2393
rapids-bot[bot] merged 2 commits into
rapidsai:mainfrom
bdice:enforce-base-resource-alignment

Conversation

@bdice
Copy link
Copy Markdown
Collaborator

@bdice bdice commented May 17, 2026

Description

Closes #2342.

Restores alignment enforcement for base CUDA memory resources by rejecting nonzero allocations whose requested alignment exceeds CUDA_ALLOCATION_ALIGNMENT. Zero-size allocations continue to return nullptr without validating the requested alignment.

Re-enables the previously disabled oversized-alignment tests for device_buffer, device_scalar, and device_uvector.

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@bdice bdice requested a review from a team as a code owner May 17, 2026 16:34
@bdice bdice requested review from miscco and rongou May 17, 2026 16:34
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 17, 2026

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: f6174b63-97a2-4e89-871f-6690dcff2896

📥 Commits

Reviewing files that changed from the base of the PR and between 4c3816a and 746c176.

📒 Files selected for processing (1)
  • cpp/src/mr/detail/cuda_async_managed_memory_resource_impl.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • cpp/src/mr/detail/cuda_async_managed_memory_resource_impl.cpp

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added an alignment validation utility to check supported alignment values.
    • Allocations now respect the requested alignment when applicable.
  • Bug Fixes

    • Memory resources now reject unsupported alignments before allocating.
    • Zero-byte allocation paths consistently return null without throwing.
  • Tests

    • Re-enabled alignment tests to verify error handling and zero-size behavior.

Walkthrough

Adds a central predicate is_supported_base_resource_alignment() and enforces it in memory resource allocate methods, forwards alignment to pool allocators for async resources, short-circuits zero-byte allocations, and re-enables alignment-related tests.

Changes

Alignment Validation and Testing

Layer / File(s) Summary
Alignment validation contract and implementation
cpp/include/rmm/aligned.hpp, cpp/src/aligned.cpp
New is_supported_base_resource_alignment() declaration and definition; SPDX year update.
Base memory resource alignment enforcement
cpp/include/rmm/mr/cuda_memory_resource.hpp, cpp/include/rmm/mr/managed_memory_resource.hpp, cpp/include/rmm/mr/pinned_host_memory_resource.hpp
Leaf memory resources add runtime alignment checks (using the new predicate) and return nullptr for zero-byte allocations where applicable; invalid alignment triggers rmm::bad_alloc.
Async and view memory resource alignment support
cpp/include/rmm/mr/cuda_async_view_memory_resource.hpp, cpp/include/rmm/mr/system_memory_resource.hpp, cpp/src/mr/detail/cuda_async_managed_memory_resource_impl.cpp, cpp/src/mr/detail/cuda_async_memory_resource_impl.cpp
Remove [[maybe_unused]] on alignment parameters, validate alignment, and forward alignment to underlying pool allocators (async paths).
Alignment validation test coverage
cpp/tests/device_buffer_tests.cu, cpp/tests/device_scalar_tests.cpp, cpp/tests/device_uvector_tests.cpp
Previously disabled large-alignment tests are enabled to assert rmm::bad_alloc for over-aligned requests; zero-sized buffer test wrapped in EXPECT_NO_THROW.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • rapidsai/rmm#2330: Introduces constructors that pass caller-requested alignment into memory resource allocate calls, which this PR's validation now enforces.
  • rapidsai/rmm#2343: Also modifies allocation call paths to handle and forward alignment through adaptors/allocators.
  • rapidsai/rmm#2337: Adjusts default device_buffer alignment handling to align with enforced validation constraints.

Suggested labels

bug, non-breaking

Suggested reviewers

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

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.73% 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 'Enforce base resource alignment limits' clearly and concisely describes the main change - restoring alignment enforcement for CUDA memory resources.
Description check ✅ Passed The description is related to the changeset, explaining the restoration of alignment enforcement and re-enabling of tests, matching the implemented changes.
Linked Issues check ✅ Passed The PR successfully addresses issue #2342 by enforcing alignment limits in base CUDA memory resources and re-enabling the previously disabled tests as required.
Out of Scope Changes check ✅ Passed All changes are directly related to the stated objective of enforcing base resource alignment limits and re-enabling associated tests, with no extraneous modifications.

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

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

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

@bdice bdice added bug Something isn't working non-breaking Non-breaking change labels May 20, 2026
@bdice bdice self-assigned this May 20, 2026
@bdice bdice moved this to In Progress in RMM Project Board May 20, 2026
@bdice
Copy link
Copy Markdown
Collaborator Author

bdice commented May 20, 2026

/merge

@rapids-bot rapids-bot Bot merged commit d7272dd into rapidsai:main May 20, 2026
87 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in RMM Project Board May 20, 2026
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 Non-breaking change

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Leaf MRs do not enforce alignment limits after device_memory_resource removal

2 participants