Skip to content

Commit

Permalink
Queues: Allow value 0, more --keepgoing, and tidier FIFO (#2167)
Browse files Browse the repository at this point in the history
* Value 0 permitted

* .data and .expect files with value 0 permitted

* Allow ans of 0

* Works?

* Back to values up to 400

* Actually allow ans of 0 to be written to ans mem

* Catch in Python oracles

* Get back to values up to 400

* No magic numbers in FIFO
  • Loading branch information
anshumanmohan authored Jun 19, 2024
1 parent de6a6cd commit 42ea1f7
Show file tree
Hide file tree
Showing 14 changed files with 250,811 additions and 250,818 deletions.
15 changes: 5 additions & 10 deletions calyx-py/calyx/queue_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,19 +173,14 @@ def insert_main(
ref_component_err=dataplane_err,
)
),
# If the dataplane component has a nonzero answer,
# If the dataplane component has an answer,
# write it to the answer-list and increment the index `j`.
cb.if_(
has_ans.out,
cb.if_with(
main.neq_use(dataplane_ans.out, 0),
[
main.mem_store_d1(
ans_mem, j.out, dataplane_ans.out, "write_ans"
),
main.incr(j),
],
),
[
main.mem_store_d1(ans_mem, j.out, dataplane_ans.out, "write_ans"),
main.incr(j),
],
),
(
cb.invoke( # Invoke the controller component.
Expand Down
6 changes: 3 additions & 3 deletions calyx-py/calyx/queue_data_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ def dump_json(num_cmds, no_err: bool, queue_size: Optional[int] = None):
}
values = {
"values": {
"data": [random.randint(1, 400) for _ in range(num_cmds)],
# The `values` memory has `num_cmds` items, whihc are all
"data": [random.randint(0, 400) for _ in range(num_cmds)],
# The `values` memory has `num_cmds` items, which are all
# random values between 0 and 400.
"format": format_gen(32),
}
Expand All @@ -105,7 +105,7 @@ def dump_json(num_cmds, no_err: bool, queue_size: Optional[int] = None):
# This says whether we should use the special no_err helper.
random.seed(5)
num_cmds = int(sys.argv[1])
no_err = len(sys.argv) > 2 and sys.argv[2] == "--no-err"
no_err = "--no-err" in sys.argv
if no_err:
queue_size = int(sys.argv[3])
dump_json(num_cmds, no_err, queue_size if no_err else None)
8 changes: 2 additions & 6 deletions calyx-py/calyx/queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,19 +158,15 @@ def operate_queue(commands, values, queue, max_cmds, keepgoing=False):
for cmd, val in zip(commands, values):
if cmd == 0:
try:
result = queue.pop()
if result:
ans.append(result)
ans.append(queue.pop())
except QueueError:
if keepgoing:
continue
break

elif cmd == 1:
try:
result = queue.peek()
if result:
ans.append(queue.peek())
ans.append(queue.peek())
except QueueError:
if keepgoing:
continue
Expand Down
Loading

0 comments on commit 42ea1f7

Please sign in to comment.