Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ This release drops support for Python 3.10, making Python 3.11 the minimum requi
* Fixed `dpnp.place` and `dpnp.tensor.place` to order the write after the cast of `vals` to the array's data type, which could put wrong values into the array on an out-of-order queue [#3164](https://github.com/IntelPython/dpnp/pull/3164)
* Fixed the example of handling duplicate indices in the `dpnp.tensor.put` docstring, which imported `dpctl.tensor`, did not parse and lost writes when `x` is longer than `indices` [#3165](https://github.com/IntelPython/dpnp/pull/3165)
* Fixed a segfault when setting `writable` on a `Flags` object created without an array [#3168](https://github.com/IntelPython/dpnp/pull/3168)
* Fixed a crash of the OpenCL CPU compiler in `dpnp.sort`, `dpnp.argsort`, `dpnp.tensor.sort` and `dpnp.tensor.argsort` by radix sort of rows of 2049 to 16384 elements [#3191](https://github.com/IntelPython/dpnp/pull/3191)

### Security

Expand Down
15 changes: 9 additions & 6 deletions dpnp/libtensor/include/kernels/sorting/radix_sort.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1086,8 +1086,9 @@ struct subgroup_radix_sort
const std::uint32_t krn_sg_size = krn.template get_info<
sycl::info::kernel_device_specific::max_sub_group_size>(dev);

// due to a bug in CPU device implementation, an additional
// synchronization is necessary for short sub-group sizes
// the CPU device compiler miscompiles the counting for short
// sub-groups unless each update is fenced (CMPLRLLVM-64592); a

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it the same as CMPLRLLVM-79305?

// barrier in place of the fence crashes its barrier pass
const bool work_around_needed =
exec_q.get_device().has(sycl::aspect::cpu) &&
(krn_sg_size < 16);
Expand Down Expand Up @@ -1198,8 +1199,9 @@ struct subgroup_radix_sort
*counters[i] = indices[i] + 1;

if (work_around_needed) {
sycl::group_barrier(
ndit.get_group());
sycl::atomic_fence(
sycl::memory_order::acq_rel,
sycl::memory_scope::work_group);
}
}
}
Expand Down Expand Up @@ -1234,8 +1236,9 @@ struct subgroup_radix_sort
*counters[i] = indices[i] + 1;

if (work_around_needed) {
sycl::group_barrier(
ndit.get_group());
sycl::atomic_fence(
sycl::memory_order::acq_rel,
sycl::memory_scope::work_group);
}
}
}
Expand Down
30 changes: 30 additions & 0 deletions dpnp/tests/tensor/test_usm_ndarray_sorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,3 +412,33 @@ def test_radix_argsort_size_1_axis():
x4 = dpt.reshape(dpt.arange(10, dtype="i1"), (1, 10))
r4 = dpt.argsort(x4, axis=0, kind="radixsort")
assert dpt.asnumpy(r4 == 0).all()


# rows of every size class of the one-work-group radix sort above 256; on the
# CPU device int8 argsort came out unstable and some data types crashed the
# compiler at block sizes of 16 and more
@pytest.mark.parametrize("n", [257, 1025, 2049, 4096, 8193, 16384])
@pytest.mark.parametrize("dtype", ["?", "i1", "u1", "i2", "i4", "i8"])
Comment on lines +420 to +421

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This misses two size classes: 513..1024 and 4097..8192 (2049 and 4096 share one, 8193 and 16384 another). On master, int8 rows of 8192 crash the CPU compiler too. u2 takes the radix sort by default but is not here; on master a (2, 3000) uint16 sort spends over 10 minutes in the CPU compiler. Maybe [257, 513, 1025, 2049, 4097, 8193] and "u2"?

@pytest.mark.parametrize("descending", [False, True])
def test_radix_sort_one_work_group(n, dtype, descending):
q = get_queue_or_skip()
skip_if_dtype_not_supported(dtype, q)

rng = np.random.default_rng(42)
if dtype == "?":
x_np = rng.integers(0, 2, size=(2, n)).astype(dtype)
else:
info = np.iinfo(dtype)
x_np = rng.integers(info.min, info.max, size=(2, n), dtype=dtype)
x = dpt.asarray(x_np, sycl_queue=q)

# stable in either order: ties keep the order of the input
_, ranks = np.unique(x_np, return_inverse=True)
ranks = ranks.reshape(x_np.shape)
expected_inds = np.argsort(-ranks if descending else ranks, kind="stable")
expected = np.take_along_axis(x_np, expected_inds, axis=-1)

s = dpt.sort(x, descending=descending, kind="radixsort")
assert_array_equal(dpt.asnumpy(s), expected)
inds = dpt.argsort(x, descending=descending, kind="radixsort")
assert_array_equal(dpt.asnumpy(inds), expected_inds)
Loading