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 3740, Sun Apr 10 17:09:42 2016 UTC revision 3741, Sun Apr 10 23:33:56 2016 UTC
# Line 141  Line 141 
141          end          end
142    
143        (* creating summation Index *)        (* creating summation Index *)
144         val esum = List.tabulate (dim, fn i => (E.V i, 1-s, s))         val esum = List.tabulate (dim, fn i => (E.V (i +sx), 1-s, s))
145        (* final ein expression body to represent field reconstruction *)        (* final ein expression body to represent field reconstruction *)
146        val (krnexp, vAs) = createKrn (dim, [], [])        val (krnexp, vAs) = createKrn (dim, [], [])
147        val exp =  E.Sum(esum, E.Opn(E.Prod, imgexp::krnexp))        val exp =  E.Sum(esum, E.Opn(E.Prod, imgexp::krnexp))
# Line 205  Line 205 
205            val freshIndex = getsumshift (sx, length index)            val freshIndex = getsumshift (sx, length index)
206            val (dx', sx', Ps) = T.imageToWorld (freshIndex, dim, dx, pid)            val (dx', sx', Ps) = T.imageToWorld (freshIndex, dim, dx, pid)
207        val sxn = freshIndex+length dx' (*next available index id *)        val sxn = freshIndex+length dx' (*next available index id *)
208            val (probe', vKs) = fieldReconstruction (avail, dim, sxn, alpha, dx', Vid, nid, vH, vF, kid)            val (probe', vKs) = fieldReconstruction (avail, dim, sxn, alpha, dx', Vid, nid, vH, vF, pid)
209        (* add new params position (nid), transformation matrix (Pid), and kernel ids *)        (* add new params position (nid), transformation matrix (Pid), and kernel ids *)
210        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,[])))
211            val (_, body') = arrangeBody (body, Ps, sx', probe')            val (_, body') = arrangeBody (body, Ps, sx', probe')
212            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))
       val _ = print(String.concat[ "\nProbe var: ", V.name(y)])  
213        (* val _ =  AvailRHS.addAssignToList (avail, einapp)*)(*FIXME: remove this*)        (* val _ =  AvailRHS.addAssignToList (avail, einapp)*)(*FIXME: remove this*)
214            in            in
215              AvailRHS.addAssignToList (avail, einapp)              AvailRHS.addAssignToList (avail, einapp)
216            end            end
217    
218    
219      (*transform T*P*P..Ps*)      (*transform T*P*P..Ps*)
220      fun createEinApp (body, alpha, index, freshIndex, dim, dx, sx) = let      fun createEinApp (body, alpha, index, freshIndex, dim, dx, sx) = let
221    
# Line 224  Line 224 
224            val (dx', newsx, Ps) = T.imageToWorld(freshIndex, dim, dx, Pid)            val (dx', newsx, Ps) = T.imageToWorld(freshIndex, dim, dx, Pid)
225          (*need to rewrite dx*)          (*need to rewrite dx*)
226            val sxx = sx@newsx            val sxx = sx@newsx
227            val (_, sizes, E.Conv(_, alpha', _, dx')) = (case sxx  
228              val (_, sizes, E.Conv(_, alpha', _, dx)) = (case sxx
229  (* QUESTION: what is the significance of "9" and "7" in this code? *)  (* QUESTION: what is the significance of "9" and "7" in this code? *)
230                   of [] => ([], index, E.Conv(9, alpha, 7, dx'))                   of [] => ([], index, E.Conv(9, alpha, 7, dx'))
231                    | _ => CleanIndex.clean(E.Conv(9, alpha, 7, dx'), index, sxx)                    | _ => CleanIndex.clean(E.Conv(9, alpha, 7, dx'), index, sxx)
232                  (* end case *))                  (* end case *))
233    
234            fun filterAlpha [] = dx'            fun filterAlpha [] = dx'
235              | filterAlpha (E.C _::es) = filterAlpha es              | filterAlpha (E.C _::es) = filterAlpha es
236              | filterAlpha (e1::es) = e1::(filterAlpha es)              | filterAlpha (e1::es) = e1::(filterAlpha es)
237    
238            val exp = E.Tensor(tid, filterAlpha alpha')            val exp = E.Tensor(tid, filterAlpha alpha')
239    
240            val (splitvar, body') = arrangeBody(body, Ps, newsx, exp)            val (splitvar, body') = arrangeBody(body, Ps, newsx, exp)
241            val params = [E.TEN(true, [dim,dim]), E.TEN(true, sizes)]            val params = [E.TEN(true, [dim,dim]), E.TEN(true, sizes)]
242            val ein0 = mkEin(params, index, body')            val ein0 = mkEin(params, index, body')
243    
244            in            in
245              (splitvar, ein0, sizes, dx', alpha')              (splitvar, ein0, sizes, dx, alpha')
246            end            end
247          (*  
248    
249    (* floats the reconstructed field term *)    (* floats the reconstructed field term *)
250      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
251            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
# Line 249  Line 255 
255                      (* transform T*P*P..Ps *)                      (* transform T*P*P..Ps *)
256            val (splitvar, ein0, sizes, dx, alpha') =            val (splitvar, ein0, sizes, dx, alpha') =
257                  createEinApp (body, alpha, index, freshIndex, dim, dx, sx)                  createEinApp (body, alpha, index, freshIndex, dim, dx, sx)
258            val vF = V.new ("T", Ty.TensorTy(sizes))            val vT = V.new ("TPP", Ty.TensorTy(sizes))
259            val einApp0 = IR.EINAPP(ein0, [vP, vF])            val einApp0 = IR.EINAPP(ein0, [vP, vT])
260            val rtn0 = if splitvar            val rtn0 = if splitvar
261                  then FloatEin.transform(y, EinSums.transform ein0, [vP, vF])                  then FloatEin.transform(y, EinSums.transform ein0, [vP, vT])
262                  else [(y, IR.EINAPP(ein0, [vP, vF]))]                  else [(y, IR.EINAPP(ein0, [vP, vT]))]
263    
264    
265                      (* reconstruct the lifted probe *)                      (* reconstruct the lifted probe *)
266        (* tensor id for position *)        (* making params args: image, position, and kernel ids *)
267        val nid = length params        val nid = 1 (* transformed image position *)
268        val kid = nid+1        val params' = List.nth(params,Vid)::E.TEN(true, [dim])::(List.tabulate(dim,fn _=> E.TEN(true,[])))
269        (* add new params position (nid) and kernel ids *)        (* create body for ein expression *)
       val params' = params@(E.TEN(true, [dim])::(List.tabulate(dim,fn _=> E.TEN(true,[]))))  
270            val sxn = length sizes (*next available index id *)            val sxn = length sizes (*next available index id *)
271            val (probe', vKs) = fieldReconstruction (avail, dim, sxn, alpha', dx, Vid, nid, vH, vF, kid)        val (probe', vKs) = fieldReconstruction (avail, dim, sxn, alpha', dx, Vid, nid, vH, vF, nid)
272        val args' = args@(vN::vKs)        val args' = List.nth(args,Vid) :: vN ::vKs
273            val einApp1 = IR.EINAPP(mkEin(params', sizes, probe'), args')            val einApp1 = IR.EINAPP(mkEin(params'@[E.TEN(true,[10])], sizes, probe'), args')
274    
275    
276            in            in
277          AvailRHS.addAssignsToList(avail, (vF, einApp1) :: rtn0)        List.app (fn e => AvailRHS.addAssignToList(avail, e)) (((vT, einApp1)::(rtn0)))
278            end            end
279  *)  
280    
281    (* expandEinOp: code->  code list    (* expandEinOp: code->  code list
282     * A this point we only have simple ein ops     * A this point we only have simple ein ops
# Line 277  Line 285 
285      fun expand avail (e as (_, IR.EINAPP(Ein.EIN{body, ...}, _))) = (case body      fun expand avail (e as (_, IR.EINAPP(Ein.EIN{body, ...}, _))) = (case body
286             of (E.Probe(E.Conv(_, _, _, []) ,_)) =>             of (E.Probe(E.Conv(_, _, _, []) ,_)) =>
287                  replaceProbe (avail, e, body, [])                  replaceProbe (avail, e, body, [])
288          | (E.Probe _) =>         (* | (E.Probe _) =>
289          replaceProbe (avail, e, body, [])          replaceProbe (avail, e, body, [])
290          (*FIXME: Only use replaceProbe while trying to isolate valnum bug*)          (*FIXME: Only use replaceProbe while trying to isolate valnum bug*)
291          (*          *)
292              | (E.Probe(E.Conv(_, alpha, _, dx) ,_)) =>              | (E.Probe(E.Conv(_, alpha, _, dx) ,_)) =>
293                  liftProbe (avail, e, body, []) (*scans dx for contant*)                  liftProbe (avail, e, body, []) (*scans dx for contant*)
294          *)  
295              | (E.Sum(sx, p as E.Probe(E.Conv(_, _, _, []), _))) =>              | (E.Sum(sx, p as E.Probe(E.Conv(_, _, _, []), _))) =>
296                  replaceProbe (avail, e, p, sx)  (*no dx*)                  replaceProbe (avail, e, p, sx)  (*no dx*)
297          (*  
298              | (E.Sum(sx, p as E.Probe(E.Conv(_, [], _, dx), _))) =>              | (E.Sum(sx, p as E.Probe(E.Conv(_, [], _, dx), _))) =>
299                  liftProbe (avail, e, p, sx) (*scalar field*)                  liftProbe (avail, e, p, sx) (*scalar field*)
300          *)  
301              | (E.Sum(sx, E.Probe p)) =>              | (E.Sum(sx, E.Probe p)) =>
302                  replaceProbe (avail, e, E.Probe p, sx)                  replaceProbe (avail, e, E.Probe p, sx)
303              | (E.Sum(sx, E.Opn(E.Prod, [eps, E.Probe p]))) =>              | (E.Sum(sx, E.Opn(E.Prod, [eps, E.Probe p]))) =>

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

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