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

Control pinned memory use with environment variables #17657

Merged
merged 8 commits into from
Jan 8, 2025
6 changes: 4 additions & 2 deletions cpp/src/utilities/host_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

#include "io/utilities/getenv_or.hpp"

#include <cudf/detail/utilities/stream_pool.hpp>
#include <cudf/logger.hpp>
#include <cudf/utilities/error.hpp>
Expand Down Expand Up @@ -277,7 +279,7 @@ bool config_default_pinned_memory_resource(pinned_mr_options const& opts)
CUDF_EXPORT auto& kernel_pinned_copy_threshold()
{
// use cudaMemcpyAsync for all pinned copies
static std::atomic<size_t> threshold = 0;
static std::atomic<size_t> threshold = getenv_or("LIBCUDF_KERNEL_PINNED_COPY_THRESHOLD", 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

One issue with static variable is that, they are initialized only once. The user will not be able to change them after they are set. Can we remove static?

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'm torn on this one. You're right, but:
I really like reading the env var once so I can log it cleanly (already a part of getenv_or).
Also, there are (C++) APIs to set these thresholds at runtime.
I'd keep this static until we have a use case that requires runtime changes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Static or not, we want to cache this after reading it once. We shouldn't be querying the environment variable every time we need to decide how to pin/copy.

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 thought this as well and tried caching the large strings env var. Turns out repeated calls to getenv are very cheap. Not arguing for this option here, just a comment to make sure folks are aware of the actual performance.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok cool, good to know!

return threshold;
}

Expand All @@ -291,7 +293,7 @@ size_t get_kernel_pinned_copy_threshold() { return kernel_pinned_copy_threshold(
CUDF_EXPORT auto& allocate_host_as_pinned_threshold()
{
// use pageable memory for all host allocations
static std::atomic<size_t> threshold = 0;
static std::atomic<size_t> threshold = getenv_or("LIBCUDF_ALLOCATE_HOST_AS_PINNED_THRESHOLD", 0);
return threshold;
}

Expand Down
Loading