Repository navigation
[Refactor 9/9] aten.sort on the npu as Sort, a CustomFusedKernel - #460
Merged
Merged
Conversation
student-Jungmin
force-pushed
the
refactor/r441-8-sort
branch
from
October 24, 2026 12:15
9065428 to
24a5ce1
Compare
student-Jungmin
changed the base branch from
refactor/r441-7-simulator
to
refactor/r441-7b-togsim-result
October 24, 2026 12:16
student-Jungmin
force-pushed
the
refactor/r441-8-sort
branch
from
October 24, 2026 12:51
24a5ce1 to
f818389
Compare
student-Jungmin
changed the base branch from
refactor/r441-7b-togsim-result
to
refactor/r441-7c-cleanup
October 24, 2026 12:52
…onic network per row through tl.gather #447's sort (aten.sort.stable and aten.sort, torchsim::sort) in the dispatcher's one form. A program sorts one row of the last axis as an [L, D] tile, padded to a power of two n, on L = min(lanes, n) lanes; the key is one int64 (a float's bits made ordered, NaN last, -0 as +0, flipped when descending) carried as two int32 words with the int32 index, so every sort is stable. Keys int32, int64 and float32. plan declines another dtype, another axis, an empty or 0-d input and a row past the scratchpad budget; a gradient declines as every CustomFusedKernel's does; the fallback runs the same network in aten ops. The compiler pin moves 70221f4 -> 2abb4a3, PSAL-POSTECH/PyTorchSim-Triton-Backend main with #335 (tt.gather lowered), which this kernel needs; TOGSim stays 5791272. On that pin test_sort passes 24/24 in functional and in timing mode, and test_topk, test_add, test_matmul, test_grouped_mm, test_custom_fused_kernel, test_eager, test_patch_scope, test_togsim_result and test_cache_identity pass. test_conv_decomposition's depthwise_grad still fails at lower ("index tile ... no one entry per position of its gather") until PSAL-POSTECH/PyTorchSim-Triton-Backend#351. #447's measurements (sim/v6e 1.13-1.15 at T 128-512 on PTB #335) are in that PR.
student-Jungmin
force-pushed
the
refactor/r441-8-sort
branch
from
October 24, 2026 13:18
f818389 to
ae8419d
Compare
student-Jungmin
changed the base branch from
refactor/r441-7c-cleanup
to
refactor/r441-7d-spad-budget
October 24, 2026 13:19
student-Jungmin
marked this pull request as ready for review
October 24, 2026 14:01
student-Jungmin
changed the base branch from
refactor/r441-7d-spad-budget
to
pytorchsim-triton-backend
October 24, 2026 14:01
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.
Draft: waiting for verification (CI and the validation reports) before review.
Part 9 of 9 of the frontend refactor. It is one commit of this part's final state. Stacked on #463 (
refactor/r441-7d-spad-budget); review only this PR's commit.What
#447's sort, moved into the dispatcher's one form:
pytorchsim/frontend/dispatcher/sort.py,Sort(CustomFusedKernel). It takesaten.sort.stableandaten.sort, astorchsim::sort.tl.gatherreads, as v6e sorts. A program sorts one row of the last axis as an[L, D]tile, padded to a power of twon, onL = min(lanes, n)lanes. The key is one int64 (a float's bits made ordered, NaN last, -0 as +0, flipped when descending), carried as two int32 words with the int32 index, so every sort is stable. Keys: int32, int64, float32.Pin
The compiler pin moves 70221f4 -> 2abb4a3, PSAL-POSTECH/PyTorchSim-Triton-Backend main with #335 (the
tl.gatherlowering this kernel needs). TOGSim stays 5791272, vcix d2d9b27.Checked locally (PTB 2abb4a3, this branch's pin)
test_sort24/24 in functional mode and in timing mode; the sort kernel compiles and runs, and only the non-last-axis cases decline, as intended.test_topk,test_add5/5,test_matmul11/11,test_grouped_mm6/6,test_custom_fused_kernel,test_eager,test_patch_scope8/8,test_togsim_result,test_cache_identityandtest_select(timing mode) pass.test_conv_decomposition6/7.depthwise_gradstops at lower ("index tile ... no one entry per position of its gather") until fit-transfers folds a gather's tile-shaped index buffer with its data tile PyTorchSim-Triton-Backend#351; the pin moves again once it merges.#447's measurements on PTB #335 (sort sim/v6e 1.13-1.15 at T 128-512; 1.97 at T 1024, register pressure) are in #447, which this replaces.