Skip to content

Commit

Permalink
Fixed CUDA failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kc611 committed Mar 19, 2024
1 parent 88b0fbb commit 21154b9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
9 changes: 7 additions & 2 deletions numba/cuda/cudadrv/devicearray.py
Expand Up @@ -868,10 +868,15 @@ def auto_device(obj, stream=0, copy=True, user_explicit=False):
# https://docs.scipy.org/doc/numpy-1.13.0/reference/arrays.interface.html
# into this function (with no overhead -- copies -- for `obj`s
# that are already `ndarray`s.
if isinstance(obj, (int, float, complex)) \
or not obj.data.contiguous:
copy_kwarg = dict()
else:
copy_kwarg = {"copy": False}
obj = np.array(
obj,
copy=False,
subok=True)
subok=True,
**copy_kwarg)
sentry_contiguous(obj)
devobj = from_array_like(obj, stream=stream)
if copy:
Expand Down
20 changes: 14 additions & 6 deletions numba/cuda/simulator/cudadrv/devicearray.py
Expand Up @@ -161,11 +161,16 @@ def copy_to_device(self, ary, stream=0):
sentry_contiguous(ary)
check_array_compatibility(self_core, ary_core)
else:
if isinstance(ary, (int, float, complex)) \
or not ary_core.data.contiguous:
copy_kwarg = dict()
else:
copy_kwarg = {"copy": False}
ary_core = np.array(
ary_core,
order='C' if self_core.flags['C_CONTIGUOUS'] else 'F',
subok=True,
copy=False)
**copy_kwarg)
check_array_compatibility(self_core, ary_core)
np.copyto(self_core._ary, ary_core)

Expand Down Expand Up @@ -299,7 +304,10 @@ def check_array_compatibility(ary1, ary2):


def to_device(ary, stream=0, copy=True, to=None):
ary = np.array(ary, copy=False, subok=True)
if isinstance(ary, (int, float, complex)) or not ary.data.contiguous:
ary = np.array(ary, subok=True)
else:
ary = np.array(ary, copy=False, subok=True)
sentry_contiguous(ary)
if to is None:
buffer_dtype = np.int64 if ary.dtype.char in 'Mm' else ary.dtype
Expand Down Expand Up @@ -395,10 +403,10 @@ def auto_device(ary, stream=0, copy=True):
return ary, False

if not isinstance(ary, np.void):
ary = np.array(
ary,
copy=False,
subok=True)
if isinstance(ary, (int, float, complex)) or not ary.data.contiguous:
ary = np.array(ary, subok=True)
else:
ary = np.array(ary, copy=False, subok=True)
return to_device(ary, stream, copy), True


Expand Down

0 comments on commit 21154b9

Please sign in to comment.