Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Globals #91

Merged
merged 9 commits into from
Dec 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Rigel has two optional dependencies: Verilator and Terra. Verilator can be insta

Which runs the pointwise example verilog through Verilator and produces an output image.

Optionally installing terra enables our fast Terra simulator. You can download the Terra binary files on https://github.com/zdevito/terra/releases (tested with release-2016-02-26) or build it. You can clone the repository and build Terra using the instructions in the [Terra Readme](https://github.com/zdevito/terra). Run the REPL and make sure it installed correctly. The terra simulator can then be run similarly to Verilator:
Optionally installing terra enables our fast Terra simulator. You can download the Terra binary files on https://github.com/zdevito/terra/releases (tested with release-2016-03-25) or build it. You can clone the repository and build Terra using the instructions in the [Terra Readme](https://github.com/zdevito/terra). Run the REPL and make sure it installed correctly. The terra simulator can then be run similarly to Verilator:

cd [rigel root]/examples
make out/pointwise_wide_handshake.terra.bmp
Expand Down
40 changes: 16 additions & 24 deletions examples/conv_wide_handshake_taps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ local S = require("systolic")
local harness = require("harness")
local C = require "examplescommon"
require "common".export()
local soc = require "soc"

R.SDF=false -- for taps

T = 8 -- throughput
--ConvRadius = 1
Expand All @@ -22,51 +25,40 @@ inputH = 64
W = inputW
H = inputH

-------------
--sinp = S.parameter( "inp", types.tuple {types.uint(8),types.uint(8):makeConst()} )
--partial = RM.lift( "partial", types.tuple {types.uint(8),types.uint(8):makeConst()}, types.int(32), 1,
-- terra( a : &tuple(uint8,uint8), out : &int32 )
-- @out = [int32](a._0)*[int32](a._1)
-- end, sinp, S.cast(S.index(sinp,0),types.int(32))*S.cast(S.index(sinp,1),types.int(32)) )
local partial = C.multiply(types.uint(8),types.uint(8),types.int(32))
-------------
--touint8inp = S.parameter("inp", types.int(32))
--touint8 = RM.lift( "touint8", types.int(32), types.uint(8), 1, terra( a : &int32, out : &uint8 ) @out = [uint8](@a >> 8) end, touint8inp, S.cast(S.rshift(touint8inp,S.constant(8,types.int(32))), types.uint(8)) )
local touint8 = C.shiftAndCast(types.int(32),types.uint(8),8)
-------------
--rsinp = S.parameter( "inp", types.tuple { types.int(32), types.int(32) } )
--reduceSumInt32 = RM.lift( "reduceSumInt32", types.tuple { types.int(32), types.int(32) }, types.int(32), 1, terra( inp : &tuple(int32,int32), out : &int32 ) @out = inp._0 + inp._1 end, rsinp, S.index(rsinp,0)+S.index(rsinp,1) )
local reduceSumInt32 = C.sum(types.int(32),types.int(32),types.int(32))
-------------
local STTYPE = types.array2d( types.uint(8), ConvWidth, ConvWidth )
local ITYPE = types.tuple{STTYPE,STTYPE:makeConst()}

local tapValue = range(ConvArea)

soc.taps = R.newGlobal("taps","input",STTYPE,tapValue)

local ITYPE = STTYPE
inp = R.input( ITYPE )
packed = R.apply( "packedtup", C.SoAtoAoS(ConvWidth,ConvWidth,{types.uint(8),types.uint(8):makeConst()}), inp )
local tapv = R.readGlobal("tg",soc.taps)
packed = R.apply( "packedtup", C.SoAtoAoS(ConvWidth,ConvWidth,{types.uint(8),types.uint(8)}), R.concat("tc",{inp,tapv}) )
conv = R.apply( "partial", RM.map( partial, ConvWidth, ConvWidth ), packed )
conv = R.apply( "sum", RM.reduce( reduceSumInt32, ConvWidth, ConvWidth ), conv )
conv = R.apply( "touint8", touint8, conv )

convolve = RM.lambda( "convolve", inp, conv )
-------------
BASE_TYPE = types.array2d( types.uint(8), T )
ITYPE = types.tuple{BASE_TYPE,STTYPE:makeConst()}
ITYPE = BASE_TYPE
inp = R.input( ITYPE )

local inpdata = R.apply( "i0", C.index(ITYPE,0), inp)
local inptaps = R.apply("idx1",C.index(ITYPE,1), inp)
local st_tap_inp = R.apply( "broad", C.broadcast(STTYPE:makeConst(),T), inptaps )

convLB = R.apply( "convLB", C.stencilLinebuffer( types.uint(8), W,H, T, -ConvWidth+1, 0, -ConvWidth+1, 0 ), inpdata)
convLB = R.apply( "convLB", C.stencilLinebuffer( types.uint(8), W,H, T, -ConvWidth+1, 0, -ConvWidth+1, 0 ), inp)
convstencils = R.apply( "convstencils", C.unpackStencil( types.uint(8), ConvWidth, ConvWidth, T ), convLB )

st_tap_inp = R.apply("ST",C.SoAtoAoS(T,1,{STTYPE,STTYPE:makeConst()}), R.concat("Sttap", {convstencils,st_tap_inp}))
convpipe = R.apply( "conv", RM.map( convolve, T ), st_tap_inp )
convpipe = R.apply( "conv", RM.map( convolve, T ), convstencils )
convpipe = R.apply( "border", C.borderSeq( types.uint(8), inputW, inputH, T, ConvWidth-1, 0, ConvWidth-1, 0, 0 ), convpipe ) -- cut off junk

convpipe = RM.lambda( "convpipe", inp, convpipe )
-------------
hsfn = RM.makeHandshake(convpipe)

local tapValue = range(ConvArea)

harness{ outFile="conv_wide_handshake_taps", fn=hsfn, inFile="frame_128.raw", tapType=STTYPE:makeConst(), tapValue=tapValue, inSize={inputW,inputH}, outSize={inputW,inputH} }

harness{ outFile="conv_wide_handshake_taps", fn=hsfn, inFile="frame_128.raw", tapType=STTYPE, tapValue=tapValue, inSize={inputW,inputH}, outSize={inputW,inputH} }
26 changes: 18 additions & 8 deletions examples/convpadcrop_wide_handshake_4_1.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ local S = require("systolic")
local harness = require "harness"
local C = require "examplescommon"
local J = require "common"
local soc = require "soc"

--T = 8 -- throughput
function MAKE(T,ConvWidth,size1080p,NOSTALL)
Expand Down Expand Up @@ -40,20 +41,21 @@ function MAKE(T,ConvWidth,size1080p,NOSTALL)
local outputW = inputW
local outputH = inputH

local TAP_TYPE = types.array2d( types.uint(8), ConvWidth, ConvWidth ):makeConst()
local TAP_TYPE = types.array2d( types.uint(8), ConvWidth, ConvWidth )
soc.taps = R.newGlobal("taps","input",TAP_TYPE,J.range(ConvWidth*ConvWidth))
-------------
-------------
local convKernel = C.convolveTaps( types.uint(8), ConvWidth, J.sel(ConvWidth==4,7,11))
local kernel = C.stencilKernelTaps( types.uint(8), T, TAP_TYPE, internalW, internalH, ConvWidth, ConvWidth, convKernel)
-------------
local BASE_TYPE = types.array2d( types.uint(8), T )
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 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 HST = types.tuple{RW_TYPE,TAP_TYPE}
local hsfninp_raw = R.input( R.Handshake(RW_TYPE) )
--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_raw

local out = R.apply("reducerate", RM.liftHandshake(RM.changeRate(types.uint(8),1,8,T)), out )

Expand All @@ -64,8 +66,16 @@ function MAKE(T,ConvWidth,size1080p,NOSTALL)
-- table.insert( statements, R.applyMethod( "s_clk", fifos[#fifos], "store", out ) )
-- out = R.applyMethod("r_clk",fifos[#fifos],"load")
-- end

-- TAPS REGRESSION
local out0, out1 = RS.fanOut{input=out,branches=2}
out0 = R.apply("out0fifo",C.fifo(BASE_TYPE,128),out0)
out1 = R.apply("out1fifo",C.fifo(BASE_TYPE,128),out1)

local trig = R.apply("trig", RM.makeHandshake(C.valueToTrigger(BASE_TYPE),nil,true), out0)
local tapinp = R.apply("RT", RM.makeHandshake(C.readTap(soc.taps),nil,true), trig)

local convpipeinp = R.apply("CPI", RM.packTuple({BASE_TYPE,TAP_TYPE}), R.concat("CONVPIPEINP",{out,hsfn_taps}))
local convpipeinp = R.apply("CPI", RM.packTuple({BASE_TYPE,TAP_TYPE}), R.concat("CONVPIPEINP",{out1,tapinp}))

local out = R.apply("HH",RM.makeHandshake(kernel), convpipeinp)

Expand Down
37 changes: 13 additions & 24 deletions examples/edge.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ local S = require("systolic")
local harness = require "harness"
local C = require "examplescommon"
local f = require "fixed"
local soc = require "soc"


local edgeTerra={}
if terralib~=nil then edgeTerra=require("edge_terra") end
Expand All @@ -18,7 +20,10 @@ T = 2

ITYPE = types.array2d( types.uint(8), 8 )
OTYPE = types.array2d( types.array2d(types.uint(8),4), 2 )
local TTYPE = types.array2d( types.uint(32), 4 ):makeConst()
--local TTYPE = types.array2d( types.uint(32), 4 ):makeConst()
local TTYPE = types.uint(32)
local TAPVALUE =10
soc.taps = R.newGlobal("taps","input",TTYPE,TAPVALUE)

TAPS = false

Expand Down Expand Up @@ -56,7 +61,7 @@ local nms = RM.lift("nms", types.array2d(ty,3,3),ty,10,

--------------
local function makeThresh()
local inptype = types.tuple{types.uint(8),types.uint(32):makeConst()}
local inptype = types.tuple{types.uint(8),types.uint(32)}

local thfn = RM.lift("thfn", inptype, types.array2d(types.uint(8),4),10,
function(inp)
Expand All @@ -66,7 +71,7 @@ local function makeThresh()
local c_zero = S.constant({0,0,0,0},types.array2d(types.uint(8),4))
return S.select(S.gt(inpData,inpTap), c_one, c_zero )
end,
function() return edgeTerra.thresh end)
function() return edgeTerra.thresh end)

if TAPS==false then
local THRESH=10
Expand All @@ -88,46 +93,30 @@ local edgefn = C.stencilKernelPadcrop( types.uint(8), W,H,T,1,1,1,1,0,edge,false
local nmsfn = C.stencilKernelPadcrop( types.uint(8), W,H,T,1,1,1,1,0,nms,false)

local FNTYPE
if TAPS then
FNTYPE = types.tuple{ITYPE,TTYPE}
else
FNTYPE = ITYPE
end
FNTYPE = ITYPE

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)), 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
out = inp
-- inptaps = R.constant( "idx1", 10, types.uint(32) )
-- inptaps = R.apply("IIT", C.broadcast(types.uint(32),2), inptaps)
end
out = inp

local out = R.apply("incrate", RM.liftHandshake(RM.changeRate(types.uint(8),1,8,2)), out )
local out = R.apply("bf",blurfn,out)
local out = R.apply("ef",edgefn,out)

if TAPS then
out = R.apply("oack",C.SoAtoAoSHandshake(2,1,{types.uint(8),types.uint(32):makeConst()}),R.concat("RT",{out,inptaps}))
out = R.apply("oack",RM.makeHandshake(C.packTapBroad(types.array2d(types.uint(8),T),TTYPE,soc.taps,T)),out)
out = R.apply("SOS",RM.makeHandshake(RM.SoAtoAoS(2,1,{types.uint(8),TTYPE})),out)
end

local out = R.apply("nf",thfn,out)

local hsfn = RM.lambda("hsfn",inp,out)

if TAPS then
harness{ outFile="edge_taps", fn=hsfn, inFile="ov7660_1chan.raw", tapType=TTYPE, tapValue={10,0,0,0}, inSize={W,H}, outSize={W,H} }
harness{ outFile="edge_taps", fn=hsfn, inFile="ov7660_1chan.raw", tapType=TTYPE, tapValue=TAPVALUE, inSize={W,H}, outSize={W,H} }
else
harness{ outFile="edge", fn=hsfn, inFile="ov7660_1chan.raw", inSize={W,H}, outSize={W,H} }
end
48 changes: 44 additions & 4 deletions examples/examplescommon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,41 @@ C.eq = memoize(function(ty)
return selm
end)

-----------------------------
C.readTap = memoize(function(global)
local G = {}
G[global]=1
local out = RM.lift( "ReadTap_"..global.name, types.null(), global.type, 0,
function(sinp) return S.readSideChannel(global.systolicValue) end, nil, "C.readTap",nil,G)
return out
end)

-----------------------------
C.valueToTrigger = memoize(function(ty)
return RM.lift( "ValueToTrigger_"..tostring(ty), ty, types.null(), 0,
function(sinp) end, nil,"C.valueToTrigger")
end)

-----------------------------
C.packTap = memoize(function(A,ty,global)
return RM.lift( "PackTap_"..tostring(A).."_"..tostring(ty), A, types.tuple{A,ty}, 0,
function(sinp) return S.tuple{sinp,S.readSideChannel(global.systolicValue)} end, nil,"C.packTap")
end)

-----------------------------
C.packTapBroad = memoize(function(A,ty,global,N)
assert(types.isType(A))
assert(types.isType(ty))
assert(type(N)=="number")
assert(rigel.isGlobal(global))

local tt = types.array2d(ty,N)
local G = {}
G[global]=1
return RM.lift( "PackTap_"..tostring(A).."_"..tostring(ty), A, types.tuple{A,types.array2d(ty,N)}, 0,
function(sinp) return S.tuple{sinp,S.cast(S.tuple(J.broadcast(S.readSideChannel(global.systolicValue),N)),tt)} end, nil,"C.packTap",nil,G)
end)

-----------------------------
C.rcp = memoize(function(ty)
err(types.isType(ty), "C.rcp error: input must be type")
Expand Down Expand Up @@ -273,13 +308,16 @@ C.convolveTaps = memoize(function( A, ConvWidth, shift )
if shift==nil then shift=7 end

local TAP_TYPE = types.array2d( A, ConvWidth, ConvWidth )
local TAP_TYPE_CONST = TAP_TYPE:makeConst()
--- local TAP_TYPE_CONST = TAP_TYPE:makeConst() XXX
local TAP_TYPE_CONST = TAP_TYPE

local INP_TYPE = types.tuple{types.array2d( A, ConvWidth, ConvWidth ),TAP_TYPE_CONST}
local inp = R.input( INP_TYPE )

local packed = R.apply( "packedtup", C.SoAtoAoS(ConvWidth,ConvWidth,{A,A:makeConst()}), inp )
local conv = R.apply( "partial", RM.map( C.multiply(A,A:makeConst(), types.uint(32)), ConvWidth, ConvWidth ), packed )
--- local packed = R.apply( "packedtup", C.SoAtoAoS(ConvWidth,ConvWidth,{A,A:makeConst()}), inp ) XXX
local packed = R.apply( "packedtup", C.SoAtoAoS(ConvWidth,ConvWidth,{A,A}), inp )
--- local conv = R.apply( "partial", RM.map( C.multiply(A,A:makeConst(), types.uint(32)), ConvWidth, ConvWidth ), packed ) XXX
local conv = R.apply( "partial", RM.map( C.multiply(A,A, types.uint(32)), ConvWidth, ConvWidth ), packed )
local conv = R.apply( "sum", RM.reduce( C.sum(types.uint(32),types.uint(32),types.uint(32)), ConvWidth, ConvWidth ), conv )
local conv = R.apply( "touint8", C.shiftAndCast(types.uint(32),A,shift), conv )

Expand Down Expand Up @@ -678,7 +716,9 @@ C.fifo = memoize(function(ty,size,X)

local inp = R.input(R.Handshake(ty))
local regs = {R.instantiateRegistered("f1",RM.fifo(ty,size))}
return RM.lambda("C_FIFO_"..tostring(ty).."_size"..tostring(size), inp, R.statements{R.applyMethod("l1",regs[1],"load"),R.applyMethod("s1",regs[1],"store",inp)}, regs, "C.fifo", {size=size} )
local st = R.applyMethod("s1",regs[1],"store",inp)
local ld = R.applyMethod("l1",regs[1],"load")
return RM.lambda("C_FIFO_"..tostring(ty).."_size"..tostring(size), inp, R.statements{ld,st}, regs, "C.fifo", {size=size} )
end)

-------------
Expand Down
Loading