-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
116 lines (90 loc) · 3.77 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# ===> denotes to possible mistakes/improvements, other comments are descriptive
# Assumption per algorithm sections are described in each file below
from dfg_generator import *
from stage1 import *
from stage2 import *
from stage3 import *
from functions import *
from math import ceil
if __name__ == "__main__":
###########################
# SECTION 0: Preparation #
###########################
# Generate DFG from equation
equations = []
with open('input.txt') as text:
for line in text:
equations.append(line.strip())
# Define map of PEs to mark which PEs are free, which are not
# PE assignment will be reflected on node.alloc property
w, h = 10, 10
scheduler = Scheduler( )
allocator = Allocator(w, h)
rescheduler = Rescheduler(w, h, 256, False)
for i, equation in enumerate(equations):
###################
# SECTION 1: HLS #
###################
print('\n------------------Synthesys of equation {} has started!---------------\n'.format(i+1))
graph = DFGGenerator(equation).graph.graph
write(graph)
scheduler.putNewGraph(graph)
allocator.putNewGraph(graph)
# Initial schedule
asap = scheduler.schedule('asap')
alap = scheduler.schedule('alap',max(asap))
# Critical path
cpextractor = CPExtractor(graph)
cp = cpextractor.extract()
# Cps are collected just for print purposes
cps = [cp]
cp_allocs = {}
# Extract critical paths, allocate and schedule
# CPs are extracted from longest to shortest length
i = 1
while cp:
if i > w*h:
pass
# raise error!
dump = [node.name for node in reversed(cp)]
print('\n{}. DUMPED cp: '.format(i), dump)
i = i + 1
allocator.allocateCp(cp, w, h, scheduler)
cp_allocs.update({cp[0].alloc : [(node.name, node.sched) for node in cp]})
cp = cpextractor.extract()
if cp:
cps.append(cp)
# Collect input allocation per PEs
input_allocs = {node.alloc : [] for node in graph if node.sched is 0}
for node in graph:
for alloc in input_allocs:
if node.sched is 0 and node.alloc == alloc:
input_allocs[alloc].append(node.name)
print('\nInput allocation by PEs:')
printDict(input_allocs)
print('\nFinal results before rescheduling (node.name, node.sched) by PEs: ')
printDict(cp_allocs)
rescheduler.putNewGraph(graph, allocator.inputs_by_pes, allocator.mult_inps)
# Second arg indicates throughput, which is by default = 1
# For now rescheduler works only for throughput of 1
# ===> Change it later for throughput of 2
rescheduler.reschedule(1)
print('\nFinal results after rescheduling (node.name, node.sched): by PEs')
cp_allocs = {cp[0].alloc : [(node.name, node.sched) for node in cp] for cp in cps}
printDict(cp_allocs)
# Show PE utilization
print('\nPE map ')
for pe in allocator.pemap:
print(pe)
############################
# SECTION 2: MICROPACKETS #
############################
print("\nNode scheds and CCM commands:")
printDict(rescheduler.node_scheds)
print("\nRouter scheds and CCM commands:")
printDict(rescheduler.router_scheds)
print('\nRescheduler marker:')
printDict(rescheduler.marker)
print("\nScheduling duration in clocks: ", rescheduler.duration)
print("\nCCM Size in bits: ", rescheduler.ccmsize)
print("\nCCM Size in bytes: ", ceil(rescheduler.ccmsize/8))