TL;DR
SCALE-Sim TPU extends the popular cycle-accurate systolic simulator by validating its performance metrics against production-grade Google TPU v4 hardware and adding lightweight machine learning models for non-systolic elementwise operations. By integrating a unified StableHLO frontend, it allows researchers to estimate whole-model latency directly from standard JAX and PyTorch compilation pipelines with high accuracy.
What Problem Does This Paper Address?
Systolic-array accelerators, such as Google’s Tensor Processing Units (TPUs), are the workhorses behind modern deep learning. To explore new architectures and optimize software, researchers rely heavily on cycle-accurate simulators like SCALE-Sim. However, traditional simulators suffer from two major limitations:
- Lack of Real-Hardware Validation: They are rarely calibrated against actual production accelerators, leaving their predictive accuracy uncertain.
- Oversimplified Workload Coverage: They focus almost exclusively on systolic kernels (like matrix multiplication and convolution). In reality, non-systolic elementwise operations (such as additions, activations, and normalizations) can account for up to 73% of total inference time, creating a massive blind spot for end-to-end performance estimation.
Furthermore, most simulators require custom, hand-written topology descriptions, making them difficult to integrate with modern machine learning compiler stacks.
Methods
The authors introduce SCALE-Sim TPU, an extended toolchain that bridges the gap between simulation and real hardware through three main components:
- StableHLO Frontend: Instead of relying on manual configuration files, the tool directly ingests StableHLO intermediate representation (IR) generated by JAX or PyTorch. A parser extracts operator metadata (shapes, types, and attributes) and automatically routes them to the correct backend model.
- TPU-Grounded GEMM Calibration: The authors map abstract simulated cycle counts to actual wall-clock time on a Google TPU v4 using regime-specific linear regression models ($t = \alpha \cdot \text{cycles} + \beta$).
- Learned Elementwise Models: For non-systolic operations (e.g.,
add,ReLU), they employ a Histogram-based Gradient Boosting Regressor (HGBR). This machine learning model uses static features—tensor size and shape—to predict execution latency, successfully capturing non-linear behaviors caused by hardware tiling and alignment boundaries.
Datasets
The authors generated custom profiling datasets directly on Google TPU v4 hardware to train and validate their models:
- GEMM Sweep: A structured parameter sweep across matrix dimensions ($M, K, N$) broken into small (32–128), medium (128–1024), and large (1024–4096) size regimes.
- Elementwise Sweep: A dataset consisting of
bf16tensor shapes with total sizes sampled log-uniformly up to ~16 million elements. This included multiple factorizations of identical total element counts and shapes near hardware-relevant boundaries (like powers of two) to expose the model to alignment and vectorization effects.
Key Insights and Ideas
- Cycles Map Linearly to Time: Across different matrix size regimes, simulated cycles show a remarkably strong linear relationship with real hardware latency. This means a simple linear calibration can reliably convert abstract simulation cycles into physical time.
- Shape Matters, Not Just Size: For elementwise operations, tensors with the exact same number of elements can exhibit different latencies depending on their dimensional layout. This is due to compiler choices around vectorization, tiling, and memory alignment, justifying the use of tree-based machine learning models (HGBR) over simple linear scaling.
- Compiler IR as the Universal Interface: Moving away from custom simulator configurations to a standardized compiler IR (StableHLO) makes architectural simulation practical and reproducible for real-world, full-scale models.
Key Results
- GEMM Validation: The linear regression models achieved an $R^2$ score higher than 0.97 for medium and large matrix sizes, demonstrating that simulated cycles explain almost all the variance in real TPU execution time. The overall $R^2$ across all swept shapes was 0.893.
- Elementwise Latency Prediction: The HGBR models achieved exceptional accuracy. For elementwise addition, the model reached an $R^2$ of 0.9973 with a median relative error of just 1.78%. For ReLU, it achieved an $R^2$ of 0.9980 and a median relative error of 2.55%.
Limitations and Future Work
- Mid-Range GEMM Deviations: The model exhibits higher aggregate error (an overall Mean Absolute Percentage Error of 32.2%) in medium-sized GEMM workloads. This discrepancy likely stems from unmodeled system-level effects like compiler-driven kernel fusion, data movement, and scheduling overheads.
- Small Tensor Overhead: For very small tensors, absolute errors are slightly higher because fixed runtime overheads dominate execution time, which can be harder to predict precisely.
- Future Work: The authors plan to expand the learned latency models to cover a wider variety of non-systolic operations (like reductions, normalization, and attention mechanisms) and incorporate more sophisticated memory-bandwidth modeling.
Summary updated