Skip to content

[Simulator] The launcher records runtime attributes and hands them to TOGSim (kernel object format 7) - #418

Merged
YWHyuk merged 7 commits into
pytorchsim-triton-backendfrom
runtime-attribute
Oct 23, 2026
Merged

YWHyuk merged 7 commits into
pytorchsim-triton-backendfrom
runtime-attribute

Conversation

@YWHyuk

@YWHyuk YWHyuk commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Rebased on pytorchsim-triton-backend 8f3afd9d (#434 and #437 merged); the compiler pin is PTB main 1b1e060, now the base's own 1bf23359, so this PR no longer moves the pin. Since #434, functional.launch calls the compiler's Spike launcher (pytorchsim_triton_compiler.runtime.spike) instead of keeping a copy, and that launcher at 1b1e060 already handles the runtime attributes (start_hidden, merge_hidden, record_attributes, worker redirects of the hidden output, no indirect_access). So this PR's own copy of that logic was dropped in the rebase; what stays in PyTorchSim is the replay cache of runtime/runtime_attribute/, --attribute_path to TOGSim, the scalars in shape_args, the bundle's attribute sources, the removal of data_values and the togsim_version() rename. Checked on 108796b0 in topk-pts:24ce740-llc92028c8 with a compiler tree identical to PTB 1b1e060: tests/system/test_attribute_sources.py, test_bundle_reuse.py, test_cache_identity.py, tests/ops/gemm/test_grouped_mm.py (timing mode, 255 s), tests/ops/misc/test_indirect_access.py and test_embedding(1024, 2048) pass, each launch leaving runtime/runtime_attribute/ records.

What changes

The launcher follows the compiler's runtime-attribute contract: what a TOG reads from data (a DMA offset, a loop bound, a gather's index tile) is recorded by the functional run and handed to TOGSim, instead of being re-derived from index dumps.

  • Kernel object format 7. contract.KERNEL_FORMAT is 7; a kernel object of another format is refused by name.
  • Hidden output and runtime attribute files (compiler side). The compiler's kernel object names a hidden output, runtime_attributes.raw, which the ELF writes; the compiler's launcher passes it to main() after the tensor paths, splits it over workers and writes runtime/runtime_attribute/ (programs.bin, attr_<key>_<id>.bin), the directory TOGSim reads. functional.launch calls that launcher (Call the compiler package's Spike launcher instead of a copy #434), so none of this is reimplemented here.
  • Replay cache. The replay cache saves and restores runtime/runtime_attribute/ with the outputs; a saved run without it is a miss.
  • --attribute_path. run_togsim passes that directory to TOGSim (the LAUNCH_KERNEL token, --attribute_path for a standalone run) and refuses, by name, a kernel that declares attributes when no functional run left them. An open TOGSimulator gets a per-launch copy, since the next functional run of the kernel rewrites the original.
  • Scalar args in shape_args. tog_shape.txt holds the grid extents, then the kernel's integer scalars in the compiler's order (kernel_object.shape_args), valued from the call's arguments by call_params, else the manifest's defaults.
  • gem5 table per (tile, call). Now the base's own c67f8c4f (a row per dump gem5_samples.read returns, its overlap that of the tile the dump names); this PR's equivalent 2f2a62c6 was dropped in the rebase.
  • No data_values. [Frontend] aten._grouped_mm on the npu is one Triton kernel whose blocks read their expert from launch data #412 (a5d1fbde) appended tile_types' data_args to shape_args, the launcher half of the rejected, closed PTB Indirect access: make offset an explicit togsim.transfer operand (blocked by memref.dma_start; needs direct togsim.transfer -> gemmini lowering) #282 (torchsim.data); no PTB commit writes data_args. Runtime attributes replace it, so data_values is removed and shape_args is the grid, then the integer scalars. The grouped_mm frontend and tests/ops/gemm/test_grouped_mm.py stay.
  • TOGSim identity from togsim_version(). The base's cache identity (5f74a762) asks the compiler for toolchain.togsim_api_version(), which PTB [TOGSim] ONNXim frontend and ACS for tutorial #315 replaced with togsim_version(); against [TOGSim] ONNXim frontend and ACS for tutorial #315 every launch stopped in store_identity. The probe and test_cache_identity.py now ask togsim_version(). The pin now names PTB main 1b1e060, which has [TOGSim] ONNXim frontend and ACS for tutorial #315.
  • No runtime/indirect_access/. Nothing creates, gathers or clears index dumps (the compiler's launcher has none). Indirect DMAs take their offsets from the runtime attributes.

Dependencies

All three are merged, and the base already pins PTB main 1b1e060 (TOGSim b9c9519, vcix-accelerator 3a99217) since #437.

Tested

Earlier check, before the rebase on #434: nn.Embedding(1024, 64) on a [128] int index plus tests/ops/misc/test_indirect_access.py::test_indirect_vectoradd, with TORCHSIM_TRITON_CODEGEN=1, functional and timing on, over the PTB #315 branch (e736714) and the TOGSim #57 branch at 7de8950 (before its version unification to 1.0.0): both report Test Passed. Each launch left runtime/runtime_attribute/ (programs.bin, attr_0_0.bin) and TOGSim was invoked with --attribute_path to it (Total_cycle 1927 and 2105). tog_shape.txt carried the integer scalar after the grid. No indirect_access directory exists anywhere in the dump.

The image used is a local one (topk-pts:24ce740 with the llc that honours +spad-vector-memory), because the PTB branch's toolchain check refuses the older llc.

Bundle keeps the launch values of runtime-attribute sources (6bcd511, 70b17aa)

The bundle's kernel files drew every input with torch.randn, so the grouped GEMM's group/start/rows tables were random and a Spike run in the compiler's CI recorded a different routing from the model's. The compiler's manifest now names, for each runtime attribute, the args its value is read from (PTB e434dd2). scripts/ci/bundle.py records exactly those args' launch values (through the new observe_every_launch_inputs hook and functional.flat_input) and writes the kernel file again, so make_inputs loads them from <kernel>_inputs.pt beside it. Every other input is still drawn, so weights are not stored. If a launch has no manifest, an attribute names no sources, a source is not an arg, or the same kernel is launched again on different source values, the bundle stops and says which one; nothing named is drawn. Pinned by tests/system/test_attribute_sources.py, which is also added to the workflow matrix. On a T=1 bundle the gmm tables come out real (grp 0..7, start 0..7, rows 1), and the compiler's CI then times gmm_down / gmm_gate_up at sim/v6e 0.897 / 0.947, the same as the direct run.

🤖 Generated with Claude Code

https://claude.ai/code/session_011cGNfHFySFsi7feZKKvq7e

…ernel object format 7

The compiler's kernel object 7 (PTB #298) names a hidden output, runtime_attributes.raw, in which the
ELF records what a TOG reads from data: a DMA offset, a loop bound, a gather's index tile. Handing it
to main(), splitting it over workers and turning it into runtime/runtime_attribute/ (programs.bin and
attr_<key>_<id>.bin) is the compiler's launcher (runtime/spike.py: start_hidden, merge_hidden,
record_attributes), which functional.launch calls since #434. What stays here is PyTorchSim's: the
replay cache saves and restores that directory with the outputs, and a saved run without it is a miss.

Refs PSAL-POSTECH/PyTorchSim-Triton-Backend#298
run_togsim handed TOGSim <launch>/attribute, a path nothing wrote, which TOGSim did not read; it now
reads attribute_path (LAUNCH_KERNEL's token, --attribute_path standalone) and refuses a TOG that
declares attributes without the records. The path is the functional run's runtime/runtime_attribute/,
refused by name when the kernel declares attributes and no functional run left it; an open
TOGSimulator gets a copy only that launch names, since it takes the launch after the next functional
run of the kernel has rewritten the original. run_standalone passes --attribute_path.

Refs PSAL-POSTECH/PyTorchSim-Triton-Backend#298
…me attributes replace them

a5d1fbd (#412) appended the elements of every argument tile_types.json lists as data_args to the
launch's shape_args (timing.data_values), so the TOG could read the grouped GEMM's group, start and
row tables from the launch. That is the compiler side of PTB #282 (torchsim.data), which was
rejected and is closed; no compiler the pin can reach writes data_args. PTB #315's runtime
attributes replace it: the functional run records each value the TOG reads from data under
runtime/runtime_attribute/, and TOGSim reads those records (the commit before this one), so the
values never travel through shape_args.

data_values and _write_extents' data argument are removed and shape_args is the grid again, as
before #412. The grouped_mm frontend, its registration and tests/ops/gemm/test_grouped_mm.py stay;
the frontend's docstring now says the TOG reads the table as runtime attributes.
…the grid

The compiler's TOG now reads every integer scalar parameter from shape_args after the grid extents
(kernel_object.shape_args). write_shape writes that list: the grid it computes, then the scalars
valued by the call's arguments (call_params), else the manifest's defaults, through the compiler's
own kernel_object so the order has one definition. The grid-count check against tog_axes.txt is
unchanged.
…he value its .raw file holds

observe_every_launch_inputs(callback) calls callback(launcher, args) before each launch runs, so a
caller can keep what the kernel reads; functional.flat_input(arg, tensor) is the numel-long CPU
tensor write_inputs writes as runtime/<arg>.raw, each element where the launch's strides put it,
now one function that both use.
…e attributes are read from

A bundle kernel file drew every input with torch.randn, so the grouped GEMM's group, start and row
tables were random and its Spike run recorded another routing than the model's. The compiler's
manifest now names, per runtime attribute, the args its value is read from (PTB e434dd2);
contract.attribute_sources reads them. bundle.py records those args' launch values at each launch
(flat_input) and writes the kernel file again with compiler_input.write(recorded=...), which saves
them as <kernel>_inputs.pt beside it; its make_inputs takes exactly those from there and draws every
other input, so weights are not stored. A launch with no kernel.json, an attribute with no sources,
a source that is no arg, or a second launch of a kernel on other source values stops the bundle by
name; nothing named is drawn.

Pin tests/system/test_attribute_sources.py: on 78ece9f "write() got an unexpected keyword argument
'recorded'".
…r reads from togsim_runtime.h

5f74a76 asks the compiler for toolchain.togsim_api_version(), the API_VERSION regex over
togsim.hpp. PTB #315 (e737897) replaced it with toolchain.togsim_version(): TOGSim has one
version, 1.0.0, which the compiler reads by compiling and running a program that prints
TOGSIM_VERSION_STRING and TOGSIM_VERSION. Against that compiler every launch stopped at
store_identity: "module 'pytorchsim_triton_compiler.toolchain' has no attribute
'togsim_api_version'" (tests/system/test_bundle_reuse.py, tests/ops/gemm/test_grouped_mm.py).
The probe and tests/system/test_cache_identity.py now ask togsim_version(); the headers digest
is unchanged. Against PTB main, which still has only togsim_api_version, this needs the pin
bump that follows #315.
@YWHyuk
YWHyuk force-pushed the runtime-attribute branch from 3460d9d to 108796b Compare October 23, 2026 12:38
@YWHyuk
YWHyuk merged commit 3d73635 into pytorchsim-triton-backend Oct 23, 2026
student-Jungmin added a commit that referenced this pull request Oct 24, 2026
…, so kernels reading runtime attributes time

The bundle job builds layer and qwen3_8b with TORCHSIM_TIMING_MODE=1 inside a container started with
TORCHSIM_FUNCTIONAL_MODE=0. Since the kernel object streams runtime attributes as record files (#418,
#443), a kernel that reads them (the grouped GEMM's block tables, RoPE's, a gather's) is timed only on
the records its functional run leaves, and timing.attribute_dir refuses the launch otherwise
("runtime_attribute not found ... run with TORCHSIM_FUNCTIONAL_MODE=1"); without Spike the rows would
also collapse to one address. The job has not left a bundle since e27b64a (2026-10-22). Locally, the
layer suite built that way left 47 of 96 workloads, the 49 others each refused so.

That run is now functional and timed; gemm (no attributes) and vector/attention (untimed) stay as they
were. The job's timeout goes 240 -> 360 min, as every layer and qwen3_8b kernel now also runs on Spike.

This commit and the pin move before it go in together: on the old pin the dispatch's sort (T = 2048,
4096) is refused at lower, which stops the layer suite the same way.
@YWHyuk
YWHyuk deleted the runtime-attribute branch October 26, 2026 05:43
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