Remove memory resources from Statistics - #1003
Conversation
|
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. |
Signed-off-by: niranda perera <niranda.perera@gmail.com>
Signed-off-by: niranda perera <niranda.perera@gmail.com>
a7bce3f to
ac296bc
Compare
Signed-off-by: niranda perera <niranda.perera@gmail.com>
There was a problem hiding this comment.
I think this file should be removed.
| @@ -135,6 +153,16 @@ class BufferResource { | |||
| */ | |||
| [[nodiscard]] rmm::host_async_resource_ref pinned_mr(); | |||
There was a problem hiding this comment.
perhaps not in this PR, but this should return a host_device_async_resource_ref, I think.
| requires cuda::mr::resource_with<T, cuda::mr::device_accessible> | ||
| [[nodiscard]] std::optional<T> device_mr_as() const noexcept { | ||
| auto resource = cuda::mr::resource_cast<T>(&device_mr_); | ||
| return resource ? std::make_optional(*resource) : std::nullopt; |
There was a problem hiding this comment.
| return resource ? std::make_optional(*resource) : std::nullopt; | |
| return resource ? *resource : std::nullopt; |
| [[nodiscard]] constexpr const std::optional<PinnedMemoryResource>& | ||
| concrete_pinned_mr() const noexcept { | ||
| return pinned_mr_; | ||
| } |
There was a problem hiding this comment.
I am bikeshedding about the names. concrete is perhaps not the best prefix?
We have device_mr_as<T> why not for symmetry pinned_mr_as<T>?
Also then, this return a const & std::optional whereas device_mr_as returns a std::optional.
Signed-off-by: niranda perera <niranda.perera@gmail.com>
…/rapidsmpf into remove-mrs-from-statistics
Signed-off-by: niranda perera <niranda.perera@gmail.com>
|
@wence- I removed those adhoc templates from the public API now. Now, methods return refs and accept resources as |
This reverts commit 2817ab6.
| if (args.enable_memory_profiler) { | ||
| log.print(ctx->statistics()->report( | ||
| stat_enabled_mr, pinned_mr, "Statistics (of the last run):" | ||
| )); | ||
| } else { | ||
| log.print(ctx->statistics()->report( | ||
| std::nullopt, std::nullopt, "Statistics (of the last run):" | ||
| )); | ||
| } |
There was a problem hiding this comment.
Let's make the MRs arguments after the header line, I think?
There was a problem hiding this comment.
Most common use was .report() or report(device_mr). I added a struct ReportArgs that gives the feeling of named-args.
| std::string report(std::string const& header = "Statistics:") const; | ||
| std::string report( | ||
| std::optional<any_device_resource> mr = std::nullopt, | ||
| std::optional<any_host_device_resource> pinned_mr = std::nullopt, |
There was a problem hiding this comment.
| std::optional<any_host_device_resource> pinned_mr = std::nullopt, | |
| std::optional<any_host_device_resource> pinned_mr = PinnedMemoryResource::Disabled, |
?
And, as suggested above, how about:
std::string report(std::string const& header = "Statistics:",
std::optional<any_device_resource> mr = std::nullopt,
std::optional<any_host_device_resource> pinned_mr = PinnedMemoryResource::Disabled);
?
| } | ||
|
|
||
| std::optional<any_host_device_resource> BufferResource::try_pinned_mr() const noexcept { | ||
| return pinned_mr_.has_value() ? std::make_optional(*pinned_mr_) : std::nullopt; |
There was a problem hiding this comment.
nit: do we need the make_optional, or is:
| return pinned_mr_.has_value() ? std::make_optional(*pinned_mr_) : std::nullopt; | |
| return pinned_mr_.has_value() ? *pinned_mr_ : std::nullopt; |
sufficient?
| template <typename T, typename... Properties> | ||
| T* get_optional_resource_as(std::optional<cuda::mr::any_resource<Properties...>>& mr) { | ||
| if (mr.has_value()) { | ||
| return cuda::mr::resource_cast<T>(&(*mr)); |
There was a problem hiding this comment.
question: What happens if the resource_cast fails?
There was a problem hiding this comment.
it returns a nullptr
| include("${rapids-cmake-dir}/cpm/package_override.cmake") | ||
| rapids_cpm_package_override("${CMAKE_CURRENT_SOURCE_DIR}/../cmake/cpm_override_packages.json") | ||
|
|
There was a problem hiding this comment.
I think you are not using this.
| def report( | ||
| self, | ||
| mr: RmmResourceAdaptor | None = None, | ||
| pinned_mr: PinnedMemoryResource | None = None, |
There was a problem hiding this comment.
question: While here should we offer access to the "header" argument from python?
There was a problem hiding this comment.
I havent seen any uses of it so far.
|
|
||
| include("${rapids-cmake-dir}/cpm/package_override.cmake") | ||
| rapids_cpm_package_override("${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/cpm_override_packages.json") | ||
|
|
Signed-off-by: niranda perera <niranda.perera@gmail.com>
| std::string report(ReportArgs report_args) const; | ||
|
|
||
| /** | ||
| * @brief Overload with all-default options. Equivalent to `report(ReportArgs{})`. | ||
| * @return Formatted statistics report. | ||
| */ | ||
| std::string report() const { | ||
| return report(ReportArgs{}); | ||
| } |
There was a problem hiding this comment.
| std::string report(ReportArgs report_args) const; | |
| /** | |
| * @brief Overload with all-default options. Equivalent to `report(ReportArgs{})`. | |
| * @return Formatted statistics report. | |
| */ | |
| std::string report() const { | |
| return report(ReportArgs{}); | |
| } | |
| std::string report(ReportArgs report_args = {}) const; |
There was a problem hiding this comment.
clang didnt like this. 🙁
| self, | ||
| RmmResourceAdaptor mr = None, | ||
| PinnedMemoryResource pinned_mr = None, | ||
| ): |
There was a problem hiding this comment.
Please allow caller to provide header as well.
Co-authored-by: Lawrence Mitchell <wence@gmx.li>
Signed-off-by: niranda perera <niranda.perera@gmail.com>
|
/merge |
`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_assert`s 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 Authors: - Niranda Perera (https://github.com/nirandaperera) - Peter Andreas Entschev (https://github.com/pentschev) Approvers: - Peter Andreas Entschev (https://github.com/pentschev) - Lawrence Mitchell (https://github.com/wence-) URL: #1009
Remove memory resources from
StatisticsconstructionStatisticsheldRmmResourceAdaptorandPinnedMemoryResourceas instance fields, tying resource lifetime to the stats object and preventing a singleStatisticsinstance from being used with different resources at report time.Solution
mr_/pinned_mr_fields and theStatistics(RmmResourceAdaptor, ...)constructor;report()andcreate_memory_recorder()now accept explicitstd::optional<any_device_resource>/std::optional<any_host_device_resource>parameters — callers supply resources at use time.try_pinned_mr()returningstd::optional<any_host_device_resource>non-throwingly; correctpinned_mr()return type tohost_device_async_resource_ref.memory/resource_types.hppwithany_device_resource/any_host_device_resourcealiases; updateRAPIDSMPF_MEMORY_PROFILEmacro to require an explicitmrargument.Closes #979
Depends on rapidsai/rapids-cmake#1008 and #985