Permalink
Browse files

Generators + Terra SOC Harness + Register slave (#114)

  • Loading branch information...
jameshegarty committed Jun 15, 2018
1 parent 0604265 commit b8ea53d58d04830a27b5e8aa9c72e78ce6bf0e82
Showing with 3,292 additions and 848 deletions.
  1. +40 −0 examples/convgen.lua
  2. +147 −2 examples/examplescommon.lua
  3. +88 −3 examples/examplescommonTerra.t
  4. +1 −0 examples/gold/convgen.bmp
  5. +1 −0 examples/gold/soc_flip.bmp
  6. BIN examples/gold/soc_simple.bmp
  7. BIN examples/gold/soc_simple.bmp
  8. +26 −4 examples/harnessSOC.lua
  9. +2 −2 examples/harnessTerra.t
  10. +292 −0 examples/harnessTerraSOC.t
  11. +6 −4 examples/makefile
  12. +1 −1 examples/nilhandshake.lua
  13. +1 −1 examples/nullary.lua
  14. +1 −1 examples/readmemory.lua
  15. +1 −1 examples/readmemory_flip.lua
  16. +7 −4 examples/soc_2in.lua
  17. +27 −0 examples/soc_flip.lua
  18. +8 −4 examples/soc_simple.lua
  19. +1 −1 examples/triggeredCounter.lua
  20. 0 {src → misc}/fixed.lua
  21. 0 {src → misc}/fixed_float.lua
  22. 0 {src → misc}/fixed_float_terra.t
  23. 0 {src → misc}/fixed_new.lua
  24. 0 {src → misc}/fixed_new_terra.t
  25. 0 {src → misc}/fixed_terra.t
  26. +3 −2 {src → misc}/rigelSimple.lua
  27. 0 {src → misc}/rigelSimpleTerra.t
  28. +3 −2 {src → misc}/rigelhll.lua
  29. 0 {src → misc}/systolic_to_magmair.t
  30. +810 −36 modules/soc.lua
  31. +295 −0 modules/socTerra.t
  32. +1 −1 platform/platform.mk
  33. +1 −1 platform/verilatorSOC/compile
  34. +155 −376 platform/verilatorSOC/harness.cpp
  35. +564 −0 platform/verilatorSOC/harness.h
  36. +14 −67 platform/verilatorSOC/mpsoc_iptop_LL.sv
  37. +2 −1 platform/verilatorSOC/run
  38. +35 −31 platform/verilatorSOC/verilator_wrapper.sv
  39. +1 −1 platform/zu9vivadoSOC/compile
  40. +0 −125 platform/zu9vivadoSOC/mpsoc_iptop_LL.sv
  41. +39 −46 platform/zu9vivadoSOC/mpsoc_top_LL.sv
  42. BIN platform/zu9vivadoSOC/processimage_mpsoc_SOC
  43. +2 −1 platform/zu9vivadoSOC/processimage_mpsoc_SOC.c
  44. +294 −26 rigel.lua
  45. +1 −1 rigelLua
  46. +1 −1 rigelTerra
  47. +177 −0 src/generators.lua
  48. +101 −45 src/modules.lua
  49. +88 −22 src/modulesTerra.t
  50. +1 −1 src/sdfrate.lua
  51. +34 −32 src/systolic.lua
  52. +16 −0 src/types.lua
  53. +1 −1 src/typesTerra.t
  54. +1 −0 unittests/makefile
  55. +1 −0 unittests/makefile.compileverilog
  56. +1 −1 unittests/moduleparams.lua
View
@@ -0,0 +1,40 @@
local R = require "rigel"
R.export()
local SOC = require "soc"
local harness = require "harnessSOC"
local RS = require "rigelSimple"
local C = require "examplescommon"
require "generators".export()
require "types".export()
regs = SOC.axiRegsN(4,0):instantiate()
local ConvWidth = 4
local ConvRadius = ConvWidth/2
inSize = { 1920, 1080 }
padSize = { 1920+16, 1080+3 }
local conv = Module{ ar(u(8),ConvWidth,ConvWidth),
function(inp)
inp = Map{AddMSBs{24}}(inp)
local coeff = c{ar(u(32),ConvWidth,ConvWidth),{4, 14, 14, 4,
14, 32, 32, 14,
14, 32, 32, 14,
4, 14, 14, 4}}
local z = Zip(inp,coeff)
local out = Map{Mul}(z)
local res = Reduce{Add}(out)
return RemoveMSBs{24}(Rshift{8}(res))
end}
harness{
regs.start,
SOC.readBurst("1080p.raw",1920,1080,u(8),1),
HS{Pad{inSize,1,{8,8,2,1}}},
-- RS.HS(C.print(ar(u(8),1))),
HS{Linebuffer{padSize,1,{3,0,3,0}}},
HS{Map{conv}},
HS{Crop{padSize,1,{9,7,3,0}}},
SOC.writeBurst("out/convgen",1920,1080,u(8),1),
regs.done}
View
@@ -19,16 +19,60 @@ C.identity = memoize(function(A)
return identity
end)
C.print = memoize(function(A)
local identity = RM.lift( "print_"..J.verilogSanitize(tostring(A)), A, A, 0, function(sinp) return sinp end, function() return CT.print(A) end, "C.print")
return identity
end)
C.cast = memoize(function(A,B)
err(types.isType(A),"cast: A should be type")
err(types.isType(B),"cast: B should be type")
err( R.isBasic(A), "cast: A should be basic type. casting "..tostring(A).." to "..tostring(B) )
err( R.isBasic(B), "cast: B should be basic type. casting "..tostring(A).." to "..tostring(B) )
assert(A:isTuple()==false) -- not supported by terra
if terralib~=nil then
err(A:isTuple()==false, "C.cast: NYI - terra cast from '"..tostring(A).."' to '"..tostring(B).."'") -- not supported by terra
end
local docast = RM.lift( J.sanitize("cast_"..tostring(A).."_"..tostring(B)), A, B, 0, function(sinp) return S.cast(sinp,B) end, function() return CT.cast(A,B) end, "C.cast" )
return docast
end)
C.bitcast = memoize(function(A,B)
err(types.isType(A),"cast: A should be type")
err(types.isType(B),"cast: B should be type")
err( R.isBasic(A), "cast: A should be basic type. casting "..tostring(A).." to "..tostring(B) )
err( R.isBasic(B), "cast: B should be basic type. casting "..tostring(A).." to "..tostring(B) )
err(A:verilogBits()==B:verilogBits(), "TYPE SIZE NOT EQ: "..tostring(A).." - "..tostring(B))
local docast = RM.lift( J.sanitize("bitcast_"..tostring(A).."_"..tostring(B)), A, B, 0,
function(sinp)
local tmp = S.cast(sinp,types.bits(A:verilogBits()))
return S.cast(tmp,B)
end,
function() return CT.bitcast(A,B) end, "C.cast" )
return docast
end)
-- takes bits(N)[M] to bits(N*M)
C.flattenBits = memoize(function(ty)
if ty:isArray() and ty:arrayOver():isBits() then
return RM.lift( J.sanitize("FlattenBits_"..tostring(ty)), ty, types.bits(ty:verilogBits()), 0, function(sinp) return S.cast(sinp,types.bits(ty:verilogBits())) end, function() assert(false) end, "C.flattenBits" )
else
J.err( "NYI - flattenBits of type "..tostring(ty) )
end
end)
-- takes bits(N*M) to bits(M)[N]
C.partitionBits = memoize(function(ty, N)
J.err( type(N)=="number", "C.partitionBits: N must be number")
J.err( ty:verilogBits()%N==0, "C.partitionBits: N must device type bits")
if ty:isBits() then
local otype = types.array2d(types.bits(ty:verilogBits()/N),N)
return RM.lift( J.sanitize("PartitionBits_"..tostring(ty).."_"..tostring(N)), ty, otype, 0, function(sinp) return S.cast(sinp,otype) end, function() assert(false) end, "C.partitionBits" )
else
J.err( "NYI - partitionBits of type "..tostring(ty) )
end
end)
-- takes {T[N/2],T[N/2]} to T[N]
C.flatten2 = memoize(function(T,N)
err(types.isType(T),"cast: T should be type")
@@ -68,6 +112,33 @@ C.multiply = memoize(function(A,B,outputType)
return partial
end)
------------
-- return A*B as a darkroom FN. A,B are types
-- returns something of type outputType
C.multiplyConst = memoize(function(A,constValue)
err( types.isType(A), "C.multiply: A must be type")
local partial = RM.lift( J.sanitize("mult_const_A"..tostring(A).."_value"..tostring(constValue)), A, A, 1,
function(sinp) return sinp*S.constant(constValue,A) end,
function() return CT.multiplyConst(A,constValue) end,
"C.multiplyConst" )
return partial
end)
C.tokenCounter = memoize(function(A)
err( types.isType(A), "C.multiply: A must be type")
local partial = RM.lift( J.sanitize("tokencounter_A"..tostring(A)), A, A, 1,
function(sinp) assert(false) end,
function() return CT.tokenCounter(A) end,
"C.tokenCounter" )
partial.terraModule = CT.tokenCounter(A)
return partial
end)
------------
-- return A+B as a darkroom FN. A,B are types
-- returns something of type outputType
@@ -122,6 +193,62 @@ C.sub = memoize(function( A, B, outputType, async )
return partial
end)
-----------------------------
C.rshift = memoize(function(A,const)
err( types.isType(A),"C.rshift: type should be rigel type")
err( type(const)=="number" or const==nil,"C.rshift: const should be number or value")
if const~=nil then
-- shift by a const
J.err( A:isUint() or A:isInt(), "generators.Rshift: type should be int or uint, but is: "..tostring(A) )
local mod = RM.lift(J.sanitize("generators_rshift_const"..tostring(const).."_"..tostring(A)), A,nil,nil,
function(inp) return S.rshift(inp,S.constant(const,A)) end)
return mod
else
assert(false)
end
end)
-----------------------------
C.addMSBs = memoize(function(A,bits)
err( types.isType(A),"C.addMSBs: type should be rigel type")
err( type(bits)=="number","C.addMSBs: bits should be number or value")
local otype
if A:isUint() then
otype = types.uint(A.precision+bits)
elseif A:isInt() then
otype = types.int(A.precision+bits)
else
J.err( A:isUint() or A:isInt(), "generators.addMSBs: type should be int or uint, but is: "..tostring(A) )
end
local mod = RM.lift(J.sanitize("generators_addMSBs_"..tostring(bits).."_"..tostring(A)), A,nil,nil,
function(inp) return S.cast(inp,otype) end)
return mod
end)
-----------------------------
C.removeMSBs = memoize(function(A,bits)
err( types.isType(A),"C.removeMSBs: type should be rigel type")
err( type(bits)=="number","C.removeMSBs: bits should be number or value")
local otype
if A:isUint() then
J.err(A.precision>bits,"removeMSBs: can't remove all the bits! attempting to remove "..bits.." bits from "..tostring(A))
otype = types.uint(A.precision-bits)
elseif A:isInt() then
J.err(A.precision>bits,"removeMSBs: can't remove all the bits! attempting to remove "..bits.." bits from "..tostring(A))
otype = types.int(A.precision-bits)
else
J.err( A:isUint() or A:isInt(), "generators.removeMSBs: type should be int or uint, but is: "..tostring(A) )
end
local mod = RM.lift(J.sanitize("generators_removeMSBs_"..tostring(bits).."_"..tostring(A)), A,nil,nil,
function(inp) return S.cast(inp,otype) end)
return mod
end)
-----------------------------
C.select = memoize(function(ty)
err(types.isType(ty), "C.select error: input must be type")
@@ -160,6 +287,24 @@ C.valueToTrigger = memoize(function(ty)
function(sinp) end, nil,"C.valueToTrigger")
end)
-----------------------------
C.triggerToConstant = memoize(function(ty,value)
J.err( types.isType(ty), "C.triggerToConstant: type must be type")
return RM.lift( "TriggerToConstant_"..tostring(ty), types.null(), ty, 0,
function(sinp) return S.constant(value,ty) end, nil,"C.triggerToConstant")
end)
-----------------------------
-- take in 1 trigger, and write out N triggers (aka trigger upsample)
C.triggerUp = memoize(function(N)
J.err(type(N)=="number","triggerUp: input must be number")
local inp = R.input(R.HandshakeTrigger)
local val = RM.makeHandshake( RM.constSeq({0},types.uint(8),1,1,1), nil, true )(inp)
val = RM.upsampleXSeq(types.uint(8),1,N)(val)
val = RM.makeHandshake(C.valueToTrigger(types.array2d(types.uint(8),1)),nil,true)(val)
return RM.lambda("TriggerUp_"..tostring(N), inp,val)
end)
-----------------------------
C.packTap = memoize(function(A,ty,global)
return RM.lift( "PackTap_"..tostring(A).."_"..tostring(ty), A, types.tuple{A,ty}, 0,
@@ -1150,7 +1295,7 @@ function C.linearPipeline(t,modulename)
end
err(type(t)=="table" and J.keycount(t)==#t, "C.linearPipeline: input must be array")
for _,v in ipairs(t) do err(R.isFunction(v), "C.linearPipeline: input must be table of Rigel modules") end
for k,v in ipairs(t) do err(R.isFunction(v), "C.linearPipeline: input must be table of Rigel modules (idx "..k..")") end
local inp = R.input(t[1].inputType)
local out = inp
@@ -1,10 +1,15 @@
local cstdlib = terralib.includec("stdlib.h")
local cstdio = terralib.includec("stdio.h")
local rigel = require "rigel"
local types = require "types"
local J = require "common"
local err = J.err
local MT = require "modulesTerra"
local data = macro(function(i) return `i._0 end)
local valid = macro(function(i) return `i._1 end)
local ready = macro(function(i) return `i._2 end)
CT={}
function CT.identity(A)
@@ -13,12 +18,68 @@ function CT.identity(A)
end
end
function CT.print(A)
local function doprint(A,symb)
assert(symb~=nil)
if A:isArray() then
local tab = {}
table.insert(tab,quote cstdio.printf("[") end)
for i=0,A:channels()-1 do
table.insert(tab,doprint(A:arrayOver(),`symb[i]))
if i~=A:channels()-1 then table.insert(tab,quote cstdio.printf(",") end) end
end
table.insert(tab,quote cstdio.printf("]") end)
return quote [tab] end
elseif A:isTuple() then
local tab = {}
table.insert(tab,quote cstdio.printf("{") end)
for i=1,#A.list do
table.insert(tab,doprint(A.list[i],`symb.["_"..(i-1)]))
if i~=#A.list then table.insert(tab,quote cstdio.printf(",") end) end
end
table.insert(tab,quote cstdio.printf("}") end)
return quote [tab] end
elseif A:isUint() or A:isInt() or A:isBits() then
return quote cstdio.printf("%d",symb) end
else
print(A)
assert(false)
end
end
return terra( a : &A:toTerraType(), out : &A:toTerraType() )
var aa = @a
[doprint(A,aa)]
cstdio.printf("\n")
@out = @a
end
end
function CT.cast(A,B)
err(types.isType(B), "examples common cast, B must be type")
if A:isBits() then
return terra( a : &A:toTerraType(), out : &B:toTerraType() )
@out = @[&B:toTerraType()](a)
end
elseif B:isBits() and A:isArray() and B:verilogBits()==A:verilogBits() then
return terra( a : &A:toTerraType(), out : &B:toTerraType() )
@out = @[&B:toTerraType()](a)
end
else
return terra( a : &A:toTerraType(), out : &B:toTerraType() )
@out = [B:toTerraType()](@a)
end
end
end
function CT.bitcast(A,B)
assert( terralib.sizeof(A:toTerraType()) == terralib.sizeof(B:toTerraType()) )
return terra( a : &A:toTerraType(), out : &B:toTerraType() )
@out = [B:toTerraType()](@a)
end
@out = @[&B:toTerraType()](a)
end
end
function CT.flatten2(T,N)
@@ -50,6 +111,30 @@ function CT.multiply(A,B,outputType)
end
end
function CT.multiplyConst(A,constValue)
return terra( a : &A:toTerraType(), out : &A:toTerraType() )
@out = [A:toTerraType()](@a)*[A:toTerraType()](constValue)
end
end
function CT.tokenCounter(A)
local struct TokenCounter { cnt:uint, ready:bool }
terra TokenCounter:reset() self.cnt=0 end
terra TokenCounter:process( a : &A:toTerraType(), out : &A:toTerraType() )
@out = @a
if valid(a) and self.ready then
self.cnt = self.cnt+1
cstdio.printf("CNT %d\n",self.cnt)
end
end
terra TokenCounter:calculateReady(readyDownstream:bool)
self.ready = readyDownstream
end
return MT.new(TokenCounter)
end
function CT.sum(A,B,outputType,async)
return terra( a : &tuple(A:toTerraType(),B:toTerraType()), out : &outputType:toTerraType() )
@out = [outputType:toTerraType()](a._0)+[outputType:toTerraType()](a._1)
View
Binary file not shown.
Oops, something went wrong.

0 comments on commit b8ea53d

Please sign in to comment.