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 3741, Sun Apr 10 23:33:56 2016 UTC revision 3742, Mon Apr 11 04:53:02 2016 UTC
# Line 48  Line 48 
48                  ])                  ])
49            (* end case *))            (* end case *))
50    
51      fun getImageDst imgArg = (case IR.Var.getDef imgArg      fun checkImg imgArg = (case IR.Var.getDef imgArg
52             of IR.OP(Op.LoadImage(Ty.ImageTy info, _), _) => info             of IR.OP(Op.LoadImage _, _) => imgArg
 (* FIXME: also border control! *)  
53              | rhs => raise Fail (String.concat[              | rhs => raise Fail (String.concat[
54                    "expected image for ", IR.Var.toString imgArg,                    "expected image for ", IR.Var.toString imgArg,
55                    " but found ", IR.RHS.toString rhs                    " but found ", IR.RHS.toString rhs
56                  ])                  ])
57            )
58    
59        fun getImagInfo e = (case IR.Var.getDef e
60            of IR.OP(Op.LoadImage(Ty.ImageTy info, _), []) => (e, info, E.None)
61            | IR.OP(Op.BorderCtlDefault info, [imgArg])    => (imgArg, info, E.Default)
62            | IR.OP(Op.BorderCtlClamp info, [imgArg])      => (imgArg, info, E.Clamp)
63            | IR.OP(Op.BorderCtlMirror info, [imgArg])     => (imgArg, info, E.Mirror)
64            | IR.OP(Op.BorderCtlWrap info, [imgArg])       => (imgArg, info, E.Wrap)
65            | rhs => raise Fail (String.concat[
66            "expected image for ", IR.Var.toString e,
67            " but found ", IR.RHS.toString rhs
68            ])
69            (* end case *))            (* end case *))
70    
71      fun getKernelDst hArg = (case IR.Var.getDef hArg      fun getKernelDst hArg = (case IR.Var.getDef hArg
# Line 65  Line 76 
76                  ])                  ])
77            (* end case *))            (* end case *))
78    
79      (*handleArgs():int*int*int*Mid IR.Var list      (* handleArgs- returns image arguments, info, and border
         ->int*Mid.IRVars list* code*int* low-il-var  
80          * uses the Param_ids for the image, kernel, and tensor          * uses the Param_ids for the image, kernel, and tensor
81          * and gets the mid-IR vars for each.          * and gets the mid-IR vars for each.
82          *Transforms the position to index space          *Transforms the position to index space
# Line 74  Line 84 
84      *)      *)
85      fun handleArgs (avail, Vid, hid, tid, args) = let      fun handleArgs (avail, Vid, hid, tid, args) = let
86            val vI = List.nth (args, Vid)            val vI = List.nth (args, Vid)
87            val info = getImageDst vI            val (vI, info, border) = getImagInfo vI
88        val vH = List.nth(args, hid)        val vH = List.nth(args, hid)
89            val (vN, vF, vP) = T.worldToIndex{            val (vN, vF, vP) = T.worldToIndex{
90                    avail = avail, info = info, img = vI, pos = List.nth(args, tid)                    avail = avail, info = info, img = vI, pos = List.nth(args, tid)
91                  }                  }
92            in            in
93              (ImageInfo.dim info, vN, vH, vF, vP)              (ImageInfo.dim info, border, vN, vH, vF, vP)
94            end            end
95    
96    (*lifted Kernel expressions    (*lifted Kernel expressions
# Line 114  Line 124 
124      (*fieldReconstruction:int*int*int,mu list, param_id, param_id, kernel, position, param_id      (*fieldReconstruction:int*int*int,mu list, param_id, param_id, kernel, position, param_id
125      * expands the body for the probed field      * expands the body for the probed field
126      *)      *)
127      fun fieldReconstruction (avail, dim, sx, alpha, dx,  Vid, nid, vH, vF, kid) = let      fun fieldReconstruction (avail, dim, sx, alpha, dx,  Vid, nid, vH, vF, kid, border) = let
128    
129    
130          (* image positions for image body *)          (* image positions for image body *)
# Line 123  Line 133 
133              then [E.Opn(E.Add, [E.Tensor(nid, []), E.Value(sx)])]              then [E.Opn(E.Add, [E.Tensor(nid, []), E.Value(sx)])]
134              else List.tabulate(dim, fn dir=> E.Opn(E.Add, [E.Tensor(nid, [E.C dir]), E.Value(dir+sx)]))              else List.tabulate(dim, fn dir=> E.Opn(E.Add, [E.Tensor(nid, [E.C dir]), E.Value(dir+sx)]))
135          (* image body *)          (* image body *)
136          val imgexp = E.Img(Vid, alpha, imgpos)          val imgexp = E.Img(Vid, alpha, imgpos, border)
137    
138          val h = getKernelDst vH          val h = getKernelDst vH
139          val s = Kernel.support h          val s = Kernel.support h
# Line 133  Line 143 
143              val dir' = dir-1              val dir' = dir-1
144              (* ein expression *)              (* ein expression *)
145              val deltas = List.map (fn e =>(E.C(dir'), e)) dx              val deltas = List.map (fn e =>(E.C(dir'), e)) dx
146              val kexp0 = E.Krn(kid+dir, deltas, E.Value(dir))              val kexp0 = E.Krn(kid+dir, deltas, dir)
147              (* evalkernel operators *)              (* evalkernel operators *)
148              val vA = liftKrn (avail, dir, dx, dim, h, vF, s)              val vA = liftKrn (avail, dir, dx, dim, h, vF, s)
149          in          in
# Line 201  Line 211 
211        val kid = pid+1        val kid = pid+1
212    
213            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
214            val (dim, vN, vH, vF, vP)  = handleArgs (avail, Vid, hid, tid, args)            val (dim, border, vN, vH, vF, vP)  = handleArgs (avail, Vid, hid, tid, args)
215            val freshIndex = getsumshift (sx, length index)            val freshIndex = getsumshift (sx, length index)
216            val (dx', sx', Ps) = T.imageToWorld (freshIndex, dim, dx, pid)            val (dx', sx', Ps) = T.imageToWorld (freshIndex, dim, dx, pid)
217        val sxn = freshIndex+length dx' (*next available index id *)        val sxn = freshIndex+length dx' (*next available index id *)
218            val (probe', vKs) = fieldReconstruction (avail, dim, sxn, alpha, dx', Vid, nid, vH, vF, pid)            val (probe', vKs) = fieldReconstruction (avail, dim, sxn, alpha, dx', Vid, nid, vH, vF, pid, border)
219        (* add new params position (nid), transformation matrix (Pid), and kernel ids *)        (* add new params position (nid), transformation matrix (Pid), and kernel ids *)
220        val params' = params @ [E.TEN(true, [dim]), E.TEN(true, [dim, dim])] @(List.tabulate(dim,fn _=> E.TEN(true,[])))        val params' = params @ [E.TEN(true, [dim]), E.TEN(true, [dim, dim])] @(List.tabulate(dim,fn _=> E.TEN(true,[])))
221            val (_, body') = arrangeBody (body, Ps, sx', probe')            val (_, body') = arrangeBody (body, Ps, sx', probe')
# Line 249  Line 259 
259    (* floats the reconstructed field term *)    (* floats the reconstructed field term *)
260      fun liftProbe (avail, (y, IR.EINAPP(Ein.EIN{params, index, body}, args)), probe, sx) = let      fun liftProbe (avail, (y, IR.EINAPP(Ein.EIN{params, index, body}, args)), probe, sx) = let
261            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
262            val (dim, vN, vH, vF, vP)  = handleArgs(avail, Vid, hid, tid, args)            val (dim, border, vN, vH, vF, vP)  = handleArgs(avail, Vid, hid, tid, args)
263            val freshIndex = getsumshift(sx, length(index))            val freshIndex = getsumshift(sx, length(index))
264    
265                      (* transform T*P*P..Ps *)                      (* transform T*P*P..Ps *)
# Line 268  Line 278 
278        val params' = List.nth(params,Vid)::E.TEN(true, [dim])::(List.tabulate(dim,fn _=> E.TEN(true,[])))        val params' = List.nth(params,Vid)::E.TEN(true, [dim])::(List.tabulate(dim,fn _=> E.TEN(true,[])))
279        (* create body for ein expression *)        (* create body for ein expression *)
280        val sxn = length sizes (*next available index id *)        val sxn = length sizes (*next available index id *)
281        val (probe', vKs) = fieldReconstruction (avail, dim, sxn, alpha', dx, Vid, nid, vH, vF, nid)        val (probe', vKs) = fieldReconstruction (avail, dim, sxn, alpha', dx, Vid, nid, vH, vF, nid, border)
282        val args' = List.nth(args,Vid) :: vN ::vKs        val args' = List.nth(args,Vid) :: vN ::vKs
283            val einApp1 = IR.EINAPP(mkEin(params'@[E.TEN(true,[10])], sizes, probe'), args')            val einApp1 = IR.EINAPP(mkEin(params'@[E.TEN(true,[10])], sizes, probe'), args')
284    

Legend:
Removed from v.3741  
changed lines
  Added in v.3742

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