def plot_throughput(csv_file, net_info, plot_dir):
    num_NNs = preprocess.get_num_NNs(csv_file)
    num_frozens = preprocess.get_num_frozens(csv_file, 0, net_info)
    data = get_data(csv_file, net_info, "throughput")
    max_layers = net_info["num_layers"]

    xs = num_frozens
    if do_flip:
        xs = list(reversed(xs))
    if do_norm:
        xs = [int(round(x * 100. / max_layers)) for x in xs]

    for i in range(
            2):  # Hack to get dimensions to match between 1st and 2nd graph
        for num_NN, marker, c in zip(num_NNs, MARKERS,
                                     plot_util.COLORLISTS[5]):
            task_fps = [
                np.average(data[num_NN][num_frozen]["task"])
                for num_frozen in num_frozens
            ]
            plt.plot(xs,
                     task_fps,
                     marker=marker,
                     label=str(num_NN) + " apps",
                     lw=4,
                     markersize=8,
                     color=c)

        # Format plot
        plt.xlabel(more_sharing_label, fontsize=25)
        # plt.tick_params(axis='x', which='both', bottom='off', top='off', labelbottom='off')
        plt.ylabel("Throughput (FPS)", fontsize=28)

        plt.tick_params(axis='y', which='major', labelsize=30)
        plt.tick_params(axis='y', which='minor', labelsize=24)
        plt.tick_params(axis='x', which='major', labelsize=30)
        plt.tick_params(axis='x', which='minor', labelsize=24)
        plt.ylim(0, 6)
        if do_norm:
            plt.xlim(0, 115)
        else:
            plt.xlim(1, max_layers + 4)

        if do_flip:
            plt.legend(loc=0, fontsize=20, frameon=True)
        else:
            plt.legend(loc=4, fontsize=20)
        plt.gca().xaxis.grid(True)
        plt.gca().yaxis.grid(True)
        plt.tight_layout()
        plt.savefig(plot_dir + "/task-throughput-partial.pdf")

        plt.clf()
Exemple #2
0
def plot_max_throughput(csv_file, plot_file):
    layers = preprocess.get_layers(csv_file, 0)
    num_NNs = preprocess.get_num_NNs(csv_file)
    data = get_data(csv_file, "throughput")
    labels = ["No sharing", "Max sharing"]

    colors = [plot_util.COLORS["red"], plot_util.COLORS["grey"]]

    fpses1 = []
    fpses2 = []
    errs1 = []
    errs2 = []

    for num_NN in num_NNs:
        fps1 = np.average(data[num_NN][layers[0]]["task"])
        err1 = np.std(data[num_NN][layers[0]]["task"])

        fps2 = np.average(data[num_NN][layers[1]]["task"]) - fps1
        err2 = np.std(data[num_NN][layers[1]]["task"])

        fpses1.append(fps1)
        fpses2.append(fps2)
        errs1.append(err1)
        errs2.append(err2)

    width = 0.5
    plt.bar(num_NNs, fpses1, width, yerr=errs1,
            label="No sharing",
            color=plot_util.NO_SHARING["color"],
            hatch=plot_util.NO_SHARING["pattern"],
            error_kw={'ecolor':'green', 'linewidth':3})

    plt.bar(num_NNs, fpses2, width, yerr=errs2, bottom=fpses1,
            label="Max sharing",
            color=plot_util.MAX_SHARING["color"],
            hatch=plot_util.MAX_SHARING["pattern"],
            error_kw={'ecolor':'green', 'linewidth':3})

    # Format plot
    plt.tick_params(axis='x', which='major', labelsize=28)
    plt.tick_params(axis='x', which='minor', labelsize=20)
    plt.tick_params(axis='y', which='major', labelsize=28)
    plt.tick_params(axis='y', which='minor', labelsize=20)
    plt.xlabel("Number of concurrent applications", fontsize=28)
    plt.ylabel("Throughput (FPS)", fontsize=28)
    plt.xlim(1, 30)
    plt.ylim(0, 20)
    plt.legend(loc=0, fontsize=15)
    plt.tight_layout()
    plt.gca().yaxis.grid(True)
    plt.savefig(plot_file)
    plt.clf()
def plot_false_negative_rate_nosharing(arch, latency_file, accuracy_file, sigma, num_events,\
                                       min_event_length_ms, max_fps, plot_dir, outfile):
    num_NNs = preprocess.get_num_NNs(latency_file)
    marker = "h"
    layer = preprocess.get_layers(latency_file, 0)[0]
    throughput_data = get_throughput_data(latency_file)
    acc_data, layer_name_by_num_frozen = get_accuracy_data(arch, accuracy_file)

    for i in range(2): # Hack to get dimensions to match between 1st and 2nd graph
        xs = []
        ys = []
        for num_NN in num_NNs:

            xs.append(num_NN)

            throughput = throughput_data[num_NN][layer]["task"]
            accuracy  = acc_data[layer]
            acc_dist = [random.gauss(accuracy, sigma) for i in range(num_events)]

            p_miss = get_probability_miss(acc_dist, min_event_length_ms, max_fps, throughput)
            ys.append(p_miss)

        plt.scatter(xs, ys, s=50, marker=marker, edgecolor='black', label=str(num_NN)+" apps")

        plt.xlabel(u"More sharing →\n(increasing FPS, decreasing accuracy)", fontsize=28)
        plt.tick_params(axis='x', which='both', bottom='off', top='off', labelbottom='off')
        plt.tick_params(axis='y', which='major', labelsize=24)
        plt.tick_params(axis='y', which='minor', labelsize=20)
        plt.ylabel("False negative rate", fontsize=28)

        #plt.title("Sigma = " + str(sigma), fontsize=30)
        plt.legend(loc=0, fontsize=15)
        plt.tight_layout()

        plt.savefig(plot_dir +"/no-sharing-fnr-" + str(num_NN) + "apps-" + \
                                str(min_event_length_ms) + "ms-" + \
                                str(sigma) + "sig.pdf")
        plt.clf()

    with open(outfile, "w+") as f:
        for x, y in zip(xs, ys):
            line = str(x) + "," + str(round(y,4)) + "\n"
            f.write(line)
Exemple #4
0
def plot_processor_latency(processors_file, plot_dir):
    layers = preprocess.get_layers(processors_file, 0)
    num_NNs = preprocess.get_num_NNs(processors_file)
    data = get_data(processors_file, "latency-processors")
    width = 0.4
    for i in range(2):              # Hack to get dimensions to match between 1st and 2nd graph
        for num_NN in num_NNs:
            xs = range(len(layers))

            base_fps = [np.average(data[num_NN][layer]["base"]) for layer in layers]
            task_fps = [np.average(data[num_NN][layer]["task"]) for layer in layers]
            base_errs = [np.std(data[num_NN][layer]["base"]) for layer in layers]
            task_errs = [np.std(data[num_NN][layer]["task"]) for layer in layers]

            plt.bar(xs, base_fps, width, yerr=base_errs,
                    label="Shared NNE",
                    color=plot_util.NO_SHARING["color"],
                    hatch=plot_util.NO_SHARING["pattern"],
                    error_kw={'ecolor':'green', 'linewidth':3})

            plt.bar(xs, task_fps, width, bottom=base_fps, yerr=task_errs,
                    label="Task NNE",
                    color=plot_util.MAINSTREAM["color"],
                    hatch=plot_util.MAINSTREAM["pattern"],
                    error_kw={'ecolor':'green', 'linewidth':3})

            plt.xlabel(more_sharing_label, fontsize=28)
            plt.ylabel("CPU per frame (ms)", fontsize=28)
            plt.ylim(0, 300)
            plt.tick_params(axis='x', which='both', bottom='off', top='off', labelbottom='off')
            plt.tick_params(axis='y', which='major', labelsize=28)
            plt.tick_params(axis='y', which='minor', labelsize=20)
            plt.legend(loc=0, fontsize=20, ncol=2)
            plt.gca().xaxis.grid(True)
            plt.gca().yaxis.grid(True)
            plt.title(str(num_NN) + " NNs", fontsize=30)
            plt.tight_layout()
            plot_file = plot_dir + "/latency-" + str(num_NN) + "-NN.pdf"
            plt.savefig(plot_file)
            plt.clf()
def plot_false_negative_rate(arch, latency_file, accuracy_file, sigma, num_events, min_event_length_ms, max_fps, plot_dir):
    num_NNs = preprocess.get_num_NNs(latency_file)
    shapes = ["o", "h", "D", "x", "1", "*", "P", "8"]
    for i in range(2): # Hack to get dimensions to match between 1st and 2nd graph
        for num_NN in [1, 2, 4]:
            cycol = cycle('crmkbgy').next
            #for num_NN, marker in zip(num_NNs[3:7], shapes):
            marker = "h"
            layers = preprocess.get_layers(latency_file, 0)

            throughput_data = get_throughput_data(latency_file)
            acc_data, layer_name_by_num_frozen = get_accuracy_data(arch, accuracy_file)

            xs  = range(0, len(layers))
            throughputs  = [throughput_data[num_NN][layer]["task"] for layer in layers]
            all_accuracies  = [acc_data[layer] for layer in layers]
            # If there is only one app, no matter what layer, accuracy is at its max
            if num_NN == 1:
                accuracies = [max(all_accuracies) for layer in layers]
            else:
                accuracies  = [acc_data[layer] for layer in layers]


            ys = []
            num_frozen_list = []
            fpses = []
            for fps, acc, layer in zip(throughputs, accuracies, layers):
                acc_dist = [random.gauss(acc, sigma) for i in range(num_events)]
                p_miss = get_probability_miss(acc_dist, min_event_length_ms, max_fps, fps)
                ys.append(p_miss)

                # Get info for annotation
                for num_frozen, layer_name in layer_name_by_num_frozen.iteritems():
                    if layer ==  layer_name:
                        break
                num_frozen_list.append(num_frozen)
                fpses.append(fps)

            plt.scatter(xs, ys, s=50, marker=marker, color=cycol(), edgecolor='black', label=str(num_NN)+" apps")

            # Annotate optimal point
            min_y = min(ys)
            x, num_frozen, fps = \
                    [(x, num_frozen, round(fps,0)) for x, y, num_frozen, fps \
                                                        in zip(xs,ys, num_frozen_list, fpses) if y==min_y][0]

            max_layers = max(layer_name_by_num_frozen.keys()) + 1
            percent_frozen = int(num_frozen / float(max_layers) * 100)

            plt.annotate("Best: Share "+str(percent_frozen) +"% layers @ " + str(fps) + " FPS",
                         xy=(x, min_y),
                         xytext=(.5, .7),
                         horizontalalignment='center',
                         xycoords='data',
                         fontsize=22,
                         textcoords='axes fraction',
                         arrowprops=dict(arrowstyle="->"))

            plt.xlabel(u"More sharing →\n(increasing FPS, decreasing accuracy)", fontsize=28)
            plt.tick_params(axis='x', which='both', bottom='off', top='off', labelbottom='off')
            plt.tick_params(axis='y', which='major', labelsize=24)
            plt.tick_params(axis='y', which='minor', labelsize=20)
            plt.xlim(6, len(layers))
            plt.ylim(0, 0.2)
            plt.ylabel("False negative rate", fontsize=28)

            #plt.title("Sigma = " + str(sigma), fontsize=30)
            plt.gca().yaxis.grid(True)
            plt.legend(loc=0, fontsize=20)
            plt.tight_layout()

            plt.savefig(plot_dir +"/false-neg-" + str(num_NN) + "apps-" + \
                                    str(min_event_length_ms) + "ms-" + \
                                    str(sigma) + "sig-" + \
                                    str(max_fps) + "fps.pdf")
            plt.clf()