configs, tests: Replace optparse with argparse

JIRA: https://gem5.atlassian.net/browse/GEM5-543

Change-Id: I997d6a4e45319a74e21bd0d61d4af6118474c849
Signed-off-by: Giacomo Travaglini <giacomo.travaglini@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/44513
Reviewed-by: Daniel Carvalho <odanrc@yahoo.com.br>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Giacomo Travaglini
2021-04-16 17:42:34 +01:00
parent 09b9512acd
commit a2c9213a31
43 changed files with 1940 additions and 1953 deletions

View File

@@ -34,7 +34,7 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import gzip
import optparse
import argparse
import os
import m5
@@ -77,22 +77,18 @@ except:
print("Failed to import packet proto definitions")
exit(-1)
parser = optparse.OptionParser()
parser = argparse.ArgumentParser()
parser.add_option("--mem-type", type="choice", default="DDR3_1600_8x8",
choices=ObjectList.mem_list.get_names(),
help = "type of memory to use")
parser.add_option("--mem-size", action="store", type="string",
default="16MB",
help="Specify the memory size")
parser.add_option("--reuse-trace", action="store_true",
help="Prevent generation of traces and reuse existing")
parser.add_argument("--mem-type", default="DDR3_1600_8x8",
choices=ObjectList.mem_list.get_names(),
help = "type of memory to use")
parser.add_argument("--mem-size", action="store", type=str,
default="16MB",
help="Specify the memory size")
parser.add_argument("--reuse-trace", action="store_true",
help="Prevent generation of traces and reuse existing")
(options, args) = parser.parse_args()
if args:
print("Error: script doesn't take any positional arguments")
sys.exit(1)
args = parser.parse_args()
# start by creating the system itself, using a multi-layer 2.0 GHz
# crossbar, delivering 64 bytes / 3 cycles (one header cycle) which
@@ -102,20 +98,20 @@ system.clk_domain = SrcClockDomain(clock = '2.0GHz',
voltage_domain =
VoltageDomain(voltage = '1V'))
mem_range = AddrRange(options.mem_size)
mem_range = AddrRange(args.mem_size)
system.mem_ranges = [mem_range]
# do not worry about reserving space for the backing store
system.mmap_using_noreserve = True
# currently not exposed as command-line options, set here for now
options.mem_channels = 1
options.mem_ranks = 1
options.external_memory_system = 0
options.tlm_memory = 0
options.elastic_trace_en = 0
# currently not exposed as command-line args, set here for now
args.mem_channels = 1
args.mem_ranks = 1
args.external_memory_system = 0
args.tlm_memory = 0
args.elastic_trace_en = 0
MemConfig.config_mem(options, system)
MemConfig.config_mem(args, system)
# there is no point slowing things down by saving any data
for ctrl in system.mem_ctrls:
@@ -218,7 +214,7 @@ for r in ranges:
filename = os.path.join(m5.options.outdir,
'lat_mem_rd%d.trc.gz' % nxt_range)
if not options.reuse_trace:
if not args.reuse_trace:
# create the actual random trace for this range
create_trace(filename, r, burst_size, itt)

View File

@@ -34,7 +34,7 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import math
import optparse
import argparse
import m5
from m5.objects import *
@@ -51,7 +51,7 @@ from common import MemConfig
# and the sequential stride size (how many bytes per activate), and
# observe what bus utilisation (bandwidth) is achieved
parser = optparse.OptionParser()
parser = argparse.ArgumentParser()
dram_generators = {
"DRAM" : lambda x: x.createDram,
@@ -59,30 +59,26 @@ dram_generators = {
}
# Use a single-channel DDR3-1600 x64 (8x8 topology) by default
parser.add_option("--mem-type", type="choice", default="DDR3_1600_8x8",
choices=ObjectList.mem_list.get_names(),
help = "type of memory to use")
parser.add_argument("--mem-type", default="DDR3_1600_8x8",
choices=ObjectList.mem_list.get_names(),
help = "type of memory to use")
parser.add_option("--mem-ranks", "-r", type="int", default=1,
help = "Number of ranks to iterate across")
parser.add_argument("--mem-ranks", "-r", type=int, default=1,
help = "Number of ranks to iterate across")
parser.add_option("--rd_perc", type="int", default=100,
help = "Percentage of read commands")
parser.add_argument("--rd_perc", type=int, default=100,
help = "Percentage of read commands")
parser.add_option("--mode", type="choice", default="DRAM",
choices=list(dram_generators.keys()),
help = "DRAM: Random traffic; \
parser.add_argument("--mode", default="DRAM",
choices=list(dram_generators.keys()),
help = "DRAM: Random traffic; \
DRAM_ROTATE: Traffic rotating across banks and ranks")
parser.add_option("--addr-map", type="choice",
choices=ObjectList.dram_addr_map_list.get_names(),
default="RoRaBaCoCh", help = "DRAM address map policy")
parser.add_argument("--addr-map",
choices=ObjectList.dram_addr_map_list.get_names(),
default="RoRaBaCoCh", help = "DRAM address map policy")
(options, args) = parser.parse_args()
if args:
print("Error: script doesn't take any positional arguments")
sys.exit(1)
args = parser.parse_args()
# at the moment we stay with the default open-adaptive page policy,
# and address mapping
@@ -104,11 +100,11 @@ system.mmap_using_noreserve = True
# force a single channel to match the assumptions in the DRAM traffic
# generator
options.mem_channels = 1
options.external_memory_system = 0
options.tlm_memory = 0
options.elastic_trace_en = 0
MemConfig.config_mem(options, system)
args.mem_channels = 1
args.external_memory_system = 0
args.tlm_memory = 0
args.elastic_trace_en = 0
MemConfig.config_mem(args, system)
# the following assumes that we are using the native DRAM
# controller, check to be sure
@@ -121,7 +117,7 @@ if not isinstance(system.mem_ctrls[0].dram, m5.objects.DRAMInterface):
system.mem_ctrls[0].dram.null = True
# Set the address mapping based on input argument
system.mem_ctrls[0].dram.addr_mapping = options.addr_map
system.mem_ctrls[0].dram.addr_mapping = args.addr_map
# stay in each state for 0.25 ms, long enough to warm things up, and
# short enough to avoid hitting a refresh
@@ -178,16 +174,16 @@ root.system.mem_mode = 'timing'
m5.instantiate()
def trace():
addr_map = ObjectList.dram_addr_map_list.get(options.addr_map)
generator = dram_generators[options.mode](system.tgen)
addr_map = ObjectList.dram_addr_map_list.get(args.addr_map)
generator = dram_generators[args.mode](system.tgen)
for stride_size in range(burst_size, max_stride + 1, burst_size):
for bank in range(1, nbr_banks + 1):
num_seq_pkts = int(math.ceil(float(stride_size) / burst_size))
yield generator(period,
0, max_addr, burst_size, int(itt), int(itt),
options.rd_perc, 0,
args.rd_perc, 0,
num_seq_pkts, page_size, nbr_banks, bank,
addr_map, options.mem_ranks)
addr_map, args.mem_ranks)
yield system.tgen.createExit(0)
system.tgen.start(trace())