-
Notifications
You must be signed in to change notification settings - Fork 4k
GH-43589: [Python] Add bindings for Buffer copy() method to other device #43590
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
base: main
Are you sure you want to change the base?
Changes from all commits
489a2be
e0b05a3
77876f9
af02588
d7a43bc
91cbaee
c08398a
42253b9
f7ff682
9319543
230abf2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1446,6 +1446,41 @@ cdef class Buffer(_Weakrefable): | |||||||||
| """ | ||||||||||
| return _wrap_device_allocation_type(self.buffer.get().device_type()) | ||||||||||
|
|
||||||||||
| def copy(self, destination): | ||||||||||
| """ | ||||||||||
| Copy the buffer to the destination device. | ||||||||||
|
|
||||||||||
| The buffer contents will be copied into a new buffer allocated onto | ||||||||||
| the destination MemoryManager or Device. It will return the new Buffer. | ||||||||||
| This function supports cross-device copies. | ||||||||||
|
|
||||||||||
| Parameters | ||||||||||
| ---------- | ||||||||||
| destination : pyarrow.MemoryManager or pyarrow.Device | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not required, but it may be nice to also allow a MemoryPool here.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't have a way to map a given MemoryPool to a device manager (AFAIK), so in that case you mean to use a different API under the hood to copy to the memory pool? (
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use Lines 295 to 298 in c557fe5
|
||||||||||
| Used to allocate the new buffer. | ||||||||||
|
|
||||||||||
| Returns | ||||||||||
| ------- | ||||||||||
| Buffer | ||||||||||
| """ | ||||||||||
| cdef: | ||||||||||
| shared_ptr[CBuffer] c_buffer | ||||||||||
| shared_ptr[CMemoryManager] c_memory_manager | ||||||||||
|
|
||||||||||
| if isinstance(destination, Device): | ||||||||||
| c_memory_manager = (<Device>destination).unwrap().get().default_memory_manager() | ||||||||||
| elif isinstance(destination, MemoryManager): | ||||||||||
| c_memory_manager = (<MemoryManager>destination).unwrap() | ||||||||||
| else: | ||||||||||
| raise TypeError( | ||||||||||
| "Argument 'destination' is incorrect type (expected pyarrow.Device or " | ||||||||||
| f"pyarrow.MemoryManager, got {type(destination)})" | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| with nogil: | ||||||||||
| c_buffer = GetResultValue(CBuffer.Copy(self.buffer, c_memory_manager)) | ||||||||||
| return pyarrow_wrap_buffer(c_buffer) | ||||||||||
|
|
||||||||||
| @property | ||||||||||
| def parent(self): | ||||||||||
| cdef shared_ptr[CBuffer] parent_buf = self.buffer.get().parent() | ||||||||||
|
|
||||||||||
Uh oh!
There was an error while loading. Please reload this page.