Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/pytorchsim_triton_backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: Triton codegen route (PyTorchSim-Triton-Backend)

# Exercises the Triton codegen route: Inductor's own Triton backend produces the
# kernel and PyTorchSim-Triton-Backend lowers it to a RISC-V ELF.
# (PyTorchSimFrontend/triton_backend/README.md)
#
# Separate from the main CI on purpose: it runs when the compiler pin moves, and
# its sweep reports rather than gates.
Expand Down
9 changes: 0 additions & 9 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
[submodule "TOGSim/extern/onnx"]
path = TOGSim/extern/onnx
url = https://github.com/onnx/onnx.git
[submodule "TOGSim/extern/protobuf"]
path = TOGSim/extern/protobuf
url = https://github.com/protocolbuffers/protobuf.git
[submodule "TOGSim/extern/booksim"]
path = TOGSim/extern/booksim
url = https://github.com/PSAL-POSTECH/booksim.git
[submodule "TOGSim/extern/ramulator2"]
path = TOGSim/extern/ramulator2
url = https://github.com/PSAL-POSTECH/ramulator2
[submodule "TOGSim/extern/stonneCore"]
path = TOGSim/extern/stonneCore
url = https://github.com/PSAL-POSTECH/stonne_core.git
6 changes: 3 additions & 3 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ report next to the number it produced — never folded into a pass.
|---|---|
| `PyTorchSimFrontend/` | Python compiler stack (Inductor backend). `extension_config.py` is the central settings reader; `triton_backend/` is the `npu` codegen route (Inductor's Triton backend, the compiler bridge, and `trace_build.py` -- the gem5/g++ half of the TOGSim trace) |
| `PyTorchSimDevice/` | C++ PyTorch backend registering the `npu` device. Built as a pip-installed package via `setup.py`. Based on `torch_openreg` (PrivateUse1 example). Produces `_C.cpython-*.so` |
| `Simulator/simulator.py` | Python drivers: `CycleSimulator` (Gem5), `TOGSimulator` (the cycle-accurate one + multi-tenant context manager). Spike is driven by `triton_backend/functional.py` |
| `Simulator/simulator.py` | `TOGSimulator`: the TOGSim process driver and multi-tenant context manager. gem5 is driven by `triton_backend/gem5.py` (`CycleSimulator`), Spike by `triton_backend/spike_run.py` |
| `Scheduler/scheduler.py` | Poisson arrival generator + scheduling utilities for multi-tenant runs |
| `TOGSim/` | C++ TOGSim source. `src/Simulator.cc`, `Core.cc`, `Dram.cc`, `Interconnect.cc`, `L2Cache.cc`, `Tile.cc`, `TileGraph.cc` are the core models. Externals: ramulator2, booksim, stonneCore, onnx, protobuf, spdlog, yaml-cpp |
| `TOGSim/` | C++ TOGSim source. `src/Simulator.cc`, `Core.cc`, `Dram.cc`, `Interconnect.cc`, `L2Cache.cc`, `Tile.cc`, `TileGraph.cc` are the core models. Externals: ramulator2, booksim, spdlog, yaml-cpp |
| `configs/` | TOGSim hardware configs (YAML). The default is `systolic_ws_256x256_c1_simple_noc_tpuv6e_functional_only.yml` -- the same machine as `..._tpuv6e.yml` and one line apart, `pytorchsim_timing_mode: 0`. Naming pattern: `systolic_ws_<size>_c<cores>_<noc>_<target>.yml` |
| `tests/` | Op- and model-level tests organized under `ops/<family>/` (elementwise, reduce, gemm, conv, attention, view, sort, sparsity, misc, fusion), `models/<name>/` (Llama, Mixtral8x7B, DeepSeek, Diffusion, MoE, MLP, MobileNet, Yolov5) plus single-file model tests (test_resnet, test_transformer, test_vit, test_mlp, test_single_perceptron), and `system/` (scheduler, eager, vectorops). Shared helper: `tests/_utils.py`. **Which of them pass is `scripts/ci/triton_route_passing.txt`**; the rest are known gaps, swept and reported by `scripts/ci/triton_route_sweep.py --all` |
| `experiments/artifact/` | Paper reproduction scripts (`cycle_validation/run_cycle.sh`, `speedup/run_speedup.sh`) |
Expand All @@ -94,7 +94,7 @@ Run a model from `tests/models/Llama/`, `tests/models/DeepSeek/`, etc. similarly

**CI coverage:** `.github/workflows/docker-image.yml` is the PR gate. It builds the base image, then the PyTorchSim-Triton-Backend layer (`Dockerfile.ptb`, pinned by `thirdparty/pytorchsim-triton-backend.json`: the compiler plus the vcix-accelerator RISC-V toolchain, pk, Spike and gem5), then the app image, and calls `.github/workflows/pytorchsim_test.yml` once per hardware config. That workflow is a **matrix over `scripts/ci/triton_route_passing.txt`**, one Docker container per test — so adding a test file gates PRs only once it is in that allowlist. Regenerate the allowlist with `python scripts/ci/triton_route_sweep.py --all --update-allowlist` and mirror it into the workflow.

`.github/workflows/pytorchsim_triton_backend.yml` runs when the compiler pin itself moves: the compiler's own smoke kernels end to end, plus the full coverage sweep (allowlist *and* the rest, reported not gated). Both workflows need `secrets.TNPU_TOKEN` — `PSAL-POSTECH/PyTorchSim-Triton-Backend` is private. See `PyTorchSimFrontend/triton_backend/README.md`.
`.github/workflows/pytorchsim_triton_backend.yml` runs when the compiler pin itself moves: the compiler's own smoke kernels end to end, plus the full coverage sweep (allowlist *and* the rest, reported not gated). Both workflows need `secrets.TNPU_TOKEN` — `PSAL-POSTECH/PyTorchSim-Triton-Backend` is private.

**For fast iteration** (skip functional check):
```bash
Expand Down
24 changes: 0 additions & 24 deletions PyTorchSimDevice/csrc/aten/native/Extra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,6 @@ int64_t _fused_sdp_choice(
return static_cast<int64_t>(sdp::SDPBackend::error);
}

// q: (B, Hq, L, E) k/v: (B, H, S, E)
const int64_t Hq = query.size(-3);
const int64_t H = key.size(-3);
const int64_t L = query.size(-2); // query sequence length
const int64_t S = key.size(-2); // key/value sequence length

// Conditions required by the MLIR FlashSDPA kernel:
// Prefill only : L == S (decode has L == 1, not supported)
// Non-GQA : Hq == H (equal query and KV heads)
// No dropout : template has no dropout implementation
// Dense tensors : no nested tensor support
const bool can_use_mlir_flash =
(L == S) &&
(Hq == H) && !enable_gqa &&
sdp::check_for_dropout(params, /*debug=*/false) &&
sdp::check_nested_tensor(params, /*debug=*/false);

const bool ctx_flash = at::globalContext().userEnabledFlashSDP();
const bool ctx_math = at::globalContext().userEnabledMathSDP();

if (ctx_flash && can_use_mlir_flash) {
return static_cast<int64_t>(sdp::SDPBackend::overrideable);
}

return static_cast<int64_t>(sdp::SDPBackend::math);
}

Expand Down
2 changes: 1 addition & 1 deletion PyTorchSimDevice/torch_openreg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

# The `npu` codegen route: Inductor's own Triton codegen, lowered by the
# compiler passes. Registered here because Inductor registers a backend per
# device, once. See PyTorchSimFrontend/triton_backend/README.md.
# device, once.
from PyTorchSimFrontend.triton_backend import (
TritonNPUScheduling, TritonNPUWrapperCodegen)
torch._inductor.codegen.common.register_backend_for_device(
Expand Down
4 changes: 1 addition & 3 deletions PyTorchSimFrontend/extension_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
"script_systolic.py"))
CONFIG_VCIX_MODEL = os.environ.get("TORCHSIM_COMPILE_VCIX_MODEL", default=os.path.join(
os.environ.get("TORCHSIM_PREFIX", "/workspace"), "vcix-build", "libtpu.so"))
# the compiler runs in its own process. Both sides now hold the same LLVM 23 bindings,
# so the seam is a process boundary rather than a version one; `mlir` is a
# namespace package, and each side still selects its own root explicitly.
# the compiler runs in its own process, under this interpreter unless overridden.
CONFIG_TORCHSIM_COMPILE_PYTHON = os.environ.get("TORCHSIM_COMPILE_PYTHON", default=sys.executable)


Expand Down
6 changes: 2 additions & 4 deletions PyTorchSimFrontend/triton_backend/compiler_bridge.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""Run pytorchsim-triton-compiler, out of process.
"""Run pytorchsim-triton-compiler in its own process and read the kernel object it leaves.

the compiler's passes run on LLVM 23's MLIR python bindings and this process holds LLVM
20's. `mlir` is a NAMESPACE package, so two LLVMs in one interpreter merge
silently; the seam between them is a file, which is measured to work.
The seam is kernel.json in the kernel's workdir; nothing here imports the compiler.
"""

import json
Expand Down
16 changes: 5 additions & 11 deletions Simulator/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ def _send_command(self, command_type, device_index, stream_index, tog_path="", a
device_index: Device index
stream_index: Stream index
tog_path: kernel-dir handle; TOGSim derives trace.so/trace_cycles.tsv from
its directory (the ONNX file itself is only read on the STONNE sparse
path) - empty for DEVICE_SYNC
its directory - empty for DEVICE_SYNC
attribute_path: Path to attribute file - empty for DEVICE_SYNC
timestamp: Timestamp in nanoseconds (default: 0)

Expand Down Expand Up @@ -220,7 +219,6 @@ def launch_kernel(self, device_index, stream_index, tog_path, attribute_path, ti
device_index: Device index
stream_index: Stream index
tog_path: kernel-dir handle; TOGSim derives trace.so from its directory
(the ONNX file itself is only read on the STONNE sparse path)
attribute_path: Path to attribute file
timestamp: Timestamp in nanoseconds (default: 0)

Expand Down Expand Up @@ -286,7 +284,7 @@ def run_standalone(

Args:
model_path: kernel-dir handle; trace.so/trace_cycles.tsv are derived from
its directory (the ONNX file itself is only read on the STONNE sparse path)
its directory
attribute_path: Path to attribute file
autotune_mode: If True, run in autotune mode (silent)
config_path: Path to TOGSim config file (required)
Expand Down Expand Up @@ -323,16 +321,12 @@ def run_standalone(
os.fsync(trace_file.fileno())

try:
# Drive the simulation from the emitted trace.so (the C++ TOG path). The
# ONNX --models_list path remains only for callers without a trace.so (the
# STONNE sparse path); the normal compile always emits one.
trace_so = os.path.join(os.path.dirname(str(model_path)), "trace.so")
cycle_tsv = os.path.join(os.path.dirname(str(model_path)), "trace_cycles.tsv")
if not os.path.exists(trace_so):
raise FileNotFoundError(f"{trace_so} not found -- the kernel has no trace to simulate")
base_cmd = TOGSimulator.get_togsim_command(config_path, togsim_path)
if os.path.exists(trace_so):
cmd = f"{base_cmd} --trace_so {trace_so} --cycle_table {cycle_tsv}"
else: # ONNX TOG path (STONNE sparse)
cmd = f"{base_cmd} --models_list {trace_file_path}"
cmd = f"{base_cmd} --trace_so {trace_so} --cycle_table {cycle_tsv}"
if extension_config.CONFIG_TOGSIM_DEBUG_LEVEL:
cmd += f" --log_level {extension_config.CONFIG_TOGSIM_DEBUG_LEVEL}"

Expand Down
20 changes: 1 addition & 19 deletions TOGSim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/extern)

# C++ setttings
set(CMAKE_CXX_STANDARD 17)
set(ONNX_ML 1)
set(JSON_BuildTests OFF CACHE INTERNAL "")
set(EXECUTABLE_OUTPUT_PATH "${CMAKE_SOURCE_DIR}/build/bin")
set(LIBRARY_OUTPUT_PATH "${CMAKE_SOURCE_DIR}/build/lib")
Expand All @@ -35,24 +34,7 @@ include_directories("${PROJECT_SOURCE_DIR}/extern/ramulator2/resources/wrappers"
# Add libaray booksim
add_subdirectory("${PROJECT_SOURCE_DIR}/extern/booksim")

# Add libary protobuf
add_subdirectory("${PROJECT_SOURCE_DIR}/extern/protobuf/cmake" EXCLUDE_FROM_ALL)
set_target_properties(libprotoc PROPERTIES FOLDER "external/protobuf")
set_target_properties(protoc PROPERTIES FOLDER "external/protobuf")

# Add libaray stonne core
add_subdirectory("${PROJECT_SOURCE_DIR}/extern/stonneCore")

# Add libaray onnx
add_definitions("-DONNX_NAMESPACE=onnx")
add_subdirectory("${PROJECT_SOURCE_DIR}/extern/onnx" EXCLUDE_FROM_ALL)
set_target_properties(onnx PROPERTIES FOLDER "extern/onnx")
set_target_properties(onnx_proto PROPERTIES FOLDER "extern/onnx")

target_include_directories(Simulator PUBLIC ${PROJECT_SOURCE_DIR}/extern/stonneCore/include)
target_include_directories(Simulator PUBLIC ${PROJECT_SOURCE_DIR}/include)
target_include_directories(Simulator PUBLIC ${PROJECT_SOURCE_DIR}/include/scheduler)
target_include_directories(Simulator PUBLIC ${PROJECT_SOURCE_DIR}/src)
target_include_directories(Simulator PUBLIC ${ONNX_INCLUDE_DIRS})
target_link_libraries(Simulator booksim2 ramulator sstStonne)
target_link_libraries(Simulator ${PROTOBUF_LIB} onnx_proto sstStonne ${CONAN_LIBS} stdc++fs)
target_link_libraries(Simulator booksim2 ramulator ${CONAN_LIBS} stdc++fs)
1 change: 0 additions & 1 deletion TOGSim/extern/onnx
Submodule onnx deleted from f7ee1a
1 change: 0 additions & 1 deletion TOGSim/extern/protobuf
Submodule protobuf deleted from 0dab03
1 change: 0 additions & 1 deletion TOGSim/extern/stonneCore
Submodule stonneCore deleted from 978041
7 changes: 0 additions & 7 deletions TOGSim/include/DMA.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,6 @@ class DMA {
tag_table[subgraph_id][key] = 1;
}

void set_tag_sparse(int subgraph_id, std::vector<int64_t>& key) {
if (tag_table.find(subgraph_id) == tag_table.end()) {
throw std::runtime_error("Subgraph does not exist in tag_table");
}
tag_table[subgraph_id][key] = -1;
}

void mark_tag_used(int subgraph_id, std::vector<int64_t>& key) {
if (tag_table.find(subgraph_id) == tag_table.end()) {
throw std::runtime_error("Subgraph does not exist in tag_table");
Expand Down
3 changes: 0 additions & 3 deletions TOGSim/include/Instruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ class Instruction : public std::enable_shared_from_this<Instruction> {
if (_wait_keys.empty()) _wait_keys.push_back(_tag_key);
return _wait_keys;
}
bool is_sparse_inst() { return _is_sparse_inst; }
void set_sparse_state(bool state) { _is_sparse_inst = state; }
uint64_t get_global_inst_id() const { return _global_inst_id; }

// SRAM-capacity model (sec 10.4), filled by the bridge and enforced by Core: a
Expand Down Expand Up @@ -212,7 +210,6 @@ class Instruction : public std::enable_shared_from_this<Instruction> {
int _nr_inner_loop = 0;
bool _is_async_dma=false;
bool _is_indirect_mode=false;
bool _is_sparse_inst=false;
std::string _indirect_index_path="";
// SRAM-capacity model (see the setters above).
int64_t _sram_alloc_id = -1;
Expand Down
7 changes: 2 additions & 5 deletions TOGSim/include/SimulationConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <string>
#include <yaml-cpp/yaml.h>

enum class CoreType { WS_MESH, STONNE };
enum class CoreType { WS_MESH };

enum class DramType { SIMPLE, RAMULATOR2 };

Expand All @@ -20,16 +20,13 @@ struct SimulationConfig {

/* Core config */
std::vector<CoreType> core_type;
std::string stonne_config_path;
uint32_t num_cores;
uint32_t core_freq_mhz;
uint32_t core_print_interval = 0;
uint32_t num_systolic_array_per_core = 1;
uint32_t num_stonne_per_core = 1;
uint32_t num_stonne_port = 1;
// Per-core VMEM/spad capacity (KB) for the trace-path DMA throttle (sec 10.4): a
// load that would overflow the spad waits for a consumer to free a tile. 0 = unset
// -> disabled. Legacy TileGraphParser insts have alloc id -1 and are never gated.
// -> disabled.
uint32_t core_spad_size_kb = 0;
// SA weight-buffer depth (sec 10.4): weight tiles a systolic array holds; a
// preload stalls until a slot frees (its matmuls finished). 2 = weight
Expand Down
1 change: 0 additions & 1 deletion TOGSim/include/Simulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <yaml-cpp/yaml.h>
#include "Common.h"
#include "Core.h"
#include "SparseCore.h"
#include "Dram.h"
#include "Interconnect.h"
#include "scheduler/Scheduler.h"
Expand Down
93 changes: 0 additions & 93 deletions TOGSim/include/SparseCore.h

This file was deleted.

3 changes: 0 additions & 3 deletions TOGSim/include/Tile.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ class Tile : public std::enable_shared_from_this<Tile> {
bool all_insts_finshed() { return _nr_insts == _nr_finished_insts; }
void* get_custom_data() { return _custom_data; }
void set_custom_data(void* custom_data ) { _custom_data = custom_data; }
void set_stonne_tile(bool stonne_tile) { _stonne_tile = stonne_tile; }
bool is_stonne_tile() { return _stonne_tile; }

protected:
std::shared_ptr<TileSubGraph> _onwer_graph;
Expand All @@ -88,7 +86,6 @@ class Tile : public std::enable_shared_from_this<Tile> {
int _scan_weight_free = 0;
std::vector<std::shared_ptr<Tile>> _child_tiles;
void *_custom_data=NULL;
bool _stonne_tile=false;
};

#endif
1 change: 0 additions & 1 deletion TOGSim/include/TileGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ class TileGraph {
void init_cache_plan(IntervalTree<unsigned long long, int>::interval_vector it) {
_cache_plan = std::make_shared<IntervalTree<unsigned long long, int>>(std::move(it));
}
bool StonneGraph = false;

class Iterator {
public:
Expand Down
Loading