python: Apply Black formatter to Python files

The command executed was `black src configs tests util`.

Change-Id: I8dfaa6ab04658fea37618127d6ac19270028d771
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/47024
Maintainer: Bobby Bruce <bbruce@ucdavis.edu>
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
Reviewed-by: Giacomo Travaglini <giacomo.travaglini@arm.com>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Bobby R. Bruce
2022-07-05 11:02:25 -07:00
committed by Giacomo Travaglini
parent 1cfaa8da83
commit 787204c92d
980 changed files with 35668 additions and 22233 deletions

View File

@@ -34,7 +34,8 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import matplotlib
matplotlib.use('Agg')
matplotlib.use("Agg")
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
import numpy as np
@@ -55,52 +56,56 @@ stackWidth = 18.0
barWidth = 0.5
plotFontSize = 18
States = ['IDLE', 'ACT', 'REF', 'ACT_PDN', 'PRE_PDN', 'SREF']
States = ["IDLE", "ACT", "REF", "ACT_PDN", "PRE_PDN", "SREF"]
EnergyStates = ['ACT_E',
'PRE_E',
'READ_E',
'REF_E',
'ACT_BACK_E',
'PRE_BACK_E',
'ACT_PDN_E',
'PRE_PDN_E',
'SREF_E']
EnergyStates = [
"ACT_E",
"PRE_E",
"READ_E",
"REF_E",
"ACT_BACK_E",
"PRE_BACK_E",
"ACT_PDN_E",
"PRE_PDN_E",
"SREF_E",
]
StackColors = {
'IDLE' : 'black', # time spent in states
'ACT' : 'lightskyblue',
'REF' : 'limegreen',
'ACT_PDN' : 'crimson',
'PRE_PDN' : 'orange',
'SREF' : 'gold',
'ACT_E' : 'lightskyblue', # energy of states
'PRE_E' : 'black',
'READ_E' : 'white',
'REF_E' : 'limegreen',
'ACT_BACK_E' : 'lightgray',
'PRE_BACK_E' : 'gray',
'ACT_PDN_E' : 'crimson',
'PRE_PDN_E' : 'orange',
'SREF_E' : 'gold'
"IDLE": "black", # time spent in states
"ACT": "lightskyblue",
"REF": "limegreen",
"ACT_PDN": "crimson",
"PRE_PDN": "orange",
"SREF": "gold",
"ACT_E": "lightskyblue", # energy of states
"PRE_E": "black",
"READ_E": "white",
"REF_E": "limegreen",
"ACT_BACK_E": "lightgray",
"PRE_BACK_E": "gray",
"ACT_PDN_E": "crimson",
"PRE_PDN_E": "orange",
"SREF_E": "gold",
}
StatToKey = {
'system.mem_ctrls_0.actEnergy' : 'ACT_E',
'system.mem_ctrls_0.preEnergy' : 'PRE_E',
'system.mem_ctrls_0.readEnergy' : 'READ_E',
'system.mem_ctrls_0.refreshEnergy' : 'REF_E',
'system.mem_ctrls_0.actBackEnergy' : 'ACT_BACK_E',
'system.mem_ctrls_0.preBackEnergy' : 'PRE_BACK_E',
'system.mem_ctrls_0.actPowerDownEnergy' : 'ACT_PDN_E',
'system.mem_ctrls_0.prePowerDownEnergy' : 'PRE_PDN_E',
'system.mem_ctrls_0.selfRefreshEnergy' : 'SREF_E'
"system.mem_ctrls_0.actEnergy": "ACT_E",
"system.mem_ctrls_0.preEnergy": "PRE_E",
"system.mem_ctrls_0.readEnergy": "READ_E",
"system.mem_ctrls_0.refreshEnergy": "REF_E",
"system.mem_ctrls_0.actBackEnergy": "ACT_BACK_E",
"system.mem_ctrls_0.preBackEnergy": "PRE_BACK_E",
"system.mem_ctrls_0.actPowerDownEnergy": "ACT_PDN_E",
"system.mem_ctrls_0.prePowerDownEnergy": "PRE_PDN_E",
"system.mem_ctrls_0.selfRefreshEnergy": "SREF_E",
}
# Skipping write energy, the example script issues 100% reads by default
# 'system.mem_ctrls_0.writeEnergy' : "WRITE"
def plotLowPStates(plot_dir, stats_fname, bank_util_list, seqbytes_list,
delay_list):
def plotLowPStates(
plot_dir, stats_fname, bank_util_list, seqbytes_list, delay_list
):
"""
plotLowPStates generates plots by parsing statistics output by the DRAM
sweep simulation described in the the configs/dram/low_power_sweep.py
@@ -122,7 +127,7 @@ def plotLowPStates(plot_dir, stats_fname, bank_util_list, seqbytes_list,
@param delay_list: list of itt max multipliers (e.g. [1, 20, 200])
"""
stats_file = open(stats_fname, 'r')
stats_file = open(stats_fname, "r")
global bankUtilValues
bankUtilValues = bank_util_list
@@ -136,7 +141,7 @@ def plotLowPStates(plot_dir, stats_fname, bank_util_list, seqbytes_list,
# throw away the first two lines of the stats file
stats_file.readline()
stats_file.readline() # the 'Begin' line
stats_file.readline() # the 'Begin' line
#######################################
# Parse stats file and gather results
@@ -147,24 +152,25 @@ def plotLowPStates(plot_dir, stats_fname, bank_util_list, seqbytes_list,
for seq_bytes in seqBytesValues:
for line in stats_file:
if 'Begin' in line:
if "Begin" in line:
break
if len(line.strip()) == 0:
continue
#### state time values ####
if 'system.mem_ctrls_0.memoryStateTime' in line:
if "system.mem_ctrls_0.memoryStateTime" in line:
# remove leading and trailing white spaces
line = line.strip()
# Example format:
# 'system.mem_ctrls_0.memoryStateTime::ACT 1000000'
statistic, stime = line.split()[0:2]
# Now grab the state, i.e. 'ACT'
state = statistic.split('::')[1]
state = statistic.split("::")[1]
# store the value of the stat in the results dict
results[delay][bank_util][seq_bytes][state] = \
int(stime)
results[delay][bank_util][seq_bytes][state] = int(
stime
)
#### state energy values ####
elif line.strip().split()[0] in list(StatToKey.keys()):
# Example format:
@@ -177,15 +183,15 @@ def plotLowPStates(plot_dir, stats_fname, bank_util_list, seqbytes_list,
# To add last traffic gen idle period stats to the results dict
for line in stats_file:
if 'system.mem_ctrls_0.memoryStateTime' in line:
line = line.strip() # remove leading and trailing white spaces
if "system.mem_ctrls_0.memoryStateTime" in line:
line = line.strip() # remove leading and trailing white spaces
# Example format:
# 'system.mem_ctrls_0.memoryStateTime::ACT 1000000'
statistic, stime = line.split()[0:2]
# Now grab the state energy, .e.g 'ACT'
state = statistic.split('::')[1]
state = statistic.split("::")[1]
idleResults[state] = int(stime)
if state == 'ACT_PDN':
if state == "ACT_PDN":
break
########################################
@@ -193,15 +199,25 @@ def plotLowPStates(plot_dir, stats_fname, bank_util_list, seqbytes_list,
########################################
# one plot per delay value
for delay in delayValues:
plot_path = plot_dir + delay + '-'
plot_path = plot_dir + delay + "-"
plotStackedStates(delay, States, 'IDLE', stateTimePlotName(plot_path),
'Time (ps) spent in a power state')
plotStackedStates(delay, EnergyStates, 'ACT_E',
stateEnergyPlotName(plot_path),
'Energy (pJ) of a power state')
plotStackedStates(
delay,
States,
"IDLE",
stateTimePlotName(plot_path),
"Time (ps) spent in a power state",
)
plotStackedStates(
delay,
EnergyStates,
"ACT_E",
stateEnergyPlotName(plot_path),
"Energy (pJ) of a power state",
)
plotIdle(plot_dir)
def plotIdle(plot_dir):
"""
Create a bar chart for the time spent in power states during the idle phase
@@ -213,15 +229,16 @@ def plotIdle(plot_dir):
ind = np.arange(len(States))
l1 = ax.bar(ind, [idleResults[x] for x in States], width)
ax.xaxis.set_ticks(ind + width/2)
ax.xaxis.set_ticks(ind + width / 2)
ax.xaxis.set_ticklabels(States)
ax.set_ylabel('Time (ps) spent in a power state')
ax.set_ylabel("Time (ps) spent in a power state")
fig.suptitle("Idle 50 us")
print("saving plot:", idlePlotName(plot_dir))
plt.savefig(idlePlotName(plot_dir), format='eps')
plt.savefig(idlePlotName(plot_dir), format="eps")
plt.close(fig)
def plotStackedStates(delay, states_list, bottom_state, plot_name, ylabel_str):
"""
Create a stacked bar chart for the list that is passed in as arg, which
@@ -237,7 +254,7 @@ def plotStackedStates(delay, states_list, bottom_state, plot_name, ylabel_str):
fig.set_figheight(stackHeight)
fig.set_figwidth(stackWidth)
width = barWidth
plt.rcParams.update({'font.size': plotFontSize})
plt.rcParams.update({"font.size": plotFontSize})
# Get the number of seq_bytes values
N = len(seqBytesValues)
@@ -251,50 +268,62 @@ def plotStackedStates(delay, states_list, bottom_state, plot_name, ylabel_str):
# Must have a bottom of the stack first
state = bottom_state
l_states[state] = [results[delay][bank_util][x][state] \
for x in seqBytesValues]
p_states[state] = ax[sub_idx].bar(ind, l_states[state], width,
color=StackColors[state])
l_states[state] = [
results[delay][bank_util][x][state] for x in seqBytesValues
]
p_states[state] = ax[sub_idx].bar(
ind, l_states[state], width, color=StackColors[state]
)
time_sum = l_states[state]
for state in states_list[1:]:
l_states[state] = [results[delay][bank_util][x][state] \
for x in seqBytesValues]
l_states[state] = [
results[delay][bank_util][x][state] for x in seqBytesValues
]
# Now add on top of the bottom = sum of values up until now
p_states[state] = ax[sub_idx].bar(ind, l_states[state], width,
color=StackColors[state],
bottom=time_sum)
p_states[state] = ax[sub_idx].bar(
ind,
l_states[state],
width,
color=StackColors[state],
bottom=time_sum,
)
# Now add the bit of the stack that we just ploted to the bottom
# resulting in a new bottom for the next iteration
time_sum = [prev_sum + new_s for prev_sum, new_s in \
zip(time_sum, l_states[state])]
time_sum = [
prev_sum + new_s
for prev_sum, new_s in zip(time_sum, l_states[state])
]
ax[sub_idx].set_title('Bank util %s' % bank_util)
ax[sub_idx].xaxis.set_ticks(ind + width/2.)
ax[sub_idx].set_title("Bank util %s" % bank_util)
ax[sub_idx].xaxis.set_ticks(ind + width / 2.0)
ax[sub_idx].xaxis.set_ticklabels(seqBytesValues, rotation=45)
ax[sub_idx].set_xlabel('Seq. bytes')
ax[sub_idx].set_xlabel("Seq. bytes")
if bank_util == bankUtilValues[0]:
ax[sub_idx].set_ylabel(ylabel_str)
myFontSize='small'
myFontSize = "small"
fontP = FontProperties()
fontP.set_size(myFontSize)
fig.legend([p_states[x] for x in states_list], states_list,
prop=fontP)
fig.legend([p_states[x] for x in states_list], states_list, prop=fontP)
plt.savefig(plot_name, format='eps', bbox_inches='tight')
plt.savefig(plot_name, format="eps", bbox_inches="tight")
print("saving plot:", plot_name)
plt.close(fig)
# These plat name functions are also called in the main script
def idlePlotName(plot_dir):
return (plot_dir + 'idle.eps')
return plot_dir + "idle.eps"
def stateTimePlotName(plot_dir):
return (plot_dir + 'state-time.eps')
return plot_dir + "state-time.eps"
def stateEnergyPlotName(plot_dir):
return (plot_dir + 'state-energy.eps')
return plot_dir + "state-energy.eps"
def initResults():
for delay in delayValues:

View File

@@ -56,15 +56,15 @@ def main():
exit(-1)
try:
stats = open(sys.argv[1] + '/stats.txt', 'r')
stats = open(sys.argv[1] + "/stats.txt", "r")
except IOError:
print("Failed to open ", sys.argv[1] + '/stats.txt', " for reading")
print("Failed to open ", sys.argv[1] + "/stats.txt", " for reading")
exit(-1)
try:
simout = open(sys.argv[1] + '/simout', 'r')
simout = open(sys.argv[1] + "/simout", "r")
except IOError:
print("Failed to open ", sys.argv[1] + '/simout', " for reading")
print("Failed to open ", sys.argv[1] + "/simout", " for reading")
exit(-1)
# Get the address ranges
@@ -116,8 +116,10 @@ def main():
# Sanity check
if not (len(ranges) == len(final_rd_lat)):
print("Address ranges (%d) and read latency (%d) do not match" % \
(len(ranges), len(final_rd_lat)))
print(
"Address ranges (%d) and read latency (%d) do not match"
% (len(ranges), len(final_rd_lat))
)
exit(-1)
for (r, l) in zip(ranges, final_rd_lat):
@@ -134,9 +136,9 @@ def main():
xticks_labels = []
for x in xticks_locations:
if x < 1024:
xticks_labels.append('%d kB' % x)
xticks_labels.append("%d kB" % x)
else:
xticks_labels.append('%d MB' % (x / 1024))
xticks_labels.append("%d MB" % (x / 1024))
plt.xticks(xticks_locations, xticks_labels, rotation=-45)
plt.minorticks_off()
@@ -145,5 +147,6 @@ def main():
plt.grid(True)
plt.show()
if __name__ == "__main__":
main()

View File

@@ -57,10 +57,15 @@ def main():
print("Usage: ", sys.argv[0], "-u|p|e <simout directory>")
exit(-1)
if len(sys.argv[1]) != 2 or sys.argv[1][0] != '-' or \
not sys.argv[1][1] in "upe":
print("Choose -u (utilisation), -p (total power), or -e " \
"(power efficiency)")
if (
len(sys.argv[1]) != 2
or sys.argv[1][0] != "-"
or not sys.argv[1][1] in "upe"
):
print(
"Choose -u (utilisation), -p (total power), or -e "
"(power efficiency)"
)
exit(-1)
# Choose the appropriate mode, either utilisation, total power, or
@@ -68,15 +73,15 @@ def main():
mode = sys.argv[1][1]
try:
stats = open(sys.argv[2] + '/stats.txt', 'r')
stats = open(sys.argv[2] + "/stats.txt", "r")
except IOError:
print("Failed to open ", sys.argv[2] + '/stats.txt', " for reading")
print("Failed to open ", sys.argv[2] + "/stats.txt", " for reading")
exit(-1)
try:
simout = open(sys.argv[2] + '/simout', 'r')
simout = open(sys.argv[2] + "/simout", "r")
except IOError:
print("Failed to open ", sys.argv[2] + '/simout', " for reading")
print("Failed to open ", sys.argv[2] + "/simout", " for reading")
exit(-1)
# Get the burst size, number of banks and the maximum stride from
@@ -84,8 +89,10 @@ def main():
got_sweep = False
for line in simout:
match = re.match("DRAM sweep with "
"burst: (\d+), banks: (\d+), max stride: (\d+)", line)
match = re.match(
"DRAM sweep with " "burst: (\d+), banks: (\d+), max stride: (\d+)",
line,
)
if match:
burst_size = int(match.groups(0)[0])
banks = int(match.groups(0)[1])
@@ -117,10 +124,11 @@ def main():
avg_pwr.append(float(match.groups(0)[0]))
stats.close()
# Sanity check
if not (len(peak_bw) == len(bus_util) and len(bus_util) == len(avg_pwr)):
print("Peak bandwidth, bus utilisation, and average power do not match")
print(
"Peak bandwidth, bus utilisation, and average power do not match"
)
exit(-1)
# Collect the selected metric as our Z-axis, we do this in a 2D
@@ -131,11 +139,11 @@ def main():
i = 0
for j in range(len(peak_bw)):
if mode == 'u':
if mode == "u":
z.append(bus_util[j])
elif mode == 'p':
elif mode == "p":
z.append(avg_pwr[j])
elif mode == 'e':
elif mode == "e":
# avg_pwr is in mW, peak_bw in MiByte/s, bus_util in percent
z.append(avg_pwr[j] / (bus_util[j] / 100.0 * peak_bw[j] / 1000.0))
else:
@@ -156,7 +164,7 @@ def main():
exit(-1)
fig = plt.figure()
ax = fig.gca(projection='3d')
ax = fig.gca(projection="3d")
X = np.arange(burst_size, max_size + 1, burst_size)
Y = np.arange(1, banks + 1, 1)
X, Y = np.meshgrid(X, Y)
@@ -165,27 +173,36 @@ def main():
# stride size in order
Z = np.array(zs)
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm,
linewidth=0, antialiased=False)
surf = ax.plot_surface(
X,
Y,
Z,
rstride=1,
cstride=1,
cmap=cm.coolwarm,
linewidth=0,
antialiased=False,
)
# Change the tick frequency to 64
start, end = ax.get_xlim()
ax.xaxis.set_ticks(np.arange(start, end + 1, 64))
ax.set_xlabel('Bytes per activate')
ax.set_ylabel('Banks')
ax.set_xlabel("Bytes per activate")
ax.set_ylabel("Banks")
if mode == 'u':
ax.set_zlabel('Utilisation (%)')
elif mode == 'p':
ax.set_zlabel('Power (mW)')
elif mode == 'e':
ax.set_zlabel('Power efficiency (mW / GByte / s)')
if mode == "u":
ax.set_zlabel("Utilisation (%)")
elif mode == "p":
ax.set_zlabel("Power (mW)")
elif mode == "e":
ax.set_zlabel("Power efficiency (mW / GByte / s)")
# Add a colorbar
fig.colorbar(surf, shrink=0.5, pad=.1, aspect=10)
fig.colorbar(surf, shrink=0.5, pad=0.1, aspect=10)
plt.show()
if __name__ == "__main__":
main()

View File

@@ -40,56 +40,70 @@ import argparse
import os
from subprocess import call
parser = argparse.ArgumentParser(formatter_class=
argparse.ArgumentDefaultsHelpFormatter)
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
parser.add_argument("--statsfile", required=True, help="stats file path")
parser.add_argument("--bankutils", default="b1 b2 b3", help="target bank " \
"utilization values separated by space, e.g. \"1 4 8\"")
parser.add_argument(
"--bankutils",
default="b1 b2 b3",
help="target bank " 'utilization values separated by space, e.g. "1 4 8"',
)
parser.add_argument("--seqbytes", default="s1 s2 s3", help="no. of " \
"sequential bytes requested by each traffic gen request." \
" e.g. \"64 256 512\"")
parser.add_argument(
"--seqbytes",
default="s1 s2 s3",
help="no. of "
"sequential bytes requested by each traffic gen request."
' e.g. "64 256 512"',
)
parser.add_argument("--delays", default="d1 d2 d3", help="string of delay"
" values separated by a space. e.g. \"1 20 100\"")
parser.add_argument(
"--delays",
default="d1 d2 d3",
help="string of delay" ' values separated by a space. e.g. "1 20 100"',
)
parser.add_argument("--outdir", help="directory to output plots",
default='plot_test')
parser.add_argument(
"--outdir", help="directory to output plots", default="plot_test"
)
parser.add_argument("--pdf", action="store_true", help="output Latex and pdf")
parser.add_argument("--pdf", action='store_true', help="output Latex and pdf")
def main():
args = parser.parse_args()
if not os.path.isfile(args.statsfile):
exit('Error! File not found: %s' % args.statsfile)
exit("Error! File not found: %s" % args.statsfile)
if not os.path.isdir(args.outdir):
os.mkdir(args.outdir)
bank_util_list = args.bankutils.strip().split()
seqbyte_list = args.seqbytes.strip().split()
delays = args.delays.strip().split()
plotter.plotLowPStates(args.outdir + '/', args.statsfile, bank_util_list,
seqbyte_list, delays)
plotter.plotLowPStates(
args.outdir + "/", args.statsfile, bank_util_list, seqbyte_list, delays
)
if args.pdf:
textwidth = '0.5'
textwidth = "0.5"
### Time and energy plots ###
#############################
# place tex and pdf files in outdir
os.chdir(args.outdir)
texfile_s = 'stacked_lowp_sweep.tex'
texfile_s = "stacked_lowp_sweep.tex"
print("\t", texfile_s)
outfile = open(texfile_s, 'w')
outfile = open(texfile_s, "w")
startDocText(outfile)
outfile.write("\\begin{figure} \n\\centering\n")
## Time plots for all delay values
for delay in delays:
# Time
filename = plotter.stateTimePlotName(str(delay) + '-')
filename = plotter.stateTimePlotName(str(delay) + "-")
outfile.write(wrapForGraphic(filename, textwidth))
outfile.write(getCaption(delay))
outfile.write("\end{figure}\n")
@@ -98,7 +112,7 @@ def main():
outfile.write("\\begin{figure} \n\\centering\n")
for delay in delays:
# Energy
filename = plotter.stateEnergyPlotName(str(delay) + '-')
filename = plotter.stateEnergyPlotName(str(delay) + "-")
outfile.write(wrapForGraphic(filename, textwidth))
outfile.write(getCaption(delay))
outfile.write("\\end{figure}\n")
@@ -111,18 +125,19 @@ def main():
print("\tpdflatex ", texfile_s)
# Run pdflatex to generate to pdf
call(["pdflatex", texfile_s])
call(["open", texfile_s.split('.')[0] + '.pdf'])
call(["open", texfile_s.split(".")[0] + ".pdf"])
def getCaption(delay):
return ('\\caption{' +
'itt delay = ' + str(delay) +
'}\n')
return "\\caption{" + "itt delay = " + str(delay) + "}\n"
def wrapForGraphic(filename, width='1.0'):
def wrapForGraphic(filename, width="1.0"):
# \t is tab and needs to be escaped, therefore \\textwidth
return '\\includegraphics[width=' + width + \
'\\textwidth]{' + filename + '}\n'
return (
"\\includegraphics[width=" + width + "\\textwidth]{" + filename + "}\n"
)
def startDocText(outfile):
@@ -135,15 +150,17 @@ def startDocText(outfile):
"""
outfile.write(start_stuff)
def endDocText(outfile):
end_stuff = '''
end_stuff = """
\\end{document}
'''
"""
outfile.write(end_stuff)
# Call main
if __name__ == '__main__':
if __name__ == "__main__":
main()