Skip to content

[TOGSim] Trace-bridge dependency + SRAM version redesign - #270

Merged
YWHyuk merged 1 commit into
feature/togsim-cpp-tracefrom
feature/bridge-dep-redesign
Jun 24, 2026
Merged

YWHyuk merged 1 commit into
feature/togsim-cpp-tracefrom
feature/bridge-dep-redesign

Conversation

@YWHyuk

@YWHyuk YWHyuk commented Jun 24, 2026 •

Copy link
Copy Markdown
Collaborator

Redesigns the C++ trace bridge's dependency model, removes the COMPUTE_BAR
fence, models compute-output spad footprint, and tidies the runtime event
machinery -- replacing a pile of special cases with one dataflow rule plus two
clean runtime mechanisms. Branches off feature/togsim-cpp-trace; disjoint file
set from the latest commit there (no conflicts).

Dependency rule (one rule)

Per SRAM buffer, keep a writers SET. A reader depends on ALL current writers
(JOIN) -- occupancy (released at ISSUE) when both are systolic-array ops, else
latency (released at finish). A writer REPLACEs the set. The only exception is
is_mm_accum (a matmul that reads AND writes the same buffer = a commutative
accumulator): skip its read edge and UNION its write, waiting only the
non-matmul init seed and not ordering co-matmuls.

  • Fixes the matmul-accumulator chain that deadlocked the SA weight-slot
    pipeline (Implement unique kernel name allocation #1) without losing the init->matmul edge.
  • A vector epilogue or the store now waits every K matmul (fixes the
    pure-vector store that an empty COMPUTE_BAR let slip, Scalar #2).

Remove COMPUTE_BAR

A matmul is its own DONE-handle (its finish is the SA drain), so the store
JOINs the matmul writers directly. Drops the compute_barrier emission in
build_skeleton and the Opcode/case/_fence_finish in Core and Instruction. Only
MEMORY_BAR remains (an async load's DONE is its data arrival, not its issue).

SRAM version model for compute outputs (capacity-aware WAR)

Buffer reuse ordering (WAR) is modeled by the SRAM version/capacity machinery,
not a hard edge (a hard WAR edge over-serializes weight-slot and double-buffered
reuse). Compute outputs (the accumulator, vector epilogue results) are tracked
too; the output size comes from the DMA records that touch the same buffer (a
buf_bytes pre-pass). A read-and-written buffer (accumulator, in-place relu) is
version-transparent so footprint is not double-counted. The COMPUTE issue path
gets the same capacity gate as a load.

Runtime mechanism cleanup (behavior-preserving, byte-identical)

  • Unify the two dependency sets into one event-indexed _deps[ISSUE|DONE] with
    add_dep/fire; the old methods are thin aliases.
  • Unify the timed effects (weight-slot frees + async-load MEMORY_BAR wakeups)
    into one _due_events table drained by process_due_events through a single
    apply_due sink.
  • Drop the dead Instruction::start_cycle field.
  • All three verified byte-identical (same Total_cycles, identical
    --log_level trace) on matmul / matmul+relu / multi-tile gemm / reduction.

Verification (no Spike)

  • 30/30 replayed traces complete, no wedge.
  • GEMM cycles within +0..3% of the prior bridge (the correct serialization from
    the init edge and the all-matmuls JOIN); the pure-vector pooling kernel +16%
    is the Scalar #2 store fix.

See docs/bridge_dependency_redesign.md for the full rule, the version/capacity
WAR model, and the runtime mechanism.

🤖 Generated with Claude Code

https://claude.ai/code/session_01HAmdM9BrsTvfi8sZnnfNno

@YWHyuk
YWHyuk force-pushed the feature/togsim-cpp-trace branch from 6ff30ce to e8697c7 Compare June 24, 2026 08:23
@YWHyuk
YWHyuk force-pushed the feature/bridge-dep-redesign branch 3 times, most recently from d85b3f4 to d4ded78 Compare June 24, 2026 11:38
@YWHyuk
YWHyuk force-pushed the feature/togsim-cpp-trace branch from 36da343 to 0f4deaa Compare June 24, 2026 11:39
@YWHyuk
YWHyuk force-pushed the feature/bridge-dep-redesign branch from d4ded78 to 03ccbcd Compare June 24, 2026 13:02
@YWHyuk
YWHyuk force-pushed the feature/togsim-cpp-trace branch from 9b913d4 to 4767e8a Compare June 24, 2026 13:16
… runtime model

Replace the trace bridge's accumulated special cases with one dataflow rule and
clean up the runtime that consumes it.

Dependency rule: per SRAM buffer keep a writers SET; a reader depends on all
current writers (occupancy=ISSUE when both are systolic-array ops, else
latency=DONE); a writer REPLACEs the set. The only exception is is_mm_accum (a
matmul that reads and writes the same buffer = a commutative accumulator): skip
its read edge and UNION its write, waiting only the non-matmul init seed and not
ordering co-matmuls. This drops the matmul-accumulator chain that deadlocked the
SA weight-slot pipeline while keeping the init->matmul edge, and lets a vector
epilogue or the store wait every K matmul (fixes the pure-vector store that an
empty COMPUTE_BAR let slip).

Remove COMPUTE_BAR entirely: a matmul is its own DONE-handle (finish == SA
drain), so the store JOINs the matmul writers directly. The whole emit/loader
chain is gone -- build_skeleton, lower_to_emitc, togsim.compute_barrier, the
runtime symbol, the Opcode/case/_fence_finish, and TraceRec::COMPUTE_BAR -- so a
stale producer fails loudly instead of emitting records the bridge would drop.
Only MEMORY_BAR remains (an async load's DONE is its data arrival, not issue).

Model compute-output spad footprint in the SRAM version/capacity machinery so
buffer reuse (WAR) is capacity-modeled, not a hard edge. The output size comes
from the DMA records that touch the same buffer (a buf_bytes pre-pass); an
in-place buffer (accumulator, relu) is version-transparent so footprint is not
double-counted. The occupy gate and version release sit in the MOVIN/MOVOUT/COMP
issue points (release before the COMP skip path so a skipped matmul still frees).

Runtime: collapse child_inst / _pipeline_children into one event-indexed
_deps[ISSUE|DONE] with add_dep(c, on) and fire(e); collapse the weight-slot
release queue and the async-load wakeup into one _due_events timed-effect table
drained by process_due_events. Both are behavior-preserving (byte-identical).

Require the weight-slot model: sa_weight_buffer_depth must be > 0 (errors at
init), and the round-robin disable mode is removed. Degenerate traces (a
consumer-less preload, an unpinned matmul) hit explicit error+exit guards rather
than asserts that vanish under NDEBUG.

Mark the legacy ONNX TOG path deprecated: it is superseded by the trace path, so
TileGraphParser logs a deprecation warning and the TORCHSIM_LEGACY_TOG=1 opt-in
warns at command build.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HAmdM9BrsTvfi8sZnnfNno
@YWHyuk
YWHyuk force-pushed the feature/bridge-dep-redesign branch from 03ccbcd to 8a77c88 Compare June 24, 2026 13:18
@YWHyuk
YWHyuk merged commit b7c1ec4 into feature/togsim-cpp-trace Jun 24, 2026
@YWHyuk
YWHyuk deleted the feature/bridge-dep-redesign branch July 8, 2026 06:52
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