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
4 changes: 4 additions & 0 deletions conda-recipe/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ set -e

$PYTHON -c "import dpnp; print(dpnp.__version__)"
$PYTHON -m dpctl -f

timeout 10m gdb --batch -ex run -ex 'info sharedlibrary' -ex 'set print elements 1000' -ex thread apply all bt --args "$PYTHON" -m pytest -ra --disable-warnings --pyargs dpnp.tests.test_histogram || true
$PYTHON -m pytest -sv --pyargs dpnp.tests.test_histogram

$PYTHON -m pytest -ra --pyargs dpnp
2 changes: 1 addition & 1 deletion dpnp/backend/extensions/statistics/bincount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ std::tuple<sycl::event, sycl::event> Bincount::call(
dpctl::utils::keep_args_alive(exec_q, {sample, histogram}, {ev});
}

return {args_ev, ev};
return std::make_pair(args_ev, ev);
}

std::unique_ptr<Bincount> bincount;
Expand Down
2 changes: 1 addition & 1 deletion dpnp/backend/extensions/statistics/histogram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ std::tuple<sycl::event, sycl::event>
exec_q, {sample, bins, histogram}, {ev});
}

return {args_ev, ev};
return std::make_pair(args_ev, ev);
}

std::unique_ptr<Histogram> hist;
Expand Down
2 changes: 1 addition & 1 deletion dpnp/backend/extensions/statistics/histogramdd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ std::tuple<sycl::event, sycl::event> Histogramdd::call(
exec_q, {sample, bins_edges, bins_edges_count, histogram}, {ev});
}

return {args_ev, ev};
return std::make_pair(args_ev, ev);
}

std::unique_ptr<Histogramdd> histdd;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ std::tuple<sycl::event, sycl::event>
auto ev = corr_func(exec_q, a.get_data(), v.get_data(), out.get_data(),
a.get_shape(0), v.get_shape(0), l_pad, r_pad, depends);

sycl::event args_ev;
args_ev = dpctl::utils::keep_args_alive(exec_q, {a, v, out}, {ev});
sycl::event args_ev =
dpctl::utils::keep_args_alive(exec_q, {a, v, out}, {ev});

return {args_ev, ev};
return std::make_pair(args_ev, ev);
}

std::unique_ptr<SlidingDotProduct1d> sdp;
Expand Down
12 changes: 6 additions & 6 deletions dpnp/dpnp_algo/dpnp_fill.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ def dpnp_fill(arr, val):
a_val = dpt.broadcast_to(a_val, arr.shape)
_manager = dpu.SequentialOrderManager[exec_q]
dep_evs = _manager.submitted_events
h_ev, c_ev = _copy_usm_ndarray_into_usm_ndarray(
ht_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_event_pair(ht_ev, c_ev)
return
elif not isinstance(val, (Number, dpnp.bool)):
raise TypeError(
Expand All @@ -74,8 +74,8 @@ 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)
ht_ev, zeros_ev = _zeros_usm_ndarray(arr, exec_q, depends=dep_evs)
_manager.add_event_pair(ht_ev, 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)
ht_ev, fill_ev = _full_usm_ndarray(val, arr, exec_q, depends=dep_evs)
_manager.add_event_pair(ht_ev, fill_ev)
20 changes: 10 additions & 10 deletions dpnp/dpnp_iface_histograms.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,6 @@ def _bincount_run_native(
size, dtype=n_dtype, usm_type=n_usm_type, sycl_queue=queue
)

_manager = dpu.SequentialOrderManager[queue]

x_usm = dpnp.get_usm_ndarray(x_casted)
weights_usm = (
dpnp.get_usm_ndarray(weights_casted)
Expand All @@ -294,7 +292,9 @@ def _bincount_run_native(
)
n_usm = dpnp.get_usm_ndarray(n_casted)

mem_ev, bc_ev = statistics_ext.bincount(
_manager = dpu.SequentialOrderManager[queue]

ht_ev, bc_ev = statistics_ext.bincount(
x_usm,
min_v.item(),
max_v.item(),
Expand All @@ -303,7 +303,7 @@ def _bincount_run_native(
depends=_manager.submitted_events,
)

_manager.add_event_pair(mem_ev, bc_ev)
_manager.add_event_pair(ht_ev, bc_ev)

return n_casted

Expand Down Expand Up @@ -647,8 +647,6 @@ def histogram(a, bins=10, range=None, density=None, weights=None):
usm_type=n_usm_type,
)

_manager = dpu.SequentialOrderManager[queue]

a_usm = dpnp.get_usm_ndarray(a_casted)
bins_usm = dpnp.get_usm_ndarray(bin_edges_casted)
weights_usm = (
Expand All @@ -658,14 +656,16 @@ def histogram(a, bins=10, range=None, density=None, weights=None):
)
n_usm = dpnp.get_usm_ndarray(n_casted)

mem_ev, ht_ev = statistics_ext.histogram(
_manager = dpu.SequentialOrderManager[queue]

ht_ev, hist_ev = statistics_ext.histogram(
a_usm,
bins_usm,
weights_usm,
n_usm,
depends=_manager.submitted_events,
)
_manager.add_event_pair(mem_ev, ht_ev)
_manager.add_event_pair(ht_ev, hist_ev)

n = dpnp.asarray(n_casted, dtype=ntype, usm_type=usm_type)

Expand Down Expand Up @@ -1039,7 +1039,7 @@ def _histdd_run_native(

_manager = dpu.SequentialOrderManager[queue]

mem_ev, hdd_ev = statistics_ext.histogramdd(
ht_ev, histdd_ev = statistics_ext.histogramdd(
sample_usm,
edges_usm,
edges_count_usm,
Expand All @@ -1048,7 +1048,7 @@ def _histdd_run_native(
depends=_manager.submitted_events,
)

_manager.add_event_pair(mem_ev, hdd_ev)
_manager.add_event_pair(ht_ev, histdd_ev)

return n

Expand Down
8 changes: 4 additions & 4 deletions dpnp/dpnp_iface_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ def _choose_run(inds, chcs, q, usm_type, out=None, mode=0):
_manager = dpu.SequentialOrderManager[q]
dep_evs = _manager.submitted_events

h_ev, choose_ev = indexing_ext._choose(inds, chcs, out, mode, q, dep_evs)
_manager.add_event_pair(h_ev, choose_ev)
ht_ev, choose_ev = indexing_ext._choose(inds, chcs, out, mode, q, dep_evs)
_manager.add_event_pair(ht_ev, choose_ev)

return out

Expand Down Expand Up @@ -335,7 +335,7 @@ def _take_index(x, inds, axis, q, usm_type, out=None, mode=0):
_manager = dpu.SequentialOrderManager[q]
dep_evs = _manager.submitted_events

h_ev, take_ev = ti._take(
ht_ev, take_ev = ti._take(
src=x,
ind=(inds,),
dst=out,
Expand All @@ -344,7 +344,7 @@ 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_event_pair(ht_ev, take_ev)

return out

Expand Down
4 changes: 2 additions & 2 deletions dpnp/dpnp_iface_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def _isclose_scalar_tol(a, b, rtol, atol, equal_nan):
)

_manager = dpu.SequentialOrderManager[exec_q]
mem_ev, ht_ev = ufi._isclose_scalar(
ht_ev, isclose_ev = ufi._isclose_scalar(
a.get_array(),
b.get_array(),
rtol,
Expand All @@ -147,7 +147,7 @@ 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_event_pair(ht_ev, isclose_ev)

return output

Expand Down
8 changes: 4 additions & 4 deletions dpnp/dpnp_iface_mathematical.py
Original file line number Diff line number Diff line change
Expand Up @@ -2945,7 +2945,7 @@ def interp(x, xp, fp, left=None, right=None, period=None):
right_usm = right.get_array() if right is not None else None

_manager = dpu.SequentialOrderManager[exec_q]
mem_ev, ht_ev = ufi._interpolate(
ht_ev, inter_ev = ufi._interpolate(
x.get_array(),
idx.get_array(),
xp.get_array(),
Expand All @@ -2956,7 +2956,7 @@ 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_event_pair(ht_ev, inter_ev)

return output

Expand Down Expand Up @@ -3517,11 +3517,11 @@ def nan_to_num(x, copy=True, nan=0.0, posinf=None, neginf=None):
q = x.sycl_queue
_manager = dpu.SequentialOrderManager[q]

h_ev, comp_ev = ufi._nan_to_num(
ht_ev, comp_ev = ufi._nan_to_num(
x_ary, nan, max_f, min_f, out_ary, q, depends=_manager.submitted_events
)

_manager.add_event_pair(h_ev, comp_ev)
_manager.add_event_pair(ht_ev, comp_ev)

return dpnp.get_result_array(out)

Expand Down
4 changes: 2 additions & 2 deletions dpnp/dpnp_iface_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,15 +699,15 @@ def _run_native_sliding_dot_product1d(a, v, l_pad, r_pad, rdtype):

_manager = dpu.SequentialOrderManager[queue]

mem_ev, corr_ev = statistics_ext.sliding_dot_product1d(
ht_ev, corr_ev = statistics_ext.sliding_dot_product1d(
a_usm,
v_usm,
out_usm,
l_pad,
r_pad,
depends=_manager.submitted_events,
)
_manager.add_event_pair(mem_ev, corr_ev)
_manager.add_event_pair(ht_ev, corr_ev)

return out

Expand Down
6 changes: 4 additions & 2 deletions dpnp/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

import dpnp

from .helper import get_dev_id
from .helper import get_dev_id, get_dev_info

skip_mark = pytest.mark.skip(reason="Skipping test.")

Expand Down Expand Up @@ -143,7 +143,9 @@ def pytest_collection_modifyitems(config, items):
print(
f"DPNP Test scope includes all integer dtypes: {bool(dtype_config.all_int_types)}"
)
print(f"DPNP current device ID: 0x{get_dev_id(dev):04X}")
print(
f"DPNP current device ID: 0x{get_dev_id(dev):04X}, info: {get_dev_info(dev)}"
)
print(f"DPNP current device is CPU: {is_cpu}")
print(f"DPNP current device is GPU: {is_gpu}")
print(f"DPNP current device supports fp64: {support_fp64}")
Expand Down
24 changes: 22 additions & 2 deletions dpnp/tests/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,18 @@ def get_dev_id(device=None):
Obtain Intel Device ID for a device (the default device if not provided).
"""

return get_dev_info(device).get("device_id", 0)


def get_dev_info(device=None):
"""
Obtain a dictionary with the info for a device (the default device if not
provided).

"""

dev = dpctl.select_default_device() if device is None else device
dev_info = dpctl.utils.intel_device_info(dev)
return dev_info.get("device_id", 0)
return dpctl.utils.intel_device_info(dev)


def get_float_dtypes(no_float16=True, device=None):
Expand Down Expand Up @@ -531,3 +540,14 @@ def requires_intel_mkl_version(version): # pragma: no cover

build_deps = numpy.show_config(mode="dicts")["Build Dependencies"]
return build_deps["blas"]["version"] >= version


def requires_memory(no_of_gbs, device=None):
"""
Check if the required number of GBs in memory of a device (the default one
if not provided) is available.

"""

free_mem = get_dev_info(device).get("free_memory", 0)
return free_mem >= no_of_gbs * (1024**3)
21 changes: 9 additions & 12 deletions dpnp/tests/test_histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@
get_integer_float_dtypes,
has_support_aspect64,
numpy_version,
requires_memory,
)

# Build a list of bin sizes to check the histogram
_bin_counts = [10, 10**2, 10**3, 10**4, 10**5]
if requires_memory(16):
_bin_counts += [10**6]


class TestDigitize:
@pytest.mark.parametrize("dtype", get_integer_float_dtypes())
Expand Down Expand Up @@ -486,10 +492,7 @@ def test_weights_another_sycl_queue(self):
with assert_raises(ValueError):
dpnp.histogram(v, weights=w)

@pytest.mark.parametrize(
"bins_count",
[10, 10**2, 10**3, 10**4, 10**5, 10**6],
)
@pytest.mark.parametrize("bins_count", _bin_counts)
def test_different_bins_amount(self, bins_count):
v = numpy.linspace(0, bins_count, bins_count, dtype=numpy.float32)
iv = dpnp.array(v)
Expand Down Expand Up @@ -584,10 +587,7 @@ def test_weights_unsupported_dtype(self, xp, dt):
w = xp.arange(5, dtype=dt)
assert_raises((TypeError, ValueError), xp.bincount, v, weights=w)

@pytest.mark.parametrize(
"bins_count",
[10, 10**2, 10**3, 10**4, 10**5, 10**6],
)
@pytest.mark.parametrize("bins_count", _bin_counts)
def test_different_bins_amount(self, bins_count):
v = numpy.arange(0, bins_count, dtype=int)
iv = dpnp.array(v)
Expand Down Expand Up @@ -863,10 +863,7 @@ def test_weights_another_sycl_queue(self):
with assert_raises(ValueError):
dpnp.histogramdd(v, weights=w)

@pytest.mark.parametrize(
"bins_count",
[10, 10**2, 10**3, 10**4, 10**5, 10**6],
)
@pytest.mark.parametrize("bins_count", _bin_counts)
def test_different_bins_amount(self, bins_count):
v = numpy.linspace(0, bins_count, bins_count, dtype=numpy.float32)
iv = dpnp.array(v)
Expand Down
Loading