Apply more feedback fixes.

This commit is contained in:
Pearu Peterson committed 2019-01-23 14:58:09 +02:00
1 parent 22134da4e2
commit 355fc0351d
5 files changed
+14 -39

No files matched your search

+2 -2
View File
@@ -121,12 +121,12 @@ class ARROW_EXPORT CudaContext : public std::enable_shared_from_this<CudaContext
/// \brief Return the device address that is reachable from kernels
/// running in the context
/// \param[in] addr memory address value
/// \param[in] addr device or host memory address
/// \param[out] devaddr the device address
/// \return Status
///
/// The device address is defined as a memory address accessible by
/// device. While it is often a device memory address but it can be
/// device. While it is often a device memory address, it can be
/// also a host memory address, for instance, when the memory is
/// allocated as host memory (using cudaMallocHost or cudaHostAlloc)
/// or as managed memory (using cudaMallocManaged) or the host
+3 -7
View File
@@ -19,7 +19,7 @@
from pyarrow.compat import tobytes
from pyarrow.lib cimport *
from pyarrow.includes.libarrow_cuda cimport *
from pyarrow.lib import py_buffer, allocate_buffer, as_buffer
from pyarrow.lib import py_buffer, allocate_buffer, as_buffer, ArrowTypeError
from pyarrow.util import get_contiguous_span
cimport cpython as cp
@@ -324,12 +324,8 @@ cdef class Context:
desc['shape'], desc.get('strides'),
np.dtype(desc['typestr']).itemsize)
return self.foreign_buffer(addr + start, end - start)
from numba.cuda.cudadrv.driver import MemoryPointer
if isinstance(obj, MemoryPointer):
addr = obj.device_pointer.value
return self.foreign_buffer(addr, obj.size)
raise NotImplementedError('cannot create device buffer view from'
' `%s` object' % (type(obj)))
raise ArrowTypeError('cannot create device buffer view from'
' `%s` object' % (type(obj)))
cdef class IpcMemHandle:
+1 -1
View File
@@ -256,7 +256,7 @@ def test_context_from_object(size):
ctx.buffer_from_object(pa.py_buffer(b"123"))
# Trying to create a device buffer from numpy.array
with pytest.raises(NotImplementedError,
with pytest.raises(pa.ArrowTypeError,
match=('cannot create device buffer view from'
' `<class \'numpy.ndarray\'>` object')):
ctx.buffer_from_object(np.array([1, 2, 3]))
@@ -83,19 +83,8 @@ def test_from_object(c, dtype, size):
ctx, nb_ctx = context_choices[c]
arr, cbuf = make_random_buffer(size, target='device', dtype=dtype, ctx=ctx)
# Creating device buffer from numba MemoryObject:
mem = cbuf.to_numba()
cbuf2 = ctx.buffer_from_object(mem)
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 = nb_cuda.to_device(arr)
darr = DeviceNDArray(size,
np.dtype(dtype).itemsize,
np.dtype(dtype),
gpu_data=mem)
cbuf2 = ctx.buffer_from_object(darr)
assert cbuf2.size == cbuf.size
arr2 = np.frombuffer(cbuf2.copy_to_host(), dtype=dtype)
@@ -116,23 +105,13 @@ def test_from_object(c, dtype, size):
arr2 = np.frombuffer(cbuf2.copy_to_host(), dtype=dtype)
np.testing.assert_equal(arr[s], arr2[s2])
# slice with negative strides
rdarr = darr[::-1]
if 1:
# workaround numba bug [numba issue 3705]:
from numba.cuda.cudadrv.driver import MemoryPointer
import ctypes
rdarr.shape = arr[::-1].shape
addr = (darr.__cuda_array_interface__['data'][0]
+ (arr[::-1].__array_interface__['data'][0]
- arr.__array_interface__['data'][0]))
mem = MemoryPointer(nb_ctx, pointer=ctypes.c_void_p(addr),
size=size)
rdarr.gpu_data = mem
cbuf2 = ctx.buffer_from_object(rdarr)
assert cbuf2.size == cbuf.size
arr2 = np.frombuffer(cbuf2.copy_to_host(), dtype=dtype)
np.testing.assert_equal(arr, arr2)
# cannot test negative strides due to numba bug, see its issue 3705
if 0:
rdarr = darr[::-1]
cbuf2 = ctx.buffer_from_object(rdarr)
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 2-dimensional numba DeviceNDArray:
if size >= 8:
+1 -1
View File
@@ -17,9 +17,9 @@
# Miscellaneous utility code
import functools
import six
import warnings
import functools
try: