From 786058aacbe0ca662e14ea5f00f1c0872a599577 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 7 Feb 2012 18:32:09 -0500 Subject: volk: adding an examples directory with scripts to benchmark and compare volk-optimized GR blocks. --- .../python/volk_benchmark/volk_plot.py | 81 ++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100755 gnuradio-examples/python/volk_benchmark/volk_plot.py (limited to 'gnuradio-examples/python/volk_benchmark/volk_plot.py') diff --git a/gnuradio-examples/python/volk_benchmark/volk_plot.py b/gnuradio-examples/python/volk_benchmark/volk_plot.py new file mode 100755 index 000000000..665df5e14 --- /dev/null +++ b/gnuradio-examples/python/volk_benchmark/volk_plot.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python + +import sys +import argparse +from volk_test_funcs import * + +try: + import matplotlib + import matplotlib.pyplot as plt +except ImportError: + sys.stderr.write("Could not import Matplotlib (http://matplotlib.sourceforge.net/)\n") + sys.exit(1) + +def main(): + desc='Plot Volk performance results from a SQLite database. ' + \ + 'Run one of the volk tests first (e.g, volk_math.py)' + parser = argparse.ArgumentParser(description=desc) + parser.add_argument('-D', '--database', type=str, + default="volk_results.db", + help='Database file to read data from [default: %(default)s]') + args = parser.parse_args() + + # Set up global plotting properties + matplotlib.rcParams['figure.subplot.bottom'] = 0.2 + matplotlib.rcParams['figure.subplot.top'] = 0.95 + matplotlib.rcParams['ytick.labelsize'] = 16 + matplotlib.rcParams['xtick.labelsize'] = 16 + matplotlib.rcParams['legend.fontsize'] = 18 + + # Get list of tables to compare + conn = create_connection(args.database) + tables = list_tables(conn) + M = len(tables) + + # width of bars depends on number of comparisons + wdth = 0.80/M + + colors = ['b', 'r', 'g', 'm', 'k'] + + # Set up figure for plotting + f0 = plt.figure(0, facecolor='w', figsize=(14,10)) + s0 = f0.add_subplot(1,1,1) + + for i,table in enumerate(tables): + # Get results from the next table + res = get_results(conn, table[0]) + + xlabels = [] + averages = [] + variances = [] + maxes = [] + mins = [] + for r in res: + xlabels.append(r['kernel']) + averages.append(r['avg']) + variances.append(r['var']) + maxes.append(r['max']) + mins.append(r['min']) + + # makes x values for this data set placement + x0 = xrange(len(res)) + x1 = [x + i*wdth for x in x0] + + s0.bar(x1, averages, width=wdth, + #yerr=variances, + color=colors[i%M], label=table[0], + edgecolor='k', linewidth=2) + + s0.legend() + s0.set_ylabel("Processing time (sec) [{0:G} items]".format(res[0]['nitems']), + fontsize=22, fontweight='bold') + s0.set_xticks(x0) + s0.set_xticklabels(xlabels) + for label in s0.xaxis.get_ticklabels(): + label.set_rotation(45) + label.set_fontsize(16) + + plt.show() + +if __name__ == "__main__": + main() -- cgit From a9a2c632040d37562a64eb81ed7d4f136a7a774e Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Thu, 9 Feb 2012 20:49:44 -0500 Subject: volk: improved GR benchmark and plotting utilities. --- .../python/volk_benchmark/volk_plot.py | 84 +++++++++++++++++----- 1 file changed, 65 insertions(+), 19 deletions(-) (limited to 'gnuradio-examples/python/volk_benchmark/volk_plot.py') diff --git a/gnuradio-examples/python/volk_benchmark/volk_plot.py b/gnuradio-examples/python/volk_benchmark/volk_plot.py index 665df5e14..d7578c5a7 100755 --- a/gnuradio-examples/python/volk_benchmark/volk_plot.py +++ b/gnuradio-examples/python/volk_benchmark/volk_plot.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -import sys +import sys, math import argparse from volk_test_funcs import * @@ -16,8 +16,15 @@ def main(): 'Run one of the volk tests first (e.g, volk_math.py)' parser = argparse.ArgumentParser(description=desc) parser.add_argument('-D', '--database', type=str, - default="volk_results.db", + default='volk_results.db', help='Database file to read data from [default: %(default)s]') + parser.add_argument('-E', '--errorbars', + action='store_true', default=False, + help='Show error bars (1 standard dev.)') + parser.add_argument('-P', '--plot', type=str, + choices=['mean', 'min', 'max'], + default='mean', + help='Set the type of plot to produce [default: %(default)s]') args = parser.parse_args() # Set up global plotting properties @@ -35,42 +42,81 @@ def main(): # width of bars depends on number of comparisons wdth = 0.80/M + # Colors to distinguish each table in the bar graph + # More than 5 tables will wrap around to the start. colors = ['b', 'r', 'g', 'm', 'k'] # Set up figure for plotting f0 = plt.figure(0, facecolor='w', figsize=(14,10)) s0 = f0.add_subplot(1,1,1) + # Create a register of names that exist in all tables + tmp_regs = [] + for table in tables: + # Get results from the next table + res = get_results(conn, table[0]) + + tmp_regs.append(list()) + for r in res: + try: + tmp_regs[-1].index(r['kernel']) + except ValueError: + tmp_regs[-1].append(r['kernel']) + + # Get only those names that are common in all tables + name_reg = tmp_regs[0] + for t in tmp_regs[1:]: + name_reg = list(set(name_reg) & set(t)) + name_reg.sort() + + # Pull the data out for each table into a dictionary + # we can ref the table by it's name and the data associated + # with a given kernel in name_reg by it's name. + # This ensures there is no sorting issue with the data in the + # dictionary, so the kernels are plotted against each other. + table_data = dict() for i,table in enumerate(tables): # Get results from the next table res = get_results(conn, table[0]) - - xlabels = [] - averages = [] - variances = [] - maxes = [] - mins = [] + + data = dict() for r in res: - xlabels.append(r['kernel']) - averages.append(r['avg']) - variances.append(r['var']) - maxes.append(r['max']) - mins.append(r['min']) + data[r['kernel']] = r + + table_data[table[0]] = data + # Plot the results + x0 = xrange(len(name_reg)) + for i,t in enumerate(table_data): # makes x values for this data set placement - x0 = xrange(len(res)) x1 = [x + i*wdth for x in x0] - s0.bar(x1, averages, width=wdth, - #yerr=variances, - color=colors[i%M], label=table[0], - edgecolor='k', linewidth=2) + ydata = [] + stds = [] + for name in name_reg: + stds.append(math.sqrt(table_data[t][name]['var'])) + if(args.plot == 'max'): + ydata.append(table_data[t][name]['max']) + elif(args.plot == 'min'): + ydata.append(table_data[t][name]['min']) + if(args.plot == 'mean'): + ydata.append(table_data[t][name]['avg']) + + if(args.errorbars is False): + stds = None + + s0.bar(x1, ydata, width=wdth, + yerr=stds, + color=colors[i%M], label=t, + edgecolor='k', linewidth=2, + error_kw={"ecolor": 'k', "capsize":5, + "linewidth":2}) s0.legend() s0.set_ylabel("Processing time (sec) [{0:G} items]".format(res[0]['nitems']), fontsize=22, fontweight='bold') s0.set_xticks(x0) - s0.set_xticklabels(xlabels) + s0.set_xticklabels(name_reg) for label in s0.xaxis.get_ticklabels(): label.set_rotation(45) label.set_fontsize(16) -- cgit From ca8889bc5d83bf380832431ebb30c88ddef5a924 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 13 Feb 2012 14:47:42 -0500 Subject: volk: better handling of plot for error bars. Older versions of pylab don't like the kwargs. --- gnuradio-examples/python/volk_benchmark/volk_plot.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'gnuradio-examples/python/volk_benchmark/volk_plot.py') diff --git a/gnuradio-examples/python/volk_benchmark/volk_plot.py b/gnuradio-examples/python/volk_benchmark/volk_plot.py index d7578c5a7..562d4f2f7 100755 --- a/gnuradio-examples/python/volk_benchmark/volk_plot.py +++ b/gnuradio-examples/python/volk_benchmark/volk_plot.py @@ -103,14 +103,16 @@ def main(): ydata.append(table_data[t][name]['avg']) if(args.errorbars is False): - stds = None - - s0.bar(x1, ydata, width=wdth, - yerr=stds, - color=colors[i%M], label=t, - edgecolor='k', linewidth=2, - error_kw={"ecolor": 'k', "capsize":5, - "linewidth":2}) + s0.bar(x1, ydata, width=wdth, + color=colors[i%M], label=t, + edgecolor='k', linewidth=2) + else: + s0.bar(x1, ydata, width=wdth, + yerr=stds, + color=colors[i%M], label=t, + edgecolor='k', linewidth=2, + error_kw={"ecolor": 'k', "capsize":5, + "linewidth":2}) s0.legend() s0.set_ylabel("Processing time (sec) [{0:G} items]".format(res[0]['nitems']), -- cgit From e36d6f1f766e702d147ca494e21131cc66f157dd Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 13 Feb 2012 16:10:14 -0500 Subject: volk: can specify a table to calculate the percent improvement against instead of just the raw numbers. --- .../python/volk_benchmark/volk_plot.py | 80 ++++++++++++++++------ 1 file changed, 60 insertions(+), 20 deletions(-) (limited to 'gnuradio-examples/python/volk_benchmark/volk_plot.py') diff --git a/gnuradio-examples/python/volk_benchmark/volk_plot.py b/gnuradio-examples/python/volk_benchmark/volk_plot.py index 562d4f2f7..823dfbf64 100755 --- a/gnuradio-examples/python/volk_benchmark/volk_plot.py +++ b/gnuradio-examples/python/volk_benchmark/volk_plot.py @@ -25,11 +25,15 @@ def main(): choices=['mean', 'min', 'max'], default='mean', help='Set the type of plot to produce [default: %(default)s]') + parser.add_argument('-%', '--percent', type=str, + default=None, metavar="table", + help='Show percent difference to the given type [default: %(default)s]') args = parser.parse_args() # Set up global plotting properties matplotlib.rcParams['figure.subplot.bottom'] = 0.2 matplotlib.rcParams['figure.subplot.top'] = 0.95 + matplotlib.rcParams['figure.subplot.right'] = 0.98 matplotlib.rcParams['ytick.labelsize'] = 16 matplotlib.rcParams['xtick.labelsize'] = 16 matplotlib.rcParams['legend.fontsize'] = 18 @@ -39,9 +43,6 @@ def main(): tables = list_tables(conn) M = len(tables) - # width of bars depends on number of comparisons - wdth = 0.80/M - # Colors to distinguish each table in the bar graph # More than 5 tables will wrap around to the start. colors = ['b', 'r', 'g', 'm', 'k'] @@ -85,12 +86,23 @@ def main(): table_data[table[0]] = data + if args.percent is not None: + for i,t in enumerate(table_data): + if args.percent == t: + norm_data = [] + for name in name_reg: + if(args.plot == 'max'): + norm_data.append(table_data[t][name]['max']) + elif(args.plot == 'min'): + norm_data.append(table_data[t][name]['min']) + elif(args.plot == 'mean'): + norm_data.append(table_data[t][name]['avg']) + + # Plot the results x0 = xrange(len(name_reg)) - for i,t in enumerate(table_data): - # makes x values for this data set placement - x1 = [x + i*wdth for x in x0] - + i = 0 + for t in (table_data): ydata = [] stds = [] for name in name_reg: @@ -99,24 +111,52 @@ def main(): ydata.append(table_data[t][name]['max']) elif(args.plot == 'min'): ydata.append(table_data[t][name]['min']) - if(args.plot == 'mean'): + elif(args.plot == 'mean'): ydata.append(table_data[t][name]['avg']) - if(args.errorbars is False): - s0.bar(x1, ydata, width=wdth, - color=colors[i%M], label=t, - edgecolor='k', linewidth=2) + if args.percent is not None: + ydata = [-100*(y-n)/y for y,n in zip(ydata,norm_data)] + if(args.percent != t): + # makes x values for this data set placement + # width of bars depends on number of comparisons + wdth = 0.80/(M-1) + x1 = [x + i*wdth for x in x0] + i += 1 + + s0.bar(x1, ydata, width=wdth, + color=colors[(i-1)%M], label=t, + edgecolor='k', linewidth=2) + else: - s0.bar(x1, ydata, width=wdth, - yerr=stds, - color=colors[i%M], label=t, - edgecolor='k', linewidth=2, - error_kw={"ecolor": 'k', "capsize":5, - "linewidth":2}) + # makes x values for this data set placement + # width of bars depends on number of comparisons + wdth = 0.80/M + x1 = [x + i*wdth for x in x0] + i += 1 + + if(args.errorbars is False): + s0.bar(x1, ydata, width=wdth, + color=colors[(i-1)%M], label=t, + edgecolor='k', linewidth=2) + else: + s0.bar(x1, ydata, width=wdth, + yerr=stds, + color=colors[i%M], label=t, + edgecolor='k', linewidth=2, + error_kw={"ecolor": 'k', "capsize":5, + "linewidth":2}) + + nitems = res[0]['nitems'] + if args.percent is None: + s0.set_ylabel("Processing time (sec) [{0:G} items]".format(nitems), + fontsize=22, fontweight='bold', + horizontalalignment='center') + else: + s0.set_ylabel("% Improvement over {0} [{1:G} items]".format( + args.percent, nitems), + fontsize=22, fontweight='bold') s0.legend() - s0.set_ylabel("Processing time (sec) [{0:G} items]".format(res[0]['nitems']), - fontsize=22, fontweight='bold') s0.set_xticks(x0) s0.set_xticklabels(name_reg) for label in s0.xaxis.get_ticklabels(): -- cgit