Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make pool_memory_resource::pool_size() public #962

Merged
merged 2 commits into from
Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 9 additions & 9 deletions include/rmm/mr/device/pool_memory_resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ class pool_memory_resource final
*/
Upstream* get_upstream() const noexcept { return upstream_mr_; }

/**
* @brief Computes the size of the current pool
*
* Includes allocated as well as free memory.
*
* @return std::size_t The total size of the currently allocated pool.
*/
[[nodiscard]] std::size_t pool_size() const noexcept { return current_pool_size_; }

protected:
using free_list = detail::coalescing_free_list;
using block_type = free_list::block_type;
Expand Down Expand Up @@ -338,15 +347,6 @@ class pool_memory_resource final
#endif
}

/**
* @brief Computes the size of the current pool
*
* Includes allocated as well as free memory.
*
* @return std::size_t The total size of the currently allocated pool.
*/
[[nodiscard]] std::size_t pool_size() const noexcept { return current_pool_size_; }

/**
* @brief Free all memory allocated from the upstream memory_resource.
*
Expand Down
5 changes: 5 additions & 0 deletions python/rmm/_lib/memory_resource.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ cdef extern from "rmm/mr/device/pool_memory_resource.hpp" \
Upstream* upstream_mr,
optional[size_t] initial_pool_size,
optional[size_t] maximum_pool_size) except +
size_t pool_size()

cdef extern from "rmm/mr/device/fixed_size_memory_resource.hpp" \
namespace "rmm::mr" nogil:
Expand Down Expand Up @@ -299,6 +300,10 @@ cdef class PoolMemoryResource(UpstreamResourceAdaptor):
"""
pass

def pool_size(self):
return (<pool_memory_resource[device_memory_resource]*>(
self.c_obj.get()))[0].pool_size()
Copy link
Member

Choose a reason for hiding this comment

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

This feels like a lot to cram into one line. Would it make sense to break this up a bit by assigning to variables?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to clean this up a bit. Unfortunately, unlike C++, I can't create a type alias for pool_memory_resource[device_memory_resource], so this is still a bit awkward looking.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(Cython doesn't let you ctypedef inside a function)

Copy link
Member

Choose a reason for hiding this comment

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

The change looks much better! Thanks Ashwin 😄

Interesting guessing you tried ctypedef? Did you try DEF? In any event this seems less critical at least from my perspective



cdef class FixedSizeMemoryResource(UpstreamResourceAdaptor):
def __cinit__(
Expand Down