/
pyramid_taps_1.lua
174 lines (128 loc) · 5.58 KB
/
pyramid_taps_1.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
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"
local soc = require "soc"
--R.SDF=false
internalT = 4 -- internal throughput
outputT = 8
A = types.uint(8)
local LARGE = string.find(arg[0],"large")
LARGE = (LARGE~=nil)
local NOFIFO = string.find(arg[0],"nofifo")
NOFIFO = (NOFIFO~=nil)
local TARGET_DEPTH = string.sub(arg[0],string.find(arg[0],"%d+"))
TARGET_DEPTH = tonumber(TARGET_DEPTH)
local ConvWidth = 8
local inputW = 64
local inputH = 32
-- 64x32 is too small
if TARGET_DEPTH==4 then inputW, inputH = 128,64 end
if LARGE then
inputW, inputH = 384, 384
end
--local TAP_TYPE = types.array2d( types.uint(8), ConvWidth, ConvWidth ):makeConst() XXX
local TAP_TYPE = types.array2d( types.uint(8), ConvWidth, ConvWidth )
--soc.taps = R.newGlobal("taps","input",TAP_TYPE,P.G)
local taps = soc.regStub{taps={TAP_TYPE,P.G}}:instantiate("taps")
taps.extern = true
local DATA_TYPE = types.array2d(A,8)
local HST = DATA_TYPE
local inp = R.input( R.Handshake(HST) )
local out = inp
if internalT<8 then
out = R.apply("CRtop",RM.liftHandshake(RM.changeRate(A,1,8,internalT)), out)
end
curW = inputW
curH = inputH
local L = {}
local SDF = {}
local outputW = 0
local outputH = inputH/math.pow(2,TARGET_DEPTH-1)
local fifos = {}
local statements = {}
for depth=1,TARGET_DEPTH do
local PI = P.pyramidIterTaps( depth, depth>1, internalT, curW, curH, ConvWidth, NOFIFO, true, taps.taps )
-- local out0, out1 = RS.fanOut{input=out,branches=2}
-- TAPS REGRESSION
-- out0 = R.apply("out0fifo"..tostring(depth),C.fifo(types.array2d(A,internalT),64),out0)
-- out1 = R.apply("out1fifo"..tostring(depth),C.fifo(types.array2d(A,internalT),256),out1)
-- local trig = R.apply("trig"..tostring(depth), RM.makeHandshake(C.valueToTrigger(types.array2d(A,internalT)),nil,true), out0)
-- local tapinp = R.apply("RT"..tostring(depth), RM.makeHandshake(C.readTap(soc.taps),nil,true), trig)
-- TAPS REGRESSION
-- tapinp = R.apply("otut0fifo"..tostring(depth),C.fifo(TAP_TYPE,128),tapinp)
-- local CCT = R.concat("CONVPIPEINP"..depth,{out1,tapinp})
-- local piinp = R.apply("CPI"..depth, RM.packTuple({types.array2d(A,internalT),TAP_TYPE}), CCT)
--out = R.apply("PT"..depth, RM.makeHandshake(C.packTap(types.array2d(A,internalT),TAP_TYPE,soc.taps)), out)
out = R.apply("p"..depth, PI, out)
local thisW = inputW*inputH/math.pow(4,depth-1)
--print("thisW",thisW,thisW/outputH)
outputW = outputW + thisW/outputH
if depth>1 then
--curT = internalT/4 -- we do changeRate so that this is always true for this implementation
curW = curW/2
curH = curH/2
end
--local THIS_TYPE = types.array2d(types.uint(8),curT)
local TOP_TYPE = types.array2d(A,internalT)
local OUT_TYPE = types.array2d(A,8)
if depth==TARGET_DEPTH then
-- we must do the changerate _before_ the fifo, or the things later will run at 1/2 rate we expect
out = R.apply("CR"..depth,RM.liftHandshake(RM.changeRate(A,1,internalT,8)), out)
-- last level
out = P.FIFO(fifos,statements,OUT_TYPE, out,nil, "finalFIFO", curW, curH, 8 )
L[depth] = out
else
out = R.apply("out_broadcast"..depth, RM.broadcastStream(TOP_TYPE,2), out)
local out0 = R.selectStream("i0"..depth,out,0)
out0 = P.FIFO( fifos, statements, TOP_TYPE, out0, nil, "internal"..depth, curW, curH, internalT )
local out1 = R.apply("CRr"..depth,RM.liftHandshake(RM.changeRate(A,1,internalT,8)), R.selectStream("i1"..depth,out,1) )
out1 = P.FIFO( fifos, statements, OUT_TYPE, out1, nil, "output"..depth, curW, curH, 8 )
L[depth] = out1
out = out0
end
SDF[depth] = {1,math.pow(4,depth-1)}
-- SDF[depth] = {PI.sdfOutput[1][1],PI.sdfOutput[1][2]}
-- if depth>1 then SDF[depth][1] = SDF[depth][1]/2 end
end
--print("outputW",outputW,"outputH",outputH)
--for k,v in ipairs(SDF) do print("SDF",v[1],v[2]) end
SDF = SDFRate.normalize(SDF)
--for k,v in ipairs(SDF) do print("SDF",v[1],v[2]) end
local RW_TYPE = types.array2d( types.uint(8), 8 ) -- simulate axi bus
--print("TARGET_DEPTH",TARGET_DEPTH)
if TARGET_DEPTH>1 then
SER = RM.serialize( RW_TYPE, SDF, RM.pyramidSchedule( TARGET_DEPTH, inputW, outputT ) )
out = R.apply("toHandshakeArray", RM.toHandshakeArrayOneHot( RW_TYPE, SDF), R.concatArray2d( "sa", L, TARGET_DEPTH, 1))
out = R.apply("ser", SER, out )
out = R.apply("flatten", RM.flattenStreams(RW_TYPE, SDF), out )
end
if outputT~=8 then
out = R.apply("CRend",RM.liftHandshake(RM.changeRate(A,1,outputT,8)), out)
end
table.insert(statements,1,out)
hsfn = RM.lambda("pyramid", inp, R.statements(statements), fifos )
local scale = math.pow(2,TARGET_DEPTH-1)
local infile = "frame_64.raw"
local outfile = "pyramid_taps_"..tostring(TARGET_DEPTH)
local design = "Gaussian Pyramid 64"
if TARGET_DEPTH==4 then infile, design = "frame_128.raw","Gaussian Pyramid 128" end
if LARGE then
infile = "frame_384_384.raw"
if NOFIFO then
outfile = "pyramid_large_nofifo_taps_"..tostring(TARGET_DEPTH)
design = "Gaussian Pyramid NOFIFO 384"
else
outfile = "pyramid_large_taps_"..tostring(TARGET_DEPTH)
design = "Gaussian Pyramid 384"
end
end
harness{ outFile=outfile, fn=hsfn, inFile=infile, tapType=TAP_TYPE, tapValue=P.G, inSize={inputW,inputH}, outSize={outputW,outputH}, earlyOverride=9999999 }
io.output("out/"..outfile..".design.txt"); io.write(design); io.close()
io.output("out/"..outfile..".designT.txt"); io.write(internalT); io.close()
io.output("out/"..outfile..".extra.txt"); io.write(TARGET_DEPTH); io.close()