From 21154b908cf104b559417543c7c257a60cbb6616 Mon Sep 17 00:00:00 2001 From: kc611 Date: Tue, 19 Mar 2024 14:27:19 +0530 Subject: [PATCH] Fixed CUDA failing tests --- numba/cuda/cudadrv/devicearray.py | 9 +++++++-- numba/cuda/simulator/cudadrv/devicearray.py | 20 ++++++++++++++------ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/numba/cuda/cudadrv/devicearray.py b/numba/cuda/cudadrv/devicearray.py index 2776fd30788..4f4aecf3526 100644 --- a/numba/cuda/cudadrv/devicearray.py +++ b/numba/cuda/cudadrv/devicearray.py @@ -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: diff --git a/numba/cuda/simulator/cudadrv/devicearray.py b/numba/cuda/simulator/cudadrv/devicearray.py index 75f6c4521fc..f9b3ddb60e6 100644 --- a/numba/cuda/simulator/cudadrv/devicearray.py +++ b/numba/cuda/simulator/cudadrv/devicearray.py @@ -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) @@ -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 @@ -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