Repository navigation
Fix the OpenCL CPU compiler crash in the one-work-group radix sort - #3191
Conversation
…ices rather than synchronize the work-group On a CPU device whose kernel takes sub-groups shorter than 16, each counter update was followed by a group_barrier, the work-around of CMPLRLLVM-64592 (int8 radix argsort comes out unstable). With 16 or more elements per work-item, from rows of 2049 elements, these barriers crash the OpenCL CPU compiler in its sycl-kernel-reduce-cross-barrier-values pass, so dpnp.sort and dpnp.argsort of such rows segfault; bool, int8, uint8, int16 and uint16 take the radix sort by default. Seen with every OpenCL CPU runtime from 2024.18 to 2026.22. A work-group fence in place of the barrier still keeps int8 argsort stable and adds no barrier region, so the compiler no longer crashes. Sort and argsort of all integer and floating data types are correct on the same runtimes, and GPU timings are unchanged since GPUs don't take the work-around.
|
View rendered docs @ https://intelpython.github.io/dpnp/index.html |
|
Array API standard conformance tests for dpnp=0.22.0dev2=np2py314h8d9cdd5_11 ran successfully. |
antonwolfy
left a comment
There was a problem hiding this comment.
I tested this head against master at the merge base, using the CI packages of both, on the CPU device of three AVX2 CPUs (PTL-H Core Ultra X7 368H, LNL, ARL-S Core Ultra 5 245K) and of PVC's AVX-512 Xeon 8480+. Three OpenCL CPU runtimes: intel-opencl-rt 2025.0.4 (2024.18.12.0.05), 2026.2.0 (2026.22.10.0.01) and the intel/llvm 2026-WW42 oclcpuexp (2026.22.10.0.02). Each sort or argsort ran in a fresh process, so each run built the kernel.
The fix works. At 4096-16384 elements, master failed in 4447 of 10440 runs, by a crash or a hang in sycl-kernel-reduce-cross-barrier-values. This PR failed in none of 15320:
| CPU, cells | master, failed/runs | this PR |
|---|---|---|
| PTL-H, all 8 dtypes × 4096/8192/16384 × sort/argsort | 491/1440 | 0/2400 |
| LNL, 10 of those cells | 100/300 | 0/500 |
| ARL-S, the same 10 cells | 91/300 | 0/500 |
| Xeon 8480+, default | 717/1440 | 0/2400 |
Xeon 8480+, CL_CONFIG_CPU_VECTORIZER_MODE=8 |
709/1440 | 0/2400 |
| the cells that failed above, rerun on each of the three runtimes (PTL-H, LNL, Xeon mode 8) | 2339/5520 | 0/5520 |
Rows of 1024 and 2048 never failed on either build. On the CPU device, test_radix_sort_one_work_group fails on master in 37-46 of its 72 nodes, all at 2049 and up, and passes on this PR. On level_zero:gpu it passes on both.
The work-around is still needed, and the fence keeps it correct. I used a standalone copy of the kernel, with int8 argsort of 3-value data. Without the work-around, the argsort was wrong in every process at sub-group 8 (what the kernels get on these AVX2 CPUs), in 33-52 % of reps at 1024, 4096 and 16384. With the fence, 0 of 45000 reps were wrong. With the barrier, none were wrong either, but the build crashed in up to 8 of 10 processes.
Some points in the description don't match what I saw:
- Not only CPUs with sub-groups shorter than 16 crash. On the Xeon in the default mode the kernel has sub-group 16 and skips the work-around, yet master crashed in 717 of 1440 runs.
work_around_neededis computed after the build, so the barrier is compiled in on every CPU device. - Every radix kernel gets sub-group 8 on the AVX2 CPUs, not only int8's, and every dtype crashes. All of
bool,int8,uint8,int16,uint16,int32,int64andfloat32crash, in 22-99 of 180 runs each on PTL-H and the Xeon. - The int64 hang is the same bug. All 222 hangs dumped in that same pass (
copyAndReplaceUses), int64 and uint16 among them. - Master can also return a wrong result without crashing. It did twice: a uint16 sort of 4096 elements (8121 of 8192 wrong) and an int64 argsort of 16384 (32756 of 32768 indices wrong).
The two open threads still apply: the comment could name CMPLRLLVM-79305, and the test could add the missing size class and u2 (my data is in that thread). The perf numbers are in a separate comment.
|
I timed sort and argsort against master at the merge base, with warm kernels. The cells were Speedup = master/PR time (old/new, > 1 = faster now), geomean over cells:
|
The barrier the fence replaced crashes the OpenCL CPU compiler as reported in CMPLRLLVM-79305, so the work-around can be revisited once that is fixed. The fence avoids CMPLRLLVM-64592 in this kernel, but not in the older copy of the kernel in that ticket's reproducer, so the comment no longer says it does in general.
… the radix sort test Rows of 513 and 4097 fall in the two size classes the test missed, and on master int8 rows of 8192 and uint16 sorts crash or hang the CPU compiler as well. The second row now holds three values, so the argsort has many ties to keep in order.
|
Thanks for the runs, @antonwolfy. I updated the description to match what you saw: the barriers are compiled in on every CPU device, since the sub-group size is only known after the build; every radix data type can crash; the hangs are the same bug (CMPLRLLVM-79305); and master can also return a wrong sort without crashing. It also now says that the fence avoids CMPLRLLVM-64592 in this kernel but not in the older copy of the kernel in that ticket's reproducer (details in the comment thread). On the perf comment: I agree the int8 sort of 64-128 elements is small enough to leave. I haven't checked whether those kernels take the work-around either. |
antonwolfy
left a comment
There was a problem hiding this comment.
Thanks, this covers both threads. The comment names both tickets, and the test now has one row size per one-work-group size class above 256, with u2 and the three-value row. The kernel code didn't change, so my earlier runs still apply.
Optional, if you touch it again:
- The description says "8 for every radix kernel on an AVX2 CPU". I only checked the 4096 class (all 8 dtypes, sort and argsort), so "every radix kernel" in my review went too far; I didn't probe the other size classes.
- The perf sentence says there is no difference beyond noise on
opencl:cpu. On the AVX2 CPUs I measured 1.08-1.11x faster from 4096 elements (see my perf comment). - With 4096 and 16384 gone, the test has no full-block row and no row at 16384, the largest size the one-work-group path takes. Adding 16384 back would cover that boundary.
a508bfd to
8ccf0b5
Compare
|
Re-checked after the last commit, which adds rows of 16384 back to
|
…3191) This PR fixes a crash of the OpenCL CPU compiler in the one-work-group radix sort, which `dpnp.sort`, `dpnp.argsort` and their `dpnp.tensor` counterparts take for rows of 2049 to 16384 elements. Radix sort is the default for `bool`, `int8`, `uint8`, `int16` and `uint16`, so a plain `dpnp.sort` of such rows can segfault on a CPU device, for example `dpt.sort(dpt.zeros((1, 4096), dtype="i1", device="opencl:cpu"))`. The kernel puts a `group_barrier` after every unrolled counter update when it runs on a CPU device whose kernel gets sub-groups shorter than 16 (8 on an AVX2 CPU, as checked for rows of 4096 elements). That is the work-around for CMPLRLLVM-64592, added in IntelPython/dpctl@5125e11eb4. The sub-group size is only known after the kernel is built, so the barriers are compiled in on every CPU device, including AVX-512 CPUs with sub-group 16 that never run them. With 16 or more elements per work-item, they crash the compiler in its `sycl-kernel-reduce-cross-barrier-values` pass (`copyAndReplaceUses`), reported as CMPLRLLVM-79305. Every radix data type can crash, and which ones do depends on the compiler's heap state; the same pass also hangs at times, and master has returned a wrong sort without crashing. The crash shows up with every OpenCL CPU runtime from 2024.18 (`intel-opencl-rt` 2025.0.4) to 2026.22 (2026.2.0). The work-around is still needed: without it, the `int8` radix argsort is unstable on the same runtimes. This PR replaces the barrier with a work-group `atomic_fence`, which adds no barrier region and so no longer crashes the compiler. In this kernel the fence keeps the `int8` argsort stable. In the older copy of the kernel in the CMPLRLLVM-64592 reproducer it doesn't, and only the barrier does, so the fence avoids that bug in this kernel rather than fixing it in general. With a standalone SYCL reproducer, sort and stable argsort of `bool`, `int8`, `uint8`, `int16`, `uint16`, `int32`, `int64`, `float32` and `float64` match `std::sort`/`std::stable_sort` in both orders. That covers 1, 37 and 300 rows of every one-work-group size class, with full-range and low-cardinality data, on seven OpenCL CPU runtimes from 2025.0.4 to 2026.2.0. `test_radix_sort_one_work_group` covers one row size of each one-work-group size class above 256 elements, and rows of 16384, the largest size that path takes, for `bool`, `int8`, `uint8`, `int16`, `uint16`, `int32` and `int64`, with full-range and three-value data. Without the fix it segfaults or hangs on `opencl:cpu` from 2049 elements; with it, it passes on `opencl:cpu` and `level_zero:gpu`, as do the sorting, `top_k` and `unique` tests. GPUs don't take the work-around. Sort and argsort timings alternated between the two builds show no difference beyond noise on the iGPU (`level_zero:gpu`). On AVX2 CPUs (`opencl:cpu`), where the fence replaces a barrier that runs, rows of 4096 elements and more sort 1.08-1.11x faster in geomean; on a Xeon with sub-group 16, which doesn't run the work-around, the change is neutral (see the perf comment in this PR). - [x] Have you provided a meaningful PR description? - [x] Have you added a test, reproducer or referred to an issue with a reproducer? - [x] Have you tested your changes locally for CPU and GPU devices? - [x] Have you made sure that new changes do not introduce compiler warnings? - [x] Have you checked performance impact of proposed changes? - [ ] Have you added documentation for your changes, if necessary? - [x] Have you added your changes to the changelog?
…#3192) This PR fixes an intermittent crash of the OpenCL CPU compiler in the complex `dpnp.minmax` kernel, which has been failing the `Generate coverage` job since `dpnp.minmax` landed in #3135 (e.g. [this run](https://github.com/IntelPython/dpnp/actions/runs/43946499556/job/133577453161)). pytest dies at about 59% of the dpnp tests in `TestMinMax::test_size`, with a SIGABRT inside `libintelocl.so` or a silent SIGALRM. Complex types can't use `sycl::reduce_over_group` with dpnp's min/max operators, so they take `CustomMinMaxGroupReducer`. It reduced the minimum and the maximum with two `custom_reduce_over_group` calls on the same local memory, with a `group_barrier` between them. In the coverage build (`-O1 -g1` plus device-side profiling for `minmax.cpp`), building this kernel corrupts the compiler's heap in `ReduceCrossBarrierValuesPass` (`malloc(): unsorted double linked list corrupted` in `collectDependencies`). It is the same pass and the same kind of corruption as the radix sort crash in #3191 (CMPLRLLVM-79305). The barriers here are needed: work-items read local memory that others wrote, so they can't become fences. This PR instead folds both extrema in one tree over a local memory of twice the work-group size, with one barrier per step for both. That gives the kernel the barrier structure of `dpnp.max` on complex, which the coverage job builds without crashing. The local memory is at most 64 KB for `complex128` on a CPU (work-group capped at 2048) and 16 KB on a GPU (capped at 512). On a Panther Lake host with the coverage build and the 2026.2.0 OpenCL CPU runtime, the complex cases of `TestMinMax::test_size` on `opencl:cpu` crashed in 5 of 20 runs before the change and in none of 20 after it, in alternating runs (17 of 48 vs 0 of 50 counting all runs). The Release build doesn't crash before the change either (0 of 70). The minmax tests of `test_statistics.py`, `test_sycl_queue.py` and `test_usm_type.py` pass on `opencl:cpu` and `level_zero:gpu`. The existing complex `test_size` cases are the reproducer. No changelog entry, since `dpnp.minmax` is not released yet. The change also speeds up the complex reduction. On a Panther Lake H host (Arc B390) and on a Xeon Platinum 8480+ host with a Data Center GPU Max 1100, with a Release build where only `_tensor_reductions_impl` differs, the median time per call with the fix divided by master over 9 alternating rounds (lower is faster): | Case | Panther Lake `opencl:cpu` | Arc B390 `level_zero:gpu` | Xeon 8480+ `opencl:cpu` | Max 1100 `level_zero:gpu` | | --- | --- | --- | --- | --- | | complex64, geomean of 7 shapes | 0.50 | 0.98 | 0.59 | 0.94 | | complex128, geomean of 7 shapes | 0.37 | 0.98 | 0.69 | 0.96 | | complex64 / complex128 `(1000000, 16)`, `axis=1` | 0.17 / 0.17 | 0.90 / 0.99 | 0.27 / 0.37 | 0.81 / 0.84 | | complex64 / complex128 `(10000000,)`, `axis=None` | 0.52 / 0.51 | 0.99 / 1.00 | 0.57 / 0.61 | 0.91 / 0.95 | | complex64 / complex128 `(4096, 4096)`, `axis=0` | 0.86 / 0.86 | 1.00 / 1.00 | 0.87 / 0.87 | 0.99 / 1.00 | | float32 (unchanged kernel), geomean of 7 shapes | 1.01 | 1.02 | 1.01 | 1.01 | The shapes are 1-D of 1000, 100000 and 10000000 elements with `axis=None`, `(4096, 4096)` with `axis=0` and `axis=1`, `(16, 1000000)` and `(1000000, 16)` with `axis=1`. All results match NumPy.
…#3192) This PR fixes an intermittent crash of the OpenCL CPU compiler in the complex `dpnp.minmax` kernel, which has been failing the `Generate coverage` job since `dpnp.minmax` landed in #3135 (e.g. [this run](https://github.com/IntelPython/dpnp/actions/runs/43946499556/job/133577453161)). pytest dies at about 59% of the dpnp tests in `TestMinMax::test_size`, with a SIGABRT inside `libintelocl.so` or a silent SIGALRM. Complex types can't use `sycl::reduce_over_group` with dpnp's min/max operators, so they take `CustomMinMaxGroupReducer`. It reduced the minimum and the maximum with two `custom_reduce_over_group` calls on the same local memory, with a `group_barrier` between them. In the coverage build (`-O1 -g1` plus device-side profiling for `minmax.cpp`), building this kernel corrupts the compiler's heap in `ReduceCrossBarrierValuesPass` (`malloc(): unsorted double linked list corrupted` in `collectDependencies`). It is the same pass and the same kind of corruption as the radix sort crash in #3191 (CMPLRLLVM-79305). The barriers here are needed: work-items read local memory that others wrote, so they can't become fences. This PR instead folds both extrema in one tree over a local memory of twice the work-group size, with one barrier per step for both. That gives the kernel the barrier structure of `dpnp.max` on complex, which the coverage job builds without crashing. The local memory is at most 64 KB for `complex128` on a CPU (work-group capped at 2048) and 16 KB on a GPU (capped at 512). On a Panther Lake host with the coverage build and the 2026.2.0 OpenCL CPU runtime, the complex cases of `TestMinMax::test_size` on `opencl:cpu` crashed in 5 of 20 runs before the change and in none of 20 after it, in alternating runs (17 of 48 vs 0 of 50 counting all runs). The Release build doesn't crash before the change either (0 of 70). The minmax tests of `test_statistics.py`, `test_sycl_queue.py` and `test_usm_type.py` pass on `opencl:cpu` and `level_zero:gpu`. The existing complex `test_size` cases are the reproducer. No changelog entry, since `dpnp.minmax` is not released yet. The change also speeds up the complex reduction. On a Panther Lake H host (Arc B390) and on a Xeon Platinum 8480+ host with a Data Center GPU Max 1100, with a Release build where only `_tensor_reductions_impl` differs, the median time per call with the fix divided by master over 9 alternating rounds (lower is faster): | Case | Panther Lake `opencl:cpu` | Arc B390 `level_zero:gpu` | Xeon 8480+ `opencl:cpu` | Max 1100 `level_zero:gpu` | | --- | --- | --- | --- | --- | | complex64, geomean of 7 shapes | 0.50 | 0.98 | 0.59 | 0.94 | | complex128, geomean of 7 shapes | 0.37 | 0.98 | 0.69 | 0.96 | | complex64 / complex128 `(1000000, 16)`, `axis=1` | 0.17 / 0.17 | 0.90 / 0.99 | 0.27 / 0.37 | 0.81 / 0.84 | | complex64 / complex128 `(10000000,)`, `axis=None` | 0.52 / 0.51 | 0.99 / 1.00 | 0.57 / 0.61 | 0.91 / 0.95 | | complex64 / complex128 `(4096, 4096)`, `axis=0` | 0.86 / 0.86 | 1.00 / 1.00 | 0.87 / 0.87 | 0.99 / 1.00 | | float32 (unchanged kernel), geomean of 7 shapes | 1.01 | 1.02 | 1.01 | 1.01 | The shapes are 1-D of 1000, 100000 and 10000000 elements with `axis=None`, `(4096, 4096)` with `axis=0` and `axis=1`, `(16, 1000000)` and `(1000000, 16)` with `axis=1`. All results match NumPy.
This PR fixes a crash of the OpenCL CPU compiler in the one-work-group radix sort, which
dpnp.sort,dpnp.argsortand theirdpnp.tensorcounterparts take for rows of 2049 to 16384 elements. Radix sort is the default forbool,int8,uint8,int16anduint16, so a plaindpnp.sortof such rows can segfault on a CPU device, for exampledpt.sort(dpt.zeros((1, 4096), dtype="i1", device="opencl:cpu")).The kernel puts a
group_barrierafter every unrolled counter update when it runs on a CPU device whose kernel gets sub-groups shorter than 16 (8 on an AVX2 CPU, as checked for rows of 4096 elements). That is the work-around for CMPLRLLVM-64592, added in IntelPython/dpctl@5125e11eb4. The sub-group size is only known after the kernel is built, so the barriers are compiled in on every CPU device, including AVX-512 CPUs with sub-group 16 that never run them. With 16 or more elements per work-item, they crash the compiler in itssycl-kernel-reduce-cross-barrier-valuespass (copyAndReplaceUses), reported as CMPLRLLVM-79305. Every radix data type can crash, and which ones do depends on the compiler's heap state; the same pass also hangs at times, and master has returned a wrong sort without crashing. The crash shows up with every OpenCL CPU runtime from 2024.18 (intel-opencl-rt2025.0.4) to 2026.22 (2026.2.0).The work-around is still needed: without it, the
int8radix argsort is unstable on the same runtimes. This PR replaces the barrier with a work-groupatomic_fence, which adds no barrier region and so no longer crashes the compiler. In this kernel the fence keeps theint8argsort stable. In the older copy of the kernel in the CMPLRLLVM-64592 reproducer it doesn't, and only the barrier does, so the fence avoids that bug in this kernel rather than fixing it in general.With a standalone SYCL reproducer, sort and stable argsort of
bool,int8,uint8,int16,uint16,int32,int64,float32andfloat64matchstd::sort/std::stable_sortin both orders. That covers 1, 37 and 300 rows of every one-work-group size class, with full-range and low-cardinality data, on seven OpenCL CPU runtimes from 2025.0.4 to 2026.2.0.test_radix_sort_one_work_groupcovers one row size of each one-work-group size class above 256 elements, and rows of 16384, the largest size that path takes, forbool,int8,uint8,int16,uint16,int32andint64, with full-range and three-value data. Without the fix it segfaults or hangs onopencl:cpufrom 2049 elements; with it, it passes onopencl:cpuandlevel_zero:gpu, as do the sorting,top_kanduniquetests.GPUs don't take the work-around. Sort and argsort timings alternated between the two builds show no difference beyond noise on the iGPU (
level_zero:gpu). On AVX2 CPUs (opencl:cpu), where the fence replaces a barrier that runs, rows of 4096 elements and more sort 1.08-1.11x faster in geomean; on a Xeon with sub-group 16, which doesn't run the work-around, the change is neutral (see the perf comment in this PR).