diff --git a/dpnp/AGENTS.md b/dpnp/AGENTS.md index 5225f273f9e6..6e3986c57fdf 100644 --- a/dpnp/AGENTS.md +++ b/dpnp/AGENTS.md @@ -18,7 +18,7 @@ - Ufuncs are module-level wrapper instances, e.g. `cbrt = DPNPUnaryFunc("cbrt", ti._cbrt_result_type, ti._cbrt, _CBRT_DOCSTRING, mkl_fn_to_call=..., mkl_impl_fn=...)`. The first argument is the public name, with no leading underscore. Kernels come from `dpnp.libtensor._tensor_elementwise_impl`; the oneMKL VM path runs first when `mkl_fn_to_call` is given and supported. - Other functions: `dpnp.check_supported_arrays_type(...)`, unwrap with `dpnp.get_usm_ndarray`, call `dpnp.tensor` (`import dpnp.tensor as dpt`) or an extension, and wrap with `dpnp_array._create_from_usm_ndarray`. Pass `out` straight to the `dpnp.tensor` or extension call when it accepts one; otherwise `dpnp.get_result_array(res, out)` copies the result into it. - Get the result queue and USM type with `get_usm_allocations([...])` (raises `ValueError` on mixed queues) or `dpt.get_execution_queue(...)` (returns `None`; raise `ExecutionPlacementError`). Creation functions take `device`, `usm_type` and `sycl_queue` (normalised by `dpnp.get_normalized_queue_device`); `*_like` functions inherit them from the input. -- Extension calls are ordered with `_manager = dpctl.utils.SequentialOrderManager[exec_q]`: pass `depends=_manager.submitted_events`, then `_manager.add_event_pair(ht_ev, ev)`. Don't add blocking waits. +- Extension calls are ordered with `_manager = dpctl.utils.SequentialOrderManager[exec_q]`: pass `depends=_manager.submitted_events`, then `_manager.add_cleanup_event(ht_ev)` and `_manager.add_event(ev)`. Don't add blocking waits. - Use `dpnp.default_float_type(...)` or `map_dtype_to_device(...)` for the default float type. - Deprecated ufuncs use `DPNPDeprecatedUnaryFunc(..., deprecated_msg=...)`. - A `dpnp.random` distribution is a `Generator` method: it calls `self._check_queues(...)` on its array parameters (raises `ExecutionPlacementError`), checks host parameters as NumPy does, and draws through `_cont` or `_float_sample` into `BitGenerator._fill`. Parameters on the device are not checked, as the check waits for the device. With `usm_type=None`, the output and the temporaries take the coerced USM type of the array parameters (`Generator._sample`). diff --git a/dpnp/dpnp_algo/dpnp_elementwise_common.py b/dpnp/dpnp_algo/dpnp_elementwise_common.py index 40c4aef3ec08..65f9fef92cc2 100644 --- a/dpnp/dpnp_algo/dpnp_elementwise_common.py +++ b/dpnp/dpnp_algo/dpnp_elementwise_common.py @@ -493,7 +493,8 @@ def __call__( ht_copy_ev, copy_ev = dti._copy_usm_ndarray_into_usm_ndarray( src=x, dst=buf, sycl_queue=exec_q, depends=dep_evs ) - _manager.add_event_pair(ht_copy_ev, copy_ev) + _manager.add_cleanup_event(ht_copy_ev) + _manager.add_event(copy_ev) x = buf dep_evs = copy_ev @@ -515,7 +516,8 @@ def __call__( sycl_queue=exec_q, depends=_manager.submitted_events, ) - _manager.add_event_pair(ht_unary_ev, unary_ev) + _manager.add_cleanup_event(ht_unary_ev) + _manager.add_event(unary_ev) for i in range(self.nout): orig_res, res = orig_out[i], out[i] @@ -527,7 +529,8 @@ def __call__( sycl_queue=exec_q, depends=[unary_ev], ) - _manager.add_event_pair(ht_copy_ev, copy_ev) + _manager.add_cleanup_event(ht_copy_ev) + _manager.add_event(copy_ev) res = out[i] = orig_res if not isinstance(res, dpnp_array): @@ -1212,7 +1215,8 @@ def __call__( ht_copy_ev, copy_ev = dti._copy_usm_ndarray_into_usm_ndarray( src=x, dst=buf, sycl_queue=exec_q, depends=dep_evs ) - _manager.add_event_pair(ht_copy_ev, copy_ev) + _manager.add_cleanup_event(ht_copy_ev) + _manager.add_event(copy_ev) arrs[i] = buf x1, x2 = arrs @@ -1249,7 +1253,8 @@ def __call__( sycl_queue=exec_q, depends=_manager.submitted_events, ) - _manager.add_event_pair(ht_binary_ev, binary_ev) + _manager.add_cleanup_event(ht_binary_ev) + _manager.add_event(binary_ev) for i in range(self.nout): orig_res, res = orig_out[i], out[i] @@ -1261,7 +1266,8 @@ def __call__( sycl_queue=exec_q, depends=[binary_ev], ) - _manager.add_event_pair(ht_copy_ev, copy_ev) + _manager.add_cleanup_event(ht_copy_ev) + _manager.add_event(copy_ev) res = out[i] = orig_res if not isinstance(res, dpnp_array): diff --git a/dpnp/dpnp_algo/dpnp_fill.py b/dpnp/dpnp_algo/dpnp_fill.py index 8ffd2e6f2fad..36d9deafb62b 100644 --- a/dpnp/dpnp_algo/dpnp_fill.py +++ b/dpnp/dpnp_algo/dpnp_fill.py @@ -61,7 +61,8 @@ def dpnp_fill(arr, val): h_ev, c_ev = _copy_usm_ndarray_into_usm_ndarray( src=a_val, dst=arr, sycl_queue=exec_q, depends=dep_evs ) - _manager.add_event_pair(h_ev, c_ev) + _manager.add_cleanup_event(h_ev) + _manager.add_event(c_ev) return elif not isinstance(val, (Number, dpnp.bool)): raise TypeError( @@ -75,7 +76,9 @@ def dpnp_fill(arr, val): # can leverage efficient memset when val is 0 if arr.flags["FORC"] and val == 0: h_ev, zeros_ev = _zeros_usm_ndarray(arr, exec_q, depends=dep_evs) - _manager.add_event_pair(h_ev, zeros_ev) + _manager.add_cleanup_event(h_ev) + _manager.add_event(zeros_ev) else: h_ev, fill_ev = _full_usm_ndarray(val, arr, exec_q, depends=dep_evs) - _manager.add_event_pair(h_ev, fill_ev) + _manager.add_cleanup_event(h_ev) + _manager.add_event(fill_ev) diff --git a/dpnp/dpnp_iface_histograms.py b/dpnp/dpnp_iface_histograms.py index 0a968d62ea93..05c1ca1bfde4 100644 --- a/dpnp/dpnp_iface_histograms.py +++ b/dpnp/dpnp_iface_histograms.py @@ -294,7 +294,8 @@ def _bincount_run_native( depends=_manager.submitted_events, ) - _manager.add_event_pair(mem_ev, bc_ev) + _manager.add_cleanup_event(mem_ev) + _manager.add_event(bc_ev) return n_casted @@ -660,7 +661,8 @@ def histogram(a, bins=10, range=None, density=None, weights=None): n_usm, depends=_manager.submitted_events, ) - _manager.add_event_pair(mem_ev, ht_ev) + _manager.add_cleanup_event(mem_ev) + _manager.add_event(ht_ev) n = dpnp.asarray(n_casted, dtype=ntype, usm_type=usm_type) @@ -1044,7 +1046,8 @@ def _histdd_run_native( depends=_manager.submitted_events, ) - _manager.add_event_pair(mem_ev, hdd_ev) + _manager.add_cleanup_event(mem_ev) + _manager.add_event(hdd_ev) return n diff --git a/dpnp/dpnp_iface_indexing.py b/dpnp/dpnp_iface_indexing.py index 773d714ec28c..0fcd287de54a 100644 --- a/dpnp/dpnp_iface_indexing.py +++ b/dpnp/dpnp_iface_indexing.py @@ -143,7 +143,8 @@ def _choose_run(inds, chcs, q, usm_type, out=None, mode=0): dep_evs = _manager.submitted_events h_ev, choose_ev = ti._choose(inds, chcs, out, mode, q, dep_evs) - _manager.add_event_pair(h_ev, choose_ev) + _manager.add_cleanup_event(h_ev) + _manager.add_event(choose_ev) return out @@ -314,7 +315,8 @@ def _take_index(x, inds, axis, q, usm_type, out=None, mode=0): sycl_queue=q, depends=dep_evs, ) - _manager.add_event_pair(h_ev, take_ev) + _manager.add_cleanup_event(h_ev) + _manager.add_event(take_ev) return out @@ -1914,7 +1916,8 @@ def putmask(a, /, mask, values): h_ev, putmask_ev = ti._putmask( usm_a, usm_mask, usm_values_1d, exec_q, dep_evs ) - _manager.add_event_pair(h_ev, putmask_ev) + _manager.add_cleanup_event(h_ev) + _manager.add_event(putmask_ev) def ravel_multi_index(multi_index, dims, mode="raise", order="C"): diff --git a/dpnp/dpnp_iface_logic.py b/dpnp/dpnp_iface_logic.py index e7fbec0e626f..713f0a2e7926 100644 --- a/dpnp/dpnp_iface_logic.py +++ b/dpnp/dpnp_iface_logic.py @@ -123,7 +123,8 @@ def _isclose_scalar_tol(a, b, rtol, atol, equal_nan): exec_q, depends=_manager.submitted_events, ) - _manager.add_event_pair(mem_ev, ht_ev) + _manager.add_cleanup_event(mem_ev) + _manager.add_event(ht_ev) return output diff --git a/dpnp/dpnp_iface_mathematical.py b/dpnp/dpnp_iface_mathematical.py index 1ff6d12c0367..6928a38a121d 100644 --- a/dpnp/dpnp_iface_mathematical.py +++ b/dpnp/dpnp_iface_mathematical.py @@ -3096,7 +3096,8 @@ def interp(x, xp, fp, left=None, right=None, period=None): exec_q, depends=_manager.submitted_events, ) - _manager.add_event_pair(mem_ev, ht_ev) + _manager.add_cleanup_event(mem_ev) + _manager.add_event(ht_ev) return output @@ -3754,7 +3755,8 @@ def _check_nan_inf(val, val_dt): depends=_manager.submitted_events, ) - _manager.add_event_pair(h_ev, comp_ev) + _manager.add_cleanup_event(h_ev) + _manager.add_event(comp_ev) return dpnp.get_result_array(out) diff --git a/dpnp/dpnp_iface_sorting.py b/dpnp/dpnp_iface_sorting.py index e2ef8d68d9c8..80c40c789a8c 100644 --- a/dpnp/dpnp_iface_sorting.py +++ b/dpnp/dpnp_iface_sorting.py @@ -173,7 +173,8 @@ def _wrap_partition_argpartition(a, kth, axis, kind, order, return_indices): ht_ev, copy_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=usm_a, dst=usm_tmp, sycl_queue=exec_q, depends=dep_evs ) - _manager.add_event_pair(ht_ev, copy_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(copy_ev) usm_a = usm_tmp dep_evs = [copy_ev] @@ -194,7 +195,8 @@ def _wrap_partition_argpartition(a, kth, axis, kind, order, return_indices): ht_ev, part_ev = partition_fn( usm_a, kth[0], usm_res, sycl_queue=exec_q, depends=dep_evs ) - _manager.add_event_pair(ht_ev, part_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(part_ev) if axis != nd - 1: inv_perm = sorted(range(nd), key=lambda d: perm[d]) diff --git a/dpnp/dpnp_iface_statistics.py b/dpnp/dpnp_iface_statistics.py index 7923a05a8dcb..0b04840b5319 100644 --- a/dpnp/dpnp_iface_statistics.py +++ b/dpnp/dpnp_iface_statistics.py @@ -142,7 +142,8 @@ def _divide_by_scalar(a, v): ht_ev, div_ev = ti._divide_by_scalar( src=usm_a, scalar=v, dst=usm_a, sycl_queue=queue, depends=dep_evs ) - _manager.add_event_pair(ht_ev, div_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(div_ev) return a @@ -694,7 +695,8 @@ def _run_native_sliding_dot_product1d(a, v, l_pad, r_pad, rdtype): r_pad, depends=_manager.submitted_events, ) - _manager.add_event_pair(mem_ev, corr_ev) + _manager.add_cleanup_event(mem_ev) + _manager.add_event(corr_ev) return out diff --git a/dpnp/dpnp_iface_window.py b/dpnp/dpnp_iface_window.py index e87a3faed8bf..cb61e43f55c4 100644 --- a/dpnp/dpnp_iface_window.py +++ b/dpnp/dpnp_iface_window.py @@ -86,7 +86,8 @@ def _call_window_kernel( dpnp.get_usm_ndarray(result), ) - _manager.add_event_pair(ht_ev, win_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(win_ev) return result diff --git a/dpnp/dpnp_utils/dpnp_utils_linearalgebra.py b/dpnp/dpnp_utils/dpnp_utils_linearalgebra.py index f0659d43a10d..b104d26cbfd9 100644 --- a/dpnp/dpnp_utils/dpnp_utils_linearalgebra.py +++ b/dpnp/dpnp_utils/dpnp_utils_linearalgebra.py @@ -136,7 +136,8 @@ def _copy_array(x, copy_flag=False, dtype=None, order="C"): sycl_queue=exec_q, depends=_manager.submitted_events, ) - _manager.add_event_pair(ht_ev, copy_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(copy_ev) return x_copy return x @@ -276,7 +277,8 @@ def _gemm_batch_matmul(exec_q, x1, x2, res): res_usm, depends=_manager.submitted_events, ) - _manager.add_event_pair(ht_ev, blas_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(blas_ev) _, res_is_c_contig, res_is_f_contig = _define_contig_flag(res) if row_major: @@ -320,7 +322,8 @@ def _gemm_matmul(exec_q, x1, x2, res): dpnp.get_usm_ndarray(res), depends=_manager.submitted_events, ) - _manager.add_event_pair(ht_ev, gemm_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(gemm_ev) if row_major: if res.flags.f_contiguous: @@ -783,7 +786,8 @@ def dpnp_dot(a, b, /, out=None, *, casting="same_kind", conjugate=False): dpnp.get_usm_ndarray(result), depends=_manager.submitted_events, ) - _manager.add_event_pair(ht_ev, dot_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(dot_ev) else: # oneapi::mkl::blas::dot does not support integer dtypes, # so using dpnp.tensor.vecdot instead @@ -1067,7 +1071,8 @@ def dpnp_multiplication( trans_op=1 if transpose else 0, depends=_manager.submitted_events, ) - _manager.add_event_pair(ht_ev, gemv_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(gemv_ev) elif call_flag == "syrk": _manager = dpu.SequentialOrderManager[exec_q] ht_ev, gemv_ev = bi._syrk( @@ -1076,7 +1081,8 @@ def dpnp_multiplication( dpnp.get_usm_ndarray(result), depends=_manager.submitted_events, ) - _manager.add_event_pair(ht_ev, gemv_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(gemv_ev) elif call_flag == "gemm": result = _gemm_matmul(exec_q, x1, x2, result) else: diff --git a/dpnp/dpnp_utils/dpnp_utils_statistics.py b/dpnp/dpnp_utils/dpnp_utils_statistics.py index e8c504352b52..444dc314c981 100644 --- a/dpnp/dpnp_utils/dpnp_utils_statistics.py +++ b/dpnp/dpnp_utils/dpnp_utils_statistics.py @@ -110,7 +110,8 @@ def _calc_median_by_select(a, ignore_nan, out=None): ht_ev, copy_ev = dti._copy_usm_ndarray_into_usm_ndarray( src=usm_a, dst=usm_tmp, sycl_queue=exec_q, depends=dep_evs ) - _manager.add_event_pair(ht_ev, copy_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(copy_ev) usm_a = usm_tmp dep_evs = [copy_ev] @@ -145,7 +146,8 @@ def _calc_median_by_select(a, ignore_nan, out=None): all_nan=usm_all_nan, depends=dep_evs, ) - _manager.add_event_pair(ht_ev, median_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(median_ev) if ignore_nan: if usm_all_nan.usm_type == "host": @@ -535,7 +537,8 @@ def dpnp_minmax(x, /, *, axis=None, keepdims=False, out=None): ht_e_cpy, cpy_e = dti._copy_usm_ndarray_into_usm_ndarray( src=x_tmp, dst=res, sycl_queue=exec_q, depends=dep_evs ) - _manager.add_event_pair(ht_e_cpy, cpy_e) + _manager.add_cleanup_event(ht_e_cpy) + _manager.add_event(cpy_e) red_evs.append(cpy_e) else: hev, red_ev = tri._minmax_over_axis( @@ -546,7 +549,8 @@ def dpnp_minmax(x, /, *, axis=None, keepdims=False, out=None): sycl_queue=exec_q, depends=dep_evs, ) - _manager.add_event_pair(hev, red_ev) + _manager.add_cleanup_event(hev) + _manager.add_event(red_ev) red_evs = [red_ev] for i, res in enumerate(out): @@ -554,7 +558,8 @@ def dpnp_minmax(x, /, *, axis=None, keepdims=False, out=None): ht_e_cpy2, cpy2_e = dti._copy_usm_ndarray_into_usm_ndarray( src=res, dst=orig_out[i], sycl_queue=exec_q, depends=red_evs ) - _manager.add_event_pair(ht_e_cpy2, cpy2_e) + _manager.add_cleanup_event(ht_e_cpy2) + _manager.add_event(cpy2_e) out[i] = orig_out[i] if keepdims: diff --git a/dpnp/fft/dpnp_utils_fft.py b/dpnp/fft/dpnp_utils_fft.py index 78893a3c01e4..690fbea3da50 100644 --- a/dpnp/fft/dpnp_utils_fft.py +++ b/dpnp/fft/dpnp_utils_fft.py @@ -239,7 +239,8 @@ def _compute_result(dsc, a, out, forward, c2c, out_strides): ht_fft_event, fft_event = fi._fft_out_of_place( dsc, a_usm, res_usm, forward, depends=dep_evs ) - _manager.add_event_pair(ht_fft_event, fft_event) + _manager.add_cleanup_event(ht_fft_event) + _manager.add_event(fft_event) if not isinstance(result, dpnp_array): return dpnp_array._create_from_usm_ndarray(result) @@ -553,7 +554,8 @@ def _truncate_or_pad(a, shape, axes): sycl_queue=exec_q, depends=dep_evs, ) - _manager.add_event_pair(ht_copy_ev, copy_ev) + _manager.add_cleanup_event(ht_copy_ev) + _manager.add_event(copy_ev) a = z return a @@ -797,10 +799,12 @@ def dpnp_fillfreq(a, m, n, val): # it's assumed there are no dependent events to populate the array ht_lin_ev, lin_ev = ti._linspace_step(0, 1, a[:m].get_array(), exec_q) - _manager.add_event_pair(ht_lin_ev, lin_ev) + _manager.add_cleanup_event(ht_lin_ev) + _manager.add_event(lin_ev) ht_lin_ev, lin_ev = ti._linspace_step(m - n, 1, a[m:].get_array(), exec_q) - _manager.add_event_pair(ht_lin_ev, lin_ev) + _manager.add_cleanup_event(ht_lin_ev) + _manager.add_event(lin_ev) return a * val diff --git a/dpnp/linalg/dpnp_utils_linalg.py b/dpnp/linalg/dpnp_utils_linalg.py index d5be77b3b907..6403e26c1d93 100644 --- a/dpnp/linalg/dpnp_utils_linalg.py +++ b/dpnp/linalg/dpnp_utils_linalg.py @@ -142,7 +142,8 @@ def _batched_eigh(a, UPLO, eigen_mode, w_type, v_type): sycl_queue=a_sycl_queue, depends=dep_evs, ) - _manager.add_event_pair(ht_ev, a_copy_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(a_copy_ev) w_orig_shape = a_orig_shape[:-1] # allocate a memory for 2d dpnp array of eigenvalues @@ -157,7 +158,8 @@ def _batched_eigh(a, UPLO, eigen_mode, w_type, v_type): depends=[a_copy_ev], ) - _manager.add_event_pair(ht_ev, evd_batch_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(evd_batch_ev) w = w.reshape(w_orig_shape) @@ -214,7 +216,8 @@ def _batched_inv(a, res_type): sycl_queue=a.sycl_queue, depends=_manager.submitted_events, ) - _manager.add_event_pair(ht_ev, copy_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(copy_ev) ipiv_stride = n a_stride = a_h.strides[0] // a_h.itemsize @@ -233,7 +236,8 @@ def _batched_inv(a, res_type): batch_size, depends=[copy_ev], ) - _manager.add_event_pair(ht_ev, getrf_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(getrf_ev) _check_lapack_dev_info(dev_info) @@ -251,7 +255,8 @@ def _batched_inv(a, res_type): batch_size, depends=[getrf_ev], ) - _manager.add_event_pair(ht_ev, getri_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(getri_ev) _check_lapack_dev_info(dev_info) @@ -286,7 +291,8 @@ def _batched_lu_factor(a, res_type): sycl_queue=a_sycl_queue, depends=_manager.submitted_events, ) - _manager.add_event_pair(ht_ev, copy_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(copy_ev) ipiv_h = dpnp.empty( (batch_size, n), @@ -316,7 +322,8 @@ def _batched_lu_factor(a, res_type): batch_size, depends=[copy_ev], ) - _manager.add_event_pair(ht_ev, getrf_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(getrf_ev) else: dev_info_h = [[0] for _ in range(batch_size)] @@ -330,7 +337,8 @@ def _batched_lu_factor(a, res_type): dev_info_h[i], depends=[copy_ev], ) - _manager.add_event_pair(ht_ev, getrf_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(getrf_ev) # Reshape the results back to their original shape out_a = a_h.reshape(orig_shape) @@ -390,7 +398,8 @@ def _batched_solve(a, b, exec_q, res_usm_type, res_type): sycl_queue=exec_q, depends=dep_evs, ) - _manager.add_event_pair(ht_ev, a_copy_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(a_copy_ev) # oneMKL LAPACK gesv overwrites `b` and assumes fortran-like array # as input. @@ -402,7 +411,8 @@ def _batched_solve(a, b, exec_q, res_usm_type, res_type): sycl_queue=exec_q, depends=dep_evs, ) - _manager.add_event_pair(ht_ev, b_copy_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(b_copy_ev) ht_ev, gesv_batch_ev = li._gesv_batch( exec_q, @@ -411,7 +421,8 @@ def _batched_solve(a, b, exec_q, res_usm_type, res_type): depends=[a_copy_ev, b_copy_ev], ) - _manager.add_event_pair(ht_ev, gesv_batch_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(gesv_batch_ev) # Gesv call overwtires `b` in Fortran order, reorder the axes # to match C order by moving the last axis to the front and @@ -465,7 +476,8 @@ def _batched_qr(a, mode="reduced"): sycl_queue=a_sycl_queue, depends=_manager.submitted_events, ) - _manager.add_event_pair(ht_ev, copy_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(copy_ev) tau_h = dpnp.empty_like( a_t, @@ -496,7 +508,8 @@ def _batched_qr(a, mode="reduced"): if dpnp.is_cuda_backend(a_sycl_queue): # pragma: no cover ht_ev.wait() else: - _manager.add_event_pair(ht_ev, geqrf_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(geqrf_ev) if mode in ["r", "raw"]: if mode == "r": @@ -535,7 +548,8 @@ def _batched_qr(a, mode="reduced"): sycl_queue=a_sycl_queue, depends=[geqrf_ev], ) - _manager.add_event_pair(ht_ev, copy_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(copy_ev) q_stride = q.strides[0] // q.itemsize tau_stride = tau_h.strides[0] // tau_h.itemsize @@ -563,7 +577,8 @@ def _batched_qr(a, mode="reduced"): batch_size, depends=[copy_ev], ) - _manager.add_event_pair(ht_ev, lapack_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(lapack_ev) q = q[..., :mc, :].swapaxes(-2, -1) r = a_t[..., :mc].swapaxes(-2, -1) @@ -669,7 +684,8 @@ def _batched_svd( sycl_queue=exec_q, depends=dep_evs, ) - _manager.add_event_pair(ht_ev, a_copy_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(a_copy_ev) u_h = dpnp.empty( u_shape, @@ -703,7 +719,8 @@ def _batched_svd( vt_h.get_array(), depends=[a_copy_ev], ) - _manager.add_event_pair(ht_ev, gesvd_batch_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(gesvd_batch_ev) s = s_h.reshape(batch_shape_orig + s_h.shape[-1:]) if compute_uv: @@ -992,7 +1009,8 @@ def _lu_factor(a, res_type): sycl_queue=a_sycl_queue, depends=_manager.submitted_events, ) - _manager.add_event_pair(ht_ev, copy_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(copy_ev) ipiv_h = dpnp.empty( n, @@ -1012,7 +1030,8 @@ def _lu_factor(a, res_type): dev_info_h, depends=[copy_ev], ) - _manager.add_event_pair(ht_ev, getrf_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(getrf_ev) dev_info_array = dpnp.array( dev_info_h, usm_type=a_usm_type, sycl_queue=a_sycl_queue @@ -1405,7 +1424,8 @@ def _triu_inplace(a): sycl_queue=a.sycl_queue, depends=_manager.submitted_events, ) - _manager.add_event_pair(ht_ev, triu_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(triu_ev) return out @@ -1824,7 +1844,8 @@ def dpnp_cholesky_batch(a, upper_lower, res_type): sycl_queue=a_sycl_queue, depends=_manager.submitted_events, ) - _manager.add_event_pair(ht_ev, copy_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(copy_ev) a_stride = a_h.strides[0] // a_h.itemsize @@ -1840,7 +1861,8 @@ def dpnp_cholesky_batch(a, upper_lower, res_type): batch_size, depends=[copy_ev], ) - _manager.add_event_pair(ht_ev, potrf_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(potrf_ev) # Get upper or lower-triangular matrix part as per `upper_lower` value # upper_lower is 0 (lower) or 1 (upper) @@ -1906,7 +1928,8 @@ def dpnp_cholesky(a, upper): sycl_queue=a_sycl_queue, depends=_manager.submitted_events, ) - _manager.add_event_pair(ht_ev, copy_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(copy_ev) # Call the LAPACK extension function _potrf # to computes the Cholesky decomposition @@ -1916,7 +1939,8 @@ def dpnp_cholesky(a, upper): upper_lower, depends=[copy_ev], ) - _manager.add_event_pair(ht_ev, potrf_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(potrf_ev) # Get upper or lower-triangular matrix part as per `upper` value if upper: @@ -2071,7 +2095,8 @@ def dpnp_eigh(a, UPLO="L", eigen_mode="V"): sycl_queue=a_sycl_queue, depends=_manager.submitted_events, ) - _manager.add_event_pair(ht_ev, copy_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(copy_ev) # allocate a memory for dpnp array of eigenvalues w = dpnp.empty_like( @@ -2090,7 +2115,8 @@ def dpnp_eigh(a, UPLO="L", eigen_mode="V"): w.get_array(), depends=_manager.submitted_events, ) - _manager.add_event_pair(ht_ev, lapack_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(lapack_ev) if eigen_mode == "V" and a_order != "F": # need to align order of eigenvectors with one of input matrix A @@ -2102,7 +2128,8 @@ def dpnp_eigh(a, UPLO="L", eigen_mode="V"): sycl_queue=a_sycl_queue, depends=[lapack_ev], ) - _manager.add_event_pair(ht_ev, copy_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(copy_ev) else: out_v = v @@ -2150,7 +2177,8 @@ def dpnp_inv(a): sycl_queue=a_sycl_queue, depends=_manager.submitted_events, ) - _manager.add_event_pair(ht_ev, copy_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(copy_ev) b_f = dpnp.eye( a_shape[0], @@ -2171,7 +2199,8 @@ def dpnp_inv(a): ht_ev, gesv_ev = li._gesv( a_sycl_queue, usm_a_f, usm_b_f, depends=_manager.submitted_events ) - _manager.add_event_pair(ht_ev, gesv_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(gesv_ev) return b_f @@ -2480,7 +2509,8 @@ def dpnp_qr(a, mode="reduced"): sycl_queue=a_sycl_queue, depends=_manager.submitted_events, ) - _manager.add_event_pair(ht_ev, copy_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(copy_ev) tau_h = dpnp.empty_like( a, @@ -2500,7 +2530,8 @@ def dpnp_qr(a, mode="reduced"): if dpnp.is_cuda_backend(a_sycl_queue): # pragma: no cover ht_ev.wait() else: - _manager.add_event_pair(ht_ev, geqrf_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(geqrf_ev) if mode in ["r", "raw"]: if mode == "r": @@ -2539,7 +2570,8 @@ def dpnp_qr(a, mode="reduced"): sycl_queue=a_sycl_queue, depends=[geqrf_ev], ) - _manager.add_event_pair(ht_ev, copy_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(copy_ev) # Get LAPACK function (_orgqr for real or _ungqf for complex data types) # for QR factorization @@ -2560,7 +2592,8 @@ def dpnp_qr(a, mode="reduced"): tau_h.get_array(), depends=[copy_ev], ) - _manager.add_event_pair(ht_ev, lapack_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(lapack_ev) q = q[:mc].transpose() r = a_t[:, :mc].transpose() @@ -2606,7 +2639,8 @@ def dpnp_solve(a, b): sycl_queue=a.sycl_queue, depends=dep_evs, ) - _manager.add_event_pair(ht_ev, a_copy_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(a_copy_ev) # oneMKL LAPACK getrs overwrites `b` and assumes fortran-like array as # input. @@ -2622,7 +2656,8 @@ def dpnp_solve(a, b): sycl_queue=b.sycl_queue, depends=dep_evs, ) - _manager.add_event_pair(ht_ev, b_copy_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(b_copy_ev) # Call the LAPACK extension function _gesv to solve the system of linear # equations with the coefficient square matrix and @@ -2631,7 +2666,8 @@ def dpnp_solve(a, b): exec_q, a_h.get_array(), b_h.get_array(), [a_copy_ev, b_copy_ev] ) - _manager.add_event_pair(ht_lapack_ev, gesv_ev) + _manager.add_cleanup_event(ht_lapack_ev) + _manager.add_event(gesv_ev) return b_h @@ -2766,7 +2802,8 @@ def dpnp_svd( sycl_queue=exec_q, depends=_manager.submitted_events, ) - _manager.add_event_pair(ht_ev, copy_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(copy_ev) u_shape, vt_shape, s_shape, jobu, jobvt = _get_svd_shapes_and_flags( m, n, compute_uv, full_matrices @@ -2797,7 +2834,8 @@ def dpnp_svd( vt_h.get_array(), depends=[copy_ev], ) - _manager.add_event_pair(ht_ev, gesvd_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(gesvd_ev) if compute_uv: # Transposing the input matrix swaps the roles of U and Vt: diff --git a/dpnp/random/_bit_generator.py b/dpnp/random/_bit_generator.py index e7349c524ae6..67c5738e1a93 100644 --- a/dpnp/random/_bit_generator.py +++ b/dpnp/random/_bit_generator.py @@ -250,7 +250,8 @@ def _fill(self, kernel, params, result): result_usm, depends=_manager.submitted_events, ) - _manager.add_event_pair(ht_ev, ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(ev) return result def random_raw(self, size=None, output=True, *, usm_type=None): diff --git a/dpnp/scipy/linalg/_utils.py b/dpnp/scipy/linalg/_utils.py index 12beae467517..c049a2d1e309 100644 --- a/dpnp/scipy/linalg/_utils.py +++ b/dpnp/scipy/linalg/_utils.py @@ -177,7 +177,8 @@ def _batched_lu_factor_scipy(a, res_type): # pylint: disable=too-many-locals sycl_queue=a_sycl_queue, depends=_manager.submitted_events, ) - _manager.add_event_pair(ht_ev, copy_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(copy_ev) ipiv_h = dpnp.empty( (batch_size, k), @@ -207,7 +208,8 @@ def _batched_lu_factor_scipy(a, res_type): # pylint: disable=too-many-locals batch_size, depends=[copy_ev], ) - _manager.add_event_pair(ht_ev, getrf_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(getrf_ev) if any(dev_info_h): diag_nums = ", ".join(str(v) for v in dev_info_h if v > 0) @@ -229,7 +231,8 @@ def _batched_lu_factor_scipy(a, res_type): # pylint: disable=too-many-locals dev_info_vecs[i], depends=[copy_ev], ) - _manager.add_event_pair(ht_ev, getrf_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(getrf_ev) diag_nums = ", ".join( str(v) for info in dev_info_vecs for v in info if v > 0 @@ -308,7 +311,8 @@ def _batched_lu_solve(lu, piv, b, res_type, trans=0): sycl_queue=lu.sycl_queue, depends=dep_evs, ) - _manager.add_event_pair(ht_ev, lu_copy_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(lu_copy_ev) # oneMKL LAPACK getrs_batch overwrites `b` and assumes fortran-like array # as input @@ -319,7 +323,8 @@ def _batched_lu_solve(lu, piv, b, res_type, trans=0): sycl_queue=b.sycl_queue, depends=dep_evs, ) - _manager.add_event_pair(ht_ev, b_copy_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(b_copy_ev) dep_evs = [lu_copy_ev, b_copy_ev] lu_stride = n * n @@ -345,7 +350,8 @@ def _batched_lu_solve(lu, piv, b, res_type, trans=0): batch_size, depends=dep_evs, ) - _manager.add_event_pair(ht_ev, getrs_batch_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(getrs_batch_ev) # Restore original shape: move batch axis back and reshape b_h = dpnp.moveaxis(b_h, -1, 0).reshape(b_orig_shape) @@ -532,7 +538,8 @@ def _potrs(c_f, b_f, uplo, exec_q): uplo, depends=_manager.submitted_events, ) - _manager.add_event_pair(ht_ev, potrs_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(potrs_ev) def _trsm(a_f, b_f, uplo, trans_op, unit_diagonal, exec_q): @@ -554,7 +561,8 @@ def _trsm(a_f, b_f, uplo, trans_op, unit_diagonal, exec_q): unit_diag=unit_diagonal, depends=_manager.submitted_events, ) - _manager.add_event_pair(ht_ev, trsm_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(trsm_ev) def _tri_trans_op(trans, flipped): @@ -585,7 +593,8 @@ def _copy_rhs(src, dst, conj, exec_q): sycl_queue=exec_q, depends=_manager.submitted_events, ) - _manager.add_event_pair(ht_ev, copy_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(copy_ev) if conj and dpnp.iscomplexobj(src): dpnp.conj(dst, out=dst) @@ -771,7 +780,8 @@ def dpnp_cho_factor(a, lower=False, overwrite_a=False, check_finite=True): sycl_queue=a_sycl_queue, depends=_manager.submitted_events, ) - _manager.add_event_pair(ht_ev, copy_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(copy_ev) dep_ev = [copy_ev] # oneMKL is column-major and sees a C-contiguous `c` transposed, @@ -802,7 +812,8 @@ def dpnp_cho_factor(a, lower=False, overwrite_a=False, check_finite=True): batch_size, depends=dep_ev, ) - _manager.add_event_pair(ht_ev, potrf_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(potrf_ev) return c, lower @@ -906,7 +917,8 @@ def dpnp_lu_factor(a, overwrite_a=False, check_finite=True): sycl_queue=a_sycl_queue, depends=_manager.submitted_events, ) - _manager.add_event_pair(ht_ev, dep_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(dep_ev) dep_ev = [dep_ev] else: # input is suitable for in-place modification @@ -933,7 +945,8 @@ def dpnp_lu_factor(a, overwrite_a=False, check_finite=True): dev_info_h, depends=dep_ev, ) - _manager.add_event_pair(ht_ev, getrf_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(getrf_ev) if any(dev_info_h): diag_nums = ", ".join(str(v) for v in dev_info_h if v > 0) @@ -1159,7 +1172,8 @@ def dpnp_lu_solve(lu, piv, b, trans=0, overwrite_b=False, check_finite=True): sycl_queue=lu.sycl_queue, depends=dep_evs, ) - _manager.add_event_pair(ht_ev, lu_copy_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(lu_copy_ev) # SciPy-compatible behavior # Copy is required if: @@ -1177,7 +1191,8 @@ def dpnp_lu_solve(lu, piv, b, trans=0, overwrite_b=False, check_finite=True): sycl_queue=b.sycl_queue, depends=dep_evs, ) - _manager.add_event_pair(ht_ev, b_copy_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(b_copy_ev) dep_evs = [lu_copy_ev, b_copy_ev] else: # input is suitable for in-place modification @@ -1197,7 +1212,8 @@ def dpnp_lu_solve(lu, piv, b, trans=0, overwrite_b=False, check_finite=True): trans_mkl, depends=dep_evs, ) - _manager.add_event_pair(ht_ev, getrs_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(getrs_ev) return b_h diff --git a/dpnp/scipy/sparse/_csr.py b/dpnp/scipy/sparse/_csr.py index d22b81dbb37e..19c07929b604 100644 --- a/dpnp/scipy/sparse/_csr.py +++ b/dpnp/scipy/sparse/_csr.py @@ -642,7 +642,8 @@ def _ensure_spmv_handle(self): _manager.submitted_events, ) - _manager.add_event_pair(ev, ev) + _manager.add_cleanup_event(ev) + _manager.add_event(ev) self._spmv_si = _si self._spmv_handle = handle @@ -720,7 +721,8 @@ def dot(self, x): ncols, _manager.submitted_events, ) - _manager.add_event_pair(ht_ev, comp_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(comp_ev) return y def __matmul__(self, x): @@ -741,7 +743,8 @@ def __del__(self): release_ev = _si._sparse_gemv_release( exec_q, handle, _manager.submitted_events ) - _manager.add_event_pair(release_ev, release_ev) + _manager.add_cleanup_event(release_ev) + _manager.add_event(release_ev) release_ev.wait() except Exception: # pylint: disable=broad-exception-caught pass diff --git a/dpnp/scipy/sparse/linalg/_iterative.py b/dpnp/scipy/sparse/linalg/_iterative.py index 25d54988a4da..86294810f4df 100644 --- a/dpnp/scipy/sparse/linalg/_iterative.py +++ b/dpnp/scipy/sparse/linalg/_iterative.py @@ -148,7 +148,8 @@ def matvec(self, x): int(self._A.shape[1]), _manager.submitted_events, ) - _manager.add_event_pair(ht_ev, comp_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(comp_ev) return y # pylint: disable-next=unused-argument @@ -979,7 +980,8 @@ def compute_hu(u, j): beta=0.0, depends=_manager.submitted_events, ) - _manager.add_event_pair(ht1, ev1) + _manager.add_cleanup_event(ht1) + _manager.add_event(ev1) # Pass 2: u = -Vj @ H[:j+1, j] + 1 * u (alpha=-1, beta=1) # pylint: disable-next=protected-access @@ -993,7 +995,8 @@ def compute_hu(u, j): beta=1.0, depends=_manager.submitted_events, ) - _manager.add_event_pair(ht2, ev2) + _manager.add_cleanup_event(ht2) + _manager.add_event(ev2) return u diff --git a/dpnp/tensor/_accumulation.py b/dpnp/tensor/_accumulation.py index d5a56521f495..f4e0304ab7b1 100644 --- a/dpnp/tensor/_accumulation.py +++ b/dpnp/tensor/_accumulation.py @@ -152,13 +152,15 @@ def _accumulate_common( ht_e, acc_ev = _accumulate_include_initial_fn( src=arr, dst=out, sycl_queue=q, depends=depends ) - _manager.add_event_pair(ht_e, acc_ev) + _manager.add_cleanup_event(ht_e) + _manager.add_event(acc_ev) if not (orig_out is None or out is orig_out): # Copy the out data from temporary buffer to original memory ht_e_cpy, cpy_e = ti._copy_usm_ndarray_into_usm_ndarray( src=out, dst=orig_out, sycl_queue=q, depends=[acc_ev] ) - _manager.add_event_pair(ht_e_cpy, cpy_e) + _manager.add_cleanup_event(ht_e_cpy) + _manager.add_event(cpy_e) out = orig_out else: if _dtype_supported(res_dt, res_dt): @@ -168,7 +170,8 @@ def _accumulate_common( ht_e_cpy, cpy_e = ti._copy_usm_ndarray_into_usm_ndarray( src=arr, dst=tmp, sycl_queue=q, depends=depends ) - _manager.add_event_pair(ht_e_cpy, cpy_e) + _manager.add_cleanup_event(ht_e_cpy) + _manager.add_event(cpy_e) if not include_initial: ht_e, acc_ev = _accumulate_fn( src=tmp, @@ -184,7 +187,8 @@ def _accumulate_common( sycl_queue=q, depends=[cpy_e], ) - _manager.add_event_pair(ht_e, acc_ev) + _manager.add_cleanup_event(ht_e) + _manager.add_event(acc_ev) else: buf_dt = _default_accumulation_type_fn(inp_dt, q) tmp = dpt.empty( @@ -193,7 +197,8 @@ def _accumulate_common( ht_e_cpy, cpy_e = ti._copy_usm_ndarray_into_usm_ndarray( src=arr, dst=tmp, sycl_queue=q, depends=depends ) - _manager.add_event_pair(ht_e_cpy, cpy_e) + _manager.add_cleanup_event(ht_e_cpy) + _manager.add_event(cpy_e) tmp_res = dpt.empty( res_sh, dtype=buf_dt, usm_type=res_usm_type, sycl_queue=q ) @@ -214,11 +219,13 @@ def _accumulate_common( sycl_queue=q, depends=[cpy_e], ) - _manager.add_event_pair(ht_e, acc_ev) + _manager.add_cleanup_event(ht_e) + _manager.add_event(acc_ev) ht_e_cpy2, cpy_e2 = ti._copy_usm_ndarray_into_usm_ndarray( src=tmp_res, dst=out, sycl_queue=q, depends=[acc_ev] ) - _manager.add_event_pair(ht_e_cpy2, cpy_e2) + _manager.add_cleanup_event(ht_e_cpy2) + _manager.add_event(cpy_e2) if appended_axis: out = dpt.squeeze(out) diff --git a/dpnp/tensor/_clip.py b/dpnp/tensor/_clip.py index 0e9c77f8103c..1ef99275965f 100644 --- a/dpnp/tensor/_clip.py +++ b/dpnp/tensor/_clip.py @@ -209,7 +209,8 @@ def _clip_none(x, val, out, order, _binary_fn): ht_binary_ev, binary_ev = _binary_fn( src1=x, src2=val_ary, dst=out, sycl_queue=exec_q, depends=dep_evs ) - _manager.add_event_pair(ht_binary_ev, binary_ev) + _manager.add_cleanup_event(ht_binary_ev) + _manager.add_event(binary_ev) if not (orig_out is None or orig_out is out): # Copy the out data from temporary buffer to original memory ht_copy_out_ev, copy_ev = ti._copy_usm_ndarray_into_usm_ndarray( @@ -218,7 +219,8 @@ def _clip_none(x, val, out, order, _binary_fn): sycl_queue=exec_q, depends=[binary_ev], ) - _manager.add_event_pair(ht_copy_out_ev, copy_ev) + _manager.add_cleanup_event(ht_copy_out_ev) + _manager.add_event(copy_ev) out = orig_out return out else: @@ -231,7 +233,8 @@ def _clip_none(x, val, out, order, _binary_fn): ht_copy_ev, copy_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=val_ary, dst=buf, sycl_queue=exec_q, depends=dep_evs ) - _manager.add_event_pair(ht_copy_ev, copy_ev) + _manager.add_cleanup_event(ht_copy_ev) + _manager.add_event(copy_ev) if out is None: if order == "K": out = _empty_like_pair_orderK( @@ -256,7 +259,8 @@ def _clip_none(x, val, out, order, _binary_fn): sycl_queue=exec_q, depends=[copy_ev], ) - _manager.add_event_pair(ht_binary_ev, binary_ev) + _manager.add_cleanup_event(ht_binary_ev) + _manager.add_event(binary_ev) if not (orig_out is None or orig_out is out): # Copy the out data from temporary buffer to original memory ht_copy_out_ev, cpy_ev = ti._copy_usm_ndarray_into_usm_ndarray( @@ -265,7 +269,8 @@ def _clip_none(x, val, out, order, _binary_fn): sycl_queue=exec_q, depends=[binary_ev], ) - _manager.add_event_pair(ht_copy_out_ev, cpy_ev) + _manager.add_cleanup_event(ht_copy_out_ev) + _manager.add_event(cpy_ev) out = orig_out return out @@ -360,7 +365,8 @@ def clip(x, /, min=None, max=None, out=None, order="K"): ht_copy_ev, copy_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=x, dst=out, sycl_queue=exec_q, depends=dep_evs ) - _manager.add_event_pair(ht_copy_ev, copy_ev) + _manager.add_cleanup_event(ht_copy_ev) + _manager.add_event(copy_ev) if not (orig_out is None or orig_out is out): # Copy the out data from temporary buffer to original memory ht_copy_out_ev, cpy_ev = ti._copy_usm_ndarray_into_usm_ndarray( @@ -369,7 +375,8 @@ def clip(x, /, min=None, max=None, out=None, order="K"): sycl_queue=exec_q, depends=[copy_ev], ) - _manager.add_event_pair(ht_copy_ev, cpy_ev) + _manager.add_cleanup_event(ht_copy_ev) + _manager.add_event(cpy_ev) out = orig_out return out elif max is None: @@ -585,7 +592,8 @@ def clip(x, /, min=None, max=None, out=None, order="K"): sycl_queue=exec_q, depends=dep_ev, ) - _manager.add_event_pair(ht_binary_ev, binary_ev) + _manager.add_cleanup_event(ht_binary_ev) + _manager.add_event(binary_ev) if not (orig_out is None or orig_out is out): # Copy the out data from temporary buffer to original memory ht_copy_out_ev, cpy_ev = ti._copy_usm_ndarray_into_usm_ndarray( @@ -594,7 +602,8 @@ def clip(x, /, min=None, max=None, out=None, order="K"): sycl_queue=exec_q, depends=[binary_ev], ) - _manager.add_event_pair(ht_copy_out_ev, cpy_ev) + _manager.add_cleanup_event(ht_copy_out_ev) + _manager.add_event(cpy_ev) out = orig_out return out @@ -608,7 +617,8 @@ def clip(x, /, min=None, max=None, out=None, order="K"): ht_copy_ev, copy_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=a_max, dst=buf2, sycl_queue=exec_q, depends=dep_ev ) - _manager.add_event_pair(ht_copy_ev, copy_ev) + _manager.add_cleanup_event(ht_copy_ev) + _manager.add_event(copy_ev) if out is None: if order == "K": out = _empty_like_triple_orderK( @@ -641,7 +651,8 @@ def clip(x, /, min=None, max=None, out=None, order="K"): sycl_queue=exec_q, depends=[copy_ev], ) - _manager.add_event_pair(ht_binary_ev, binary_ev) + _manager.add_cleanup_event(ht_binary_ev) + _manager.add_event(binary_ev) if not (orig_out is None or orig_out is out): # Copy the out data from temporary buffer to original memory ht_copy_out_ev, cpy_ev = ti._copy_usm_ndarray_into_usm_ndarray( @@ -650,7 +661,8 @@ def clip(x, /, min=None, max=None, out=None, order="K"): sycl_queue=exec_q, depends=[binary_ev], ) - _manager.add_event_pair(ht_copy_out_ev, cpy_ev) + _manager.add_cleanup_event(ht_copy_out_ev) + _manager.add_event(cpy_ev) out = orig_out return out @@ -664,7 +676,8 @@ def clip(x, /, min=None, max=None, out=None, order="K"): ht_copy_ev, copy_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=a_min, dst=buf1, sycl_queue=exec_q, depends=dep_ev ) - _manager.add_event_pair(ht_copy_ev, copy_ev) + _manager.add_cleanup_event(ht_copy_ev) + _manager.add_event(copy_ev) if out is None: if order == "K": out = _empty_like_triple_orderK( @@ -697,7 +710,8 @@ def clip(x, /, min=None, max=None, out=None, order="K"): sycl_queue=exec_q, depends=[copy_ev], ) - _manager.add_event_pair(ht_binary_ev, binary_ev) + _manager.add_cleanup_event(ht_binary_ev) + _manager.add_event(binary_ev) if not (orig_out is None or orig_out is out): # Copy the out data from temporary buffer to original memory ht_copy_out_ev, cpy_ev = ti._copy_usm_ndarray_into_usm_ndarray( @@ -706,7 +720,8 @@ def clip(x, /, min=None, max=None, out=None, order="K"): sycl_queue=exec_q, depends=[binary_ev], ) - _manager.add_event_pair(ht_copy_out_ev, cpy_ev) + _manager.add_cleanup_event(ht_copy_out_ev) + _manager.add_event(cpy_ev) out = orig_out return out @@ -733,7 +748,8 @@ def clip(x, /, min=None, max=None, out=None, order="K"): ht_copy1_ev, copy1_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=a_min, dst=buf1, sycl_queue=exec_q, depends=dep_evs ) - _manager.add_event_pair(ht_copy1_ev, copy1_ev) + _manager.add_cleanup_event(ht_copy1_ev) + _manager.add_event(copy1_ev) if order == "K": buf2 = _empty_like_orderK(a_max, buf2_dt) else: @@ -741,7 +757,8 @@ def clip(x, /, min=None, max=None, out=None, order="K"): ht_copy2_ev, copy2_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=a_max, dst=buf2, sycl_queue=exec_q, depends=dep_evs ) - _manager.add_event_pair(ht_copy2_ev, copy2_ev) + _manager.add_cleanup_event(ht_copy2_ev) + _manager.add_event(copy2_ev) if out is None: if order == "K": out = _empty_like_triple_orderK( @@ -767,5 +784,6 @@ def clip(x, /, min=None, max=None, out=None, order="K"): sycl_queue=exec_q, depends=[copy1_ev, copy2_ev], ) - _manager.add_event_pair(ht_, clip_ev) + _manager.add_cleanup_event(ht_) + _manager.add_event(clip_ev) return out diff --git a/dpnp/tensor/_copy_utils.py b/dpnp/tensor/_copy_utils.py index e54147366abe..253cd6bea516 100644 --- a/dpnp/tensor/_copy_utils.py +++ b/dpnp/tensor/_copy_utils.py @@ -199,7 +199,8 @@ def _extract_impl(ary, ary_mask, axis=0): sycl_queue=exec_q, depends=dep_evs, ) - _manager.add_event_pair(hev, ev) + _manager.add_cleanup_event(hev) + _manager.add_event(ev) return dst @@ -266,7 +267,8 @@ def _nonzero_impl(ary): ) hev, nz_ev = ti._nonzero(cumsum, indexes, ary.shape, exec_q) res = tuple(indexes[i, :] for i in range(ary.ndim)) - _manager.add_event_pair(hev, nz_ev) + _manager.add_cleanup_event(hev) + _manager.add_event(nz_ev) return res @@ -412,7 +414,8 @@ def _place_impl(ary, ary_mask, vals, axis=0): sycl_queue=exec_q, depends=dep_ev, ) - _manager.add_event_pair(hev, pl_ev) + _manager.add_cleanup_event(hev) + _manager.add_event(pl_ev) return @@ -486,7 +489,8 @@ def _put_multi_index(ary, inds, p, vals, mode=0): sycl_queue=exec_q, depends=dep_ev, ) - _manager.add_event_pair(hev, put_ev) + _manager.add_cleanup_event(hev) + _manager.add_event(put_ev) return @@ -539,7 +543,8 @@ def _take_multi_index(ary, inds, p, mode=0): sycl_queue=exec_q, depends=dep_ev, ) - _manager.add_event_pair(hev, take_ev) + _manager.add_cleanup_event(hev) + _manager.add_event(take_ev) return res @@ -646,11 +651,13 @@ def _copy_overlapping(dst, src): hcp1, cp1 = ti._copy_usm_ndarray_into_usm_ndarray( src=src, dst=tmp, sycl_queue=q, depends=dep_evs ) - _manager.add_event_pair(hcp1, cp1) + _manager.add_cleanup_event(hcp1) + _manager.add_event(cp1) hcp2, cp2 = ti._copy_usm_ndarray_into_usm_ndarray( src=tmp, dst=dst, sycl_queue=q, depends=[cp1] ) - _manager.add_event_pair(hcp2, cp2) + _manager.add_cleanup_event(hcp2) + _manager.add_event(cp2) def _copy_same_shape(dst, src): @@ -671,7 +678,8 @@ def _copy_same_shape(dst, src): hev, cpy_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=src, dst=dst, sycl_queue=copy_q, depends=dep_evs ) - _manager.add_event_pair(hev, cpy_ev) + _manager.add_cleanup_event(hev) + _manager.add_event(cpy_ev) if hasattr(np, "broadcast_shapes"): diff --git a/dpnp/tensor/_ctors.py b/dpnp/tensor/_ctors.py index 1aeef2408986..75648eca8f7c 100644 --- a/dpnp/tensor/_ctors.py +++ b/dpnp/tensor/_ctors.py @@ -305,7 +305,8 @@ def _asarray_from_usm_ndarray( hev, cpy_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=usm_ndary, dst=res, sycl_queue=eq, depends=dep_evs ) - _manager.add_event_pair(hev, cpy_ev) + _manager.add_cleanup_event(hev) + _manager.add_event(cpy_ev) else: tmp = dpt.asnumpy(usm_ndary) res[...] = tmp @@ -398,7 +399,8 @@ def _device_copy_walker(seq_o, res, _manager): ht_ev, cpy_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=seq_o, dst=res, sycl_queue=exec_q, depends=deps ) - _manager.add_event_pair(ht_ev, cpy_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(cpy_ev) return if hasattr(seq_o, "__usm_ndarray__"): usm_arr = seq_o.__usm_ndarray__ @@ -412,7 +414,8 @@ def _device_copy_walker(seq_o, res, _manager): ht_ev, cpy_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=usm_ar, dst=res, sycl_queue=exec_q, depends=deps ) - _manager.add_event_pair(ht_ev, cpy_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(cpy_ev) return if isinstance(seq_o, (list, tuple)): for i, el in enumerate(seq_o): @@ -657,7 +660,8 @@ def arange( _manager = SequentialOrderManager[sycl_queue] # populating newly allocated array, no task dependencies hev, lin_ev = ti._linspace_step(_start, _step, res, sycl_queue) - _manager.add_event_pair(hev, lin_ev) + _manager.add_cleanup_event(hev) + _manager.add_event(lin_ev) if is_bool: res_out = dpt.usm_ndarray( (sh,), @@ -669,7 +673,8 @@ def arange( hev_cpy, cpy_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=res, dst=res_out, sycl_queue=sycl_queue, depends=[lin_ev] ) - _manager.add_event_pair(hev_cpy, cpy_ev) + _manager.add_cleanup_event(hev_cpy) + _manager.add_event(cpy_ev) return res_out return res @@ -1109,7 +1114,8 @@ def eye( if n_rows != 0 and n_cols != 0: _manager = SequentialOrderManager[sycl_queue] hev, eye_ev = ti._eye(k, dst=res, sycl_queue=sycl_queue) - _manager.add_event_pair(hev, eye_ev) + _manager.add_cleanup_event(hev) + _manager.add_event(eye_ev) return res @@ -1215,7 +1221,8 @@ def full( _manager = SequentialOrderManager[sycl_queue] # populating new allocation, no dependent events hev, full_ev = ti._full_usm_ndarray(fill_value, res, sycl_queue) - _manager.add_event_pair(hev, full_ev) + _manager.add_cleanup_event(hev) + _manager.add_event(full_ev) return res @@ -1311,7 +1318,8 @@ def full_like( hev, copy_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=X, dst=res, sycl_queue=sycl_queue, depends=dep_evs ) - _manager.add_event_pair(hev, copy_ev) + _manager.add_cleanup_event(hev) + _manager.add_event(copy_ev) return res else: _validate_fill_value(fill_value) @@ -1322,7 +1330,8 @@ def full_like( _manager = SequentialOrderManager[sycl_queue] # populating new allocation, no dependent events hev, full_ev = ti._full_usm_ndarray(fill_value, res, sycl_queue) - _manager.add_event_pair(hev, full_ev) + _manager.add_cleanup_event(hev) + _manager.add_event(full_ev) return res else: return full( @@ -1434,7 +1443,8 @@ def linspace( hev, la_ev = ti._linspace_affine( start, stop, dst=res, include_endpoint=endpoint, sycl_queue=sycl_queue ) - _manager.add_event_pair(hev, la_ev) + _manager.add_cleanup_event(hev) + _manager.add_event(la_ev) return res if int_dt is None else dpt.astype(res, int_dt) @@ -1578,7 +1588,8 @@ def ones( _manager = SequentialOrderManager[sycl_queue] # populating new allocation, no dependent events hev, full_ev = ti._full_usm_ndarray(1, res, sycl_queue) - _manager.add_event_pair(hev, full_ev) + _manager.add_cleanup_event(hev) + _manager.add_event(full_ev) return res @@ -1649,7 +1660,8 @@ def ones_like( _manager = SequentialOrderManager[sycl_queue] # populating new allocation, no dependent events hev, full_ev = ti._full_usm_ndarray(1, res, sycl_queue) - _manager.add_event_pair(hev, full_ev) + _manager.add_cleanup_event(hev) + _manager.add_event(full_ev) return res else: sh = x.shape @@ -1714,7 +1726,8 @@ def tril(x, /, *, k=0): hev, cpy_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=x, dst=res, sycl_queue=q, depends=dep_evs ) - _manager.add_event_pair(hev, cpy_ev) + _manager.add_cleanup_event(hev) + _manager.add_event(cpy_ev) elif k < -shape[nd - 2]: res = dpt.zeros( x.shape, @@ -1736,7 +1749,8 @@ def tril(x, /, *, k=0): hev, tril_ev = ti._tril( src=x, dst=res, k=k, sycl_queue=q, depends=dep_evs ) - _manager.add_event_pair(hev, tril_ev) + _manager.add_cleanup_event(hev) + _manager.add_event(tril_ev) return res @@ -1800,7 +1814,8 @@ def triu(x, /, *, k=0): hev, cpy_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=x, dst=res, sycl_queue=q, depends=dep_evs ) - _manager.add_event_pair(hev, cpy_ev) + _manager.add_cleanup_event(hev) + _manager.add_event(cpy_ev) else: res = dpt.empty( x.shape, @@ -1814,7 +1829,8 @@ def triu(x, /, *, k=0): hev, triu_ev = ti._triu( src=x, dst=res, k=k, sycl_queue=q, depends=dep_evs ) - _manager.add_event_pair(hev, triu_ev) + _manager.add_cleanup_event(hev) + _manager.add_event(triu_ev) return res @@ -1883,7 +1899,8 @@ def zeros( _manager = SequentialOrderManager[sycl_queue] # populating new allocation, no dependent events hev, zeros_ev = ti._zeros_usm_ndarray(res, sycl_queue) - _manager.add_event_pair(hev, zeros_ev) + _manager.add_cleanup_event(hev) + _manager.add_event(zeros_ev) return res @@ -1957,7 +1974,8 @@ def zeros_like( _manager = SequentialOrderManager[sycl_queue] # populating new allocation, no dependent events hev, full_ev = ti._full_usm_ndarray(0, res, sycl_queue) - _manager.add_event_pair(hev, full_ev) + _manager.add_cleanup_event(hev) + _manager.add_event(full_ev) return res else: _ensure_native_dtype_device_support(dtype, sycl_queue.sycl_device) diff --git a/dpnp/tensor/_elementwise_common.py b/dpnp/tensor/_elementwise_common.py index 093426903e86..6d288b45bc1d 100644 --- a/dpnp/tensor/_elementwise_common.py +++ b/dpnp/tensor/_elementwise_common.py @@ -261,14 +261,16 @@ def __call__(self, x, /, *, out=None, order="K"): ht_unary_ev, unary_ev = self.unary_fn_( x, out, sycl_queue=exec_q, depends=dep_evs ) - _manager.add_event_pair(ht_unary_ev, unary_ev) + _manager.add_cleanup_event(ht_unary_ev) + _manager.add_event(unary_ev) if not (orig_out is None or orig_out is out): # Copy the out data from temporary buffer to original memory ht_copy_ev, cpy_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=out, dst=orig_out, sycl_queue=exec_q, depends=[unary_ev] ) - _manager.add_event_pair(ht_copy_ev, cpy_ev) + _manager.add_cleanup_event(ht_copy_ev) + _manager.add_event(cpy_ev) out = orig_out return out @@ -284,7 +286,8 @@ def __call__(self, x, /, *, out=None, order="K"): ht_copy_ev, copy_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=x, dst=buf, sycl_queue=exec_q, depends=dep_evs ) - _manager.add_event_pair(ht_copy_ev, copy_ev) + _manager.add_cleanup_event(ht_copy_ev) + _manager.add_event(copy_ev) if out is None: if order == "K": out = _empty_like_orderK(buf, res_dt) @@ -294,7 +297,8 @@ def __call__(self, x, /, *, out=None, order="K"): ht, uf_ev = self.unary_fn_( buf, out, sycl_queue=exec_q, depends=[copy_ev] ) - _manager.add_event_pair(ht, uf_ev) + _manager.add_cleanup_event(ht) + _manager.add_event(uf_ev) return out @@ -624,7 +628,8 @@ def __call__(self, o1, o2, /, *, out=None, order="K"): sycl_queue=exec_q, depends=dep_evs, ) - _manager.add_event_pair(ht_, comp_ev) + _manager.add_cleanup_event(ht_) + _manager.add_event(comp_ev) else: buf2 = dpt.empty_like(src2, dtype=buf2_dt) dep_evs = _manager.submitted_events @@ -637,7 +642,8 @@ def __call__(self, o1, o2, /, *, out=None, order="K"): sycl_queue=exec_q, depends=dep_evs, ) - _manager.add_event_pair(ht_copy_ev, copy_ev) + _manager.add_cleanup_event(ht_copy_ev) + _manager.add_event(copy_ev) buf2 = dpt.broadcast_to(buf2, res_shape) ht_, bf_ev = self.binary_inplace_fn_( @@ -646,7 +652,8 @@ def __call__(self, o1, o2, /, *, out=None, order="K"): sycl_queue=exec_q, depends=[copy_ev], ) - _manager.add_event_pair(ht_, bf_ev) + _manager.add_cleanup_event(ht_) + _manager.add_event(bf_ev) return out @@ -710,7 +717,8 @@ def __call__(self, o1, o2, /, *, out=None, order="K"): sycl_queue=exec_q, depends=deps_ev, ) - _manager.add_event_pair(ht_binary_ev, binary_ev) + _manager.add_cleanup_event(ht_binary_ev) + _manager.add_event(binary_ev) if not (orig_out is None or orig_out is out): # Copy the out data from temporary buffer to original memory ht_copy_out_ev, cpy_ev = ti._copy_usm_ndarray_into_usm_ndarray( @@ -719,7 +727,8 @@ def __call__(self, o1, o2, /, *, out=None, order="K"): sycl_queue=exec_q, depends=[binary_ev], ) - _manager.add_event_pair(ht_copy_out_ev, cpy_ev) + _manager.add_cleanup_event(ht_copy_out_ev) + _manager.add_event(cpy_ev) out = orig_out return out elif buf1_dt is None: @@ -731,7 +740,8 @@ def __call__(self, o1, o2, /, *, out=None, order="K"): ht_copy_ev, copy_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=src2, dst=buf2, sycl_queue=exec_q, depends=dep_evs ) - _manager.add_event_pair(ht_copy_ev, copy_ev) + _manager.add_cleanup_event(ht_copy_ev) + _manager.add_event(copy_ev) if out is None: if order == "K": out = _empty_like_pair_orderK( @@ -756,7 +766,8 @@ def __call__(self, o1, o2, /, *, out=None, order="K"): sycl_queue=exec_q, depends=[copy_ev], ) - _manager.add_event_pair(ht_binary_ev, binary_ev) + _manager.add_cleanup_event(ht_binary_ev) + _manager.add_event(binary_ev) if not (orig_out is None or orig_out is out): # Copy the out data from temporary buffer to original memory ht_copy_out_ev, cpy_ev = ti._copy_usm_ndarray_into_usm_ndarray( @@ -765,7 +776,8 @@ def __call__(self, o1, o2, /, *, out=None, order="K"): sycl_queue=exec_q, depends=[binary_ev], ) - _manager.add_event_pair(ht_copy_out_ev, cpy_ev) + _manager.add_cleanup_event(ht_copy_out_ev) + _manager.add_event(cpy_ev) out = orig_out return out elif buf2_dt is None: @@ -777,7 +789,8 @@ def __call__(self, o1, o2, /, *, out=None, order="K"): ht_copy_ev, copy_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=src1, dst=buf1, sycl_queue=exec_q, depends=dep_evs ) - _manager.add_event_pair(ht_copy_ev, copy_ev) + _manager.add_cleanup_event(ht_copy_ev) + _manager.add_event(copy_ev) if out is None: if order == "K": out = _empty_like_pair_orderK( @@ -802,7 +815,8 @@ def __call__(self, o1, o2, /, *, out=None, order="K"): sycl_queue=exec_q, depends=[copy_ev], ) - _manager.add_event_pair(ht_binary_ev, binary_ev) + _manager.add_cleanup_event(ht_binary_ev) + _manager.add_event(binary_ev) if not (orig_out is None or orig_out is out): # Copy the out data from temporary buffer to original memory ht_copy_out_ev, cpy_ev = ti._copy_usm_ndarray_into_usm_ndarray( @@ -811,7 +825,8 @@ def __call__(self, o1, o2, /, *, out=None, order="K"): sycl_queue=exec_q, depends=[binary_ev], ) - _manager.add_event_pair(ht_copy_out_ev, cpy_ev) + _manager.add_cleanup_event(ht_copy_out_ev) + _manager.add_event(cpy_ev) out = orig_out return out @@ -828,7 +843,8 @@ def __call__(self, o1, o2, /, *, out=None, order="K"): ht_copy1_ev, copy1_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=src1, dst=buf1, sycl_queue=exec_q, depends=dep_evs ) - _manager.add_event_pair(ht_copy1_ev, copy1_ev) + _manager.add_cleanup_event(ht_copy1_ev) + _manager.add_event(copy1_ev) if order == "K": buf2 = _empty_like_orderK(src2, buf2_dt) else: @@ -836,7 +852,8 @@ def __call__(self, o1, o2, /, *, out=None, order="K"): ht_copy2_ev, copy2_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=src2, dst=buf2, sycl_queue=exec_q, depends=dep_evs ) - _manager.add_event_pair(ht_copy2_ev, copy2_ev) + _manager.add_cleanup_event(ht_copy2_ev) + _manager.add_event(copy2_ev) if out is None: if order == "K": out = _empty_like_pair_orderK( @@ -860,7 +877,8 @@ def __call__(self, o1, o2, /, *, out=None, order="K"): sycl_queue=exec_q, depends=[copy1_ev, copy2_ev], ) - _manager.add_event_pair(ht_, bf_ev) + _manager.add_cleanup_event(ht_) + _manager.add_event(bf_ev) return out def _inplace_op(self, o1, o2): @@ -974,7 +992,8 @@ def _inplace_op(self, o1, o2): sycl_queue=exec_q, depends=dep_evs, ) - _manager.add_event_pair(ht_, comp_ev) + _manager.add_cleanup_event(ht_) + _manager.add_event(comp_ev) else: buf = dpt.empty_like(src2, dtype=buf_dt) dep_evs = _manager.submitted_events @@ -987,7 +1006,8 @@ def _inplace_op(self, o1, o2): sycl_queue=exec_q, depends=dep_evs, ) - _manager.add_event_pair(ht_copy_ev, copy_ev) + _manager.add_cleanup_event(ht_copy_ev) + _manager.add_event(copy_ev) buf = dpt.broadcast_to(buf, res_shape) ht_, bf_ev = self.binary_inplace_fn_( @@ -996,6 +1016,7 @@ def _inplace_op(self, o1, o2): sycl_queue=exec_q, depends=[copy_ev], ) - _manager.add_event_pair(ht_, bf_ev) + _manager.add_cleanup_event(ht_) + _manager.add_event(bf_ev) return o1 diff --git a/dpnp/tensor/_indexing_functions.py b/dpnp/tensor/_indexing_functions.py index 54b88fe6d5f7..9945d75ac1eb 100644 --- a/dpnp/tensor/_indexing_functions.py +++ b/dpnp/tensor/_indexing_functions.py @@ -194,7 +194,8 @@ def place(arr, mask, vals): sycl_queue=exec_q, depends=_manager.submitted_events, ) - _manager.add_event_pair(hev, pl_ev) + _manager.add_cleanup_event(hev) + _manager.add_event(pl_ev) def put(x, indices, vals, /, *, axis=None, mode="wrap"): @@ -342,7 +343,8 @@ def put_vec_duplicates(vec, ind, vals): sycl_queue=exec_q, depends=deps_ev, ) - _manager.add_event_pair(hev, put_ev) + _manager.add_cleanup_event(hev) + _manager.add_event(put_ev) def put_along_axis(x, indices, vals, /, *, axis=-1, mode="wrap"): @@ -542,14 +544,16 @@ def take(x, indices, /, *, axis=None, out=None, mode="wrap"): sycl_queue=exec_q, depends=deps_ev, ) - _manager.add_event_pair(hev, take_ev) + _manager.add_cleanup_event(hev) + _manager.add_event(take_ev) if not (orig_out is None or out is orig_out): # Copy the out data from temporary buffer to original memory ht_e_cpy, cpy_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=out, dst=orig_out, sycl_queue=exec_q, depends=[take_ev] ) - _manager.add_event_pair(ht_e_cpy, cpy_ev) + _manager.add_cleanup_event(ht_e_cpy) + _manager.add_event(cpy_ev) out = orig_out return out diff --git a/dpnp/tensor/_linear_algebra_functions.py b/dpnp/tensor/_linear_algebra_functions.py index 84723d27f8eb..cfb8c36d5927 100644 --- a/dpnp/tensor/_linear_algebra_functions.py +++ b/dpnp/tensor/_linear_algebra_functions.py @@ -222,7 +222,8 @@ def tensordot(x1, x2, axes=2): sycl_queue=exec_q, depends=dep_evs, ) - _manager.add_event_pair(ht_dot_ev, dot_ev) + _manager.add_cleanup_event(ht_dot_ev) + _manager.add_event(dot_ev) return out @@ -233,7 +234,8 @@ def tensordot(x1, x2, axes=2): ht_copy_ev, copy_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=arr2, dst=buf2, sycl_queue=exec_q, depends=dep_evs ) - _manager.add_event_pair(ht_copy_ev, copy_ev) + _manager.add_cleanup_event(ht_copy_ev) + _manager.add_event(copy_ev) out = dpt.empty( res_shape, dtype=res_dt, @@ -252,7 +254,8 @@ def tensordot(x1, x2, axes=2): sycl_queue=exec_q, depends=[copy_ev], ) - _manager.add_event_pair(ht_dot_ev, dot_ev) + _manager.add_cleanup_event(ht_dot_ev) + _manager.add_event(dot_ev) return out @@ -262,7 +265,8 @@ def tensordot(x1, x2, axes=2): ht_copy_ev, copy_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=arr1, dst=buf1, sycl_queue=exec_q, depends=dep_evs ) - _manager.add_event_pair(ht_copy_ev, copy_ev) + _manager.add_cleanup_event(ht_copy_ev) + _manager.add_event(copy_ev) out = dpt.empty( res_shape, dtype=res_dt, @@ -281,7 +285,8 @@ def tensordot(x1, x2, axes=2): sycl_queue=exec_q, depends=[copy_ev], ) - _manager.add_event_pair(ht_dot_ev, dot_ev) + _manager.add_cleanup_event(ht_dot_ev) + _manager.add_event(dot_ev) return out @@ -290,12 +295,14 @@ def tensordot(x1, x2, axes=2): ht_copy1_ev, copy1_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=arr1, dst=buf1, sycl_queue=exec_q, depends=deps_ev ) - _manager.add_event_pair(ht_copy1_ev, copy1_ev) + _manager.add_cleanup_event(ht_copy1_ev) + _manager.add_event(copy1_ev) buf2 = _empty_like_orderK(arr2, buf2_dt) ht_copy2_ev, copy2_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=arr2, dst=buf2, sycl_queue=exec_q, depends=deps_ev ) - _manager.add_event_pair(ht_copy2_ev, copy2_ev) + _manager.add_cleanup_event(ht_copy2_ev) + _manager.add_event(copy2_ev) out = dpt.empty( res_shape, dtype=res_dt, @@ -314,7 +321,8 @@ def tensordot(x1, x2, axes=2): sycl_queue=exec_q, depends=[copy1_ev, copy2_ev], ) - _manager.add_event_pair(ht_, dot_ev) + _manager.add_cleanup_event(ht_) + _manager.add_event(dot_ev) return out @@ -428,7 +436,8 @@ def vecdot(x1, x2, axis=-1): ht_conj_ev, conj_ev = tei._conj( src=x1, dst=x1_tmp, sycl_queue=exec_q, depends=dep_evs ) - _manager.add_event_pair(ht_conj_ev, conj_ev) + _manager.add_cleanup_event(ht_conj_ev) + _manager.add_event(conj_ev) x1 = x1_tmp if x1.shape != broadcast_sh: x1 = dpt.broadcast_to(x1, broadcast_sh) @@ -455,7 +464,8 @@ def vecdot(x1, x2, axis=-1): sycl_queue=exec_q, depends=dep_evs, ) - _manager.add_event_pair(ht_dot_ev, dot_ev) + _manager.add_cleanup_event(ht_dot_ev) + _manager.add_event(dot_ev) return dpt.reshape(out, res_sh) elif buf1_dt is None: @@ -465,14 +475,16 @@ def vecdot(x1, x2, axis=-1): ht_conj_ev, conj_e = tei._conj( src=x1, dst=x1_tmp, sycl_queue=exec_q, depends=deps_ev ) - _manager.add_event_pair(ht_conj_ev, conj_e) + _manager.add_cleanup_event(ht_conj_ev) + _manager.add_event(conj_e) x1 = x1_tmp buf2 = _empty_like_orderK(x2, buf2_dt) deps_ev = _manager.submitted_events ht_copy_ev, copy_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=x2, dst=buf2, sycl_queue=exec_q, depends=deps_ev ) - _manager.add_event_pair(ht_copy_ev, copy_ev) + _manager.add_cleanup_event(ht_copy_ev) + _manager.add_event(copy_ev) if x1.shape != broadcast_sh: x1 = dpt.broadcast_to(x1, broadcast_sh) if buf2.shape != broadcast_sh: @@ -497,7 +509,8 @@ def vecdot(x1, x2, axis=-1): sycl_queue=exec_q, depends=[copy_ev], ) - _manager.add_event_pair(ht_dot_ev, dot_ev) + _manager.add_cleanup_event(ht_dot_ev) + _manager.add_event(dot_ev) return dpt.reshape(out, res_sh) elif buf2_dt is None: @@ -506,12 +519,14 @@ def vecdot(x1, x2, axis=-1): ht_copy_ev, copy_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=x1, dst=buf1, sycl_queue=exec_q, depends=deps_ev ) - _manager.add_event_pair(ht_copy_ev, copy_ev) + _manager.add_cleanup_event(ht_copy_ev) + _manager.add_event(copy_ev) if buf1.dtype.kind == "c": ht_conj_ev, conj_ev = tei._conj( src=buf1, dst=buf1, sycl_queue=exec_q, depends=[copy_ev] ) - _manager.add_event_pair(ht_conj_ev, conj_ev) + _manager.add_cleanup_event(ht_conj_ev) + _manager.add_event(conj_ev) if buf1.shape != broadcast_sh: buf1 = dpt.broadcast_to(buf1, broadcast_sh) if x2.shape != broadcast_sh: @@ -537,7 +552,8 @@ def vecdot(x1, x2, axis=-1): sycl_queue=exec_q, depends=deps_ev, ) - _manager.add_event_pair(ht_dot_ev, dot_ev) + _manager.add_cleanup_event(ht_dot_ev) + _manager.add_event(dot_ev) return dpt.reshape(out, res_sh) buf1 = _empty_like_orderK(x1, buf1_dt) @@ -545,17 +561,20 @@ def vecdot(x1, x2, axis=-1): ht_copy1_ev, copy1_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=x1, dst=buf1, sycl_queue=exec_q, depends=deps_ev ) - _manager.add_event_pair(ht_copy1_ev, copy1_ev) + _manager.add_cleanup_event(ht_copy1_ev) + _manager.add_event(copy1_ev) if buf1.dtype.kind == "c": ht_conj_ev, conj_ev = tei._conj( src=buf1, dst=buf1, sycl_queue=exec_q, depends=[copy1_ev] ) - _manager.add_event_pair(ht_conj_ev, conj_ev) + _manager.add_cleanup_event(ht_conj_ev) + _manager.add_event(conj_ev) buf2 = _empty_like_orderK(x2, buf2_dt) ht_copy2_ev, copy2_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=x2, dst=buf2, sycl_queue=exec_q, depends=deps_ev ) - _manager.add_event_pair(ht_copy2_ev, copy2_ev) + _manager.add_cleanup_event(ht_copy2_ev) + _manager.add_event(copy2_ev) if buf1.shape != broadcast_sh: buf1 = dpt.broadcast_to(buf1, broadcast_sh) if buf2.shape != broadcast_sh: @@ -581,7 +600,8 @@ def vecdot(x1, x2, axis=-1): sycl_queue=exec_q, depends=deps_ev, ) - _manager.add_event_pair(ht_dot_ev, dot_ev) + _manager.add_cleanup_event(ht_dot_ev) + _manager.add_event(dot_ev) return out @@ -836,7 +856,8 @@ def matmul(x1, x2, out=None, dtype=None, order="K"): sycl_queue=exec_q, depends=deps_evs, ) - _manager.add_event_pair(ht_dot_ev, dot_ev) + _manager.add_cleanup_event(ht_dot_ev) + _manager.add_event(dot_ev) if not (orig_out is None or orig_out is out): # Copy the out data from temporary buffer to original memory ht_copy_out_ev, cpy_ev = ti._copy_usm_ndarray_into_usm_ndarray( @@ -845,7 +866,8 @@ def matmul(x1, x2, out=None, dtype=None, order="K"): sycl_queue=exec_q, depends=[dot_ev], ) - _manager.add_event_pair(ht_copy_out_ev, cpy_ev) + _manager.add_cleanup_event(ht_copy_out_ev) + _manager.add_event(cpy_ev) out = orig_out if appended_axes: out = dpt.squeeze(out, tuple(appended_axes)) @@ -859,7 +881,8 @@ def matmul(x1, x2, out=None, dtype=None, order="K"): ht_copy_ev, copy_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=x2, dst=buf2, sycl_queue=exec_q, depends=deps_evs ) - _manager.add_event_pair(ht_copy_ev, copy_ev) + _manager.add_cleanup_event(ht_copy_ev) + _manager.add_event(copy_ev) if out is None: if order == "K": out = _empty_like_pair_orderK( @@ -889,7 +912,8 @@ def matmul(x1, x2, out=None, dtype=None, order="K"): sycl_queue=exec_q, depends=[copy_ev], ) - _manager.add_event_pair(ht_dot_ev, dot_ev) + _manager.add_cleanup_event(ht_dot_ev) + _manager.add_event(dot_ev) if not (orig_out is None or orig_out is out): # Copy the out data from temporary buffer to original memory ht_copy_out_ev, cpy_ev = ti._copy_usm_ndarray_into_usm_ndarray( @@ -898,7 +922,8 @@ def matmul(x1, x2, out=None, dtype=None, order="K"): sycl_queue=exec_q, depends=[dot_ev], ) - _manager.add_event_pair(ht_copy_out_ev, cpy_ev) + _manager.add_cleanup_event(ht_copy_out_ev) + _manager.add_event(cpy_ev) out = orig_out if appended_axes: out = dpt.squeeze(out, tuple(appended_axes)) @@ -913,7 +938,8 @@ def matmul(x1, x2, out=None, dtype=None, order="K"): ht_copy_ev, copy_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=x1, dst=buf1, sycl_queue=exec_q, depends=deps_ev ) - _manager.add_event_pair(ht_copy_ev, copy_ev) + _manager.add_cleanup_event(ht_copy_ev) + _manager.add_event(copy_ev) if out is None: if order == "K": out = _empty_like_pair_orderK( @@ -943,7 +969,8 @@ def matmul(x1, x2, out=None, dtype=None, order="K"): sycl_queue=exec_q, depends=[copy_ev], ) - _manager.add_event_pair(ht_dot_ev, dot_ev) + _manager.add_cleanup_event(ht_dot_ev) + _manager.add_event(dot_ev) if not (orig_out is None or orig_out is out): # Copy the out data from temporary buffer to original memory ht_copy_out_ev, cpy_ev = ti._copy_usm_ndarray_into_usm_ndarray( @@ -952,7 +979,8 @@ def matmul(x1, x2, out=None, dtype=None, order="K"): sycl_queue=exec_q, depends=[dot_ev], ) - _manager.add_event_pair(ht_copy_out_ev, cpy_ev) + _manager.add_cleanup_event(ht_copy_out_ev) + _manager.add_event(cpy_ev) out = orig_out if appended_axes: out = dpt.squeeze(out, tuple(appended_axes)) @@ -971,7 +999,8 @@ def matmul(x1, x2, out=None, dtype=None, order="K"): ht_copy1_ev, copy1_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=x1, dst=buf1, sycl_queue=exec_q, depends=deps_ev ) - _manager.add_event_pair(ht_copy1_ev, copy1_ev) + _manager.add_cleanup_event(ht_copy1_ev) + _manager.add_event(copy1_ev) if order == "K": buf2 = _empty_like_orderK(x2, buf2_dt) else: @@ -979,7 +1008,8 @@ def matmul(x1, x2, out=None, dtype=None, order="K"): ht_copy2_ev, copy2_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=x2, dst=buf2, sycl_queue=exec_q, depends=deps_ev ) - _manager.add_event_pair(ht_copy2_ev, copy2_ev) + _manager.add_cleanup_event(ht_copy2_ev) + _manager.add_event(copy2_ev) if out is None: if order == "K": out = _empty_like_pair_orderK( @@ -1009,7 +1039,8 @@ def matmul(x1, x2, out=None, dtype=None, order="K"): sycl_queue=exec_q, depends=[copy1_ev, copy2_ev], ) - _manager.add_event_pair(ht_, dot_ev) + _manager.add_cleanup_event(ht_) + _manager.add_event(dot_ev) if appended_axes: out = dpt.squeeze(out, tuple(appended_axes)) return out diff --git a/dpnp/tensor/_manipulation_functions.py b/dpnp/tensor/_manipulation_functions.py index 13ad4dfff9aa..36ab48aeacaa 100644 --- a/dpnp/tensor/_manipulation_functions.py +++ b/dpnp/tensor/_manipulation_functions.py @@ -186,7 +186,8 @@ def _concat_axis_None(arrays): sycl_queue=exec_q, depends=deps, ) - _manager.add_event_pair(hev, cpy_ev) + _manager.add_cleanup_event(hev) + _manager.add_event(cpy_ev) else: src_ = array # _copy_usm_ndarray_for_reshape requires src and dst to have @@ -196,14 +197,16 @@ def _concat_axis_None(arrays): ht_copy_ev, cpy_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=src_, dst=src2_, sycl_queue=exec_q, depends=deps ) - _manager.add_event_pair(ht_copy_ev, cpy_ev) + _manager.add_cleanup_event(ht_copy_ev) + _manager.add_event(cpy_ev) hev, reshape_copy_ev = ti._copy_usm_ndarray_for_reshape( src=src2_, dst=res[fill_start:fill_end], sycl_queue=exec_q, depends=[cpy_ev], ) - _manager.add_event_pair(hev, reshape_copy_ev) + _manager.add_cleanup_event(hev) + _manager.add_event(reshape_copy_ev) else: hev, cpy_ev = ti._copy_usm_ndarray_for_reshape( src=src_, @@ -211,7 +214,8 @@ def _concat_axis_None(arrays): sycl_queue=exec_q, depends=deps, ) - _manager.add_event_pair(hev, cpy_ev) + _manager.add_cleanup_event(hev) + _manager.add_event(cpy_ev) fill_start = fill_end return res @@ -375,7 +379,8 @@ def concat(arrays, /, *, axis=0): sycl_queue=exec_q, depends=deps, ) - _manager.add_event_pair(hev, cpy_ev) + _manager.add_cleanup_event(hev) + _manager.add_event(cpy_ev) fill_start = fill_end return res @@ -717,7 +722,8 @@ def repeat(x, repeats, /, *, axis=None): sycl_queue=exec_q, depends=dep_evs, ) - _manager.add_event_pair(ht_rep_ev, rep_ev) + _manager.add_cleanup_event(ht_rep_ev) + _manager.add_event(rep_ev) else: if repeats.dtype != dpt.int64: rep_buf = dpt.empty( @@ -729,7 +735,8 @@ def repeat(x, repeats, /, *, axis=None): ht_copy_ev, copy_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=repeats, dst=rep_buf, sycl_queue=exec_q, depends=dep_evs ) - _manager.add_event_pair(ht_copy_ev, copy_ev) + _manager.add_cleanup_event(ht_copy_ev) + _manager.add_event(copy_ev) cumsum = dpt.empty( (axis_size,), dtype=dpt.int64, @@ -761,7 +768,8 @@ def repeat(x, repeats, /, *, axis=None): axis=axis, sycl_queue=exec_q, ) - _manager.add_event_pair(ht_rep_ev, rep_ev) + _manager.add_cleanup_event(ht_rep_ev) + _manager.add_event(rep_ev) else: cumsum = dpt.empty( (axis_size,), @@ -793,7 +801,8 @@ def repeat(x, repeats, /, *, axis=None): axis=axis, sycl_queue=exec_q, ) - _manager.add_event_pair(ht_rep_ev, rep_ev) + _manager.add_cleanup_event(ht_rep_ev) + _manager.add_event(rep_ev) return res @@ -848,7 +857,8 @@ def roll(x, /, shift, *, axis=None): sycl_queue=exec_q, depends=dep_evs, ) - _manager.add_event_pair(hev, roll_ev) + _manager.add_cleanup_event(hev) + _manager.add_event(roll_ev) return res axis = normalize_axis_tuple(axis, x.ndim, allow_duplicate=True) broadcasted = np.broadcast(shift, axis) @@ -869,7 +879,8 @@ def roll(x, /, shift, *, axis=None): ht_e, roll_ev = ti._copy_usm_ndarray_for_roll_nd( src=x, dst=res, shifts=shifts, sycl_queue=exec_q, depends=dep_evs ) - _manager.add_event_pair(ht_e, roll_ev) + _manager.add_cleanup_event(ht_e) + _manager.add_event(roll_ev) return res @@ -974,7 +985,8 @@ def stack(arrays, /, *, axis=0): hev, cpy_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=arrays[i], dst=_dst, sycl_queue=exec_q, depends=dep_evs ) - _manager.add_event_pair(hev, cpy_ev) + _manager.add_cleanup_event(hev) + _manager.add_event(cpy_ev) return res @@ -1139,5 +1151,6 @@ def tile(x, repetitions, /): hev, cp_ev = ti._copy_usm_ndarray_for_reshape( src=x, dst=res, sycl_queue=exec_q, depends=dep_evs ) - _manager.add_event_pair(hev, cp_ev) + _manager.add_cleanup_event(hev) + _manager.add_event(cp_ev) return dpt.reshape(res, res_shape) diff --git a/dpnp/tensor/_reduction.py b/dpnp/tensor/_reduction.py index ad5064fa8fe5..e1c302875638 100644 --- a/dpnp/tensor/_reduction.py +++ b/dpnp/tensor/_reduction.py @@ -107,12 +107,14 @@ def _comparison_over_axis(x, axis, keepdims, out, _reduction_fn): ht_e_cpy, cpy_e = ti._copy_usm_ndarray_into_usm_ndarray( src=x_tmp, dst=out, sycl_queue=exec_q, depends=dep_evs ) - _manager.add_event_pair(ht_e_cpy, cpy_e) + _manager.add_cleanup_event(ht_e_cpy) + _manager.add_event(cpy_e) if not (orig_out is None or orig_out is out): ht_e_cpy2, cpy2_e = ti._copy_usm_ndarray_into_usm_ndarray( src=out, dst=orig_out, sycl_queue=exec_q, depends=[cpy_e] ) - _manager.add_event_pair(ht_e_cpy2, cpy2_e) + _manager.add_cleanup_event(ht_e_cpy2) + _manager.add_event(cpy2_e) out = orig_out return out @@ -123,12 +125,14 @@ def _comparison_over_axis(x, axis, keepdims, out, _reduction_fn): sycl_queue=exec_q, depends=dep_evs, ) - _manager.add_event_pair(hev, red_ev) + _manager.add_cleanup_event(hev) + _manager.add_event(red_ev) if not (orig_out is None or orig_out is out): ht_e_cpy2, cpy2_e = ti._copy_usm_ndarray_into_usm_ndarray( src=out, dst=orig_out, sycl_queue=exec_q, depends=[red_ev] ) - _manager.add_event_pair(ht_e_cpy2, cpy2_e) + _manager.add_cleanup_event(ht_e_cpy2) + _manager.add_event(cpy2_e) out = orig_out if keepdims: @@ -223,12 +227,14 @@ def _reduction_over_axis( ht_e_cpy, cpy_e = ti._copy_usm_ndarray_into_usm_ndarray( src=arr, dst=out, sycl_queue=q, depends=dep_evs ) - _manager.add_event_pair(ht_e_cpy, cpy_e) + _manager.add_cleanup_event(ht_e_cpy) + _manager.add_event(cpy_e) if not (orig_out is None or orig_out is out): ht_e_cpy2, cpy2_e = ti._copy_usm_ndarray_into_usm_ndarray( src=out, dst=orig_out, sycl_queue=q, depends=[cpy_e] ) - _manager.add_event_pair(ht_e_cpy2, cpy2_e) + _manager.add_cleanup_event(ht_e_cpy2) + _manager.add_event(cpy2_e) out = orig_out return out @@ -240,12 +246,14 @@ def _reduction_over_axis( sycl_queue=q, depends=dep_evs, ) - _manager.add_event_pair(ht_e, red_e) + _manager.add_cleanup_event(ht_e) + _manager.add_event(red_e) if not (orig_out is None or orig_out is out): ht_e_cpy, cpy_e = ti._copy_usm_ndarray_into_usm_ndarray( src=out, dst=orig_out, sycl_queue=q, depends=[red_e] ) - _manager.add_event_pair(ht_e_cpy, cpy_e) + _manager.add_cleanup_event(ht_e_cpy) + _manager.add_event(cpy_e) out = orig_out else: if _dtype_supported(res_dt, res_dt, res_usm_type, q): @@ -255,7 +263,8 @@ def _reduction_over_axis( ht_e_cpy, cpy_e = ti._copy_usm_ndarray_into_usm_ndarray( src=arr, dst=tmp, sycl_queue=q, depends=dep_evs ) - _manager.add_event_pair(ht_e_cpy, cpy_e) + _manager.add_cleanup_event(ht_e_cpy) + _manager.add_event(cpy_e) ht_e_red, red_ev = _reduction_fn( src=tmp, trailing_dims_to_reduce=red_nd, @@ -263,7 +272,8 @@ def _reduction_over_axis( sycl_queue=q, depends=[cpy_e], ) - _manager.add_event_pair(ht_e_red, red_ev) + _manager.add_cleanup_event(ht_e_red) + _manager.add_event(red_ev) else: buf_dt = _default_reduction_type_fn(inp_dt, q) tmp = dpt.empty( @@ -272,7 +282,8 @@ def _reduction_over_axis( ht_e_cpy, cpy_e = ti._copy_usm_ndarray_into_usm_ndarray( src=arr, dst=tmp, sycl_queue=q, depends=dep_evs ) - _manager.add_event_pair(ht_e_cpy, cpy_e) + _manager.add_cleanup_event(ht_e_cpy) + _manager.add_event(cpy_e) tmp_res = dpt.empty( res_shape, dtype=buf_dt, usm_type=res_usm_type, sycl_queue=q ) @@ -283,11 +294,13 @@ def _reduction_over_axis( sycl_queue=q, depends=[cpy_e], ) - _manager.add_event_pair(ht_e_red, r_e) + _manager.add_cleanup_event(ht_e_red) + _manager.add_event(r_e) ht_e_cpy2, cpy2_e = ti._copy_usm_ndarray_into_usm_ndarray( src=tmp_res, dst=out, sycl_queue=q, depends=[r_e] ) - _manager.add_event_pair(ht_e_cpy2, cpy2_e) + _manager.add_cleanup_event(ht_e_cpy2) + _manager.add_event(cpy2_e) if keepdims: res_shape = res_shape + (1,) * red_nd @@ -370,7 +383,8 @@ def _search_over_axis(x, axis, keepdims, out, _reduction_fn): ht_e_fill, fill_ev = ti._full_usm_ndarray( fill_value=0, dst=out, sycl_queue=exec_q, depends=dep_evs ) - _manager.add_event_pair(ht_e_fill, fill_ev) + _manager.add_cleanup_event(ht_e_fill) + _manager.add_event(fill_ev) return out hev, red_ev = _reduction_fn( @@ -380,12 +394,14 @@ def _search_over_axis(x, axis, keepdims, out, _reduction_fn): sycl_queue=exec_q, depends=dep_evs, ) - _manager.add_event_pair(hev, red_ev) + _manager.add_cleanup_event(hev) + _manager.add_event(red_ev) if not (orig_out is None or orig_out is out): ht_e_cpy2, cpy2_e = ti._copy_usm_ndarray_into_usm_ndarray( src=out, dst=orig_out, sycl_queue=exec_q, depends=[red_ev] ) - _manager.add_event_pair(ht_e_cpy2, cpy2_e) + _manager.add_cleanup_event(ht_e_cpy2) + _manager.add_event(cpy2_e) out = orig_out if keepdims: diff --git a/dpnp/tensor/_reshape.py b/dpnp/tensor/_reshape.py index 9885cce3721a..cbbbe557254c 100644 --- a/dpnp/tensor/_reshape.py +++ b/dpnp/tensor/_reshape.py @@ -189,7 +189,8 @@ def reshape(X, /, shape, *, order="C", copy=None): hev, r_e = _copy_usm_ndarray_for_reshape( src=X_t, dst=flat_res, sycl_queue=copy_q, depends=dep_evs ) - _manager.add_event_pair(hev, r_e) + _manager.add_cleanup_event(hev) + _manager.add_event(r_e) return dpt.usm_ndarray( tuple(shape), dtype=X.dtype, buffer=flat_res, order=order ) diff --git a/dpnp/tensor/_search_functions.py b/dpnp/tensor/_search_functions.py index 60c81ed59803..f212141ed2ef 100644 --- a/dpnp/tensor/_search_functions.py +++ b/dpnp/tensor/_search_functions.py @@ -357,7 +357,8 @@ def where(condition, x1, x2, /, *, order="K", out=None): src=x1, dst=_x1, sycl_queue=exec_q, depends=dep_evs ) x1 = _x1 - _manager.add_event_pair(ht_copy1_ev, copy1_ev) + _manager.add_cleanup_event(ht_copy1_ev) + _manager.add_event(copy1_ev) if x2_dtype != out_dtype: if order == "K": @@ -368,7 +369,8 @@ def where(condition, x1, x2, /, *, order="K", out=None): src=x2, dst=_x2, sycl_queue=exec_q, depends=dep_evs ) x2 = _x2 - _manager.add_event_pair(ht_copy2_ev, copy2_ev) + _manager.add_cleanup_event(ht_copy2_ev) + _manager.add_event(copy2_ev) if out is None: if order == "K": @@ -400,7 +402,8 @@ def where(condition, x1, x2, /, *, order="K", out=None): sycl_queue=exec_q, depends=dep_evs, ) - _manager.add_event_pair(hev, where_ev) + _manager.add_cleanup_event(hev) + _manager.add_event(where_ev) if not (orig_out is None or orig_out is out): # Copy the out data from temporary buffer to original memory ht_copy_out_ev, cpy_ev = ti._copy_usm_ndarray_into_usm_ndarray( @@ -409,7 +412,8 @@ def where(condition, x1, x2, /, *, order="K", out=None): sycl_queue=exec_q, depends=[where_ev], ) - _manager.add_event_pair(ht_copy_out_ev, cpy_ev) + _manager.add_cleanup_event(ht_copy_out_ev) + _manager.add_event(cpy_ev) out = orig_out return out diff --git a/dpnp/tensor/_searchsorted.py b/dpnp/tensor/_searchsorted.py index 39491b02f1e8..131f2f736a08 100644 --- a/dpnp/tensor/_searchsorted.py +++ b/dpnp/tensor/_searchsorted.py @@ -172,7 +172,8 @@ def searchsorted( ) x1 = res x1_deps = [ev] - _manager.add_event_pair(ht_ev, ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(ev) dt1, dt2 = _resolve_weak_types_all_py_ints(x1_dt, x2_dt, sycl_dev) dt = _to_device_supported_dtype(dpt.result_type(dt1, dt2), sycl_dev) @@ -181,7 +182,8 @@ def searchsorted( x1_buf = _empty_like_orderK(x1, dt) # get the submitted events again to ensure the copy waits take call ht_ev, ev = ti_copy(src=x1, dst=x1_buf, sycl_queue=q, depends=x1_deps) - _manager.add_event_pair(ht_ev, ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(ev) x1 = x1_buf if not isinstance(x2, usm_ndarray): @@ -189,7 +191,8 @@ def searchsorted( elif x2_dt != dt: x2_buf = _empty_like_orderK(x2, dt) ht_ev, ev = ti_copy(src=x2, dst=x2_buf, sycl_queue=q, depends=dep_evs) - _manager.add_event_pair(ht_ev, ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(ev) x2 = x2_buf index_dt = ti_default_device_index_type(q) @@ -209,5 +212,6 @@ def searchsorted( ht_ev, s_ev = _searchsorted_right( hay=x1, needles=x2, positions=dst, sycl_queue=q, depends=dep_evs ) - _manager.add_event_pair(ht_ev, s_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(s_ev) return dst diff --git a/dpnp/tensor/_set_functions.py b/dpnp/tensor/_set_functions.py index 0c51b25fc999..d28b94aa4d4d 100644 --- a/dpnp/tensor/_set_functions.py +++ b/dpnp/tensor/_set_functions.py @@ -123,13 +123,15 @@ def unique_values(x: dpt.usm_ndarray) -> dpt.usm_ndarray: sycl_queue=exec_q, depends=dep_evs, ) - _manager.add_event_pair(ht_ev, sort_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(sort_ev) else: tmp = dpt.empty_like(fx, order="C") ht_ev, copy_ev = _copy_usm_ndarray_into_usm_ndarray( src=fx, dst=tmp, sycl_queue=exec_q, depends=dep_evs ) - _manager.add_event_pair(ht_ev, copy_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(copy_ev) ht_ev, sort_ev = _sort_ascending( src=tmp, trailing_dims_to_sort=1, @@ -137,7 +139,8 @@ def unique_values(x: dpt.usm_ndarray) -> dpt.usm_ndarray: sycl_queue=exec_q, depends=[copy_ev], ) - _manager.add_event_pair(ht_ev, sort_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(sort_ev) unique_mask = dpt.empty(fx.shape, dtype="?", sycl_queue=exec_q) ht_ev, uneq_ev = _not_equal( src1=s[:-1], @@ -146,12 +149,14 @@ def unique_values(x: dpt.usm_ndarray) -> dpt.usm_ndarray: sycl_queue=exec_q, depends=[sort_ev], ) - _manager.add_event_pair(ht_ev, uneq_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(uneq_ev) # writing into new allocation, no dependencies ht_ev, one_ev = _full_usm_ndarray( fill_value=True, dst=unique_mask[0], sycl_queue=exec_q ) - _manager.add_event_pair(ht_ev, one_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(one_ev) cumsum = dpt.empty(s.shape, dtype=dpt.int64, sycl_queue=exec_q) # synchronizing call n_uniques = mask_positions( @@ -170,7 +175,8 @@ def unique_values(x: dpt.usm_ndarray) -> dpt.usm_ndarray: dst=unique_vals, sycl_queue=exec_q, ) - _manager.add_event_pair(ht_ev, ex_e) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(ex_e) return unique_vals @@ -219,13 +225,15 @@ def unique_counts(x: dpt.usm_ndarray) -> UniqueCountsResult: sycl_queue=exec_q, depends=dep_evs, ) - _manager.add_event_pair(ht_ev, sort_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(sort_ev) else: tmp = dpt.empty_like(fx, order="C") ht_ev, copy_ev = _copy_usm_ndarray_into_usm_ndarray( src=fx, dst=tmp, sycl_queue=exec_q, depends=dep_evs ) - _manager.add_event_pair(ht_ev, copy_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(copy_ev) ht_ev, sort_ev = _sort_ascending( src=tmp, dst=s, @@ -233,7 +241,8 @@ def unique_counts(x: dpt.usm_ndarray) -> UniqueCountsResult: sycl_queue=exec_q, depends=[copy_ev], ) - _manager.add_event_pair(ht_ev, sort_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(sort_ev) unique_mask = dpt.empty(s.shape, dtype="?", sycl_queue=exec_q) ht_ev, uneq_ev = _not_equal( src1=s[:-1], @@ -242,12 +251,14 @@ def unique_counts(x: dpt.usm_ndarray) -> UniqueCountsResult: sycl_queue=exec_q, depends=[sort_ev], ) - _manager.add_event_pair(ht_ev, uneq_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(uneq_ev) # no dependency, since we write into new allocation ht_ev, one_ev = _full_usm_ndarray( fill_value=True, dst=unique_mask[0], sycl_queue=exec_q ) - _manager.add_event_pair(ht_ev, one_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(one_ev) cumsum = dpt.empty(unique_mask.shape, dtype=dpt.int64, sycl_queue=exec_q) # synchronizing call n_uniques = mask_positions( @@ -272,14 +283,16 @@ def unique_counts(x: dpt.usm_ndarray) -> UniqueCountsResult: dst=unique_vals, sycl_queue=exec_q, ) - _manager.add_event_pair(ht_ev, ex_e) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(ex_e) unique_counts = dpt.empty( n_uniques + 1, dtype=ind_dt, usm_type=x_usm_type, sycl_queue=exec_q ) idx = dpt.empty(x.size, dtype=ind_dt, sycl_queue=exec_q) # writing into new allocation, no dependency ht_ev, id_ev = _linspace_step(start=0, dt=1, dst=idx, sycl_queue=exec_q) - _manager.add_event_pair(ht_ev, id_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(id_ev) ht_ev, extr_ev = _extract( src=idx, cumsum=cumsum, @@ -289,12 +302,14 @@ def unique_counts(x: dpt.usm_ndarray) -> UniqueCountsResult: sycl_queue=exec_q, depends=[id_ev], ) - _manager.add_event_pair(ht_ev, extr_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(extr_ev) # no dependency, writing into disjoint segmenent of new allocation ht_ev, set_ev = _full_usm_ndarray( x.size, dst=unique_counts[-1], sycl_queue=exec_q ) - _manager.add_event_pair(ht_ev, set_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(set_ev) _counts = dpt.empty_like(unique_counts[1:]) ht_ev, sub_ev = _subtract( src1=unique_counts[1:], @@ -303,7 +318,8 @@ def unique_counts(x: dpt.usm_ndarray) -> UniqueCountsResult: sycl_queue=exec_q, depends=[set_ev, extr_ev], ) - _manager.add_event_pair(ht_ev, sub_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(sub_ev) return UniqueCountsResult(unique_vals, _counts) @@ -353,13 +369,15 @@ def unique_inverse(x): sycl_queue=exec_q, depends=dep_evs, ) - _manager.add_event_pair(ht_ev, sort_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(sort_ev) else: tmp = dpt.empty_like(fx, order="C") ht_ev, copy_ev = _copy_usm_ndarray_into_usm_ndarray( src=fx, dst=tmp, sycl_queue=exec_q, depends=dep_evs ) - _manager.add_event_pair(ht_ev, copy_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(copy_ev) ht_ev, sort_ev = _argsort_ascending( src=tmp, trailing_dims_to_sort=1, @@ -367,7 +385,8 @@ def unique_inverse(x): sycl_queue=exec_q, depends=[copy_ev], ) - _manager.add_event_pair(ht_ev, sort_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(sort_ev) ht_ev, argsort_ev = _argsort_ascending( src=sorting_ids, trailing_dims_to_sort=1, @@ -375,7 +394,8 @@ def unique_inverse(x): sycl_queue=exec_q, depends=[sort_ev], ) - _manager.add_event_pair(ht_ev, argsort_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(argsort_ev) s = dpt.empty_like(fx) # s = fx[sorting_ids] ht_ev, take_ev = _take( @@ -388,7 +408,8 @@ def unique_inverse(x): sycl_queue=exec_q, depends=[sort_ev], ) - _manager.add_event_pair(ht_ev, take_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(take_ev) unique_mask = dpt.empty(fx.shape, dtype="?", sycl_queue=exec_q) ht_ev, uneq_ev = _not_equal( src1=s[:-1], @@ -397,12 +418,14 @@ def unique_inverse(x): sycl_queue=exec_q, depends=[take_ev], ) - _manager.add_event_pair(ht_ev, uneq_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(uneq_ev) # no dependency ht_ev, one_ev = _full_usm_ndarray( fill_value=True, dst=unique_mask[0], sycl_queue=exec_q ) - _manager.add_event_pair(ht_ev, one_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(one_ev) cumsum = dpt.empty(unique_mask.shape, dtype=dpt.int64, sycl_queue=exec_q) # synchronizing call n_uniques = mask_positions( @@ -421,13 +444,15 @@ def unique_inverse(x): dst=unique_vals, sycl_queue=exec_q, ) - _manager.add_event_pair(ht_ev, uv_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(uv_ev) cum_unique_counts = dpt.empty( n_uniques + 1, dtype=ind_dt, usm_type=x_usm_type, sycl_queue=exec_q ) idx = dpt.empty(x.size, dtype=ind_dt, sycl_queue=exec_q) ht_ev, id_ev = _linspace_step(start=0, dt=1, dst=idx, sycl_queue=exec_q) - _manager.add_event_pair(ht_ev, id_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(id_ev) ht_ev, extr_ev = _extract( src=idx, cumsum=cumsum, @@ -437,11 +462,13 @@ def unique_inverse(x): sycl_queue=exec_q, depends=[id_ev], ) - _manager.add_event_pair(ht_ev, extr_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(extr_ev) ht_ev, set_ev = _full_usm_ndarray( x.size, dst=cum_unique_counts[-1], sycl_queue=exec_q ) - _manager.add_event_pair(ht_ev, set_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(set_ev) _counts = dpt.empty_like(cum_unique_counts[1:]) ht_ev, sub_ev = _subtract( src1=cum_unique_counts[1:], @@ -450,7 +477,8 @@ def unique_inverse(x): sycl_queue=exec_q, depends=[set_ev, extr_ev], ) - _manager.add_event_pair(ht_ev, sub_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(sub_ev) inv = dpt.empty_like(x, dtype=ind_dt, order="C") ht_ev, ssl_ev = _searchsorted_left( @@ -462,7 +490,8 @@ def unique_inverse(x): uv_ev, ], ) - _manager.add_event_pair(ht_ev, ssl_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(ssl_ev) return UniqueInverseResult(unique_vals, inv) @@ -529,13 +558,15 @@ def unique_all(x: dpt.usm_ndarray) -> UniqueAllResult: sycl_queue=exec_q, depends=dep_evs, ) - _manager.add_event_pair(ht_ev, sort_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(sort_ev) else: tmp = dpt.empty_like(fx, order="C") ht_ev, copy_ev = _copy_usm_ndarray_into_usm_ndarray( src=fx, dst=tmp, sycl_queue=exec_q, depends=dep_evs ) - _manager.add_event_pair(ht_ev, copy_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(copy_ev) ht_ev, sort_ev = _argsort_ascending( src=tmp, trailing_dims_to_sort=1, @@ -543,7 +574,8 @@ def unique_all(x: dpt.usm_ndarray) -> UniqueAllResult: sycl_queue=exec_q, depends=[copy_ev], ) - _manager.add_event_pair(ht_ev, sort_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(sort_ev) ht_ev, args_ev = _argsort_ascending( src=sorting_ids, trailing_dims_to_sort=1, @@ -551,7 +583,8 @@ def unique_all(x: dpt.usm_ndarray) -> UniqueAllResult: sycl_queue=exec_q, depends=[sort_ev], ) - _manager.add_event_pair(ht_ev, args_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(args_ev) s = dpt.empty_like(fx) # s = fx[sorting_ids] ht_ev, take_ev = _take( @@ -564,7 +597,8 @@ def unique_all(x: dpt.usm_ndarray) -> UniqueAllResult: sycl_queue=exec_q, depends=[sort_ev], ) - _manager.add_event_pair(ht_ev, take_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(take_ev) unique_mask = dpt.empty(fx.shape, dtype="?", sycl_queue=exec_q) ht_ev, uneq_ev = _not_equal( src1=s[:-1], @@ -573,11 +607,13 @@ def unique_all(x: dpt.usm_ndarray) -> UniqueAllResult: sycl_queue=exec_q, depends=[take_ev], ) - _manager.add_event_pair(ht_ev, uneq_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(uneq_ev) ht_ev, one_ev = _full_usm_ndarray( fill_value=True, dst=unique_mask[0], sycl_queue=exec_q ) - _manager.add_event_pair(ht_ev, one_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(one_ev) cumsum = dpt.empty(unique_mask.shape, dtype=dpt.int64, sycl_queue=exec_q) # synchronizing call n_uniques = mask_positions( @@ -604,13 +640,15 @@ def unique_all(x: dpt.usm_ndarray) -> UniqueAllResult: dst=unique_vals, sycl_queue=exec_q, ) - _manager.add_event_pair(ht_ev, uv_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(uv_ev) cum_unique_counts = dpt.empty( n_uniques + 1, dtype=ind_dt, usm_type=x_usm_type, sycl_queue=exec_q ) idx = dpt.empty(x.size, dtype=ind_dt, sycl_queue=exec_q) ht_ev, id_ev = _linspace_step(start=0, dt=1, dst=idx, sycl_queue=exec_q) - _manager.add_event_pair(ht_ev, id_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(id_ev) ht_ev, extr_ev = _extract( src=idx, cumsum=cumsum, @@ -620,11 +658,13 @@ def unique_all(x: dpt.usm_ndarray) -> UniqueAllResult: sycl_queue=exec_q, depends=[id_ev], ) - _manager.add_event_pair(ht_ev, extr_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(extr_ev) ht_ev, set_ev = _full_usm_ndarray( x.size, dst=cum_unique_counts[-1], sycl_queue=exec_q ) - _manager.add_event_pair(ht_ev, set_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(set_ev) _counts = dpt.empty_like(cum_unique_counts[1:]) ht_ev, sub_ev = _subtract( src1=cum_unique_counts[1:], @@ -633,7 +673,8 @@ def unique_all(x: dpt.usm_ndarray) -> UniqueAllResult: sycl_queue=exec_q, depends=[set_ev, extr_ev], ) - _manager.add_event_pair(ht_ev, sub_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(sub_ev) inv = dpt.empty_like(x, dtype=ind_dt, order="C") ht_ev, ssl_ev = _searchsorted_left( @@ -645,7 +686,8 @@ def unique_all(x: dpt.usm_ndarray) -> UniqueAllResult: uv_ev, ], ) - _manager.add_event_pair(ht_ev, ssl_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(ssl_ev) return UniqueAllResult( unique_vals, sorting_ids[cum_unique_counts[:-1]], @@ -760,7 +802,8 @@ def isin( ht_ev, ev = _copy_usm_ndarray_into_usm_ndarray( src=x_arr, dst=x_buf, sycl_queue=exec_q, depends=dep_evs ) - _manager.add_event_pair(ht_ev, ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(ev) else: x_buf = x_arr @@ -772,7 +815,8 @@ def isin( ht_ev, ev = _copy_usm_ndarray_into_usm_ndarray( src=test_arr, dst=test_buf, sycl_queue=exec_q, depends=dep_evs ) - _manager.add_event_pair(ht_ev, ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(ev) else: test_buf = test_arr @@ -792,5 +836,6 @@ def isin( invert=invert, depends=dep_evs, ) - _manager.add_event_pair(ht_ev, s_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(s_ev) return dst diff --git a/dpnp/tensor/_sorting.py b/dpnp/tensor/_sorting.py index 95f25183c42e..fbceca7dcace 100644 --- a/dpnp/tensor/_sorting.py +++ b/dpnp/tensor/_sorting.py @@ -144,13 +144,15 @@ def sort(x, /, *, axis=-1, descending=False, stable=True, kind=None): sycl_queue=exec_q, depends=dep_evs, ) - _manager.add_event_pair(ht_ev, impl_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(impl_ev) else: tmp = dpt.empty_like(arr, order="C") ht_ev, copy_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=arr, dst=tmp, sycl_queue=exec_q, depends=dep_evs ) - _manager.add_event_pair(ht_ev, copy_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(copy_ev) res = dpt.empty_like(arr, order="C") ht_ev, impl_ev = impl_fn( src=tmp, @@ -159,7 +161,8 @@ def sort(x, /, *, axis=-1, descending=False, stable=True, kind=None): sycl_queue=exec_q, depends=[copy_ev], ) - _manager.add_event_pair(ht_ev, impl_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(impl_ev) if a1 != nd: inv_perm = sorted(range(nd), key=lambda d: perm[d]) res = dpt.permute_dims(res, inv_perm) @@ -263,13 +266,15 @@ def argsort(x, axis=-1, descending=False, stable=True, kind=None): sycl_queue=exec_q, depends=dep_evs, ) - _manager.add_event_pair(ht_ev, impl_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(impl_ev) else: tmp = dpt.empty_like(arr, order="C") ht_ev, copy_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=arr, dst=tmp, sycl_queue=exec_q, depends=dep_evs ) - _manager.add_event_pair(ht_ev, copy_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(copy_ev) res = dpt.empty_like(arr, dtype=index_dt, order="C") ht_ev, impl_ev = impl_fn( src=tmp, @@ -278,7 +283,8 @@ def argsort(x, axis=-1, descending=False, stable=True, kind=None): sycl_queue=exec_q, depends=[copy_ev], ) - _manager.add_event_pair(ht_ev, impl_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(impl_ev) if a1 != nd: inv_perm = sorted(range(nd), key=lambda d: perm[d]) res = dpt.permute_dims(res, inv_perm) @@ -438,13 +444,15 @@ def top_k(x, k, /, *, axis=_NO_AXIS, mode="largest"): sycl_queue=exec_q, depends=dep_evs, ) - _manager.add_event_pair(ht_ev, impl_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(impl_ev) else: tmp = dpt.empty_like(arr, order="C") ht_ev, copy_ev = ti._copy_usm_ndarray_into_usm_ndarray( src=arr, dst=tmp, sycl_queue=exec_q, depends=dep_evs ) - _manager.add_event_pair(ht_ev, copy_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(copy_ev) vals = dpt.empty( res_sh, dtype=arr.dtype, @@ -469,7 +477,8 @@ def top_k(x, k, /, *, axis=_NO_AXIS, mode="largest"): sycl_queue=exec_q, depends=[copy_ev], ) - _manager.add_event_pair(ht_ev, impl_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(impl_ev) if axis is not None and a1 != nd: inv_perm = sorted(range(nd), key=lambda d: perm[d]) vals = dpt.permute_dims(vals, inv_perm) diff --git a/dpnp/tensor/_statistical_functions.py b/dpnp/tensor/_statistical_functions.py index 078eab6be8bb..d29f7eade705 100644 --- a/dpnp/tensor/_statistical_functions.py +++ b/dpnp/tensor/_statistical_functions.py @@ -67,7 +67,8 @@ def _var_impl(x, axis, correction, keepdims): ht_e_buf, c_e1 = ti._copy_usm_ndarray_into_usm_ndarray( src=x, dst=buf, sycl_queue=q, depends=dep_evs ) - _manager.add_event_pair(ht_e_buf, c_e1) + _manager.add_cleanup_event(ht_e_buf) + _manager.add_event(c_e1) else: buf = x # calculate mean @@ -80,7 +81,8 @@ def _var_impl(x, axis, correction, keepdims): ht_e1, c_e2 = ti._copy_usm_ndarray_into_usm_ndarray( src=buf, dst=mean_ary, sycl_queue=q, depends=dep_evs ) - _manager.add_event_pair(ht_e1, c_e2) + _manager.add_cleanup_event(ht_e1) + _manager.add_event(c_e2) else: mean_ary = dpt.empty( res_shape, @@ -96,7 +98,8 @@ def _var_impl(x, axis, correction, keepdims): sycl_queue=q, depends=dep_evs, ) - _manager.add_event_pair(ht_e1, r_e1) + _manager.add_cleanup_event(ht_e1) + _manager.add_event(r_e1) mean_ary_shape = res_shape + (1,) * red_nd inv_perm = sorted(range(nd), key=lambda d: perm[d]) @@ -110,7 +113,8 @@ def _var_impl(x, axis, correction, keepdims): ht_e2, d_e1 = tei._divide_by_scalar( src=mean_ary, scalar=nelems, dst=mean_ary, sycl_queue=q, depends=dep_evs ) - _manager.add_event_pair(ht_e2, d_e1) + _manager.add_cleanup_event(ht_e2) + _manager.add_event(d_e1) # subtract mean from original array to get deviations dev_ary = dpt.empty_like(buf) @@ -119,12 +123,14 @@ def _var_impl(x, axis, correction, keepdims): ht_e4, su_e = tei._subtract( src1=buf, src2=mean_ary, dst=dev_ary, sycl_queue=q, depends=[d_e1] ) - _manager.add_event_pair(ht_e4, su_e) + _manager.add_cleanup_event(ht_e4) + _manager.add_event(su_e) # square deviations ht_e5, sq_e = tei._square( src=dev_ary, dst=dev_ary, sycl_queue=q, depends=[su_e] ) - _manager.add_event_pair(ht_e5, sq_e) + _manager.add_cleanup_event(ht_e5) + _manager.add_event(sq_e) # take sum of squared deviations dev_ary2 = dpt.permute_dims(dev_ary, perm) @@ -144,7 +150,8 @@ def _var_impl(x, axis, correction, keepdims): sycl_queue=q, depends=[sq_e], ) - _manager.add_event_pair(ht_e6, r_e2) + _manager.add_cleanup_event(ht_e6) + _manager.add_event(r_e2) if keepdims: res_shape = res_shape + (1,) * red_nd @@ -159,7 +166,8 @@ def _var_impl(x, axis, correction, keepdims): ht_e7, d_e2 = tei._divide_by_scalar( src=res, scalar=div, dst=res, sycl_queue=q, depends=dep_evs ) - _manager.add_event_pair(ht_e7, d_e2) + _manager.add_cleanup_event(ht_e7) + _manager.add_event(d_e2) return res, [d_e2] @@ -236,7 +244,8 @@ def mean(x, axis=None, keepdims=False): sycl_queue=q, depends=dep_evs, ) - _manager.add_event_pair(ht_e1, r_e) + _manager.add_cleanup_event(ht_e1) + _manager.add_event(r_e) else: tmp = dpt.empty( arr2.shape, dtype=res_dt, usm_type=res_usm_type, sycl_queue=q @@ -244,7 +253,8 @@ def mean(x, axis=None, keepdims=False): ht_e_cpy, cpy_e = ti._copy_usm_ndarray_into_usm_ndarray( src=arr2, dst=tmp, sycl_queue=q, depends=dep_evs ) - _manager.add_event_pair(ht_e_cpy, cpy_e) + _manager.add_cleanup_event(ht_e_cpy) + _manager.add_event(cpy_e) res = dpt.empty( res_shape, dtype=res_dt, usm_type=res_usm_type, sycl_queue=q ) @@ -255,7 +265,8 @@ def mean(x, axis=None, keepdims=False): sycl_queue=q, depends=[cpy_e], ) - _manager.add_event_pair(ht_e_red, r_e) + _manager.add_cleanup_event(ht_e_red) + _manager.add_event(r_e) if keepdims: res_shape = res_shape + (1,) * sum_nd @@ -266,7 +277,8 @@ def mean(x, axis=None, keepdims=False): ht_e2, div_e = tei._divide_by_scalar( src=res, scalar=nelems, dst=res, sycl_queue=q, depends=dep_evs ) - _manager.add_event_pair(ht_e2, div_e) + _manager.add_cleanup_event(ht_e2) + _manager.add_event(div_e) return res @@ -375,5 +387,6 @@ def std(x, axis=None, correction=0.0, keepdims=False): ht_ev, sqrt_ev = tei._sqrt( src=res, dst=res, sycl_queue=exec_q, depends=deps ) - _manager.add_event_pair(ht_ev, sqrt_ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(sqrt_ev) return res diff --git a/dpnp/tensor/_utility_functions.py b/dpnp/tensor/_utility_functions.py index 0dc2e33d6707..79e622166a45 100644 --- a/dpnp/tensor/_utility_functions.py +++ b/dpnp/tensor/_utility_functions.py @@ -105,7 +105,8 @@ def _boolean_reduction(x, axis, keepdims, func, identity): sycl_queue=exec_q, depends=dep_evs, ) - _manager.add_event_pair(hev0, ev0) + _manager.add_cleanup_event(hev0) + _manager.add_event(ev0) # copy to boolean result array res = dpt.empty( @@ -117,7 +118,8 @@ def _boolean_reduction(x, axis, keepdims, func, identity): hev1, ev1 = ti._copy_usm_ndarray_into_usm_ndarray( src=res_tmp, dst=res, sycl_queue=exec_q, depends=[ev0] ) - _manager.add_event_pair(hev1, ev1) + _manager.add_cleanup_event(hev1) + _manager.add_event(ev1) if keepdims: res_shape = res_shape + (1,) * red_nd diff --git a/dpnp/tests/test_random_generator.py b/dpnp/tests/test_random_generator.py index 4ee24faf8b37..41b1fa466043 100644 --- a/dpnp/tests/test_random_generator.py +++ b/dpnp/tests/test_random_generator.py @@ -323,7 +323,8 @@ def test_param_overlaps_result(self): ht_ev, ev = ri._normal( q, engine, [1], 0, 0, [x, 1.0], x, depends=_manager.submitted_events ) - _manager.add_event_pair(ht_ev, ev) + _manager.add_cleanup_event(ht_ev) + _manager.add_event(ev) assert dpnp.isfinite(dpnp.asarray(x)).all() @pytest.mark.parametrize("param_size", [0, 2, 4])