Skip to content

[Refactor 2/9] CustomFusedKernel for topk, grouped_mm and fused SDPA; NPUDeviceInterface and registration.py - #450

Merged
student-Jungmin merged 1 commit into
pytorchsim-triton-backendfrom
refactor/r441-2-fused-kernel
Oct 24, 2026
Merged

student-Jungmin merged 1 commit into
pytorchsim-triton-backendfrom
refactor/r441-2-fused-kernel

Conversation

@student-Jungmin

@student-Jungmin student-Jungmin commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

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

  • The fused kernels run the same kernels with the same plans.
  • The core count is read from the machine file: an unread machine file is refused instead of a silent 1.

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.

@student-Jungmin
student-Jungmin force-pushed the refactor/r441-2-fused-kernel branch from 5a0ddaa to 9cf0ed6 Compare October 24, 2026 07:32
@student-Jungmin student-Jungmin changed the title [Refactor 2/8] CustomFusedKernel: one form for topk, grouped_mm and fused SDPA [Refactor 2/5] CustomFusedKernel for topk, grouped_mm and fused SDPA; NPUDeviceInterface and registration.py Oct 24, 2026
@student-Jungmin
student-Jungmin force-pushed the refactor/r441-2-fused-kernel branch from 9cf0ed6 to 1deaa3a Compare October 24, 2026 08:17
…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
student-Jungmin force-pushed the refactor/r441-2-fused-kernel branch from 1deaa3a to 8fbacef Compare October 24, 2026 11:15
@student-Jungmin student-Jungmin changed the title [Refactor 2/5] CustomFusedKernel for topk, grouped_mm and fused SDPA; NPUDeviceInterface and registration.py [Refactor 2/6] CustomFusedKernel for topk, grouped_mm and fused SDPA; NPUDeviceInterface and registration.py Oct 24, 2026
@student-Jungmin student-Jungmin changed the title [Refactor 2/6] CustomFusedKernel for topk, grouped_mm and fused SDPA; NPUDeviceInterface and registration.py [Refactor 2/7] CustomFusedKernel for topk, grouped_mm and fused SDPA; NPUDeviceInterface and registration.py Oct 24, 2026
@student-Jungmin student-Jungmin changed the title [Refactor 2/7] CustomFusedKernel for topk, grouped_mm and fused SDPA; NPUDeviceInterface and registration.py [Refactor 2/8] CustomFusedKernel for topk, grouped_mm and fused SDPA; NPUDeviceInterface and registration.py Oct 24, 2026
@student-Jungmin student-Jungmin changed the title [Refactor 2/8] CustomFusedKernel for topk, grouped_mm and fused SDPA; NPUDeviceInterface and registration.py [Refactor 2/9] CustomFusedKernel for topk, grouped_mm and fused SDPA; NPUDeviceInterface and registration.py Oct 24, 2026
@student-Jungmin
student-Jungmin marked this pull request as ready for review October 24, 2026 14:00
@student-Jungmin
student-Jungmin changed the base branch from refactor/r441-1-layout to pytorchsim-triton-backend October 24, 2026 14:00
@student-Jungmin
student-Jungmin merged commit a792a75 into pytorchsim-triton-backend Oct 24, 2026
@YWHyuk
YWHyuk deleted the refactor/r441-2-fused-kernel branch October 27, 2026 07:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant