Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cpp/include/rapidsmpf/memory/buffer_resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,10 @@ class BufferResource : public std::enable_shared_from_this<BufferResource> {
* - @p stream is synchronized with the device buffer's current stream, and
* - the device buffer's current stream is updated to @p stream.
*
* If @p data is empty and has no stream (e.g. a default-constructed or moved-from
* `rmm::device_buffer`), no synchronization is performed and its stream is set to
* @p stream.
*
* @param data Unique pointer to the device or pinned host buffer.
* @param stream CUDA stream associated with the new Buffer. Use or synchronize with
* this stream when operating on the Buffer.
Expand Down
7 changes: 6 additions & 1 deletion cpp/src/memory/buffer_resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,12 @@ std::unique_ptr<Buffer> BufferResource::move(
);
cuda::stream_ref upstream = data->stream();
if (upstream.get() != stream.get()) {
cuda_stream_join(stream, upstream);
// Default-constructed and moved-from RMM buffers have no stream or work to join.
bool const empty_without_stream =
data->capacity() == 0 && upstream == cuda::invalid_stream;
if (!empty_without_stream) {
cuda_stream_join(stream, upstream);
}
data->set_stream(stream);
}

Expand Down
28 changes: 28 additions & 0 deletions cpp/tests/test_buffer_resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,34 @@ std::int64_t reserved_bytes(BufferResource const& br, MemoryType mem_type) {
return br.memory_available(mem_type) - br.memory_available_for_reservation(mem_type);
}

TEST(BufferResource, MoveDefaultConstructedDeviceBuffer) {
StreamPool stream_pool{1};
auto stream = stream_pool.get_stream();
auto br = BufferResource::create(rmm::mr::get_current_device_resource_ref());

auto buffer = br->move(std::make_unique<rmm::device_buffer>(), stream);

EXPECT_EQ(buffer->size, 0U);
EXPECT_EQ(buffer->stream().get(), stream.get());
EXPECT_NO_THROW(buffer->latest_write_event().host_wait());
}

TEST(BufferResource, MoveMovedFromDeviceBuffer) {
StreamPool stream_pool{1};
auto stream = stream_pool.get_stream();
auto br = BufferResource::create(rmm::mr::get_current_device_resource_ref());

auto source = std::make_unique<rmm::device_buffer>(16, stream);
auto destination = std::move(*source);

auto buffer = br->move(std::move(source), stream);

EXPECT_EQ(buffer->size, 0U);
EXPECT_EQ(buffer->stream().get(), stream.get());
EXPECT_NO_THROW(buffer->latest_write_event().host_wait());
EXPECT_EQ(destination.size(), 16U);
}

TEST(BufferResource, ReservationOverbooking) {
// Create a buffer resource that always reports 10 KiB of available device memory.
auto br = BufferResource::create(
Expand Down
Loading