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

GH-41126: [Python] Basic bindings for Device and MemoryManager classes #41685

Merged
merged 5 commits into from
May 31, 2024

Conversation

jorisvandenbossche
Copy link
Member

@jorisvandenbossche jorisvandenbossche commented May 16, 2024

Rationale for this change

Add bindings for the C++ arrow::Device and arrow::MemoryManager classes.

What changes are included in this PR?

Basic bindings by adding the pyarrow.Device and pyarrow.MemoryManager classes, and just tested for CPU.

What is not included here are additional methods on the MemoryManager class (eg to allocate or copy buffers), and this is also not yet tested for CUDA. Planning to do this as follow-ups, and first doing those basic bindings should enable further enhancements to be done in parallel.

Are these changes tested?

Yes, for the CPU device only.

Copy link

⚠️ GitHub issue #41126 has been automatically assigned in GitHub to PR creator.

Copy link
Member

@AlenkaF AlenkaF left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@danepitkin danepitkin left a comment

Choose a reason for hiding this comment

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

Is it possible to add tests to test_cuda.py to test a non-cpu path?

"""
Return the DeviceAllocationType of this device.
"""
return _wrap_device_allocation_type(self.device.get().device_type())
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we wrap device_type, but not other properties like is_cpu?

Copy link
Member Author

Choose a reason for hiding this comment

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

is_cpu is a simple bool, and cython takes care of returning that as a python object. For the type here I wanted to return a python enum (and not just an integer)

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the explanation!

python/pyarrow/tests/test_device.py Show resolved Hide resolved

The returned singleton instance uses the default MemoryPool.
"""
return MemoryManager.wrap(c_default_cpu_memory_manager())
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 plan to later subclass Device with CPUDevice and MemoryManager with CPUMemoryManager, respectively?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not necessarily, for now, if not needed? For CPU I am not sure if it is worth it, as looking at device.h, it seems the main thing the subclass provides is allowing to specify a memory pool when creating (which we could also expose through default_cpu_memory_manager if we want to expose this?
For CUDA there might be more CUDA-specific methods/attributes where it might be more worth providing a subclass.

Copy link
Member

Choose a reason for hiding this comment

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

Indeed, we can do add them later when desired.

@github-actions github-actions bot added awaiting changes Awaiting changes and removed awaiting committer review Awaiting committer review labels May 29, 2024
@jorisvandenbossche
Copy link
Member Author

Is it possible to add tests to test_cuda.py to test a non-cpu path?

We should certainly do that, but we were planning to do that in a follow-up

@pitrou
Copy link
Member

pitrou commented May 29, 2024

We should certainly do that, but we were planning to do that in a follow-up

Ah, fair enough.

@github-actions github-actions bot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels May 30, 2024
@jorisvandenbossche jorisvandenbossche merged commit 31fe24d into apache:main May 31, 2024
10 of 12 checks passed
@jorisvandenbossche jorisvandenbossche removed the awaiting change review Awaiting change review label May 31, 2024
@jorisvandenbossche jorisvandenbossche deleted the memory-manager branch May 31, 2024 07:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants