How can i compile & run a c program (with OpenMP) in gem5 Full System?

邮差的信 提交于 2020-01-24 12:16:50

问题


I am an undergraduate student working on my thesis about parallel programming. I am using OpenMP model. Now i want to use gem5 for measure performance. That's why i install gem5 Full System successfully by following link:

http://cearial01.kaist.ac.kr/index.php/2016/08/26/gem5-documentation/

Now i want to compile & run a c program with OpenMP (matmul.c) using gem5. How can i compile & 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? How can i change no of processor, cache memory size, no of cpu during running & compilation?

I am new student of this section. That's why my asking list is too big! Hope anybody don't mind.

Best Regards, Litu


回答1:


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?

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.

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

  • builds both the cross compiler and the image for me, and thus ensure compatibility
  • makes it easy to automate building new software with its package system
  • can produce very simple images, which are more suitable for gem5 and architecture research

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

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

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

I think this is done in GCC with:

./configure --enable-libgomp

or through the Buildroot option:

BR2_GCC_ENABLE_OPENMP=y

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

and search the options.

You come across:

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

    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
    

    But keep in mind that:

    • 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.


来源:https://stackoverflow.com/questions/42734909/how-can-i-compile-run-a-c-program-with-openmp-in-gem5-full-system

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!