Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dpnp/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`).
Expand Down
18 changes: 12 additions & 6 deletions dpnp/dpnp_algo/dpnp_elementwise_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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):
Expand Down
9 changes: 6 additions & 3 deletions dpnp/dpnp_algo/dpnp_fill.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
9 changes: 6 additions & 3 deletions dpnp/dpnp_iface_histograms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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

Expand Down
9 changes: 6 additions & 3 deletions dpnp/dpnp_iface_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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"):
Expand Down
3 changes: 2 additions & 1 deletion dpnp/dpnp_iface_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 4 additions & 2 deletions dpnp/dpnp_iface_mathematical.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down
6 changes: 4 additions & 2 deletions dpnp/dpnp_iface_sorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -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])
Expand Down
6 changes: 4 additions & 2 deletions dpnp/dpnp_iface_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion dpnp/dpnp_iface_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 12 additions & 6 deletions dpnp/dpnp_utils/dpnp_utils_linearalgebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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:
Expand Down
15 changes: 10 additions & 5 deletions dpnp/dpnp_utils/dpnp_utils_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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":
Expand Down Expand Up @@ -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(
Expand All @@ -546,15 +549,17 @@ 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):
if not (orig_out[i] is None or orig_out[i] is res):
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:
Expand Down
12 changes: 8 additions & 4 deletions dpnp/fft/dpnp_utils_fft.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down
Loading
Loading