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 2829, Wed Nov 12 23:24:38 2014 UTC revision 2830, Tue Nov 18 17:48:05 2014 UTC
# Line 50  Line 50 
50      | _ =>(print(String.concat n);1)      | _ =>(print(String.concat n);1)
51      (*end case*))      (*end case*))
52    
53  (*Create fractional, and integer position vectors*)  (*transform image-space position x to world space position*)
54  fun transformToImgSpace  (dim,v,posx,imgArgDst)=let  fun WorldToImagespace(dim,v,posx,imgArgDst)=let
55      val translate=DstOp.Translate v      val translate=DstOp.Translate v
56      val transform=DstOp.Transform v      val transform=DstOp.Transform v
57      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?*)
58      val T  = DstV.new ("T", DstTy.tensorTy [dim])   (*translate*)      val T  = DstV.new ("T", DstTy.tensorTy [dim])   (*translate*)
59      val x  = DstV.new ("x", DstTy.vecTy dim)            (*Image-Space position*)      val x  = DstV.new ("x", DstTy.vecTy dim)            (*Image-Space position*)
60      val x0  = DstV.new ("x0", DstTy.vecTy dim)      val x0  = DstV.new ("x0", DstTy.vecTy dim)
     val x1  = DstV.new ("x1", DstTy.vecTy dim)  
     val f  = DstV.new ("f", DstTy.vecTy dim)            (*fractional*)  
     val nd = DstV.new ("nd", DstTy.vecTy dim)           (*real position*)  
     val n  = DstV.new ("n", DstTy.iVecTy dim)           (*integer position*)  
     val PosToImgSpace=mk.transform(dim,dim)  
61      val PosToImgSpaceA=mk.transformA(dim,dim)      val PosToImgSpaceA=mk.transformA(dim,dim)
62      val PosToImgSpaceB=mk.transformB dim      val PosToImgSpaceB=mk.transformB dim
     val P  = DstV.new ("P", DstTy.tensorTy [dim,dim])   (*transform dim by dim?*)  
63      val code=[      val code=[
64          assign(M, transform, [imgArgDst]),          assign(M, transform, [imgArgDst]),
65          assign(T, translate, [imgArgDst]),          assign(T, translate, [imgArgDst]),
66          (*assignEin(x, PosToImgSpace,[M,posx,T]) ,  (* MX+T*)*)          assignEin(x0, PosToImgSpaceA,[M,posx]) , (*xo=MX*)
67          assignEin(x0, PosToImgSpaceA,[M,posx]) ,          assignEin(x, PosToImgSpaceB,[x0,T])  (*x=x0+T*)
68          assignEin(x, PosToImgSpaceB,[x0,T]) ,          ]
69        in (M,x,code)
70        end
71    
72    
73    (*Create fractional, and integer position vectors*)
74    fun transformToImgSpace  (dim,v,posx,imgArgDst)=let
75    
76        val f  = DstV.new ("f", DstTy.vecTy dim)            (*fractional*)
77        val nd = DstV.new ("nd", DstTy.vecTy dim)           (*real position*)
78        val n  = DstV.new ("n", DstTy.iVecTy dim)           (*integer position*)
79        val P  = DstV.new ("P", DstTy.tensorTy [dim,dim])   (*transform dim by dim?*)
80    
81        val (M,x,code1)=WorldToImagespace(dim,v,posx,imgArgDst)
82        val code=[
83          assign(nd, DstOp.Floor dim, [x]),   (*nd *)          assign(nd, DstOp.Floor dim, [x]),   (*nd *)
84          assignEin(f, mk.subTen([dim]),[x,nd]),           (*fractional*)          assignEin(f, mk.subTen([dim]),[x,nd]),           (*fractional*)
85          assign(n, DstOp.RealToInt dim, [nd]), (*real to Int*)          assign(n, DstOp.RealToInt dim, [nd]), (*real to Int*)
86          assignEin(P, mk.transpose([dim,dim]), [M])          assignEin(P, mk.transpose([dim,dim]), [M])
87          ]          ]
88      in ([n,f],P,code)      in ([n,f],P,code1@code)
89      end      end
90    
91  fun getRHS x  = (case SrcIL.Var.binding x  fun getRHS x  = (case SrcIL.Var.binding x
# Line 111  Line 118 
118      (*end case*))      (*end case*))
119    
120    
121  fun handleArgs(V,h,t,(params,args),origargs,lift,dstargs)=let  fun handleArgs(V,h,t,args,origargs,lift,dstargs)=let
122      val E.IMG(dim)=List.nth(params,V)  
123      val kArg=List.nth(origargs,h)      val kArg=List.nth(origargs,h)
124      val imgArg=List.nth(origargs,V)      val imgArg=List.nth(origargs,V)
125      val newposArg=List.nth(args, t)      val newposArg=List.nth(args, t)
126      val imgArgDst=List.nth(dstargs,V)      val imgArgDst=List.nth(dstargs,V)
127      val (s,img,argcode,argsVH) =getArgs(h,kArg,V,imgArg,args,lift,imgArgDst)      val (s,img,argcode,argsVH) =getArgs(h,kArg,V,imgArg,args,lift,imgArgDst)
128        val dim=ImageInfo.dim img
129      val (argsT,P,code')=transformToImgSpace(dim,img,newposArg,imgArgDst)      val (argsT,P,code')=transformToImgSpace(dim,img,newposArg,imgArgDst)
130      in (dim,argsVH@argsT,argcode@code', s,P)      in (dim,argsVH@argsT,argcode@code', s,P)
131      end      end
132    
133    
 (*createDels=> creates the kronecker deltas for each Kernel*)  
 fun createDels([],_)= []  
     | createDels(d::ds,dim)= [( E.C dim,d)]@createDels(ds,dim)  
   
134  (*Created new body for probe*)  (*Created new body for probe*)
135  fun createBody(dim, s,sx,shape,deltas,V, h, nid, fid)=let  fun createBody(dim, s,sx,shape,deltas,V, h, nid, fid)=let
136    
# Line 139  Line 143 
143      | createKRN(dim,imgpos,rest)=let      | createKRN(dim,imgpos,rest)=let
144          val dim'=dim-1          val dim'=dim-1
145          val sum=sx+dim'          val sum=sx+dim'
146          val dels=createDels(deltas,dim')          val dels=List.map (fn e=>(E.C dim',e)) deltas
147          val pos=[E.Add[E.Tensor(fid,[E.C dim']),E.Value(sum)]]          val pos=[E.Add[E.Tensor(fid,[E.C dim']),E.Value(sum)]]
148          val rest'= E.Krn(h,dels,E.Sub(E.Tensor(nid,[E.C dim']),E.Value(sum)))          val rest'= E.Krn(h,dels,E.Sub(E.Tensor(nid,[E.C dim']),E.Value(sum)))
149          in          in
# Line 164  Line 168 
168      | mapIndex(E.C c::es,index) = mapIndex(es,index)      | mapIndex(E.C c::es,index) = mapIndex(es,index)
169    
170    
 (*  
 (*Lift probe and Multiply by P*)  
 fun liftProbe(E.Probe(E.Conv(V,alpha,H,dx),E.Tensor(t,_)),(params,args),index, sumIndex,origargs)=let  
     val _ =print "Lift Probe"  
   
     val n=length(index)  
     val ns=length sumIndex  
     val nshift=length(dx)  
     val np=length(params)  
     val nsumshift =(case ns  
         of 0=>   n  
         |_=>let  val (E.V v,_,_)=List.nth(sumIndex, ns-1)  
             in  
                 v+1  
             end  
         (* end case *))  
   
   
     (*Outer Index-id Of Probe*)  
     val VShape=ShapeConv(alpha, n)  
     val HShape=ShapeConv(dx, n)  
     val shape=VShape@HShape  
   
     (* Bindings for Shape*)  
     val shapebind= mapIndex(shape,index)  
     val Vshapebind= mapIndex(VShape,index)  
   
     (*Look at Args and get dim, mid-il ops, support, and Arg for transformation matrix P*)  
     val (dim,args',code,support,PArg) = handleArgs(V,H,t,(params,args), origargs,1)  
     val _ =print("\nSupport is "^Int.toString support)  
   
     (*New transformations:params, sx, rest, will be empty if no transformation is made*)  
     val (oldArg,newArg,dx, paramsT,sxT,restT,ixT,dataT) = T.Transform(dx,shapebind,Vshapebind,dim,PArg,nsumshift,ns,4)  
   
     (*rewriteBody*)  
     val bodyExpanded = createBody(dim, support,nsumshift+nshift,alpha,dx,0, 1, 3, 2)  
   
     val sx=sumIndex@sxT  
     val body'=(case sx  
         of [] =>E.Prod(restT@[bodyExpanded])  
         | _ => E.Sum(sx, E.Prod(restT@[bodyExpanded]))  
         (*end case*))  
   
     (*create new EIN OPerator*)  
     val _ =print("Found this many args ")  
     val _ =print(Int.toString(length(args')))  
   
     val params'=[E.IMG(dim),E.KRN,E.TEN(3,[dim]),E.TEN(1,[dim])]@paramsT  
     val (p',i',b',a')=shift.clean(params', index@ixT, body', args'@[PArg])  
     val newbie'=Ein.EIN{params=p', index=i', body=b'}  
     val data=assignEin (oldArg, newbie', a')  
   
     val _ = (case testing  
         of 0 => 1  
         | _ => (print(String.concat["\n Lift Probe\n", split.printA(newArg, newbie', a'),"\n"]);1)  
         (*end case *))  
     in  
         (E.Tensor(np,shape), (params@[E.TEN(1,shapebind)],args@[newArg]),code@[data]@dataT)  
     end  
  |liftProbe _ =raise Fail"Incorrect body for Probe"  
   
 *)  
   
171    
172   (* Expand probe in place *)   (* Expand probe in place *)
173   fun replaceProbe(b,(params,args),index, sumIndex,origargs,dstargs)=let   fun replaceProbe(b,(params,args),index, sumIndex,origargs,dstargs)=let
# Line 254  Line 195 
195      val Vshapebind= mapIndex(VShape,index)      val Vshapebind= mapIndex(VShape,index)
196    
197    
198      val (dim,argsA,code,s,PArg) = handleArgs(V,h,t,(params,args), origargs,0,dstargs)      val (dim,argsA,code,s,PArg) = handleArgs(V,h,t,args, origargs,0,dstargs)
199      val _ =testp["\nSupport is ",Int.toString s]      val _ =testp["\nSupport is ",Int.toString s]
200      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)
201    

Legend:
Removed from v.2829  
changed lines
  Added in v.2830

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