Repository navigation
[GEMM Timing Validation][Frontend] An npu mm the compiler's copy_node.plan holds runs the resident mm, as v6e XLA runs it - #457
Merged
Conversation
student-Jungmin
force-pushed
the
gemm-copy-node
branch
from
October 24, 2026 08:38
c51c983 to
bdbbc9e
Compare
…ident mm, as v6e XLA runs it v6e XLA runs a GEMM in two steps: a cross-program prefetch copies one operand whole into VMEM (the larger one that fits, the smaller when the larger is the whole VMEM, none for a vector product), then the fusion walks the output tiles streaming the other operand, K whole. The resident mm template (pytorchsim/frontend/inductor/autotune/mm_resident.py) is that program: one program loads the held operand whole, then walks the output tiles two at a time into two buffers, each stored through store_output so an epilogue fuses per tile. Which operand and what tile is the compiler's copy_node.plan (one statement of it, read here); the compiler emits that load as the kernel's copy node and its TOG reads the operand held. Where the plan holds an operand the template is offered alone (it would never win a race on TOGSim cycles against the K-split mm template, the exposed copy being the point), its one config annotated tile_source "planned"; every other mm (declined by the plan, another dtype or out_dtype, another device) keeps the mm template, the reason logged. This changes the default mm path for those shapes. NPUChoices (registration.py) narrows the offer and marks the config template_record.PLANNED; its heuristic is in template_kernel_configs.py. timing.simulate_standalone runs a kernel object's copy nodes before the kernel (also in a session) and reports the sum, the parts beside it (kernel_cycles, copy_node_cycles); template_timing times through it. The kernel object is format 9 (copy_nodes). The compiler pin moves 2abb4a3 -> 6f88e2b, PSAL-POSTECH/PyTorchSim-Triton-Backend main with #347 (kernel format 9, contract copy_node, the copy node and the held TOG) and #351; TOGSim stays 5791272. tests/system/test_copy_node.py: the offer and its declines, the config, relu fused into the one kernel, inference_mode, eager and grad with values (functional mode), the timed copy node and the sum. tests/system/test_select.py times a bmm: an mm the plan holds is planned, and nothing of it is timed.
student-Jungmin
force-pushed
the
gemm-copy-node
branch
from
October 24, 2026 14:16
bdbbc9e to
c90517b
Compare
student-Jungmin
marked this pull request as ready for review
October 24, 2026 14:17
student-Jungmin
merged commit Oct 24, 2026
338b42d
into
pytorchsim-triton-backend
2 of 3 checks passed
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.
The front-end half of PSAL-POSTECH/PyTorchSim-Triton-Backend#347, which has the motivation. In short: v6e XLA runs a GEMM in two steps. A cross-program prefetch first copies one operand whole into VMEM, with nothing beside it. The fusion then walks the output tiles streaming the other operand, K whole.
Turning the TPU's prefetch off, looking at compute-bound GEMMs only, and forbidding the K split did not close the sim's fast gap. So the npu now builds the kernel the TPU runs.
What it does
pytorchsim/frontend/inductor/autotune/mm_resident.py: the resident mm, an Inductor TritonTemplate.store_output, so an epilogue fuses per tile, as in the mm template.Target.matmul_width.copy_node.plan. The rule lives in one place and is read here.tile_source"planned".timing.simulate_standaloneruns a kernel object's copy nodes before the kernel, also in a session, and reports the sum with the parts beside it.template_timingtimes through it, and NPUChoices (registration.py) marks the configtemplate_record.PLANNED.copy_nodes).It uses the same Inductor extension points the mm heuristic already uses: TritonTemplate, register_template_heuristic, V.choices. There is no public path that keeps epilogue fusion for a GEMM. A
triton_opwould make the kernel opaque to Inductor.Tests
tests/system/test_copy_node.py:Compiler pin
third_party/pytorchsim-triton-backend.jsonmoves 2abb4a3 -> 6f88e2b, PyTorchSim-Triton-Backend main with PSAL-POSTECH/PyTorchSim-Triton-Backend#347 merged (kernel format 9, contractcopy_node, the copy node and the held TOG) and #351. TOGSim stays 5791272.Numbers
Local, stacked with PSAL-POSTECH/PyTorchSim-Triton-Backend#347, the 106 CI gemm shapes against the v6e (prefetch on, minus the lead-in):
The full table is on #347. This PR's CI builds the bundle on the moved pin and measures it on the maintainer baseline.
Default change: every npu mm that copy_node.plan holds (M and N above 1, an operand fitting the scratchpad) now builds the resident mm instead of the timed mm template. In the gemm suite that is 97 of 110 shapes; M = 1 keeps its path.
tests/system/test_select.pynow times a bmm: an mm the plan holds is planned, and nothing of it is timed.