Ubuntu20.04搭建gem5并运行helloworld

文章目录

相关资料

  1. gem5官网
  2. 知乎-计算机体系结构-gem5模拟器入门
  3. gem5:Hello World Tutorial

一、安装gem5

1.下载依赖

bash 复制代码
sudo apt install build-essential git m4 scons zlib1g zlib1g-dev \
    libprotobuf-dev protobuf-compiler libprotoc-dev libgoogle-perftools-dev \
    python3-dev python-is-python3 libboost-all-dev pkg-config

从github或gitee上拷贝gem5代码

bash 复制代码
git clone https://gitee.com/koverlu/gem5.git

拷贝完成后,会多一个gem5的目录我们进入该目录,在执行对应的构建命令。这里构建的是X86架构,如果要构建ARM或其他架构同理

bash 复制代码
cd gem5
scons build/X86/gem5.opt -j9

构建完成后,如果没有错误,说明构建成功。在gem5目录下会多一个名为build的目录。

二、运行helloworld

在安装完gem5的环境后,我们可以编写对应的helloworld程序进行测试。在根目录下(gem5目录下),新建一个名为hello-world.py的python文件。

python 复制代码
from gem5.isas import ISA
from gem5.components.boards.simple_board import SimpleBoard
from gem5.components.cachehierarchies.classic.no_cache import NoCache
from gem5.components.memory.single_channel import SingleChannelDDR3_1600
from gem5.components.processors.simple_processor import SimpleProcessor
from gem5.components.processors.cpu_types import CPUTypes
from gem5.resources.resource import Resource
from gem5.simulate.simulator import Simulator


# Obtain the components.
cache_hierarchy = NoCache()
memory = SingleChannelDDR3_1600("1GiB")
processor = SimpleProcessor(cpu_type=CPUTypes.ATOMIC, isa=ISA.x86, num_cores=1)

#Add them to the board.
board = SimpleBoard(
    clk_freq="3GHz",
    processor=processor,
    memory=memory,
    cache_hierarchy=cache_hierarchy,
)

# Set the workload.
binary = Resource("x86-hello64-static")
board.set_se_binary_workload(binary)

# Setup the Simulator and run the simulation.
simulator = Simulator(board=board)
simulator.run()

这个例子演示了一个最简单的环境,没有Cache,CPU直连主存。值得一提的是,官方文档上给的helloworld示例有问题,SimpleProcessor函数需要有三个参数,还需要指定ISA,在最上方也需要引入from gem5.isas import ISA。否则执行会报错。

使用如下命令运行该程序,如果输出Hello World!,则说明成功.

bash 复制代码
./build/X86/gem5.opt hello-world.py
相关推荐
若云止水33 分钟前
Ubuntu 下 nginx-1.24.0 源码分析 - ngx_init_cycle 函数 - 详解(4)
数据库·nginx·ubuntu
紫雾凌寒33 分钟前
计算机视觉 |解锁视频理解三剑客——TimeSformer
python·深度学习·神经网络·计算机视觉·transformer·timesformer
程序员杰哥1 小时前
测试用例详解
自动化测试·软件测试·python·功能测试·测试工具·职场和发展·测试用例
go54631584657 小时前
本地部署 GitHub 上的 Python 人脸识别项目
开发语言·python·github
FreakStudio8 小时前
手把手教你用 MicroPython 玩转幻尔串口舵机,代码+教程全公开
python·嵌入式·大学生·面向对象·技术栈·电子diy·电子计算机
tekin8 小时前
基于 Python 开发在线多人游戏服务器案例解析
服务器·python·游戏·在线多人游戏服务器
让学习成为一种生活方式10 小时前
libGL.so.1: cannot open shared object file: No such file or directory-linux022
linux·开发语言·python
java1234_小锋10 小时前
一周学会Flask3 Python Web开发-Jinja2模板继承和include标签使用
python·flask·flask3
图书馆钉子户10 小时前
from flask_session import Session 为什么是Session(app)这么用?
python·flask·mybatis
一只蜗牛儿11 小时前
Sherpa-ONNX:说话人识别与语音识别自动开启(VAD)+ Python API 完整指南
人工智能·python·语音识别