MCPcopy Create free account
hub / github.com/apache/arrow / test_copy_from_to_host

Function test_copy_from_to_host

python/pyarrow/tests/test_cuda.py:357–381  ·  view source on GitHub ↗
(size)

Source from the content-addressed store, hash-verified

355
356@pytest.mark.parametrize("size", [0, 1, 1000])
357def test_copy_from_to_host(size):
358 # Create a buffer in host containing range(size)
359 dt = np.dtype('uint16')
360 nbytes = size * dt.itemsize
361 buf = pa.allocate_buffer(nbytes, resizable=True) # in host
362 assert isinstance(buf, pa.Buffer)
363 assert not isinstance(buf, cuda.CudaBuffer)
364 arr = np.frombuffer(buf, dtype=dt)
365 assert arr.size == size
366 arr[:] = range(size)
367 arr_ = np.frombuffer(buf, dtype=dt)
368 np.testing.assert_equal(arr, arr_)
369
370 # Create a device buffer of the same size and copy from host
371 device_buffer = global_context.new_buffer(nbytes)
372 assert isinstance(device_buffer, cuda.CudaBuffer)
373 assert isinstance(device_buffer, pa.Buffer)
374 assert device_buffer.size == nbytes
375 assert not device_buffer.is_cpu
376 device_buffer.copy_from_host(buf, position=0, nbytes=nbytes)
377
378 # Copy back to host and compare contents
379 buf2 = device_buffer.copy_to_host(position=0, nbytes=nbytes)
380 arr2 = np.frombuffer(buf2, dtype=dt)
381 np.testing.assert_equal(arr, arr2)
382
383
384@pytest.mark.parametrize("size", [0, 1, 1000])

Callers

nothing calls this directly

Calls 1

dtypeMethod · 0.80

Tested by

no test coverage detected