Skip to content

Commit

Permalink
Setup CI formatting check for Calyx-Py and Queues (#2295)
Browse files Browse the repository at this point in the history
Closes #2251 

Changes:
- Run `black --line-length 88` on `frontend/queues`, `calyx-py`, and
`fud`
- Tweak `.github/workflows/format.yml` to check formatting for these
directories
    - add the `--check` options to all calls to `black`
  • Loading branch information
polybeandip authored Oct 6, 2024
1 parent 47d0dc8 commit 7260196
Show file tree
Hide file tree
Showing 25 changed files with 138 additions and 131 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,23 @@ jobs:
- name: Fud Formatting check
uses: psf/black@stable
with:
options: "--line-length 88"
options: "--line-length 88 --check"
src: 'fud'
- name: Calyx-Py Formatting check
uses: psf/black@stable
with:
options: "--line-length 88 --check"
src: 'calyx-py'
- name: Systolic Array Formatting check
uses: psf/black@stable
with:
options: "--line-length 88"
options: "--line-length 88 --check"
src: 'frontends/systolic-lang'
- name: Queues Formatting check
uses: psf/black@stable
with:
options: "--line-length 88 --check"
src: 'frontends/queues'
- name: Fud Linting check
uses: TrueBrain/actions-flake8@master
with:
Expand Down
4 changes: 3 additions & 1 deletion calyx-py/calyx/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ def case(
width = self.infer_width(signal)
ifs = []
for branch, controllable in cases.items():
std_eq = self.eq(width, self.generate_name(f"{signal.name}_eq_{branch}"), signed)
std_eq = self.eq(
width, self.generate_name(f"{signal.name}_eq_{branch}"), signed
)

with self.continuous:
std_eq.left = signal
Expand Down
4 changes: 2 additions & 2 deletions calyx-py/test/case.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from calyx.builder import Builder, invoke

#Creates a component the has a case statement.

# Creates a component the has a case statement.
def add_case(prog):
# Inputs/Outputs
my_comp = prog.component("my_comp")
Expand All @@ -25,4 +26,3 @@ def build():

if __name__ == "__main__":
build().emit()

5 changes: 3 additions & 2 deletions calyx-py/test/port_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ def insert_foo_component(prog):
foo_inputs = [
("in_1", 1),
("in_2", 2, ["data"]),
("in_3", 2, ["data", ("write_together", 1)])
]
("in_3", 2, ["data", ("write_together", 1)]),
]

cb.add_comp_ports(comp, foo_inputs, [])

Expand All @@ -18,6 +18,7 @@ def insert_foo_component(prog):
comp.output("out_3", 1, ["data", ("done", 1)])
# ANCHOR_END: port_attributes


if __name__ == "__main__":
prog = cb.Builder()
insert_foo_component(prog)
Expand Down
68 changes: 35 additions & 33 deletions frontends/queues/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,41 @@ 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" : {}
}
"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]

flow_no = file.split("flow")[0][-1]

if "round_robin" in file:
if "binheap" in file:
out["binheap"]["round_robin"][flow_no] = data
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
out["binheap"]["strict"][flow_no] = data
else:
out["specialized"]["strict"][flow_no] = data
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)
Expand All @@ -55,43 +52,48 @@ def draw(data, stat, logic, unit):
ax.set_ylabel(stat, fontsize=20)
else:
ax.set_ylabel(f"{stat} ({unit})", fontsize=20)

file = ""

if logic == Logic.RR:
specialized = ax.scatter(
data["specialized"]["round_robin"].keys(),
data["specialized"]["round_robin"].values(),
c='b')
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')
data["binheap"]["round_robin"].keys(),
data["binheap"]["round_robin"].values(),
c="g",
)

ax.set_title("Round Robin Queues", fontweight='bold', fontsize=20)
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')
data["specialized"]["strict"].keys(),
data["specialized"]["strict"].values(),
c="b",
)
binheap = ax.scatter(
data["binheap"]["strict"].keys(),
data["binheap"]["strict"].values(),
c='g')
data["binheap"]["strict"].keys(), data["binheap"]["strict"].values(), c="g"
)

ax.set_title("Strict Queues", fontweight='bold', fontsize=20)
ax.set_title("Strict Queues", fontweight="bold", fontsize=20)
file = append_path_prefix(f"{stat}_strict")

plt.legend((specialized, binheap),
("Specialized (i.e. Cassandra style)", "Binary Heap"),
fontsize=12)
plt.legend(
(specialized, binheap),
("Specialized (i.e. Cassandra style)", "Binary Heap"),
fontsize=12,
)

plt.savefig(file)

print(f"Generated {file}.png")


# Parse data for round_robin and strict queues
stat = sys.argv[1]
data = {}
Expand All @@ -107,13 +109,13 @@ def draw(data, stat, logic, unit):
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]
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.RR, unit)
draw(data, stat, Logic.STRICT, unit)
2 changes: 1 addition & 1 deletion frontends/queues/queues/binheap/binheap.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def insert_binheap(prog, name, queue_size_factor, rnk_w, val_w):

comp = prog.component(name)

max_queue_size = 2 ** queue_size_factor
max_queue_size = 2**queue_size_factor
addr_size = queue_size_factor

cmd = comp.input("cmd", 1)
Expand Down
11 changes: 4 additions & 7 deletions frontends/queues/queues/binheap/flow_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,19 @@ def insert_flow_inference(comp, value, flow, boundaries, name):
guard = comp.and_(1)

with comp.comb_group(f"{name}_bound_check_{b}") as bound_check_b:
le.left = value
le.left = value
le.right = boundaries[b]
if b > 0:
lt.left = boundaries[b-1]
lt.left = boundaries[b - 1]
lt.right = value
else:
lt.left = 0
lt.left = 0
lt.right = 1
guard.left = le.out
guard.right = lt.out

set_flow_b = comp.reg_store(flow, b, f"{name}_set_flow_{b}")
bound_check = cb.if_with(
cb.CellAndGroup(guard, bound_check_b),
set_flow_b
)
bound_check = cb.if_with(cb.CellAndGroup(guard, bound_check_b), set_flow_b)

bound_checks.append(bound_check)

Expand Down
49 changes: 18 additions & 31 deletions frontends/queues/queues/binheap/round_robin.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ def insert_binheap_rr(prog, name, boundaries, queue_size_factor=FACTOR):

flow_in = comp.reg(bits_needed(n - 1), "flow_in")
infer_flow_in = insert_flow_inference(
comp, value, flow_in, boundaries, "infer_flow_in"
comp, value, flow_in, boundaries, "infer_flow_in"
)

flow_out = comp.reg(bits_needed(n - 1), "flow_out")
infer_flow_out = insert_flow_inference(
comp, ans.out, flow_out, boundaries, "infer_flow_out"
comp, ans.out, flow_out, boundaries, "infer_flow_out"
)

rank_ptrs = [comp.reg(32, f"r_{i}") for i in range(n)]
Expand All @@ -39,19 +39,14 @@ def insert_binheap_rr(prog, name, boundaries, queue_size_factor=FACTOR):
turn = comp.reg(bits_needed(n - 1), "turn")
turn_neq_flow_out = comp.neq_use(turn.out, flow_out.out)
turn_incr_mod_n = cb.if_with(
comp.eq_use(turn.out, n - 1),
comp.reg_store(turn, 0),
comp.incr(turn)
)
comp.eq_use(turn.out, n - 1), comp.reg_store(turn, 0), comp.incr(turn)
)

init = comp.reg(1, "init")
init_eq_0 = comp.eq_use(init.out, 0)
init_state = cb.if_with(
init_eq_0,
[
cb.par(*[ comp.reg_store(rank_ptrs[i], i) for i in range(n) ]),
comp.incr(init)
]
[cb.par(*[comp.reg_store(rank_ptrs[i], i) for i in range(n)]), comp.incr(init)],
)

def binheap_invoke(value, rank):
Expand All @@ -63,35 +58,27 @@ def binheap_invoke(value, rank):
ref_ans=ans,
ref_err=err,
)
binheap_invokes = dict([
(i, binheap_invoke(value, rank_ptrs[i].out))
for i in range(n)
])

binheap_invokes = dict(
[(i, binheap_invoke(value, rank_ptrs[i].out)) for i in range(n)]
)

update_state_pop = [
infer_flow_out,
cb.while_with(
turn_neq_flow_out,
[
comp.case(turn.out, rank_ptr_incrs),
turn_incr_mod_n
]
),
turn_incr_mod_n
]
infer_flow_out,
cb.while_with(
turn_neq_flow_out, [comp.case(turn.out, rank_ptr_incrs), turn_incr_mod_n]
),
turn_incr_mod_n,
]
update_state_push = comp.case(flow_in.out, rank_ptr_incrs)

comp.control += [
init_state,
infer_flow_in,
comp.case(flow_in.out, binheap_invokes),
cb.if_with(
err_eq_0,
comp.case(
cmd,
{ 0: update_state_pop, 1: update_state_push }
)
)
err_eq_0, comp.case(cmd, {0: update_state_pop, 1: update_state_push})
),
]

return comp
Expand Down
22 changes: 7 additions & 15 deletions frontends/queues/queues/binheap/strict.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@
FACTOR = 4


def insert_binheap_strict(
prog,
name,
boundaries,
order,
queue_size_factor=FACTOR):
def insert_binheap_strict(prog, name, boundaries, order, queue_size_factor=FACTOR):
n = len(boundaries)

comp = prog.component(name)
Expand All @@ -27,9 +22,7 @@ def insert_binheap_strict(
err = comp.reg(1, "err", is_ref=True)

flow = comp.reg(bits_needed(n - 1), "flow")
infer_flow = insert_flow_inference(
comp, value, flow, boundaries, "infer_flow"
)
infer_flow = insert_flow_inference(comp, value, flow, boundaries, "infer_flow")

def binheap_invoke(value, rank):
return cb.invoke(
Expand All @@ -40,12 +33,12 @@ def binheap_invoke(value, rank):
ref_ans=ans,
ref_err=err,
)
binheap_invokes = dict([
(i, binheap_invoke(value, order.index(i)))
for i in range(n)
])

comp.control += [ infer_flow, comp.case(flow.out, binheap_invokes) ]
binheap_invokes = dict(
[(i, binheap_invoke(value, order.index(i))) for i in range(n)]
)

comp.control += [infer_flow, comp.case(flow.out, binheap_invokes)]

return comp

Expand Down Expand Up @@ -77,4 +70,3 @@ def generate(prog, numflows):
pifo = insert_binheap_strict(prog, "pifo", boundaries, order)

return pifo

2 changes: 1 addition & 1 deletion frontends/queues/queues/fifo.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def insert_fifo(prog, name, queue_len_factor=QUEUE_LEN_FACTOR, val_width=32):
# If it is 1, we push `value` to the queue.
value = fifo.input("value", val_width) # The value to push to the queue

max_queue_len = 2 ** queue_len_factor
max_queue_len = 2**queue_len_factor
mem = fifo.seq_mem_d1("mem", val_width, max_queue_len, queue_len_factor)
write = fifo.reg(queue_len_factor) # The next address to write to
read = fifo.reg(queue_len_factor) # The next address to read from
Expand Down
Loading

0 comments on commit 7260196

Please sign in to comment.