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

Add default pinned pool that falls back to new pinned allocations #15665

Merged
merged 44 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
163ad97
pool with fallback
vuule May 6, 2024
1e850d6
don't use default pool
vuule May 6, 2024
3be42ba
fix allocator copy assignment
vuule May 6, 2024
395dcf1
fix ver2
vuule May 6, 2024
70ae74e
Merge branch 'branch-24.06' into bug-allocator-copy-wrong-stream
vuule May 6, 2024
503d170
Merge branch 'bug-allocator-copy-wrong-stream' into perf-defaul-piine…
vuule May 6, 2024
0873b1f
copyright
vuule May 6, 2024
ff18a21
fix operator==
vuule May 7, 2024
f5a735c
Merge branch 'branch-24.06' of https://github.com/rapidsai/cudf into …
vuule May 7, 2024
5766805
Merge branch 'bug-allocator-copy-wrong-stream' of https://github.com/…
vuule May 7, 2024
0bd92bf
Merge branch 'bug-allocator-copy-wrong-stream' into perf-defaul-piine…
vuule May 7, 2024
854c0ab
simplify pool creation
vuule May 7, 2024
5bf0ce4
namespace; comments
vuule May 7, 2024
284654d
Merge branch 'branch-24.06' into perf-defaul-piined-pool
vuule May 7, 2024
ff4d7f6
clean up
vuule May 7, 2024
f5b2c84
Merge branch 'branch-24.06' of https://github.com/rapidsai/cudf into …
vuule May 7, 2024
cf3f8a3
Merge branch 'perf-defaul-piined-pool' of https://github.com/vuule/cu…
vuule May 7, 2024
80b5963
mild polish
vuule May 7, 2024
d23684d
Merge branch 'branch-24.06' of https://github.com/rapidsai/cudf into …
vuule May 8, 2024
1828e05
Merge branch 'branch-24.06' of https://github.com/rapidsai/cudf into …
vuule May 9, 2024
0122038
remove inline
vuule May 9, 2024
60030da
scoped_lock
vuule May 9, 2024
a62377e
try
vuule May 9, 2024
6733c45
clean up
vuule May 9, 2024
abf40a8
clarify try-catch fallback
vuule May 9, 2024
fa7dce7
remove export
vuule May 9, 2024
a244d7c
non-indexed stream
vuule May 9, 2024
7076e73
Update cpp/src/io/utilities/config_utils.cpp
ttnghia May 9, 2024
0b8aa44
Merge branch 'branch-24.06' into perf-defaul-piined-pool
vuule May 9, 2024
3db44a3
Merge branch 'branch-24.06' of https://github.com/rapidsai/cudf into …
vuule May 13, 2024
27d30c8
make default_pinned_mr cheap to call multiple times
vuule May 13, 2024
224e68f
static_assert fixed_pinned_pool_memory_resource
vuule May 13, 2024
382e7b3
Merge branch 'perf-defaul-piined-pool' of https://github.com/vuule/cu…
vuule May 13, 2024
b2fd734
fix host_mr
vuule May 13, 2024
0eccf9a
add config function
vuule May 13, 2024
ecd6481
align config size; add missing header
vuule May 13, 2024
709123f
Merge branch 'branch-24.06' of https://github.com/rapidsai/cudf into …
vuule May 13, 2024
01b1bdb
Merge branch 'branch-24.06' of https://github.com/rapidsai/cudf into …
vuule May 14, 2024
ecb5f5a
CUDF_EXPORT
vuule May 14, 2024
f0d0bf0
fail config if resource is already created
vuule May 14, 2024
f989a56
fix config check
vuule May 15, 2024
d0e6dd7
Merge branch 'branch-24.06' of https://github.com/rapidsai/cudf into …
vuule May 15, 2024
2b4952a
docs
vuule May 15, 2024
fdcfad3
Merge branch 'branch-24.06' into perf-defaul-piined-pool
vuule May 16, 2024
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
9 changes: 9 additions & 0 deletions cpp/include/cudf/io/memory_resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,13 @@ rmm::host_async_resource_ref set_host_memory_resource(rmm::host_async_resource_r
*/
rmm::host_async_resource_ref get_host_memory_resource();

/**
* @brief Configure the size of the default host memory resource.
*
* Must be called before any other function in this header.
Copy link
Contributor

@ttnghia ttnghia May 13, 2024

Choose a reason for hiding this comment

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

This is a dangerous requirement, and may not be satisfied. How about making the static function re-configuruable?

Copy link
Contributor

@ttnghia ttnghia May 13, 2024

Choose a reason for hiding this comment

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

For doing so:

  1. Static variable is declared outside of function scope (but in an anonymous namespace, so it is static inside just this TU). In addition, it can be a smart pointer.
  2. host_mr will initialize it with std::nullopt size if it is nullptr, otherwise just derefs the current pointer and returns.
  3. User can specify a size parameter to recompute and overwrite that static variable with a new mr.
  4. All these ops should be thread safe.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

to clarify, the issue with calling config after get/set is that it would have no effect.

allowing this opens another can of worms., e.g. what is the intended effect of calling config after set?

Copy link
Contributor

@ttnghia ttnghia May 14, 2024

Choose a reason for hiding this comment

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

If we don't allow this, let's make some validity check to prevent it from being accidentally misused. It sounds unsafe if we just make an assumption.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@abellina what behavior do you suggest when config is called after the first resource use? I'm not sure if we should throw or just warn.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should throw, I agree with @ttnghia that we should do something in that case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a mechanism to throw if config is called after the default resource has already been created.
@abellina might be good to test your branch with this change.

*
* @param size The size of the default host memory resource
*/
void config_host_memory_resource(size_t size);

} // namespace cudf::io
26 changes: 20 additions & 6 deletions cpp/src/io/utilities/config_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,16 @@ static_assert(cuda::mr::resource_with<fixed_pinned_pool_memory_resource,
cuda::mr::host_accessible>,
"");

rmm::host_async_resource_ref default_pinned_mr()
rmm::host_async_resource_ref make_default_pinned_mr(std::optional<size_t> config_size)
{
static fixed_pinned_pool_memory_resource mr = []() {
auto const size = []() -> size_t {
static fixed_pinned_pool_memory_resource mr = [config_size]() {
auto const size = [&config_size]() -> size_t {
if (auto const env_val = getenv("LIBCUDF_PINNED_POOL_SIZE"); env_val != nullptr) {
return std::atol(env_val);
}

if (config_size.has_value()) { return *config_size; }

size_t free{}, total{};
CUDF_CUDA_TRY(cudaMemGetInfo(&free, &total));
// 0.5% of the total device memory, capped at 100MB
Expand All @@ -228,16 +230,22 @@ rmm::host_async_resource_ref default_pinned_mr()
return mr;
}

rmm::host_async_resource_ref make_host_mr(std::optional<size_t> size)
{
static rmm::host_async_resource_ref mr_ref = make_default_pinned_mr(size);
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps this was asked before but I'm curious when/how this object is destroyed?
Is it destroyed automatically when the process ends i.e. after main() completes?
Are there any CUDA API calls in the destructor(s)?
Maybe this is ok for host memory resources.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

great question. Currently the pool itself is not destroyed as it caused a segfault at the end of some tests; presumably because of the call to cudaFreeHost after main(). But this is something I should revisit and verify what exactly the issue was.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, can't destroy a static pool resource object. Open to suggestions to avoid the pool leak.

return mr_ref;
}

std::mutex& host_mr_mutex()
{
static std::mutex map_lock;
return map_lock;
}

rmm::host_async_resource_ref host_mr()
rmm::host_async_resource_ref& host_mr()
{
static rmm::host_async_resource_ref host_mr = default_pinned_mr();
return host_mr;
static rmm::host_async_resource_ref mr_ref = make_host_mr(std::nullopt);
return mr_ref;
}

} // namespace
Expand All @@ -256,4 +264,10 @@ rmm::host_async_resource_ref get_host_memory_resource()
return host_mr();
}

void config_host_memory_resource(size_t size)
{
std::scoped_lock lock{host_mr_mutex()};
make_host_mr(size);
}

} // namespace cudf::io
Loading