From 6c904f7b960c3b4944ea19281a6c7e0e16b55275 Mon Sep 17 00:00:00 2001 From: Mark Harris <783069+harrism@users.noreply.github.com> Date: Tue, 23 Jan 2024 20:27:54 +1100 Subject: [PATCH] Make device_memory_resource::do_get_mem_info() and supports_get_mem_info() nonvirtual. Remove derived implementations and calls in RMM (#1430) Closes #1426 As part of #1388, this PR contributes to deprecating and removing all `get_mem_info` functionality from memory resources. This first PR makes these methods optional without deprecating them. - Makes `rmm::mr::device_memory_resource::supports_get_mem_info()` nonvirtual (and always return false) - Makes `rmm::mr::device_memory_resource::do_get_mem_info()` nonvirtual (and always return `{0, 0}`). - Removes all derived implementations of the above. - Removes all calls to the above. Authors: - Mark Harris (https://github.com/harrism) Approvers: - Bradley Dice (https://github.com/bdice) - Vyas Ramasubramani (https://github.com/vyasr) URL: https://github.com/rapidsai/rmm/pull/1430 --- .../utilities/simulated_memory_resource.hpp | 21 +-------------- .../mr/device/aligned_resource_adaptor.hpp | 26 ------------------- .../rmm/mr/device/arena_memory_resource.hpp | 19 -------------- .../rmm/mr/device/binning_memory_resource.hpp | 21 --------------- .../mr/device/callback_memory_resource.hpp | 8 +----- .../mr/device/cuda_async_memory_resource.hpp | 20 -------------- .../cuda_async_view_memory_resource.hpp | 20 -------------- .../rmm/mr/device/cuda_memory_resource.hpp | 24 +---------------- .../rmm/mr/device/device_memory_resource.hpp | 7 +++-- .../failure_callback_resource_adaptor.hpp | 26 +------------------ .../mr/device/fixed_size_memory_resource.hpp | 23 +--------------- .../mr/device/limiting_resource_adaptor.hpp | 24 ----------------- .../mr/device/logging_resource_adaptor.hpp | 26 +------------------ .../rmm/mr/device/managed_memory_resource.hpp | 26 +------------------ include/rmm/mr/device/owning_wrapper.hpp | 24 +---------------- .../rmm/mr/device/pool_memory_resource.hpp | 24 +---------------- .../mr/device/statistics_resource_adaptor.hpp | 25 +----------------- .../device/thread_safe_resource_adaptor.hpp | 26 +------------------ .../mr/device/tracking_resource_adaptor.hpp | 25 +----------------- .../rmm/mr/host/pinned_memory_resource.hpp | 20 -------------- tests/device_check_resource_adaptor.hpp | 13 +--------- tests/mock_resource.hpp | 2 -- tests/mr/device/adaptor_tests.cpp | 16 +----------- tests/mr/device/aligned_mr_tests.cpp | 6 ----- tests/mr/device/arena_mr_tests.cpp | 4 --- tests/mr/device/failure_callback_mr_tests.cpp | 6 ----- tests/mr/device/mr_tests.cpp | 25 ------------------ tests/mr/device/pool_mr_tests.cpp | 1 - 28 files changed, 19 insertions(+), 489 deletions(-) diff --git a/benchmarks/utilities/simulated_memory_resource.hpp b/benchmarks/utilities/simulated_memory_resource.hpp index b7965a021..00f6a5649 100644 --- a/benchmarks/utilities/simulated_memory_resource.hpp +++ b/benchmarks/utilities/simulated_memory_resource.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021, NVIDIA CORPORATION. + * Copyright (c) 2020-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -59,13 +59,6 @@ class simulated_memory_resource final : public device_memory_resource { */ [[nodiscard]] bool supports_streams() const noexcept override { return false; } - /** - * @brief Query whether the resource supports the get_mem_info API. - * - * @return false - */ - [[nodiscard]] bool supports_get_mem_info() const noexcept override { return false; } - private: /** * @brief Allocates memory of size at least `bytes`. @@ -95,18 +88,6 @@ class simulated_memory_resource final : public device_memory_resource { */ void do_deallocate(void* ptr, std::size_t, cuda_stream_view) override {} - /** - * @brief Get free and available memory for memory resource. - * - * @param stream to execute on. - * @return std::pair containing free_size and total_size of memory. - */ - [[nodiscard]] std::pair do_get_mem_info( - cuda_stream_view stream) const override - { - return std::make_pair(0, 0); - } - char* begin_{}; char* end_{}; }; diff --git a/include/rmm/mr/device/aligned_resource_adaptor.hpp b/include/rmm/mr/device/aligned_resource_adaptor.hpp index be7c3036c..dda510e52 100644 --- a/include/rmm/mr/device/aligned_resource_adaptor.hpp +++ b/include/rmm/mr/device/aligned_resource_adaptor.hpp @@ -96,16 +96,6 @@ class aligned_resource_adaptor final : public device_memory_resource { return upstream_->supports_streams(); } - /** - * @brief Query whether the resource supports the get_mem_info API. - * - * @return bool true if the upstream resource supports get_mem_info, false otherwise. - */ - [[nodiscard]] bool supports_get_mem_info() const noexcept override - { - return upstream_->supports_get_mem_info(); - } - /** * @brief The default alignment used by the adaptor. */ @@ -183,22 +173,6 @@ class aligned_resource_adaptor final : public device_memory_resource { alignment_ == cast->alignment_ && alignment_threshold_ == cast->alignment_threshold_; } - /** - * @brief Get free and available memory from upstream resource. - * - * The free size may not be fully allocatable because of alignment requirements. - * - * @throws rmm::cuda_error if unable to retrieve memory info. - * - * @param stream Stream on which to get the mem info. - * @return std::pair containing free_size and total_size of memory - */ - [[nodiscard]] std::pair do_get_mem_info( - cuda_stream_view stream) const override - { - return upstream_->get_mem_info(stream); - } - /** * @brief Calculate the allocation size needed from upstream to account for alignments of both the * size and the base pointer. diff --git a/include/rmm/mr/device/arena_memory_resource.hpp b/include/rmm/mr/device/arena_memory_resource.hpp index 1b821b440..658a107d6 100644 --- a/include/rmm/mr/device/arena_memory_resource.hpp +++ b/include/rmm/mr/device/arena_memory_resource.hpp @@ -118,13 +118,6 @@ class arena_memory_resource final : public device_memory_resource { */ bool supports_streams() const noexcept override { return true; } - /** - * @brief Query whether the resource supports the get_mem_info API. - * - * @return bool false. - */ - bool supports_get_mem_info() const noexcept override { return false; } - private: using global_arena = rmm::mr::detail::arena::global_arena; using arena = rmm::mr::detail::arena::arena; @@ -312,18 +305,6 @@ class arena_memory_resource final : public device_memory_resource { } } - /** - * @brief Get free and available memory for memory resource. - * - * @param stream to execute on. - * @return std::pair containing free_size and total_size of memory. - */ - std::pair do_get_mem_info( - [[maybe_unused]] cuda_stream_view stream) const override - { - return std::make_pair(0, 0); - } - /** * Dump memory to log. * diff --git a/include/rmm/mr/device/binning_memory_resource.hpp b/include/rmm/mr/device/binning_memory_resource.hpp index 2a9975b18..33b92d4d7 100644 --- a/include/rmm/mr/device/binning_memory_resource.hpp +++ b/include/rmm/mr/device/binning_memory_resource.hpp @@ -106,13 +106,6 @@ class binning_memory_resource final : public device_memory_resource { */ [[nodiscard]] bool supports_streams() const noexcept override { return true; } - /** - * @brief Query whether the resource supports the get_mem_info API. - * - * @return false - */ - [[nodiscard]] bool supports_get_mem_info() const noexcept override { return false; } - /** * @brief Get the upstream memory_resource object. * @@ -197,20 +190,6 @@ class binning_memory_resource final : public device_memory_resource { if (res != nullptr) { res->deallocate(ptr, bytes, stream); } } - /** - * @brief Get free and available memory for memory resource - * - * @throws std::runtime_error if we could not get free / total memory - * - * @param stream the stream being executed on - * @return std::pair with available and free memory for resource - */ - [[nodiscard]] std::pair do_get_mem_info( - [[maybe_unused]] cuda_stream_view stream) const override - { - return std::make_pair(0, 0); - } - Upstream* upstream_mr_; // The upstream memory_resource from which to allocate blocks. std::vector>> owned_bin_resources_; diff --git a/include/rmm/mr/device/callback_memory_resource.hpp b/include/rmm/mr/device/callback_memory_resource.hpp index 36802c83a..11270ebe2 100644 --- a/include/rmm/mr/device/callback_memory_resource.hpp +++ b/include/rmm/mr/device/callback_memory_resource.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, NVIDIA CORPORATION. + * Copyright (c) 2022-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -138,13 +138,7 @@ class callback_memory_resource final : public device_memory_resource { deallocate_callback_(ptr, bytes, stream, deallocate_callback_arg_); } - [[nodiscard]] std::pair do_get_mem_info(cuda_stream_view) const override - { - throw std::runtime_error("cannot get free / total memory"); - } - [[nodiscard]] bool supports_streams() const noexcept override { return false; } - [[nodiscard]] bool supports_get_mem_info() const noexcept override { return false; } allocate_callback_t allocate_callback_; deallocate_callback_t deallocate_callback_; diff --git a/include/rmm/mr/device/cuda_async_memory_resource.hpp b/include/rmm/mr/device/cuda_async_memory_resource.hpp index f8295c6f6..b1d010cd6 100644 --- a/include/rmm/mr/device/cuda_async_memory_resource.hpp +++ b/include/rmm/mr/device/cuda_async_memory_resource.hpp @@ -164,13 +164,6 @@ class cuda_async_memory_resource final : public device_memory_resource { */ [[nodiscard]] bool supports_streams() const noexcept override { return true; } - /** - * @brief Query whether the resource supports the get_mem_info API. - * - * @return false - */ - [[nodiscard]] bool supports_get_mem_info() const noexcept override { return false; } - private: #ifdef RMM_CUDA_MALLOC_ASYNC_SUPPORT cuda_async_view_memory_resource pool_{}; @@ -232,19 +225,6 @@ class cuda_async_memory_resource final : public device_memory_resource { return async_mr != nullptr; #endif } - - /** - * @brief Get free and available memory for memory resource - * - * @throws rmm::cuda_error if unable to retrieve memory info. - * - * @return std::pair contaiing free_size and total_size of memory - */ - [[nodiscard]] std::pair do_get_mem_info( - rmm::cuda_stream_view) const override - { - return std::make_pair(0, 0); - } }; /** @} */ // end of group diff --git a/include/rmm/mr/device/cuda_async_view_memory_resource.hpp b/include/rmm/mr/device/cuda_async_view_memory_resource.hpp index 562944669..553c9a708 100644 --- a/include/rmm/mr/device/cuda_async_view_memory_resource.hpp +++ b/include/rmm/mr/device/cuda_async_view_memory_resource.hpp @@ -99,13 +99,6 @@ class cuda_async_view_memory_resource final : public device_memory_resource { */ [[nodiscard]] bool supports_streams() const noexcept override { return true; } - /** - * @brief Query whether the resource supports the get_mem_info API. - * - * @return true - */ - [[nodiscard]] bool supports_get_mem_info() const noexcept override { return false; } - private: #ifdef RMM_CUDA_MALLOC_ASYNC_SUPPORT cudaMemPool_t cuda_pool_handle_{}; @@ -169,19 +162,6 @@ class cuda_async_view_memory_resource final : public device_memory_resource { { return dynamic_cast(&other) != nullptr; } - - /** - * @brief Get free and available memory for memory resource - * - * @throws rmm::cuda_error if unable to retrieve memory info. - * - * @return std::pair contaiing free_size and total_size of memory - */ - [[nodiscard]] std::pair do_get_mem_info( - rmm::cuda_stream_view) const override - { - return std::make_pair(0, 0); - } }; /** @} */ // end of group diff --git a/include/rmm/mr/device/cuda_memory_resource.hpp b/include/rmm/mr/device/cuda_memory_resource.hpp index 256899776..284e49793 100644 --- a/include/rmm/mr/device/cuda_memory_resource.hpp +++ b/include/rmm/mr/device/cuda_memory_resource.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2021, NVIDIA CORPORATION. + * Copyright (c) 2019-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,13 +51,6 @@ class cuda_memory_resource final : public device_memory_resource { */ [[nodiscard]] bool supports_streams() const noexcept override { return false; } - /** - * @brief Query whether the resource supports the get_mem_info API. - * - * @return true - */ - [[nodiscard]] bool supports_get_mem_info() const noexcept override { return true; } - private: /** * @brief Allocates memory of size at least \p bytes. @@ -108,21 +101,6 @@ class cuda_memory_resource final : public device_memory_resource { { return dynamic_cast(&other) != nullptr; } - - /** - * @brief Get free and available memory for memory resource - * - * @throws rmm::cuda_error if unable to retrieve memory info. - * - * @return std::pair contaiing free_size and total_size of memory - */ - [[nodiscard]] std::pair do_get_mem_info(cuda_stream_view) const override - { - std::size_t free_size{}; - std::size_t total_size{}; - RMM_CUDA_TRY(cudaMemGetInfo(&free_size, &total_size)); - return std::make_pair(free_size, total_size); - } }; /** @} */ // end of group } // namespace rmm::mr diff --git a/include/rmm/mr/device/device_memory_resource.hpp b/include/rmm/mr/device/device_memory_resource.hpp index 55006f9b0..fd8a71c80 100644 --- a/include/rmm/mr/device/device_memory_resource.hpp +++ b/include/rmm/mr/device/device_memory_resource.hpp @@ -306,7 +306,7 @@ class device_memory_resource { * * @return bool true if the resource supports get_mem_info, false otherwise. */ - [[nodiscard]] virtual bool supports_get_mem_info() const noexcept = 0; + [[nodiscard]] virtual bool supports_get_mem_info() const noexcept { return false; }; /** * @brief Queries the amount of free and total memory for the resource. @@ -384,7 +384,10 @@ class device_memory_resource { * @return std::pair with available and free memory for resource */ [[nodiscard]] virtual std::pair do_get_mem_info( - cuda_stream_view stream) const = 0; + cuda_stream_view stream) const + { + return {0, 0}; + } }; static_assert(cuda::mr::async_resource_with); /** @} */ // end of group diff --git a/include/rmm/mr/device/failure_callback_resource_adaptor.hpp b/include/rmm/mr/device/failure_callback_resource_adaptor.hpp index f8cbe8597..0f8c4b020 100644 --- a/include/rmm/mr/device/failure_callback_resource_adaptor.hpp +++ b/include/rmm/mr/device/failure_callback_resource_adaptor.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021, NVIDIA CORPORATION. + * Copyright (c) 2020-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -135,16 +135,6 @@ class failure_callback_resource_adaptor final : public device_memory_resource { return upstream_->supports_streams(); } - /** - * @brief Query whether the resource supports the get_mem_info API. - * - * @return bool true if the upstream resource supports get_mem_info, false otherwise. - */ - [[nodiscard]] bool supports_get_mem_info() const noexcept override - { - return upstream_->supports_get_mem_info(); - } - private: /** * @brief Allocates memory of size at least `bytes` using the upstream @@ -199,20 +189,6 @@ class failure_callback_resource_adaptor final : public device_memory_resource { : upstream_->is_equal(other); } - /** - * @brief Get free and available memory from upstream resource. - * - * @throws rmm::cuda_error if unable to retrieve memory info. - * - * @param stream Stream on which to get the mem info. - * @return std::pair contaiing free_size and total_size of memory - */ - [[nodiscard]] std::pair do_get_mem_info( - cuda_stream_view stream) const override - { - return upstream_->get_mem_info(stream); - } - Upstream* upstream_; // the upstream resource used for satisfying allocation requests failure_callback_t callback_; void* callback_arg_; diff --git a/include/rmm/mr/device/fixed_size_memory_resource.hpp b/include/rmm/mr/device/fixed_size_memory_resource.hpp index 91cc95c53..b7a3babee 100644 --- a/include/rmm/mr/device/fixed_size_memory_resource.hpp +++ b/include/rmm/mr/device/fixed_size_memory_resource.hpp @@ -104,13 +104,6 @@ class fixed_size_memory_resource */ [[nodiscard]] bool supports_streams() const noexcept override { return true; } - /** - * @brief Query whether the resource supports the get_mem_info API. - * - * @return false - */ - [[nodiscard]] bool supports_get_mem_info() const noexcept override { return false; } - /** * @brief Get the upstream memory_resource object. * @@ -211,20 +204,6 @@ class fixed_size_memory_resource return block_type{ptr}; } - /** - * @brief Get free and available memory for memory resource - * - * @throws std::runtime_error if we could not get free / total memory - * - * @param stream the stream being executed on - * @return std::pair with available and free memory for resource - */ - [[nodiscard]] std::pair do_get_mem_info( - [[maybe_unused]] cuda_stream_view stream) const override - { - return std::make_pair(0, 0); - } - /** * @brief free all memory allocated using the upstream resource. * @@ -244,7 +223,7 @@ class fixed_size_memory_resource { lock_guard lock(this->get_mutex()); - auto const [free, total] = get_upstream()->get_mem_info(rmm::cuda_stream_default); + auto const [free, total] = rmm::available_device_memory(); std::cout << "GPU free memory: " << free << " total: " << total << "\n"; std::cout << "upstream_blocks: " << upstream_blocks_.size() << "\n"; diff --git a/include/rmm/mr/device/limiting_resource_adaptor.hpp b/include/rmm/mr/device/limiting_resource_adaptor.hpp index 2123c3cac..e10a453c5 100644 --- a/include/rmm/mr/device/limiting_resource_adaptor.hpp +++ b/include/rmm/mr/device/limiting_resource_adaptor.hpp @@ -88,16 +88,6 @@ class limiting_resource_adaptor final : public device_memory_resource { return upstream_->supports_streams(); } - /** - * @brief Query whether the resource supports the get_mem_info API. - * - * @return bool true if the upstream resource supports get_mem_info, false otherwise. - */ - [[nodiscard]] bool supports_get_mem_info() const noexcept override - { - return upstream_->supports_get_mem_info(); - } - /** * @brief Query the number of bytes that have been allocated. Note that * this can not be used to know how large of an allocation is possible due @@ -178,20 +168,6 @@ class limiting_resource_adaptor final : public device_memory_resource { return upstream_->is_equal(other); } - /** - * @brief Get free and available memory from upstream resource. - * - * @throws rmm::cuda_error if unable to retrieve memory info. - * - * @param stream Stream on which to get the mem info. - * @return std::pair contaiing free_size and total_size of memory - */ - [[nodiscard]] std::pair do_get_mem_info( - [[maybe_unused]] cuda_stream_view stream) const override - { - return {allocation_limit_ - allocated_bytes_, allocation_limit_}; - } - // maximum bytes this allocator is allowed to allocate. std::size_t allocation_limit_; diff --git a/include/rmm/mr/device/logging_resource_adaptor.hpp b/include/rmm/mr/device/logging_resource_adaptor.hpp index 781571157..455cde4c6 100644 --- a/include/rmm/mr/device/logging_resource_adaptor.hpp +++ b/include/rmm/mr/device/logging_resource_adaptor.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2023, NVIDIA CORPORATION. + * Copyright (c) 2020-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -154,16 +154,6 @@ class logging_resource_adaptor final : public device_memory_resource { return upstream_->supports_streams(); } - /** - * @brief Query whether the resource supports the get_mem_info API. - * - * @return bool true if the upstream resource supports get_mem_info, false otherwise. - */ - [[nodiscard]] bool supports_get_mem_info() const noexcept override - { - return upstream_->supports_get_mem_info(); - } - /** * @brief Flush logger contents. */ @@ -295,20 +285,6 @@ class logging_resource_adaptor final : public device_memory_resource { return upstream_->is_equal(other); } - /** - * @brief Get free and available memory from upstream resource. - * - * @throws rmm::cuda_error if unable to retrieve memory info. - * - * @param stream Stream on which to get the mem info. - * @return std::pair contaiing free_size and total_size of memory - */ - [[nodiscard]] std::pair do_get_mem_info( - cuda_stream_view stream) const override - { - return upstream_->get_mem_info(stream); - } - // make_logging_adaptor needs access to private get_default_filename template // NOLINTNEXTLINE(readability-redundant-declaration) diff --git a/include/rmm/mr/device/managed_memory_resource.hpp b/include/rmm/mr/device/managed_memory_resource.hpp index dfa7710bf..5b0a80426 100644 --- a/include/rmm/mr/device/managed_memory_resource.hpp +++ b/include/rmm/mr/device/managed_memory_resource.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2021, NVIDIA CORPORATION. + * Copyright (c) 2019-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,13 +51,6 @@ class managed_memory_resource final : public device_memory_resource { */ [[nodiscard]] bool supports_streams() const noexcept override { return false; } - /** - * @brief Query whether the resource supports the get_mem_info API. - * - * @return true - */ - [[nodiscard]] bool supports_get_mem_info() const noexcept override { return true; } - private: /** * @brief Allocates memory of size at least \p bytes. @@ -112,23 +105,6 @@ class managed_memory_resource final : public device_memory_resource { { return dynamic_cast(&other) != nullptr; } - - /** - * @brief Get free and available memory for memory resource - * - * @throws rmm::cuda_error if unable to retrieve memory info - * - * @param stream to execute on - * @return std::pair contaiing free_size and total_size of memory - */ - [[nodiscard]] std::pair do_get_mem_info( - [[maybe_unused]] cuda_stream_view stream) const override - { - std::size_t free_size{}; - std::size_t total_size{}; - RMM_CUDA_TRY(cudaMemGetInfo(&free_size, &total_size)); - return std::make_pair(free_size, total_size); - } }; /** @} */ // end of group diff --git a/include/rmm/mr/device/owning_wrapper.hpp b/include/rmm/mr/device/owning_wrapper.hpp index da513796d..7dd160265 100644 --- a/include/rmm/mr/device/owning_wrapper.hpp +++ b/include/rmm/mr/device/owning_wrapper.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021, NVIDIA CORPORATION. + * Copyright (c) 2020-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -165,14 +165,6 @@ class owning_wrapper : public device_memory_resource { return wrapped().supports_streams(); } - /** - * @briefreturn{true if the wrapped resource supports get_mem_info, false otherwise} - */ - [[nodiscard]] bool supports_get_mem_info() const noexcept override - { - return wrapped().supports_get_mem_info(); - } - private: /** * @brief Allocates memory using the wrapped resource. @@ -220,20 +212,6 @@ class owning_wrapper : public device_memory_resource { return wrapped().is_equal(other); } - /** - * @brief Get free and available memory from upstream resource. - * - * @throws rmm::cuda_error if unable to retrieve memory info. - * - * @param stream Stream on which to get the mem info. - * @return std::pair contaiing free_size and total_size of memory - */ - [[nodiscard]] std::pair do_get_mem_info( - cuda_stream_view stream) const override - { - return wrapped().get_mem_info(stream); - } - upstream_tuple upstreams_; ///< The owned upstream resources std::unique_ptr wrapped_; ///< The wrapped resource that uses the upstreams }; diff --git a/include/rmm/mr/device/pool_memory_resource.hpp b/include/rmm/mr/device/pool_memory_resource.hpp index 63239e750..44f8f96c4 100644 --- a/include/rmm/mr/device/pool_memory_resource.hpp +++ b/include/rmm/mr/device/pool_memory_resource.hpp @@ -236,13 +236,6 @@ class pool_memory_resource final */ [[nodiscard]] bool supports_streams() const noexcept override { return true; } - /** - * @brief Query whether the resource supports the get_mem_info API. - * - * @return bool false - */ - [[nodiscard]] bool supports_get_mem_info() const noexcept override { return false; } - /** * @brief Get the upstream memory_resource object. * @@ -487,7 +480,7 @@ class pool_memory_resource final { lock_guard lock(this->get_mutex()); - auto const [free, total] = upstream_mr_->get_mem_info(rmm::cuda_stream_default); + auto const [free, total] = rmm::available_device_memory(); std::cout << "GPU free memory: " << free << " total: " << total << "\n"; std::cout << "upstream_blocks: " << upstream_blocks_.size() << "\n"; @@ -528,21 +521,6 @@ class pool_memory_resource final return {largest, total}; } - /** - * @brief Get free and available memory for memory resource - * - * @throws nothing - * - * @param stream to execute on - * @return std::pair contaiing free_size and total_size of memory - */ - [[nodiscard]] std::pair do_get_mem_info( - cuda_stream_view stream) const override - { - // TODO implement this - return {0, 0}; - } - private: Upstream* upstream_mr_; // The "heap" to allocate the pool from std::size_t current_pool_size_{}; diff --git a/include/rmm/mr/device/statistics_resource_adaptor.hpp b/include/rmm/mr/device/statistics_resource_adaptor.hpp index dd186efc0..ed38a20f4 100644 --- a/include/rmm/mr/device/statistics_resource_adaptor.hpp +++ b/include/rmm/mr/device/statistics_resource_adaptor.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021, NVIDIA CORPORATION. + * Copyright (c) 2020-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -119,16 +119,6 @@ class statistics_resource_adaptor final : public device_memory_resource { */ bool supports_streams() const noexcept override { return upstream_->supports_streams(); } - /** - * @brief Query whether the resource supports the get_mem_info API. - * - * @return bool true if the upstream resource supports get_mem_info, false otherwise. - */ - bool supports_get_mem_info() const noexcept override - { - return upstream_->supports_get_mem_info(); - } - /** * @brief Returns a `counter` struct for this adaptor containing the current, * peak, and total number of allocated bytes for this @@ -222,19 +212,6 @@ class statistics_resource_adaptor final : public device_memory_resource { : upstream_->is_equal(other); } - /** - * @brief Get free and available memory from upstream resource. - * - * @throws rmm::cuda_error if unable to retrieve memory info. - * - * @param stream Stream on which to get the mem info. - * @return std::pair contaiing free_size and total_size of memory - */ - std::pair do_get_mem_info(cuda_stream_view stream) const override - { - return upstream_->get_mem_info(stream); - } - counter bytes_; // peak, current and total allocated bytes counter allocations_; // peak, current and total allocation count std::shared_timed_mutex mutable mtx_; // mutex for thread safe access to allocations_ diff --git a/include/rmm/mr/device/thread_safe_resource_adaptor.hpp b/include/rmm/mr/device/thread_safe_resource_adaptor.hpp index 13184b257..15ad3f0a5 100644 --- a/include/rmm/mr/device/thread_safe_resource_adaptor.hpp +++ b/include/rmm/mr/device/thread_safe_resource_adaptor.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021, NVIDIA CORPORATION. + * Copyright (c) 2020-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -76,16 +76,6 @@ class thread_safe_resource_adaptor final : public device_memory_resource { */ bool supports_streams() const noexcept override { return upstream_->supports_streams(); } - /** - * @brief Query whether the resource supports the get_mem_info API. - * - * @return bool true if the upstream resource supports get_mem_info, false otherwise. - */ - bool supports_get_mem_info() const noexcept override - { - return upstream_->supports_get_mem_info(); - } - private: /** * @brief Allocates memory of size at least `bytes` using the upstream @@ -134,20 +124,6 @@ class thread_safe_resource_adaptor final : public device_memory_resource { return upstream_->is_equal(other); } - /** - * @brief Get free and available memory from upstream resource. - * - * @throws rmm::cuda_error if unable to retrieve memory info. - * - * @param stream Stream on which to get the mem info. - * @return std::pair contaiing free_size and total_size of memory - */ - std::pair do_get_mem_info(cuda_stream_view stream) const override - { - lock_t lock(mtx); - return upstream_->get_mem_info(stream); - } - std::mutex mutable mtx; // mutex for thread safe access to upstream Upstream* upstream_; ///< The upstream resource used for satisfying allocation requests }; diff --git a/include/rmm/mr/device/tracking_resource_adaptor.hpp b/include/rmm/mr/device/tracking_resource_adaptor.hpp index 271ccab23..2ad88f079 100644 --- a/include/rmm/mr/device/tracking_resource_adaptor.hpp +++ b/include/rmm/mr/device/tracking_resource_adaptor.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2023, NVIDIA CORPORATION. + * Copyright (c) 2020-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -118,16 +118,6 @@ class tracking_resource_adaptor final : public device_memory_resource { */ bool supports_streams() const noexcept override { return upstream_->supports_streams(); } - /** - * @brief Query whether the resource supports the get_mem_info API. - * - * @return bool true if the upstream resource supports get_mem_info, false otherwise. - */ - bool supports_get_mem_info() const noexcept override - { - return upstream_->supports_get_mem_info(); - } - /** * @brief Get the outstanding allocations map * @@ -277,19 +267,6 @@ class tracking_resource_adaptor final : public device_memory_resource { : upstream_->is_equal(other); } - /** - * @brief Get free and available memory from upstream resource. - * - * @throws rmm::cuda_error if unable to retrieve memory info. - * - * @param stream Stream on which to get the mem info. - * @return std::pair contaiing free_size and total_size of memory - */ - std::pair do_get_mem_info(cuda_stream_view stream) const override - { - return upstream_->get_mem_info(stream); - } - bool capture_stacks_; // whether or not to capture call stacks std::map allocations_; // map of active allocations std::atomic allocated_bytes_; // number of bytes currently allocated diff --git a/include/rmm/mr/host/pinned_memory_resource.hpp b/include/rmm/mr/host/pinned_memory_resource.hpp index cb8524999..9f68b70fa 100644 --- a/include/rmm/mr/host/pinned_memory_resource.hpp +++ b/include/rmm/mr/host/pinned_memory_resource.hpp @@ -56,26 +56,6 @@ class pinned_memory_resource final : public host_memory_resource { */ [[nodiscard]] bool supports_streams() const noexcept { return false; } - /** - * @brief Query whether the resource supports the get_mem_info API. - * - * @return bool false. - */ - [[nodiscard]] bool supports_get_mem_info() const noexcept { return false; } - - /** - * @brief Queries the amount of free and total memory for the resource. - * - * @param stream the stream whose memory manager we want to retrieve - * - * @returns a pair containing the free memory in bytes in .first and total amount of memory in - * .second - */ - [[nodiscard]] std::pair get_mem_info(cuda_stream_view stream) const - { - return std::make_pair(0, 0); - } - /** * @brief Pretend to support the allocate_async interface, falling back to stream 0 * diff --git a/tests/device_check_resource_adaptor.hpp b/tests/device_check_resource_adaptor.hpp index f9ad4cf70..6ff82e77a 100644 --- a/tests/device_check_resource_adaptor.hpp +++ b/tests/device_check_resource_adaptor.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, NVIDIA CORPORATION. + * Copyright (c) 2023-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,11 +32,6 @@ class device_check_resource_adaptor final : public rmm::mr::device_memory_resour return upstream_->supports_streams(); } - [[nodiscard]] bool supports_get_mem_info() const noexcept override - { - return upstream_->supports_get_mem_info(); - } - [[nodiscard]] device_memory_resource* get_upstream() const noexcept { return upstream_; } private: @@ -66,12 +61,6 @@ class device_check_resource_adaptor final : public rmm::mr::device_memory_resour return upstream_->is_equal(other); } - [[nodiscard]] std::pair do_get_mem_info( - rmm::cuda_stream_view stream) const override - { - return upstream_->get_mem_info(stream); - } - rmm::cuda_device_id device_id; rmm::mr::device_memory_resource* upstream_{}; }; diff --git a/tests/mock_resource.hpp b/tests/mock_resource.hpp index 0436e2a2a..d8eb4e5b9 100644 --- a/tests/mock_resource.hpp +++ b/tests/mock_resource.hpp @@ -24,11 +24,9 @@ namespace rmm::test { class mock_resource : public rmm::mr::device_memory_resource { public: MOCK_METHOD(bool, supports_streams, (), (const, override, noexcept)); - MOCK_METHOD(bool, supports_get_mem_info, (), (const, override, noexcept)); MOCK_METHOD(void*, do_allocate, (std::size_t, cuda_stream_view), (override)); MOCK_METHOD(void, do_deallocate, (void*, std::size_t, cuda_stream_view), (override)); using size_pair = std::pair; - MOCK_METHOD(size_pair, do_get_mem_info, (cuda_stream_view), (const, override)); }; } // namespace rmm::test diff --git a/tests/mr/device/adaptor_tests.cpp b/tests/mr/device/adaptor_tests.cpp index 98fc3a429..e43818091 100644 --- a/tests/mr/device/adaptor_tests.cpp +++ b/tests/mr/device/adaptor_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -147,20 +147,6 @@ TYPED_TEST(AdaptorTest, SupportsStreams) EXPECT_EQ(this->mr->supports_streams(), this->cuda.supports_streams()); } -TYPED_TEST(AdaptorTest, MemInfo) -{ - EXPECT_EQ(this->mr->supports_get_mem_info(), this->cuda.supports_get_mem_info()); - - auto [free, total] = this->mr->get_mem_info(rmm::cuda_stream_default); - - if (this->mr->supports_get_mem_info()) { - EXPECT_NE(total, 0); - } else { - EXPECT_EQ(free, 0); - EXPECT_EQ(total, 0); - } -} - TYPED_TEST(AdaptorTest, AllocFree) { void* ptr{nullptr}; diff --git a/tests/mr/device/aligned_mr_tests.cpp b/tests/mr/device/aligned_mr_tests.cpp index 5fbb4b8f1..4d149c182 100644 --- a/tests/mr/device/aligned_mr_tests.cpp +++ b/tests/mr/device/aligned_mr_tests.cpp @@ -72,12 +72,6 @@ TEST(AlignedTest, SupportsGetMemInfo) { mock_resource mock; aligned_mock mr{&mock}; - - EXPECT_CALL(mock, supports_get_mem_info()).WillOnce(Return(true)); - EXPECT_TRUE(mr.supports_get_mem_info()); - - EXPECT_CALL(mock, supports_get_mem_info()).WillOnce(Return(false)); - EXPECT_FALSE(mr.supports_get_mem_info()); } TEST(AlignedTest, DefaultAllocationAlignmentPassthrough) diff --git a/tests/mr/device/arena_mr_tests.cpp b/tests/mr/device/arena_mr_tests.cpp index 1068e0cf0..fbd96599e 100644 --- a/tests/mr/device/arena_mr_tests.cpp +++ b/tests/mr/device/arena_mr_tests.cpp @@ -596,10 +596,6 @@ TEST_F(ArenaTest, FeatureSupport) // NOLINT { arena_mr mr{rmm::mr::get_current_device_resource(), 1_MiB}; EXPECT_TRUE(mr.supports_streams()); - EXPECT_FALSE(mr.supports_get_mem_info()); - auto [free, total] = mr.get_mem_info(rmm::cuda_stream_default); - EXPECT_EQ(free, 0); - EXPECT_EQ(total, 0); } } // namespace diff --git a/tests/mr/device/failure_callback_mr_tests.cpp b/tests/mr/device/failure_callback_mr_tests.cpp index 79acd5c7e..12fbff268 100644 --- a/tests/mr/device/failure_callback_mr_tests.cpp +++ b/tests/mr/device/failure_callback_mr_tests.cpp @@ -61,14 +61,8 @@ class always_throw_memory_resource final : public mr::device_memory_resource { throw ExceptionType{"foo"}; } void do_deallocate(void* ptr, std::size_t bytes, cuda_stream_view stream) override{}; - [[nodiscard]] std::pair do_get_mem_info( - cuda_stream_view stream) const override - { - return {0, 0}; - } [[nodiscard]] bool supports_streams() const noexcept override { return false; } - [[nodiscard]] bool supports_get_mem_info() const noexcept override { return false; } }; TEST(FailureCallbackTest, DifferentExceptionTypes) diff --git a/tests/mr/device/mr_tests.cpp b/tests/mr/device/mr_tests.cpp index bf513adda..5f9be9f54 100644 --- a/tests/mr/device/mr_tests.cpp +++ b/tests/mr/device/mr_tests.cpp @@ -97,31 +97,6 @@ TEST_P(mr_test, SupportsStreams) } } -TEST_P(mr_test, GetMemInfo) -{ - if (this->mr->supports_get_mem_info()) { - const auto allocation_size{16 * 256}; - { - auto const [free, total] = this->mr->get_mem_info(rmm::cuda_stream_view{}); - EXPECT_TRUE(free >= allocation_size); - } - - void* ptr{nullptr}; - ptr = this->mr->allocate(allocation_size); - - { - auto const [free, total] = this->mr->get_mem_info(rmm::cuda_stream_view{}); - EXPECT_TRUE(free >= allocation_size); - } - - this->mr->deallocate(ptr, allocation_size); - } else { - auto const [free, total] = this->mr->get_mem_info(rmm::cuda_stream_view{}); - EXPECT_EQ(free, 0); - EXPECT_EQ(total, 0); - } -} - // Simple reproducer for https://github.com/rapidsai/rmm/issues/861 TEST_P(mr_test, AllocationsAreDifferentDefaultStream) { diff --git a/tests/mr/device/pool_mr_tests.cpp b/tests/mr/device/pool_mr_tests.cpp index a2793386f..7193ef301 100644 --- a/tests/mr/device/pool_mr_tests.cpp +++ b/tests/mr/device/pool_mr_tests.cpp @@ -213,7 +213,6 @@ class fake_async_resource { // To model stream_resource [[nodiscard]] bool supports_streams() const noexcept { return false; } - [[nodiscard]] bool supports_get_mem_info() const noexcept { return false; } private: void* do_allocate(std::size_t bytes, cuda_stream_view) { return nullptr; }