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 3744, Mon Apr 11 22:06:24 2016 UTC revision 3777, Tue Apr 26 22:49:35 2016 UTC
# Line 89  Line 89 
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          val dim = ImageInfo.dim info
93            in            in
94              (ImageInfo.dim info, border, vN, vH, vF, vP)              (vI, vH, vN, vF, vP, info, border, dim)
95            end            end
96    
97    (*lifted Kernel expressions    (*lifted Kernel expressions
# Line 121  Line 122 
122            (* end case *)            (* end case *)
123          end          end
124    
125      (*fieldReconstruction:int*int*int,mu list, param_id, param_id, kernel, position, param_id  
126      * expands the body for the probed field      fun mkLdVoxel (avail, vI, vN, info, alpha, shape, dim, s) = let
127      *)         val vLb = AvailRHS.addAssign (avail, "lit", Ty.intTy,  IR.LIT(Literal.Int (1-(IntInf.fromInt s))))
128      fun fieldReconstruction (avail, dim, sx, alpha, dx,  Vid, nid, vH, vF, kid, border) = let         val s'= 2*s
129    
130           fun f i =
131            let
132                val vA = AvailRHS.addAssign (avail, "lit", Ty.intTy,  IR.LIT(Literal.Int (IntInf.fromInt  i)))
133                val vB = AvailRHS.addAssign (avail, "subscript", Ty.intTy, IR.OP(Op.Subscript(Ty.TensorTy[dim]), [vN, vA]))
134                in
135                    AvailRHS.addAssign (avail, "add", Ty.intTy, IR.OP(Op.IAdd, [vB, vLb]))
136                end
137    
138            (* image positions *)
139            val supportshape =  List.tabulate(dim, fn _ => s')
140            val ldty = Ty.TensorTy shape
141            val vNs = List.tabulate( dim, fn n => f n)
142            in
143            AvailRHS.addAssign (avail, "ldvox", ldty, IR.OP(Op.LoadVoxels (info, s), vI::vNs))
144            end
145    
146    
147    
148        (*fieldReconstruction expands the body for the probed field*)
149          fun fieldReconstruction (avail, sx, alpha, shape, dx,  Vid, kid, hid, tid, args) = let
150            val  (vI, vH, vN, vF, vP, info, border, dim) = handleArgs (avail, Vid, hid, tid, args)
151          val h = getKernelDst vH          val h = getKernelDst vH
152          val s = Kernel.support h          val s = Kernel.support h
153    
154          (* image positions for image body *)  
155          val imgpos =          val imgexp= E.Tensor(Vid, List.rev (alpha))
156              if (dim = 1)          val vLd = mkLdVoxel (avail, vI, vN, info, alpha, shape, dim, s)
             then [E.Opn(E.Add, [E.Tensor(nid, []), E.Value(sx)])]  
             else List.tabulate(dim, fn dir=> E.Opn(E.Add, [E.Tensor(nid, [E.C dir]), E.Value(dir+sx)]))  
         (* image body *)  
         val imgexp = E.Img(Vid, alpha, imgpos, s, border)  
157    
158          (* create kernel body *)          (* create kernel body *)
159          fun createKrn (0,  krnexp, vAs) = (krnexp, vAs)          fun createKrn (0,  krnexp, vAs) = (krnexp, vAs)
# Line 155  Line 174 
174        val (krnexp, vAs) = createKrn (dim, [], [])        val (krnexp, vAs) = createKrn (dim, [], [])
175        val exp =  E.Sum(esum, E.Opn(E.Prod, imgexp::krnexp))        val exp =  E.Sum(esum, E.Opn(E.Prod, imgexp::krnexp))
176            in            in
177              (exp, vAs)               (vAs, vLd, vN, vP,  exp)
178            end            end
179    
180     (*getsumshift:sum_indexid list* int list-> int     (*getsumshift:sum_indexid list* int list-> int
# Line 207  Line 226 
226       (* tensor ids for position, transform matrix P, and kernel terms*)       (* tensor ids for position, transform matrix P, and kernel terms*)
227            val nid = length params            val nid = length params
228            val pid = nid+1            val pid = nid+1
229        val kid = pid+1        val kid = pid
230    
231            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
232            val (dim, border, vN, vH, vF, vP)  = handleArgs (avail, Vid, hid, tid, args)        val E.IMG(dim, shape) = List.nth(params, Vid)
233            val freshIndex = getsumshift (sx, length index)            val freshIndex = getsumshift (sx, length index)
234            val (dx', sx', Ps) = T.imageToWorld (freshIndex, dim, dx, pid)            val (dx', sx', Ps) = T.imageToWorld (freshIndex, dim, dx, pid)
235        val sxn = freshIndex+length dx' (*next available index id *)        val sxn = freshIndex+length dx' (*next available index id *)
236            val (probe', vKs) = fieldReconstruction (avail, dim, sxn, alpha, dx', Vid, nid, vH, vF, pid, border)  
237          val (vKs, vLd, vN, vP, probe') =  fieldReconstruction (avail, sxn, alpha, shape, dx',  Vid, kid, hid, tid, args)
238    
239        (* add new params position (nid), transformation matrix (Pid), and kernel ids *)        (* add new params position (nid), transformation matrix (Pid), and kernel ids *)
240        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,[])))
241            val (_, body') = arrangeBody (body, Ps, sx', probe')            val (_, body') = arrangeBody (body, Ps, sx', probe')
242    
243          val args = List.take(args, Vid)@(vLd::List.drop(args, Vid+1))
244            val einapp = (y, IR.EINAPP(mkEin(params', index, body'), args @ [vN, vP]@vKs))            val einapp = (y, IR.EINAPP(mkEin(params', index, body'), args @ [vN, vP]@vKs))
245        (* val _ =  AvailRHS.addAssignToList (avail, einapp)*)(*FIXME: remove this*)  
246            in            in
247              AvailRHS.addAssignToList (avail, einapp)              AvailRHS.addAssignToList (avail, einapp)
248            end            end
# Line 258  Line 281 
281    (* floats the reconstructed field term *)    (* floats the reconstructed field term *)
282      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
283            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
           val (dim, border, vN, vH, vF, vP)  = handleArgs(avail, Vid, hid, tid, args)  
284            val freshIndex = getsumshift(sx, length(index))            val freshIndex = getsumshift(sx, length(index))
285          val E.IMG(dim, shape) = List.nth(params, Vid)
286    
287                      (* transform T*P*P..Ps *)                      (* transform T*P*P..Ps *)
288            val (splitvar, ein0, sizes, dx, alpha') =            val (splitvar, ein0, sizes, dx, alpha') =
289                  createEinApp (body, alpha, index, freshIndex, dim, dx, sx)                  createEinApp (body, alpha, index, freshIndex, dim, dx, sx)
290            val vT = V.new ("TPP", Ty.TensorTy(sizes))            val vT = V.new ("TPP", Ty.TensorTy(sizes))
           val einApp0 = IR.EINAPP(ein0, [vP, vT])  
           val rtn0 = if splitvar  
                 then FloatEin.transform(y, EinSums.transform ein0, [vP, vT])  
                 else [(y, IR.EINAPP(ein0, [vP, vT]))]  
   
291    
292                      (* reconstruct the lifted probe *)                      (* reconstruct the lifted probe *)
293        (* making params args: image, position, and kernel ids *)        (* making params args: image, position, and kernel ids *)
294        val nid = 1 (* transformed image position *)        val nid = 1 (* transformed image position *)
295          val kid = nid
296        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,[])))
297        (* create body for ein expression *)        (* create body for ein expression *)
298        val sxn = length sizes (*next available index id *)        val sxn = length sizes (*next available index id *)
299        val (probe', vKs) = fieldReconstruction (avail, dim, sxn, alpha', dx, Vid, nid, vH, vF, nid, border)         val (vKs, vLd, vN, vP, probe')  =  fieldReconstruction (avail, sxn, alpha', shape, dx,  Vid, kid, hid, tid, args)
300        val args' = List.nth(args,Vid) :: vN ::vKs        val args' = vLd :: vN ::vKs
301            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')
302    
303                      (* transform T*P*P..Ps *)
304          val rtn0 = if splitvar
305          then FloatEin.transform(y, EinSums.transform ein0, [vP, vT])
306          else [(y, IR.EINAPP(ein0, [vP, vT]))]
307    
308            in            in
309        List.app (fn e => AvailRHS.addAssignToList(avail, e)) (((vT, einApp1)::(rtn0)))        List.app (fn e => AvailRHS.addAssignToList(avail, e)) (((vT, einApp1)::(rtn0)))
# Line 294  Line 317 
317      fun expand avail (e as (_, IR.EINAPP(Ein.EIN{body, ...}, _))) = (case body      fun expand avail (e as (_, IR.EINAPP(Ein.EIN{body, ...}, _))) = (case body
318             of (E.Probe(E.Conv(_, _, _, []) ,_)) =>             of (E.Probe(E.Conv(_, _, _, []) ,_)) =>
319                  replaceProbe (avail, e, body, [])                  replaceProbe (avail, e, body, [])
        (* | (E.Probe _) =>  
         replaceProbe (avail, e, body, [])  
         (*FIXME: Only use replaceProbe while trying to isolate valnum bug*)  
         *)  
320              | (E.Probe(E.Conv(_, alpha, _, dx) ,_)) =>              | (E.Probe(E.Conv(_, alpha, _, dx) ,_)) =>
321                  liftProbe (avail, e, body, []) (*scans dx for contant*)                  liftProbe (avail, e, body, []) (*scans dx for contant*)
322    

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

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