Skip to content

Commit 4314fd7

Browse files
GH-41126: [Python] Test Buffer device/device_type access on CUDA (#42221)
### Rationale for this change Adding tests for the new Buffer properties added in #41685 but now testing that it works out of the box with CUDA. * GitHub Issue: #41126 Authored-by: Joris Van den Bossche <[email protected]> Signed-off-by: Joris Van den Bossche <[email protected]>
1 parent b33f040 commit 4314fd7

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

‎python/pyarrow/tests/test_cuda.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,28 @@ def put(*args, **kwargs):
545545
put(position=position, nbytes=nbytes)
546546

547547

548+
def test_buffer_device():
549+
buf = cuda.new_host_buffer(10)
550+
assert buf.device_type == pa.DeviceAllocationType.CUDA_HOST
551+
assert isinstance(buf.device, pa.Device)
552+
assert isinstance(buf.memory_manager, pa.MemoryManager)
553+
assert buf.is_cpu
554+
assert buf.device.is_cpu
555+
assert buf.device == pa.default_cpu_memory_manager().device
556+
# it is not entirely clear if CudaHostBuffer should use the default CPU memory
557+
# manager (as it does now), see https://github.com/apache/arrow/pull/42221
558+
assert buf.memory_manager.is_cpu
559+
560+
_, buf = make_random_buffer(size=10, target='device')
561+
assert buf.device_type == pa.DeviceAllocationType.CUDA
562+
assert isinstance(buf.device, pa.Device)
563+
assert buf.device == global_context.memory_manager.device
564+
assert isinstance(buf.memory_manager, pa.MemoryManager)
565+
assert not buf.is_cpu
566+
assert not buf.device.is_cpu
567+
assert not buf.memory_manager.is_cpu
568+
569+
548570
def test_BufferWriter():
549571
def allocate(size):
550572
cbuf = global_context.new_buffer(size)

0 commit comments

Comments
 (0)