-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtool.py
402 lines (358 loc) · 15.4 KB
/
vtool.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# pip install dash-cytoscape==0.1.1
#
import json
import dash
import dash_core_components as dcc
import dash_html_components as html
import dash_cytoscape as cyto
from dash.dependencies import Input, Output
from textwrap import dedent as d
import plotly.graph_objects as go
# import MLTL compiler
from MLTL_Compiler import *
from MLTL_Resource import *
from Software_Time import *
cyto.load_extra_layouts()
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
server = app.server
app.title = "MLTL Compiler"
default_stylesheet = [
{
'selector': '[type = "ATOM"]',
'style': {
'background-color': '#ff9900',
'label': 'data(name)'
}
},
{
'selector': '[type = "BOOL"]',
'style': {
'background-color': '#BFD7B5',
'label': 'data(name)'
}
},
{
'selector': '[type = "NEG"]',
'style': {
'background-color': '#66ff99',
'label': 'data(name)'
}
},
{
'selector': '[type = "GLOBAL"]',
'style': {
'background-color': '#6699ff',
'label': 'data(name)'
}
},
{
'selector': '[type = "AND"]',
'style': {
'background-color': '#ff6666',
'label': 'data(name)'
}
},
{
'selector': '[type = "UNTIL"]',
'style': {
'background-color': '#cc00cc',
'label': 'data(name)'
}
},
{
'selector': 'edge',
'style': {
'curve-style': 'bezier',
'target-arrow-color': 'black',
'target-arrow-shape': 'vee',
'line-color': 'black'
}
}
]
styles = {
'json-output': {
'overflow-y': 'scroll',
'height': 'calc(50% - 25px)',
'border': 'thin lightgrey solid'
},
'tab': {'height': 'calc(98vh - 115px)'},
}
app.layout = html.Div(
children = [
################title
html.Div(
[html.H1('R2U2 MLTL Compiler')],
className = 'row',
style = {'textAlign':'center'}
),
############### left view
html.Div(
className = 'row',
children= [
html.Div(
className = 'three columns',
children = [
dcc.Markdown(d("""
### MLTL Formula Configuration
""")),
dcc.Markdown(d("""
###### MLTL Formula
""")),
# dcc.Input(id='formula', value='a0 U[5] a1; a1&a3;', type='text'),
dcc.Textarea(
id='formula',
value='a0;\na1 & a2;\na3 U[1,4]a5;\nG[10] b0;\n(a3 U[1,4]a5)&(G[10] b0);',
style={'width': '100%', 'height': '150px'},
),
dcc.Checklist(
id = 'optimization',
options=[
{'label': 'Common Subexpression Elimination', 'value': 'opt_cse'},
],
value=['opt_cse',]
),
html.Pre(id='compile_status', style = {'color': 'green'}),
dcc.Markdown(d("""
**Prediction Horizon Hp**
""")),
dcc.Input(id='pred_length', value='0', type='text'),
html.Div(
style={'backgroundColor': '#F7FAC0'},
children = [
dcc.Markdown(d("---\n### Hardware System Configuration")),
dcc.Markdown(d("**Hardware Clock Frequency (MHz)**")),
dcc.Input(style={'backgroundColor': '#F7FAC0'},id='hardware_clk', value='100', type='text'),
dcc.Markdown(d("**LUT Type Select**")),
dcc.Dropdown(
id = 'LUT_type',
style={'backgroundColor': '#F7FAC0'},
options=[
{'label': 'LUT-3', 'value': '3'},
{'label': 'LUT-4', 'value': '4'},
{'label': 'LUT-6', 'value': '6'},
],
value='3',
clearable=False
),
dcc.Markdown(d("**Resource to Observe Select**")),
dcc.Dropdown(
id = 'resource_type',
style={'backgroundColor': '#F7FAC0'},
options=[
{'label': 'LUT', 'value': 'LUT'},
{'label': '18Kb BRAM', 'value': '18kbBRAM'},
],
value='LUT',
clearable=False
),
dcc.Markdown(d("**Timestamp Length (bit)**")),
dcc.Slider(
id='timestamp_length',
min=0,
max=64,
step=1,
value=32,
),
# html.Div(style="width:500px;height:100px;border:1px solid #000;"),
html.Div(id='slider-output-container-ts'),
# dcc.Input(id='timestamp_length', value='32', type='text'),
html.Div(
# style={'backgroundColor': '#A2F0E4'},
children = [
dcc.Markdown(d("---\n### Results for Timing and Resource")),
dcc.Markdown(d("**Worst-case Execution Time**")),
html.Div(id="comp_speed_FPGA",),
dcc.Markdown(d("**Total Entry of SCQ for the AST**")),
html.Div(id="tot_scq_size",),
]
),
],
),
html.Div(
style={'backgroundColor': '#A2F0E4'},
children = [
dcc.Markdown(d("---\n### Software System Configuration")),
# Command exection time for each operator
dcc.Markdown(d("**CPU Clock Cycle for Each Operator**")),
dcc.Input(style={'backgroundColor': '#A2F0E4'}, id='op_exe_time', value='10', type='text'),
# Processing time for each atomic checker
dcc.Markdown(d("**CPU Clock Cycle for Each Atomic Checker**")),
dcc.Input(style={'backgroundColor': '#A2F0E4'}, id='at_exe_time', value='10', type='text'),
dcc.Markdown(d("**CPU Clock Frequency (GHz)**")),
dcc.Input(style={'backgroundColor': '#A2F0E4'}, id='cpu_clk', value='10', type='text'),
dcc.Markdown(d("**Worst-case Execution Time**")),
html.Div(id="comp_speed_CPU",),
dcc.Markdown(d("**Total Memory usage for SCQ**")),
html.Div(id="tot_memory",),
]
)
],
style={'height': '300px'},
),
html.Div(
className = 'five columns',
children = [
cyto.Cytoscape(
id='tree',
# layout={'name': 'circle'},
layout={'name': 'klay','klay': {'direction': 'DOWN'}},
stylesheet=default_stylesheet,
style={'width': '100%', 'height': '450px'},
elements=[]
),
dcc.Graph(
id='resource_usage',
figure = go.Figure(),
)
]
),
html.Div(
className = 'four columns',
children = [
dcc.Tabs(
id='tabs',
children=[
dcc.Tab(
label='Mouseover Data',
children=[
html.Div(
style=styles['tab'],
children=[
html.P(id='status',children=['Init']),
# html.P('Node Data JSON:'),
html.Pre(
id='mouseover-node-data-json-output',
style=styles['json-output']
),
html.P('Edge Data JSON:'),
html.Pre(
id='mouseover-edge-data-json-output',
style=styles['json-output']
)
]
)
]
),
dcc.Tab(
label='Assembly Output',
children=[
html.Div(
style=styles['tab'],
children=[
html.P('Assembly:'),
html.Pre(
id='assembly_window',
style=styles['json-output'],
),
]
)
]
),
]
),
]
)
],
),
])
@app.callback(
Output('slider-output-container-ts', 'children'),
[Input('timestamp_length', 'value')])
def update_output(value):
return 'You have selected "{}" bit'.format(value)
@app.callback(Output('mouseover-edge-data-json-output', 'children'),
[Input('tree', 'mouseoverEdgeData')])
def displayMouseoverEdgeData(data):
return json.dumps(data, indent=2)
@app.callback(
Output('mouseover-node-data-json-output', 'children'),
[Input('tree', 'mouseoverNodeData')])
def displayMouseoverNodeTitle(data):
if (data==None or 'bpd' not in data):
return html.P('None')
return html.P(
'Name:'+str(data['name'])+'\n'
+'bpd:'+str(data['bpd'])+'\n'
+'wpd:'+str(data['wpd'])+'\n'
+'SCQ size:'+str(data['scq_size'])+'\n'
)
@app.callback(Output('status', 'children'),
[Input('tree', 'mouseoverNodeData')])
def displayMouseoverNodeData(data):
if (data==None or 'num' not in data):
return html.P('Node: Unselected')
return html.P('Node: '+str(data['num']))
def speed_unit_conversion(clk):
if clk < 0:
comp_speed = "Err: Operator unsupported in hardware!"
elif clk<1000:
comp_speed = '{:.6f}μs/ {:.6f}MHz'.format(clk, 1/clk)
elif clk<1000000:
comp_speed = '{:.6f}ms/ {:.6f}KHz'.format(clk/1000, 1/(clk/1000))
else:
comp_speed = '{:.6f}s/ {:.6f}Hz'.format(clk/1000000, 1/(clk/1000000))
return comp_speed
@app.callback( # multiple output is a new feature since dash==0.39.0
[Output(component_id = 'tree', component_property = 'elements'),
Output(component_id = 'assembly_window', component_property = 'children'),
Output(component_id = 'compile_status', component_property = 'children'),
Output(component_id = 'compile_status', component_property = 'style'),
Output(component_id = 'comp_speed_FPGA', component_property = 'children'),
Output(component_id = 'comp_speed_CPU', component_property = 'children'),
Output(component_id = 'tot_scq_size', component_property = 'children'),
Output(component_id = 'tot_memory', component_property = 'children'),
Output(component_id = 'resource_usage', component_property = 'figure'),
],
[Input(component_id = 'formula', component_property = 'value'),
Input(component_id = 'optimization', component_property = 'value'),
Input(component_id = 'pred_length', component_property = 'value'),
Input(component_id = 'hardware_clk', component_property = 'value'),
Input(component_id = 'timestamp_length', component_property = 'value'),
Input(component_id = 'LUT_type', component_property = 'value'),
Input(component_id = 'resource_type', component_property = 'value'),
Input(component_id = 'op_exe_time', component_property = 'value'),
Input(component_id = 'at_exe_time', component_property = 'value'),
Input(component_id = 'cpu_clk', component_property = 'value'),
]
)
def update_element(formula, optimization, pred_length, hw_clk, timestamp_length, LUT_type, resource_type, op_exe_time, at_exe_time, cpu_clk):
opt_cse = True if 'opt_cse' in optimization else False
pg = Postgraph(MLTL=formula,Hp=int(pred_length),optimize_cse=opt_cse)
compile_status = "Compile status: "+ pg.status.upper()
if (pg.status!='pass'):
elements = []
assembly_window = 'Error'
style = {'color':'red'}
comp_speed_FPGA = 'NA'
comp_speed_CPU = 'NA'
else:
node = [
{'data':{'id': str(node), 'num': num, 'type': node.type, 'name':node.name,'bpd':node.bpd, 'wpd':node.wpd, 'scq_size':node.scq_size} }
for num , node in enumerate(pg.valid_node_set) if isinstance(node, Observer)
]
edge = []
atomic_op = set()
for src in pg.valid_node_set:
if (src.left):
edge.append({'data':{'source':str(src), 'target':str(src.left)}})
if (src.right):
edge.append({'data':{'source':str(src), 'target':str(src.right)}})
if (src.left==None and src.right==None):
atomic_op.add(src)
elements = node + edge
assembly_window = pg.asm
style = {'color':'blue'}
tot_memory = str(pg.tot_size*timestamp_length/8/1024)+"KB" #KB
tot_scq_size = str(pg.tot_size) # + "(" + str()+ ")"
tmp = pg.tot_time/int(hw_clk)
comp_speed_FPGA = speed_unit_conversion(tmp)
comp_speed_CPU = speed_unit_conversion(int(at_exe_time)*len(atomic_op)+int(op_exe_time)*pg.tot_size/int(cpu_clk))
resource_fig = data_process.RF
resource_fig.config(LUT_type, tot_scq_size, int(timestamp_length))
select_fig = resource_fig.get_LUT_fig() if resource_type == "LUT" else resource_fig.get_BRAM_fig()
return elements, assembly_window, compile_status, style, comp_speed_FPGA, comp_speed_CPU , tot_scq_size, tot_memory, select_fig
if __name__ == '__main__':
app.run_server(debug=True)