Repository navigation
[Refactor 2/9] CustomFusedKernel for topk, grouped_mm and fused SDPA; NPUDeviceInterface and registration.py - #450
Merged
student-Jungmin merged 1 commit intoOct 24, 2026
Conversation
student-Jungmin
force-pushed
the
refactor/r441-2-fused-kernel
branch
from
October 24, 2026 07:32
5a0ddaa to
9cf0ed6
Compare
student-Jungmin
force-pushed
the
refactor/r441-1-layout
branch
from
October 24, 2026 07:32
ca1ed67 to
fb09d09
Compare
student-Jungmin
force-pushed
the
refactor/r441-1-layout
branch
from
October 24, 2026 08:17
fb09d09 to
2113c7b
Compare
student-Jungmin
force-pushed
the
refactor/r441-2-fused-kernel
branch
from
October 24, 2026 08:17
9cf0ed6 to
1deaa3a
Compare
…eviceInterface and registration.py topk, grouped_mm (GroupedMM, taking aten._grouped_mm and transformers' grouped_mm_fallback) and attention (FusedSDPA) are CustomFusedKernel subclasses in custom_fused_kernel.py, which also holds the scratchpad budget every plan is held to. A subclass states the ops it takes, kernels(), plan() (blocks, or a Decline that leaves the op to its aten fallback()), launch() and, for SDPA, outputs(); ops and kernels are named by the objects, and each route counts under calls. The same kernels run with the same plans. docs/fused_kernel.md and .ko.md say how to add one. NPUDeviceInterface reports the machine's vector lanes as the SM count and only what Inductor reads; the core count is read from the machine file, and an unread machine file is refused instead of a silent 1. tiling.py is frontend/tiling.py, read by Inductor and the dispatcher. A kernel's blocks are computed in one place, blocks_for, with no silent fallback; template_grid lives in kernel_metadata, its only reader. registration.py holds everything npu registers, one section per registry, and patches only what has no hook. Driver and openreg leftovers go. Comments and docstrings in the files this part changes are at most three lines, none inside a function body.
student-Jungmin
force-pushed
the
refactor/r441-2-fused-kernel
branch
from
October 24, 2026 11:15
1deaa3a to
8fbacef
Compare
student-Jungmin
force-pushed
the
refactor/r441-1-layout
branch
from
October 24, 2026 11:16
2113c7b to
75aab75
Compare
student-Jungmin
marked this pull request as ready for review
October 24, 2026 14:00
student-Jungmin
changed the base branch from
refactor/r441-1-layout
to
pytorchsim-triton-backend
October 24, 2026 14:00
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 2 of 9 of the frontend refactor. It is one commit (9cf0ed6) of this part's final state, so each part reviews on its own. Stacked on #449 (
refactor/r441-1-layout); review only this PR's commit.This PR absorbs #451.
What
topk, grouped_mm (GroupedMM, taking aten._grouped_mm and transformers' grouped_mm_fallback) and
attention (FusedSDPA) are CustomFusedKernel subclasses in custom_fused_kernel.py, which also holds
the scratchpad budget every plan is held to. A subclass states the ops it takes, kernels(), plan()
(blocks, or a Decline that leaves the op to its aten fallback()), launch() and, for SDPA,
outputs(); ops and kernels are named by the objects, and each route counts under calls. The same
kernels run with the same plans. docs/fused_kernel.md and .ko.md say how to add one.
NPUDeviceInterface reports the machine's vector lanes as the SM count and only what Inductor
reads; the core count is read from the machine file, and an unread machine file is refused
instead of a silent 1. tiling.py is frontend/tiling.py, read by Inductor and the dispatcher. A
kernel's blocks are computed in one place, blocks_for, with no silent fallback; template_grid
lives in kernel_metadata, its only reader. registration.py holds everything npu registers, one
section per registry, and patches only what has no hook. Driver and openreg leftovers go.
Behavior change
Checked locally
At this PR's tip, with PTB 522042a (this branch's pin) and TOGSim b9c9519, everything passes: test_add 5/5, test_matmul 11/11, test_histc, test_eager, test_patch_scope 8/8, test_custom_fused_kernel, test_topk.
No cycle numbers here: nothing in this part is meant to change a kernel's cycles. The CI validation report is the check.
Comments and docstrings in the files these parts change are at most three lines, none inside a function body. What they no longer say is in the commit message. Test files whose only change here is an import rename (test_result -> check_result) and scripts/ keep their comments, as this change did not touch that code.