Esempio n. 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)
def test_ej7(width_in, width_gain, width_out):
    from ej7 import SumaPonderada
    core = SumaPonderada()
    ports = [
        core.PiX0, core.PiX1, core.PiX2, core.PiW0, core.PiW1, core.PiW2,
        core.PoZ
    ]
    run(core, 'tb_ej7', ports=ports, vcd_file=waveform_dir + '/ej7.vcd')
Esempio n. 3
0
def test_core(width, depth):
    core = CircularROM(width=width, init=mem_init[:depth])
    os.environ['cocotb_param_depth'] = str(depth)
    ports = core.get_ports()
    run(core,
        'cnn.tests.test_rom',
        ports=ports,
        vcd_file=f'./test_rom_w{width}_d{depth}.vcd')
Esempio n. 4
0
def test_axi_lite_device():
    core = AxiLiteDevice(addr_w=5, data_w=32, registers=regs)
    ports = [core.axi_lite[f] for f in core.axi_lite.fields]
    ports += [core.registers[f] for f in core.registers.fields]
    run(core,
        'cores_nmigen.test.test_axi_lite',
        ports=ports,
        vcd_file='./test_axi_lite_device.vcd')
Esempio n. 5
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)
Esempio n. 6
0
def test_main_wrapper(latency):
    core = StreamWrapper(wrapped_core=ExampleCore(16, latency),
                         input_stream=DataStream(16, direction='sink', name='input'),
                         output_stream=DataStream(16, direction='source', name='output'),
                         input_map={'data': 'data_i'},
                         output_map={'data': 'data_o'},
                         latency=latency)
    ports = core.get_ports()
    run(core, 'cnn.tests.test_stream_wrapper', ports=ports, vcd_file=f'./test_stream_wrapper.vcd')
Esempio n. 7
0
def test_main(width, depth):
    fifo = StreamFifoCDC(input_stream=DataStream(width, 'sink', name='input'),
                         output_stream=DataStream(width, 'source', name='output'),
                         depth=depth,
                         r_domain='read',
                         w_domain='write')
    ports = [fifo.input[f] for f in fifo.input.fields]   
    ports += [fifo.output[f] for f in fifo.output.fields]
    run(fifo, 'cores_nmigen.test.test_fifo_cdc', ports=ports, vcd_file='test_stream_fifo_cdc.vcd')
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 = f'./test_matrix_interface_i{width}_shape{printable_shape}.vcd'
    run(core, 'cores_nmigen.test.test_matrix_interface', ports=ports, vcd_file=vcd_file)
Esempio n. 9
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)
Esempio n. 10
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)
Esempio n. 11
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)
Esempio n. 12
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)
Esempio n. 13
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)
Esempio n. 14
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)
Esempio n. 15
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)
Esempio n. 16
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)
Esempio n. 17
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)
    dut.rst <= 1
    await RisingEdge(dut.clk)
    await RisingEdge(dut.clk)
    dut.rst <= 0


@cocotb.test()
async def burst(dut):
    await init_test(dut)

    stream_input = Stream.Driver(dut.clk, dut, 'a__')
    stream_output = Stream.Driver(dut.clk, dut, 'r__')

    N = 100
    width = len(dut.a__data)
    mask = int('1' * width, 2)

    data = [getrandbits(width) for _ in range(N)]
    expected = [(d + 1) & mask for d in data]
    cocotb.fork(stream_input.send(data))
    recved = await stream_output.recv(N)
    assert recved == expected


if __name__ == '__main__':
    core = Incrementador(5)
    run(core,
        'example',
        ports=[*list(core.a.fields.values()), *list(core.r.fields.values())],
        vcd_file='incrementador.vcd')
Esempio n. 19
0
        # If sum > maxlim, it restarts forward from the negatives
        minlim + (a + b - maxlim - 1) if (a + b) > maxlim

        # If sum < minlim, it restarts backwards from the positives
        else maxlim - (minlim - a - b - 1) if (a + b) < minlim else (a + b)
        for a, b in zip(data_a, data_b)
    ]

    cocotb.fork(stream_input_a.send(data_a))

    # Waits 10 posedge before sending data_b, to check if a will hold its value until b picks it up
    for _ in range(10):
        await RisingEdge(dut.clk)

    cocotb.fork(stream_input_b.send(data_b))
    res = await stream_output.recv(N)
    assert res == expected


if __name__ == '__main__':
    core = Binary_Adder(8)

    run(
        core,
        'Binary_Adder',
        ports=[
            *list(core.a.fields.values()), *list(core.b.fields.values()),
            *list(core.r.fields.values())
        ],
        vcd_file='binary_adder.vcd',
    )
    cocotb.fork(stream_input_a.send(data_a))
    cocotb.fork(stream_input_b.send(data_b))

    # se llama al proceso recv para el stream_output y se espera a que este termine. recv lo que hace es que
    # en cada rise del clock, si r.valid es 1  ==> se copia el valor de r.data en en la lista 'data', definida dentro de recv.
    # Finalmente 'recv' devuelve esta lista.
    recved = await stream_output.recv(N)

    # se chequea si recved, es decir, los datos recibidos, coinciden con los datos esperados
    assert recved == expected


# =======================================================
'''
Main programa
'''
# Inicico del programa

if __name__ == '__main__':

    N_in = 8  # cantidad de bits de las streams de entrada 'a' y 'b'
    N_out = 16  # cantidad de bits del stream de salida, 'r''

    core = Adder(N_in, N_out)  # "core" es una instancia de la clase Adder
    run(core,
        'entrega_ej_1',
        ports=[
            *list(core.a.fields.values()), *list(core.b.fields.values()),
            *list(core.r.fields.values())
        ],
        vcd_file='adder.vcd')
Esempio n. 21
0
    rst <= (1 if logic == 'negative' else 0)


@cocotb.test()
def fast_to_slow(dut):
    axi_input = AxiStream(dut, 'input_', get_clock_signal(dut, CD_I))
    axi_output = AxiStream(dut, 'output_', get_clock_signal(dut, CD_O))
    init_axis_signals(axi_input, 'input')
    init_axis_signals(axi_output, 'output')

    start_clock(dut, CD_I, 10, 'ns')
    start_clock(dut, CD_O, 20, 'ns')

    yield Combine(reset_pulse(dut, CD_I), reset_pulse(dut, CD_O))

    yield Timer(100, 'ns')


def get_ports(m):
    ports = [m.input[f] for f in m.input.fields]
    ports += [m.output[f] for f in m.output.fields]
    return ports


if __name__ == '__main__':
    fifo = AxiStreamFifo(width=50, depth=256, cd_i=CD_I, cd_o=CD_O)
    run(fifo,
        'nmigen_axi.test.axi_stream.test_fifo',
        ports=get_ports(fifo),
        vcd_file='output.vcd')
def test_ej6(width_in, width_gain, width_out):
    from ej6 import Gain
    core = Gain(width_in=width_in, width_gain=width_gain, width_out=width_out)
    ports = [core.input, core.gain, core.output]
    run(core, 'tb_ej6', ports=ports, vcd_file=waveform_dir + '/ej6.vcd')
def test_ej5(width_in, width_out):
    from ej5 import Mean8
    core = Mean8(width_in=width_in, width_out=width_out)
    ports = [*core.inputs, core.output]
    run(core, 'tb_ej5', ports=ports, vcd_file=waveform_dir + '/ej5.vcd')
def test_ej4(width_in, width_out):
    from ej4 import RoundConvergent
    core = RoundConvergent(width_in=width_in, width_out=width_out)
    ports = [core.input, core.output]
    run(core, 'tb_ej4', ports=ports, vcd_file=waveform_dir + '/ej4.vcd')
def test_ej3(width_in, width_out):
    from ej3 import RoundNearest
    core = RoundNearest(width_in=width_in, width_out=width_out)
    ports = [core.input, core.output]
    run(core, 'tb_ej3', ports=ports, vcd_file=waveform_dir + '/ej3.vcd')
Esempio n. 26
0
    await init_test(dut)

    stream_input_a = Stream.Driver(dut.clk, dut, 'a__')
    stream_input_b = Stream.Driver(dut.clk, dut, 'b__')
    stream_output = Stream.Driver(dut.clk, dut, 'r__')

    N = 100
    width = len(dut.a__data)
    mask = int('1' * width, 2)

    data_a = [getrandbits(width) for _ in range(N)]
    data_b = [getrandbits(width) for _ in range(N)]

    expected = [(a + b) & mask for a in data_a for b in data_b]

    cocotb.fork(stream_input_a.send(data_a))
    cocotb.fork(stream_input_b.send(data_b))

    recved = await stream_output.recv(N)
    assert recved == expected


if __name__ == '__main__':
    core = Sumador(5)
    run(core,
        'ej1',
        ports=[
            *list(core.a.fields.values()), *list(core.b.fields.values()),
            *list(core.r.fields.values())
        ],
        vcd_file='sumador.vcd')
Esempio n. 27
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)
def test_ej1(width):
    from ej1 import Suma6
    core = Suma6(width)
    ports = core.inputs
    ports.append(core.output)
    run(core, 'tb_ej1', ports=ports, vcd_file=waveform_dir + '/ej1.vcd')
Esempio n. 29
0
    expected = [(a + b) & mask for a, b in zip(data_a, data_b)]

    # for a, b, r in zip(data_a, data_b, expected):
    #    dut._log.info("[a]:{:02X}, [b]:{:02X}, [r]:{:02X}".format(a, b, r))

    send_a = cocotb.fork(stream_input_a.send(data_a))
    send_b = cocotb.fork(stream_input_b.send(data_b))
    send_a.join()
    send_b.join()

    received = await stream_output.recv(N)

    for expctd, rcvd in zip(expected, received):
        if expctd != rcvd:
            dut._log.info("Expected {} Got {}".format(expctd, rcvd))
            raise TestFailure("Test failed")

    raise TestSuccess("Test passed")


if __name__ == '__main__':
    core = Adder(5)
    run(core,
        'test_adder',
        ports=[
            *list(core.a.fields.values()), *list(core.b.fields.values()),
            *list(core.r.fields.values())
        ],
        vcd_file='adder.vcd')
def test_ej2(width_in, width_out):
    from ej2 import Truncador
    core = Truncador(width_in=width_in, width_out=width_out)
    ports = [core.input, core.output]
    run(core, 'tb_ej2', ports=ports, vcd_file=waveform_dir + '/ej2.vcd')