Debian Codegraph @

easel/devkit/techtree.py

raw symbols SCIP
1 #! /usr/bin/env python3
2
3 # Usage:
4 # techtree.py <depfile>
5 #
6 # Where input <depfile> is created in Easel directory by clang preprocessing:
7 # for cfile in esl_*.c easel.c; do clang -MM -c -I. -DeslENABLE_AVX -DeslENABLE_AVX512 -DeslENABLE_VMX -DeslENABLE_NEON -DeslENABLE_SSE -DHAVE_MPI ${cfile} >> easel.dep; done
8 #
9 # (Some harmless errors will come out on stderr about NEON and VMX instructions not being enabled; ignore them.)
10 #
11 # This input file consists of lists of dependencies, possibly wrapped to multiple lines,
12 # as in:
13 #
14 # esl_cpu.o: esl_cpu.c esl_config.h easel.h esl_cpu.h
15 # esl_dirichlet.o: esl_dirichlet.c esl_config.h easel.h esl_fileparser.h \
16 # esl_minimizer.h esl_random.h esl_stats.h esl_vectorops.h \
17 # esl_dirichlet.h
18 # esl_distance.o: esl_distance.c esl_config.h easel.h esl_alphabet.h \
19 # esl_dmatrix.h esl_random.h esl_distance.h
20 #
21 # For each module, we extract its name ("esl_distance.o" => "distance"). We
22 # ignore the dependency on a module's own .c and .h file, and on esl_config.h.
23 #
24 # Four global data structures describe the proposed layout of the tech tree,
25 # as shown in the tech tree figure:
26 # <easelgrps> specifies an order that the groups organize into:
27 # base, a layer of fundamental stuff, sequence handling,
28 # statistics, misc stuff off the base, and MPI over all.
29 # <easelmods> specifies how modules are assigned to groups;
30 # <easelmods[g]> is an ordered list of modules that belong to group <g>
31 # <easelparents> specifies dependencies at group level:
32 # <easelparents[g]> is a set of groups that group <g> depends on.
33 # <easeladd> specifies additional dependencies within a group:
34 # <easeladd[m]> is a set of modules that <m> depends on within m's own group.
35 #
36 # The script validates this proposed layout, and checks that the actual dependencies
37 # in Easel are consistent with it.
38 #
39 # The output is in two sections: the actual dependencies of each Easel module
40 # (so you can consider improved layouts), followed by a list of any actual
41 # dependencies that aren't satisfied by the current layout.
42 #
43
44 import sys
45 import re
46
47
48 easelgrps = [
49 'BASE',
50 'BIOLOGICAL_SEQUENCES', 'NUMERICAL_METHODS', 'ALGORITHMS', 'FILE_INPUT',
51 'ADVANCED_SEQUENCES', 'MULTIPLE_ALIGNMENTS', 'MULTIPLE_ALIGNMENT_FILES', 'SEQUENCE_FILES',
52 'STATISTICAL_DISTRIBUTIONS', 'MIXTURE_DISTRIBUTIONS',
53 'COMMANDLINE', 'BENCHMARKS', 'SIMD_VECTORS', 'MULTITHREADING',
54 'MPI'
55 ]
56
57 easelmods = {
58 'BASE' : [ 'easel', 'mem', 'random', 'regexp', 'stack', 'vectorops' ],
59 'ALGORITHMS' : [ 'arr2', 'arr3', 'bitfield', 'cluster', 'dmatrix', 'heap', 'keyhash', 'matrixops', 'quicksort', 'red_black', 'varint', 'huffman', 'graph', 'tree' ],
60 'NUMERICAL_METHODS' : [ 'rootfinder', 'minimizer', 'rand64' ],
61 'BIOLOGICAL_SEQUENCES' : [ 'alphabet', 'composition', 'hmm' ],
62 'FILE_INPUT' : [ 'buffer', 'fileparser', 'recorder', 'ssi', 'json' ],
63 'COMMANDLINE' : [ 'getopts', 'subcmd' ],
64 'BENCHMARKS' : [ 'stopwatch' ],
65 'STATISTICAL_DISTRIBUTIONS' : [ 'stats', 'normal', 'histogram', 'exponential', 'gamma', 'gev', 'gumbel', 'stretchexp', 'weibull' ],
66 'MIXTURE_DISTRIBUTIONS': [ 'dirichlet', 'mixgev', 'hyperexp', 'mixdchlet' ],
67 'ADVANCED_SEQUENCES' : [ 'distance', 'wuss', 'paml', 'randomseq', 'ratematrix', 'scorematrix', 'swat' ],
68 'MULTIPLE_ALIGNMENTS' : [ 'msa', 'msacluster', 'msashuffle', 'msaweight' ],
69 'MULTIPLE_ALIGNMENT_FILES' : [ 'msafile', 'msafile2', 'msafile_a2m', 'msafile_afa', 'msafile_clustal', 'msafile_phylip', 'msafile_psiblast', 'msafile_selex', 'msafile_stockholm' ],
70 'SEQUENCE_FILES' : [ 'sq', 'sqio_ascii', 'sqio_ncbi', 'sqio', 'dsqdata', 'gencode' ],
71 'SIMD_VECTORS' : [ 'alloc', 'cpu', 'sse', 'avx', 'avx512', 'neon', 'vmx' ],
72 'MULTITHREADING' : [ 'threads', 'workqueue' ],
73 'MPI' : [ 'mpi' ],
74 }
75
76 easelparents = {
77 'BASE' : {},
78 'BIOLOGICAL_SEQUENCES' : { 'BASE' },
79 'NUMERICAL_METHODS' : { 'BASE' },
80 'ALGORITHMS': { 'BASE' },
81 'FILE_INPUT': { 'BASE' },
82 'COMMANDLINE': { 'BASE' },
83 'BENCHMARKS': { 'BASE' },
84 'SIMD_VECTORS': { 'BASE' },
85 'MULTITHREADING': { 'BASE' },
86 'ADVANCED_SEQUENCES': { 'BIOLOGICAL_SEQUENCES', 'NUMERICAL_METHODS', 'ALGORITHMS', 'FILE_INPUT' },
87 'STATISTICAL_DISTRIBUTIONS' : { 'NUMERICAL_METHODS' },
88 'MIXTURE_DISTRIBUTIONS' : { 'STATISTICAL_DISTRIBUTIONS', 'ALGORITHMS', 'FILE_INPUT' },
89 'MULTIPLE_ALIGNMENTS' : { 'ADVANCED_SEQUENCES' },
90 'MULTIPLE_ALIGNMENT_FILES' : { 'MULTIPLE_ALIGNMENTS' },
91 'SEQUENCE_FILES' : { 'MULTIPLE_ALIGNMENT_FILES' },
92 'MPI': { 'BENCHMARKS', 'SEQUENCE_FILES' }
93 }
94
95 easeladd = {
96 # BASE
97 'easel' : set(),
98 'mem' : { 'easel' },
99 'random' : { 'easel' },
100 'regexp' : { 'easel' },
101 'stack' : { 'easel', 'random' },
102 'vectorops' : { 'easel', 'random' },
103 # ALGORITHMS
104 'arr2' : set(),
105 'arr3' : set(),
106 'bitfield' : set(),
107 'cluster' : set(),
108 'dmatrix' : set(),
109 'heap' : set(),
110 'keyhash' : set(),
111 'matrixops' : set(),
112 'quicksort' : set(),
113 'red_black' : set(),
114 'varint' : set(),
115 'huffman' : { 'quicksort' },
116 'graph' : { 'matrixops' },
117 'tree' : { 'arr2', 'dmatrix', 'stack'},
118 # NUMERICAL_METHODS
119 'rootfinder' : set(),
120 'minimizer' : set(),
121 'rand64' : set(),
122 # BIOLOGICAL_SEQUENCES
123 'alphabet' : set(),
124 'composition' : set(),
125 'hmm' : { 'alphabet' },
126 # FILE_INPUT
127 'buffer' : set(),
128 'fileparser' : set(),
129 'recorder' : set(),
130 'ssi' : set(),
131 'json' : { 'buffer' },
132 # COMMANDLINE
133 'getopts' : set(),
134 'subcmd' : { 'getopts' },
135 # BENCHMARKS
136 'stopwatch' : set(),
137 # STATISTICAL_DISTRIBUTIONS
138 'stats' : set(),
139 'normal' : { 'stats' },
140 'histogram' : { 'stats' },
141 'exponential' : { 'stats', 'histogram' },
142 'gamma' : { 'stats', 'histogram' },
143 'gev' : { 'stats' },
144 'gumbel' : { 'stats' },
145 'stretchexp' : { 'stats', 'histogram' },
146 'weibull' : { 'stats', 'histogram' },
147 # MIXTURE_DISTRIBUTIONS
148 'dirichlet' : set(),
149 'hyperexp' : set(),
150 'mixdchlet' : { 'dirichlet' },
151 'mixgev' : { 'dirichlet' },
152 # ADVANCED_SEQUENCES
153 'distance' : set(),
154 'wuss' : set(),
155 'paml' : set(),
156 'randomseq' : set(),
157 'ratematrix' : set(),
158 'scorematrix' : { 'ratematrix' },
159 'swat' : { 'scorematrix' },
160 # MULTIPLE_ALIGNMENTS
161 'msa' : set(),
162 'msacluster' : { 'msa' },
163 'msashuffle' : { 'msa' },
164 'msaweight' : { 'msa', 'msacluster' },
165 # MULTIPLE_ALIGNMENT_FILES
166 'msafile' : set(),
167 'msafile2' : set(),
168 'msafile_a2m' : { 'msafile' },
169 'msafile_afa' : { 'msafile' },
170 'msafile_clustal' : { 'msafile' },
171 'msafile_phylip' : { 'msafile' },
172 'msafile_psiblast' : { 'msafile' },
173 'msafile_selex' : { 'msafile' },
174 'msafile_stockholm' : { 'msafile' },
175 # SEQUENCE_FILES
176 'sq' : set(),
177 'sqio' : { 'sq' },
178 'sqio_ascii' : { 'sq', 'sqio' },
179 'sqio_ncbi' : { 'sq', 'sqio' },
180 'dsqdata' : { 'sq', 'sqio', 'sqio_ascii' },
181 'gencode' : { 'sq', 'sqio', 'sqio_ascii', 'sqio_ncbi' },
182 # SIMD_VECTORS
183 'alloc' : set(),
184 'cpu' : set(),
185 'sse' : set(),
186 'avx' : set(),
187 'avx512' : set(),
188 'neon' : set(),
189 'vmx' : set(),
190 # MULTITHREADING
191 'threads' : set(),
192 'workqueue' : set(),
193 # MPI
194 'mpi' : set(),
195 }
196
197
198
199 def main():
200 if (len(sys.argv) != 2):
201 sys.exit("Usage: techtree.py <.dep file>");
202
203 validate_layout()
204 Ma = expand_layout() # Ma[m] is a set of allowable dependencies for module <m>, according to layout
205
206 # Get the actual dependencies from the input file.
207 # <D[m]> is a set of module dependencies for module <m>
208 # excluding esl_config.h and itself, as parsed out of input
209 # depfile.
210 #
211 D = {}
212 for line in open(sys.argv[1]):
213 mat = re.match(r'(\S+): (.+)', line) # First line in a list of dependencies?
214 if mat:
215 m = process_token(mat.group(1))
216 fields = mat.group(2).split()
217 D[m] = set();
218 else:
219 fields = line.split()
220
221 for s in fields:
222 if s != "\\" and s != 'esl_config.h': # ignore \ and esl_config.h...
223 s = process_token(s) # ... extract module name from filename
224 if s != m: # ... and ignore dependencies on itself
225 D[m].add(s) # ... otherwise, add dependencies to the set.
226
227 output_direct_deplines(D) # First section: actual dependencies, organized for study.
228 compare_layout(Ma, D) # Followed by any problems in them.
229
230
231 def process_token(tok):
232 """
233 """
234 tok = re.sub(r'^esl_', '', tok)
235 tok = re.sub(r'.[coh]$', '', tok)
236 return tok
237 ####
238
239
240 # validate_layout()
241 #
242 # Checks the four global data structures that define the figure
243 # layout.
244 #
245 def validate_layout():
246 Gl = set(easelgrps) # <easelgrps> list is all the group names
247 Gm = set(easelmods.keys()) # <easelmods> keys are also all the group names
248 Gp = set(easelparents.keys()) # <easelparents> keys are also all the group names
249 if Gl != Gm: sys.exit("easelgrps and easelmods have different set of group names")
250 if Gl != Gp: sys.exit("easelgrps and easelparents have different set of group names")
251
252 Mm = [] # Get all the module names in <easelmods>'s sets.
253 for g in easelmods.keys():
254 for m in easelmods[g]:
255 Mm.append(m)
256 if len(Mm) != len(set(Mm)):
257 sys.exit("easelmods must have same module assigned to >1 group")
258 Mm = set(Mm)
259 Ma = set(easeladd.keys())
260 if Mm != Ma:
261 sys.exit("easelmods and easeladd have a different set of module names")
262
263 print("# {0} groups".format(len(Gm)))
264 print("# {0} modules".format(len(Mm)))
265 ####
266
267
268 # expand_layout()
269 #
270 # Use the immediate group dependencies in <easelparents> to traverse
271 # upwards through the graph for each group <g>, to get the complete
272 # set of dependencies for it. Use that to obtain its complete set of
273 # module dependencies.
274 #
275 # Return a <Ma>, a dict of sets: Ma[m] is a set of modules that module
276 # <m> depends on.
277 #
278 def expand_layout():
279 # Use a pushdown automaton to recursively find all group dependencies
280 # for each group <g>; store this set in Ga[g].
281 Ga = {}
282 for g in easelparents.keys():
283 Ga[g] = set()
284 pda = list(easelparents[g])
285 while len(pda):
286 g2 = pda.pop()
287 Ga[g].add(g2)
288 pda.extend(list(easelparents[g2]))
289
290 # Using Ga, plus additional within-group module dependencies in <adds>,
291 # expand set of group dependencies to set of module dependencies for each module <m>.
292 Ma = {}
293 for g in easelmods.keys():
294 mdep = set()
295 for g2 in Ga[g]: # for each group that <g> depends on...
296 mdep = mdep | set(easelmods[g2]) # add the modules in that group
297 for m in easelmods[g]:
298 Ma[m] = mdep | easeladd[m]
299 return Ma
300 ####
301
302
303 def compare_layout(Ma, D):
304 for m in Ma.keys():
305 if not Ma[m] >= D[m]:
306 print(m, D[m] - Ma[m])
307
308 def output_direct_deplines(D):
309 for g in easelgrps:
310 print('# {0}'.format(g))
311 for m in easelmods[g]:
312 print('{0:20s}: '.format(m), end='')
313
314 for g2 in easelgrps:
315 for m2 in easelmods[g2]:
316 if m2 in D[m]:
317 print('{0} '.format(m2), end='')
318 print('')
319 print('')
320
321 if __name__ == "__main__":
322 main()
323
324
325