Skip to content

[TOGSim] Spad buffer sizes come from the producer (trace ABI 15); semaphore refusals pinned by name - #324

Merged
YWHyuk merged 2 commits into
pytorchsim-triton-backendfrom
togsim-semaphore-followups
Oct 8, 2026
Merged

YWHyuk merged 2 commits into
pytorchsim-triton-backendfrom
togsim-semaphore-followups

Conversation

@YWHyuk

@YWHyuk YWHyuk commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-ups to the semaphore change (7b21d07, 2fd095a), from a review of it.

A spad buffer is as large as the producer states (trace ABI 15)

sram_schedule() sized a buffer by summing the bytes of the DMAs that fill or drain one version. A store leaves the version open, so every later store of the same tile added its bytes again: a tile stored twice counted twice, a state stored on each of N trips N times, and once the sum passed the spad try_occupy_sram never succeeded and the simulator never ended. 2fd095a itself lists the double drain as not fixed.

The compiler allocated the buffer and knows its size, so the producer now exports it and TOGSim only reads it:

  • togsim_runtime.h: ABI 15. A producer defines togsim_spad_buffer_count and togsim_spad_buffer_bytes[], the byte size of each buffer id its read_bufs/write_bufs name (0 for an id that is no spad buffer).
  • The loader refuses a producer that states no table. The bridge refuses a DMA'd buffer whose size is missing or 0, and the summing in index() and sram_schedule() is gone.

tests/sram_pieces gains producers that fail on 05c2d47 (48 KB spad):

producer 05c2d47 footprint this branch
twostore (a tile stored to two tensors) 49152 32768
runstate (a state stored every trip) 65536, max_dispatch 1 16384, max_dispatch 2
computestate (a computed state stored every trip) 81920, never ends (timeout) 32768, ends
unsized (a table that is too short, or no table) runs refused

pieces and scatter keep 32768 and 16640. Every test producer now states its sizes.

Each refused semaphore case names its refusal

run_k1.sh used to pass a refused case on any non-zero exit with any [TOGSim-trace] message, so a case that lost its scenario and hit a different refusal still passed. Each case now names the message it must get.

Checked by mutation: with K1 case 2 rewritten to wait on sem 7, the old script passes and this one fails ("wanted wait on a semaphore never signaled, got: ... wait expects another element count").

Test scripts on 05c2d47

Since the packed tensor layout (d91215e), TOGSim requires a trace_tensors.txt next to the .so. Neither test script wrote one, so on 05c2d47 every case failed with "trace_tensors.txt is absent". Both scripts now write it, placing tensors 1 MiB apart (the old layout). K1's arrival order (the small load lands first) was measured on that layout; with tensors 128 MiB apart the scenario is lost.

Verification

All on this branch:

  • tests/sram_pieces/run_pieces.sh: all PASS.
  • tests/semaphore_batch/run_k1.sh: K1 PASS. Cases 1, 2 and 3 and rewait case 1 each get the refusal they name.
  • PyTorchSim-Triton-Backend semaphore-followups, which pins this branch: 10 kernels have the same TOGSim cycles as on 05c2d47, and their spad footprints are identical except istft_overlap_add, 57344 → 55296. That drop is exactly the 2048 B its twice-stored output had been over-counted.

PyTorchSim-Triton-Backend PR that pins this branch: PSAL-POSTECH/PyTorchSim-Triton-Backend#27

YWHyuk added 2 commits October 8, 2026 20:36
…As that fill it

Trace ABI 15. A producer exports togsim_spad_buffer_count and
togsim_spad_buffer_bytes[]: the byte size of every buffer id its
read_bufs/write_bufs name (0 for an id that is no spad buffer). The
loader refuses a producer that states none, and the bridge refuses a
DMA'd buffer whose stated size is missing or 0. sram_schedule() no
longer sums the bytes of the DMAs filling or draining one version.

That sum over-counted every buffer stored more than once in a version:
a store leaves the version open, so each later store of the same tile
added its bytes again. A tile stored to two tensors counted twice, a
state stored on each of N trips counted N times, and when the sum passed
the spad, try_occupy_sram never succeeded and the simulator never ended.
The compiler allocated the buffer and knows its size; TOGSim reads it
instead of deriving it a second time.

tests/sram_pieces gains three producers, each failing on 05c2d47:

  producer      05c2d47 footprint      now
  twostore      49152                  32768
  runstate      65536 (max_dispatch 1) 16384 (max_dispatch 2)
  computestate  81920, no end (timeout) 32768, ends

and unsized_producer (a too-short table, no table) for the two
refusals. pieces and scatter keep 32768 and 16640. Every test producer
states its sizes.

run_pieces.sh writes the trace_tensors.txt TOGSim has required beside
the .so since the packed tensor layout (d91215e); without it both
sram_pieces cases already failed on 05c2d47 with "trace_tensors.txt is
absent". The tensors sit 1 MiB apart, as before that change.
run_k1.sh passed a refused case on rc != 0 plus any lowercase
[TOGSim-trace] line, so a case that lost its scenario and tripped
another of the four semaphore refusals still passed. Each case now names
its expected message: K1 1 "wait expects another element count", 2
"wait on a semaphore never signaled", 3 "unwaited load batch", rewait 1
"re-wait expects another element count".

Checked by mutation: K1 case 2 rewritten to wait sem 7 (case 1's
refusal) passes the old script and fails this one with "wanted \"wait
on a semaphore never signaled\", got: ... wait expects another element
count".

Like run_pieces.sh, it now writes trace_tensors.txt beside the .so (1
MiB apart, the layout K1's arrival order was measured on); on 05c2d47
every case failed with "trace_tensors.txt is absent".
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