Skip to content

Latest commit

History

922 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

M2Sim: Cycle-Accurate Apple M2 CPU Simulator

Build StatusGo Report CardLicense

M2Sim is a cycle-accurate simulator for the Apple M2 CPU that achieves 16.9% average timing error across 18 benchmarks. Built on the Akita simulation framework, M2Sim enables detailed performance analysis of ARM64 workloads on Apple Silicon architectures.

🎯 Project Status: COMPLETED

Final Achievement: 16.9% average timing accuracy across 18 benchmarks, meeting all success criteria.

Success CriterionTargetAchievedStatus
Functional EmulationARM64 user-space execution✅ Complete
Timing Accuracy<20% average error16.9% achieved
Modular DesignSeparate functional/timing✅ Implemented
Benchmark Coverageμs to ms range18 benchmarks validated

🚀 Quick Start

Prerequisites

  • Go 1.21 or later
  • ARM64 cross-compiler (aarch64-linux-musl-gcc)
  • Python 3.8+ (for analysis tools)

Installation

# Clone the repository
git clone https://github.com/sarchlab/m2sim.git
cd m2sim
# Build the simulator
go build ./...
# Run tests
ginkgo -r
# Build main binary
go build -o m2sim ./cmd/m2sim

Basic Usage

# Functional emulation only
./m2sim -elf benchmarks/arithmetic.elf
# Cycle-accurate timing simulation
./m2sim -elf benchmarks/arithmetic.elf -timing
# Fast timing approximation
./m2sim -elf benchmarks/arithmetic.elf -fasttiming

Reproduce Paper Results

# Run complete experimental validation
python3 reproduce_experiments.py
# Generate figures for paper
python3 paper/generate_figures.py
# Compile LaTeX papercd paper && pdflatex m2sim_micro2026.tex

📊 Performance Results

Timing Accuracy Summary

Benchmark CategoryCountAverage ErrorRange
Microbenchmarks1114.4%1.3% - 47.4%
PolyBench720.8%11.1% - 33.6%
Overall1816.9%1.3% - 47.4%

Key Architectural Insights

  • Branch Prediction: 1.3% error - validates M2's exceptional prediction accuracy
  • Cache Hierarchy: 3-11% error range - efficient L1I/L1D/L2 hierarchy modeling
  • Memory Bandwidth: High bandwidth utilization confirmed through concurrent operations
  • SIMD Performance: 24-30% error indicates complex vector unit timing (improvement area)

🏗️ Architecture Overview

Simulator Components

M2Sim Architecture
├── Functional Emulator (emu/) # ARM64 instruction execution
│ ├── Decoder # 200+ ARM64 instructions
│ ├── Register File # ARM64 register state
│ └── Syscall Interface # Linux syscall emulation
├── Timing Model (timing/) # Cycle-accurate performance
│ ├── Pipeline # 8-wide superscalar, 5-stage
│ ├── Cache Hierarchy # L1I/L1D (32KB), L2 (256KB)
│ └── Branch Prediction # Two-level adaptive predictor
└── Integration Layer # ELF loading, measurement framework

Pipeline Configuration

  • Architecture: 8-wide superscalar, in-order execution
  • Stages: Fetch → Decode → Execute → Memory → Writeback
  • Branch Predictor: Two-level adaptive with 12-cycle misprediction penalty
  • Cache Hierarchy: L1I/L1D (32KB each, 1-cycle), L2 (256KB, 10-cycle)

📁 Project Structure

m2sim/
├── cmd/m2sim/ # Main simulator binary
├── emu/ # Functional ARM64 emulator
├── timing/ # Cycle-accurate timing model
│ ├── core/ # CPU core timing
│ ├── cache/ # Cache hierarchy
│ ├── pipeline/ # Pipeline implementation
│ └── latency/ # Instruction latencies
├── benchmarks/ # Validation benchmark suite
│ ├── microbenchmarks/ # Targeted stress tests
│ └── polybench/ # Linear algebra kernels
├── docs/ # Documentation
│ ├── reference/ # Core technical references
│ ├── development/ # Historical development docs
│ └── archive/ # Archived analysis
├── results/ # Experimental results
│ ├── final/ # Completion reports
│ └── baselines/ # Hardware measurement data
├── paper/ # Research paper and figures
└── reproduce_experiments.py # Complete reproducibility script

🔬 Research Usage

Adding New Benchmarks

  1. Compile to ARM64 ELF:

    aarch64-linux-musl-gcc -static -O2 -o benchmark.elf benchmark.c
  2. Collect Hardware Baseline:

    # Use multi-scale regression methodology# Measure at multiple input sizes: 100, 500, 1K, 5K, 10K instructions# Apply linear regression: y = mx + b (m = per-instruction latency)
  3. Run Simulation:

    ./m2sim -elf benchmark.elf -timing -limit 100000
  4. Calculate Error:

    error = |t_sim - t_real| / min(t_sim, t_real)
    

Extending the Simulator

Multi-Core Support: Framework ready for cache coherence and shared memory SIMD Enhancement: Detailed vector pipeline for improved accuracy Out-of-Order: Register renaming for arithmetic co-issue Power Modeling: Leverage M2's efficiency characteristics

📋 Validation Methodology

Hardware Baseline Collection

  • Platform: Apple M2 MacBook Air (2022)
  • Measurement: 15 runs per data point, trimmed mean
  • Regression: Multi-scale linear fitting (R² > 0.999 required)
  • Validation: Statistical confidence intervals

Benchmark Suite Design

  • Microbenchmarks: Target individual architectural features
  • PolyBench: Intermediate-complexity linear algebra kernels
  • Coverage: Arithmetic, memory, branches, SIMD, dependencies

Error Analysis

  • Formula: Symmetric relative error measurement
  • Target: <20% average error across benchmark suite
  • Categories: Excellent (<10%), Good (10-20%), Acceptable (20-30%)

📖 Documentation

Core References

Research Papers

Development History

🏆 Achievements

Technical Milestones

  • H1: Core simulator with pipeline timing and cache hierarchy
  • H2: SPEC benchmark enablement with syscall coverage
  • H3: Microbenchmark calibration achieving 14.1% accuracy
  • H4: Multi-core analysis framework (statistical foundation complete)
  • H5: 15+ intermediate benchmarks with 16.9% average accuracy

Research Contributions

  1. First Open-Source M2 Simulator: Enables reproducible Apple Silicon research
  2. Validated Methodology: Multi-scale regression baseline collection
  3. Architectural Insights: Quantified M2 performance characteristics
  4. Production Accuracy: 16.9% error suitable for research conclusions

🔧 Development

Building from Source

# Development build with all checks
go build ./...
golangci-lint run ./...
ginkgo -r
# Performance profiling
go build -o profile ./cmd/profile
./profile -elf benchmark.elf -cpuprofile cpu.prof

Contributing

  1. Read:CLAUDE.md for development guidelines
  2. Test: Ensure all tests pass and lint checks succeed
  3. Document: Update relevant documentation for changes
  4. Validate: Verify accuracy on affected benchmarks

📄 Citation

If you use M2Sim in your research, please cite:

@inproceedings{m2sim2026,
title={M2Sim: Cycle-Accurate Apple M2 CPU Simulation with 16.9\% Average Timing Error},
author={M2Sim Team},
booktitle={Proceedings of the 59th IEEE/ACM International Symposium on Microarchitecture},
year={2026},
organization={IEEE/ACM}
}

🤝 Related Projects

  • Akita - Underlying simulation framework
  • MGPUSim - GPU simulator using Akita
  • SARCH Lab - Computer architecture research

📞 Support

📜 License

This project is developed by the SARCH Lab at [University/Institution].


M2Sim - Enabling Apple Silicon research through cycle-accurate simulation.

Generated: February 12, 2026 | Status: Project Complete ✅

About

Apple M2 CPU simulator using Akita framework

Resources

Stars

5 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages