import numpy as np import os import prettyplotlib as ppl # makes nicer colors and generally better to look at graphs import matplotlib.pyplot as plt import matplotlib as mpl from prettyplotlib import brewer2mpl mpl.rcParams.update({'font.family':'Open Sans'}) def extractInfo(data): means = np.mean(data, axis=0) stds = np.std(data, axis=0) meanGpuHough = means[-3] stdGpuHough = stds[-3] meanCpuHough = means[-5] stdCpuHough = stds[-5] meansCpuAngle = [] meansGpuAngle = [] for hit in data: cpuAngle = hit[3] gpuAngle = hit[5] if cpuAngle not in meansCpuAngle: meansCpuAngle.append(cpuAngle) if gpuAngle not in meansGpuAngle: meansGpuAngle.append(gpuAngle) meanCpuAngle = np.mean(meansCpuAngle) meanGpuAngle = np.mean(meansGpuAngle) stdCpuAngle = np.std(meansCpuAngle) stdGpuAngle = np.std(meansGpuAngle) nAngles = data[0][2] nThreads = data[0][-2] nBlocks = data[0][-1] # return {"nBlocks": nBlocks, "nThreads": nThreads, "nAngles": nAngles, "meanCpuAngle": meanCpuAngle, "stdCpuAngle": stdCpuAngle, "meanGpuAngle": meanGpuAngle, "stdGpuAngle": stdGpuAngle, "meanCpuHough": meanCpuHough, "stdCpuHough": stdCpuHough, "meanGpuHough": meanGpuHough, "stdGpuHough": stdGpuHough} return (nBlocks, nThreads, nAngles, meanCpuAngle, stdCpuAngle, meanGpuAngle, stdGpuAngle, meanCpuHough, stdCpuHough, meanGpuHough, stdGpuHough) # _filenames = ["timings-128-180.csv", "timings-128-1800.csv", "timings-128-360.csv", "timings-128-3600.csv", "timings-128-720.csv", "timings-16-180.csv", "timings-16-1800.csv", "timings-16-360.csv", "timings-16-3600.csv", "timings-16-720.csv", "timings-256-180.csv", "timings-256-1800.csv", "timings-256-360.csv", "timings-256-3600.csv", "timings-256-720.csv", "timings-312-180.csv", "timings-312-1800.csv", "timings-312-360.csv", "timings-312-3600.csv", "timings-312-720.csv", "timings-32-180.csv", "timings-32-1800.csv", "timings-32-360.csv", "timings-32-3600.csv", "timings-32-720.csv", "timings-380-180.csv", "timings-380-1800.csv", "timings-380-360.csv", "timings-380-3600.csv", "timings-380-720.csv", "timings-452-180.csv", "timings-452-1800.csv", "timings-452-360.csv", "timings-452-3600.csv", "timings-452-720.csv", "timings-512-180.csv", "timings-512-1800.csv", "timings-512-360.csv", "timings-512-3600.csv", "timings-512-720.csv", "timings-64-180.csv", "timings-64-1800.csv", "timings-64-360.csv", "timings-64-3600.csv", "timings-64-720.csv", "timings-8-180.csv", "timings-8-1800.csv", "timings-8-360.csv", "timings-8-3600.csv", "timings-8-720.csv"] # correctFilenames = [] # for item in _filenames: # correctFilenames.append("timings-ikp507-4" + "/" + item) folder = "timings-ikp507-4" _filenames = os.listdir(folder) correctFilenames = [] for item in _filenames: correctFilenames.append(folder + "/" + item) data = [] for entry in correctFilenames: data.append(np.genfromtxt(entry, delimiter=',')) statistics = [] for datum in data: statistics.append(extractInfo(datum)) npStatistics = np.asarray(statistics) fixedAngle = [] for stat in statistics: if (stat[2] == 360): fixedAngle.append(stat) npFixedAngle = np.asarray(fixedAngle) fixedThread = [] for stat in statistics: if (stat[1] == 256): fixedThread.append(stat) npFixedThread = np.asarray(fixedThread) colorGpuHough = color=ppl.colors.set2[0] colorGpuAngle = color=ppl.colors.set2[1] colorCpuHough = color=ppl.colors.set2[2] colorCpuAngle = color=ppl.colors.set2[3] markerGpuHough = "o" markerGpuAngle = "s" markerCpuHough = "v" markerCpuAngle = "*" markerEdgeWidth = 0.6 fig = plt.figure(figsize=(14,8)) ax = fig.add_subplot(1, 1, 1) ax.set_title("Angles = 360 (every 1 degree)") ax.set_xlabel("Number of Threads") ax.set_ylabel("Execution time / ms") xLabels = npFixedAngle[:,1] xLabelsBlocks = npFixedAngle[:,0] xLabelNames = [] # for entry in zip(xLabels, xLabelsBlocks): # xLabelNames.append(str(int(entry[0])) + "\n" + str(int(entry[1]))) for entry in xLabels: xLabelNames.append(str(int(entry))) xLabels = np.insert(xLabels, 0, 0) xLabels = np.append(xLabels, 540) xLabelNames.insert(0, "") xLabelNames.append("") ax.set_xticks(xLabels) ax.set_xticklabels(xLabelNames) ax.set_autoscalex_on(False) fig1b = plt.figure(figsize=(14,8)) ax1b = fig1b.add_subplot(1, 1, 1) ax1b.set_title("Angles = 360 (every 1 degree)") ax1b.set_xlabel("Number of Threads") ax1b.set_ylabel("Execution time / ms") ax.grid(axis='y', color='0.3', linestyle=':', antialiased=True) ax1b.grid(axis='y', color='0.3', linestyle=':', antialiased=True) ax.errorbar(npFixedAngle[:,1], npFixedAngle[:,3], yerr=npFixedAngle[:,4], label="CPU Angle", linewidth=2, fmt=markerCpuAngle, color=colorCpuAngle, markeredgewidth=markerEdgeWidth) ax.errorbar(npFixedAngle[:,1], npFixedAngle[:,5], yerr=npFixedAngle[:,6], label="GPU Angle", linewidth=2, fmt=markerGpuAngle, color=colorGpuAngle, markeredgewidth=markerEdgeWidth) (_, caps, _) = ax1b.errorbar(npFixedAngle[:,1], npFixedAngle[:,5], yerr=npFixedAngle[:,6], label="GPU Angle", linewidth=2, fmt=markerGpuAngle, color=colorGpuAngle, markeredgewidth=markerEdgeWidth) for cap in caps: cap.set_markeredgewidth(1) # # ppl.plot(ax, data[:,0], data[:,6], label=r"Dynamic Parallelism (bunch size 1000 ns)", linewidth=2) # # position of ticks plt.tick_params(which='major', direction='in', bottom=True) ax.legend(loc=0, prop={'size':12}) ax1b.legend(loc=0, prop={'size':12}) fig.savefig('cpugpuangle-vs-thread.pdf', dpi=50, bbox_inches='tight') fig1b.savefig('gpuangle-vs-thread.pdf', dpi=50, bbox_inches='tight') fig2 = plt.figure(figsize=(14,8)) ax2 = fig2.add_subplot(1, 1, 1) ax2.set_title("Angles = 360 (every 1 degree)") ax2.set_xlabel("Number of Threads") ax2.set_ylabel("Execution time / ms") fig2b = plt.figure(figsize=(14,8)) ax2b = fig2b.add_subplot(1, 1, 1) ax2b.set_title("Angles = 360 (every 1 degree)") ax2b.set_xlabel("Number of Threads") ax2b.set_ylabel("Execution time / ms") ax2.grid(axis='y', color='0.3', linestyle=':', antialiased=True) ax2b.grid(axis='y', color='0.3', linestyle=':', antialiased=True) ax2.errorbar(npFixedAngle[:,1], npFixedAngle[:,7], yerr=npFixedAngle[:,8], label="CPU Hough", linewidth=2, fmt=markerCpuHough, color=colorCpuHough, markeredgewidth=markerEdgeWidth) ax2.errorbar(npFixedAngle[:,1], npFixedAngle[:,9], yerr=npFixedAngle[:,10], label="GPU Hough", linewidth=2, fmt=markerGpuHough, color=colorGpuHough, markeredgewidth=markerEdgeWidth) ax2b.errorbar(npFixedAngle[:,1], npFixedAngle[:,9], yerr=npFixedAngle[:,10], label="GPU Hough", linewidth=2, fmt=markerGpuHough, color=colorGpuHough, markeredgewidth=markerEdgeWidth) ax2.legend(loc=0, prop={'size':12}) ax2.set_xticks(xLabels) ax2.set_xticklabels(xLabelNames) ax2.set_autoscalex_on(False) fig2.savefig('cpugpuhough-vs-thread.pdf', dpi=50, bbox_inches='tight') print npFixedAngle[:,1][3], npFixedAngle[:,7][3], npFixedAngle[:,9][3], npFixedAngle[:,7][3]/npFixedAngle[:,9][3] ax2b.set_xticks(xLabels) ax2b.set_xticklabels(xLabelNames) ax2b.set_autoscalex_on(False) ax2b.legend(loc=0, prop={'size':12}) fig2b.savefig('gpuhough-vs-thread.pdf', dpi=50, bbox_inches='tight') fig3 = plt.figure(figsize=(14,8)) ax3 = fig3.add_subplot(1, 1, 1) ax3.set_title("Angles = 360 (every 1 degree)") ax3.set_xlabel("Number of Threads") ax3.set_ylabel("Execution time / ms") ax3.grid(axis='y', color='0.3', linestyle=':', antialiased=True) ax3.errorbar(npFixedAngle[:,1], npFixedAngle[:,5], yerr=npFixedAngle[:,6], label="GPU Angle", linewidth=2, fmt=markerGpuAngle, color=colorGpuAngle, markeredgewidth=markerEdgeWidth) ax3.errorbar(npFixedAngle[:,1], npFixedAngle[:,9], yerr=npFixedAngle[:,10], label="GPU Hough", linewidth=2, fmt=markerGpuHough, color=colorGpuHough, markeredgewidth=markerEdgeWidth) ax3.legend(loc=0, prop={'size':12}) ax3.set_xticks(xLabels) ax3.set_xticklabels(xLabelNames) ax3.set_autoscalex_on(False) fig3.savefig('gpuhoughangle-vs-thread.pdf', dpi=50, bbox_inches='tight') #### fig4 = plt.figure(figsize=(14,8)) ax4 = fig4.add_subplot(1, 1, 1) ax4.set_title("Threads = 256") ax4.set_xlabel("Number of Angle Values") ax4.set_ylabel("Execution time / ms") ax4.grid(axis='y', color='0.3', linestyle=':', antialiased=True) ax4.errorbar(npFixedThread[:,2], npFixedThread[:,5], yerr=npFixedThread[:,6], label="GPU Angle", linewidth=2, fmt=markerGpuAngle, color=colorGpuAngle, markeredgewidth=markerEdgeWidth) ax4.errorbar(npFixedThread[:,2], npFixedThread[:,9], yerr=npFixedThread[:,10], label="GPU Hough", linewidth=2, fmt=markerGpuHough, color=colorGpuHough, markeredgewidth=markerEdgeWidth) ax4.legend(loc=0, prop={'size':12}) fig4.savefig('gpuhoughangle-vs-angles.pdf', dpi=50, bbox_inches='tight') fig5 = plt.figure(figsize=(14,8)) ax5 = fig5.add_subplot(1, 1, 1) ax5.set_title("Threads = 256") ax5.set_xlabel("Number of Angle Values") ax5.set_ylabel("Execution time / ms") ax5.grid(axis='y', color='0.3', linestyle=':', antialiased=True) ax5.errorbar(npFixedThread[:,2], npFixedThread[:,9], yerr=npFixedThread[:,10], label="GPU Hough", linewidth=2, fmt=markerGpuHough, color=colorGpuHough, markeredgewidth=markerEdgeWidth) ax5.errorbar(npFixedThread[:,2], npFixedThread[:,7], yerr=npFixedThread[:,8], label="CPU Hough", linewidth=2, fmt=markerCpuHough, color=colorCpuHough, markeredgewidth=markerEdgeWidth) ax5.legend(loc=2, prop={'size':12}) fig5.savefig('cpugpuhough-vs-angles.pdf', dpi=50, bbox_inches='tight') ax5.set_yscale("log") fig5.savefig('cpugpuhough-vs-angles--log.pdf', dpi=50, bbox_inches='tight') print npFixedThread[:,2][-2], npFixedThread[:,7][-2], npFixedThread[:,9][-2], npFixedThread[:,7][-2]/npFixedThread[:,9][-2]