Repository navigation
[Simulator] The launcher records runtime attributes and hands them to TOGSim (kernel object format 7) - #418
Merged
Conversation
This was referenced Oct 23, 2026
YWHyuk
force-pushed
the
runtime-attribute
branch
2 times, most recently
from
October 23, 2026 09:55
862feac to
52e3500
Compare
YWHyuk
marked this pull request as ready for review
October 23, 2026 09:55
YWHyuk
force-pushed
the
runtime-attribute
branch
from
October 23, 2026 10:01
52e3500 to
3460d9d
Compare
…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
force-pushed
the
runtime-attribute
branch
from
October 23, 2026 12:38
3460d9d to
108796b
Compare
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.
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.
Rebased on pytorchsim-triton-backend
8f3afd9d(#434 and #437 merged); the compiler pin is PTB main1b1e060, now the base's own1bf23359, so this PR no longer moves the pin. Since #434,functional.launchcalls the compiler's Spike launcher (pytorchsim_triton_compiler.runtime.spike) instead of keeping a copy, and that launcher at1b1e060already handles the runtime attributes (start_hidden,merge_hidden,record_attributes, worker redirects of the hidden output, noindirect_access). So this PR's own copy of that logic was dropped in the rebase; what stays in PyTorchSim is the replay cache ofruntime/runtime_attribute/,--attribute_pathto TOGSim, the scalars inshape_args, the bundle's attribute sources, the removal ofdata_valuesand thetogsim_version()rename. Checked on108796b0intopk-pts:24ce740-llc92028c8with a compiler tree identical to PTB1b1e060: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.pyandtest_embedding(1024, 2048)pass, each launch leavingruntime/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.
contract.KERNEL_FORMATis 7; a kernel object of another format is refused by name.runtime_attributes.raw, which the ELF writes; the compiler's launcher passes it tomain()after the tensor paths, splits it over workers and writesruntime/runtime_attribute/(programs.bin,attr_<key>_<id>.bin), the directory TOGSim reads.functional.launchcalls that launcher (Call the compiler package's Spike launcher instead of a copy #434), so none of this is reimplemented here.runtime/runtime_attribute/with the outputs; a saved run without it is a miss.--attribute_path.run_togsimpasses that directory to TOGSim (theLAUNCH_KERNELtoken,--attribute_pathfor a standalone run) and refuses, by name, a kernel that declares attributes when no functional run left them. An openTOGSimulatorgets a per-launch copy, since the next functional run of the kernel rewrites the original.shape_args.tog_shape.txtholds the grid extents, then the kernel's integer scalars in the compiler's order (kernel_object.shape_args), valued from the call's arguments bycall_params, else the manifest's defaults.c67f8c4f(a row per dumpgem5_samples.readreturns, its overlap that of the tile the dump names); this PR's equivalent2f2a62c6was dropped in the rebase.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_argstoshape_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 writesdata_args. Runtime attributes replace it, sodata_valuesis removed andshape_argsis the grid, then the integer scalars. The grouped_mm frontend andtests/ops/gemm/test_grouped_mm.pystay.togsim_version(). The base's cache identity (5f74a762) asks the compiler fortoolchain.togsim_api_version(), which PTB [TOGSim] ONNXim frontend and ACS for tutorial #315 replaced withtogsim_version(); against [TOGSim] ONNXim frontend and ACS for tutorial #315 every launch stopped instore_identity. The probe andtest_cache_identity.pynow asktogsim_version(). The pin now names PTB main1b1e060, which has [TOGSim] ONNXim frontend and ACS for tutorial #315.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
shape_args,argv_hidden).indirect_index_<key>_<n>.raw.All three are merged, and the base already pins PTB main
1b1e060(TOGSimb9c9519, vcix-accelerator3a99217) since #437.Tested
Earlier check, before the rebase on #434:
nn.Embedding(1024, 64)on a[128]int index plustests/ops/misc/test_indirect_access.py::test_indirect_vectoradd, withTORCHSIM_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 reportTest Passed. Each launch leftruntime/runtime_attribute/(programs.bin,attr_0_0.bin) and TOGSim was invoked with--attribute_pathto it (Total_cycle 1927 and 2105).tog_shape.txtcarried the integer scalar after the grid. Noindirect_accessdirectory exists anywhere in the dump.The image used is a local one (
topk-pts:24ce740with thellcthat honours+spad-vector-memory), because the PTB branch's toolchain check refuses the olderllc.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.pyrecords exactly those args' launch values (through the newobserve_every_launch_inputshook andfunctional.flat_input) and writes the kernel file again, somake_inputsloads them from<kernel>_inputs.ptbeside 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 bytests/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