mirror of
https://github.com/apache/arrow.git
synced 2026-10-29 17:15:39 +08:00
Moved some buffer_from_objects tests under test_cuda.
This commit is contained in:
1 parent
562c18052c
commit
dbd1cec6b8
2 files changed
+32
-25
No files matched your search
@@ -230,6 +230,38 @@ def test_context_device_buffer(size):
|
||||
np.testing.assert_equal(arr[soffset:soffset+ssize], arr2)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("size", [0, 1, 1000])
|
||||
def test_context_from_object(size):
|
||||
ctx = global_context
|
||||
arr, cbuf = make_random_buffer(size, target='device')
|
||||
dtype = arr.dtype
|
||||
|
||||
# Creating device buffer from a CUDA host buffer
|
||||
hbuf = cuda.new_host_buffer(size * arr.dtype.itemsize)
|
||||
np.frombuffer(hbuf, dtype=dtype)[:] = arr
|
||||
cbuf2 = ctx.buffer_from_object(hbuf)
|
||||
assert cbuf2.size == cbuf.size
|
||||
arr2 = np.frombuffer(cbuf2.copy_to_host(), dtype=dtype)
|
||||
np.testing.assert_equal(arr, arr2)
|
||||
|
||||
# Creating device buffer from a device buffer
|
||||
cbuf2 = ctx.buffer_from_object(cbuf2)
|
||||
assert cbuf2.size == cbuf.size
|
||||
arr2 = np.frombuffer(cbuf2.copy_to_host(), dtype=dtype)
|
||||
np.testing.assert_equal(arr, arr2)
|
||||
|
||||
# Trying to create a device buffer from a Buffer
|
||||
with pytest.raises(pa.ArrowTypeError,
|
||||
match=('buffer is not backed by a CudaBuffer')):
|
||||
ctx.buffer_from_object(pa.py_buffer(b"123"))
|
||||
|
||||
# Trying to create a device buffer from numpy.array
|
||||
with pytest.raises(NotImplementedError,
|
||||
match=('cannot create device buffer view from'
|
||||
' `<class \'numpy.ndarray\'>` object')):
|
||||
ctx.buffer_from_object(np.array([1, 2, 3]))
|
||||
|
||||
|
||||
@pytest.mark.parametrize("size", [0, 1, 8, 1000])
|
||||
def test_CudaBuffer(size):
|
||||
arr, buf = make_random_buffer(size)
|
||||
|
||||
@@ -90,12 +90,6 @@ def test_from_object(c, dtype, size):
|
||||
arr2 = np.frombuffer(cbuf2.copy_to_host(), dtype=dtype)
|
||||
np.testing.assert_equal(arr, arr2)
|
||||
|
||||
# Creating device buffer from a device buffer
|
||||
cbuf2 = ctx.buffer_from_object(cbuf2)
|
||||
assert cbuf2.size == cbuf.size
|
||||
arr2 = np.frombuffer(cbuf2.copy_to_host(), dtype=dtype)
|
||||
np.testing.assert_equal(arr, arr2)
|
||||
|
||||
# Creating device buffer from numba DeviceNDArray:
|
||||
darr = DeviceNDArray((size,), (np.dtype(dtype).itemsize,), np.dtype(dtype),
|
||||
gpu_data=mem)
|
||||
@@ -144,25 +138,6 @@ def test_from_object(c, dtype, size):
|
||||
arr2 = np.frombuffer(cbuf2.copy_to_host(), dtype=dtype)
|
||||
np.testing.assert_equal(arr, arr2)
|
||||
|
||||
# Creating device buffer from a CUDA host buffer
|
||||
hbuf = cuda.new_host_buffer(size * arr.dtype.itemsize)
|
||||
np.frombuffer(hbuf, dtype=dtype)[:] = arr
|
||||
cbuf2 = ctx.buffer_from_object(hbuf)
|
||||
assert cbuf2.size == cbuf.size
|
||||
arr2 = np.frombuffer(cbuf2.copy_to_host(), dtype=dtype)
|
||||
np.testing.assert_equal(arr, arr2)
|
||||
|
||||
# Trying to create a device buffer from a Buffer
|
||||
with pytest.raises(pa.ArrowTypeError,
|
||||
match=('buffer is not backed by a CudaBuffer')):
|
||||
ctx.buffer_from_object(pa.py_buffer(b"123"))
|
||||
|
||||
# Trying to create a device buffer from numpy.array
|
||||
with pytest.raises(NotImplementedError,
|
||||
match=('cannot create device buffer view from'
|
||||
' `<class \'numpy.ndarray\'>` object')):
|
||||
ctx.buffer_from_object(np.array([1,2,3]))
|
||||
|
||||
|
||||
@pytest.mark.parametrize("c", range(len(context_choice_ids)),
|
||||
ids=context_choice_ids)
|
||||
|
||||
Reference in new issue
Block a user