Repository navigation
Tensors at simulated DRAM addresses, the same for TOGSim and Spike - #531
Merged
student-Jungmin merged 7 commits intoNov 11, 2026
Merged
Conversation
…ice allocator The openreg MemoryManager now also allocates each device block a range of a simulated DRAM: from 0, aligned to 16 KiB (XLA's program HBM alignment, what TOGSim lays tensors out at), first fit over the holes freed blocks left, else above everything allocated. orFree frees the range, coalescing it with its neighbours, in the same call that unmaps the host pages and erases the block from the registry, so a host address reused after munmap never inherits an old range. orPointerGetSimAddress gives a device pointer's address: its block's range plus the pointer's offset in the block. The device allocator hands every storage its own block (no caching allocator sits on top), so this is the storage's base plus (data_ptr - storage.data_ptr()), and a buffer Inductor reuses keeps its address. torch.npu.sim_address(tensor) and torch.npu.sim_address_alignment() expose it through the device module's own Python surface; no private torch API is involved. The space is unbounded here: the machine, and with it address_map.dram_size, is known only when a launch is timed, and the timing path refuses a launch whose tensors end past it (the next commit). The timing path's tog_tensor_addrs.txt (next commit) is what reads this; tests/system/test_tensor_placement.py pins both.
…r_addrs.txt, and an older TOGSim is refused TOGSim laid every launch's tensor arguments out from address 0, so in one session a buffer one kernel wrote sat at another address when the next kernel read it, unrelated tensors shared addresses, and the DRAM channels and the L2 saw that layout. The original PyTorchSim gave TOGSim each tensor's host data_ptr; the trace path had dropped it. run_togsim now writes tog_tensor_addrs.txt into the launch directory beside tog_tensors.txt: one line per kernel object argument in argument order, "name addr bytes align role", addr the simulated DRAM address the device allocator gave the launch tensor's storage plus its offset (torch.npu.sim_address), bytes as tog_tensors.txt states them, align the alignment addr has (at most the allocator's 16 KiB), role the manifest's. Copy nodes get a copy beside theirs. A launch whose argument ends past the machine's address_map.dram_size is refused; a launch that passes no tensor writes none and logs why. Template timing has no host tensors and writes none. get_togsim_command runs Simulator --version once per binary and mtime and refuses anything older than 1.1.0 or of another major (an old Simulator has no --version), so the file is never silently ignored. A session checks before it makes its FIFO. Verified: tests/system/test_tensor_placement.py (new; in CI and the route allowlist) puts a buffer one kernel writes and the next reads at one address in both launches' files, keeps live storages disjoint and reuses a freed range; it fails on dram-trace 5448859 (no file). test_togsim_exit pins the version refusal, and its and test_togsim_result's stub Simulators answer --version. test_launch_record, test_launch_dir, test_copy_node, test_togsim_result, test_togsim_exit, test_one_layer_kv_write pass; Qwen3-0.6B layer decode 128 and prefill 64 run with every launch at given addresses. Needs TOGSim 1.1.0 (TOGSim dram-trace 4d5959a), which PyTorchSim-Triton-Backend dram-trace 3f3e3a28 pins; with the c4a6ee2b image this pin names, the timing path refuses to run until the pin moves. Depends on the previous [Device] commit.
…r_addrs.txt in each launch's runtime directory The address file is the one per-launch file both simulators read, so it moves out of the timing path into a module of its own, pytorchsim/simulator/placement.py, which functional and timing both import: write_tensor_addrs(workdir, meta, args, launch_dir=None) writes it for Spike into runtime/ beside the .raw files, where the compiler's wrapper reads it and maps each tensor at address_map.dram_base plus its address, or, given launch_dir, for TOGSim into the launch directory beside tog.so. One function produces the lines for both; the file's name and line format are the compiler's kernel_object.TENSOR_ADDRS_FILE and tensor_addr_line. tensor_args and ShapeMismatch move with it, and functional re-exports both under their old names. A launch whose tensors are not npu ones (template timing runs its candidates on CPU zeros) or that passes none gets no file, a stale one removed, and the reason logged: the wrapper and TOGSim then lay the arguments out from 0. tests/system/test_spike_placement.py pins it: the runtime/ file equals the TOGSim launch directory's. On feat/tensor-placement it fails with FileNotFoundError on runtime/tog_tensor_addrs.txt. Measured with PyTorchSim-Triton-Backend feat/spike-placement: Qwen3-0.6B one layer, decode at 128 and prefill at 64, pass; the breakdown's Spike time went 11.27 s to 7.30 s (decode) and 13.86 s to 9.58 s (prefill) against feat/tensor-placement with dram-trace, as read inputs are mapped rather than read(); with the compiler's final wrapper (DRAM mapped whole to the last tensor), run on a node shared with a sweep, 17.28 s and 8.46 s. Qwen3-8B layer decode 1024 passes (max diff 0.0522), and every address its Spike launches print is dram_base plus the address its TOGSim launch was given. Depends on PyTorchSim-Triton-Backend dram-trace (kernel_object.TENSOR_ADDRS_FILE, tensor_addr_line, and the wrapper that reads the file); an older compiler has neither. Arguments that are views of one storage (K and V out of tokenwise pages, q/k/v out of one qkv) now overlap in DRAM, and the wrapper copies their .raw files over each other in argument order. flat_input writes each .raw as the storage's own span from the argument's offset, not zeros between its elements, so every overlapping .raw agrees; zeros there let a later argument zero an earlier one's values (test_fused_sdpa paged_kvcache err 0.83, test_gqa's GQA Attention 0.07). tests/system/test_overlapping_views_spike.py pins it: a * 2 + b over x[:, 0] and x[:, 1] matches the CPU, max abs diff 6.6 with the zero-filled .raw.
… not compiled for efb39c2 (2026-08-12) wrote the TOG's grid axis count to tog_axes.txt beside a reused tog.so and compared it with each launch's extents, because the TOG then read shape_args[k] without looking at the count the ABI hands it: a launch with one extent too few had it read past the list and loop to the value it found (test_gqa allocated tens of gigabytes). Since TOGSim 1.0.0 (2026-10-22) every TOG the compiler emits reads its shape through togsim::shape<N>, which exits 1 naming both counts when tog_shape.txt gives another number than N, grid extents and scalars together (TOGSim tests/kernels pins it). The file was a second copy of what kernel.json's abi.parallel_axes and the TOG itself state, checked more narrowly, so it and its check are removed; a mismatch now ends the run with TOGSim's message, which the timing path raises as for any TOGSim exit (test_togsim_exit).
…OGSim's sidecars by their new names The compiler pin moves from main 087e399b to the dram-trace branch's tip. That tip adds the masked-transfer DMA start and sizing in the TOG and the refusal of a masked start it cannot size, the release-token fix, the PtrAnalysis div and rem fixes, masked-off read rows parked inside their tensor, TOGSim 1.1.0 (tensors at the addresses tog_tensor_addrs.txt gives, sidecars renamed), and the wrapper that maps every tensor at dram_base plus its placement address. The device, timing and functional commits before this one need that compiler and that TOGSim; with the older image the timing path refuses its TOGSim 1.0.0. TOGSim 1.1.0 renames four files beside tog.so and refuses the old names, so the timing path writes and reads them by the new ones: tog_shape.txt -> tog_shape_args.txt, tog_tensors.txt -> tog_tensor_bytes.txt, tog_cycles.tsv -> tog_tile_cycles.tsv, tog_units.tsv -> tog_unit_table.tsv (timing, togsim, gem5, build_identity's stale patterns, and the stub TOGSim directories of test_togsim_exit and test_togsim_result). A workdir cached under the old names has no tables by the new ones, so they are measured again. The image comes from a manual run of that repository's images workflow on dram-trace, which publishes ghcr.io/psal-postech/pytorchsim-triton-backend:<sha>-<arch> like a main commit's.
student-Jungmin
changed the base branch from
pr/pts-6-system-tests-ci
to
pytorchsim-triton-backend
November 10, 2026 18:07
…am-trace commits the previous pin named PyTorchSim-Triton-Backend#396-#400 landed the dram-trace tip's commits on main, so the pin moves from that branch to main, where the images workflow publishes the base image. TOGSim comes along as main's third_party/TOGSim submodule, 7a35ffc (TOGSim#70).
…t with a published runtime image 2171fad6's images run never published <sha>-runtime: its simulate layer shard died on a runner with a full disk, so the manifest job was skipped. d02b86f1 (the merge of PyTorchSim-Triton-Backend#399) has the image and pins TOGSim at 7a35ffc. It lacks only #400 (kernel functions page-aligned, so gem5 tile cycles stop moving with the wrapper's size); values are unaffected, tile cycles may shift until the next pin bump brings it in.
student-Jungmin
merged commit Nov 11, 2026
a03ea67
into
pytorchsim-triton-backend
4 of 5 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Stacked on #530. Needs PSAL-POSTECH/PyTorchSim-Triton-Backend#399 and PSAL-POSTECH/TOGSim#70.
Every npu storage gets a simulated DRAM address from the device allocator, and each launch tells both simulators where its tensors are, in
tog_tensor_addrs.txt: TOGSim in the launch directory, Spike inruntime/, where the compiler's wrapper maps each tensor atdram_baseplus that address.tog_axes.txtgoes: the TOG refuses a shape_args count it was not compiled for.Arguments that are views of one storage (K and V out of tokenwise pages, q/k/v out of one qkv) now overlap in DRAM, and the wrapper copies their
.rawfiles over each other; each.rawholds the storage's own span from the argument's offset, not zeros between its elements, so they agree.Pins
third_partypins PyTorchSim-Triton-Backend and TOGSim at their DRAM-trace branch commits for now; they will be re-pinned to each repository'smainonce those PRs merge, before this one.Verification
All system tests on the top of the stack pass except test_compiler_failure, which fails the same way on
pytorchsim-triton-backend. test_overlapping_views_spike fails on the tree before (max abs diff 6.6); test_fused_sdpa's paged cases and test_gqa pass (they failed once arguments shared DRAM, before the.rawfix).