Skip to content

Delegate logging_resource_adaptor_impl sync methods to their stream-ordered counterparts - #2445

Closed
raja-vardhan wants to merge 1 commit into
rapidsai:mainfrom
raja-vardhan:fix/logging-adaptor-sync-delegation
Closed

raja-vardhan wants to merge 1 commit into
rapidsai:mainfrom
raja-vardhan:fix/logging-adaptor-sync-delegation

Conversation

@raja-vardhan

Copy link
Copy Markdown

Description

logging_resource_adaptor_impl::allocate_sync and deallocate_sync duplicated the try/catch and logging bodies of their stream-ordered counterparts. This PR has them delegate to the allocate / deallocate methods by passing a default cuda_stream_view{}, matching the pattern already used by limiting_resource_adaptor_impl (introduced in #2277).

cuda_stream_view implicitly converts to cuda::stream_ref, and both code paths already emit identical log output via format_stream(stream) for the default stream, so this is a behavior-preserving cleanup that removes the duplicated logic.

closes #2444

Checklist

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

@copy-pr-bot

copy-pr-bot Bot commented Jun 14, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

Release Notes

  • Refactor
    • Improved consistency in resource allocation and deallocation operations by aligning synchronous behavior with asynchronous variants, ensuring unified logging and formatting across both operation types.

Walkthrough

In logging_resource_adaptor_impl.cpp, allocate_sync and deallocate_sync are refactored to delegate directly to allocate(cuda_stream_view{}, ...) and deallocate(cuda_stream_view{}, ...), removing 12 lines of duplicated try/catch and spdlog formatting logic.

Changes

Sync method delegation in logging_resource_adaptor_impl

Layer / File(s) Summary
allocate_sync/deallocate_sync forward to stream-ordered methods
cpp/src/mr/detail/logging_resource_adaptor_impl.cpp
Both sync methods are reduced to single forwarding calls into the existing stream-ordered allocate/deallocate with a default cuda_stream_view{}, eliminating the duplicated inline try/catch and logging/formatting bodies.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Suggested labels

non-breaking

Suggested reviewers

  • vyasr
  • davidwendt
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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 accurately summarizes the main refactoring: delegating sync methods to stream-ordered counterparts.
Description check ✅ Passed The description clearly explains the code duplication issue and the delegation solution, referencing the linked issue #2444 and pattern from #2277.
Linked Issues check ✅ Passed The PR successfully implements the requirements from #2444: sync methods now delegate to stream-ordered counterparts using default cuda_stream_view{}, eliminating duplication while preserving behavior.
Out of Scope Changes check ✅ Passed All changes are within scope, focusing solely on refactoring sync method delegation in logging_resource_adaptor_impl to match the established pattern.

✏️ 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.

@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/mr/detail/logging_resource_adaptor_impl.cpp`:
- Around line 27-30: The `allocate_sync` method in
`logging_resource_adaptor_impl::allocate_sync` delegates to the stream-ordered
`allocate` function but fails to synchronize the stream before returning, making
the method asynchronous instead of truly synchronous as its contract requires.
Fix this by capturing the cuda_stream_view used in the allocate call, and after
the allocate call returns, explicitly call synchronize() on the stream before
returning the pointer to ensure the GPU allocation is complete before the caller
gains access to the memory.
🪄 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: 60812d39-adb1-4701-8c9f-b5065af04778

📥 Commits

Reviewing files that changed from the base of the PR and between 9ad6c33 and 85e3b82.

📒 Files selected for processing (1)
  • cpp/src/mr/detail/logging_resource_adaptor_impl.cpp

Comment on lines 27 to 30
void* logging_resource_adaptor_impl::allocate_sync(std::size_t bytes, std::size_t alignment)
{
auto const stream = cuda_stream_view{};
try {
auto const ptr = upstream_mr_.allocate(stream, bytes, alignment);
logger_->info("allocate,%p,%zu,%s", ptr, bytes, rmm::detail::format_stream(stream));
return ptr;
} catch (...) {
logger_->info("allocate failure,%p,%zu,%s", nullptr, bytes, rmm::detail::format_stream(stream));
throw;
}
return allocate(cuda_stream_view{}, bytes, alignment);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

CRITICAL: Missing stream synchronization in allocate_sync

The synchronous allocation contract requires blocking until the GPU allocation is complete. The current implementation delegates to the stream-ordered allocate but returns immediately without synchronizing, making this method asynchronous rather than synchronous.

Compare to the base class pattern in stream_ordered_memory_resource.hpp (lines 164-170):

auto const stream = cuda_stream_view{};
void* ptr = allocate(stream, bytes, alignment);
stream.synchronize();  // Required!
return ptr;

Why this matters: Callers of allocate_sync expect the allocation to be complete on return. Without synchronization, accessing the memory can race with ongoing GPU operations, causing non-deterministic failures.

🔒 Correct implementation with synchronization
 void* logging_resource_adaptor_impl::allocate_sync(std::size_t bytes, std::size_t alignment)
 {
-  return allocate(cuda_stream_view{}, bytes, alignment);
+  auto const stream = cuda_stream_view{};
+  void* ptr = allocate(stream, bytes, alignment);
+  stream.synchronize();
+  return ptr;
 }
🤖 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/mr/detail/logging_resource_adaptor_impl.cpp` around lines 27 - 30,
The `allocate_sync` method in `logging_resource_adaptor_impl::allocate_sync`
delegates to the stream-ordered `allocate` function but fails to synchronize the
stream before returning, making the method asynchronous instead of truly
synchronous as its contract requires. Fix this by capturing the cuda_stream_view
used in the allocate call, and after the allocate call returns, explicitly call
synchronize() on the stream before returning the pointer to ensure the GPU
allocation is complete before the caller gains access to the memory.

auto const stream = cuda_stream_view{};
logger_->info("free,%p,%zu,%s", ptr, bytes, rmm::detail::format_stream(stream));
upstream_mr_.deallocate(stream, ptr, bytes, alignment);
deallocate(cuda_stream_view{}, ptr, bytes, alignment);

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.

This is also wrong: it doesn't synchronise, so it doesn't change the stream synchronisation behaviour at all.

Please follow the pattern in, for example, cuda_memory_resource_impl to see a correct pattern to apply.

logger_->info("allocate failure,%p,%zu,%s", nullptr, bytes, rmm::detail::format_stream(stream));
throw;
}
return allocate(cuda_stream_view{}, bytes, alignment);

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.

This doesn't change the synchronisation behaviour, which is the thing you're trying to fix.

@wence-

wence- commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

I did a quick audit and it turns out we have the same problem in many adaptors, so I am closing this, in favour of #2449

@wence- wence- closed this Jun 17, 2026
@github-project-automation github-project-automation Bot moved this from Review to Done in RMM Project Board Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[FEA] Delegate logging_resource_adaptor_impl sync methods to their stream-ordered counterparts

2 participants