Example #1
0
    def test_throughput_hw(self, topology, wbits, abits, kind):
        prev_chkpt_name = get_checkpoint_name(topology, wbits, abits, "deploy_" + kind)
        end2end_example = "%s_w%da%d_%s" % (topology, wbits, abits, kind)
        model = load_test_checkpoint_or_skip(prev_chkpt_name)  # NOQA
        cfg = get_build_env(kind, target_clk_ns)
        if cfg["ip"] == "":
            pytest.skip("PYNQ board IP address not specified")
        ret = dict()
        # try a range of batch sizes, some may fail due to insufficient DMA
        # buffers
        bsize_range_in = [8 ** i for i in range(5)]
        bsize_range = []
        for bsize in bsize_range_in:
            res = throughput_test_remote(model, bsize)
            if res is not None:
                ret[bsize] = res
                bsize_range.append(bsize)
            else:
                # assume we reached largest possible N
                break
        y = [ret[key]["runtime[ms]"] for key in bsize_range]
        lrret = linregress(bsize_range, y)
        ret_str = ""
        ret_str += "\n" + "%s Throughput Test Results" % end2end_example
        ret_str += "\n" + "-----------------------------"
        ret_str += "\n" + "From linear regression:"
        ret_str += "\n" + "Invocation overhead: %f ms" % lrret.intercept
        ret_str += "\n" + "Time per sample: %f ms" % lrret.slope
        ret_str += "\n" + "Raw data:"

        ret_str += "\n" + "{:<8} {:<16} {:<16} {:<16} {:<16} {:<16}".format(
            "N", "runtime[ms]", "fclk[mhz]", "fps", "DRAM rd[Mb/s]", "DRAM wr[Mb/s]"
        )
        for k in bsize_range:
            v = ret[k]
            ret_str += "\n" + "{:<8} {:<16} {:<16} {:<16} {:<16} {:<16}".format(
                k,
                np.round(v["runtime[ms]"], 4),
                v["fclk[mhz]"],
                np.round(v["throughput[images/s]"], 2),
                np.round(v["DRAM_in_bandwidth[Mb/s]"], 2),
                np.round(v["DRAM_out_bandwidth[Mb/s]"], 2),
            )
        ret_str += "\n" + "-----------------------------"
        warnings.warn(ret_str)
        largest_bsize = bsize_range[-1]
        update_dashboard_data(
            topology, wbits, abits, "fclk[mhz]", ret[largest_bsize]["fclk[mhz]"]
        )
        update_dashboard_data(
            topology,
            wbits,
            abits,
            "throughput[images/s]",
            ret[largest_bsize]["throughput[images/s]"],
        )
Example #2
0
    import shutil
    import os

    # image = Image.open('/workspace/finn/onnx_experiments/img_MNIST_grayscale.png')
    # x = TF.to_tensor(image)
    # x.unsqueeze_(0)
    #
    # parent_model = load("5_dataflow_parent")
    # sdp_node = parent_model.graph.node[2]
    # remote_exec_model = build_dir + "8_deploy.onnx"
    # getCustomOp(sdp_node).set_nodeattr("model", remote_exec_model)
    # save(parent_model,"9_dataflow_parent_with_remote_bitfile_exec")

    # THROUGHPUT TESTS
    from finn.core.throughput_test import throughput_test_remote
    res = throughput_test_remote(model, batchsize=10000)
    print("Network metrics:")
    with open(build_dir + "res.txt", "w") as f:
        for key in res:
            print(str(key) + ": " + str(res[key]))
            f.write(str(key) + ": " + str(res[key]) + "\n")

    II = 64
    # frequency in MHz
    f_MHz = 100
    # expected throughput in MFPS
    expected_throughput = f_MHz / II
    # measured throughput (FPS) from throughput test, converted to MFPS
    measured_throughput = res["throughput[images/s]"] * 0.000001
    # peformance
    print("We reach approximately " +