From deccc0e58f69979ffba21e683bbc951fb8e8fcc6 Mon Sep 17 00:00:00 2001 From: Akash Dhiraj Date: Mon, 4 Nov 2024 15:38:50 -0500 Subject: [PATCH] Move evaluation scripts to separate directory --- frontends/queues/evaluation/cycles.sh | 35 ++++++ frontends/queues/evaluation/plot_pcap_sim.py | 16 +++ frontends/queues/evaluation/plot_stats.py | 116 ++++++++++++++++++ frontends/queues/evaluation/resources.sh | 41 +++++++ .../tests/binheap/strict/strict_2flow_test.py | 7 +- 5 files changed, 213 insertions(+), 2 deletions(-) create mode 100755 frontends/queues/evaluation/cycles.sh create mode 100644 frontends/queues/evaluation/plot_pcap_sim.py create mode 100644 frontends/queues/evaluation/plot_stats.py create mode 100755 frontends/queues/evaluation/resources.sh diff --git a/frontends/queues/evaluation/cycles.sh b/frontends/queues/evaluation/cycles.sh new file mode 100755 index 000000000..5ea18748d --- /dev/null +++ b/frontends/queues/evaluation/cycles.sh @@ -0,0 +1,35 @@ +#!/usr/bin/bash + +shopt -s globstar + +cd "$(dirname "$0")/../../.." # move to root + +declare -a files=(frontends/queues/tests/**/*.py) +num_files=${#files[@]} + +echo "{" + +for (( i=0; i<${num_files}; i++ )); do + file="${files[$i]}" + name="$(basename $file .py)" + dir="$(dirname $file)" + + cycles="$(python3 $file 20000 --keepgoing |\ + fud e --from calyx --to jq \ + --through verilog \ + --through dat \ + -s verilog.data "$dir/$name.data" \ + -s jq.expr ".cycles" \ + -q)" + + echo -n "\"${file#*tests/}\" : $cycles" + + # because JSON doesn't allow trailing ','s + if [ $i -ne $(( num_files - 1 )) ]; then + echo "," + else + echo "" + fi +done + +echo "}" diff --git a/frontends/queues/evaluation/plot_pcap_sim.py b/frontends/queues/evaluation/plot_pcap_sim.py new file mode 100644 index 000000000..1ba8702ab --- /dev/null +++ b/frontends/queues/evaluation/plot_pcap_sim.py @@ -0,0 +1,16 @@ +import os +import json + + +def append_path_prefix(file): + path_to_script = os.path.dirname(__file__) + path_to_file = os.path.join(path_to_script, file) + return path_to_file + + +def parse(file): + out[] = + + +if __name__ == "__main__": + diff --git a/frontends/queues/evaluation/plot_stats.py b/frontends/queues/evaluation/plot_stats.py new file mode 100644 index 000000000..49c56f7ab --- /dev/null +++ b/frontends/queues/evaluation/plot_stats.py @@ -0,0 +1,116 @@ +import os +import sys +import json +from enum import Enum +import matplotlib.pyplot as plt + + +class Logic(Enum): + RR = 1 + STRICT = 2 + + +def append_path_prefix(file): + path_to_script = os.path.dirname(__file__) + path_to_file = os.path.join(path_to_script, file) + return path_to_file + + +def parse(stat, file): + out = { + "binheap": {"round_robin": {}, "strict": {}}, + "specialized": {"round_robin": {}, "strict": {}}, + } + + with open(file) as file: + data = json.load(file) + for file, data in data.items(): + if isinstance(data, dict): + data = data[stat] + + flow_no = file.split("flow")[0][-1] + + if "round_robin" in file: + if "binheap" in file: + out["binheap"]["round_robin"][flow_no] = data + else: + out["specialized"]["round_robin"][flow_no] = data + if "strict" in file: + if "binheap" in file: + out["binheap"]["strict"][flow_no] = data + else: + out["specialized"]["strict"][flow_no] = data + + return out + + +def draw(data, stat, logic, unit): + fig, ax = plt.subplots(1, 1) + fig.set_size_inches(20, 10, forward=True) + ax.set_xlabel("number of flows", fontsize=20) + if unit is None: + ax.set_ylabel(stat, fontsize=20) + else: + ax.set_ylabel(f"{stat} ({unit})", fontsize=20) + + if logic == Logic.RR: + specialized = ax.scatter( + data["specialized"]["round_robin"].keys(), + data["specialized"]["round_robin"].values(), + c="b", + ) + binheap = ax.scatter( + data["binheap"]["round_robin"].keys(), + data["binheap"]["round_robin"].values(), + c="g", + ) + + ax.set_title("Round Robin Queues", fontweight="bold", fontsize=20) + file = append_path_prefix(f"{stat}_round_robin") + + elif logic == Logic.STRICT: + specialized = ax.scatter( + data["specialized"]["strict"].keys(), + data["specialized"]["strict"].values(), + c="b", + ) + binheap = ax.scatter( + data["binheap"]["strict"].keys(), data["binheap"]["strict"].values(), c="g" + ) + + ax.set_title("Strict Queues", fontweight="bold", fontsize=20) + file = append_path_prefix(f"{stat}_strict") + + plt.legend((specialized, binheap), ("Specialized", "Binary Heap"), fontsize=12) + + plt.savefig(file) + + print(f"Generated {file}.png") + + +if __name__ == "__main__": + # Parse data for round_robin and strict queues + stat = sys.argv[1] + data = {} + if stat == "total_time": + file1 = sys.argv[2] + file2 = sys.argv[3] + + cycle_data = parse("cycles", file1) + slack_data = parse("worst_slack", file2) + + data = cycle_data.copy() + for impl in data.keys(): + for logic in data[impl].keys(): + for flow_no in data[impl][logic].keys(): + cycles = cycle_data[impl][logic][flow_no] + slack = slack_data[impl][logic][flow_no] + data[impl][logic][flow_no] = (1000 * cycles) / (7 - slack) + else: + file = sys.argv[2] + data = parse(stat, file) + + # Draw results + unit = "μs" if stat == "total_time" else None + draw(data, stat, Logic.RR, unit) + draw(data, stat, Logic.STRICT, unit) diff --git a/frontends/queues/evaluation/resources.sh b/frontends/queues/evaluation/resources.sh new file mode 100755 index 000000000..661e095d9 --- /dev/null +++ b/frontends/queues/evaluation/resources.sh @@ -0,0 +1,41 @@ +#!/usr/bin/bash + +shopt -s globstar + +if [ "$#" -gt 1 ]; then + echo "usage: ./resources.sh [resource]" + exit 1 +fi + +cd "$(dirname "$0")/../../.." # move to root + +declare -a files=(frontends/queues/tests/**/*.py) +num_files=${#files[@]} + +echo "{" + +for (( i=0; i<${num_files}; i++ )); do + file="${files[$i]}" + name="$(basename $file .py)" + dir="$(dirname $file)" + + resources="$(python3 $file 20000 --keepgoing |\ + fud e --from calyx --to resource-estimate)" + + if [ "$#" -eq 1 ]; then + resource=$(jq ".$1" <<< "$resources") + echo -n "\"${file#*tests/}\" : $resource" + else + echo "\"${file#*tests/}\" :" + echo -n "$resources" + fi + + # because JSON doesn't allow trailing ','s + if [ $i -ne $(( num_files - 1 )) ]; then + echo "," + else + echo "" + fi +done + +echo "}" diff --git a/frontends/queues/tests/binheap/strict/strict_2flow_test.py b/frontends/queues/tests/binheap/strict/strict_2flow_test.py index 0d62c5be9..031ae069e 100644 --- a/frontends/queues/tests/binheap/strict/strict_2flow_test.py +++ b/frontends/queues/tests/binheap/strict/strict_2flow_test.py @@ -1,6 +1,7 @@ import sys import calyx.builder as cb import queues.queue_call as qc +import queues.sim_pcap as sp import queues.binheap.strict as st import queues.flow_inference as fi @@ -15,11 +16,13 @@ prog = cb.Builder() + order = [1, 0] if sim_pcap: - raise Exception("Not Implemented") + flow_infer = fi.insert_tuple_flow_inference(prog, "flow_inference", NUMFLOWS) + pifo = st.insert_binheap_strict(prog, "pifo", NUMFLOWS, order, flow_infer) + sp.insert_main(prog, pifo, num_cmds, NUMFLOWS) else: boundaries = [200, 400] - order = [1, 0] flow_infer = fi.insert_boundary_flow_inference( prog, "flow_inference", boundaries )