Delegate logging_resource_adaptor_impl sync methods to their stream-ordered counterparts - #2445
raja-vardhan wants to merge 1 commit into
Conversation
…rdered counterparts
📝 WalkthroughSummary by CodeRabbitRelease Notes
WalkthroughIn ChangesSync method delegation in logging_resource_adaptor_impl
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (1)
cpp/src/mr/detail/logging_resource_adaptor_impl.cpp
| 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); | ||
| } |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
This doesn't change the synchronisation behaviour, which is the thing you're trying to fix.
|
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 |
Description
logging_resource_adaptor_impl::allocate_syncanddeallocate_syncduplicated the try/catch and logging bodies of their stream-ordered counterparts. This PR has them delegate to theallocate/deallocatemethods by passing a defaultcuda_stream_view{}, matching the pattern already used bylimiting_resource_adaptor_impl(introduced in #2277).cuda_stream_viewimplicitly converts tocuda::stream_ref, and both code paths already emit identical log output viaformat_stream(stream)for the default stream, so this is a behavior-preserving cleanup that removes the duplicated logic.closes #2444
Checklist