learning_gem5 part1_05 gem5 v24.1:使用 gem5 标准库配置脚本

gem5 标准库的引入改变了编写 gem5 配置脚本的方式。下文 gem5 v21.0 章节中提到的许多旧版配置脚本现已被弃用,转而推荐使用位于 configs/example/gem5_library 的 gem5 标准库配置脚本。

其目录结构简要如下:

复制代码
gem5_library
    |
    |- caches       #contains a configuration script for the octopi cache
    |
    |- checkpoints  #scripts for taking and restoring from checkpoints
    |
    |- dramsys      #scripts for using gem5 with dramsys
    |
    |- looppoints   #scripts for taking and restoring from looppoints
    |
    |- multisim     #scripts for launching multiple simulations at once using multisim
    |
    |- spatter_gen  #scripts for SpatterGen
    |
    |- (various example configuration scripts not sorted into a subdirectory)

直接放在 gem5_library 目录下的示例配置脚本与您在《Learning gem5》前面部分见过的类似,但种类更丰富(例如,不同的 ISA、主板和工作负载)。这些脚本的源代码可以在此处查看


gem5 v21.0:使用默认配置脚本

本章将探讨如何使用 gem5 自带的默认配置脚本。gem5 附带了许多配置脚本,使您能够快速使用 gem5。然而,一个常见的误区是在没有完全理解模拟内容的情况下使用这些脚本。在使用 gem5 进行计算机体系结构研究时,完全理解您所模拟的系统至关重要。本章将引导您了解默认配置脚本的一些重要选项和部分。

在前几章中,您已经从零开始创建了自己的配置脚本。这非常强大,因为它允许您指定每一个系统参数。然而,有些系统的设置非常复杂(例如,全系统 ARM 或 x86 机器)。幸运的是,gem5 开发人员提供了许多脚本来帮助构建系统。

目录结构概览

所有的 gem5 配置文件都可以在 configs/ 目录下找到。目录结构如下所示:

复制代码
configs/boot:
bbench-gb.rcS  bbench-ics.rcS  hack_back_ckpt.rcS  halt.sh

configs/common:
Benchmarks.py   Caches.py  cpu2000.py    FileSystemConfig.py  GPUTLBConfig.py   HMC.py       MemConfig.py   Options.py     Simulation.py
CacheConfig.py  cores      CpuConfig.py  FSConfig.py          GPUTLBOptions.py  __init__.py  ObjectList.py  SimpleOpts.py  SysPaths.py

configs/dist:
sw.py

configs/dram:
lat_mem_rd.py  low_power_sweep.py  sweep.py

configs/example:
apu_se.py  etrace_replay.py  garnet_synth_traffic.py  hmctest.py    hsaTopology.py  memtest.py  read_config.py  ruby_direct_test.py      ruby_mem_test.py     sc_main.py
arm        fs.py             hmc_hello.py             hmc_tgen.cfg  memcheck.py     noc_config  riscv           ruby_gpu_random_test.py  ruby_random_test.py  se.py

configs/learning_gem5:
part1  part2  part3  README

configs/network:
__init__.py  Network.py

configs/nvm:
sweep_hybrid.py  sweep.py

configs/ruby:
AMD_Base_Constructor.py  CHI.py        Garnet_standalone.py  __init__.py              MESI_Three_Level.py  MI_example.py      MOESI_CMP_directory.py  MOESI_hammer.py
CHI_config.py            CntrlBase.py  GPU_VIPER.py          MESI_Three_Level_HTM.py  MESI_Two_Level.py    MOESI_AMD_Base.py  MOESI_CMP_token.py      Ruby.py

configs/splash2:
cluster.py  run.py

configs/topologies:
BaseTopology.py  Cluster.py  CrossbarGarnet.py  Crossbar.py  CustomMesh.py  __init__.py  MeshDirCorners_XY.py  Mesh_westfirst.py  Mesh_XY.py  Pt2Pt.py

各目录简要说明如下:

  • boot/ : 这些是在全系统模式下使用的 rcS 文件。这些文件在 Linux 启动后由模拟器加载,并由 shell 执行。其中大多数用于在全系统模式下控制基准测试。有些是实用功能,如 hack_back_ckpt.rcS。这些文件在关于全系统模拟的章节中有更深入的介绍。

  • common/: 此目录包含许多用于创建模拟系统的辅助脚本和函数。

    复制代码
    `Options.py` contains a variety of options that can be set on the
    command line. Like the number of CPUs, system clock, and many, many
    more. This is a good place to look to see if the option you want to
    change already has a command line parameter.
    
    `CacheConfig.py` contains the options and functions for setting
    cache parameters for the classic memory system.
    
    `MemConfig.py` provides some helper functions for setting the memory
    system.
    
    `FSConfig.py` contains the necessary functions to set up full-system
    simulation for many different kinds of systems. Full-system
    simulation is discussed further in it's own chapter.
    
    `Simulation.py` contains many helper functions to set up and run
    gem5. A lot of the code contained in this file manages saving and
    restoring checkpoints. The example configuration files below in
    `examples/` use the functions in this file to execute the gem5
    simulation. This file is quite complicated, but it also allows a lot
    of flexibility in how the simulation is run.
  • dram/: 包含测试 DRAM 的脚本。

  • example/ : 此目录包含一些可以直接使用的 gem5 示例配置脚本。特别是 se.pyfs.py 非常有用。关于这些文件的更多信息可以在下一节找到。此目录中还有一些其他的实用配置脚本。

  • learning_gem5/: 此目录包含《learning_gem5》书中出现的所有 gem5 配置脚本。

  • network/: 此目录包含 HeteroGarnet 网络的配置脚本。

  • nvm/: 此目录包含使用 NVM 接口的示例脚本。

  • ruby/: 此目录包含 Ruby 及其包含的缓存一致性协议的配置脚本。更多细节可以在关于 Ruby 的章节中找到。

  • splash2/: 此目录包含运行 splash2 基准测试套件的脚本,并提供一些选项来配置模拟系统。

  • topologies/: 此目录包含在创建 Ruby 缓存层次结构时可以使用的拓扑实现。更多细节可以在关于 Ruby 的章节中找到。

使用 se.pyfs.py

在本节中,我将讨论一些可以通过命令行传递给 se.pyfs.py 的常用选项。关于如何运行全系统模拟的更多细节可以在全系统模拟章节中找到。这里我将讨论这两个文件共有的选项。

本节讨论的大多数选项可以在 Options.py 中找到,并在 addCommonOptions 函数中注册。本节不详细说明所有选项。要查看所有选项,请使用 --help 运行配置脚本,或阅读脚本的源代码。

首先,让我们在没有任何参数的情况下运行 hello world 程序:

复制代码
build/X86/gem5.opt configs/example/se.py --cmd=tests/test-progs/hello/bin/x86/linux/hello

我们得到如下输出:

复制代码
gem5 Simulator System.  http://gem5.org
gem5 is copyrighted software; use the --copyright option for details.

gem5 version 21.0.0.0
gem5 compiled May 17 2021 18:05:59
gem5 started May 18 2021 00:33:42
gem5 executing on amarillo, pid 85168
command line: build/X86/gem5.opt configs/example/se.py --cmd=tests/test-progs/hello/bin/x86/linux/hello

Global frequency set at 1000000000000 ticks per second
warn: No dot file generated. Please install pydot to generate the dot file and pdf.
warn: DRAM device capacity (8192 Mbytes) does not match the address range assigned (512 Mbytes)
0: system.remote_gdb: listening for remote gdb on port 7005
**** REAL SIMULATION ****
info: Entering event queue @ 0.  Starting simulation...
Hello world!
Exiting @ tick 5943000 because exiting with last active thread context

然而,这根本不是一个非常有趣的模拟!默认情况下,gem5 使用原子 CPU 和原子内存访问,所以没有报告任何真实的时间数据!为了确认这一点,您可以查看 m5out/config.ini。CPU 信息显示在第 51 行左右:

复制代码
[system.cpu]
type=X86AtomicSimpleCPU
children=interrupts isa mmu power_state tracer workload
branchPred=Null
checker=Null
clk_domain=system.cpu_clk_domain
cpu_id=0
do_checkpoint_insts=true
do_statistics_insts=true

为了在时序模式下实际运行 gem5,让我们指定一个 CPU 类型。同时,我们也可以指定 L1 缓存的大小。

复制代码
build/X86/gem5.opt configs/example/se.py --cmd=tests/test-progs/hello/bin/x86/linux/hello --cpu-type=TimingSimpleCPU --l1d_size=64kB --l1i_size=16kB

输出:

复制代码
gem5 Simulator System.  http://gem5.org
gem5 is copyrighted software; use the --copyright option for details.

gem5 version 21.0.0.0
gem5 compiled May 17 2021 18:05:59
gem5 started May 18 2021 00:36:10
gem5 executing on amarillo, pid 85269
command line: build/X86/gem5.opt configs/example/se.py --cmd=tests/test-progs/hello/bin/x86/linux/hello --cpu-type=TimingSimpleCPU --l1d_size=64kB --l1i_size=16kB

Global frequency set at 1000000000000 ticks per second
warn: No dot file generated. Please install pydot to generate the dot file and pdf.
warn: DRAM device capacity (8192 Mbytes) does not match the address range assigned (512 Mbytes)
0: system.remote_gdb: listening for remote gdb on port 7005
**** REAL SIMULATION ****
info: Entering event queue @ 0.  Starting simulation...
Hello world!
Exiting @ tick 454646000 because exiting with last active thread context

现在,让我们检查 config.ini 文件,确保这些选项正确地传递到了最终系统中。如果您在 m5out/config.ini 中搜索 "cache",您会发现没有创建任何缓存!尽管我们指定了缓存大小,但我们没有指定系统应该使用缓存,所以它们没有被创建。正确的命令行应该是:

复制代码
build/X86/gem5.opt configs/example/se.py --cmd=tests/test-progs/hello/bin/x86/linux/hello --cpu-type=TimingSimpleCPU --l1d_size=64kB --l1i_size=16kB --caches

输出:

复制代码
gem5 Simulator System.  http://gem5.org
gem5 is copyrighted software; use the --copyright option for details.

gem5 version 21.0.0.0
gem5 compiled May 17 2021 18:05:59
gem5 started May 18 2021 00:37:03
gem5 executing on amarillo, pid 85560
command line: build/X86/gem5.opt configs/example/se.py --cmd=tests/test-progs/hello/bin/x86/linux/hello --cpu-type=TimingSimpleCPU --l1d_size=64kB --l1i_size=16kB --caches

Global frequency set at 1000000000000 ticks per second
warn: No dot file generated. Please install pydot to generate the dot file and pdf.
warn: DRAM device capacity (8192 Mbytes) does not match the address range assigned (512 Mbytes)
0: system.remote_gdb: listening for remote gdb on port 7005
**** REAL SIMULATION ****
info: Entering event queue @ 0.  Starting simulation...
Hello world!
Exiting @ tick 31680000 because exiting with last active thread context

在最后一行,我们看到总时间从 454646000 ticks 减少到 31680000 ticks,快了很多!看起来缓存可能已经启用了。但是,最好再次检查 config.ini 文件。

复制代码
[system.cpu.dcache]
type=Cache
children=power_state replacement_policy tags
addr_ranges=0:18446744073709551615
assoc=2
clk_domain=system.cpu_clk_domain
clusivity=mostly_incl
compressor=Null
data_latency=2
demand_mshr_reserve=1
eventq_index=0
is_read_only=false
max_miss_count=0
move_contractions=true
mshrs=4
power_model=
power_state=system.cpu.dcache.power_state
prefetch_on_access=false
prefetcher=Null
replace_expansions=true
replacement_policy=system.cpu.dcache.replacement_policy
response_latency=2
sequential_access=false
size=65536
system=system
tag_latency=2
tags=system.cpu.dcache.tags
tgts_per_mshr=20
warmup_percentage=0
write_allocator=Null
write_buffers=8
writeback_clean=false
cpu_side=system.cpu.dcache_port
mem_side=system.membus.cpu_side_ports[2]

se.pyfs.py 的一些常用选项

所有可能的选项都可以通过运行以下命令查看:

复制代码
build/X86/gem5.opt configs/example/se.py --help
复制代码

以下是该列表中的一些重要选项:

  • --cpu-type=CPU_TYPE: 要使用的 CPU 类型。这是一个需要始终设置的重要参数。默认是 atomic,它不执行时序模拟。

  • --sys-clock=SYS_CLOCK: 以系统速度运行的模块的顶层时钟。

  • --cpu-clock=CPU_CLOCK: 以 CPU 速度运行的模块的时钟。这与上面的系统时钟是分开的。

  • --mem-type=MEM_TYPE: 要使用的内存类型。选项包括不同的 DDR 内存和 Ruby 内存控制器。

  • --caches: 使用经典缓存进行模拟。

  • --l2cache: 如果使用经典缓存,则模拟包含 L2 缓存。

  • --ruby: 使用 Ruby 而不是经典缓存作为缓存系统模拟。

  • -m TICKS, --abs-max-tick=TICKS: 运行到指定的绝对模拟 tick(包括从恢复的检查点开始的 ticks)。如果您只想模拟特定的模拟时间,这很有用。

  • -I MAXINSTS, --maxinsts=MAXINSTS: 要模拟的指令总数(默认:永远运行)。如果您想在执行一定数量的指令后停止模拟,这很有用。

  • -c CMD, --cmd=CMD: 在系统调用模拟模式下运行的二进制文件。

  • -o OPTIONS, --options=OPTIONS: 传递给二进制文件的选项,在整个字符串周围使用 " "。当您运行一个需要选项的命令时,这很有用。您可以通过此变量传递参数和选项(例如 --whatever)。

  • --output=OUTPUT: 将标准输出重定向到文件。如果您想将模拟应用程序的输出重定向到文件而不是打印到屏幕,这很有用。注意:要重定向 gem5 输出,您必须在配置脚本之前传递参数。

  • --errout=ERROUT: 将标准错误重定向到文件。与上面类似。

    https://github.com/gem5/website/blob/stable/_pages/documentation/learning_gem5/part1/part1_5_gem5_example_configs.md

相关推荐
Eloudy7 小时前
gem5 的统计包 和 API
arch·gem5
Eloudy2 天前
learning_gem5 part1_04 理解gem5统计信息与输出文件
gpu·arch·gem5
Eloudy3 天前
learning_gem5 part1_02 创建简单的配置脚本
gem5
Eloudy3 天前
全文 -- GPU-Initiated Networking for NCCL
gpu·arch
HyperAI超神经3 天前
【TVM 教程】优化大语言模型
人工智能·语言模型·自然语言处理·cpu·gpu·编程语言·tvm
Eloudy3 天前
learning_gem5 part1_01 构建 gem5
gem5
Felven4 天前
天数智芯MR50推理卡测试
gpu·推理·mr50·天数
杰克逊的日记4 天前
slurm部署
cpu·gpu·作业管理
Eloudy4 天前
AMD Instinct MI300 系列 GPU 技术规格说明
gpu