Skip to content

Implement per-(thread, CUDA context) bounce buffer cache singleton (libcurl multi poll-based backend 3/n)#965

Merged
rapids-bot[bot] merged 42 commits into
rapidsai:mainfrom
kingcrimsontianyu:bounce-buffer-cache
Jun 26, 2026
Merged

Implement per-(thread, CUDA context) bounce buffer cache singleton (libcurl multi poll-based backend 3/n)#965
rapids-bot[bot] merged 42 commits into
rapidsai:mainfrom
kingcrimsontianyu:bounce-buffer-cache

Conversation

@kingcrimsontianyu

@kingcrimsontianyu kingcrimsontianyu commented May 24, 2026

Copy link
Copy Markdown
Contributor

This PR introduces a per-(thread, CUDA context) cache of bounce buffers with asynchronous, stream-ordered recycling. This establishes the foundation for the device-side concurrency control for the MULTI_POLL remote I/O backend. It bounds pinned-memory pressure per reactor while letting completed H2D transfers return their buffers to a free list without blocking the reactor thread.

@kingcrimsontianyu kingcrimsontianyu added the feature request New feature or request label May 24, 2026
@copy-pr-bot

copy-pr-bot Bot commented May 24, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@kingcrimsontianyu kingcrimsontianyu added breaking Introduces a breaking change and removed non-breaking Introduces a non-breaking change labels Jun 23, 2026
@kingcrimsontianyu
kingcrimsontianyu marked this pull request as ready for review June 23, 2026 17:05
@kingcrimsontianyu
kingcrimsontianyu requested review from a team as code owners June 23, 2026 17:05
* @note noexcept: any failure during the underlying push or deallocation is caught and logged.
*/
void put(void* buffer, std::size_t size);
void put(void* buffer, std::size_t size) noexcept;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This PR is marked breaking since this function is made noexcept now.

auto const n = defaults::remote_io_num_reactors();
std::optional<std::size_t> const per_reactor_max =
(max_total == 0) ? std::nullopt : std::optional{std::max<std::size_t>(max_total / n, 1)};
return new BounceBufferCachePerThreadAndContext(per_reactor_max);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think this bounce buffer cache here will be useful for the io_uring implementation in the future (in place of the bounce buffer ring approach, which enforces usage ordering and likely hurts performance). But for now let it be specific to the MULTI_POLL backend. In the future perhaps we can make BounceBufferCachePerThreadAndContext templated on an internal enum to differentiate local I/O from remote I/O.

@madsbk madsbk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Overall looks good

Comment thread cpp/src/detail/bounce_buffer_cache.cpp Outdated
Comment thread cpp/src/detail/bounce_buffer_cache.cpp
Comment thread cpp/src/detail/bounce_buffer_cache.cpp Outdated
Comment thread cpp/src/detail/bounce_buffer_cache.cpp

@bdice bdice left a comment

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.

A bit of docs clarity on “cap” would be nice. Otherwise this is awesome! Should be good to go once @madsbk’s comments are addressed.

Comment thread cpp/include/kvikio/detail/bounce_buffer_cache.hpp Outdated
@kingcrimsontianyu
kingcrimsontianyu requested a review from madsbk June 25, 2026 15:49

@madsbk madsbk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @kingcrimsontianyu, looks very good!

@kingcrimsontianyu

Copy link
Copy Markdown
Contributor Author

/merge

@rapids-bot
rapids-bot Bot merged commit 5baea46 into rapidsai:main Jun 26, 2026
64 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking Introduces a breaking change c++ Affects the C++ API of KvikIO feature request New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants