Repository navigation
[Refactor 4/9] autotune/ by kind of kernel, blocks pinned in triton_kernel_kwargs; codegen split as Inductor's files are - #453
Merged
student-Jungmin merged 1 commit intoOct 24, 2026
Conversation
student-Jungmin
force-pushed
the
refactor/r441-4-postgrad-patterns
branch
from
October 24, 2026 07:32
13f1c47 to
7cd3f48
Compare
student-Jungmin
force-pushed
the
refactor/r441-5-autotune
branch
from
October 24, 2026 07:32
46740ca to
291f563
Compare
student-Jungmin
force-pushed
the
refactor/r441-4-postgrad-patterns
branch
from
October 24, 2026 08:17
7cd3f48 to
d427f57
Compare
student-Jungmin
force-pushed
the
refactor/r441-5-autotune
branch
from
October 24, 2026 08:17
291f563 to
8ca3b66
Compare
…rnel_kwargs; codegen split as Inductor's files are frontend/inductor/autotune/ is template_kernel_configs (the configs mm, bmm and conv templates are offered), template_kernel_selection (which config a template takes) and generated_kernel_blocks (the blocks of every other kernel, and its reductions' persistence and split). In backend/, select is template_timing and autotune is retile. NPUChoices and the mm heuristics register with the rest. Generated kernels' blocks are pinned through Inductor's triton_kernel_kwargs hook instead of a constructor override; combo_kernels is set False, as Inductor's default is, since combo kernels skip that hook. The same kernels get the same names and blocks before and after. codegen/scheduling.py is scheduling, wrapper and user_kernel. One torchsim_compile line, kernel_metadata.compile_call, serves Inductor's kernels and a model's own; one dtype table, kernel_metadata.TOKEN_DTYPE, with bits from torch. codegen logs its fallbacks (an unknown storage span, an untimed fusion), and the wrapper sets its user-kernel bookkeeping in __init__. registration.py lists its registries in its docstring, one section each, and post_grad_pass its rewrites; test_module_form keeps both in that form. Comments and docstrings in the files this part changes are at most three lines, none inside a function body. What they no longer say: codegen/wrapper.py: Inductor's cache keys a user kernel's name by triton_meta alone; the 0-d rendering is decided for the kernel's device because the line is rendered after the CPU island's. frontend/tiling.py: a persistent reduction rendered for a bigger scratchpad than the target has is refused by the compiler as over budget, whatever XBLOCK shrinks to; a block wider than its numel strands the mask's rank-1 index rows ONE_LANE against banked data, and a numel of 1 under a lane-wide block is a tile of digits whose mask the DMA cannot state; the lane axis is the compiler's select_lane_axis, passes later; a one-lane-wide pointwise block runs a program per lanes elements and the fixed cost outweighs the data; the compiler lays a reduction's axis across the lanes when its rows fill fewer lanes, whatever it combines by (PTB TorchsimAnchorLayouts.cpp anchorReduce); padding on r is not counted since the reduce stops at its mask, and XBLOCK = lanes gives the earlier R0_BLOCK. tests/system/test_patch_scope.py: test_device_predicate_reads_every_spelling -- the upstream operand is sampled.
student-Jungmin
force-pushed
the
refactor/r441-5-autotune
branch
from
October 24, 2026 11:15
8ca3b66 to
f7a0cf3
Compare
student-Jungmin
force-pushed
the
refactor/r441-4-postgrad-patterns
branch
from
October 24, 2026 11:16
d427f57 to
9a4db9d
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-4-postgrad-patterns
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 4 of 9 of the frontend refactor. It is one commit (291f563) of this part's final state, so each part reviews on its own. Stacked on #452 (
refactor/r441-4-postgrad-patterns); review only this PR's commit.This PR absorbs #454.
What
frontend/inductor/autotune/ is template_kernel_configs (the configs mm, bmm and conv templates
are offered), template_kernel_selection (which config a template takes) and
generated_kernel_blocks (the blocks of every other kernel, and its reductions' persistence and
split). In backend/, select is template_timing and autotune is retile. NPUChoices and the mm
heuristics register with the rest. Generated kernels' blocks are pinned through Inductor's
triton_kernel_kwargs hook instead of a constructor override; combo_kernels is set False, as
Inductor's default is, since combo kernels skip that hook. The same kernels get the same names
and blocks before and after.
codegen/scheduling.py is scheduling, wrapper and user_kernel. One torchsim_compile line,
kernel_metadata.compile_call, serves Inductor's kernels and a model's own; one dtype table,
kernel_metadata.TOKEN_DTYPE, with bits from torch. codegen logs its fallbacks (an unknown storage
span, an untimed fusion), and the wrapper sets its user-kernel bookkeeping in init.
registration.py lists its registries in its docstring, one section each, and post_grad_pass its
rewrites; test_module_form keeps both in that form.
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, test_conv_transpose 5/5, test_zero_length_gemm 7/7, test_module_form.
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.