3 # Copyright 2008 Free Software Foundation, Inc.
5 # This file is part of GNU Radio
7 # GNU Radio is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3, or (at your option)
12 # GNU Radio is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along
18 # with this program; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 from gnuradio import gr, gru, eng_notation, blks2
23 from gnuradio.eng_option import eng_option
24 from optparse import OptionParser
28 class pipeline(gr.hier_block2):
29 def __init__(self, nstages, ntaps=256):
31 Create a pipeline of nstages of gr.fir_filter_fff's connected in serial
32 terminating in a gr.null_sink.
34 gr.hier_block2.__init__(self, "pipeline",
35 gr.io_signature(1, 1, gr.sizeof_float),
36 gr.io_signature(0, 0, 0))
37 taps = ntaps*[1.0/ntaps]
39 for i in range(nstages):
40 op = gr.fir_filter_fff(1, taps)
41 self.connect(upstream, op)
44 self.connect(upstream, gr.null_sink(gr.sizeof_float))
47 class top(gr.top_block):
49 gr.top_block.__init__(self)
51 default_nsamples = 10e6
52 parser=OptionParser(option_class=eng_option)
53 parser.add_option("-p", "--npipelines", type="intx", default=1,
54 metavar="NPIPES", help="the number of pipelines to create (default=%default)")
55 parser.add_option("-s", "--nstages", type="intx", default=1,
56 metavar="NSTAGES", help="the number of stages in each pipeline (default=%default)")
57 parser.add_option("-N", "--nsamples", type="eng_float", default=default_nsamples,
58 help=("the number of samples to run through the graph (default=%s)" %
59 (eng_notation.num_to_str(default_nsamples))))
60 parser.add_option("-m", "--machine-readable", action="store_true", default=False,
61 help="enable machine readable output")
63 (options, args) = parser.parse_args()
68 self.npipes = options.npipelines
69 self.nstages = options.nstages
70 self.nsamples = options.nsamples
71 self.machine_readable = options.machine_readable
75 # Something vaguely like floating point ops
76 self.flop = 2 * ntaps * options.npipelines * options.nstages * options.nsamples
78 src = gr.null_source(gr.sizeof_float)
79 head = gr.head(gr.sizeof_float, int(options.nsamples))
80 self.connect(src, head)
82 for n in range(options.npipelines):
83 self.connect(head, pipeline(options.nstages, ntaps))
90 delta = map((lambda a, b: a-b), stop, start)
91 user, sys, childrens_user, childrens_sys, real = delta
92 total_user = user + childrens_user
93 total_sys = sys + childrens_sys
94 if tb.machine_readable:
95 print "%3d %3d %.3e %7.3f %7.3f %7.3f %7.3f %.6e %.3e" % (
96 tb.npipes, tb.nstages, tb.nsamples, real, total_user, total_sys, (total_user+total_sys)/real, tb.flop, tb.flop/real)
98 print "npipes %7d" % (tb.npipes,)
99 print "nstages %7d" % (tb.nstages,)
100 print "nsamples %s" % (eng_notation.num_to_str(tb.nsamples),)
101 print "real %7.3f" % (real,)
102 print "user %7.3f" % (total_user,)
103 print "sys %7.3f" % (total_sys,)
104 print "(user+sys)/real %7.3f" % ((total_user + total_sys)/real,)
105 print "pseudo_flop %s" % (eng_notation.num_to_str(tb.flop),)
106 print "pseudo_flop/real %s" % (eng_notation.num_to_str(tb.flop/real),)
109 if __name__ == "__main__":
113 except KeyboardInterrupt:
114 raise SystemExit, 128