-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathsyn
executable file
·385 lines (348 loc) · 21 KB
/
syn
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
#!/bin/csh -f
####################################################################################
## Copyright (c) 2015 ; The University of British Columbia ; All rights reserved. ##
## ##
## Redistribution and use in source and binary forms, with or without ##
## modification, are permitted provided that the following conditions are met: ##
## * Redistributions of source code must retain the above copyright ##
## notice, this list of conditions and the following disclaimer. ##
## * Redistributions in binary form must reproduce the above copyright ##
## notice, this list of conditions and the following disclaimer in the ##
## documentation and/or other materials provided with the distribution. ##
## * Neither the name of the University of British Columbia (UBC) nor the names ##
## of its contributors may be used to endorse or promote products ##
## derived from this software without specific prior written permission. ##
## ##
## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" ##
## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ##
## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE ##
## DISCLAIMED. IN NO EVENT SHALL University of British Columbia (UBC) BE LIABLE ##
## FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ##
## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ##
## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ##
## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ##
## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ##
## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ##
####################################################################################
####################################################################################
## Run-in-batch Synthesis Flow Manager ##
## ##
## Author: Ameer M.S. Abdelhadi ([email protected]; [email protected]) ##
## SRAM-based TCAM; The University of British Columbia (UBC), December 2015 ##
####################################################################################
####################################################################################
## USAGE: ##
## ./syn <Architecture list> <Pattern width list (X 9-bit)> <Depth list (X 1k)> ##
## [-cd='Output encoder combinatorial max depth list'] [-pw] [-ri] [-ro] ##
## - arguments surrounded by angle brackets '<>' are mandatory, while arguments ##
## surrouned by square brackets are optional. ##
## - lists are comma delimited list with no spaces and can be surrounded by any ##
## type of brackets '()', '[]', '{}', or '<>'. ##
## - Mandatory arguments: ##
## * Architecture list is 'LMP' for longest-prefix-match TCAM, 'PEM' for ##
## priority-encoded TCAM, or 'LMP,PEM' for both. ##
## * Pattern width is a postive integer and represents multiples of 9-bits. ##
## * CAM depth is a positive integer and represents multiples of 1024 lines. ##
## - Optional switches: ##
## * '-cd' Output encoder combinatorial maximum depth; acheived by pipelining, ##
## default is infinite (fully combinatorial) ##
## * '-pw' pipeline write / doubles the number of writing cycles to ~1k cycles. ##
## * '-ri' register all inputs (basically, for static timing analysis). ##
## * '-ro' register all outputs (basically, for static timing analysis). ##
## ##
## EXAMPLES: ##
## ./syn PEM 14 8 -ri -ro ##
## Synthesis a PEM TCAM with 8 K-lines, 126 bits pattern width, registered ##
## inputs and outputs, unpipelined write and combinatorial output decoders ##
## ./syn PEM,LPM 4,7 2,4 -cd=2,4 -pw -ri -ro ##
## Synthesis a PEM and LPM TCAMs with 2 and 4 k-lines, 36 and 63 bit pattern, ##
## 2 and 4 encoder max combinatorial depth, pipelined write, and registered IOs##
## ##
## The following files and directories will be created after compilation: ##
## - syn.res : A list of results, each run in a separate line, including: ##
## frequency, resources usage, and runtime ##
## - log/ : Altera's logs and reports ##
####################################################################################
# setup environment variables and Altera's CAD tools
# change file to your own flow if necessary
source ./altera.15.1.csh
# text coloring and formatting
set BLK = '\x1b[1;30m' # black
set RED = '\x1b[1;31m' # red
set GRN = '\x1b[1;32m' # green
set YLW = '\x1b[1;33m' # yellow
set BLU = '\x1b[1;34m' # blue
set MGN = '\x1b[1;35m' # magenta
set CYN = '\x1b[1;36m' # cyan
set GRY = '\x1b[1;90m' # gray
set WTE = '\x1b[1;97m' # gray
set LRED = '\x1b[1;91m' # light red
set LGRN = '\x1b[1;92m' # light green
set LYLW = '\x1b[1;93m' # light yellow
set LBLU = '\x1b[1;94m' # light blue
set LMGN = '\x1b[1;95m' # light magenta
set LCYN = '\x1b[1;96m' # light cyan
set LGRY = '\x1b[1;37m' # light gray
set BLKI = '\x1b[7;30m' # black inverted
set REDI = '\x1b[7;31m' # red inverted
set GRNI = '\x1b[7;32m' # green inverted
set YLWI = '\x1b[7;33m' # yellow inverted
set BLUI = '\x1b[7;34m' # blue inverted
set MGNI = '\x1b[7;35m' # magenta inverted
set CYNI = '\x1b[7;36m' # cyan inverted
set GRYI = '\x1b[7;90m' # gray inverted
set WTEI = '\x1b[7;97m' # gray inverted
set LREDI = '\x1b[7;91m' # light red inverted
set LGRNI = '\x1b[7;92m' # light green inverted
set LYLWI = '\x1b[7;93m' # light yellow inverted
set LBLUI = '\x1b[7;94m' # light blue inverted
set LMGNI = '\x1b[7;95m' # light magenta inverted
set LCYNI = '\x1b[7;96m' # light cyan inverted
set LGRYI = '\x1b[7;37m' # light gray inverted
set RST = '\x1b[0m' # reset formatting
# require at least 3 mandatory arguments
if (${#argv} < 3) then
printf "${RED}Error: At least 3 arguments are required\n${RST}"
goto errorMessage
endif
# convert each argument list into a c-shell list (remove commas and etc.)
set ARCHLST = (`echo ${argv[1]} | tr ",()[]{}<>" " "`)
set PATWLST = (`echo ${argv[2]} | tr ",()[]{}<>" " "`)
set CAMDLST = (`echo ${argv[3]} | tr ",()[]{}<>" " "`)
# default optional argument values
set ECMDLST = 999999 # encoder combinatorial maximum depth, default is infinite (fully combinatorial)
set PIPEWRT = 0 # pipeline write / default is unpipelined
set REGINPS = 0 # register inputs / default is unregistered
set REGOUTS = 0 # register outputs / default is unregistered
# optional arguments
set i = 4
while ($i <= ${#argv})
set ARG1 = `echo ${argv[$i]}|cut -d'=' -f1`
set ARG2 = `echo ${argv[$i]}|cut -d'=' -f2`
switch ($ARG1)
case "-[Cc][Dd]":
set ECMDLST = (`echo ${ARG2} | tr ",()[]{}<>" " "`)
breaksw
case "-[Pp][Ww]":
set PIPEWRT = 1
breaksw
case "-[Rr][Ii]":
set REGINPS = 1
breaksw
case "-[Rr][Oo]":
set REGOUTS = 1
breaksw
default:
printf "${RED}Error (${ARG1}): wrong argument\n${RST}"
goto errorMessage
breaksw
endsw
@ i++
end
# check architecture list argument correctness
foreach ARGVAL ($ARCHLST)
if ( ($ARGVAL != "PEM") & ($ARGVAL != "LPM") ) then
printf "${RED}Error (${ARGVAL}): architecture should be PEM ot LPM\n${RST}"
goto errorMessage
endif
end
# check arguments correctness (positive integer numbers)
foreach ARGVAL ($CAMDLST $PATWLST $ECMDLST)
set ARGVALIsNumber=`echo $ARGVAL | egrep -c '^[0-9]+$'`
if ($ARGVALIsNumber != 1) then
printf "${RED}Error (${ARGVAL}): Pattern width, CAM depth, and output encoder combinatorial max depth lists should be a possitive integer lists\n${RST}"
goto errorMessage
endif
end
# total different designs
@ FlowOprNum = ( (${#ARCHLST}) * (${#CAMDLST}) * (${#PATWLST}) * (${#ECMDLST}) )
@ FlowOprCnt = 0
printf "${GRNI}== Synthesis in batch with the following parameters:\n"
printf "= Architecture : $ARCHLST\n"
printf "= CAM Depth : $CAMDLST\n"
printf "= Pattern width : $PATWLST\n"
printf "= encoder's combinatorial max depth: $ECMDLST\n"
printf "= pipeline write? : $PIPEWRT\n"
printf "= registered inputs? : $REGINPS\n"
printf "= registered outputs? : $REGOUTS\n${RST}"
#print header
set FML = `grep " FAMILY " iitcam.qsf | cut -d\" -f2`
set DEV = `grep " DEVICE " iitcam.qsf | cut -d" " -f4`
set TTL1 = 'TCAM TCAM Patt- Pipe- OutputEncoder Fmax-MHz 0.9v Combinational ALUT usage for logic LABs I/O Pins BRAM Bits Utiliz. \n'
set TTL2 = 'Archi- Depth ern lined Registered? Combinatorail ------------- ----------------------------------------- Route Total Total ----------------- -------------- BRAM M L A B ----------------- Runtime\n'
set TTL3 = 'tecture X1024 Width Write Inputs Outputs Maximum Depth T = 0c T= 85c Total 7-LUTs 6-LUTs 5-LUTs 4-LUTs 3-LUTs ALUTs Reg. ALMs Total Logic Mem. Tot. Clk Ded. M20K B i t s Utilized Occupied DSPs Minutes\n'
set SEPR = '======= ===== ===== ===== ======= ======= ============= ====== ====== ====== ====== ====== ====== ====== ====== ====== ====== ====== ===== ===== ===== ==== ==== ==== ==== ======= ======== ======== ==== =======\n'
set FRMT = (`echo $SEPR| tr " " "\n" | perl -nle '$a= length; print "%-${a}s"' | tr "\n" " "`) # formating
set FCNT = `echo $SEPR|wc -w` # fields count
if !(-f syn.res) then
printf "$FML $DEV\n\n$TTL1$TTL2$TTL3$SEPR" >! syn.res
endif
#initialize result values
set val = (`repeat $FCNT echo "N/A"`)
# create log directoy
if !(-d log) mkdir log
# operate on all different RAM parameters
foreach CURARCH ($ARCHLST)
foreach CURPATW ($PATWLST)
foreach CURCAMD ($CAMDLST)
foreach CURECMD ($ECMDLST)
@ FlowOprCnt++
set curRunStartTime = `date +%T`
set curRunStartTimeStamp = `date +%s`
set RUNNAME = "${CURARCH}_${CURPATW}X${CURCAMD}-${CURECMD}-${REGINPS}-${REGOUTS}"
# Pattern width in bits
set PATWBIT = `expr $CURPATW \* 9`
# CAM depth entries
set CAMDENT = `expr $CURCAMD \* 1024`
# prefix width
set PREFWID = `perl -e "use POSIX; print ceil(log($PATWBIT)/log(2))"`
printf "${GRNI}\n== Starting Synthesis (${FlowOprCnt}/${FlowOprNum}) @${curRunStartTime}: [Pattern Width:$PATWBIT; CAM Depth:${CURCAMD}k; Pipelined writes?:${CURPATW}; Encoder's combinatorial max depth:${CURECMD}]\n${RST}"
# create configuration file base on architectural
if (-e config.vh) \rm -f config.vh
printf "${BLU}= Generating TCAM configuration file config.vh\n${RST}"
printf '// TCAM Configuration File\n' >! config.vh
printf '// Generated by flow manager for logic synthesis\n' >> config.vh
printf '`define ARCH "%s"\t// TCAM architecture\n' $CURARCH >> config.vh
printf '`define CDEP %s \t// CAM depth (k-lines)\n' $CURCAMD >> config.vh
printf '`define PWID %s \t// pattern width(9bit)\n' $CURPATW >> config.vh
printf '`define PWRT %s \t// pipelined writes?\n' $PIPEWRT >> config.vh
printf '`define REGM %s \t// register MLAB outs?\n' 0 >> config.vh
printf '`define REGI %s \t// register inputs?\n' $REGINPS >> config.vh
printf '`define REGO %s \t// register outputs?\n' $REGOUTS >> config.vh
# clean previous report files before run
if (-d output_files) \rm -rf output_files
# clean previous values before run
set val = (`repeat $FCNT echo "N/A"`)
# Generate priority encoders / mux tree / reduction or tree
if (-e pem_out.v) \rm -f pem_out.v
if (-e lpm_out.v) \rm -f lpm_out.v
if ($CURARCH == "PEM") then
printf "${BLU}= Generating PEM encoder pem_out.v: ./pem out ${CAMDENT} -cmd=${CURECMD}\n${RST}"
./pem out ${CAMDENT} -cmd=${CURECMD}
else
printf "${BLU}= Generating LPM encoder lpm_out.v: ./lpm.2c out ${CAMDENT} ${PREFWID} -cmd=${CURECMD}\n${RST}"
./lpm.2c out ${CAMDENT} ${PREFWID} -cmd=${CURECMD}
endif
# run current synthesis
printf "${BLU}= Running quartus_map...\n${RST}"
quartus_map --64bit --read_settings_files=on --write_settings_files=off iitcam -c iitcam | tee log/${RUNNAME}.map.log
printf "${BLU}= Running quartus_cdb...\n${RST}"
quartus_cdb --64bit --merge iitcam -c iitcam | tee log/${RUNNAME}.cdb.log
printf "${BLU}= Running quartus_fit...\n${RST}"
quartus_fit --64bit --read_settings_files=off --write_settings_files=off iitcam -c iitcam | tee log/${RUNNAME}.fit.log
printf "${BLU}= Running quartus_sta...\n${RST}"
quartus_sta --64bit iitcam -c iitcam | tee log/${RUNNAME}.sta.log
# calculate runtime and generate a report / per run
set curRunFinishTime = `date +%T`
set curRunFinishTimeStamp = `date +%s`
@ curRunTimeDiff = $curRunFinishTimeStamp - $curRunStartTimeStamp
set curRuntimeMin = `echo "scale=2;$curRunTimeDiff/60"|bc`
# collect data
printf "${BLU}= Collecting results...\n${RST}"
set val[1] = $CURARCH
set val[2] = $CURCAMD
set val[3] = $PATWBIT
set val[4] = $PIPEWRT
set val[5] = $REGINPS
set val[6] = $REGOUTS
set val[7] = $CURECMD
if (-f output_files/iitcam.sta.rpt) then
set val[8] = `grep -a4 "Slow 900mV 0C Model Fmax Summary" output_files/iitcam.sta.rpt | tail -1 | cut -d" " -f2 | tr -d " \n"`;
set val[9] = `grep -a4 "Slow 900mV 85C Model Fmax Summary" output_files/iitcam.sta.rpt | tail -1 | cut -d" " -f2 | tr -d " \n"`
endif
if (-f output_files/iitcam.fit.rpt) then
grep -A92 "; Fitter Resource Usage Summary" output_files/iitcam.fit.rpt >! __fit_rpt__.tmp
set val[10] = `grep "ALUT usage for logic" __fit_rpt__.tmp | cut -d";" -f3 | cut -d"/" -f1| tr -d ", "`
set val[11] = `grep "7 input" __fit_rpt__.tmp | cut -d";" -f3 | cut -d"/" -f1| tr -d ", "`
set val[12] = `grep "6 input" __fit_rpt__.tmp | cut -d";" -f3 | cut -d"/" -f1| tr -d ", "`
set val[13] = `grep "5 input" __fit_rpt__.tmp | cut -d";" -f3 | cut -d"/" -f1| tr -d ", "`
set val[14] = `grep "4 input" __fit_rpt__.tmp | cut -d";" -f3 | cut -d"/" -f1| tr -d ", "`
set val[15] = `grep "<=3 input" __fit_rpt__.tmp | cut -d";" -f3 | cut -d"/" -f1| tr -d ", "`
set val[16] = `grep "ALUT usage for route" __fit_rpt__.tmp | cut -d";" -f3 | cut -d"/" -f1| tr -d ", "`
set val[17] = `grep "Dedicated logic registers" __fit_rpt__.tmp | cut -d";" -f3 | cut -d"/" -f1| tr -d ", "`
set val[18] = `grep "ALMs needed \[" __fit_rpt__.tmp | cut -d";" -f3 | cut -d"/" -f1| tr -d ", "`
set val[19] = `grep "Total LABs" __fit_rpt__.tmp | cut -d";" -f3 | cut -d"/" -f1| tr -d ", "`
set val[20] = `grep "Logic LABs" __fit_rpt__.tmp | cut -d";" -f3 | cut -d"/" -f1| tr -d ", "`
set val[21] = `grep "Memory LABs" __fit_rpt__.tmp | cut -d";" -f3 | cut -d"/" -f1| tr -d ", "`
set val[22] = `grep "I/O pins" __fit_rpt__.tmp | cut -d";" -f3 | cut -d"/" -f1| tr -d ", "`
set val[23] = `grep "Clock pins" __fit_rpt__.tmp | cut -d";" -f3 | cut -d"/" -f1| tr -d ", "`
set val[24] = `grep "Dedicated input" __fit_rpt__.tmp | cut -d";" -f3 | cut -d"/" -f1| tr -d ", "`
set val[25] = `grep "M20K" __fit_rpt__.tmp | cut -d";" -f3 | cut -d"/" -f1| tr -d ", "`
set val[26] = `grep "MLAB" __fit_rpt__.tmp | cut -d";" -f3 | cut -d"/" -f1| tr -d ", "`
set val[27] = `grep "block memory bits" __fit_rpt__.tmp | cut -d";" -f3 | cut -d"/" -f1| tr -d ", "`
set val[28] = `grep "block memory implementation" __fit_rpt__.tmp | cut -d";" -f3 | cut -d"/" -f1| tr -d ", "`
set val[29] = `grep "DSP" __fit_rpt__.tmp | cut -d";" -f3 | cut -d"/" -f1| tr -d ", "`
set val[30] = $curRuntimeMin
\rm -rf __fit_rpt__.tmp
endif
foreach i (`seq $FCNT`)
if ( $val[$i] == "" ) set val[$i] = "N/A"
end
# print to report
printf "$FRMT\n" $val >> syn.res
# move log files into log directory
printf "${BLU}= Moving log files and reports...\n${RST}"
if (-d output_files) then
cd output_files
foreach fileName (*.*)
if (-f $fileName) \mv -f $fileName "../log/${RUNNAME}.`echo $fileName | cut -d. -f2-`"
end
cd ../
\rm -rf output_files
endif
if (-f config.vh) \mv -f config.vh log/${RUNNAME}.config.vh
if (-f pem_out.v) \mv -f pem_out.v log/${RUNNAME}.pem_out.v
if (-f lpm_out.v) \mv -f lpm_out.v log/${RUNNAME}.lpm_out.v
# compress and move db/ and incremental_db/
if (-d db) then
tar -cJf db.tar.xz db/
\mv -f db.tar.xz log/${RUNNAME}.db.tar.xz
\rm -rf db/
endif
if (-d incremental_db) then
tar -cJf incremental_db.tar.xz incremental_db/
\mv -f incremental_db.tar.xz log/${RUNNAME}.incremental_db.tar.xz
\rm -rf incremental_db/
endif
printf "${GRNI}== Synthesis (${FlowOprCnt}/${FlowOprNum}) Completed after ${curRuntimeMin} minutes: [Pattern Width:$PATWBIT; CAM Depth:${CURCAMD}k; Pipelined writes?:${CURPATW}; Encoder's combinatorial max depth:${CURECMD}]\n${RST}"
end
end
end
end
goto scriptEnd
# error message
errorMessage:
printf $RED
cat << EOH
USAGE:
./syn <Architecture list> <Pattern width list (X 9-bit)> <Depth list (X 1k)>
[-cd='Output encoder combinatorial max depth list'] [-pw] [-ri] [-ro]
- arguments surrounded by angle brackets '<>' are mandatory, while arguments
surrouned by square brackets are optional.
- lists are comma delimited list with no spaces and can be surrounded by any
type of brackets '()', '[]', '{}', or '<>'.
- Mandatory arguments:
* Architecture list is 'LMP' for longest-prefix-match TCAM, 'PEM' for
priority-encoded TCAM, or 'LMP,PEM' for both.
* Pattern width is a postive integer and represents multiples of 9-bits.
* CAM depth is a positive integer and represents multiples of 1024 lines.
- Optional switches:
* '-cd' Output encoder combinatorial maximum depth; acheived by pipelining,
default is infinite (fully combinatorial)
* '-pw' pipeline write / doubles the number of writing cycles to ~1k cycles.
* '-ri' register all inputs (basically, for static timing analysis).
* '-ro' register all outputs (basically, for static timing analysis).
EXAMPLES:
./syn PEM 14 8 -ri -ro
Synthesis a PEM TCAM with 8 K-lines, 126 bits pattern width, registered
inputs and outputs, unpipelined write and combinatorial output decoders
./syn PEM,LPM 4,7 2,4 -cd=2,4 -pw -ri -ro
Synthesis a PEM and LPM TCAMs with 2 and 4 k-lines, 36 and 63 bit pattern,
2 and 4 encoder max combinatorial depth, pipelined write, and registered IOs
The following files and directories will be created after compilation:
- syn.res : A list of results, each run in a separate line, including:
frequency, resources usage, and runtime
- log/ : Altera's logs and reports
EOH
printf $RST
scriptEnd: