且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 gem5 Full System 中编译和运行 C 程序(使用 OpenMP)?

更新时间:2023-11-11 11:30:16

我如何编译和运行这个程序?我的意思是我将这个程序文件(matmul.c)存储在哪个文件夹中进行编译?我如何创建这个程序的目标文件?

How can I compile and run this program? I mean inside which folder I stored this program file (matmul.c) for compile? How I create object file of this program?

如何交叉编译图像不是 gem5 特定的,所以我会简短.

How to cross compile for an image is not gem5 specific, so I'll be brief.

首先,您必须获得图像的交叉编译器.

First you must obtain a cross compiler for the image.

***的方法是从与图像相同的来源获取交叉编译器,以确保兼容性.

The best way to do that, is to get a cross compiler from the same source as the image to ensure compatibility.

我的首选方法是使用最少的 Buildroot 映像.构建根:

My preferred approach is to use minimal Buildroot images. Buildroot:

  • 为我构建交叉编译器和映像,从而确保兼容性
  • 使用其软件包系统可以轻松地自动构建新软件
  • 可以生成非常简单的图片,更适合gem5和架构研究

这是我在 GitHub 上的设置.它包含一个最小的 OpenMP/a> 我已经在 gem5 中成功运行.

This is my setup on GitHub. It contains a minimal OpenMP hello world which I have successfully run inside of gem5.

另一个不错的选择是使用 https://crosstool-ng.github.io/

Another good option is to use https://crosstool-ng.github.io/

既然你想要 OpenMP 支持,你必须构建支持的 GCC 交叉编译器.

Since you want OpenMP support, you must build the GCC cross compiler compiler with support.

我认为这是在 GCC 中完成的:

I think this is done in GCC with:

./configure --enable-libgomp

或通过 Buildroot 选项:

or through the Buildroot option:

BR2_GCC_ENABLE_OPENMP=y

然后在编译时,必须将-fopenmp选项传递给gcc.

And then when compiling, you must pass the -fopenmp option to gcc.

如何更改处理器数量和缓存大小?

How can I change the number of processors and the cache memory size?

自己回答这个问题的***方法是使用类似的东西:

The best way to answer that question yourself is to use something like:

./build/ARM/gem5.opt configs/example/fs.py -h

并搜索选项.

你遇到了:

  • -n NUM_CPUS,--num-cpus=NUM_CPUS.

对于 ARM,您还需要传递带有相应内核数的 .dtb,例如:./system/arm/dt/armv7_gem5_v1_2cpu.dtb 用于 2 个内核.

For ARM you also need to pass a .dtb with the corresponding core count, e.g.: ./system/arm/dt/armv7_gem5_v1_2cpu.dtb for 2 cores.

缓存:您会很容易找到以下选项:

caches: you will find the following options easily:

 --caches --l1d_size=1024 --l1i_size=1024 --l2cache --l2_size=1024 --l3_size=1024

但请记住:

  • the Linux kernel does not see the cache sizes correctly as of fbe63074e3a8128bdbe1a5e8f6509c565a3abbd4 How to switch CPU models in gem5 after restoring a checkpoint and then observe the difference?
  • caches only affect certain CPU types, usually the more detailed such as ARM HPI and x86 DerivO3CPU, but not AtomicSimpleCPU.