Skip to content

Commit

Permalink
Move evaluation scripts to separate directory
Browse files Browse the repository at this point in the history
  • Loading branch information
polybeandip committed Nov 4, 2024
1 parent 7a66029 commit deccc0e
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 2 deletions.
35 changes: 35 additions & 0 deletions frontends/queues/evaluation/cycles.sh
Original file line number Diff line number Diff line change
@@ -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 "}"
16 changes: 16 additions & 0 deletions frontends/queues/evaluation/plot_pcap_sim.py
Original file line number Diff line number Diff line change
@@ -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__":

116 changes: 116 additions & 0 deletions frontends/queues/evaluation/plot_stats.py
Original file line number Diff line number Diff line change
@@ -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)
41 changes: 41 additions & 0 deletions frontends/queues/evaluation/resources.sh
Original file line number Diff line number Diff line change
@@ -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 "}"
7 changes: 5 additions & 2 deletions frontends/queues/tests/binheap/strict/strict_2flow_test.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
)
Expand Down

0 comments on commit deccc0e

Please sign in to comment.