Skip to content

Call the compiler package's Spike launcher instead of a copy - #434

Merged
YWHyuk merged 1 commit into
pytorchsim-triton-backendfrom
item10/launcher-from-ptb
Oct 23, 2026
Merged

YWHyuk merged 1 commit into
pytorchsim-triton-backendfrom
item10/launcher-from-ptb

Conversation

@YWHyuk

@YWHyuk YWHyuk commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #428

Why

pytorchsim/simulator/functional.py carried a ~250-line copy of the compiler's Spike launcher (split, clash fallback, inout single-process, trace merge). PSAL-POSTECH/PyTorchSim-Triton-Backend#330 moves that launcher into the compiler package; this PR calls it instead of keeping the copy.

What changed (before -> after)

  • e9e6ae3 — functional.py calls spike.launch() from the compiler package and deletes the copied helpers (net −250 lines). Kept: tensor <-> .raw I/O, the replay cache, PTS's own TORCHSIM_SPIKE / TORCHSIM_PK / TORCHSIM_SPIKE_JOBS with the existing TORCHSIM_COMPILE_* fallbacks. New compiler_bridge.compiler_module(name) generalises compiler_contract() with the same check that the import comes from the TORCHSIM_COMPILE_DIR checkout. codecache.py:23 remains the only importer and calls only functional.run.

Verification (seed 0; implementer + independent reviewer, separate containers)

Dependencies

Resolved. PSAL-POSTECH/PyTorchSim-Triton-Backend#330 is merged as 479243b on PTB main, and this branch's base already pins it (#436, 8967db2). The provisional pin commit (127eaa3) is dropped; the PR is the functional.py commit alone, rebased onto the current base.

Open issues

  • Same outputs, small behaviour differences: log text is PTB's ([spike], inout message names the argument); the dma_access error no longer names an env var; Spike dump directories are created after run_options; a scalar with no value raises ko.ObjectError instead of SpikeError (both RuntimeError, nothing catches by class).
  • functional.py:26-30 _NP_CARRIER still duplicates ko.NP_DTYPE (bool->bool here vs bool->int8 there), follow-up.

🤖 Generated with Claude Code

https://claude.ai/code/session_01UnJWSTNtd6944XAzy4bhk5

@YWHyuk YWHyuk self-assigned this Oct 23, 2026
…her, not its own copy

functional.py:253-511 was a second copy of the compiler's Spike
launcher (SPIKE/PK aside: ITEMSIZE, artifact, argv_order, argv_scalars,
grid3, writable, splittable, nbytes, _run, launch, _jobs, _split,
_worker_path, _prepare, _merge_outputs, _merge_traces), kept in step by
hand. The compiler now ships it as pytorchsim_triton_compiler.runtime.spike
(PyTorchSim-Triton-Backend runtime/launcher-in-package), so this file
keeps only what is PyTorchSim's: tensors <-> runtime/*.raw, the replay
cache, and its own config names for Spike, pk and the job count
(TORCHSIM_SPIKE / TORCHSIM_PK / TORCHSIM_SPIKE_JOBS, each falling back to
the TORCHSIM_COMPILE_* spelling as before). launch() resolves the ELF
and run_options() and hands both to spike.launch(); a missing ELF or
target is a SpikeError as before. compiler_bridge.compiler_module(name)
is compiler_contract() generalised to any module of the package, with
the same "imports from the checkout TORCHSIM_COMPILE_DIR names" check.

Needs the compiler pin to carry runtime/spike.py (next commit).

Checked in topk-ptb:pts-base-92028c8, torch.manual_seed(0), before =
PyTorchSim 069878a with PTB main 602777c (5fb15ee, rebased onto, moves only
the pin file), after = this commit with
PTB runtime/launcher-in-package 127eaa3: tests/ops/elementwise/test_add.py,
tests/ops/reduce/test_reduce.py, tests/ops/reduce/test_softmax.py,
test_add.py with TORCHSIM_SPIKE_JOBS=4, and with TORCHSIM_SPIKE_JOBS=4
tests/ops/gemm/test_bmm.py (16, 12 and 4 programs over 4 processes),
tests/ops/misc/test_indirect_access.py and test_inplace_partial_write.py
(inout: one process). Same verdicts, and all 125 runtime/*.raw and
indirect_access dumps byte-identical.
@YWHyuk
YWHyuk force-pushed the item10/launcher-from-ptb branch from a5ad788 to 14fb0ae Compare October 23, 2026 10:18
@YWHyuk
YWHyuk marked this pull request as ready for review October 23, 2026 10:18
@YWHyuk
YWHyuk merged commit 8f3afd9 into pytorchsim-triton-backend Oct 23, 2026
YWHyuk added a commit that referenced this pull request Oct 23, 2026
…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
@YWHyuk
YWHyuk deleted the item10/launcher-from-ptb 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