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 ability to enable rmm pool on cudf.pandas import #15628

Open
wants to merge 5 commits into
base: branch-24.06
Choose a base branch
from

Conversation

galipremsagar
Copy link
Contributor

@galipremsagar galipremsagar commented May 1, 2024

Description

This PR enables allocating of rmm memory pool on cudf.pandas import using the following environment variables:

export CUDF_PANDAS_RMM_MODE="pool"

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@galipremsagar galipremsagar added improvement Improvement / enhancement to an existing function non-breaking Non-breaking change labels May 1, 2024
@galipremsagar galipremsagar self-assigned this May 1, 2024
@galipremsagar galipremsagar requested a review from a team as a code owner May 1, 2024 15:12
@github-actions github-actions bot added the cuDF (Python) Affects Python cuDF API. label May 1, 2024
python/cudf/cudf/pandas/__init__.py Outdated Show resolved Hide resolved
python/cudf/cudf/pandas/__init__.py Outdated Show resolved Hide resolved
python/cudf/cudf/pandas/__init__.py Outdated Show resolved Hide resolved
if cudf_pandas_mr is not None:
from rmm.mr import PoolMemoryResource

mr = PoolMemoryResource(
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we always want the user's specified MR to be wrapped in a pool?

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 don't know, open to suggestions here. Or we can change this as we know which works the best from experimenting.

Copy link
Member

Choose a reason for hiding this comment

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

Certainly not. In the example in the PR description you specify CudeAsyncMemoryResource. That already has a pool, you probably wouldn't always want to wrap that in an RMM PoolMemoryResource.

I thought in the meeting we discussed just providing a limited set of choices here. More sophisticated users should be able to import RMM first and configure the current device resource to override if they have very specific MR needs.

Copy link
Contributor

Choose a reason for hiding this comment

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

We do a similar thing in libcudf NVBench benchmarks. Here are the options we expose there, for reference:

inline std::shared_ptr<rmm::mr::device_memory_resource> create_memory_resource(
std::string const& mode)
{
if (mode == "cuda") return make_cuda();
if (mode == "pool") return make_pool();
if (mode == "async") return make_async();
if (mode == "arena") return make_arena();
if (mode == "managed") return make_managed();
if (mode == "managed_pool") return make_managed_pool();
CUDF_FAIL("Unknown rmm_mode parameter: " + mode +
"\nExpecting: cuda, pool, async, arena, managed, or managed_pool");
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@harrism Do you feel comfortable having a similar option set for cudf.pandas?

Copy link
Member

@madsbk madsbk May 6, 2024

Choose a reason for hiding this comment

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

@harrism Do you feel comfortable having a similar option set for cudf.pandas?

I think this option set would be good, it covers the typical use cases.

Copy link
Member

Choose a reason for hiding this comment

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

Do you think we need arena?

Copy link
Member

Choose a reason for hiding this comment

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

Do you think we need arena?

Maybe, I haven't tried it, but its fragmentation avoidance might be useful.
However, to limit the user complexity/documentation of cudf.pandas, I am also fine skipping arena. We can always add it later if it turns out to be useful.

Copy link
Member

Choose a reason for hiding this comment

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

I think you can also manually enable it by importing RMM and enabling it before importing cudf.pandas.

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 updated the PR to have simpler rmm mode selection and added pytests for the same.

@harrism @bdice This should be ready for review.

Co-authored-by: Bradley Dice <bdice@bradleydice.com>
Copy link
Member

@harrism harrism left a comment

Choose a reason for hiding this comment

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

I don't think we should always wrap with a PoolMemoryResource

if cudf_pandas_mr is not None:
from rmm.mr import PoolMemoryResource

mr = PoolMemoryResource(
Copy link
Member

Choose a reason for hiding this comment

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

Certainly not. In the example in the PR description you specify CudeAsyncMemoryResource. That already has a pool, you probably wouldn't always want to wrap that in an RMM PoolMemoryResource.

I thought in the meeting we discussed just providing a limited set of choices here. More sophisticated users should be able to import RMM first and configure the current device resource to override if they have very specific MR needs.


if (rmm_mode := os.getenv("CUDF_PANDAS_RMM_MODE", None)) is not None:
import rmm.mr
from rmm._lib.memory_resource import get_free_device_memory
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This method is being added in: rapidsai/rmm#1567

Copy link
Member

@madsbk madsbk left a comment

Choose a reason for hiding this comment

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

Looks good

Comment on lines +1453 to +1454

del env["CUDF_PANDAS_RMM_MODE"]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
del env["CUDF_PANDAS_RMM_MODE"]

I don't you need this since env is a copy?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cuDF (Python) Affects Python cuDF API. improvement Improvement / enhancement to an existing function non-breaking Non-breaking change
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

None yet

4 participants