Indian Institute of Technology, Kharagpur
High Performance Computer Architecture (CS60003)
gem5 Simulator - Tutorial
Anirban Chakraborty
Teaching Assistant
[Link]@[Link]
gem5 Simulator - Tutorial High Performance Computer Architecture (CS60003) – IIT Kharagpur 1
Outline
• What is gem5?
• Key Features
• System Requirements
• Build and Run
• gem5 Architecture
• Example Scripts
• Understanding gem5 output
• Additional material
gem5 Simulator - Tutorial High Performance Computer Architecture (CS60003) – IIT Kharagpur 2
What is gem5?
Michigan m5 + Wisconsin GEMS = gem5
“The gem5 simulator is a modular platform for computer-
system architecture research, encompassing system-level
architecture as well as processor microarchitecture.”
Nathan Binkert, Bradford Bechmann, Gabriel Black, Steven K. Reinhardt, Ali Saidi, Arkaprava Basu, Joel Hestness, Derek R.
Hower, Tushar Krishna, Somayeh Sardashti, Rathijit Sen, Korey Sewell, Muhammad Shoaib, Nilay Vaish, Mark D. Hill and David
A. Wood. 2011. The gem5 simulator. SIGARCH Computer Architecture News 39, 2 (August 2011), 1-7.
gem5 Simulator - Tutorial High Performance Computer Architecture (CS60003) – IIT Kharagpur 3
Key Features
• Execution modes: System-call Emulation (SE), Full System (FS)
• Available binaries: [Link], [Link], [Link], [Link],
[Link]
• ISAs: ALPHA, ARM, MIPS, POWER, RISC-V, SPARC, x86 and NULL
• CPU models: AtomicSimple, TimingSimple, InOrder, O3
• Memory models: Classic, Ruby
• Interconnection Networks: Simple, Garnet
gem5 Simulator - Tutorial High Performance Computer Architecture (CS60003) – IIT Kharagpur 4
System Requirements
• Platforms
• Linux, BSD, MacOS, Solaris
• 64 bit machine is an advantage
• Dependencies
• Git / Mercurial
• Gcc/ g++ 4.8+
• Python 2.7+
• Scons 0.98.1+
• SWIG 2.0.4+
• M4
• Zlib
gem5 Simulator - Tutorial High Performance Computer Architecture (CS60003) – IIT Kharagpur 5
Build and Run
• Install Dependencies (Ubuntu)
sudo apt install build-essential git m4 scons zlib1g zlib1g-dev
libprotobuf-dev protobuf-compiler libprotoc-dev libgoogle-perftools-dev
python-dev python
• Get gem5
git clone [Link]
• Build gem5
scons build/X86/[Link] -j9
High Performance Computer Architecture (CS60003) – IIT
gem5 Simulator - Tutorial 6
Kharagpur
Build and Run (contd.)
High Performance Computer Architecture (CS60003) – IIT
gem5 Simulator - Tutorial 7
Kharagpur
The Build Process
> scons build/X86/[Link] –j9
build/X86/[Link]:
scons: the build system that
“parameter” passed to scons.
gem5 uses (similar to make)
Gem5’s Sconscript interprets this.
opt: version of executable to
X86: specifies the default
compile (other types are debug,
build options for x86 ISA.
perf, fast, etc.)
High Performance Computer Architecture (CS60003) – IIT
gem5 Simulator - Tutorial 8
Kharagpur
Build and Run (contd.)
High Performance Computer Architecture (CS60003) – IIT
gem5 Simulator - Tutorial 9
Kharagpur
gem5 architecture
• gem5 consists of “SimObjects”
• most C++ objects in gem5 inherit from class SimObjects
• represent physical system components
• gem5 completely controlled by Python scripts
• All (C++) SimObjects are exposed to Python
High Performance Computer Architecture (CS60003) – IIT
gem5 Simulator - Tutorial 10
Kharagpur
Our 1st config script
• Simple CPU connected
to a memory bus
(without cache)
High Performance Computer Architecture (CS60003) – IIT
gem5 Simulator - Tutorial 11
Kharagpur
Running config script
> build/X86/[Link]
configs/tutorial/[Link]
build/X86/[Link]: the configs/[…]/[Link]: the
gem5 binary to run configuration script
High Performance Computer Architecture (CS60003) – IIT
gem5 Simulator - Tutorial 12
Kharagpur
2nd config script
• Adding two levels of
cache memories into
our simple script
High Performance Computer Architecture (CS60003) – IIT
gem5 Simulator - Tutorial 13
Kharagpur
Understanding gem5 output
> m5out
[Link]: detailed
[Link]: dumps
statistics output. Each
all the parameters [Link]:
SimObject defines and
of all SimObjects same as
update statistics. They
used. This shows [Link], but
are printed here at
exactly what you in json format
the end of the
simulated
simulation
High Performance Computer Architecture (CS60003) – IIT
gem5 Simulator - Tutorial 14
Kharagpur
Conclusion
• Additional material
[Link]
High Performance Computer Architecture (CS60003) – IIT
gem5 Simulator - Tutorial 15
Kharagpur