Repository navigation
Implement kernels for median and paritition functions - #3138
Open
ndgrigorian wants to merge 12 commits into
Open
ndgrigorian wants to merge 12 commits into
ndgrigorian wants to merge 12 commits into
Conversation
Contributor
|
View rendered docs @ https://intelpython.github.io/dpnp/pull/3138/index.html |
Contributor
|
Array API standard conformance tests for dpnp=0.22.0dev0=np2py314h8d9cdd5_39 ran successfully. |
ndgrigorian
force-pushed
the
feature/implement-median-partition-fns
branch
2 times, most recently
from
November 2, 2026 06:38
0f57805 to
8667696
Compare
ndgrigorian
force-pushed
the
feature/refactor-dpnp-backend-to-libtensor
branch
from
November 2, 2026 15:06
e24ca7b to
2df1e76
Compare
ndgrigorian
force-pushed
the
feature/implement-median-partition-fns
branch
from
November 2, 2026 15:07
8667696 to
58ce933
Compare
ndgrigorian
marked this pull request as ready for review
November 2, 2026 16:00
ndgrigorian
requested review from
antonwolfy and
vlad-perevezentsev
as code owners
November 2, 2026 16:00
Collaborator
ndgrigorian
force-pushed
the
feature/refactor-dpnp-backend-to-libtensor
branch
2 times, most recently
from
November 2, 2026 21:41
236c2e1 to
43ca63d
Compare
ndgrigorian
force-pushed
the
feature/implement-median-partition-fns
branch
from
November 2, 2026 22:19
58ce933 to
89cc1d4
Compare
Base automatically changed from
feature/refactor-dpnp-backend-to-libtensor
to
master
November 3, 2026 16:31
ndgrigorian
force-pushed
the
feature/implement-median-partition-fns
branch
2 times, most recently
from
November 3, 2026 22:08
74de517 to
c7864b9
Compare
3 of 7 tasks
partition.cpp is a dpnp source, built with the coverage flags, but gen_coverage.py treated _tensor_sorting_impl as libtensor-only and left it out of the default report. List it first in the module like the other dpnp sources, so the linker keeps its instrumented copies of shared inline functions.
The device coverage counters of partition.cpp and median.cpp reach the sort and top_k kernels through the shared inline helpers, about 500 device globals per kernel image. Their init events make the OpenCL CPU runtime use a freed command, so the coverage tests segfaulted at random in top_k, sort and unique_all.
With n=1 the signed-zero row was all NaN, so NumPy and dpnp warned. test_all_nan_rows covers that case.
out[...] = res broadcast the medians into an out of the wrong shape, e.g. (2, 3) or (1, 3) for an axis=0 median of a (4, 3) array, where the sort path raised ValueError. The shape is checked against the result with keepdims applied, as NumPy accepts such an out. NumPy's nanmedian broadcasts too, but dpnp keeps raising as before and as documented.
Both returned on an empty batch before checking kth, the data types, contiguity and overlap, so a call that raised for a non-empty array passed for an empty one. _median also left the all_nan flag uninitialized. The early returns now come after the checks, and _median zeroes the flag first. _median also checks that src does not overlap all_nan.
With keepdims=True the sort path passed out of the keepdims shape to dpnp.mean and _calc_nanmedian, which expect the shape without the reduced axes and raised ValueError, while NumPy accepts it. out is now checked against the keepdims shape once, and both paths write the medians to a view of it with the reduced axes indexed away, which never copies. The select path no longer needs the result shape.
partition.cpp and median.cpp are dpnp sources, built with the default fast floating-point model of icpx, which keeps -fno-signed-zeros. The compiler could fold `val == 0 ? 0 : val` to `val`, so -0.0 kept its own key, and the median of zeros came back as -0.0, where NumPy's mean gives +0.0. Mapping the key of -0.0 to that of +0.0 with integer compares holds under any floating-point flags.
dpt.full submits its fill asynchronously, so without depends the extension's clearing fill could run first and leave the initial 7.
ndgrigorian
force-pushed
the
feature/implement-median-partition-fns
branch
from
November 4, 2026 19:59
01da8d2 to
9d6de57
Compare
Every kernel image of a module carries all its device coverage counters, so the median kernels still got the 768 counters of the bincount, histogram and sliding window sources after median.cpp became host only. Their device global init events crash the OpenCL CPU runtime in the kernel bundle launches of the radix select, as in nanmedian. The device counts never reach the profile, so the reported coverage is unchanged.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR proposes the addition of updates to radix selection algorithms to generalize for cases of
medianandpartitionrelated functions, which allows the removal ofdpnp_partition_cfrom the DPNP backendThe median and partition functions can pass through either a sorting or a radix selection path, based on input types (and in the case of partition, always when
kthis multiple elements)Supersedes #2423