Skip to content

[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 into
pytorchsim-triton-backendfrom
refactor/r441-5-autotune
Oct 24, 2026
Merged

student-Jungmin merged 1 commit into
pytorchsim-triton-backendfrom
refactor/r441-5-autotune

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 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

  • The same kernels get the same names and blocks; combo_kernels=False is Inductor's default.
  • codegen logs its fallbacks: an unknown storage span, an untimed fusion.

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.

@student-Jungmin
student-Jungmin force-pushed the refactor/r441-4-postgrad-patterns branch from 13f1c47 to 7cd3f48 Compare October 24, 2026 07:32
@student-Jungmin
student-Jungmin force-pushed the refactor/r441-5-autotune branch from 46740ca to 291f563 Compare October 24, 2026 07:32
@student-Jungmin student-Jungmin changed the title [Refactor 5/8] autotune/ by kind of kernel; blocks pinned in triton_kernel_kwargs [Refactor 4/5] autotune/ by kind of kernel, blocks pinned in triton_kernel_kwargs; codegen split as Inductor's files are Oct 24, 2026
@student-Jungmin
student-Jungmin force-pushed the refactor/r441-4-postgrad-patterns branch from 7cd3f48 to d427f57 Compare October 24, 2026 08:17
@student-Jungmin
student-Jungmin force-pushed the refactor/r441-5-autotune branch from 291f563 to 8ca3b66 Compare October 24, 2026 08:17
…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
student-Jungmin force-pushed the refactor/r441-5-autotune branch from 8ca3b66 to f7a0cf3 Compare October 24, 2026 11:15
@student-Jungmin
student-Jungmin force-pushed the refactor/r441-4-postgrad-patterns branch from d427f57 to 9a4db9d Compare October 24, 2026 11:16
@student-Jungmin student-Jungmin changed the title [Refactor 4/5] autotune/ by kind of kernel, blocks pinned in triton_kernel_kwargs; codegen split as Inductor's files are [Refactor 4/6] autotune/ by kind of kernel, blocks pinned in triton_kernel_kwargs; codegen split as Inductor's files are Oct 24, 2026
@student-Jungmin student-Jungmin changed the title [Refactor 4/6] autotune/ by kind of kernel, blocks pinned in triton_kernel_kwargs; codegen split as Inductor's files are [Refactor 4/7] autotune/ by kind of kernel, blocks pinned in triton_kernel_kwargs; codegen split as Inductor's files are Oct 24, 2026
@student-Jungmin student-Jungmin changed the title [Refactor 4/7] autotune/ by kind of kernel, blocks pinned in triton_kernel_kwargs; codegen split as Inductor's files are [Refactor 4/8] autotune/ by kind of kernel, blocks pinned in triton_kernel_kwargs; codegen split as Inductor's files are Oct 24, 2026
@student-Jungmin student-Jungmin changed the title [Refactor 4/8] autotune/ by kind of kernel, blocks pinned in triton_kernel_kwargs; codegen split as Inductor's files are [Refactor 4/9] autotune/ by kind of kernel, blocks pinned in triton_kernel_kwargs; codegen split as Inductor's files are 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-4-postgrad-patterns to pytorchsim-triton-backend October 24, 2026 14:00
@student-Jungmin
student-Jungmin merged commit 069388a into pytorchsim-triton-backend Oct 24, 2026
@YWHyuk
YWHyuk deleted the refactor/r441-5-autotune branch October 27, 2026 07:47
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