CoffeeBeforeArch.github.io

View on GitHub

Working with GPGPU-Sim - Adding Configuration Options

In the first blog of this series, I discussed how to run a CUDA application with the GPGPU-Sim simulator. However, you’ll want to do a lot more than that. One of the first things you will likely want to do is add custom options to the GPGPU-Sim configuration file. This will allow you to re-configure the simulator for your specific needs without having to recompile everything.

Where to Look

At the start of execution with the simulator, all possible configuration options are printed to the screen. If we want to add a new option, we first need to find a good starting point within the code base. Let’s take a look at gpu-sim.cc. From the root directory of the GPGPU-Sim repository, this is located at src/gpgpu-sim/gpu-sim.cc. Here is a link if you would like to look online.

Just below the include statements in gpu-sim.cc are multiple implementations of a method called reg_options(class OptionParser *opp). For example, one of these ispower_config::reg_options, and is where you would register options for the power model. Likewise, you can find an implementation for memory_config, shader_core_config, and gpgpu_sim_config. There is a final implementation located in src/abstract_hardware_model.cc for gpgpu_functional_sim_config. This is where options related to the functional (rather than performance) model should be placed.

Near the start of execution, gpgpu_sim_config::reg_options is called from inside of src/gpgpusim_entrypoint.cc. This then calls all the reg_options methods for the other classes. The loaded configuration options are then used to construct the various classes that build up the simulated GPGPU architecture.

Examining an Existing Option

Before we go through the process of adding a new option to the simulator, let’s examine how one of the existing options gets parsed. -gpgpu_max_cycle is a good place to start. This sets the maximum number of GPGPU cycles to simulate before killing a simulation. This option is parsed by gpgpu_sim_config::reg_options. Here is what the code looks like.

option_parser_register(opp, "-gpgpu_max_cycle", OPT_INT64, &gpu_max_cycle_opt,
                        "terminates gpu simulation early (0 = no limit)", "0");

Let’s go over each of the arguments. opp is the option_parser_t object, which is passed to all calls to option_parser_register. Next is -gpgpu_max_cycle, which is the name of the option that will be parsed from the GPGPU-Sim configuration file. We then have the data type for the value read from the configuration file (OPT_INT64 in this case).

The next argument is a reference to the variable where the value we are reading in from the configuration file will be stored. For example, the value we set in the configuration file for -gpgpu_max_cycle will be stored in &gpu_max_cycle_opt. gpu_max_cycle_opt is a data member of the gpgpu_sim_config class. The final two options are a string that describes what the option does, and a default value for the option.

Adding a New Option

Adding a new option that can be toggled in a GPGPU-Sim configuration file is a simple two-step process:

  1. Add a new call to option_parser_register(...) in the appropriate reg_options method.
  2. Add the variable that will store the value of that option in the appropriate class.

Lets add a dummy option called -magic_number that allows us to pass an integer into the simulator. We can start by adding this option to gpgpu_sim_config::reg_options in the src/gpgpu-sim/gpu-sim.cc file. Here is how mine looked.

option_parser_register(opp, "-magic_number", OPT_INT32, &magic_number_opt,
                      "A dummy magic number", "0");

With this, we’ve specified an option called -magic_number that we can use to pass in an 32 bit integer that has a default value of 0. Next, let’s add magic_number_opt, the variable where the value of this option will be stored. I did this by adding the following lines to the gpgpu_sim_config class in src/gpgpu-sim/gpu-sim.h.

// Our magic number
int magic_number_opt;

That’s it! Now we can add the option to a gpgpusim.config file, and see it printed out along with all the other configuration options when we use the simulator. For this, I’ll just be using the same application and setup as the previous blog post.

The configuration option can be placed anywhere in the gpgpusim.config file. I will just add it to the bottom of the file for simplicity.

-magic_number 25

While our magic number does not affect the actual simulation, we can still verify that it was correctly passed into the simulator. From the configuration option dump done at the start of execution, you should be able to see a line like this:

-magic_number                          25 # A dummy magic number

If we go ahead and delete the option from the GPGPU-Sim configuration file, you should see the following print.

-magic_number                          0 # A dummy magic number

Simple enough! That’s just the default value that we specified within our call to option_parser_register(...).

Concluding Remarks

Adding new configuration options to GPGPU-Sim fairly simple process, as long as you know where to start. In later posts, we’ll add more meaningful configuration options to the simulator to show how we can modify/enhance parts of the micro-architecture.

Cheers,

–Nick

Discussion Points