Giter Club home page Giter Club logo

ase_riscv_gem5_sim's Introduction

Architetture dei Sistemi di Elaborazione@Politecnico di Torino: SIMULATING AN OoO RISC-V CPU WITH GEM5

This README provides an environment for simulating a program on a parametrizable RISC-V Out of Order (OoO) CPU and visualize the pipeline. You can see the flow in the Figure below.

flow

Table of contest

Setup the environment

First of all, you need to clone the repository with the following command, for SSH:

git clone [email protected]:cad-polito-it/ase_riscv_gem5_sim.git

For HTTPS:

git clone https://github.com/cad-polito-it/ase_riscv_gem5_sim.git

Prerequisites

In order to simulate a benchmark, you need the following three tools:

  • A Risc-V cross compiler
  • An architectural simulator
  • A pipeline visualizer

Installation guidelines are provided for each of the aforementioned tools. In case you are using LABINF PCs, you can skip the installation part (Be aware, tools' compilation is time consuming!).

An important file for the simulation flow is the setup_default. In this file you need to specify you installation paths for different tools. For example:

export CC="/usr/bin/riscv64-linux-gnu-gcc-10"
export GEM5_INSTALLATION_PATH="/mnt/d/gem5_simulator/build/"
export GEM5_SRC="/mnt/d/gem5_simulator/gem5/"

The CC is the cross compiler, and it is installed in /usr/bin. Meanwhile the Architectural Simulator (Gem5) is installed in /mnt/d/gem5_simulator/build, while its soruce are at /mnt/d/gem5_simulator/gem5.

Installing a Risc-V toolchain, the cross-compiler

You can compile from scratch the toolchain for Risc-V following the instruction @ https://github.com/riscv-collab/riscv-gnu-toolchain

For linux users, you can intall the toolchain using you package manager. For example, for ubuntu users:

sudo apt install gcc-riscv64-linux-gnu

Installing Gem5, the Architectural Simulator

To install Gem5, you can follow the guidelines @ https://www.gem5.org/documentation/general_docs/building

Just remember that you need the following Gem5 characteristics to install:

  • ISA = RISCV.
  • variant = opt.

Be aware: the Gem5 compilation is very, very, very (did i already say very?!) time consuming.

Installing Konata, the Pipeline Visualizer

To download Konata, visit the Konata github pages @ https://github.com/shioyadan/Konata/releases

Download the appropriate Konata release for your operating system. Konata is available for various platforms, including Windows, macOS, and Linux.

Unzip the release, inside you will find an executable named konata or konata.exe (OS dependent!).

Be aware: For windows/macOS users, you need to open the Konata application manually and load the trace

HOWTO - Simulate a Program

To simulate a program, run the simulate.sh script with the desired program as an argument:

./simulate.sh -i ./programs/sanity_test/ -nogui

You can specify with -gui or -nogui the automatic opening of the Konata simulation (for linux users).

This will produce an ELF (Executable and Linkable Format) file in the programs/sanity_test/ directory. Afterward, the ELF is passed to the Architectural Simulator, and program-related statistics (stats.txt) and trace (trace.out)are dumped in ./results/sanity_test/

HOWTO - Visualize the Pipeline with Konata

The instruction trace, and the statistics are extractred only from a Region of Interest (ROI), as Figure below shows.

#ifdef _GEM5_
#include <gem5/m5ops.h>
#endif /*_GEM5_*/

int main() {


/********************************************************
 *****      Starting Region of Interest (ROI)    ********
********************************************************/
#if _GEM5_
 m5_work_begin(1,1);   
#endif /*_GEM5_*/

    // my c benchmark core 
    angle2time_conversion();
    tooth_to_spark();

/********************************************************
 *****      End Region of Interest (ROI)         ********
********************************************************/
#ifdef _GEM5_
    m5_work_end(1,1);
#endif /*_GEM5_*/
    return 0;
}

To visualize the pipeline, follow these steps:

  1. Load the trace.out file onto Konata, a tool for visualizing gem5 traces. From the menu in the window or using drag and drop. load

  2. Use Konata's interface to visualize and analyze the pipeline behavior of your simulated program.

Note For linux-based users you can directly launch the pipeline visualizer with the option -gui option in simulate script

Contributors

ase_riscv_gem5_sim's People

Contributors

franout avatar annachiara19 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.