Skip to content

Commit

Permalink
Soc travis (#112)
Browse files Browse the repository at this point in the history
* SOC backend (incl 2x DMA) working in verilator and zu9
  • Loading branch information
jameshegarty committed Apr 10, 2018
1 parent f4e147d commit 01b881e
Show file tree
Hide file tree
Showing 31 changed files with 907 additions and 459 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -40,6 +40,7 @@ script:
env:
- TARGET=verilog
- TARGET=verilator
- TARGET=verilatorSOC
- TARGET=terra
- TARGET=unit
- TARGET=coverage
Expand Down
Binary file added examples/frame_128_inv.raw
Binary file not shown.
Binary file added examples/gold/soc_2in.bmp
Binary file not shown.
Binary file added examples/gold/soc_simple.bmp
Binary file not shown.
29 changes: 0 additions & 29 deletions examples/harnessLL.lua

This file was deleted.

48 changes: 48 additions & 0 deletions examples/harnessSOC.lua
@@ -0,0 +1,48 @@
local R = require "rigel"
local C = require "examplescommon"
local SOC = require "soc"
local J = require "common"

return function(fn,t)
if R.isFunction(fn)==false then
fn = C.linearPipeline(fn,"Top")
else
J.err(fn.name=="Top","Top module must be called 'Top', but is "..fn.name)
end

local backend
if t~=nil then backend = t.backend end
if backend==nil then backend = arg[1] end
if backend==nil then backend = "verilog" end

local filename = string.gsub(arg[0],".lua","") --arg[0]
print("FILENAME",filename)

if backend=="verilog" or backend=="verilator" then
io.output("out/"..filename..".v")
io.write(fn:toVerilog())
io.output():close()
elseif backend=="metadata" then
local f = io.open("out/"..filename..".metadata.lua","w")

local inputList = {}
for i=0,SOC.ports do
if fn.globalMetadata["MAXI"..i.."_read_filename"]~=nil then
table.insert(inputList,"{filename='"..fn.globalMetadata["MAXI"..i.."_read_filename"].."',W="..fn.globalMetadata["MAXI"..i.."_read_W"]..",H="..fn.globalMetadata["MAXI"..i.."_read_H"]..",bitsPerPixel="..fn.globalMetadata["MAXI"..i.."_read_bitsPerPixel"]..",V="..fn.globalMetadata["MAXI"..i.."_read_V"]..",address=0x"..string.format("%x",fn.globalMetadata["MAXI"..i.."_read_address"]).."}")
end
end

local outputList = {}
for i=0,SOC.ports do
if fn.globalMetadata["MAXI"..i.."_write_filename"]~=nil then
table.insert(outputList,"{filename='"..fn.globalMetadata["MAXI"..i.."_write_filename"].."',W="..fn.globalMetadata["MAXI"..i.."_write_W"]..",H="..fn.globalMetadata["MAXI"..i.."_write_H"]..",bitsPerPixel="..fn.globalMetadata["MAXI"..i.."_write_bitsPerPixel"]..",V="..fn.globalMetadata["MAXI"..i.."_write_V"]..",address=0x"..string.format("%x",fn.globalMetadata["MAXI"..i.."_write_address"]).."}")
end
end

f:write( "return {inputs={"..table.concat(inputList,",").."},outputs={"..table.concat(outputList,",").."},topModule='"..fn.name.."',memoryStart=0x30008000,memoryEnd=0x"..string.format("%x",SOC.currentAddr).."}" )
f:close()
else
print("backend",backend)
assert(false)
end
end
14 changes: 9 additions & 5 deletions examples/lk_tr_core.lua
Expand Up @@ -158,15 +158,17 @@ function makeA( T, dType, window, bits )
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 FdxB = R.apply("fdxB", RM.broadcastStream(stt,3),Fdx)
local Fdx0 = R.selectStream("fdx0",FdxB,0)
local Fdx1 = R.selectStream("fdx1",FdxB,1)
local Fdx2 = R.selectStream("fdx2",FdxB,2)

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 FdyB = R.apply("fdyB", RM.broadcastStream(stt,3),Fdy)
local Fdy0 = R.selectStream("fdy0",FdyB,0)
local Fdy1 = R.selectStream("fdy1",FdyB,1)
local Fdy2 = R.selectStream("fdy2",FdyB,2)

local partial = makePartial( dType, dType, bits.Apartial[1], bits.Apartial[2] )
bits.Apartial[3] = partial[3]
Expand All @@ -177,7 +179,7 @@ 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",{Fdx0,Fdx0}) )
local inp0 = R.apply("inp0", C.SoAtoAoSHandshake(window*T,window,{dType,dType}), R.concat("o0",{Fdx0,Fdx2}) )
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 )
Expand All @@ -187,9 +189,11 @@ function makeA( T, dType, window, bits )
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 out1B = R.apply("out1B", RM.broadcastStream(R.extractData(out1.type),2),out1)
out1 = R.selectStream("out1B1",out1B,0)
local out2 = R.selectStream("out1B2",out1B,1)

local inp3 = R.apply("inp3", C.SoAtoAoSHandshake(window*T,window,{dType,dType}), R.concat("o3",{Fdy1,Fdy1}) )
local inp3 = R.apply("inp3", C.SoAtoAoSHandshake(window*T,window,{dType,dType}), R.concat("o3",{Fdy1,Fdy2}) )
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 Down
13 changes: 12 additions & 1 deletion examples/makefile
@@ -1,7 +1,14 @@
BUILDDIR ?= out

SRCS_SOC = soc_simple.lua soc_2in.lua

VERILATOR_SOC = $(patsubst %.lua,$(BUILDDIR)/%.verilatorSOC.bit,$(SRCS_SOC))
VERILATOR_SOC = $(patsubst %.lua,$(BUILDDIR)/%.verilatorSOC.raw,$(SRCS_SOC))
VERILATOR_SOC = $(patsubst %.lua,$(BUILDDIR)/%.verilatorSOC.bmp,$(SRCS_SOC))
VERILATOR_SOC = $(patsubst %.lua,$(BUILDDIR)/%.verilatorSOC.correct.txt,$(SRCS_SOC))

SRCS = $(wildcard *.lua)
SRCS := $(filter-out harness.lua examplescommon.lua pyramid_core.lua harris_core.lua sift_core.lua sift_core_hw.lua campipe_core.lua descriptor_core.lua stereo_core.lua stereo_tr_core.lua lk_core.lua lk_tr_core.lua soc_simple.lua harnessLL.lua,$(SRCS))
SRCS := $(filter-out harness.lua examplescommon.lua pyramid_core.lua harris_core.lua sift_core.lua sift_core_hw.lua campipe_core.lua descriptor_core.lua stereo_core.lua stereo_tr_core.lua lk_core.lua lk_tr_core.lua $(SRCS_SOC) harnessSOC.lua,$(SRCS))
METADATA = $(patsubst %.lua,$(BUILDDIR)/%.metadata.lua,$(SRCS))

RIGEL_VERILATOR_INCLUDE ?= $(shell pkg-config --variable=includedir verilator)
Expand Down Expand Up @@ -221,6 +228,10 @@ verilator: $(VERILATOR)
touch $(BUILDDIR)/verilator_done.txt
date

verilatorSOC: $(VERILATOR_SOC)
touch $(BUILDDIR)/verilatorSOC_done.txt
date

isim: $(ISIM)

stats: $(STATS)
Expand Down
23 changes: 23 additions & 0 deletions examples/soc_2in.lua
@@ -0,0 +1,23 @@
local R = require "rigel"
local SOC = require "soc"
local C = require "examplescommon"
local harness = require "harnessSOC"
local RS = require "rigelSimple"
local RM = require "modules"
require "types".export()

local inp = R.input(R.HandshakeTrigger)
local inp0, inp1 = RS.fanOut{input=inp,branches=2}
local a = SOC.readBurst("frame_128.raw",128,64,u(8),8)(inp0)
--a = C.fifo(b(64),1024)(a)
a = RS.HS(C.cast(b(64),ar(u(8),8)))(a)
local bb = SOC.readBurst("frame_128_inv.raw",128,64,u(8),8)(inp1)
--bb = C.fifo(b(64),1024)(bb)
bb = RS.HS(C.cast(b(64),ar(u(8),8)))(bb)
local out = RS.fanIn{a,bb}
out = RS.HS(RM.SoAtoAoS(8,1,{u(8),u(8)}))(out)
out = RS.HS(RM.map(C.sum(u(8),u(8),u(8)),8))(out)
out = RS.HS(C.cast(ar(u(8),8),b(64)))(out)
out = SOC.writeBurst("out/soc_2in",128,64,u(8),8)(out)

harness(RM.lambda("Top",inp,out))
10 changes: 7 additions & 3 deletions examples/soc_simple.lua
@@ -1,9 +1,13 @@
local R = require "rigel"
local SOC = require "soc"
local C = require "examplescommon"
local harness = require "harnessLL"
local harness = require "harnessSOC"
local RS = require "rigelSimple"
require "types".export()

print(i,u,b)
harness{SOC.axiBurstReadN("frame_128.raw",(128*64)/8,0), RS.HS(C.cast(b(64),u(64))), RS.HS(C.plus100(u(64))), RS.HS(C.cast(u(64),b(64))), SOC.axiBurstWriteN("out/soc_simple",(128*64)/8,0)}
harness{
SOC.readBurst("frame_128.raw",128,64,u(8),8),
RS.HS(C.cast(b(64),u(64))),
RS.HS(C.plus100(u(64))),
RS.HS(C.cast(u(64),b(64))),
SOC.writeBurst("out/soc_simple",128,64,u(8),8)}
37 changes: 36 additions & 1 deletion misc/extractMetadata.lua
@@ -1,6 +1,41 @@
local metadata = dofile(arg[1])

if arg[2]=="INPUT_FILES" then
function basename(fn)
local a,b,c = string.match(fn, "(.-)([^\\/]-%.?([^%.\\/]*))$")
return b
end

if arg[2]=="memoryStart" or arg[2]=="memoryEnd" then
print(string.format("%x",metadata[arg[2]]))
elseif arg[2]=="__INPUT_HOST_FILES" or arg[2]=="__INPUT_DEVICE_FILES" then
local str = ""
for _,v in ipairs(metadata.inputs) do
if arg[2]=="__INPUT_HOST_FILES" then
str = str..v.filename.." "
else
str = str..basename(v.filename).." "
end
end
print(str)
elseif arg[2]=="__INPUTS" or arg[2]=="__INPUTS_ZYNQ" then
-- special case for SOC
local str = ""
for _,v in ipairs(metadata.inputs) do
local fn = v.filename
if arg[2]=="__INPUTS_ZYNQ" then fn=basename(fn) end
str = str..fn.." 0x"..string.format("%x",v.address).." "
end
print(str)
elseif arg[2]=="__OUTPUTS" or arg[2]=="__OUTPUTS_ZYNQ" then
-- special case for SOC
local str = ""
for _,v in ipairs(metadata.outputs) do
local fn = v.filename
if arg[2]=="__OUTPUTS_ZYNQ" then fn=basename(fn) end
str = str..fn.." 0x"..string.format("%x",v.address).." "..v.W.." "..v.H.." "..v.bitsPerPixel.." "
end
print(str)
elseif arg[2]=="INPUT_FILES" then
local i=1
local str = ""
while metadata["inputFile"..i] do
Expand Down
6 changes: 6 additions & 0 deletions misc/raw2bmp.lua
Expand Up @@ -5,6 +5,12 @@ ffi = require "ffi"

local metadata = dofile(arg[3])

if type(metadata.outputs)=="table" then
-- special case: SOC
metadata.outputBitsPerPixel = metadata.outputs[1].bitsPerPixel
metadata.outputWidth = metadata.outputs[1].W
metadata.outputHeight = metadata.outputs[1].H
end

ffi.cdef[[
typedef struct {} FILE;
Expand Down

0 comments on commit 01b881e

Please sign in to comment.