gstlal-inspiral  0.4.2
 All Classes Namespaces Files Functions Variables Pages
gstlal_inspiral_flopulator
1 #!/usr/bin/env python
2 #
3 # Copyright (C) 2014 Chad Hanna, Miguel Fernandez
4 #
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the
7 # Free Software Foundation; either version 2 of the License, or (at your
8 # option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13 # Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 
19 ## @file
20 # A program to compute the LLOID filtering costs of an SVD bank as produced by gstlal_svd_bank
21 
22 
23 import numpy
24 import sys
25 from gstlal import svd_bank
26 
27 #FIXME hack to deal with pre ER5 / post ER5 bank file formats, remove when not an issue
28 try:
29  banks = svd_bank.read_banks(sys.argv[1])
30 except AttributeError:
31  banks = [svd_bank.read_bank(sys.argv[1])]
32 
33 totalMFLOPS=0
34 averageMFLOPS=0
35 totalMT = 0
36 
37 for i, bank in enumerate(banks):
38 
39  print ""
40  rT = [f.rate for f in bank.bank_fragments]
41  r = numpy.array(sorted(list(set(rT))))
42  rT = numpy.array(rT)
43 
44  UT = numpy.array([f.mix_matrix.shape[0] for f in bank.bank_fragments])
45  MT = [f.mix_matrix.shape[1] for f in bank.bank_fragments][0]
46  NT = numpy.array([(f.end - f.start) * f.rate for f in bank.bank_fragments])
47 
48  print "\nSUB BANK %d" % i
49  print "--->\tUnique sampling rates: ",r
50  print "--->\tSampling rate for a given time slice: ",rT
51  print "--->\tTotal SVD filters for a given time slice: ",UT
52  print "--->\tNumber of SVD filter samples: ",NT
53  print "--->\tTotal real templates (e.g. twice number of complex templates): ",MT
54 
55  # Convolution of a 16 sample filter requires a multiply-add per sample point of data for each sample of the filter for each physical template
56  resample = (r * 16 * 2 * MT).sum()
57 
58  # Convolution of a NT sample filter requires a multiply-add per sample point of data for each sample of the filter for each svd template
59  filter = (NT * rT * UT * 2).sum()
60 
61  reconstruct = (MT * UT * rT * 2).sum()
62 
63  add = (rT * MT).sum()
64 
65  # get FLOPs per *complex* template (note the divide by 2)
66  totalMT += MT / 2
67  print "--->\tMFLOPS from resampling: ", resample / 1000.**2
68  print "--->\tMFLOPS from filtering: ", filter / 1000.**2
69  print "--->\tMFLOPS from reconstruction: ", reconstruct / 1000.**2
70  print "--->\tMFLOPS from addition: ", add / 1000.**2
71 
72  MFLOPs = resample / 1000.**2 + filter / 1000.**2 + reconstruct / 1000.**2 + add / 1000.**2
73  totalMFLOPS += MFLOPs
74 
75  print "--->\tTotal MFLOPS: ", MFLOPs
76  print "--->\tMFLOPS per complex template: ", MFLOPs / (MT / 2.)
77 
78 averageMFLOPS = totalMFLOPS / totalMT
79 print "--\nAverage MFLOPS per template:", averageMFLOPS