Skip to content

Initial stats cleanup#1009

Merged
rapids-bot[bot] merged 37 commits into
rapidsai:mainfrom
nirandaperera:stats-refactor
May 27, 2026
Merged

Initial stats cleanup#1009
rapids-bot[bot] merged 37 commits into
rapidsai:mainfrom
nirandaperera:stats-refactor

Conversation

@nirandaperera

@nirandaperera nirandaperera commented May 1, 2026

Copy link
Copy Markdown
Contributor

Statistics was constructible directly (make_shared<Statistics>(false) was not equal to Statistics::disabled()), MemoryRecorder held a raw Statistics* (lifetime hazard noted by an existing TODO), provider statistics() accessors returned shared_ptr by value (atomic refcount bumps on hot paths), and secondary objects like AllGather redundantly carried their own statistics_ member already reachable through the buffer resource / context.

In this PR, following changes were made

  • Make Statistics constructible only through factory methods (create(), from_options(), disabled()); the public ctor is removed and disabled() is now the canonical singleton for the disabled case.
  • Inherit Statistics from std::enable_shared_from_this so MemoryRecorder owns a shared_ptr<Statistics> instead of a raw pointer; recorder no-ops when stats are disabled.
  • Introduce a StatisticsProvider concept and have providers (BufferResource, ProgressThread, streaming::Context) return std::shared_ptr<Statistics> const& from statistics(); each provider static_asserts the concept.
  • Drop the redundant statistics parameter and statistics_ member from coll::AllGather (and its Python binding); secondary classes now derive their Statistics from the provider they already receive.

Related to #1008

Depends on #1003

@copy-pr-bot

copy-pr-bot Bot commented May 1, 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.

@nirandaperera nirandaperera mentioned this pull request May 1, 2026
3 tasks
Comment thread cmake/cpm_override_packages.json Outdated

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.

Committed in error?

Comment thread cpp/include/rapidsmpf/statistics.hpp Outdated
Comment thread cpp/include/rapidsmpf/progress_thread.hpp
@nirandaperera

Copy link
Copy Markdown
Contributor Author

@wence- this is a draft on top of #1003. Let's merge it first, then I will rebase this.

Signed-off-by: niranda perera <niranda.perera@gmail.com>

remove stats from allgather

Signed-off-by: niranda perera <niranda.perera@gmail.com>

stats provider concept

Signed-off-by: niranda perera <niranda.perera@gmail.com>

WIP

Signed-off-by: niranda perera <niranda.perera@gmail.com>
Signed-off-by: niranda perera <niranda.perera@gmail.com>
Signed-off-by: niranda perera <niranda.perera@gmail.com>
Signed-off-by: niranda perera <niranda.perera@gmail.com>
@nirandaperera nirandaperera added improvement Improves an existing functionality non-breaking Introduces a non-breaking change labels May 7, 2026
@nirandaperera nirandaperera marked this pull request as ready for review May 7, 2026 16:40
@nirandaperera nirandaperera requested review from a team as code owners May 7, 2026 16:40
@nirandaperera

nirandaperera commented May 7, 2026

Copy link
Copy Markdown
Contributor Author

@wence- this is ready for review now

Signed-off-by: niranda perera <niranda.perera@gmail.com>

@pentschev pentschev 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.

At a high-level this looks ok. Left some minor suggestions.

Comment thread cpp/include/rapidsmpf/memory/buffer_resource.hpp Outdated
Comment thread cpp/include/rapidsmpf/memory/buffer_resource.hpp Outdated
Comment thread cpp/include/rapidsmpf/statistics.hpp Outdated
@nirandaperera nirandaperera requested a review from wence- May 8, 2026 17:57
@nirandaperera nirandaperera requested a review from pentschev May 11, 2026 18:57

@pentschev pentschev 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.

This looks good to me, thanks Niranda.

Signed-off-by: niranda perera <niranda.perera@gmail.com>
Signed-off-by: niranda perera <niranda.perera@gmail.com>

@wence- wence- 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.

I think we need to think through what this design, especially around disabled statistics, looks like. Right now it seems very over-complicated and has, from my reading, somewhat inconsistent semantics.

Before writing some more code, let us figure out what it is we actually want to support (it can be different from what we support today!)

Comment thread cpp/include/rapidsmpf/statistics.hpp Outdated
Comment thread cpp/src/coll/allreduce.cpp Outdated
Comment thread cpp/src/streaming/cudf/parquet.cpp Outdated
Comment thread cpp/src/statistics.cpp
Comment thread cpp/src/statistics.cpp Outdated
Comment thread cpp/src/statistics.cpp Outdated
Comment thread cpp/src/statistics.cpp Outdated
Signed-off-by: niranda perera <niranda.perera@gmail.com>
Signed-off-by: niranda perera <niranda.perera@gmail.com>
Signed-off-by: niranda perera <niranda.perera@gmail.com>
Signed-off-by: niranda perera <niranda.perera@gmail.com>
@nirandaperera nirandaperera requested review from pentschev and wence- May 26, 2026 19:42
Signed-off-by: niranda perera <niranda.perera@gmail.com>
Signed-off-by: niranda perera <niranda.perera@gmail.com>

@wence- wence- 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.

I've had another read over this and I think it is in a good place now.

Minor nits to fix in this round before merging: where you introduce new construction arguments that provide a default value for statistics (e.g. from_options) please just require a statistics object (because of planned followup to remove statistics defaults).

Also, I think it is better to return shared_ptr const& from statistics providers. The consumer can then either get a shared_ptr or just use the method slot directly.

Comment thread cpp/include/rapidsmpf/memory/buffer_resource.hpp
Comment thread cpp/include/rapidsmpf/streaming/core/context.hpp
Comment thread cpp/include/rapidsmpf/statistics.hpp Outdated
Comment thread cpp/include/rapidsmpf/statistics.hpp Outdated
Comment thread cpp/include/rapidsmpf/statistics.hpp Outdated
Comment thread cpp/include/rapidsmpf/statistics.hpp Outdated
Comment on lines +650 to +652
* @note Returning by value provides clear ownership semantics. Callers that invoke
* `statistics()` multiple times within the same scope should cache the result
* in a local variable to avoid repeated atomic refcount operations on hot paths.

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.

So I think there was some back and forth here. TBH, I think that the statistics method should return shared_ptr<Statistics> const&.

That way, the following works "as expected" but everything is efficient.

auto br = std::make_shared<BufferResource>(...);

br->statistics()->record(); // doesn't bump refcount

auto stats = br->statistics(); // does bump refcount, because stats is a shared_ptr, not shared_ptr&

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 was thinking on the same lines here, but then decided against it, because IMO returning the value forces callers to be mindful of the lifetime aspects (and at minimum its the safest).

Comment thread cpp/src/statistics.cpp
Comment thread cpp/src/statistics.cpp
nirandaperera and others added 6 commits May 27, 2026 08:06
Co-authored-by: Lawrence Mitchell <wence@gmx.li>
Signed-off-by: niranda perera <niranda.perera@gmail.com>
Signed-off-by: niranda perera <niranda.perera@gmail.com>
Signed-off-by: niranda perera <niranda.perera@gmail.com>

@pentschev pentschev 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.

One minor docstring issue, otherwise LGTM. Thanks Niranda.

Comment thread cpp/include/rapidsmpf/streaming/core/context.hpp Outdated
Signed-off-by: niranda perera <niranda.perera@gmail.com>
Signed-off-by: niranda perera <niranda.perera@gmail.com>
Signed-off-by: niranda perera <niranda.perera@gmail.com>
@nirandaperera

Copy link
Copy Markdown
Contributor Author

/merge

@rapids-bot rapids-bot Bot merged commit 7191ed3 into rapidsai:main May 27, 2026
66 checks passed
rapids-bot Bot pushed a commit to rapidsai/cudf that referenced this pull request May 28, 2026
This has several fixes for cudf CI

- *temporarily* relax strict xfail for flaky xpass-ing tests in cudf-pandas. Tracked at #22681
- Vendor a couple of `detail` functions from RMM that were changed in rapidsai/rmm#2416
- compatibility with an API change in rapidsmpf's `Statistics` rapidsai/rapidsmpf#1009.

Authors:
  - Tom Augspurger (https://github.com/TomAugspurger)
  - Niranda Perera (https://github.com/nirandaperera)

Approvers:
  - GALI PREM SAGAR (https://github.com/galipremsagar)
  - Bradley Dice (https://github.com/bdice)
  - Yunsong Wang (https://github.com/PointKernel)

URL: #22677
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement Improves an existing functionality non-breaking Introduces a non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants