diff --git a/dpnp/dpnp_algo/dpnp_elementwise_common.py b/dpnp/dpnp_algo/dpnp_elementwise_common.py index b13ea56bc329..34a0a630bdf1 100644 --- a/dpnp/dpnp_algo/dpnp_elementwise_common.py +++ b/dpnp/dpnp_algo/dpnp_elementwise_common.py @@ -179,7 +179,6 @@ def __call__( out_usm = None if out is None else dpnp.get_usm_ndarray(out) res_usm = super().__call__(x_usm, out=out_usm, order=order) - dpnp.synchronize_array_data(res_usm) if out is not None and isinstance(out, dpnp_array): return out return dpnp_array._create_from_usm_ndarray(res_usm) @@ -352,7 +351,6 @@ def __call__( out_usm = None if out is None else dpnp.get_usm_ndarray(out) res_usm = super().__call__(x1_usm, x2_usm, out=out_usm, order=order) - dpnp.synchronize_array_data(res_usm) if out is not None and isinstance(out, dpnp_array): return out return dpnp_array._create_from_usm_ndarray(res_usm) @@ -540,7 +538,6 @@ def __call__(self, x, decimals=0, out=None, dtype=None): if dtype is not None: res_usm = dpt.astype(res_usm, dtype, copy=False) - dpnp.synchronize_array_data(res_usm) if out is not None and isinstance(out, dpnp_array): return out return dpnp_array._create_from_usm_ndarray(res_usm) diff --git a/dpnp/dpnp_array.py b/dpnp/dpnp_array.py index 1738e1dfcaf3..d4eb27810303 100644 --- a/dpnp/dpnp_array.py +++ b/dpnp/dpnp_array.py @@ -257,9 +257,6 @@ def __getitem__(self, key): res = self.__new__(dpnp_array) res._array_obj = item - - if self._array_obj.usm_data is not res._array_obj.usm_data: - dpnp.synchronize_array_data(self) return res def __gt__(self, other): @@ -456,7 +453,6 @@ def __setitem__(self, key, val): val = val.get_array() self._array_obj.__setitem__(key, val) - dpnp.synchronize_array_data(self) # '__setstate__', # '__sizeof__', diff --git a/dpnp/dpnp_container.py b/dpnp/dpnp_container.py index 8f70e015393c..401a12245092 100644 --- a/dpnp/dpnp_container.py +++ b/dpnp/dpnp_container.py @@ -80,7 +80,6 @@ def arange( sycl_queue=sycl_queue_normalized, ) - dpnp.synchronize_array_data(array_obj) return dpnp_array(array_obj.shape, buffer=array_obj) @@ -133,7 +132,6 @@ def asarray( if array_obj is x1_obj and isinstance(x1, dpnp_array): return x1 - dpnp.synchronize_array_data(array_obj) return dpnp_array(array_obj.shape, buffer=array_obj, order=order) @@ -143,7 +141,6 @@ def copy(x1, /, *, order="K"): order = "K" array_obj = dpt.copy(dpnp.get_usm_ndarray(x1), order=order) - dpnp.synchronize_array_data(array_obj) return dpnp_array(array_obj.shape, buffer=array_obj, order="K") @@ -205,7 +202,6 @@ def eye( usm_type=usm_type, sycl_queue=sycl_queue_normalized, ) - dpnp.synchronize_array_data(array_obj) return dpnp_array(array_obj.shape, buffer=array_obj, order=order) @@ -240,7 +236,6 @@ def full( usm_type=usm_type, sycl_queue=sycl_queue_normalized, ) - dpnp.synchronize_array_data(array_obj) return dpnp_array(array_obj.shape, buffer=array_obj, order=order) @@ -269,21 +264,18 @@ def ones( usm_type=usm_type, sycl_queue=sycl_queue_normalized, ) - dpnp.synchronize_array_data(array_obj) return dpnp_array(array_obj.shape, buffer=array_obj, order=order) def tril(x1, /, *, k=0): """Creates `dpnp_array` as lower triangular part of an input array.""" array_obj = dpt.tril(dpnp.get_usm_ndarray(x1), k=k) - dpnp.synchronize_array_data(array_obj) return dpnp_array(array_obj.shape, buffer=array_obj, order="K") def triu(x1, /, *, k=0): """Creates `dpnp_array` as upper triangular part of an input array.""" array_obj = dpt.triu(dpnp.get_usm_ndarray(x1), k=k) - dpnp.synchronize_array_data(array_obj) return dpnp_array(array_obj.shape, buffer=array_obj, order="K") @@ -312,6 +304,4 @@ def zeros( usm_type=usm_type, sycl_queue=sycl_queue_normalized, ) - # TODO: uncomment once dpctl implements asynchronous call - # dpnp.synchronize_array_data(array_obj) return dpnp_array(array_obj.shape, buffer=array_obj, order=order) diff --git a/dpnp/dpnp_iface.py b/dpnp/dpnp_iface.py index 7dded27b2d9b..a5bdb3899da2 100644 --- a/dpnp/dpnp_iface.py +++ b/dpnp/dpnp_iface.py @@ -284,7 +284,6 @@ def astype(x1, dtype, order="K", casting="unsafe", copy=True, device=None): x1_obj, dtype, order=order, casting=casting, copy=copy, device=device ) - dpnp.synchronize_array_data(x1) if array_obj is x1_obj and isinstance(x1, dpnp_array): # return x1 if dpctl returns a zero copy of x1_obj return x1 @@ -797,6 +796,5 @@ def synchronize_array_data(a): """ - if hasattr(dpu, "SequentialOrderManager"): - check_supported_arrays_type(a) - dpu.SequentialOrderManager[a.sycl_queue].wait() + check_supported_arrays_type(a) + dpu.SequentialOrderManager[a.sycl_queue].wait() diff --git a/dpnp/dpnp_iface_arraycreation.py b/dpnp/dpnp_iface_arraycreation.py index 6698f3f782e8..3197173d6386 100644 --- a/dpnp/dpnp_iface_arraycreation.py +++ b/dpnp/dpnp_iface_arraycreation.py @@ -2188,7 +2188,7 @@ def geomspace( """ - res = dpnp_geomspace( + return dpnp_geomspace( start, stop, num, @@ -2200,9 +2200,6 @@ def geomspace( axis=axis, ) - dpnp.synchronize_array_data(res) - return res - def identity( n, @@ -2410,7 +2407,7 @@ def linspace( """ - res = dpnp_linspace( + return dpnp_linspace( start, stop, num, @@ -2423,12 +2420,6 @@ def linspace( axis=axis, ) - if isinstance(res, tuple): # (result, step) is returning - dpnp.synchronize_array_data(res[0]) - else: - dpnp.synchronize_array_data(res) - return res - def loadtxt( fname, @@ -2643,7 +2634,7 @@ def logspace( """ - res = dpnp_logspace( + return dpnp_logspace( start, stop, num=num, @@ -2656,9 +2647,6 @@ def logspace( axis=axis, ) - dpnp.synchronize_array_data(res) - return res - # pylint: disable=redefined-outer-name def meshgrid(*xi, copy=True, sparse=False, indexing="xy"): @@ -2759,9 +2747,7 @@ def meshgrid(*xi, copy=True, sparse=False, indexing="xy"): if copy: output = [dpt.copy(x) for x in output] - dpnp.synchronize_array_data(output[0]) - output = [dpnp_array._create_from_usm_ndarray(x) for x in output] - return output + return [dpnp_array._create_from_usm_ndarray(x) for x in output] class MGridClass: diff --git a/dpnp/dpnp_iface_histograms.py b/dpnp/dpnp_iface_histograms.py index 3b211c30ef01..c0e95e588c1a 100644 --- a/dpnp/dpnp_iface_histograms.py +++ b/dpnp/dpnp_iface_histograms.py @@ -40,17 +40,11 @@ import operator import warnings -import dpctl.tensor as dpt import dpctl.utils as dpu import numpy import dpnp -from .dpnp_algo.dpnp_arraycreation import ( - dpnp_linspace, -) -from .dpnp_array import dpnp_array - __all__ = [ "digitize", "histogram", @@ -63,10 +57,14 @@ def _ravel_check_a_and_weights(a, weights): - """Check input `a` and `weights` arrays, and ravel both.""" + """ + Check input `a` and `weights` arrays, and ravel both. + The returned array have :class:`dpnp.ndarray` type always. + + """ # ensure that `a` array has supported type - a = dpnp.get_usm_ndarray(a) + dpnp.check_supported_arrays_type(a) usm_type = a.usm_type # ensure that the array is a "subtractable" dtype @@ -77,11 +75,11 @@ def _ravel_check_a_and_weights(a, weights): RuntimeWarning, stacklevel=3, ) - a = dpt.astype(a, numpy.uint8) + a = dpnp.astype(a, numpy.uint8) if weights is not None: # check that `weights` array has supported type - weights = dpnp.get_usm_ndarray(weights) + dpnp.check_supported_arrays_type(weights) usm_type = dpu.get_coerced_usm_type([usm_type, weights.usm_type]) # check that arrays have the same allocation queue @@ -92,9 +90,9 @@ def _ravel_check_a_and_weights(a, weights): if weights.shape != a.shape: raise ValueError("weights should have the same shape as a.") - weights = dpt.reshape(weights, -1) + weights = dpnp.ravel(weights) - a = dpt.reshape(a, -1) + a = dpnp.ravel(a) return a, weights, usm_type @@ -120,7 +118,7 @@ def _get_outer_edges(a, range): first_edge, last_edge = 0, 1 else: - first_edge, last_edge = dpt.min(a), dpt.max(a) + first_edge, last_edge = a.min(), a.max() if not (dpnp.isfinite(first_edge) and dpnp.isfinite(last_edge)): raise ValueError( f"autodetected range of [{first_edge}, {last_edge}] " @@ -164,9 +162,11 @@ def _get_bin_edges(a, bins, range, usm_type): "a and bins must be allocated on the same SYCL queue" ) - bin_edges = dpnp.as_usm_ndarray( - bins, usm_type=usm_type, sycl_queue=sycl_queue - ) + bin_edges = bins + else: + bin_edges = dpnp.asarray( + bins, sycl_queue=sycl_queue, usm_type=usm_type + ) if dpnp.any(bin_edges[:-1] > bin_edges[1:]): raise ValueError( @@ -188,7 +188,7 @@ def _get_bin_edges(a, bins, range, usm_type): ) # bin edges must be computed - bin_edges = dpnp_linspace( + bin_edges = dpnp.linspace( first_edge, last_edge, n_equal_bins + 1, @@ -196,7 +196,7 @@ def _get_bin_edges(a, bins, range, usm_type): dtype=bin_type, sycl_queue=sycl_queue, usm_type=usm_type, - ).get_array() + ) return bin_edges, (first_edge, last_edge, n_equal_bins) return bin_edges, None @@ -209,11 +209,8 @@ def _search_sorted_inclusive(a, v): """ - return dpt.concat( - ( - dpt.searchsorted(a, v[:-1], side="left"), - dpt.searchsorted(a, v[-1:], side="right"), - ) + return dpnp.concatenate( + (a.searchsorted(v[:-1], "left"), a.searchsorted(v[-1:], "right")) ) @@ -305,14 +302,8 @@ def digitize(x, bins, right=False): # Use dpnp.searchsorted directly if bins are increasing return dpnp.searchsorted(bins, x, side=side) - usm_x = dpnp.get_usm_ndarray(x) - usm_bins = dpnp.get_usm_ndarray(bins) - # Reverse bins and adjust indices if bins are decreasing - usm_res = usm_bins.size - dpt.searchsorted(usm_bins[::-1], usm_x, side=side) - - dpnp.synchronize_array_data(usm_res) - return dpnp_array._create_from_usm_ndarray(usm_res) + return bins.size - dpnp.searchsorted(bins[::-1], x, side=side) def histogram(a, bins=10, range=None, density=None, weights=None): @@ -426,36 +417,26 @@ def histogram(a, bins=10, range=None, density=None, weights=None): else: # Compute via cumulative histogram if weights is None: - sa = dpt.sort(a) + sa = dpnp.sort(a) cum_n = _search_sorted_inclusive(sa, bin_edges) else: - zero = dpt.zeros( + zero = dpnp.zeros( 1, dtype=ntype, sycl_queue=a.sycl_queue, usm_type=usm_type ) - sorting_index = dpt.argsort(a) + sorting_index = dpnp.argsort(a) sa = a[sorting_index] sw = weights[sorting_index] - cw = dpt.concat((zero, dpt.cumulative_sum(sw, dtype=ntype))) + cw = dpnp.concatenate((zero, sw.cumsum(dtype=ntype))) bin_index = _search_sorted_inclusive(sa, bin_edges) cum_n = cw[bin_index] n = dpnp.diff(cum_n) - # convert bin_edges to dpnp.ndarray - bin_edges = dpnp_array._create_from_usm_ndarray(bin_edges) - if density: # pylint: disable=possibly-used-before-assignment - db = dpnp.diff(bin_edges) - db = dpt.astype(db.get_array(), dpnp.default_float_type()) + db = dpnp.diff(bin_edges).astype(dpnp.default_float_type()) + return n / db / n.sum(), bin_edges - usm_n = n.get_array() - hist = usm_n / db / dpt.sum(usm_n) - - dpnp.synchronize_array_data(hist) - return dpnp_array._create_from_usm_ndarray(hist), bin_edges - - dpnp.synchronize_array_data(n) return n, bin_edges @@ -541,6 +522,4 @@ def histogram_bin_edges(a, bins=10, range=None, weights=None): a, weights, usm_type = _ravel_check_a_and_weights(a, weights) bin_edges, _ = _get_bin_edges(a, bins, range, usm_type) - - dpnp.synchronize_array_data(bin_edges) - return dpnp_array._create_from_usm_ndarray(bin_edges) + return bin_edges diff --git a/dpnp/dpnp_iface_manipulation.py b/dpnp/dpnp_iface_manipulation.py index a4b7352d4e64..b262e314440c 100644 --- a/dpnp/dpnp_iface_manipulation.py +++ b/dpnp/dpnp_iface_manipulation.py @@ -675,8 +675,6 @@ def concatenate( elif out is not None: dpnp.copyto(out, res, casting=casting) return out - - dpnp.synchronize_array_data(res) return res @@ -912,8 +910,6 @@ def expand_dims(a, axis): usm_a = dpnp.get_usm_ndarray(a) usm_res = dpt.expand_dims(usm_a, axis=axis) - - dpnp.synchronize_array_data(usm_res) return dpnp_array._create_from_usm_ndarray(usm_res) @@ -1303,8 +1299,6 @@ def repeat(a, repeats, axis=None): usm_arr = dpnp.get_usm_ndarray(a) usm_res = dpt.repeat(usm_arr, repeats, axis=axis) - - dpnp.synchronize_array_data(usm_res) return dpnp_array._create_from_usm_ndarray(usm_res) @@ -1382,8 +1376,6 @@ def reshape(a, /, newshape, order="C", copy=None): usm_a = dpnp.get_usm_ndarray(a) usm_res = dpt.reshape(usm_a, shape=newshape, order=order, copy=copy) - - dpnp.synchronize_array_data(usm_res) return dpnp_array._create_from_usm_ndarray(usm_res) @@ -1494,8 +1486,6 @@ def roll(x, shift, axis=None): usm_x = dpnp.get_usm_ndarray(x) usm_res = dpt.roll(usm_x, shift=shift, axis=axis) - - dpnp.synchronize_array_data(usm_res) return dpnp_array._create_from_usm_ndarray(usm_res) @@ -1645,8 +1635,6 @@ def squeeze(a, /, axis=None): usm_a = dpnp.get_usm_ndarray(a) usm_res = dpt.squeeze(usm_a, axis=axis) - - dpnp.synchronize_array_data(usm_res) return dpnp_array._create_from_usm_ndarray(usm_res) @@ -1732,8 +1720,6 @@ def stack(arrays, /, *, axis=0, out=None, dtype=None, casting="same_kind"): elif out is not None: dpnp.copyto(out, res, casting=casting) return out - - dpnp.synchronize_array_data(res) return res @@ -1788,8 +1774,6 @@ def swapaxes(a, axis1, axis2): usm_a = dpnp.get_usm_ndarray(a) usm_res = dpt.swapaxes(usm_a, axis1=axis1, axis2=axis2) - - dpnp.synchronize_array_data(usm_res) return dpnp_array._create_from_usm_ndarray(usm_res) @@ -1870,8 +1854,6 @@ def tile(A, reps): usm_a = dpnp.get_usm_ndarray(A) usm_res = dpt.tile(usm_a, reps) - - dpnp.synchronize_array_data(usm_res) return dpnp_array._create_from_usm_ndarray(usm_res)