Skip to content

[Fix][Relax] Dispatch median sorting on GPU - #20917

Open
0z5a wants to merge 1 commit into
apache:mainfrom
0z5a:codex/median-gpu-dispatch-20261104
Open

0z5a wants to merge 1 commit into
apache:mainfrom
0z5a:codex/median-gpu-dispatch-20261104

Conversation

@0z5a

@0z5a 0z5a commented Nov 4, 2026

Copy link
Copy Markdown

relax.median currently legalizes its sort to a CPU packed function even for GPU targets. A simple median therefore reaches CUDA code generation with tirx.call_packed in a device kernel and fails to compile.

Dispatch GPU median with a known input shape to the existing GPU argsort implementation, then select the lower middle value and, for an axis reduction, its original index. Global reductions retain the requested keepdims shape. The CPU and target-less paths remain unchanged; the new dispatch covers the existing global and single-axis cases.

Fixes #20673.

Testing

  • Reproduced the unresolved packed-call error on the original CUDA path; the change compiles global and single-axis median.
  • GH200 and B300: 9 GPU regression cases passed on each device, covering values, indices, scalar inputs, FP16, integer inputs, global and axis reductions, and symbolic row counts. The B300 test used a local CUDA header-layout view so NVRTC could find the toolkit's CCCL headers.
  • NVPTX (sm_80): global and single-axis cases compiled; no NVPTX runtime test was run.
  • Median and existing sort/scan dispatch tests with GPU visibility disabled: 34 passed, 28 skipped, 1 xpassed.
  • Applicable changed-file pre-commit checks, including ASF headers and Ruff, passed; unrelated language-specific hooks were skipped.

@0z5a
0z5a marked this pull request as ready for review November 5, 2026 21:55

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant