Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /branches/vis15/src/compiler/high-to-mid/probe-ein.sml
ViewVC logotype

Diff of /branches/vis15/src/compiler/high-to-mid/probe-ein.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3777, Tue Apr 26 22:49:35 2016 UTC revision 3784, Wed Apr 27 18:13:26 2016 UTC
# Line 57  Line 57 
57          )          )
58    
59      fun getImagInfo e = (case IR.Var.getDef e      fun getImagInfo e = (case IR.Var.getDef e
60          of IR.OP(Op.LoadImage(Ty.ImageTy info, _), []) => (e, info, E.None)          of IR.OP(Op.LoadImage(Ty.ImageTy info, _), []) => (e, info, NONE)
61          | IR.OP(Op.BorderCtlDefault info, [imgArg])    => (imgArg, info, E.Default)          | IR.OP(Op.BorderCtlDefault info, [imgArg])    => (imgArg, info, raise Fail "Default boarder control")
62          | IR.OP(Op.BorderCtlClamp info, [imgArg])      => (imgArg, info, E.Clamp)          | IR.OP(Op.BorderCtlClamp info, [imgArg])      => (imgArg, info, SOME IndexCtl.Clamp)
63          | IR.OP(Op.BorderCtlMirror info, [imgArg])     => (imgArg, info, E.Mirror)          | IR.OP(Op.BorderCtlMirror info, [imgArg])     => (imgArg, info, SOME IndexCtl.Mirror)
64          | IR.OP(Op.BorderCtlWrap info, [imgArg])       => (imgArg, info, E.Wrap)          | IR.OP(Op.BorderCtlWrap info, [imgArg])       => (imgArg, info, SOME IndexCtl.Wrap)
65          | rhs => raise Fail (String.concat[          | rhs => raise Fail (String.concat[
66          "expected image for ", IR.Var.toString e,          "expected image for ", IR.Var.toString e,
67          " but found ", IR.RHS.toString rhs          " but found ", IR.RHS.toString rhs
# Line 123  Line 123 
123          end          end
124    
125    
126      fun mkLdVoxel (avail, vI, vN, info, alpha, shape, dim, s) = let      fun mkLdVoxel (avail, vI, vN, info, alpha, shape, dim, s, border) = let
127         val vLb = AvailRHS.addAssign (avail, "lit", Ty.intTy,  IR.LIT(Literal.Int (1-(IntInf.fromInt s))))         val vLb = AvailRHS.addAssign (avail, "lit", Ty.intTy,  IR.LIT(Literal.Int (1-(IntInf.fromInt s))))
        val s'= 2*s  
   
128         fun f i =         fun f i =
129          let          let
130              val vA = AvailRHS.addAssign (avail, "lit", Ty.intTy,  IR.LIT(Literal.Int (IntInf.fromInt  i)))              val vA = AvailRHS.addAssign (avail, "lit", Ty.intTy,  IR.LIT(Literal.Int (IntInf.fromInt  i)))
# Line 136  Line 134 
134              end              end
135    
136          (* image positions *)          (* image positions *)
137            val s'= 2*s
138          val supportshape =  List.tabulate(dim, fn _ => s')          val supportshape =  List.tabulate(dim, fn _ => s')
139          val ldty = Ty.TensorTy shape          val ldty = Ty.TensorTy (shape@supportshape)
140          val vNs = List.tabulate( dim, fn n => f n)          val vNs = List.tabulate( dim, fn n => f n)
141    
142            val op1 = (case border
143                of NONE => Op.LoadVoxels (info, s)
144                | SOME b =>  Op.LoadVoxelsWithCtl (info, s, b)
145                (* end case *))
146          in          in
147          AvailRHS.addAssign (avail, "ldvox", ldty, IR.OP(Op.LoadVoxels (info, s), vI::vNs))              AvailRHS.addAssign (avail, "ldvox", ldty, IR.OP(op1, [vI, vN]))
148          end          end
149    
150    
151    
152      (*fieldReconstruction expands the body for the probed field*)      (*fieldReconstruction expands the body for the probed field*)
153        fun fieldReconstruction (avail, sx, alpha, shape, dx,  Vid, kid, hid, tid, args) = let        fun fieldReconstruction (avail, sx, alpha, shape, dx,  Vid, Vidnew, kid, hid, tid, args) = let
154          val  (vI, vH, vN, vF, vP, info, border, dim) = handleArgs (avail, Vid, hid, tid, args)          val  (vI, vH, vN, vF, vP, info, border, dim) = handleArgs (avail, Vid, hid, tid, args)
155          val h = getKernelDst vH          val h = getKernelDst vH
156          val s = Kernel.support h          val s = Kernel.support h
157    
158            (* creating summation Index *)
159            val vs = List.tabulate (dim, fn i => (i +sx))
160            val esum = List.map (fn i => (E.V i, 1-s, s)) vs
161    
162            (*represent image in ein expression with tensor*)
163            val imgexp= E.Img(Vidnew, alpha, List.map (fn i=> E.Value i)  vs, s, E.None)
164            (*val imgexp = E.Tensor (Vidnew, alpha@(List.map (fn i => E.V i) vs))*)
165    
166          val imgexp= E.Tensor(Vid, List.rev (alpha))          (* create load voxel operator for image *)
167          val vLd = mkLdVoxel (avail, vI, vN, info, alpha, shape, dim, s)          val vLd = mkLdVoxel (avail, vI, vN, info, alpha, shape, dim, s, border)
168    
169          (* create kernel body *)          (* create kernel body *)
170          fun createKrn (0,  krnexp, vAs) = (krnexp, vAs)          fun createKrn (0,  krnexp, vAs) = (krnexp, vAs)
# Line 168  Line 179 
179              createKrn (dir', kexp0::krnexp, vA::vAs)              createKrn (dir', kexp0::krnexp, vA::vAs)
180          end          end
181    
       (* creating summation Index *)  
        val esum = List.tabulate (dim, fn i => (E.V (i +sx), 1-s, s))  
182        (* final ein expression body to represent field reconstruction *)        (* final ein expression body to represent field reconstruction *)
183        val (krnexp, vAs) = createKrn (dim, [], [])        val (krnexp, vKs) = createKrn (dim, [], [])
184        val exp =  E.Sum(esum, E.Opn(E.Prod, imgexp::krnexp))        val exp =  E.Sum(esum, E.Opn(E.Prod, imgexp::krnexp))
185            in            in
186               (vAs, vLd, vN, vP,  exp)               (vLd::vKs, vP,  exp)
187            end            end
188    
189     (*getsumshift:sum_indexid list* int list-> int     (*getsumshift:sum_indexid list* int list-> int
# Line 224  Line 233 
233       fun replaceProbe (avail, (y, IR.EINAPP(Ein.EIN{params, index, body}, args)), probe, sx) = let       fun replaceProbe (avail, (y, IR.EINAPP(Ein.EIN{params, index, body}, args)), probe, sx) = let
234    
235       (* tensor ids for position, transform matrix P, and kernel terms*)       (* tensor ids for position, transform matrix P, and kernel terms*)
236            val nid = length params            val pid = length params
237            val pid = nid+1        val Vidnew = pid+1
238        val kid = pid        val kid = Vidnew
239    
240            val E.Probe(E.Conv(Vid, alpha, hid, dx), E.Tensor(tid, _)) = probe            val E.Probe(E.Conv(Vid, alpha, hid, dx), E.Tensor(tid, _)) = probe
241        val E.IMG(dim, shape) = List.nth(params, Vid)        val E.IMG(dim, shape) = List.nth(params, Vid)
242            val freshIndex = getsumshift (sx, length index)            val freshIndex = getsumshift (sx, length index)
243            val (dx', sx', Ps) = T.imageToWorld (freshIndex, dim, dx, pid)            val (dx', sx', Ps) = T.imageToWorld (freshIndex, dim, dx, pid)
244        val sxn = freshIndex+length dx' (*next available index id *)        val sxn = freshIndex+length dx' (*next available index id *)
245          val (args', vP, probe') = fieldReconstruction (avail, sxn, alpha, shape, dx',  Vid, Vidnew, kid, hid, tid, args)
246    
       val (vKs, vLd, vN, vP, probe') =  fieldReconstruction (avail, sxn, alpha, shape, dx',  Vid, kid, hid, tid, args)  
247    
248        (* add new params position (nid), transformation matrix (Pid), and kernel ids *)        (* add new params transformation matrix (Pid), image param, and kernel ids *)
249        val params' = params @ [E.TEN(true, [dim]), E.TEN(true, [dim, dim])] @(List.tabulate(dim,fn _=> E.TEN(true,[])))        val pP = E.TEN(true, [dim, dim])
250          val pV = List.nth(params, Vid)
251          val pK = List.tabulate(dim,fn _=> E.KRN)
252          val params' = params @ (pP::pV::pK)
253            val (_, body') = arrangeBody (body, Ps, sx', probe')            val (_, body') = arrangeBody (body, Ps, sx', probe')
254          val einapp = (y, IR.EINAPP(mkEin(params', index, body'), args @ (vP::args')))
       val args = List.take(args, Vid)@(vLd::List.drop(args, Vid+1))  
           val einapp = (y, IR.EINAPP(mkEin(params', index, body'), args @ [vN, vP]@vKs))  
   
255            in            in
256              AvailRHS.addAssignToList (avail, einapp)              AvailRHS.addAssignToList (avail, einapp)
257            end            end
# Line 291  Line 300 
300    
301                      (* reconstruct the lifted probe *)                      (* reconstruct the lifted probe *)
302        (* making params args: image, position, and kernel ids *)        (* making params args: image, position, and kernel ids *)
303        val nid = 1 (* transformed image position *)        val kid = 0 (* params used *)
304        val kid = nid        val params' = List.nth(params,Vid)::(List.tabulate(dim,fn _=> E.KRN))
       val params' = List.nth(params,Vid)::E.TEN(true, [dim])::(List.tabulate(dim,fn _=> E.TEN(true,[])))  
305        (* create body for ein expression *)        (* create body for ein expression *)
306        val sxn = length sizes (*next available index id *)        val sxn = length sizes (*next available index id *)
307         val (vKs, vLd, vN, vP, probe')  =  fieldReconstruction (avail, sxn, alpha', shape, dx,  Vid, kid, hid, tid, args)        val (args', vP, probe') = fieldReconstruction (avail, sxn, alpha', shape, dx,  Vid, Vid, kid, hid, tid, args)
308        val args' = vLd :: vN ::vKs            val einApp1 = IR.EINAPP(mkEin(params', sizes, probe'), args')
           val einApp1 = IR.EINAPP(mkEin(params'@[E.TEN(true,[10])], sizes, probe'), args')  
309    
310                    (* transform T*P*P..Ps *)                    (* transform T*P*P..Ps *)
311        val rtn0 = if splitvar        val rtn0 = if splitvar

Legend:
Removed from v.3777  
changed lines
  Added in v.3784

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0