Skip to content

A launch directory per kernel launch; a model test's forward in one TOGSim session - #529

Merged
student-Jungmin merged 2 commits into
pytorchsim-triton-backendfrom
pr/pts-2-launch-dir-session
Nov 10, 2026
Merged

student-Jungmin merged 2 commits into
pytorchsim-triton-backendfrom
pr/pts-2-launch-dir-session

Conversation

@student-Jungmin

Copy link
Copy Markdown
Collaborator

Summary

Stacked on #528.

  • Each kernel launch gets a launch directory of its own (launch-<pid>-<n>-<unique>) with launch.json recording the call: two launches of one compiled kernel (Qwen3-8B prefill's k_proj and v_proj) used to share and overwrite each other's shape, address and runtime-attribute files, and a session could read the second's for the first. Argument names come from Inductor's IR at codegen. TORCHSIM_KEEP_LAUNCHES=1 keeps the directories past exit.
  • A model test's device forward runs in one TOGSim session, and the session prints its cycles.

The two graph_prefetch system tests' mocked launchers now take the new torchsim_arg_names keyword.

Verification

test_launch_record.py and test_launch_dir.py fail on the tree before; Qwen3-8B cycles unchanged.

…a record of its call

A kernel's launch directory was per kernel and per process, so two launches of one compiled kernel shared its shape, tensor and held runtime attribute files, and a session could read the second launch's files for the first. Its meta.json named the first call site's buffers for every launch (Qwen3-8B prefill's v_proj read as a second k_proj). Each launch now gets launch-<pid>-<n>-<unique> beside the kernel's shared tog.so and cycle tables (symlinked), holding that launch's files and launch.json: the kernel, and per argument the name the wrapper passes (bufN, also through reinterpret_tensor), shape, stride, dtype and data_ptr. The names are written into each npu kernel call at codegen by TritonNPUWrapperCodegen, taken from Inductor's IR nodes (get_name, a ReinterpretView's buffer, or a call arg the graph knows as a buffer or input), never parsed from rendered strings; numel and literal arguments are None. Nothing inspects frames.

A process removes its launch directories when it exits unless TORCHSIM_KEEP_LAUNCHES=1, which a user keeps to map a session trace back to tensors. workdir_of returns the kernel workdir for a copy node's handle too. Pins: tests/system/test_launch_record.py (one kernel launched twice in a session, and an inline reinterpret_tensor argument) and test_launch_dir.py (a name an earlier run with the same pid left, removal at exit and keeping), failing on the tree before. Qwen3-8B cycles unchanged.
… the session prints its cycles

Each kernel launch ran TOGSim standalone and a layer's cycles were the sum of those runs, each starting from an
empty simulator, so a layer had no single timeline and its DRAM trace could not be laid end to end. A session is
what a caller opens: every model test (one_layer.run for every --part layer row, its MLA decode, and the lm, body
or fixed-input call of twenty model tests) now runs its device call inside `with torch.npu.TOGSimulator():`; the
CPU reference stays outside. A launch outside any block still runs standalone, as before.

A block's launches print nothing of their own, so TOGSimulator, when its block closes without an exception, prints
one "[TOGSim] session simulated: N cycles, K launches" line from the result TOGSim wrote, which run_grid already
sums as it summed the standalone launches' lines. tests/system/test_session_cycles.py pins it: two kernels in one
block give that line once; on the tree before, the block printed none.

Qwen3-8B layer decode 1024: 462,104 summed, 456,635 in one session; prefill 128: 603,709 and 597,573. Kernels run
back to back; each is a little shorter without a standalone run's start and drain.
@student-Jungmin
student-Jungmin changed the base branch from pr/pts-4-decode-writes-kv to pytorchsim-triton-backend November 10, 2026 18:07
@student-Jungmin
student-Jungmin merged commit 42deef6 into pytorchsim-triton-backend Nov 10, 2026
@YWHyuk
YWHyuk deleted the pr/pts-2-launch-dir-session branch November 19, 2026 05:29
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