diff --git a/docs/latency_throughput.md b/docs/latency_throughput.md new file mode 100644 index 0000000..2ee1539 --- /dev/null +++ b/docs/latency_throughput.md @@ -0,0 +1,3 @@ +# Latency and Throughput of Instructions + +{{ latency_throughput_table() }} diff --git a/main.py b/main.py index c6f6f05..111da56 100644 --- a/main.py +++ b/main.py @@ -20,7 +20,31 @@ with open(f'code/measure-{cpu}.csv', newline='') as csvfile: reader = csv.DictReader(csvfile) for row in reader: - measure[cpu][row['name']] = row + latency = [] + for part in row['latency'].split('/'): + if part == "": + lat = "N/A" + else: + lat = float(part) + if abs((lat - round(lat)) / lat) < 0.02: + lat = round(lat) + latency.append(lat) + latency = sorted(list(set(latency))) + + throughput_cpi = float(row['throughput(cpi)']) + if abs(throughput_cpi - round(throughput_cpi)) < 0.03: + throughput_cpi = round(throughput_cpi) + + # TODO: handle small cpi better by 1/ipc + throughput_ipc = float(row['throughput(ipc)']) + if abs(throughput_ipc - round(throughput_ipc)) < 0.03: + throughput_ipc = round(throughput_ipc) + + measure[cpu][row['name']] = { + 'latency': ", ".join(map(str, latency)), + 'throughput(cpi)': throughput_cpi, + 'throughput(ipc)': throughput_ipc, + } # depends on implementation of env.macro() def my_macro(env): @@ -103,29 +127,9 @@ def instruction(intrinsic, instr, desc): throughputs = [] for cpu in cpus: if instr_name in measure[cpu]: - latency = [] - for part in measure[cpu][instr_name]['latency'].split('/'): - if part == "": - lat = "N/A" - else: - lat = float(part) - if abs((lat - round(lat)) / lat) < 0.02: - lat = round(lat) - latency.append(lat) - latency = sorted(list(set(latency))) - - throughput_cpi = float(measure[cpu][instr_name]['throughput(cpi)']) - if abs(throughput_cpi - round(throughput_cpi)) < 0.03: - throughput_cpi = round(throughput_cpi) - - # TODO: handle small cpi better by 1/ipc - throughput_ipc = float(measure[cpu][instr_name]['throughput(ipc)']) - if abs(throughput_ipc - round(throughput_ipc)) < 0.03: - throughput_ipc = round(throughput_ipc) - show_cpus.append(cpu) - latencies.append(", ".join(map(str, latency))) - throughputs.append(throughput_cpi) + latencies.append(measure[cpu][instr_name]['latency']) + throughputs.append(measure[cpu][instr_name]['throughput(cpi)']) if len(show_cpus) > 0: latency_throughput = f""" @@ -1844,3 +1848,31 @@ def all_groups(): result.append(title) break return json.dumps(sorted(list(set(result)))) + + @env.macro + def latency_throughput_table(): + result = "" + for cpu in cpus: + result += f"" + result += f"" + for cpu in cpus: + result += f"" + result += f"" + + result += "" + + insts = [] + for cpu in cpus: + insts.extend(measure[cpu].keys()) + insts = sorted(list(set(insts))) + + for inst in insts: + result += "" + result += f"" + for cpu in cpus: + result += f"" + result += f"" + result += "" + + result += "" + return result \ No newline at end of file
Instructino{cpu}
LatencyThroughput (CPI)
{inst}{measure[cpu][inst]['latency']}{measure[cpu][inst]['throughput(cpi)']}