Skip to content

[Simulator] PyTorchSim runs the TOGSim the compiler carries, and speaks its TOG names (ABI 16) - #348

Merged
YWHyuk merged 20 commits into
pytorchsim-triton-backendfrom
togsim-dir
Oct 13, 2026
Merged

YWHyuk merged 20 commits into
pytorchsim-triton-backendfrom
togsim-dir

Conversation

@YWHyuk

@YWHyuk YWHyuk commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator

About PyTorchSim #346. #346 ("A load of what a buffer already holds is not read again") changed the in-tree TOGSim/ after TOGSim became its own repository, and the TOGSim repository does not carry it yet (PSAL-POSTECH/TOGSim#22). From this change on PyTorchSim runs the TOGSim the compiler pins, so that behaviour is absent until TOGSim carries it and the pin moves.

Branch togsim-dir (18 commits) -> pytorchsim-triton-backend at aaa3ee84 (#346 merged). Head 5ab54226.

One thing to settle before merging: #346 changed the in-tree TOGSim/ after the split, and PSAL-POSTECH/TOGSim does not have that change (see "#346"). With this PR the in-tree copy stops being run, so #346's effect is lost until TOGSim carries it.

What this is

Two things that cannot land apart.

  1. Where TOGSim is. TOGSim is its own repository, PSAL-POSTECH/TOGSim. The compiler (PyTorchSim-Triton-Backend) pins it as the submodule third_party/TOGSim, and this repository reaches it through the compiler checkout it already pins: PyTorchSim -> PyTorchSim-Triton-Backend -> TOGSim. One variable, TOGSIM_DIR, says where it is.
  2. What it is called. What the compiler emits and TOGSim loads is a tile-operation-graph (TOG). TOGSim ABI 16 names its surface after it (--tog_so, tog.so, tog_*.tsv, tog_*.txt), and the compiler that carries that TOGSim writes tog.so and "tog_so" in a kernel.json of format 2. The frontend follows.

They are one PR because the compiler commit this repository must pin does both: it is the first that carries TOGSim, and the TOGSim it carries is ABI 16. A frontend at the old names cannot run with it, and a frontend at the new names cannot run with any earlier compiler.

There is no fallback to the TOGSim/ in this tree. An earlier version of this branch kept one for compiler pins from before the split. That copy is ABI 15 (--trace_so, trace.so), so keeping it reachable would mean a frontend that speaks one set of names to the carried TOGSim and another to its own. It speaks one. After this PR nothing reads TOGSim/; the stacked PR deletes it together with configs/.

Order

  1. PSAL-POSTECH/TOGSim: ABI 16 on its main, v1.2.0 at af85f7b. Done. (v1.3.0 at 83f43c8 is out since; see "TOGSim v1.3.0".)
  2. PyTorchSim-Triton-Backend BIAS DMA wait #59: third_party/TOGSim at af85f7b, tog.so, kernel.json format 2. Merged as ff9d399e; its main is 688388c7, and the image for that commit is published.
  3. This PR, pinned to 688388c7.
  4. The removal PR (togsim-remove), stacked on this one; once this one is merged its base is changed to pytorchsim-triton-backend.

The pin

The last commit, [Deps] The compiler pin moves to 688388c7: TOGSim as its submodule, at ABI 16, changes one line: ref in third_party/pytorchsim-triton-backend.json, from 65fb0585 to 688388c7f8aa322221ebbfef81f3f89f42966299, the head of the compiler's main. That commit carries third_party/TOGSim at af85f7b (v1.2.0). ghcr.io/psal-postech/pytorchsim-triton-backend:688388c7f8aa322221ebbfef81f3f89f42966299 is in the registry (pushed 2026-10-12T19:18Z, also tagged main). The file is one of the three that decide the base image tag, so CI rebuilds the base once (third_party-6a7b2e2e905c with this pin).

When the compiler moves its TOGSim submodule (to v1.3.0, or to a commit that carries #346's change), this repository follows by moving that one line again.

#346

ee5f8a48 (#346, "A load of what a buffer already holds is not read again") was merged into pytorchsim-triton-backend after this branch was first cut. It changes TOGSim/include/Instruction.h, TOGSim/src/Core.cc and TOGSim/src/togsim_trace_bridge.cc in this tree (ABI 15). It is the only commit on the base since c9a279be.

PSAL-POSTECH/TOGSim does not have it: at 83f43c8 (v1.3.0) no file under src/ or include/ contains tag_scope, wait_scope or struct Resident, and no commit message mentions it. The patch does not apply to v1.2.0 or v1.3.0 as it is: Instruction.h applies, Core.cc and togsim_trace_bridge.cc conflict under a 3-way apply.

What that means here: after this PR the Simulator that runs is the compiler's third_party/TOGSim (v1.2.0), so a repeated load is read again, as before #346 (its message gives 8192x768x3072 at 309622 cycles without the change and 269075 with it). Either TOGSim takes the change and the compiler pin is moved before this merges, or this merges knowing the regression and the pin follows later. That is a decision for the reviewers; nothing here ports it.

TOGSim v1.3.0

The pinned compiler carries v1.2.0. v1.3.0 keeps TOGSIM_ABI_VERSION 16 and the same include/togsim_runtime.h (SHA-256 8d4d4a15... at both tags), and refuses three things it used to accept: a run without a cycle table, a compute whose tile id the cycle table does not hold, and a work-item that needs more of the spad at once than a core has. This branch was checked against it with TOGSIM_DIR naming a v1.3.0 checkout:

  • A cycle table is always written and always passed. timing.run writes tog_cycles.tsv and tog_units.tsv when either is missing, and timing.run_togsim raises FileNotFoundError unless tog.so and both tables are in the workdir; TOGSimulator.run_standalone passes --cycle_table and --unit_table; a session launch (--models_list) names a launch directory into which contract.link_shared has linked the three files.
  • No tile id beyond the table. write_cycle_tables writes one row per entry of the compiler's tile_types (overlap_offset), and raises when gem5 returns a different number of samples.
  • Nothing relies on the flat 128-cycle stub: there is no path that launches without the tables.
  • A refusal is an error here too, not a crash and not a quiet success (commits 16-17). Both were gaps against v1.3.0 and are reproduced below on its Simulator: run_standalone answered a non-zero exit with assert 0, which autotune does not catch, and shutdown dropped the session Simulator's exit status.

Changes

TOGSIM_DIR (commits 1-8):

  • pytorchsim/config.py: CONFIG_TOGSIM_DIR is TOGSIM_DIR if set, else $TORCHSIM_COMPILE_DIR/third_party/TOGSim. The header is $TOGSIM_DIR/include/togsim_runtime.h, the binary $TOGSIM_DIR/build/bin/Simulator, the machine configs $TOGSIM_DIR/configs (CONFIG_TOGSIM_CONFIG_DIR, from which the default TOGSIM_CONFIG is taken). A machine config that is not there raises FileNotFoundError naming the path, the checkout and both variables.
  • pytorchsim/simulator/togsim.py: the session, the standalone run and get_togsim_command take the Simulator from CONFIG_TOGSIM_DIR; a missing Simulator is an error that names TOGSIM_DIR.
  • pytorchsim/driver/compiler_bridge.py: compiler_env() sets TOGSIM_DIR for the compiler subprocess, so the header the TOG is compiled against, the header this process digests and the Simulator it starts are one checkout.
  • pytorchsim/driver/codecache.py: a missing togsim_runtime.h raises instead of digesting to None, which admitted any cached artifact.
  • .github/workflows/docker-image.yml: the three togsim_config paths are under /workspace/pytorchsim-triton-compiler/third_party/TOGSim/configs/.
  • scripts/build_from_source.sh: initialises the compiler's third_party/TOGSim and runs its togsim step (needs conan 1.56 and cmake on PATH).

The names (commits 9-15; the pin is the last commit, 18):

before now
TOG trace.so tog.so
cycle table, unit table trace_cycles.tsv, trace_units.tsv tog_cycles.tsv, tog_units.tsv
launch sidecars trace_shape.txt, trace_tensors.txt, trace_tensor_shapes.txt tog_shape.txt, tog_tensors.txt, tog_tensor_shapes.txt
this repository's own sidecar trace_axes.txt tog_axes.txt
Simulator flag --trace_so --tog_so
kernel.json artifact key, format "trace_so", 1 "tog_so", 2
provenance.json key "trace_abi" "tog_abi"
timing.py TRACE_SO, emit_trace() TOG_SO, write_cycle_tables()
wall-clock span wallclock.TOGSIM_TRACE, "togsim/trace" wallclock.TOGSIM_TABLES, "togsim/tables"
  • timing.emit_trace emitted nothing of the TOG: the compiler builds tog.so, and this function measures the tile under gem5 and writes the two tables. It is write_cycle_tables.
  • scripts/util_viewer.py reads the workdir from --tog_so on a logged command line and still from --trace_so, because logs under togsim_results/ outlive the simulator that wrote them.
  • scripts/ci/triton_route_sweep.py: the last stage file is tog.so, the togsim bucket matches tog\.so.
  • .claude/CLAUDE.md: "tile-operation-graph (TOG)" on first mention, "TOG" after. Two statements that were wrong beyond the name are corrected (the compiler, not this repository, compiles the TOG; its directory is lowering/tog/).
  • "trace" is kept where it is one: the .trace command stream and trace_log of a session, --log_level trace / TOGSIM_DEBUG_LEVEL=trace, scripts/trace_timeline.py.

A Simulator that exits non-zero (commits 16-17):

  • TOGSimulator.run_standalone raises RuntimeError("TOGSim Simulator exited with status N: <the last line it printed>") instead of assert 0. Autotune's _time_tile already scores RuntimeError as inf, so a candidate TOGSim refuses is skipped like one that times out; outside autotune the Simulator's whole output is logged as an error first.
  • TOGSimulator.shutdown keeps the status of the session Simulator and, after writing the log and the trace and removing the FIFO, raises RuntimeError when it is not 0. torch.npu.simulator.__exit__ calls it, so the with block raises. The session's output is not captured, so the reason is on the Simulator's own output.
  • tests/system/test_togsim_exit.py holds both with a stub Simulator (no TOGSim needed) and is added to scripts/ci/triton_route_passing.txt and the workflow matrix.

Behaviour to know about

  • Warm caches are rebuilt, once. A workdir under TORCHSIM_DUMP_PATH written before this PR holds a format-1 kernel.json and a provenance.json keyed trace_abi. Its identity matches none computed now, so it is cleared and recompiled on first use; clear_stale removes the old trace.so / trace_*.tsv as well as the new names. trace.cpp and trace_axes.txt are left behind in such a workdir, unread.
  • That path used to be a crash. torchsim_compile read the manifest before comparing identities, and contract.kernel_object raises KernelObjectMismatch on a format it does not know; nothing caught it. Commit 9 (cached_elf) makes a foreign-format manifest in a workdir of another identity a rebuild. The same manifest in a workdir this identity wrote still raises, saying that contract.KERNEL_FORMAT and the pinned compiler must move together, because a rebuild would write the same file.
  • A compiler checkout without TOGSim is an error, not a quiet switch to another copy: reading a machine value, digesting the header and starting the Simulator each raise with TOGSIM_DIR named.
  • TOGSIM_DIR=$TORCHSIM_DIR/TOGSim does not work. The in-tree Simulator refuses --tog_so. Nothing sets it that way; the directory goes in the next PR.
  • A session that TOGSim ended early now fails. A script whose with torch.npu.simulator(...) block used to return after the Simulator exited non-zero now gets a RuntimeError from the block. v1.3.0's three refusals end a session this way; only the spad one was run.
  • A breakdown key changes: togsim/trace is togsim/tables in breakdown_<run>.json and in the TORCHSIM_BREAKDOWN table.
  • Grouping. This repository does not choose a TOG grouping; the compiler's default, typed, applies. typed is deprecated in the compiler and in TOGSim (a typed TOG that uses compute_type 1-3 logs one warning per Simulator process before the simulation and replays with unchanged cycles). No option is added here; moving to segment is a separate change, and it changes cycle counts (gemm 24818 -> 24586, softmax 1589 -> 1722 on tpuv6e).
  • Between this PR and the next, docker/Dockerfile still builds the in-tree TOGSim/ that nothing runs, and its comment still says "trace producer". The next PR removes both.

Verified locally, at head 5ab54226

All runs are in the published image of the pin, ghcr.io/psal-postech/pytorchsim-triton-backend:688388c7... (compiler, Spike, gem5 and the built TOGSim v1.2.0 as the image carries them), as a non-root user, with this branch mounted as TORCHSIM_DIR, TORCHSIM_TRITON_CODEGEN=1, torch 2.14 and a device/ built outside the image. "v1.3.0" means the same image with TOGSIM_DIR naming a checkout of TOGSim v1.3.0 built in that image with conan 1.56 and cmake.

  • Rebase. Onto aaa3ee84 with no conflict: the one commit merged since touches only TOGSim/. The tree differs from the branch as first cut (13e907de) by [TOGSim] A load of what a buffer already holds is not read again #346's three files, the pin line, and commits 16-17 (five files: togsim.py, the _time_tile docstring in autotune.py, the new test and its two list entries).
  • tests/ops/elementwise/test_add.py, timing on (tpuv6e), standalone launches (--tog_so ... --cycle_table ... --unit_table ...): five of five passed on v1.2.0 and on v1.3.0, the same totals on both: 81, 326, 5889, 639866, 5642. No refusal and no TOGSim warning in any log. The workdirs hold a format-2 kernel.json with tog_so.
  • experiments/gemm.py, timing on (tpuv6e), a session (--models_list) plus the autotune path (write_cycle_tables and run_standalone): finished on v1.2.0 and on v1.3.0, autotune 1799 cycles and Total execution cycles: 1799 on both. The launch directory holds tog.so, tog_cycles.tsv and tog_units.tsv as links. TOGSim logs its typed-grouping deprecation warning once per Simulator process, so twice in this run: once for the autotune candidate's standalone Simulator (in its captured log under autotune/128x128x128/launch-7/togsim_result/) and once for the session (see "Grouping").
  • tests/system/test_togsim_result.py: PASS. tests/system/test_togsim_exit.py: PASS; on the tree before commit 16 it fails with AssertionError from run_standalone, and before commit 17 its session case fails because shutdown returns.
  • A refused kernel, on the v1.3.0 Simulator. The TOG is the one TOGSim's own spad_capacity/refused.one_byte_over case builds (one byte over a 48 kB spad), not a kernel this compiler emitted. Before commits 16-17 (at 79a07464) and at this head:
    • run_standalone(..., autotune_mode=True): before, AssertionError, which escapes _time_tile's except; now RuntimeError: TOGSim Simulator exited with status 1: ... work-item 0 (key 10) needs 49153 bytes in the spad at once, and a core's spad holds 49152 (core_spad_size_kb: 48).
    • python3 -m pytorchsim.simulator.togsim <kernel> <attribute> --config machine.yml: before, exit 0; now exit 1 with the RuntimeError.
    • A with torch.npu.simulator(config_path=...) block that calls torch.npu.launch_kernel on it and torch.npu.synchronize(): before, the block returned; now it raises the RuntimeError.
  • The 12 changed Python files parse, the 2 changed shell scripts pass bash -n, the five workflows load as YAML.

Verified on the branch as first cut and not repeated at this head: the stale-cache script (format-1 manifests rebuilt, the same-identity case raising), scripts/util_viewer.py on old and new logs, the sweep's bucket expression.

The cycle totals differ from the ones recorded when the branch was first cut (81, 334, 5475, 6094, 650213): those were measured with the compiler at 87743844, these with 688388c7. The base commit cannot be run with this compiler (it reads trace.so), so there is no same-compiler comparison against the base.

Not verified

  • CI on a runner: the base image build (third_party-6a7b2e2e905c does not exist yet), the app image build, and the gate. The gate runs its tests with TORCHSIM_TIMING_MODE=0, so it does not start TOGSim; only the non-gating accuracy job does.
  • scripts/build_from_source.sh beyond bash -n; scripts/ci/triton_route_sweep.py as a whole; the allowlist; the other two CI machines (32x32, 8x8).
  • A kernel this compiler emitted being refused by v1.3.0: none of the kernels run here is one, and no larger model was run. The refusal handling above was exercised with TOGSim's own test TOG. Whether an autotune candidate can exceed core_spad_size_kb on a shipped machine config is not known.
  • The other two v1.3.0 refusals (no readable tog_cycles.tsv under --models_list, a tile id the table does not hold) were not provoked; they leave the Simulator through the same non-zero exit.
  • A session that goes on sending commands after the Simulator has exited. Read from the code, not run: _send_command raises RuntimeError first, and in torch.npu.simulator.__exit__ a raise from synchronize() skips shutdown. Unchanged here.
  • A second process sharing a dump path while a stale workdir is rebuilt.

git grep -n -i 'trace producer\|trace_so\|trace\.so\|trace_abi' at the head, outside TOGSim/

  • pytorchsim/driver/codecache.py:39: _STALE_PATTERNS keeps trace.so, trace_cycles.tsv, trace_units.tsv so an old workdir is cleared.
  • scripts/util_viewer.py:9,25: the pattern and its docstring accept --trace_so from old logs.
  • docker/Dockerfile:6: a comment in the block the next PR deletes.

Inside TOGSim/ the in-tree copy keeps its ABI-15 text (and #346's change); the next PR deletes it.

YWHyuk added 19 commits October 13, 2026 14:08
…r carries

TOGSim is becoming its own repository, pinned by the compiler as
third_party/TOGSim, and this repository reaches it through the compiler
checkout it already pins. One variable says where it is: TOGSIM_DIR is the
TOGSim repository root, with the header at $TOGSIM_DIR/include and the binary
at $TOGSIM_DIR/build/bin/Simulator. Unset, it is
$TORCHSIM_COMPILE_DIR/third_party/TOGSim.

There is no fallback to the TOGSim/ still in this tree. That copy is ABI 15
and the TOGSim the compiler carries is ABI 16, with other file names and
another flag, so a frontend that could reach either would have to speak both.
It speaks one: the in-tree copy is no longer read by anything, and the stacked
change deletes it.

config.CONFIG_TOGSIM_DIR is that root and the three places that spelled
$TORCHSIM_DIR/TOGSim read it: the header directory, the Simulator path of the
session and of a standalone run. config.CONFIG_TOGSIM_CONFIG_DIR is its
configs/, and the default TOGSIM_CONFIG is taken from it.
…runs

The compiler builds trace.so against a togsim_runtime.h it finds on its own,
and this process digests a header into the cache identity and starts a
Simulator; nothing made the three the same checkout. compiler_env() now sets
TOGSIM_DIR to config.CONFIG_TOGSIM_DIR for every compiler subprocess, which is
the variable the compiler reads once it carries TOGSim as third_party/TOGSim.
A compiler from before that carries no TOGSim, and this frontend does not run
with one.

Not run against a compiler: none that reads TOGSIM_DIR is published yet.
…that names TOGSIM_DIR

A missing togsim_runtime.h used to digest to None: the cache identity then
carried "trace_abi": null and a cached trace.so was admitted whatever header
it had been built against. With the header in another repository that is the
likeliest way to be wrong (a submodule that was never initialised), so
_trace_abi() raises FileNotFoundError naming the path and TOGSIM_DIR instead.

get_togsim_command() does the same for build/bin/Simulator, which before
surfaced as the subprocess's bare "No such file or directory".
… TOGSIM_DIR

With no TOGSim checkout the default config path does not exist, and reading
any machine value raised FileNotFoundError with the path alone. It now says
which checkout TOGSIM_DIR resolved to and that TOGSIM_CONFIG may name a config
file instead, as the header and Simulator errors already do.
…image carries

docker-image.yml named its three TOGSIM_CONFIG files under
/workspace/PyTorchSim/configs. They are the same three names under
/workspace/pytorchsim-triton-compiler/third_party/TOGSim/configs now, the
directory the simulator the tests start comes from.

This needs a compiler pin whose image carries third_party/TOGSim; with the
pin at 65fb058 the paths do not exist. Not run: no such image is published.
The script left TOGSim out ("TOGSim is built from this repo") and the copy in
this tree was built by hand. It now initialises the compiler's
third_party/TOGSim submodule beside vcix-accelerator and runs the compiler's
togsim step, which fetches TOGSim's own submodules and builds
third_party/TOGSim/build/bin/Simulator, where config.CONFIG_TOGSIM_DIR
looks.

The step runs conan and cmake from PATH; the compiler's setup/system.sh
installs conan 1.56.0 and cmake 3.26.4 and sets the conan profile to
libstdc++, as root, and is not run from here.

Needs a compiler pin that has third_party/TOGSim and the togsim step: at
65fb058 neither exists and the script stops at the submodule update. Checked
with bash -n only.
…ild says it builds TOGSim

The variable and its default go in the table of what config.py reads.
The README and the build notes said build_from_source.sh builds the compiler,
Spike, pk and gem5; it builds the compiler's TOGSim as well now.
third_party/pytorchsim-triton-backend.json is the only pin this repository
keeps, and since the compiler carries TOGSim as a submodule its ref decides
the Simulator, the runtime header and the machine configs too. The description
says so. The ref is not moved here: it has to become a compiler commit that
has third_party/TOGSim, and none is published yet.
…t an uncaught KernelObjectMismatch

torchsim_compile read the cached ELF through contract.artifact before it
compared identities, and contract.kernel_object raises KernelObjectMismatch on
a kernel.json whose format it does not know. Nothing caught it, so a warm cache
from a compiler with another manifest format stopped the run at import of the
generated wrapper, where the identity check two lines below would have rebuilt
it.

cached_elf() decides it in one place. A manifest of another format in a workdir
whose provenance.json is not this identity is a stale cache: it is cleared and
rebuilt like any other, and clear_stale removes kernel.json with the stage
artifacts so the rebuild starts without it. The same manifest in a workdir this
identity wrote means contract.KERNEL_FORMAT and the pinned compiler disagree;
rebuilding would write the same file again, so it is raised, saying that the
two must move together.

The reader's own message named "rebuild the kernel cache" without saying how;
it names scripts/clear_codegen_cache.sh.
…og_so, and kernel.json format 2

What the compiler emits and TOGSim loads is a tile-operation-graph (TOG).
TOGSim ABI 16 names its surface after it, and the compiler that carries that
TOGSim names its artifacts the same way, so the frontend follows both at once:

  trace.so                  -> tog.so
  trace_cycles.tsv          -> tog_cycles.tsv
  trace_units.tsv           -> tog_units.tsv
  trace_shape.txt           -> tog_shape.txt
  trace_tensors.txt         -> tog_tensors.txt
  trace_tensor_shapes.txt   -> tog_tensor_shapes.txt
  --trace_so                -> --tog_so
  kernel.json "trace_so"    -> "tog_so"

The compiler made that last rename its kernel.json format 2, so
contract.KERNEL_FORMAT is 2. A workdir holding a format-1 manifest is another
identity's and is rebuilt (the commit before this one).

trace_axes.txt, which only this repository reads, becomes tog_axes.txt.
timing.TRACE_SO is timing.TOG_SO. clear_stale removes the new names and still
removes the old ones, which a workdir written before this commit holds.

There is no compatibility path: TOGSim 16 refuses --trace_so and an ABI-15
TOG, and the in-tree TOGSim/, which is ABI 15, is not read any more.

The command stream's .trace file, the FIFO's trace_log and --log_level trace
keep their names: they are a record of what was sent or replayed, not the TOG.
…TOG, this step measures it

timing.emit_trace emits nothing of the TOG. The compiler builds tog.so; this
function measures the tile under gem5 and writes tog_cycles.tsv and
tog_units.tsv beside it. It is named for that, and its wall-clock span follows:
wallclock.TOGSIM_TRACE ("togsim/trace") is wallclock.TOGSIM_TABLES
("togsim/tables"), which is also the key in breakdown_<run>.json and the row
in the TORCHSIM_BREAKDOWN table.
_trace_abi() and the "trace_abi" key of provenance.json are _tog_abi() and
"tog_abi": the digest is of the header a TOG is compiled against. The key is
part of the identity, so a provenance.json written before this commit matches
no identity computed after it: every workdir from the old names is rebuilt on
first use and none is reused.

The docstring said TOGSim declares the refusal of a mismatched ABI and does not
check. TOGSim 16 checks, at load; the digest turns the same condition into a
cache miss first.
… from an older one

util_viewer.py joins a TOGSim log to its kernel workdir by the path after the
flag on the logged command line. TOGSim 16 logs --tog_so. The logs under
togsim_results/ outlive the simulator that wrote them, so the pattern accepts
either flag and the page still builds from a directory that holds both.

trace_timeline.py's usage line and clear_codegen_cache.sh's list of what a
workdir holds name the flag and the file as they are now. trace_timeline.py
keeps its name: it draws a --log_level trace log.
triton_route_sweep.py places a failed kernel by the last stage file its
workdir holds, and buckets a failure by its text. The last stage file is
tog.so, labelled "TOG"; the togsim bucket matches tog\.so, and its owner reads
"TOGSim / the TOG". TOGSim's own lines, now prefixed [TOGSim], were already
matched by the bucket's first alternative.
…its files as they are

.claude/CLAUDE.md said "trace producer", trace.so, trace_cycles.tsv,
trace_shape.txt and trace_to_tilegraph. It says tile-operation-graph (TOG) on
first mention and TOG after, with the file and symbol names of TOGSim ABI 16.

Two statements were wrong beyond the names and are corrected: the compiler
compiles the TOG to tog.so (this repository does not, it writes the two tables
beside it), and the compiler's directory is lowering/tog/, not trace/.

"trace" stays where it is one: the .trace command stream under
togsim_results/, TOGSIM_DEBUG_LEVEL=trace and scripts/trace_timeline.py.
…rries its last line

run_standalone answered a Simulator that exited non-zero with `assert 0`.
Nothing catches an AssertionError: autotune's _time_tile, which scores a
candidate that does not compile or run as inf, catches CompilerError,
RuntimeError and FileNotFoundError, so the first candidate TOGSim refused
ended the whole compile instead of being skipped.

TOGSim 1.3.0 makes that exit ordinary. It refuses at load a work-item that
needs more of the spad at once than a core has (601de86), a compute whose tile
id the cycle table does not hold, and a run with no cycle table; before it, the
first of these hung and met autotune's timeout, which is a RuntimeError
already.

The exit is now a RuntimeError with the status and the last line the Simulator
printed, which for a refusal is the refusal. Outside autotune the whole output
is still logged as an error first.

tests/system/test_togsim_exit.py holds this with a stub Simulator, and joins
the allowlist and the workflow matrix. On the tree before this commit it fails
with the AssertionError.

Run against the Simulator of TOGSim 83f43c80 (v1.3.0) on the TOG its
spad_capacity case builds, one byte over a 48 kB spad: before, AssertionError;
now, "TOGSim Simulator exited with status 1: ... work-item 0 (key 10) needs
49153 bytes in the spad at once, and a core's spad holds 49152". No kernel this
compiler emitted has been seen refused.
shutdown waited for the Simulator and dropped its exit status, so a session
TOGSim ended early returned as one that ran: `with torch.npu.simulator(...)`
left its block quietly and the script went on to print that the simulation was
done.

A session Simulator stops at the first command it cannot process. TOGSim 1.3.0
adds three such commands that an earlier one ran or hung on: a launched kernel
with no readable tog_cycles.tsv, a compute whose tile id the table does not
hold, and a work-item over the spad.

shutdown still writes the log and the trace and removes the FIFO, and then
raises a RuntimeError with the status. The session's output is not captured,
so the reason is on the Simulator's own output and the message says so.

test_togsim_exit.py holds both ends with the stub Simulator: a status of 1
raises after the cleanup, a status of 0 does not.

Run against the Simulator of TOGSim 83f43c80 (v1.3.0) on the refused
spad_capacity TOG: `python -m pytorchsim.simulator.togsim` exited 0 before and
exits 1 now, and a torch.npu.simulator block that launches it returned quietly
before and raises now.
…t ABI 16

688388c7 is the head of PyTorchSim-Triton-Backend's main. It contains that
repository's #59, the first commit that carries TOGSim as third_party/TOGSim
(at af85f7b, v1.2.0, TOGSIM_ABI_VERSION 16) and that emits tog.so, "tog_so"
and a kernel.json of format 2. Everything before this commit on the branch is
written for such a compiler and runs with no earlier one: 65fb058, the pin
until now, carries no TOGSim and writes trace.so.

The image ghcr.io/psal-postech/pytorchsim-triton-backend:688388c7... is in
the registry. This file is one of the three that decide the base image tag,
so CI rebuilds the base once.

Only the ref changes. A later compiler commit that moves its TOGSim submodule
is followed by moving this one line again.
…le and the TPU v6e HBM3 address mapper

688388c7 -> 11ef9b00 of PyTorchSim-Triton-Backend. It carries TOGSim a1c4209
(v1.3.0 plus the MOP4CLXOR mapper of HBM3_TPUv6e) and one compiler change,
0f3ba03 (a dot's elementwise consumer runs at its last-K pops). ABI stays 16.
[Deps] The compiler pin moves to 11ef9b00: the TPU v6e HBM3 address mapper
@YWHyuk
YWHyuk marked this pull request as ready for review October 13, 2026 05:11
@YWHyuk
YWHyuk merged commit 2885af6 into pytorchsim-triton-backend Oct 13, 2026
YWHyuk added a commit that referenced this pull request Oct 13, 2026
… TOGSIM_DIR

TOGSim is its own repository (PSAL-POSTECH/TOGSim) and the compiler,
PyTorchSim-Triton-Backend, pins it as third_party/TOGSim. The dependency line
is PyTorchSim -> compiler -> TOGSim, so this repository pins the compiler only.

- TOGSIM_DIR names the TOGSim checkout; by default it is the one inside the
  compiler checkout. The compiler is handed the same TOGSim this process
  digests and runs, so the header a TOG is built against is the Simulator's.
- A TOGSim without its header or its Simulator, and a machine config that is
  not there, are errors that name TOGSIM_DIR.
- The gate's three machine configs are read from the TOGSim the compiler image
  carries, and build_from_source.sh builds that TOGSim.
- The environment table and the from-source notes say so, and the compiler
  pin's description says it is also what pins TOGSim.

PyTorchSim #348.
YWHyuk added a commit that referenced this pull request Oct 13, 2026
…so, kernel.json format 2

What the compiler emits is a tile-operation-graph (TOG), and TOGSim's ABI 16
names it so. The frontend follows: tog.so and tog.cpp, tog_cycles.tsv,
tog_units.tsv, tog_tensors.txt, tog_shape.txt, --tog_so, and kernel.json at
format 2.

- emit_trace is write_cycle_tables: the compiler emits the TOG, this step
  measures its tiles.
- The cache identity's header digest is "tog_abi". A workdir that another
  kernel-object format wrote is rebuilt instead of raising an uncaught
  KernelObjectMismatch.
- util_viewer reads --tog_so from a log, and still --trace_so from an older
  one. The route sweep looks for tog.so.
- The repo guide calls what the compiler emits a TOG and names its files as
  they are.

PyTorchSim #348.
YWHyuk added a commit that referenced this pull request Oct 13, 2026
…nd in a session

TOGSim v1.3.0 refuses a run without a cycle table, a compute whose tile id the
table does not hold and a work-item larger than the spad, each with exit 1.

- run_standalone raised an AssertionError, which escaped autotune's except
  list. It is a RuntimeError that carries the Simulator's last line, so
  autotune drops that candidate and goes on.
- A session whose Simulator exited non-zero returned as if it had succeeded.
  shutdown keeps the exit status and raises after the logs are written and the
  FIFOs are removed, so a torch.npu.simulator block raises.

tests/system/test_togsim_exit.py pins both, and is in the route's passing list.

PyTorchSim #348.
YWHyuk added a commit that referenced this pull request Oct 13, 2026
…t v1.3.0 with the TPU v6e HBM3 address mapper

third_party/pytorchsim-triton-backend.json, ref 65fb0585 -> 11ef9b00, the head
of the compiler's main. Its image is published.

- third_party/TOGSim at a1c4209: TOG ABI 16, v1.3.0 (the three refusals), and
  PSAL-POSTECH/TOGSim #20, the TPU v6e HBM3 mapping addresses with MOP4CLXOR
  instead of RoBaRaCoCh. Every tpuv6e cycle count moves with the mapper.
- The compiler's sync-by-default transfers (PTB #62), the pop rule of the
  accelerator model (PTB #63), and a dot's elementwise consumer running at its
  last-K pops.

TOGSim does not carry PyTorchSim #346 (a load of what a buffer already holds
is not read again) yet: PSAL-POSTECH/TOGSim #22, #23. That behaviour is absent
from here on until TOGSim carries it and this pin moves.

PyTorchSim #348, #350.
@YWHyuk
YWHyuk deleted the togsim-dir branch October 23, 2026 03:03
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