Esempio n. 1
0
def test_cosim_both_queue(cosim_cls, din_delay, dout_delay):
    verif(drv(t=Queue[Uint[8]], seq=[list(range(10))])
          | delay_rng(din_delay, din_delay),
          drv(t=Queue[Uint[8]], seq=[list(range(10))])
          | delay_rng(din_delay, din_delay),
          f=czip(sim_cls=cosim_cls),
          ref=czip(name='ref_model'),
          delays=[delay_rng(dout_delay, dout_delay)])

    sim()
Esempio n. 2
0
def reduce2(din, cfg: TCfg, *, f, max_size):
    """Similar to the Python reduce function, applies a rolling computation to
    sequential pairs of values in a list. The ``din`` input is of type
    :class:`Queue` which holds the values to be used for computation while the
    ``cfg`` input is a :class:`Tuple` consisting of a ``reduce_size`` field and
    the ``init`` field holding the inital value.

    Args:
        f: Function to be performed
        max_size: Maximal length of the input `Queue` which is the depth of the
          FIFO used for storing intermediate values

    Returns:
        The result of the reduce operation
    """

    acctype = cfg.dtype['init']

    qtype = Queue[acctype, din.dtype.lvl - 1]

    temp_res = Intf(dtype=qtype)
    cfg_rep = cfg | replicate
    sec_opnd = (cfg_rep, temp_res) \
        | priority_mux \
        | fmap(f=union_collapse, fcat=czip, lvl=1)

    result = czip(din, sec_opnd) | decouple | fmap(f=f, fcat=czip, lvl=2)
    acc, fin_res = result | Union[qtype, qtype] | demux
    acc | fifo(intfs=[temp_res], depth=max_size)

    return fin_res
Esempio n. 3
0
def filter(pixels: Queue[Array[Uint[8], 3]], coef: Queue[Array[Fixp, 3]], *,
           window_num):

    window_cnt = replicate(when(coef['eot'], window_num), 3 * 3)

    mem_wr_data = czip(qcnt(coef, running=True, w_out=4, init=0),
                       coef) | flatten

    coef_rd = qrange(window_cnt['data']) \
        | flatten \
        | sdp(wr_addr_data=mem_wr_data, depth=16)

    pix_coef = czip(pixels, coef_rd) | reorder

    res = [dot(p) for p in pix_coef]

    return ccat(*res)
Esempio n. 4
0
def filter(pixels: Queue[Uint[8]], coef: Queue[Fixp], *, window_num):
    coef_t = coef.dtype.data
    accum_t = Fixp[coef_t.integer + 2, coef_t.width + 2]

    window_cnt = replicate(window_num, 3 * 3)

    mem_wr_data = czip(qcnt(coef, running=True, w_out=4, init=0),
                       coef) | flatten

    coef_rd = qrange(window_cnt['data']) \
        | flatten \
        | sdp(wr_addr_data=mem_wr_data, depth=16)

    return czip(pixels, coef_rd) \
        | queuemap(f=mul) \
        | accum(init=accum_t(0.0), cast=saturate) \
        | qround \
        | saturate(t=Uint[8])
def send_result(
        addr: Queue[Tuple[Uint['w_scale'], Tuple['y_scaled', 'x_scaled']], 1],
        res: Queue[Uint[1], 1]):

    demux_ctrl = res | yield_zeros_and_eot

    maybe_send = czip(addr, demux_ctrl) | Queue[Union[Unit, addr.dtype[0]], 1]
    detected_addr = maybe_send | filt(fixsel=1)
    interrupt = maybe_send[1] | yield_on_one_uint

    return detected_addr, interrupt
Esempio n. 6
0
def filter(din: Queue[Uint[8]], *, coeffs, precision=32):
    accum_t = Ufixp[10, 10 + precision]

    coeff = qrange(3*3) \
        | flatten \
        | rom(data=coeffs, dtype=Ufixp[0, precision])

    return czip(din, coeff) \
        | queuemap(f=mul) \
        | accum(init=accum_t(0.0), cast=saturate) \
        | qround \
        | saturate(t=Uint[8])
Esempio n. 7
0
def features_mem(rd_addr: Queue[Uint['w_addr'], 2], rst_in: Unit, *, casc_hw):

    w_rect = casc_hw.w_rect_data // 2

    rst_in | local_rst
    rd_addr = rd_addr | decouple_sp

    features_data = []
    for i in range(3):
        feature = rects_mem(rd_addr_if=rd_addr[0], inst_num=i, casc_hw=casc_hw)
        features_data.append(feature | decouple_sp)

    feature_data_t = Intf(Tuple[Uint[w_rect], Uint[1], Int[casc_hw.w_weight]])
    features_zip = czip(*features_data) | Queue[Array[feature_data_t.dtype, 3],
                                                1]

    sync = cart(rd_addr[1] | dreg, features_zip)

    dout_eot = ccat(sync[1], sync[0][0]) | Uint[3]
    dout = ccat(sync[0][1], dout_eot) | Queue[Array[feature_data_t.dtype, 3],
                                              3]
    return dout
Esempio n. 8
0
def test_general():
    iout = czip(Intf(Uint[1]), Intf(Queue[Uint[2], 1]),
                Intf(Queue[Uint[3], 3]), Intf(Queue[Uint[4], 5]))

    assert iout.dtype == Queue[Tuple[Uint[1], Uint[2], Uint[3], Uint[4]], 5]
Esempio n. 9
0
from pygears.lib import drv, check, czip
from pygears.typing import Queue, Uint

x = drv(t=Queue[Uint[5]], seq=[[10, 11], [13, 14, 15]])
y = drv(t=Queue[Uint[5]], seq=[[20, 21, 22], [23, 24]])

czip(x, y) | check(ref=[[(10, 20), (11, 22)], [(13, 23), (15, 24)]])
Esempio n. 10
0
from pygears.lib import drv, check, czip
from pygears.typing import Queue, Uint

x = drv(t=Queue[Uint[5]], seq=[[10, 11, 12]])
y = drv(t=Queue[Uint[5]], seq=[[20, 21, 22]])

czip(x, y) | check(ref=[[(10, 20), (11, 21), (12, 22)]])