fix(rocprim): radix sort merge comparator must not quiet signaling NaNs #16568
All Vouch review confidence checks passed
Residual risk 0.24 = Change Risk (0.45) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 444 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.365
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #16568"
general
weight: 0.35
umfranzw
radix_sort_keys/radix_sort_pairs(andhipcub::DeviceRadixSort, sotorch.sort) lose andduplicate elements when floating point keys mix signaling and quiet NaNs, for 1025 to 2^20 items (the
merge-sort path; below 100000 items for half and bfloat16). Short segments of
segmented_radix_sort_keys/pairsorder such keys wrongly too.The merge path sorts 1024-item tiles with the radix block sort (raw bits, -0.0 folded into +0.0) and
then merges them with
compare_nan_sensitive, which folded -0.0 witha + T(0)since #3617. Thataddition quiets signaling NaNs, so the merge compared different bits than the block sort; tiles were no
longer sorted under the merge comparator and the merge-path partitions wrote some outputs twice and
others never. Before the fix the result is not deterministic and a run can hang or fault the GPU.
compare_nan_sensitivenow maps the key bits from sign-magnitude to two's complement (a negative keybecomes minus its magnitude) and compares them as signed integers. -0.0 and +0.0 both map to 0 and all
other bit patterns, NaNs included, keep exactly the order of the radix key codec. No floating point
arithmetic, so the
__HIP_NO_HALF_OPERATORS__special case is no longer needed.Checked against the radix key codec in both directions for every float, half and bfloat16 bit pattern
and for 2^31 adjacent plus 2^31 random double pairs and special values: no mismatch (develop: 2, 2, 2 and 73).
The change is applied to all three copies of rocPRIM in the repository:
projects/hipccl/hipccl3/rocprim,projects/hipccl/hipccl2/rocprimand the deprecatedprojects/rocprim(the copy shipped in ROCm 10.2).CHANGELOG entries are added for hipccl3 (rocPRIM 5.1.0) and
projects/rocprim.Tests:
RocprimDeviceRadixSort.SortPairsMixedNaNsandRocprimDeviceSegmentedRadixSort.SortPairsMixedNaNs(float, double, half, bfloat16; ascending and descending; random keys with signaling and quiet NaNs; exact
comparison with a host stable sort). They fail without the fix and pass with it on gfx1201 and gfx1100 for
hipccl3, and on gfx1100 for hipccl2 and projects/rocprim; the existing radix sort, segmented radix sort and radix
key codec tests still pass.
Performance,
benchmark_device_radix_sortandbenchmark_device_segmented_radix_sort_{keys,pairs},merge-path sizes and f32/f64/half keys (f64 only in the segmented benchmark; radix sort f64 timed with a standalone
loop: 1M keys 728 -> 448 us on gfx1201, 479 -> 319 us on gfx1100), 3 repetitions, throughput patched/develop (no MI
GPU was available):
(0.84 to 1.70), pairs 1.02 (0.97 to 1.42).
gfx942 double merge kernels are +0 to +5% instructions and the segmented warp-sort helpers +12%, float
+1 to +2%; please benchmark on MI300/MI355. The gfx1201 f32 1M keys-only loss comes from
the merge-path search loop, where the select in the new mapping adds a VCC dependency wait on gfx12; a
branch-free mapping recovers about 10% of it there but is slower for f64 and on gfx1100. The comparator
alone is 1 to 3 VALU shorter than develop for float and half (about 20 shorter for bfloat16) on gfx1201,
gfx1100, gfx942, gfx90a and gfx950; for double it is 1 shorter on RDNA and 1 longer on CDNA.
Fixes #16364