Skip to content

Commit

Permalink
Readyfix (#57)
Browse files Browse the repository at this point in the history
Improved ready bit wiring in Terra. As a consequence, fanOut of HS modules without a broadcastStream now results in an error! (Technically, this may have been an error before, but wasn't checked). This makes ready bit wiring much simpler - no ANDing of ready bits in the wiring code.
  • Loading branch information
jameshegarty committed Aug 21, 2017
1 parent 249ec26 commit 1707f85
Show file tree
Hide file tree
Showing 18 changed files with 261 additions and 130 deletions.
6 changes: 4 additions & 2 deletions examples/convpadcrop_wide_handshake_4_1.lua
@@ -1,4 +1,5 @@
local R = require "rigel"
local RS = require "rigelSimple"
local RM = require "modules"
local types = require("types")
local S = require("systolic")
Expand Down Expand Up @@ -49,8 +50,9 @@ function MAKE(T,ConvWidth,size1080p,NOSTALL)
local RW_TYPE = types.array2d( types.uint(8), 8 ) -- simulate axi bus
local HST = types.tuple{RW_TYPE,TAP_TYPE}
local hsfninp_raw = R.input( R.Handshake(HST) )
local hsfninp = R.apply( "idx0", RM.makeHandshake(C.index(HST,0)), hsfninp_raw )
local hsfn_taps = R.apply( "idx1", RM.makeHandshake(C.index(HST,1)), hsfninp_raw )
local inp0, inp1 = RS.fanOut{input=hsfninp_raw,branches=2}
local hsfninp = R.apply( "idx0", RM.makeHandshake(C.index(HST,0)), inp0 )
local hsfn_taps = R.apply( "idx1", RM.makeHandshake(C.index(HST,1)), inp1 )
local out = hsfninp

local out = R.apply("reducerate", RM.liftHandshake(RM.changeRate(types.uint(8),1,8,T)), out )
Expand Down
5 changes: 3 additions & 2 deletions examples/descriptor_core.lua
Expand Up @@ -43,9 +43,10 @@ descriptor.descriptor = sift.siftDescriptor(types.int(8))

function norm()
local inp = R.input( R.HS( R.tuple{ R.array(R.int32,1), R.array(R.float,1) } ) )
local inp0, inp1 = R.fanOut{input=inp, branches=2}

local desc_sum = R.index{input=R.index{input=inp, key=1 }, key=0}
local desc0 = rigel.apply("d0lift",RM.makeHandshake(sift.fixedLift(R.int32)), R.index{input=R.index{input=inp,key=0 },key=0} )
local desc_sum = R.index{input=R.index{input=inp0, key=1 }, key=0}
local desc0 = rigel.apply("d0lift",RM.makeHandshake(sift.fixedLift(R.int32)), R.index{input=R.index{input=inp1,key=0 },key=0} )

local desc = rigel.apply("pt",RM.packTuple{R.float,R.float},rigel.concat("PTT",{desc0,desc_sum}))
local desc = rigel.apply("ptt",RM.makeHandshake(sift.fixedDiv(R.float)),desc)
Expand Down
9 changes: 7 additions & 2 deletions examples/edge.lua
Expand Up @@ -95,12 +95,17 @@ else
end

local inp = R.input(R.Handshake(FNTYPE))
local inpB = R.apply("inpB", RM.broadcastStream(FNTYPE,2), inp)
local inp0 = R.selectStream("inp0",inpB,0)
local inp1 = R.selectStream("inp1",inpB,1)
--local inp0, inp1 = RS.fanOut{input=inp, branches=2}

local out
local inptaps

if TAPS then
out = R.apply( "i0", RM.makeHandshake(C.index(FNTYPE,0)), inp)
inptaps = R.apply("idx1",RM.makeHandshake(C.index(FNTYPE,1)), inp)
out = R.apply( "i0", RM.makeHandshake(C.index(FNTYPE,0)), inp0)
inptaps = R.apply("idx1",RM.makeHandshake(C.index(FNTYPE,1)), inp1)
inptaps = R.apply("idx11",RM.makeHandshake(C.index(TTYPE,0)), inptaps)
inptaps = R.apply("IIT", RM.makeHandshake(C.broadcast(types.uint(32):makeConst(),2)), inptaps)
else
Expand Down
12 changes: 10 additions & 2 deletions examples/harnessTerra.t
Expand Up @@ -17,9 +17,17 @@ local terraWrapper = J.memoize(function(fn,inputFilename,inputType,tapType,outpu

local ITYPE = types.tuple{types.null(),fixedTapInputType}
inpSymb = R.input( R.Handshake(ITYPE) )

local inpL, inpR = inpSymb, inpSymb

if tapType~=nil then
local O = R.apply("bstream",RM.broadcastStream(ITYPE,2),inpSymb)
inpL = R.selectStream("b0",O,0)
inpR = R.selectStream("b1",O,1)
end

local inpdata = R.apply("inpdata", RM.makeHandshake(C.index(types.tuple{types.null(),fixedTapInputType},0),nil,true), inpSymb)
local inptaps = R.apply("inptaps", RM.makeHandshake(C.index(types.tuple{types.null(),fixedTapInputType},1)), inpSymb)
local inpdata = R.apply("inpdata", RM.makeHandshake(C.index(types.tuple{types.null(),fixedTapInputType},0),nil,true), inpL)
local inptaps = R.apply("inptaps", RM.makeHandshake(C.index(types.tuple{types.null(),fixedTapInputType},1)), inpR)

out = R.apply("fread",RM.makeHandshake(RM.freadSeq(inputFilename,R.extractData(inputType)),nil,true),inpdata)
local hsfninp = out
Expand Down
47 changes: 35 additions & 12 deletions examples/lk_tr_core.lua
Expand Up @@ -152,9 +152,21 @@ function makeA( T, dType, window, bits )

local stt = types.array2d(dType, window*T, window)
local inpt = types.tuple{ stt, stt }
local inp = R.input( R.Handshake(inpt) )
local Fdx = R.apply("fdx", RM.makeHandshake(C.index(inpt,0)), inp)
local Fdy = R.apply("fdy", RM.makeHandshake(C.index(inpt,1)), inp)
local input = R.input( R.Handshake(inpt) )
local inputB = R.apply("inpB", RM.broadcastStream(inpt,2),input)
local input0 = R.selectStream("input0",inputB,0)
local input1 = R.selectStream("input1",inputB,1)

local Fdx = R.apply("fdx", RM.makeHandshake(C.index(inpt,0)), input0)
local FdxB = R.apply("fdxB", RM.broadcastStream(stt,2),Fdx)
local Fdx0 = R.selectStream("fdx0",FdxB,0)
local Fdx1 = R.selectStream("fdx1",FdxB,1)

local Fdy = R.apply("fdy", RM.makeHandshake(C.index(inpt,1)), input1)
--local Fdy0, Fdy1 = RS.fanOut{input=Fdy, branches=2}
local FdyB = R.apply("fdyB", RM.broadcastStream(stt,2),Fdy)
local Fdy0 = R.selectStream("fdy0",FdyB,0)
local Fdy1 = R.selectStream("fdy1",FdyB,1)

local partial = makePartial( dType, dType, bits.Apartial[1], bits.Apartial[2] )
bits.Apartial[3] = partial[3]
Expand All @@ -165,19 +177,19 @@ function makeA( T, dType, window, bits )
local rsumfn = makeSumReduce(partial_type,false)
local rsumAsyncfn = makeSumReduce(partial_type,true)

local inp0 = R.apply("inp0", C.SoAtoAoSHandshake(window*T,window,{dType,dType}), R.concat("o0",{Fdx,Fdx}) )
local inp0 = R.apply("inp0", C.SoAtoAoSHandshake(window*T,window,{dType,dType}), R.concat("o0",{Fdx0,Fdx0}) )
local out0 = R.apply("out0", RM.makeHandshake(RM.map(partialfn, window*T, window)), inp0 )
local out0 = R.apply("out0red", RM.makeHandshake(RM.reduce(rsumfn, window*T, window)), out0 )
local out0 = R.apply("out0redseq", RM.liftHandshake(RM.liftDecimate(RM.reduceSeq( rsumAsyncfn, T ))), out0 )

local inp1 = R.apply("inp1", C.SoAtoAoSHandshake(window*T,window,{dType,dType}), R.concat("o1",{Fdx,Fdy}) )
local inp1 = R.apply("inp1", C.SoAtoAoSHandshake(window*T,window,{dType,dType}), R.concat("o1",{Fdx1,Fdy0}) )
local out1 = R.apply("out1", RM.makeHandshake(RM.map(partialfn, window*T, window)), inp1 )
local out1 = R.apply("out1red", RM.makeHandshake(RM.reduce(rsumfn, window*T, window)), out1 )
local out1 = R.apply("out1redseq", RM.liftHandshake(RM.liftDecimate(RM.reduceSeq( rsumAsyncfn, T ))), out1 )

local out2 = out1

local inp3 = R.apply("inp3", C.SoAtoAoSHandshake(window*T,window,{dType,dType}), R.concat("o3",{Fdy,Fdy}) )
local inp3 = R.apply("inp3", C.SoAtoAoSHandshake(window*T,window,{dType,dType}), R.concat("o3",{Fdy1,Fdy1}) )
local out3 = R.apply("out3", RM.makeHandshake(RM.map(partialfn, window*T, window)), inp3 )
local out3 = R.apply("out3red", RM.makeHandshake(RM.reduce(rsumfn, window*T, window)), out3 )
local out3 = R.apply("out3redseq", RM.liftHandshake(RM.liftDecimate(RM.reduceSeq( rsumAsyncfn, T ))), out3 )
Expand All @@ -186,7 +198,7 @@ function makeA( T, dType, window, bits )
out = R.apply("PT",RM.packTuple({partial_type,partial_type,partial_type,partial_type}),out)
out = R.apply("PTC",RM.makeHandshake(C.tupleToArray(partial_type,4)),out)

return RM.lambda("A", inp, out ), partial_type
return RM.lambda("A", input, out ), partial_type
end

function minus(ty)
Expand Down Expand Up @@ -232,7 +244,13 @@ function makeB( T, dtype, window, bits )
--print("GMF type", gmf_type)
cost = cost + gmf_cost*window*window
gmf = R.apply("SSM",RM.makeHandshake(RM.map(m,window*T,window)), gmf)
gmf = FIFO( fifos, statements, types.array2d(gmf_type,window*T,window), gmf)
local GMFT = types.array2d(gmf_type,window*T,window)
gmf = FIFO( fifos, statements, GMFT, gmf)

local gmfB = R.apply("inpB", RM.broadcastStream(GMFT,2),gmf)
local gmf0 = R.selectStream("inp0",gmfB,0)
local gmf1 = R.selectStream("inp1",gmfB,1)

---------

local partial = makePartial( dtype, gmf_type, bits.Bpartial[1], bits.Bpartial[2] )
Expand All @@ -244,13 +262,13 @@ function makeB( T, dtype, window, bits )
local rsumfn = makeSumReduce(partial_type,false)
local rsumAsyncfn = makeSumReduce(partial_type,true)

local out_0 = R.concat("o0tup",{Fdx, gmf})
local out_0 = R.concat("o0tup",{Fdx, gmf0})
local out_0 = R.apply("o0P", C.SoAtoAoSHandshake(window*T,window,{dtype, gmf_type}), out_0)
local out_0 = R.apply("o0", RM.makeHandshake(RM.map(partialfn, window*T, window)), out_0)
local out_0 = R.apply("out0red", RM.makeHandshake(RM.reduce(rsumfn, window*T, window)), out_0 )
local out_0 = R.apply("out0redseq", RM.liftHandshake(RM.liftDecimate(RM.reduceSeq(rsumAsyncfn, T))), out_0 )

local out_1 = R.concat("o1tup",{Fdy, gmf})
local out_1 = R.concat("o1tup",{Fdy, gmf1})
local out_1 = R.apply("o1P", C.SoAtoAoSHandshake(window*T,window,{dtype,gmf_type}), out_1)
local out_1 = R.apply("o1", RM.makeHandshake(RM.map(partialfn, window*T, window)), out_1)
local out_1 = R.apply("out1red", RM.makeHandshake(RM.reduce(rsumfn, window*T, window)), out_1 )
Expand Down Expand Up @@ -318,8 +336,13 @@ function makeLK( internalT, internalW, internalH, window, bits )

local INPTYPE = types.array2d(types.uint(8),2)
local inp = R.input(R.Handshake(INPTYPE))
local frame0 = R.apply("f0", RM.makeHandshake(C.index(INPTYPE, 0 )), inp)
local frame1 = R.apply("f1", RM.makeHandshake(C.index(INPTYPE, 1 )), inp)

local inpB = R.apply("inpB", RM.broadcastStream(INPTYPE,2),inp)
local inp0 = R.selectStream("inp0",inpB,0)
local inp1 = R.selectStream("inp1",inpB,1)

local frame0 = R.apply("f0", RM.makeHandshake(C.index(INPTYPE, 0 )), inp0)
local frame1 = R.apply("f1", RM.makeHandshake(C.index(INPTYPE, 1 )), inp1)


local frame0_arr = R.apply("f0_arr", RM.makeHandshake(C.arrayop(types.uint(8),1)), frame0)
Expand Down
6 changes: 4 additions & 2 deletions examples/pyramid_core.lua
@@ -1,5 +1,6 @@
local R = require "rigel"
local RM = require "modules"
local RS = require "rigelSimple"
local types = require "types"
local C = require "examplescommon"
local P = {}
Expand Down Expand Up @@ -78,13 +79,14 @@ function P.pyramidIterTaps(i,doDownsample,internalT,W,H,ConvWidth,nofifo,DUMB_DO
local TAP_TYPE = types.array2d( A, ConvWidth, ConvWidth):makeConst()
local INP_TYPE = types.tuple{DATA_TYPE,TAP_TYPE}
local inp = R.input( R.Handshake(INP_TYPE) )
local inpL, inpR = RS.fanOut{input=inp, branches=2}
local borderValue = 0

local fifos = {}
local statements = {}

local out = R.apply("idx0",RM.makeHandshake(C.index(INP_TYPE,0)),inp)
local tapinp = R.apply("idx1",RM.makeHandshake(C.index(INP_TYPE,1)),inp)
local out = R.apply("idx0",RM.makeHandshake(C.index(INP_TYPE,0)),inpL)
local tapinp = R.apply("idx1",RM.makeHandshake(C.index(INP_TYPE,1)),inpR)

local PadWidth = ConvWidth/2
if PadWidth < internalT then PadWidth = internalT end
Expand Down
17 changes: 9 additions & 8 deletions examples/pyramid_taps_1.lua
@@ -1,10 +1,12 @@
local R = require "rigel"
local RM = require "modules"
local RS = require "rigelSimple"
local types = require("types")
local harness = require "harness"
local C = require "examplescommon"
local P = require "pyramid_core"
local SDFRate = require "sdfrate"
local J = require "common"

internalT = 4 -- internal throughput
outputT = 8
Expand Down Expand Up @@ -36,8 +38,8 @@ local DATA_TYPE = types.array2d(A,8)
local HST = types.tuple{DATA_TYPE,TAP_TYPE}

local inp = R.input( R.Handshake(HST) )
local tapinp = R.apply("idx1",RM.makeHandshake(C.index(HST,1)),inp)
local out = R.apply("idx0",RM.makeHandshake(C.index(HST,0)),inp)
local inpList = J.pack(RS.fanOut{input=inp,branches=1+TARGET_DEPTH})
local out = R.apply("idx0",RM.makeHandshake(C.index(HST,0)),inpList[1])

if internalT<8 then
out = R.apply("CRtop",RM.liftHandshake(RM.changeRate(A,1,8,internalT)), out)
Expand All @@ -57,14 +59,13 @@ local statements = {}


for depth=1,TARGET_DEPTH do
--print("DODEPTH",depth)
--local PI = P.pyramidIter(depth,depth>1,internalT,curW,curH,ConvWidth)

local PI = P.pyramidIterTaps( depth, depth>1, internalT, curW, curH, ConvWidth, NOFIFO, true )
--print("PI",PI.inputType,PI.outputType)
--print(PI.sdfInput[1][1],PI.sdfInput[1][2])
--print(PI.sdfOutput[1][1],PI.sdfOutput[1][2])

local piinp = R.apply("CPI"..depth, RM.packTuple({types.array2d(A,internalT),TAP_TYPE}), R.concat("CONVPIPEINP"..depth,{out,tapinp}))
local tapinp = R.apply("idx1_"..tostring(depth),RM.makeHandshake(C.index(HST,1)),inpList[1+depth])

local CCT = R.concat("CONVPIPEINP"..depth,{out,tapinp})
local piinp = R.apply("CPI"..depth, RM.packTuple({types.array2d(A,internalT),TAP_TYPE}), CCT)
out = R.apply("p"..depth, PI, piinp)

local thisW = inputW*inputH/math.pow(4,depth-1)
Expand Down
18 changes: 15 additions & 3 deletions examples/pyramid_tr_1.lua
@@ -1,10 +1,12 @@
local R = require "rigel"
local RM = require "modules"
local RS = require "rigelSimple"
local types = require("types")
local harness = require "harness"
local C = require "examplescommon"
local P = require "pyramid_core"
local SDFRate = require "sdfrate"
local J = require "common"

T = 4 -- throughput
outputT = 8
Expand Down Expand Up @@ -35,14 +37,24 @@ local DATA_TYPE = types.array2d(A,8)
local HST = types.tuple{DATA_TYPE,TAP_TYPE}

local inp = R.input( R.Handshake(HST) )
local inp0, inp1 = RS.fanOut{input=inp,branches=2}

local out = R.apply("idx0", RM.makeHandshake( C.index(HST,0)),inp)
local out = R.apply("idx0", RM.makeHandshake( C.index(HST,0)),inp0)
if T<8 then
out = R.apply("CRtop", RM.liftHandshake( RM.changeRate(A,1,8,T)), out)
end

local tapinp = R.apply("idx1", RM.makeHandshake( C.index(HST,1)),inp)
local totT = 0
local totTT = T
for depth=1,TARGET_DEPTH do
if totTT>1 then totT=totT+1 end
if depth>1 then totTT=totTT/4; end
end

local tapinp = R.apply("idx1", RM.makeHandshake( C.index(HST,1)),inp1)
--print("TOT",totT)
local tapinpL = J.pack(RS.fanOut{input=tapinp, branches=totT})

curT = T
--vecT = T
curW = inputW
Expand All @@ -61,7 +73,7 @@ for depth=1,TARGET_DEPTH do

if curT>1 then
PI = P.pyramidIterTaps(depth,depth>1,curT,curW,curH,ConvWidth,NOFIFO,false)
local piinp = R.apply("CPI"..depth, RM.packTuple({types.array2d(A,curT),TAP_TYPE}), R.concat("CONVPIPEINP"..depth,{out,tapinp}))
local piinp = R.apply("CPI"..depth, RM.packTuple({types.array2d(A,curT),TAP_TYPE}), R.concat("CONVPIPEINP"..depth,{out,tapinpL[depth]}))
out = R.apply("p"..depth, PI, piinp)
else
PI = P.pyramidIterTR(depth,curT,curW,curH,ConvWidth,NOFIFO)
Expand Down
6 changes: 4 additions & 2 deletions examples/sift_core.lua
@@ -1,4 +1,5 @@
local R = require "rigel"
local RS = require "rigelSimple"
local RM = require "modules"
local types = require("types")
local S = require("systolic")
Expand Down Expand Up @@ -258,10 +259,11 @@ local function siftKernel(dxdyType)
local inp_pos = C.fifo( fifos, statements, ITYPE, R.selectStream("i0",inp_broad,0), 1, "p0", true)
local pos = R.apply("p",RM.makeHandshake(C.index(ITYPE,1)), inp_pos)
local pos = C.fifo( fifos, statements, PTYPE, pos, 1024, "posfifo")
local posL, posR = RS.fanOut{input=pos,branches=2}
-- local pos = C.fifo( fifos, statements, PTYPE, pos, 1024, "p0")
local posX = R.apply("px",RM.makeHandshake(C.index(PTYPE,0)),pos)
local posX = R.apply("px",RM.makeHandshake(C.index(PTYPE,0)),posL)
local posX = C.fifo( fifos, statements, posType, posX, 1024, "pxfifo" )
local posY = R.apply("py",RM.makeHandshake(C.index(PTYPE,1)),pos)
local posY = R.apply("py",RM.makeHandshake(C.index(PTYPE,1)),posR)
local posY = C.fifo( fifos, statements, posType, posY, 1024, "pyfifo" )

local inp_dxdy = C.fifo( fifos, statements, ITYPE, R.selectStream("i1",inp_broad,1), 1, "p1", true)
Expand Down
5 changes: 3 additions & 2 deletions examples/sift_core_hw.lua
Expand Up @@ -300,11 +300,12 @@ function sift.siftKernel(dxdyType)
local inp_pos = C.fifo( fifos, statements, ITYPE, R.selectStream("i0",inp_broad,0), 1, "p0", true) -- fifo size can also be 1 (tested in SW)
local pos = R.apply("p",RM.makeHandshake(C.index(ITYPE,1)), inp_pos)
local pos = C.fifo( fifos, statements, PTYPE, pos, 1024, "posfifo")
local pos0, pos1 = RS.fanOut{input=pos,branches=2}

-- local pos = C.fifo( fifos, statements, PTYPE, pos, 1024, "p0")
local posX = R.apply("px",RM.makeHandshake(C.index(PTYPE,0)),pos)
local posX = R.apply("px",RM.makeHandshake(C.index(PTYPE,0)),pos0)
local posX = C.fifo( fifos, statements, posType, posX, 1024, "pxfifo" )
local posY = R.apply("py",RM.makeHandshake(C.index(PTYPE,1)),pos)
local posY = R.apply("py",RM.makeHandshake(C.index(PTYPE,1)),pos1)
local posY = C.fifo( fifos, statements, posType, posY, 1024, "pyfifo" )

local inp_dxdy = C.fifo( fifos, statements, ITYPE, R.selectStream("i1",inp_broad,1), 1, "p1", true) -- fifo size can also be 1 (tested in SW)
Expand Down
10 changes: 7 additions & 3 deletions rigel.lua
Expand Up @@ -117,7 +117,9 @@ function darkroom.hasReady(a)
elseif darkroom.isRV(a) then return true
elseif a:isTuple() and darkroom.isHandshake(a.list[1]) then
return true
elseif darkroom.isHandshakeArray(a) then
elseif a:isArray() and darkroom.isHandshake(a:arrayOver()) then
return true
elseif darkroom.isHandshakeArray(a) or darkroom.isHandshakeTmuxed(a) then
return true
elseif darkroom.isBasic(a) or darkroom.isV(a) then
return false
Expand Down Expand Up @@ -150,7 +152,9 @@ function darkroom.extractValid(a)
end

function darkroom.streamCount(A)
if darkroom.isHandshake(A) then
if darkroom.isBasic(A) or darkroom.isV(A) or darkroom.isRV(A) then
return 0
elseif darkroom.isHandshake(A) then
return 1
elseif A:isArray() and darkroom.isHandshake(A:arrayOver()) then
return A:channels()
Expand All @@ -159,7 +163,7 @@ function darkroom.streamCount(A)
elseif darkroom.isHandshakeTmuxed(A) or darkroom.isHandshakeArray(A) then
return A.params.N
else
return 0
err(false, "NYI streamCount "..tostring(A))
end
end

Expand Down
2 changes: 1 addition & 1 deletion src/fixed.lua
Expand Up @@ -29,7 +29,7 @@ function fixed.isFixedType(ty)
end

function fixed.expectFixed(ty)
err( fixed.isFixedType(ty), "Expected fixed point type")
err( fixed.isFixedType(ty), "Expected fixed point type but was "..tostring(ty))
end

function fixed.extract(ty)
Expand Down

0 comments on commit 1707f85

Please sign in to comment.