8 |
|
|
9 |
structure Probe : sig |
structure Probe : sig |
10 |
|
|
11 |
val expand : MidIL.Var.var * FieldDef.field_def * HighIL.Var.var |
val expand : MidIL.var * FieldDef.field_def * HighIL.var -> HighIL.assign list |
|
-> HighIL.assign list |
|
12 |
|
|
13 |
end = struct |
end = struct |
14 |
|
|
15 |
structure SrcIL = HighIL |
structure SrcIL = HighIL |
16 |
structure SrcOp = SrcIL.Op |
structure SrcOp = HighOps |
17 |
structure DstIL = MidIL |
structure DstIL = MidIL |
18 |
structure DstOp = DstIL.Op |
structure DstOp = MidOps |
19 |
structure VMap = SrcIL.Var.Map |
structure VMap = SrcIL.Var.Map |
20 |
|
|
21 |
(* a tree representation of nested iterations over the image space, where the |
(* a tree representation of nested iterations over the image space, where the |
60 |
|
|
61 |
fun assign (x, rator, args) = (x, DstIL.OP(rator, args)) |
fun assign (x, rator, args) = (x, DstIL.OP(rator, args)) |
62 |
fun cons (x, args) = (x, DstIL.CONS args) |
fun cons (x, args) = (x, DstIL.CONS args) |
63 |
fun realLit (x, r) = (x, DstIL.LIT(Literal.Float(FloatLit.fromInt i))) |
fun realLit (x, i) = (x, DstIL.LIT(Literal.Float(FloatLit.fromInt i))) |
64 |
fun intLit (x, i) = (x, DstIL.LIT(Literal.Int(IntInf.fromInt i))) |
fun intLit (x, i) = (x, DstIL.LIT(Literal.Int(IntInf.fromInt i))) |
65 |
|
|
66 |
(* generate code for probing the field (D^k (v * h)) at pos *) |
(* generate code for probing the field (D^k (v * h)) at pos *) |
75 |
val nd = DstIL.Var.new "nd" |
val nd = DstIL.Var.new "nd" |
76 |
val n = DstIL.Var.new "n" |
val n = DstIL.Var.new "n" |
77 |
val transformCode = [ |
val transformCode = [ |
78 |
assign(x, DstIL.Transform v, [pos]), |
assign(x, DstOp.Transform v, [pos]), |
79 |
assign(nd, DstIL.Floor dim, [x]), |
assign(nd, DstOp.Floor dim, [x]), |
80 |
assign(f, DstIL.Sub dimTy, [x, nd]), |
assign(f, DstOp.Sub dimTy, [x, nd]), |
81 |
assign(n, DstOp.TruncToInt dim, [nd]) |
assign(n, DstOp.TruncToInt dim, [nd]) |
82 |
] |
] |
83 |
(* generate code to load the voxel data *) |
(* generate code to load the voxel data *) |
88 |
vox = DstIL.Var.new(String.concat("v" :: List.map Int.toString id)) |
vox = DstIL.Var.new(String.concat("v" :: List.map Int.toString id)) |
89 |
} |
} |
90 |
in |
in |
91 |
IT.create (depth, width, fn _ => (), f, g, ([], [])) |
IT.create (dim-1, 2*s, fn _ => (), f, g, ([], [])) |
92 |
end |
end |
93 |
val loadCode = let |
val loadCode = let |
94 |
fun genCode ({offsets, vox}, code) = let |
fun genCode ({offsets, vox}, code) = let |
111 |
val a = DstIL.Var.new "a" |
val a = DstIL.Var.new "a" |
112 |
in |
in |
113 |
indicesCode :: [ |
indicesCode :: [ |
114 |
assign(a, VoxelAddress v, indices), |
assign(a, DstOp.VoxelAddress v, indices), |
115 |
assign(vox, LoadVoxels(ty, 2*s)) |
assign(vox, DstOp.LoadVoxels(ty, 2*s)) |
116 |
] @ code |
] @ code |
117 |
end |
end |
118 |
in |
in |
137 |
val t' = DstIL.Var.new "r" |
val t' = DstIL.Var.new "r" |
138 |
in |
in |
139 |
realLit (t', n) :: |
realLit (t', n) :: |
140 |
assign (t, DstIL.Add DstIL.realTy, [fd, t']) :: |
assign (t, DstOp.Add DstOp.realTy, [fd, t']) :: |
141 |
code |
code |
142 |
end |
end |
143 |
val coeffCode = |
val coeffCode = |
144 |
cons(a, List.map #1 tmps) :: |
cons(a, List.map #1 tmps) :: |
145 |
List.tabulate (k+1, fn i => |
List.tabulate (k+1, fn i => |
146 |
assign(coefficient(d, i), EvalKernel(2*s, h, i), [a])) |
assign(coefficient(d, i), DstOp.EvalKernel(2*s, h, i), [a])) |
147 |
in |
in |
148 |
assign(fd, DstOp.Select d, f) :: |
assign(fd, DstOp.Select d, f) :: |
149 |
(List.foldr mkArg (coeffCode @ code) tmps) |
(List.foldr mkArg (coeffCode @ code) tmps) |
160 |
val hh = coefficient (d, 0) (* FIXME: what is the right value for k? *) |
val hh = coefficient (d, 0) (* FIXME: what is the right value for k? *) |
161 |
in |
in |
162 |
cons (vv, List.map getVox kids) :: |
cons (vv, List.map getVox kids) :: |
163 |
assign (t, DstIL.Dot, [hh, vv]) :: code |
assign (t, DstOp.Dot, [hh, vv]) :: code |
164 |
end |
end |
165 |
val reduceCode = genReduce (1, voxIter, []) |
val reduceCode = genReduce (1, voxIter, []) |
166 |
in |
in |