Example #1
0
def test_main(width_i, stages):
    core = TreeAdderSigned(width_i=width_i,
                           n_stages=stages,
                           reg_in=True, reg_out=True)
    ports = core.get_ports()
    vcd_file = vcd_only_if_env(f'./test_adder_i{width_i}_s{stages}.vcd')
    run(core, 'cnn.tests.test_tree_operations', ports=ports, vcd_file=vcd_file)
Example #2
0
def test_dot_product(width_i, shape):
    os.environ['coco_param_shape'] = str(shape)
    core = DotProduct(width_i=width_i, shape=shape)
    ports = core.get_ports()
    printable_shape = '_'.join([str(i) for i in shape])
    vcd_file = vcd_only_if_env(
        f'./test_dot_product_i{width_i}_shape{printable_shape}.vcd')
    run(core, 'cnn.tests.test_dot_product', ports=ports, vcd_file=vcd_file)
Example #3
0
def test_farm(width, shape, n_cores):
    os.environ['coco_param_shape'] = str(shape)
    core = Farm(width=width,
                shape=shape,
                n_cores=n_cores)
    ports = core.get_ports()
    printable_shape = '_'.join([str(i) for i in shape])
    vcd_file = vcd_only_if_env(f'./test_farm_i{width}_shape{printable_shape}.vcd')
    run(core, 'cnn.tests.test_farm', ports=ports, vcd_file=vcd_file)
Example #4
0
def test_stream_macc(args, kwargs):
    core = StreamMacc(*args, **kwargs)
    ports = core.get_ports()
    iw = len(core.input.data)
    cw = len(core.r_data)
    aw = len(core.accumulator)
    ow = len(core.output.data)
    vcd_file = vcd_only_if_env(
        f'./test_stream_macc_i{iw}_c{cw}_a{aw}_w{ow}.vcd')
    run(core, 'cnn.tests.test_stream_macc', ports=ports, vcd_file=vcd_file)
Example #5
0
def test_main(width_i, n_stages, reg_in, reg_out):
    core = TreeHighestUnsignedWrapped(width_i=width_i,
                                      n_stages=n_stages,
                                      reg_in=reg_in,
                                      reg_out=reg_out)
    N = len(core.inputs)
    os.environ['coco_param_N'] = str(N)
    ports = core.get_ports()
    vcd_file = vcd_only_if_env(f'./test_highest_w{width_i}_s{n_stages}.vcd')
    run(core, 'cnn.tests.test_highest', ports=ports, vcd_file=vcd_file)
Example #6
0
def test_main(data_w, height, width, N, mode):
    os.environ['coco_param_height'] = str(height)
    os.environ['coco_param_width'] = str(width)
    os.environ['coco_param_N'] = str(N)
    os.environ['coco_param_mode'] = mode
    core = Pooling(data_w=data_w, input_shape=(height, width), N=N, mode=mode)
    ports = core.get_ports()
    vcd_file = vcd_only_if_env(
        f'./test_pooling_dw{data_w}_h{height}_w{width}_N{N}_m{mode}.vcd')
    run(core, 'cnn.tests.test_pooling', ports=ports, vcd_file=vcd_file)
Example #7
0
def test_row_fifos(input_w, row_length, N, invert):
    os.environ['coco_param_N'] = str(N)
    os.environ['coco_param_row_length'] = str(row_length)
    os.environ['coco_param_invert'] = str(int(invert))
    core = RowFifos(input_w=input_w, row_length=row_length, N=N, invert=invert)
    vcd_file = vcd_only_if_env(
        f'./test_row_fifos_i{input_w}_rowlength{row_length}_N{N}_invert{int(invert)}.vcd'
    )
    ports = core.get_ports()
    run(core, 'cnn.tests.test_row_fifos', ports=ports, vcd_file=vcd_file)
Example #8
0
def test_matrix_feeder(data_w, height, width, N, invert):
    os.environ['coco_param_N'] = str(N)
    os.environ['coco_param_height'] = str(height)
    os.environ['coco_param_width'] = str(width)
    os.environ['coco_param_invert'] = str(int(invert))
    core = MatrixFeeder(data_w=data_w,
                        input_shape=(height, width),
                        N=N,
                        invert=invert)
    ports = core.get_ports()
    vcd_file = vcd_only_if_env(f'./test_matrix_feeder_i{data_w}_h{height}_w{width}_N{N}_invert{invert}.vcd')
    run(core, 'cnn.tests.test_matrix_feeder', ports=ports, vcd_file=vcd_file)
Example #9
0
def test_matrix_interface(width, shape):
    os.environ['coco_param_shape'] = str(shape)
    core = MatrixInterfaceBypass(
        width=width,
        shape=shape,
    )
    ports = core.get_ports()
    printable_shape = '_'.join([str(i) for i in shape])
    vcd_file = vcd_only_if_env(
        f'./test_matrix_interface_i{width}_shape{printable_shape}.vcd')
    run(core,
        'cnn.tests.test_matrix_interface',
        ports=ports,
        vcd_file=vcd_file)
Example #10
0
def test_convolution(width, img_height, img_width, N, n_cores):
    os.environ['coco_param_N'] = str(N)
    os.environ['coco_param_img_height'] = str(img_height)
    os.environ['coco_param_img_width'] = str(img_width)
    os.environ['coco_param_n_cores'] = str(int(n_cores))
    core = Convolution(width=width,
                       input_shape=(img_height, img_width),
                       N=N,
                       n_cores=n_cores)
    ports = core.get_ports()
    vcd_file = vcd_only_if_env(
        f'./test_convolution_i{width}_h{img_height}_w{img_width}_N{N}_n{n_cores}.vcd'
    )
    run(core, 'cnn.tests.test_convolution', ports=ports, vcd_file=vcd_file)
Example #11
0
def test_main(data_w, input_shape, output_shape, fill_value):
    ih, iw = input_shape
    oh, ow = output_shape
    os.environ['coco_param_ih'] = str(ih)
    os.environ['coco_param_iw'] = str(iw)
    os.environ['coco_param_oh'] = str(oh)
    os.environ['coco_param_ow'] = str(ow)
    os.environ['coco_param_fill_value'] = str(fill_value)
    core = Resizer(data_w=data_w,
                   input_shape=input_shape,
                   output_shape=output_shape,
                   fill_value=fill_value)
    ports = core.get_ports()
    vcd_file = vcd_only_if_env(f'./test_resizer_ih{ih}_iw{iw}_oh{oh}_ow{ow}_fill{fill_value}.vcd')
    run(core, 'cnn.tests.test_resizer', ports=ports, vcd_file=vcd_file)
Example #12
0
def test_mlp_node(width_i, width_w, n_inputs, n_neurons):
    seed = random.randint(0, 99999)
    os.environ['coco_param_n_inputs'] = str(n_inputs)
    os.environ['coco_param_n_neurons'] = str(n_neurons)
    os.environ['coco_param_seed'] = str(
        seed)  # so from cocotb can generate same random data
    rom_init = get_rom(width_w, (n_inputs + 1) * n_neurons, seed=seed)
    core = mlpNode(width_i=width_i,
                   width_w=width_w,
                   n_inputs=n_inputs,
                   rom_init=rom_init)
    ports = core.get_ports()
    vcd_file = vcd_only_if_env(
        f'./test_mlp_node_d{width_i}_w{width_w}_n{n_inputs}_m{n_neurons}.vcd')
    run(core, 'cnn.tests.test_mlp_node', ports=ports, vcd_file=vcd_file)
Example #13
0
def test_main(width, leak):
    os.environ['coco_param_leak'] = str(leak)
    core = Relu(width=width, leak=leak)
    ports = core.get_ports()
    vcd_file = vcd_only_if_env(f'./test_relu_w{width}_l{leak}.vcd')
    run(core, 'cnn.tests.test_relu', ports=ports, vcd_file=vcd_file)
Example #14
0
def test_mac(input_w, output_w):
    core = MAC(input_w=input_w, output_w=output_w)
    ports = core.get_ports()
    vcd_file = vcd_only_if_env(f'./test_mac_i{input_w}_o{output_w}.vcd')
    run(core, 'cnn.tests.test_mac', ports=ports, vcd_file=vcd_file)