Exemplo n.º 1
0
def mkFFT4(datawidth=16, point=8):
    din = [(dataflow.Variable('din' + str(i) + 're',
                              width=datawidth,
                              point=point,
                              signed=True),
            dataflow.Variable('din' + str(i) + 'im',
                              width=datawidth,
                              point=point,
                              signed=True)) for i in range(4)]

    # call software-defined method
    rslt = fft4(din)

    vars = []
    for i, (re, im) in enumerate(rslt):
        re.output('dout' + str(i) + 're')
        im.output('dout' + str(i) + 'im')
        vars.append(re)
        vars.append(im)

    df = dataflow.Dataflow(*vars)
    m = df.to_module('fft4')

    #try:
    #    df.draw_graph()
    #except:
    #    print('Dataflow graph could not be generated.', file=sys.stderr)

    return m
Exemplo n.º 2
0
def mkMain():
    # input variiable
    x = dataflow.Variable('xdata', valid='xvalid', ready='xready', width=8, signed=False)
    y = dataflow.Variable('ydata', valid='yvalid', ready='yready', width=8, signed=False)

    # dataflow definition
    bits = []
    carry = None
    for xbit, ybit in zip(x, y):
        if carry is None:
            v = xbit ^ ybit
        else:
            v = carry ^ xbit ^ ybit
        bits.append(v)
        carry = v

    bits.reverse()

    z = dataflow.Cat(*bits)

    # set output attribute
    z.output('zdata', valid='zvalid', ready='zready')

    df = dataflow.Dataflow(z)
    m = df.to_module('main')

    return m
Exemplo n.º 3
0
def mkMain():
    # input variiable
    m = Module('main')

    clk = m.Input('CLK')
    rst = m.Input('RST')

    xdata = m.Input('xdata', 32)
    xvalid = m.Input('xvalid')
    xready = m.Output('xready')

    ydata = m.Input('ydata', 32)
    yvalid = m.Input('yvalid')
    yready = m.Output('yready')

    zdata = m.Output('zdata', 32)
    zvalid = m.Output('zvalid')
    zready = m.Input('zready')

    x = dataflow.Variable(xdata, valid=xvalid, ready=xready)
    y = dataflow.Variable(ydata, valid=yvalid, ready=yready)

    # dataflow definition
    z = x + y

    # set output attribute
    z.output(zdata, valid=zvalid, ready=zready)

    # dataflow object
    df = dataflow.Dataflow(z)

    # implement the dataflow object on the existing module
    m = df.implement(m, clk, rst)

    return m
Exemplo n.º 4
0
def mkMain(width=4):
    # input variiable
    x = dataflow.Variable('xdata', width=width)
    y = dataflow.Variable('ydata', width=width)

    # dataflow definition
    bits = []
    carry = None
    for xbit, ybit in zip(x, y):
        if carry is None:
            v = xbit ^ ybit
        else:
            v = carry ^ xbit ^ ybit
        bits.append(v)
        carry = v

    bits.reverse()

    z = dataflow.Cat(*bits)

    # set output attribute
    z.output('zdata')

    df = dataflow.Dataflow(z)
    m = df.to_module('main')

    return m
Exemplo n.º 5
0
def mkMain():
    # input variiable
    x = dataflow.Variable('xdata',
                          valid='xvalid',
                          ready='xready',
                          signed=False)
    reset = dataflow.Variable('resetdata',
                              valid='resetvalid',
                              ready='resetready',
                              width=1,
                              signed=False)
    enable = dataflow.Variable('enabledata',
                               valid='enablevalid',
                               ready='enableready',
                               width=1,
                               signed=False)

    # dataflow definition
    z = dataflow.ReduceAdd(x,
                           initval=0,
                           enable=enable,
                           reset=reset,
                           signed=False)

    # set output attribute
    z.output('zdata', valid='zvalid', ready='zready')

    df = dataflow.Dataflow(z)
    m = df.to_module('main')
    # df.draw_graph()

    return m
Exemplo n.º 6
0
def mkMain():
    # input variiable
    x = dataflow.Variable('xdata', valid='xvalid', ready='xready')
    reset = dataflow.Variable('resetdata',
                              valid='resetvalid',
                              ready='resetready',
                              width=1)
    enable = dataflow.Variable('enabledata',
                               valid='enablevalid',
                               ready='enableready',
                               width=1)

    # dataflow definition
    z, v = dataflow.RegionAdd(x * x,
                              4,
                              initval=0,
                              enable=enable,
                              reset=reset,
                              filter=True)

    # set output attribute
    z.output('zdata', valid='zvalid', ready='zready')
    v.output('vdata', valid='vvalid', ready='vready')

    df = dataflow.Dataflow(z, v)
    m = df.to_module('main')
    # df.draw_graph()

    return m
Exemplo n.º 7
0
def mkMain(n=128, datawidth=32, numports=2):
    m = Module('main')

    clk = m.Input('CLK')
    rst = m.Input('RST')

    x = dataflow.Variable()
    y = x + 1
    z = y + 1

    y.output('ydata', 'yvalid', 'yready')
    z.output('zdata', 'zvalid', 'zready')

    # source variable
    xsrc = dataflow.Variable('xdata', 'xvalid', 'xready')
    # connect a variable to the variable that has no input_data
    x.connect(xsrc)

    # synthesize dataflow
    df = dataflow.Dataflow(z)
    df.implement(m, clk, rst, aswire=True)
    #df.draw_graph()

    
    # write
    xfsm = FSM(m, 'xfsm', clk, rst)
    xcount = m.TmpReg(32, initval=0)
    
    xack = x.write(xcount, cond=xfsm)
    xfsm.If(xack)(
        xcount.inc()
    )
    xfsm.Then().If(xcount == 15).goto_next()

    xfsm.make_always()

    
    # read
    yseq = Seq(m, 'yseq', clk, rst)
    
    ydata, yvalid = y.read(cond=yseq)
    yseq.If(yvalid)(
        Systask('display', "ydata=%d", ydata)
    )

    yseq.make_always()


    zseq = Seq(m, 'zseq', clk, rst)
    
    zdata, zvalid = z.read(cond=zseq)
    zseq.If(zvalid)(
        Systask('display', "zdata=%d", zdata)
    )

    zseq.make_always()

    
    return m
Exemplo n.º 8
0
def mkMain(n=128, datawidth=32, numports=2):
    m = Module('main')

    clk = m.Input('CLK')
    rst = m.Input('RST')

    # variables
    x = dataflow.Variable('xdata', 'xvalid', 'xready')
    y = dataflow.Variable('ydata', 'yvalid', 'yready')
    z = x + y
    z.output('zdata', 'zvalid', 'zready')

    # synthesize dataflow
    df = dataflow.Dataflow(z)
    df.implement(m, clk, rst, aswire=True)
    #df.draw_graph()

    inputs = df.get_input()
    outputs = df.get_output()

    # write
    xfsm = FSM(m, 'xfsm', clk, rst)
    xcount = m.TmpReg(32, initval=0)
    
    xack = inputs['xdata'].write(xcount, cond=xfsm)
    xfsm.If(xack)(
        xcount.inc()
    )
    xfsm.Then().If(xcount == 15).goto_next()

    xfsm.make_always()

    
    # write
    yfsm = FSM(m, 'yfsm', clk, rst)
    ycount = m.TmpReg(32, initval=0)
    
    yack = inputs['ydata'].write(ycount, cond=yfsm)
    yfsm.If(yack)(
        ycount( ycount + 1 )
    )
    yfsm.Then().If(ycount == 15).goto_next()
    
    yfsm.make_always()

    
    # read
    zseq = Seq(m, 'zseq', clk, rst)
    
    zdata, zvalid = outputs['zdata'].read(cond=zseq)
    zseq.If(zvalid)(
        Systask('display', "zdata=%d", zdata)
    )

    zseq.make_always()

    
    return m
Exemplo n.º 9
0
def mkMadd():
    x = dataflow.Variable('xd', valid='xv', signed=True)
    y = dataflow.Variable('yd', valid='yv', signed=True)
    vreset = dataflow.Variable('vreset_data', valid='vreset', width=1)

    xy = x * y

    z = dataflow.Iadd(xy, signed=True, initval=0, reset=vreset)

    z.output('zd', valid='zv')
    df = dataflow.Dataflow(z)
    m = df.to_module('madd')

    return m
Exemplo n.º 10
0
def mkMain():
    # input variiable
    x = dataflow.Variable('xdata', valid='xvalid', ready='xready')
    y = dataflow.Variable('ydata', valid='yvalid', ready='yready')

    # dataflow definition
    z = dataflow.CustomOp(add, x, y)

    # set output attribute
    z.output('zdata', valid='zvalid', ready='zready')

    df = dataflow.Dataflow(z)
    m = df.to_module('main')

    return m
Exemplo n.º 11
0
def mkMain():
    # input variiable
    x = dataflow.Variable('xdata', valid='xvalid', ready='xready', signed=True)
    y = dataflow.Variable('ydata', valid='yvalid', ready='yready', signed=True)

    # dataflow definition
    z = x * y

    # set output attribute
    z.output('zdata', valid='zvalid', ready='zready')

    df = dataflow.Dataflow(z)
    m = df.to_module('main')

    return m
Exemplo n.º 12
0
def mkMain():
    # input variiable
    x = dataflow.Variable('xdata')
    y = dataflow.Variable('ydata')

    # dataflow definition
    z = x + y

    # set output attribute
    z.output('zdata')

    df = dataflow.Dataflow(z)
    m = df.to_module('main')

    return m
Exemplo n.º 13
0
def mkMain():
    # input variiable
    x = dataflow.Variable('xdata', valid='xvalid', ready='xready')
    y = dataflow.Variable('ydata', valid='yvalid', ready='yready')

    # Mux with constant condition: only true_value is selected
    z = dataflow.Mux(1, x + y, x - y)

    # set output attribute
    z.output('zdata', valid='zvalid', ready='zready')

    df = dataflow.Dataflow(z)
    m = df.to_module('main')

    return m
Exemplo n.º 14
0
def mkMovAvg(length=8, datawidth=32):
    x = dataflow.Variable('xdata',
                          valid='xvalid',
                          ready='xready',
                          signed=True,
                          width=datawidth)

    srcs = [x.prev(i) for i in range(length)]

    #y = add_serial(srcs)
    y = add_parallel(srcs)

    if math.log(length, 2) % 1.0 == 0.0:
        y = y >> int(math.log(length, 2))
    else:
        y = y / length

    y.output('ydata', valid='yvalid', ready='yready')
    df = dataflow.Dataflow(y)
    m = df.to_module('movavg')

    #try:
    #    df.draw_graph()
    #except:
    #    print('Dataflow graph could not be generated.', file=sys.stderr)

    return m
Exemplo n.º 15
0
def mkStencilPipeline2D(coe=None, size=3, width=32, point=16):
    # size-port stream inputs
    iports = [dataflow.Variable('idata%d' % i, valid='ivalid%d' % i,
                                width=width, point=point, signed=True)
              for i in range(size)]

    if coe is None:
        coe = [[dataflow.Constant(1.0 / (1.0 * size * size), point=point) for i in range(size)]
               for j in range(size)]

    # source data
    data = [[d.prev(j) for j in range(size)] for d in iports]

    # from 2D list to 1D list
    data_list = []
    coe_list = []
    for d, c in zip(data, coe):
        data_list.extend(d)
        coe_list.extend(c)

    # computation by calling standard method
    rslt = stencil(coe_list, data_list)

    rslt.output('odata', valid='ovalid')

    df = dataflow.Dataflow(rslt)
    m = df.to_module('stencil_pipeline_2d')

    # try:
    #    df.draw_graph()
    # except:
    #    print('Dataflow graph could not be generated.', file=sys.stderr)

    return m
Exemplo n.º 16
0
def mkMain():
    # input variiable
    x = dataflow.Variable('xdata', valid='xvalid', ready='xready')
    y = dataflow.Variable('ydata', valid='yvalid', ready='yready')

    # dataflow definition
    z = x - y + dataflow.Constant(5)
    z = dataflow.Sign(z)

    # set output attribute
    z.output('zdata', valid='zvalid', ready='zready')

    df = dataflow.Dataflow(z)
    m = df.to_module('main')

    return m
Exemplo n.º 17
0
def mkMain():
    # input variiable
    x = dataflow.Variable('xdata', valid='xvalid', ready='xready')
    y = dataflow.Variable('ydata', valid='yvalid', ready='yready')

    # dataflow definition
    v = x + y
    z = (v + v.prev(1) + v.prev(2)) / 3

    # set output attribute
    z.output('zdata', valid='zvalid', ready='zready')

    df = dataflow.Dataflow(z)
    m = df.to_module('main')
    
    return m
Exemplo n.º 18
0
def mkMain():
    # input variiable
    x = dataflow.Variable('xdata', valid='xvalid', ready='xready')
    y = dataflow.Variable('ydata', valid='yvalid', ready='yready')

    # dataflow definition
    z = x + y
    z = z[0:16]  # = dataflow.Slice(z, 15, 0)

    # set output attribute
    z.output('zdata', valid='zvalid', ready='zready')

    df = dataflow.Dataflow(z)
    m = df.to_module('main')

    return m
def mkMain():
    # input variiable
    x = dataflow.Variable('xdata', valid='xvalid', ready='xready')
    y = dataflow.Variable('ydata', valid='yvalid', ready='yready')

    # dataflow definition
    z1 = x * y
    z2 = x * y + 1

    # set output attribute
    z1.output('z1data', valid='z1valid', ready='z1ready')
    z2.output('z2data', valid='z2valid', ready='z2ready')

    df = dataflow.Dataflow(z1, z2)
    m = df.to_module('main')

    return m
Exemplo n.º 20
0
def mkMain():
    # input variiable
    x = dataflow.Variable('xdata', valid='xvalid', ready='xready', signed=False)
    y = dataflow.Variable('ydata', valid='yvalid', ready='yready', signed=False)

    # dataflow definition
    patterns = tuple([i * i for i in range(256)])
    lut = dataflow.LUT(x, patterns, signed=False)
    z = lut + y

    # set output attribute
    z.output('zdata', valid='zvalid', ready='zready')

    df = dataflow.Dataflow(z)
    m = df.to_module('main')

    return m
Exemplo n.º 21
0
def mkMain(n=128, datawidth=32, numports=2):
    m = Module('main')

    clk = m.Input('CLK')
    rst = m.Input('RST')

    a = dataflow.Parameter('aparam', 10)  # parameter
    b = dataflow.ParameterVariable('bparam')  # input / wire

    xparam = m.Parameter('xparam', 100)
    x = dataflow.ParameterVariable(xparam)

    yparam = m.Reg('yparam', 32, initval=0)
    y = dataflow.ParameterVariable(yparam)

    zparam = 30
    z = dataflow.ParameterVariable(zparam)

    v = dataflow.Variable('vdata')
    w = dataflow.Variable('wdata')

    c = v + a + b + x + y + 1 + z + w
    c.output('cdata', valid='cvalid')

    # synthesize dataflow
    df = dataflow.Dataflow(c)
    df.implement(m, clk, rst, aswire=True)
    #df.draw_graph()

    fsm = FSM(m, 'fsm', clk, rst)
    count = m.TmpReg(32, initval=0)

    b.raw_data.assign(20)
    v.raw_data.assign(1000)
    w.raw_data.assign(2000)

    fsm(yparam(200))
    fsm.goto_next()

    fsm.If(c.valid)(count.inc(), Systask('display', "c=%d", c.data))

    fsm.If(count == 4).goto_next()

    fsm.make_always()

    return m
Exemplo n.º 22
0
def mkMain(n=128, datawidth=32, numports=2):
    m = Module('main')

    clk = m.Input('CLK')
    rst = m.Input('RST')

    x = dataflow.Variable('xdata', signed=False)
    y = dataflow.Variable(signed=False)

    z = x + y
    y.connect(z)  # y <- z <- y loop
    z.output('zdata')

    # synthesize dataflow
    df = dataflow.Dataflow(z)
    df.implement(m, clk, rst, aswire=True)  # -> ValueError ("Loop detected.")
    # df.draw_graph()

    return m
Exemplo n.º 23
0
def mkMain():
    # input variiable
    x = dataflow.Variable('xdata', valid='xvalid', ready='xready', signed=False)
    y = dataflow.Variable('ydata', valid='yvalid', ready='yready', signed=False)

    # dataflow definition
    z = x + y

    # set output attribute
    z.output('zdata', valid='zvalid', ready='zready')

    df = dataflow.Dataflow(z)
    m = df.to_module('main')
    try:
        df.draw_graph()
    except:
        print('Pygraphviz is not installed.')

    return m
Exemplo n.º 24
0
def mkMain():
    # input variiable
    x = dataflow.Variable('xdata', valid='xvalid', ready='xready')
    reset = dataflow.Variable('resetdata',
                              valid='resetvalid',
                              ready='resetready',
                              width=1)

    # dataflow definition
    z = dataflow.Iadd(x, initval=0, reset=reset)

    # set output attribute
    z.output('zdata', valid='zvalid', ready='zready')

    df = dataflow.Dataflow(z)
    m = df.to_module('main')
    #df.draw_graph()

    return m
Exemplo n.º 25
0
def mkMain():
    # input variiable
    x = dataflow.Variable('xdata', valid='xvalid', ready='xready')
    y = dataflow.Variable('ydata', valid='yvalid', ready='yready')
    reset = dataflow.Variable('resetdata',
                              valid='resetvalid',
                              ready='resetready')

    # dataflow definition
    v = x * y
    z = dataflow.ReduceAdd(v, initval=0, reset=reset)

    # set output attribute
    z.output('zdata', valid='zvalid', ready='zready')

    df = dataflow.Dataflow(z)
    m = df.to_module('main')

    return m
Exemplo n.º 26
0
def mkSort(numports=8):
    values = [dataflow.Variable('din%d' % i) for i in range(numports)]
    rslt = sort(values)

    for i, r in enumerate(rslt):
        r.output('dout%d' % i)

    df = dataflow.Dataflow(*rslt)
    m = df.to_module('sort')

    return m
Exemplo n.º 27
0
    def DataflowVar(self,
                    data,
                    valid=None,
                    ready=None,
                    width=32,
                    point=0,
                    signed=False):
        tmp = None

        data_name = None
        if isinstance(data, vtypes._Variable):
            data_name = data.name
        else:
            if tmp is None: tmp = self.get_tmp()
            data_wire = self.Wire('inport%d_data' % tmp, width=width)
            self.comb(data_wire(data))
            data_name = data_wire.name

        valid_name = None
        if valid is None:
            pass
        elif isinstance(valid, vtypes._Variable):
            valid_name = valid.name
        else:
            if tmp is None: tmp = self.get_tmp()
            valid_wire = self.Wire('inport%d_valid' % tmp)
            self.comb(valid_wire(valid))
            valid_name = valid_wire.name

        ready_name = None
        if ready is None:
            pass
        elif isinstance(ready, vtypes._Variable):
            ready_name = ready.name
        else:
            if tmp is None: tmp = self.get_tmp()
            ready_wire = self.Wire('inport%d_ready' % tmp)
            self.comb(ready(ready_wire))
            ready_name = ready_wire.name

        v = dataflow.Variable(data_name,
                              valid_name,
                              ready_name,
                              width=width,
                              point=0,
                              signed=signed)

        # remember RTL signal connectivity
        v.rtl_data = data
        v.rtl_valid = valid
        v.rtl_ready = ready

        return v
Exemplo n.º 28
0
def mkRadix2(datawidth=32):
    din0 = (dataflow.Variable('din0re', width=datawidth),
            dataflow.Variable('din0im', width=datawidth))
    din1 = (dataflow.Variable('din1re', width=datawidth),
            dataflow.Variable('din1im', width=datawidth))
    cnst = (dataflow.Variable('cnstre', width=datawidth),
            dataflow.Variable('cnstim', width=datawidth))
    
    r0, r1 = radix2(din0, din1, cnst)
    
    r0[0].output('dout0re')
    r0[1].output('dout0im')
    r1[0].output('dout1re')
    r1[1].output('dout1im')
    
    rslt = list(r0) + list(r1)
    df = dataflow.Dataflow(*rslt)
    
    m = df.to_module('radix2')

    try:
        df.draw_graph()
    except:
        print('Dataflow graph could not be generated.', file=sys.stderr)

    return m
Exemplo n.º 29
0
def mkMain():
    # input variiable
    x = dataflow.Variable('xdata', valid='xvalid', ready='xready')

    # dataflow definition
    z = dataflow.Imul(x, initval=1)

    # set output attribute
    z.output('zdata', valid='zvalid', ready='zready')

    df = dataflow.Dataflow(z)
    m = df.to_module('main')

    return m
Exemplo n.º 30
0
def mkMain():
    # input variiable
    x = dataflow.Variable('xdata', valid='xvalid', ready='xready')
    y = dataflow.Variable('ydata', valid='yvalid', ready='yready')

    # dataflow definition
    z = x + y

    # set output attribute
    z.output('zdata', valid='zvalid', ready='zready')

    # dataflow object
    df = dataflow.Dataflow(z)

    # implement the dataflow object on the existing module
    m = Module('main')
    clk = m.Input('CLK')
    rst = m.Input('RST')

    # To synthesize Variables as I/O, aswire must be False explicitly
    m = df.implement(m, clk, rst, aswire=False)

    return m