Exemple #1
0
def prefill(din, *, num, dtype):
    fill = once(val=dtype(0)) \
        | replicate(num) \
        | flatten

    return priority_mux(fill, din) \
        | union_collapse
Exemple #2
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)
Exemple #3
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])
Exemple #4
0
def classifier(fb_data: Queue[Array[Tuple[Uint['w_ii'], Uint[1],
                                          Int['w_weight']], 3], 3],
               feat_addr: Queue[Uint['w_addr_feat'], 2],
               stage_addr: Queue[Uint['w_stage_addr'], 1],
               stddev: Uint['w_stddev'],
               rst_in: Unit,
               *,
               w_ii=b'w_ii',
               w_weight=b'w_weight',
               casc_hw):
    rst_in | local_rst

    stage_addr = stage_addr | dreg
    stddev = stddev | dreg
    # fb_data = fb_data | dreg_sp
    feat_addr = feat_addr | dreg | dreg_sp

    stddev_repl = replicate(ccat(5000, stddev))
    stddev_repl = stddev_repl[0]

    rect_sum_s = fb_data | rect_sum(w_ii=w_ii, w_weight=w_weight)
    feature_threshold = rom(feat_addr[0],
                            data=casc_hw.feature_threshold_mem,
                            dtype=Int[casc_hw.w_feature_threshold])

    stddev_repl = stddev_repl | cart_sync_with(
        ccat(rect_sum_s, 0) | Queue[rect_sum_s.dtype, 1])
    res = ccat(rect_sum_s, feature_threshold, stddev_repl)

    leaf_num = res | get_leaf_num | dreg_sp
    leaf_val = leaf_vals(feat_addr=feat_addr, din=leaf_num, casc_hw=casc_hw)

    stage_eot = feat_addr[1][0] | dreg_sp
    leaf_val = ccat(leaf_val, stage_eot) | Queue[leaf_val.dtype, 1]

    accum_stage = leaf_val | accum_on_eot(add_num=256)

    stage_res = accum_stage | get_stage_res(stage_addr=stage_addr,
                                            casc_hw=casc_hw)

    stage_res = ccat(stage_res | dreg_sp,
                     stage_addr[1]) | Queue[stage_res.dtype, 1]

    return stage_res
Exemple #5
0
from pygears.lib import replicate, check, drv
from pygears.typing import Uint

drv(t=Uint[4], seq=[5]) \
    | replicate(4) \
    | check(ref=[[5, 5, 5, 5]])