Main »

Homework 2


edit SideBar

CS 752: Advanced Computer Architecture I (Fall 2014 Section 1 of 1)

Homework 2

Due Monday, 10/20

You should do this assignment in groups of THREE PEOPLE. No late assignments.


The purpose of this assignment is to help you become familiar with gem5

1. Download gem5' source code from There are two ways to do this.

a. Download a .tar.bz2 by visiting the website. You can untar the downloaded file using tar -xvjf <file name>.

b. Use mercurial to clone the gem5 repository. Execute the following command:

    hg clone

This command would clone the repository in the current directory. You can read more about mercurial on the following site:

At the end of this step you should have a directory that holds the source code for the simulator. We will call this directory $GEM5_HOME.

2. Next we compile the simulator for x86 architecture with ruby memory system and coherence protocol set to MESI_Two_Level. Change to the directory $GEM5_HOME. Execute the following command:

 scons PROTOCOL=MESI_Two_Level build/X86/gem5.opt

Scons is the build tool that gem5 uses. You can read about it on the site: The PROTOCOL option specifies the protocol to be compiled. Read more about the different options here:

Error messages that you might receive:

a. Error: gcc version 4.6 or newer required.

       Installed version: 4.4.7

Solution: If you are on a CSL supported machine, then add the following lines to your .bashrc.local file, which can be found in your home directory.

export PATH=/s/gcc-4.7.3/bin:$PATH export LD_LIBRARY_PATH=/s/gcc-4.7.3/lib64:$LD_LIBRARY_PATH

Note that you will have to logout and login again for the settings to take effect. Alternately, you can set these two variables for the current environment by invoking those commands from a command line. Note that these instructions are for the Bourne Again shell. You would have to do something similar for other shells.

b. Error: SWIG version 2.0.4 or newer required.

       Installed version: 1.3.40

Solution: You would need to download and install swig. You would need to visit the site: Download the version 2.0.4 which known to work well. Untar the downloaded file:

    tar -xvzf swig-2.0.4.tar.gz

Change to the directory swig-2.0.4. Execute the following commands:

    ./configure --prefix<PATH WEHRE TO INSTALL SWIG>; make; make install

This should create a binary called swig. Add the bin directory in the directory where swig gets installed to the PATH variable like we did for GCC compiler earlier. Logout and login again for the settings to take effect.

c. Some Python related problem.

Solution: Add the following lines to your .bashrc.local file.

    export PATH=/s/python-2.7.3/bin:$PATH
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/s/python-2.7.3/lib
    export LIBRARY_PATH=/s/python-2.7.3/lib:$LIBRARY_PATH

At the end of this step you should have the executable build/X86/gem5.opt. There are four other versions (debug, fast, prof, perf) of the simulator that you can build. Read about them on the page: You may need to use the debug version to in case you make changes to the simulator.

3. Test your executable. Run the following command:

    ./build/X86/gem5.opt ./configs/example/ -c tests/test-progs/hello/bin/x86/linux/hello --ruby

You should see the string "Hello world!" in the output.

4. Write a program that implements Sieve of Eratosthenes and outputs one single integer at the end: the number of prime numbers <= 100,000,000. Compile your program as a static binary. The output should be: 5761455.

5. Simulate your program using the following configurations: Default Out-of-order CPU. L1 instruction cache: 32K 8-way set associative. L1 data cache: (32K, 64K, 128K, 256K, 8-way) set associative. L2 unified cache: 1MB 8-way set associative.

Keep the block size fixed at 64-bytes. Read the file $GEM5_HOME/configs/common/ to know about the available options. Report the IPC and the cache hierarchy miss rates for the different configurations of the L1 Data cache specified above.

For all of the above tests, use the first 100M instructions to warmup the caches and then collect statistics for next 100M instructions.

6. Recall the Pentium vs Pentium Pro problem discussed in the lecture. The coherence protocol MESI_Two_Level is a write allocate protocol. For L1 cache sizes listed above, simulate two different versions of the sieve, one that writes to a variable irrespective of the current value, and the other that tests the value first before performing the write. Report any significant performance difference and the relevant statistical variables that point to the cause of the difference. If you do not see any performance difference, again make your case using the relevant statistical variables.

Refer to the following paper for more details on the Sieve experiment: Sprunt, B. (2002). The basics of performance-monitoring hardware. IEEE Micro, 22(4), 64-71.

7. Report any bugs that you find in the simulator to This is important as gem5 is an open source simulator and is dependent on user feedback for improvement.

Tips and Tricks

  • Start early.

What to Hand In

Turn in your assignment by sending an email message to the class mailing list with the subject line: [CS752 Homework2]

0. The email should contain the names and ID numbers of the students submitting the assignment. The files below should be attached as a zip file to the email.

1. A file named sieve.c with the implementation of sieve of Eratosthenes.

2. The files stats.txt and config.ini for each of the four different configurations specified in step 5. Also provide the command line you used for executing the simulator.

3. The files stats.txt and config.ini for each of the four different configurations obtained after the sieve was modified as suggested in the paper by Sprunt.

4. A file named report.txt containing a short report with your observations and conclusions from the experiment.

Page last modified on October 16, 2014, at 12:03 PM, visited times