1- ########################################
1+ """
22# Utilities for writing Verilog code from Vivado HLS blocks
3- ########################################
3+ """
4+
45#from collections import deque
56from TrackletGraph import MemModule , ProcModule
67from WriteVHDLSyntax import writeStartSwitchAndInternalBX , writeProcControlSignalPorts , writeProcBXPort , writeProcMemoryLHSPorts , writeProcMemoryRHSPorts , writeProcCombination
78import re
89
9- ########################################
10- # Memory objects
11- ########################################
1210def getMemoryClassName_InputStub (instance_name ):
11+ """
12+ # Memory objects
1313 # Two examples of instance name: IL_L1PHIB_neg_PS10G_1_A, IL_L1PHIH_PS10G_2_B
14+ """
1415 position = instance_name .split ('_' )[1 ][:2 ] # layer/disk
1516 ptmodule = instance_name .replace ('_neg' ,'' ).split ('_' )[2 ][:2 ] # PS or 2S
1617
@@ -27,7 +28,9 @@ def getMemoryClassName_InputStub(instance_name):
2728 return 'InputStubMemory<' + bitformat + '>'
2829
2930def getMemoryClassName_VMStubsTE (instance_name ):
31+ """
3032 # An example of instance name: VMSTE_L6PHIB15n3
33+ """
3134 position = instance_name .split ('_' )[1 ][:2 ] # layer/disk
3235 philabel = instance_name .split ('_' )[1 ][5 ] # PHI
3336
@@ -97,7 +100,9 @@ def getMemoryClassName_VMStubsTE(instance_name):
97100 return memoryclass + '<' + bitformat + '>'
98101
99102def getMemoryClassName_VMStubsME (instance_name ):
103+ """
100104 # An example of instance name: VMSME_D3PHIB8n1
105+ """
101106 position = instance_name .split ('_' )[1 ][:2 ] # layer/disk
102107 bitformat = ''
103108
@@ -112,10 +117,10 @@ def getMemoryClassName_VMStubsME(instance_name):
112117 return 'VMStubMEMemory<' + bitformat + '>'
113118
114119def getMemoryClassName_AllStubs (instance_name ):
115- ######################
120+ """
116121 # FIXME: separate Disk PS and 2S AllStub memories for MatchCalculator
117122 # when config files are updated
118- ######################
123+ """
119124
120125 # An example of instance name: AS_D1PHIAn5
121126 position = instance_name .split ('_' )[1 ][:2 ]
@@ -129,17 +134,23 @@ def getMemoryClassName_AllStubs(instance_name):
129134 raise ValueError ("Unknown Layer/Disk " + position )
130135
131136def getMemoryClassName_StubPairs (instance_name ):
137+ """
132138 # e.g. SP_L1PHIA2_L2PHIA3
139+ """
133140 assert ('SP_' in instance_name )
134141 return 'StubPairMemory'
135142
136143def getMemoryClassName_TrackletParameters (instance_name ):
144+ """
137145 # e.g. TPAR_L1L2L
146+ """
138147 assert ('TPAR_' in instance_name )
139148 return 'TrackletParameterMemory'
140149
141150def getMemoryClassName_TrackletProjections (instance_name ):
151+ """
142152 # e.g. TPROJ_L5L6A_L1PHIB
153+ """
143154 position = instance_name .split ('_' )[2 ][:2 ] # layer/disk
144155 bitformat = ''
145156
@@ -154,7 +165,9 @@ def getMemoryClassName_TrackletProjections(instance_name):
154165 return 'TrackletProjectionMemory<' + bitformat + '>'
155166
156167def getMemoryClassName_AllProj (instance_name ):
168+ """
157169 # e.g. AP_L4PHIB
170+ """
158171 position = instance_name .split ('_' )[1 ][:2 ] # layer/disk
159172 bitformat = ''
160173
@@ -169,7 +182,9 @@ def getMemoryClassName_AllProj(instance_name):
169182 return 'AllProjectionMemory<' + bitformat + '>'
170183
171184def getMemoryClassName_VMProjections (instance_name ):
185+ """
172186 # e.g. VMPROJ_D3PHIA2
187+ """
173188 position = instance_name .split ('_' )[1 ][:2 ] # layer/disk
174189 if position in ['L1' ,'L2' ,'L3' ,'L4' ,'L5' ,'L6' ]:
175190 return 'VMProjectionMemory<BARREL>'
@@ -178,12 +193,16 @@ def getMemoryClassName_VMProjections(instance_name):
178193 return 'VMProjectionMemory<DISK>'
179194
180195def getMemoryClassName_CandidateMatch (instance_name ):
196+ """
181197 # e.g. CM_L2PHIA8
198+ """
182199 assert ('CM_' in instance_name )
183200 return 'CandidateMatchMemory'
184201
185202def getMemoryClassName_FullMatch (instance_name ):
203+ """
186204 # e.g. FM_L5L6_L3PHIB
205+ """
187206 position = instance_name .split ('_' )[2 ][:2 ]
188207 if position in ['L1' ,'L2' ,'L3' ,'L4' ,'L5' ,'L6' ]:
189208 return 'FullMatchMemory<BARREL>'
@@ -192,12 +211,16 @@ def getMemoryClassName_FullMatch(instance_name):
192211 return 'FullMatchMemory<DISK>'
193212
194213def getMemoryClassName_TrackFit (instance_name ):
214+ """
195215 # e.g. TF_L3L4
216+ """
196217 assert ('TF_' in instance_name )
197218 return 'TrackFitMemory'
198219
199220def getMemoryClassName_CleanTrack (instance_name ):
221+ """
200222 # e.g. CT_L5L6
223+ """
201224 assert ('CT_' in instance_name )
202225 return 'CleanTrackMemory'
203226
@@ -233,11 +256,13 @@ def getHLSMemoryClassName(module):
233256 raise ValueError (module .mtype + " is unknown." )
234257
235258def labelConnectedMemoryArrays (proc_list ):
259+ """
236260 # label those memories that will be constructed in an array
237261 # (if these scripts end up generating the HLS top levels, will this function
238262 # be needed? That is, even if the templated HLS function has arrays on the
239263 # interface, the top-level could still be individual memories, although you'd
240264 # still have to pass those individual memories to the templated block as an array
265+ """
241266 for aProcModule in proc_list :
242267
243268 if aProcModule .mtype == 'TrackletCalculator' :
@@ -255,11 +280,13 @@ def labelConnectedMemoryArrays(proc_list):
255280 #elif aProcModule.mtype == '':
256281
257282def getListsOfGroupedMemories (aProcModule ):
283+ """
258284 # Get a list of memories and a list of ports for a given processing module
259285 # The memories are further grouped in a list if they are expected to be
260286 # constructed and passed to the processing function as an array
261287
262288 # add array name to 'userlabel' of the connected memory module
289+ """
263290 labelConnectedMemoryArrays ([aProcModule ])
264291
265292 memList = list (aProcModule .upstreams + aProcModule .downstreams )
@@ -288,10 +315,12 @@ def getListsOfGroupedMemories(aProcModule):
288315 return newmemList , newportList
289316
290317def groupAllConnectedMemories (proc_list , mem_list ):
318+ """
291319 # Regroup memories into the lists called inside, topin, topout
292320 # topin: memories at the top of the fw block, stimulated by test bench
293321 # inside: memories internal to the fw block
294322 # topout: memories at the bottom of the fw blcok, read by test bench
323+ """
295324
296325 memories_topin = [] # input memories at the top function interface
297326 memories_inside = [] # memories instantiated inside the top function
@@ -336,6 +365,8 @@ def groupAllConnectedMemories(proc_list, mem_list):
336365# matchArgPortNames: Match the HLS argument names to the python-generated port names from
337366# the wires file. Once these scripts also generate the top-level HLS
338367# blocks, these functions might not be needed
368+ ########################################
369+
339370################################
340371# VMRouter
341372################################
@@ -470,9 +501,11 @@ def matchArgPortNames_TC(argname, portname):
470501################################
471502# ProjectionRouter
472503################################
473- ####
474- # Write ProjectionRouter template parameters
504+
475505def writeTemplatePars_PR (aPRModule ):
506+ """
507+ # Write ProjectionRouter template parameters
508+ """
476509 instance_name = aPRModule .inst
477510 # e.g. PR_L3PHIC
478511 pos = instance_name .split ('_' )[1 ][0 :2 ]
@@ -497,10 +530,10 @@ def writeTemplatePars_PR(aPRModule):
497530 templpars_str = PROJTYPE + ',' + VMPTYPE + ',' + str (nInMemory )+ ',' + LAYER + ',' + DISK
498531 return templpars_str
499532
500- ####
501- # Define rules to match the argument and the port names for ProjectionRouter
502533def matchArgPortNames_PR (argname , portname ):
503-
534+ """
535+ # Define rules to match the argument and the port names for ProjectionRouter
536+ """
504537 if 'projin' in argname :
505538 # projXXin for input TrackletProjection memories
506539 return 'proj' in portname and 'in' in portname
@@ -516,9 +549,11 @@ def matchArgPortNames_PR(argname, portname):
516549################################
517550# MatchEngine
518551################################
519- ####
520- # Write MatchEngine template parameters
552+
521553def writeTemplatePars_ME (aMEModule ):
554+ """
555+ # Write MatchEngine template parameters
556+ """
522557 instance_name = aMEModule .inst
523558 # e.g. ME_L4PHIC20
524559 pos = instance_name .split ('_' )[1 ][0 :2 ]
@@ -538,10 +573,10 @@ def writeTemplatePars_ME(aMEModule):
538573 templpars_str = LAYER + ',' + VMSTYPE
539574 return templpars_str
540575
541- ####
542- # Define rules to match the argument and the port names for MatchEngine
543576def matchArgPortNames_ME (argname , portname ):
544-
577+ """
578+ # Define rules to match the argument and the port names for MatchEngine
579+ """
545580 if argname == 'inputStubData' :
546581 return portname == 'vmstubin'
547582 elif argname == 'inputProjectionData' :
@@ -555,6 +590,7 @@ def matchArgPortNames_ME(argname, portname):
555590################################
556591# MatchCalculator
557592################################
593+
558594def writeTemplatePars_MC (aMCModule ):
559595 instance_name = aMCModule .inst
560596 # e.g. MC_L2PHID
@@ -624,6 +660,7 @@ def decodeSeedIndex_MC(memoryname):
624660################################
625661# FitTrack
626662################################
663+
627664def writeTemplatePars_FT (aFTModule ):
628665 raise ValueError ("FitTrack is not implemented yet!" )
629666 return ""
@@ -635,6 +672,7 @@ def matchArgPortNames_FT(argname, portname):
635672################################
636673# PurgeDuplicate
637674################################
675+
638676def writeTemplatePars_PD (aPDModule ):
639677 raise ValueError ("DuplicateRemoval is not implemented yet!" )
640678 return ""
@@ -643,12 +681,13 @@ def matchArgPortNames_PD(argname, portname):
643681 raise ValueError ("DuplicateRemoval is not implemented yet!" )
644682 return False
645683
646- ################################
647684def parseProcFunction (proc_name , fname_def ):
685+ """
648686 # Parse the definition of the processing function in the HLS header file
649687 # Assume all processing functions are templatized
650688 # Return a list of function argument types, argument names,
651689 # and template parameters
690+ """
652691
653692 # Open the header file
654693 file_proc_hh = open (fname_def )
@@ -744,7 +783,6 @@ def parseProcFunction(proc_name, fname_def):
744783
745784 return arg_types_list , arg_names_list , templ_pars_list
746785
747- ################################
748786def writeModuleInst_generic (module , hls_src_dir , f_writeTemplatePars ,
749787 f_matchArgPortNames , first_of_type ):
750788 ####
0 commit comments