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

SCM Repository

[diderot] Diff of /branches/charisee_dev/src/compiler/high-to-mid/ProbeEin.sml
ViewVC logotype

Diff of /branches/charisee_dev/src/compiler/high-to-mid/ProbeEin.sml

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

revision 2679, Tue Jul 29 04:18:35 2014 UTC revision 2680, Wed Aug 6 00:51:53 2014 UTC
# Line 58  Line 58 
58      "but found ", SrcIL.vbToString vb])      "but found ", SrcIL.vbToString vb])
59      (* end case *))      (* end case *))
60    
61    fun getRHSDst x  = (case DstIL.Var.binding x
62    of DstIL.VB_RHS(DstIL.OP(rator, args)) => (O rator, args)
63    | DstIL.VB_RHS(DstIL.VAR x') => getRHSDst x'
64    | DstIL.VB_RHS(DstIL.EINAPP (e,args))=>(E e,args)
65    | DstIL.VB_RHS(DstIL.CONS (ty,args))=>(C ty,args)
66    | DstIL.VB_NONE=>(S 2,[])
67    | vb => raise Fail(concat[
68    "expected rhs operator for ", DstIL.Var.toString x,
69    "but found ", DstIL.vbToString vb])
70    (* end case *))
71    
72    
73    
74    
75    
76    
77  (*Create fractional, and integer position vectors*)  (*Create fractional, and integer position vectors*)
78  fun transformToImgSpace  (dim,v,posx)=let  fun transformToImgSpace  (dim,v,posx,varII)=let
79    
80      val translate=DstOp.Translate v      val translate=DstOp.Translate v
81      val transform=DstOp.Transform v      val transform=DstOp.Transform v
82      val M  = DstV.new ("M", DstTy.tensorTy [dim,dim])   (*transform dim by dim?*)      val M  = DstV.new ("M", DstTy.tensorTy [dim,dim])   (*transform dim by dim?*)
83    
84      val T  = DstV.new ("T", DstTy.tensorTy [dim,dim])   (*translate*)      val T  = DstV.new ("T", DstTy.tensorTy [dim])   (*translate*)
85      val x  = DstV.new ("x", DstTy.vecTy dim)            (*Image-Space position*)      val x  = DstV.new ("x", DstTy.vecTy dim)            (*Image-Space position*)
86    
87        val xA  = DstV.new ("xA", DstTy.vecTy dim)            (*Image-Space position*)
88       (* val xB  = DstV.new ("xB", DstTy.vecTy dim)            (*Image-Space position*)*)
89      val f  = DstV.new ("f", DstTy.vecTy dim)            (*fractional*)      val f  = DstV.new ("f", DstTy.vecTy dim)            (*fractional*)
90      val nd = DstV.new ("nd", DstTy.vecTy dim)           (*real position*)      val nd = DstV.new ("nd", DstTy.vecTy dim)           (*real position*)
91      val n  = DstV.new ("n", DstTy.iVecTy dim)           (*integer position*)      val n  = DstV.new ("n", DstTy.iVecTy dim)           (*integer position*)
92      val PosToImgSpace=mk.transform(dim,dim)      val PosToImgSpace=mk.transform(dim,dim)
93    
94         val PosToImgSpaceA=mk.transformA(dim,dim)
95         val PosToImgSpaceB=mk.transformB(dim,dim)
96      val P  = DstV.new ("P", DstTy.tensorTy [dim,dim])   (*transform dim by dim?*)      val P  = DstV.new ("P", DstTy.tensorTy [dim,dim])   (*transform dim by dim?*)
97    
98      val code=[      val code=[
99          assign(M, transform, []),          assign(M, transform, [varII]),
100          assign(T, translate, []),          assign(T, translate, [varII]),
101          assignEin(x, PosToImgSpace,[M,posx,T]) ,  (* MX+T*)          assignEin(x, PosToImgSpace,[M,posx,T]) ,  (* MX+T*)
102    
103    (*          assignEin(xA, PosToImgSpaceA,[M,posx,T]) ,  (* MX*)
104            assignEin(x, PosToImgSpaceB,[xA,T]) ,  (* ^+T*)*)
105          assign(nd, DstOp.Floor dim, [x]),   (*nd *)          assign(nd, DstOp.Floor dim, [x]),   (*nd *)
106          assignEin(f, mk.subTen([dim]),[x,nd]),           (*fractional*)          assignEin(f, mk.subTen([dim]),[x,nd]),           (*fractional*)
107          assign(n, DstOp.RealToInt dim, [nd]), (*real to Int*)          assign(n, DstOp.RealToInt dim, [nd]), (*real to Int*)
# Line 93  Line 116 
116      val l2=List.drop(args,place+1)      val l2=List.drop(args,place+1)
117      in l1@[kvar]@l2 end      in l1@[kvar]@l2 end
118    
119    fun getImageSrc x  = (case SrcIL.Var.binding x
120    of SrcIL.VB_RHS(SrcIL.OP(SrcOp.LoadImage(img),[ivar])) =>
121            (print(String.concat["\n MOUSE-TOP::","---",SrcIL.Var.toString(ivar)]))
122    | vb => print "not imgae op"
123    (* end case *))
124    
125    fun getImageDst x  = (case DstIL.Var.binding x
126    of DstIL.VB_RHS(DstIL.OP(DstOp.LoadImage(img),[ivar])) =>
127    (print(String.concat["\n MOUSE-Orig:","---",DstIL.Var.toString(x),"\n MOUSE-BOT:","---",DstIL.Var.toString(ivar)]);ivar)
128    | vb => raise Fail  "not load op"
129    (* end case *))
130    
131    
132    
133  (*Get Img, and Kern Args*)  (*Get Img, and Kern Args*)
134  fun getArgs(hid,hArg,V,imgArg,args,lift)=case (getRHS hArg,getRHS imgArg)  fun getArgs(hid,hArg,V,imgArg,args,lift,varI)=case (getRHS hArg,getRHS imgArg)
135      of ((O2(SrcOp.Kernel(h, i)),argK),(O2(SrcOp.LoadImage img),_))=> let      of ((O2(SrcOp.Kernel(h, i)),argK),(O2(SrcOp.LoadImage img),[yy]))=> let
136          val hvar=DstV.new ("KNL", DstTy.KernelTy)          val hvar=DstV.new ("KNL", DstTy.KernelTy)
137          val imgvar=DstV.new ("IMG", DstTy.ImageTy img)          val imgvar=DstV.new ("IMG", DstTy.ImageTy img)
138          val argsVK= (case lift          val argsVK= (case lift
139              of 0=> let              of 0=> let
140                    val _=print "non lift"
141                  val argsN=replaceH(hvar, hid,args)                  val argsN=replaceH(hvar, hid,args)
142                  in replaceH(imgvar, V,argsN) end                  in (*replaceH(imgvar, V,argsN)*) replaceH(varI, V,argsN) end
143              | _ => [imgvar, hvar]              | _ =>(* [imgvar, hvar]*) [varI, hvar]
144          (* end case *))          (* end case *))
         val assigments=[assign (hvar, DstOp.Kernel(h, i), []), assign(imgvar,DstOp.LoadImage img,[])]  
145    
146              (*val Vimg= assign(imgvar,DstOp.LoadImage img, varI)*)
147    
148            val assigments=[assign (hvar, DstOp.Kernel(h, i), [])]
149          in          in
150              (Kernel.support h ,img, assigments,argsVK)              (Kernel.support h ,img, assigments,argsVK)
151          end          end
# Line 114  Line 153 
153      |  _ => raise Fail "Not a kernel argument"      |  _ => raise Fail "Not a kernel argument"
154    
155    
156  fun handleArgs(V,h,t,(params,args),origargs,lift)=let  fun handleArgs(V,h,t,(params,args),origargs,lift,dstargs)=let
157      val E.IMG(dim)=List.nth(params,V)      val E.IMG(dim)=List.nth(params,V)
158      val kArg=List.nth(origargs,h)      val kArg=List.nth(origargs,h)
159      val imgArg=List.nth(origargs,V)      val imgArg=List.nth(origargs,V)
160      val newposArg=List.nth(args, t)      val newposArg=List.nth(args, t)
161      val (s,img,argcode,argsVH) =getArgs(h,kArg,V,imgArg,args,lift)      val imgArgDst=List.nth(dstargs,V)
162      val (argsT,P,code')=transformToImgSpace(dim,img,newposArg)      val (s,img,argcode,argsVH) =getArgs(h,kArg,V,imgArg,args,lift,imgArgDst)
163        val varII =getImageDst imgArgDst
164    
165        val (argsT,P,code')=transformToImgSpace(dim,img,newposArg,varII)
166      in (dim,argsVH@argsT,argcode@code', s,P)      in (dim,argsVH@argsT,argcode@code', s,P)
167      end      end
168    
# Line 166  Line 208 
208      | mapIndex(E.C c::es,index) = mapIndex(es,index)      | mapIndex(E.C c::es,index) = mapIndex(es,index)
209    
210    
211    (*
212  (*Lift probe and Multiply by P*)  (*Lift probe and Multiply by P*)
213  fun liftProbe(E.Probe(E.Conv(V,alpha,H,dx),E.Tensor(t,_)),(params,args),index, sumIndex,origargs)=let  fun liftProbe(E.Probe(E.Conv(V,alpha,H,dx),E.Tensor(t,_)),(params,args),index, sumIndex,origargs)=let
214      val _ =print "Lift Probe"      val _ =print "Lift Probe"
# Line 225  Line 268 
268      end      end
269   |liftProbe _ =raise Fail"Incorrect body for Probe"   |liftProbe _ =raise Fail"Incorrect body for Probe"
270    
271    *)
272    
273    
274    
275  (*Does not yet do transformation*)  (*Does not yet do transformation*)
276   (* Expand probe in place *)   (* Expand probe in place *)
277   fun replaceProbe(b,(params,args),index, sumIndex,origargs)=let   fun replaceProbe(b,(params,args),index, sumIndex,origargs,dstargs)=let
278    
279      val E.Probe(E.Conv(V,alpha,h,dx),E.Tensor(t,_))=b      val E.Probe(E.Conv(V,alpha,h,dx),E.Tensor(t,_))=b
280      val fid=length(params)      val fid=length(params)
# Line 254  Line 299 
299      val Vshapebind= mapIndex(VShape,index)      val Vshapebind= mapIndex(VShape,index)
300    
301    
302      val (dim,argsA,code,s,PArg) = handleArgs(V,h,t,(params,args), origargs,0)      val (dim,argsA,code,s,PArg) = handleArgs(V,h,t,(params,args), origargs,0,dstargs)
303      val (_,_,dx, _,sxT,restT,_,_) = T.Transform(dx,shapebind,Vshapebind,dim,PArg,nsumshift,1,nid+1)      val (_,_,dx, _,sxT,restT,_,_) = T.Transform(dx,shapebind,Vshapebind,dim,PArg,nsumshift,1,nid+1)
304    
305      val params'=params@[E.TEN(3,[dim]),E.TEN(1,[dim]),E.TEN(1,[dim,dim])]      val params'=params@[E.TEN(3,[dim]),E.TEN(1,[dim]),E.TEN(1,[dim,dim])]
# Line 276  Line 321 
321      in (body',(params',args') ,code)      in (body',(params',args') ,code)
322      end      end
323    
324    (*
325  (*Checks if (1) Summation variable occurs just once (2) it matches n.  (*Checks if (1) Summation variable occurs just once (2) it matches n.
326  Then we lift otherwise expand in place *)  Then we lift otherwise expand in place *)
327  fun checkSum(sx,b,info,index,origargs)=(case sx  fun checkSum(sx,b,info,index,origargs)=(case sx
# Line 294  Line 340 
340          end          end
341      | _ =>replaceProbe(b, info,index, sx,origargs)      | _ =>replaceProbe(b, info,index, sx,origargs)
342      (*end case*))      (*end case*))
343    *)
344    
345  fun flatten []=[]  fun flatten []=[]
346      | flatten(e1::es)=e1@(flatten es)      | flatten(e1::es)=e1@(flatten es)
# Line 343  Line 389 
389                      of  (* [] => liftProbe(E.Probe(E.Conv v, E.Tensor t ), info,index, c,origargs)                      of  (* [] => liftProbe(E.Probe(E.Conv v, E.Tensor t ), info,index, c,origargs)
390                        | [i]=> checkSum(i,b, info,index,origargs)                        | [i]=> checkSum(i,b, info,index,origargs)
391                        |*) _ => let                        |*) _ => let
392                          val (b,m,code)=replaceProbe(E.Probe(E.Conv v, E.Tensor t ), info,index, (flatten sx)@c,origargs)                          val (b,m,code)=replaceProbe(E.Probe(E.Conv v, E.Tensor t ), info,index, (flatten sx)@c,origargs,args)
393                          in (E.Sum(c,b),m,code)                          in (E.Sum(c,b),m,code)
394                          end                          end
395                  (* end case*))                  (* end case*))
# Line 353  Line 399 
399              in (case sx              in (case sx
400                  of (* []=> liftProbe(b, info,index, [],origargs)                  of (* []=> liftProbe(b, info,index, [],origargs)
401                  | [i]=> checkSum(i,b, info,index,origargs)                  | [i]=> checkSum(i,b, info,index,origargs)
402                  |*) _ => replaceProbe(b, info,index, flatten sx,origargs)                  |*) _ => replaceProbe(b, info,index, flatten sx,origargs,args)
403               (* end case*))               (* end case*))
404              end              end
405          | E.Probe _=> (dummy,info,[])          | E.Probe _=> (dummy,info,[])

Legend:
Removed from v.2679  
changed lines
  Added in v.2680

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