Skip to content

Commit

Permalink
update generalize_pifos
Browse files Browse the repository at this point in the history
  • Loading branch information
Cassandra Nicole Sziklai committed Jun 20, 2024
1 parent 662fd4a commit e7805b6
Show file tree
Hide file tree
Showing 14 changed files with 121,432 additions and 285 deletions.
1 change: 1 addition & 0 deletions calyx-py/calyx/err.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
error: ./runt.toml is missing. Runt expects a directory with a runt.toml file.
15 changes: 15 additions & 0 deletions calyx-py/calyx/pifo_oracle3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# For usage, see gen_queue_data_expect.sh

import sys
import calyx.queues as queues
from calyx import queue_util

if __name__ == "__main__":
max_cmds, len = int(sys.argv[1]), int(sys.argv[2])
commands, values = queue_util.parse_json()

# Our PIFO is simple: it just orchestrates three FIFOs. The boundary is 200.
pifo = queues.NPifo(3, 200, len)

ans = queues.operate_queue(commands, values, pifo, max_cmds)
queue_util.dump_json(commands, values, ans)
60 changes: 60 additions & 0 deletions calyx-py/calyx/queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,63 @@ def operate_queue(commands, values, queue, max_cmds):
# Pad the answer memory with zeroes until it is of length `max_cmds`.
ans += [0] * (max_cmds - len(ans))
return ans

@dataclass
class NPifo:
"""
"""
def __init__(self, n, boundary, max_len: int, error_mode=True):
self.data = []
for i in range(n):
queue = Fifo(max_len) # TODO: I am confused on the difference between len and max_len
self.data.append(queue)
#self.data = (queue_1, queue_2)
self.hot = 0
self.pifo_len = 0
divide = (boundary * 2) // n_flows
self.boundaries = []
for i in range(n):
bound = divide + (divide * n)
self.boundaries.append(bound)

self.max_len = max_len
self.error_mode = error_mode
assert (
self.pifo_len <= self.max_len
) # We can't be initialized with a PIFO that is too long.

def push(self, val: int):
"""Pushes `val` to the PIFO."""
if self.pifo_len == self.max_len:
if self.error_mode:
raise QueueError("Cannot push to full PIFO.")
return
for b in range(len(self.boundaries)):
if val <= self.boundaries[b]:
self.data[b].push(val)
break

self.pifo_len += 1 # TODO: issue with me not understanding how length works

def pop(self) -> Optional[int]:
"""Pops the PIFO."""
if self.pifo_len == 0:
if self.error_mode:
raise QueueError("Cannot pop from empty PIFO.")
return None
self.pifo_len -= 1 # We decrement `pifo_len` by 1.
if self.hot == 0:
try:
self.hot = 1
return self.data[0].pop()
except QueueError:
self.hot = 0
return self.data[1].pop()
else:
try:
self.hot = 0
return self.data[1].pop()
except QueueError:
self.hot = 1
return self.data[0].pop()

119 changes: 119 additions & 0 deletions calyx-py/test/correctness/general_pifo.data
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
{
"commands": {
"data": [
2,
0,
2,
0,
2,
2,
2,
2,
0,
0,
2,
0,
2,
2,
2,
2,
0,
0,
2,
0,
2,
2,
2,
0,
0,
0,
0,
0,
0,
0
],
"format": {
"is_signed": false,
"numeric_type": "bitnum",
"width": 2
}
},
"values": {
"data": [
317,
317,
228,
65,
68,
1,
3,
108,
397,
111,
85,
86,
149,
161,
102,
277,
348,
321,
105,
94,
354,
101,
197,
153,
12,
185,
213,
85,
75,
136
],
"format": {
"is_signed": false,
"numeric_type": "bitnum",
"width": 32
}
},
"ans_mem": {
"data": [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
],
"format": {
"is_signed": false,
"numeric_type": "bitnum",
"width": 32
}
}
}
Empty file.
Loading

0 comments on commit e7805b6

Please sign in to comment.