TLDR
The simple way to add flags is to use the gem5 SimpleOpts
file. You can accomplish this using the following imports:
sys.path.append(os.environ['GEM_CONFIGS'])
# Import gem5's (very) thin wrapper around
# the argparse library
from common import SimpleOpts
Note that we need the $GEM_CONFIGS
environment variable so that we can add their scripts to the script path, but don't get your feathers fluffed for that. The cool part that this wrapper provides is an interface to the simulation object's arguments.
It's important to know that this really is just a wrapper for argparse. If you look in common.Options
you can use the default options that gem5 has built in:
from common import Options
import argparse
parser = argparse.ArgumentParser()
Options.addCommonOptions(parser)
this includes the number of processors, cache sizes and others, but I think that it is important to know how to more closely integrate these options with your script. Besides which, the default options probably cover a lot more options than you need to (or should) change in any given experimental run.
Using the provided interface is simple:
SimpleOpts.add_option("--binary", nargs="?", default=default_binary)
options = SimpleOpts.parse_args()
Now you can access options.binary
and get the command line entry provided by the user. There are a lot of arguments you can supply to the add_option()
function, all of which are documented in the argparse documentation and I highly encourage that you take a look through that. My most frequently used options are the action
, type
and help
arguments.