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 2923, Tue Mar 3 15:33:44 2015 UTC revision 2976, Fri Mar 6 16:37:08 2015 UTC
# Line 14  Line 14 
14      structure P=Printer      structure P=Printer
15      structure T=TransformEin      structure T=TransformEin
16      structure MidToS=MidToString      structure MidToS=MidToString
17        structure DstV = DstIL.Var
18        structure DstTy = MidILTypes
19    
20      in      in
21    
22      (* This file expands probed fields      (* This file expands probed fields
# Line 142  Line 145 
145      | formBody(E.Prod [e])=e      | formBody(E.Prod [e])=e
146      | formBody e=e      | formBody e=e
147    
148        (* silly change in order of the product to match vis branch WorldtoSpace functions*)
149        fun multiPs([P0,P1,P2],sx,body)= formBody(E.Sum(sx, E.Prod([P0,P1,P2,body])))
150          | multiPs(Ps,sx,body)=formBody(E.Sum(sx, E.Prod([body]@Ps)))
151    
152      (* replaceProbe:ein_exp* params *midIL.var list * int list* sum_id list      (* replaceProbe:ein_exp* params *midIL.var list * int list* sum_id list
153              -> ein_exp* *code              -> ein_exp* *code
154      * Transforms position to world space      * Transforms position to world space
# Line 150  Line 157 
157      * replace probe with expanded version      * replace probe with expanded version
158      *)      *)
159      fun replaceProbe(b,params,args,index, sx)=let      fun replaceProbe(b,params,args,index, sx)=let
160            val _=print(String.concat["\n Replace probe:\n",P.printbody b])
161          val E.Probe(E.Conv(Vid,alpha,hid,dx),E.Tensor(tid,_))=b          val E.Probe(E.Conv(Vid,alpha,hid,dx),E.Tensor(tid,_))=b
162          val fid=length(params)          val fid=length(params)
163          val nid=fid+1          val nid=fid+1
# Line 160  Line 168 
168          val (dx,newsx1,Ps)=transformToIndexSpace(freshIndex,dim,dx,Pid)          val (dx,newsx1,Ps)=transformToIndexSpace(freshIndex,dim,dx,Pid)
169          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])]
170          val body' = createBody(dim, s,freshIndex+nshift,alpha,dx,Vid, hid, nid, fid)          val body' = createBody(dim, s,freshIndex+nshift,alpha,dx,Vid, hid, nid, fid)
171            val body' = multiPs(Ps,newsx1,body')
         (*silly change in order of product to match vis branch WorldtoSpace functions*)  
         val body' =(case Ps  
             of [_,_,_]=>        formBody(E.Sum(newsx1, E.Prod(Ps@[body'])))  
             | _ =>  formBody(E.Sum(newsx1, E.Prod([body']@Ps)))  
             (*end case*))  
172          val args'=argsA@[PArg]          val args'=argsA@[PArg]
173          in          in
174              (body',params',args' ,code)              (body',params',args' ,code)
175          end          end
176    
177        fun mkEin(params,index,body)=E.EIN{params=params, index=index,body=body}
178        fun mkEinApp(rator,args)=DstIL.EINAPP(rator,args)
179    
180        fun createEinApp(alpha,index,freshIndex,dim,dx)= let
181            val Pid=0
182            val tid=1
183    
184            val (newdx,newsx,Ps)=transformToIndexSpace(freshIndex,dim,dx,Pid)
185            val params=[E.TEN(1,[dim,dim]),E.TEN(1,index)]
186            val t=E.Tensor(tid,alpha@newdx)
187            val body = multiPs(Ps,newsx,t)
188            val rator=mkEin(params,index,body)
189            in
190                rator
191            end
192    
193    
194    
195        fun liftProbe(y,b,params,args,index, sx)=let
196            val E.Probe(E.Conv(Vid,alpha,hid,dx),E.Tensor(tid,_))=b
197            val fid=length(params)
198            val nid=fid+1
199            val nshift=length(dx)
200            val (dim,argsA,code,s,PArg) = handleArgs(Vid,hid,tid,args)
201            val freshIndex=getsumshift(sx,index)
202    
203    
204            (*transform T*P*P..Ps*)
205            val FArg  = DstV.new ("F", DstTy.TensorTy(index))
206            val rator=createEinApp(alpha,index,freshIndex,dim,dx)
207            val einApp0=mkEinApp(rator,[PArg,FArg])
208    
209    
210            (*lifted probe*)
211            val params'=params@[E.TEN(3,[dim]),E.TEN(1,[dim])]
212            val body' = createBody(dim, s,freshIndex+nshift,alpha,dx,Vid, hid, nid, fid)
213            val args'=argsA
214            val ein1=mkEin(params', index,body')
215            val einApp1=mkEinApp(ein1,args')
216    
217            val rtn=code@[(FArg,einApp1),(y,einApp0)]
218    
219    
220            in
221                rtn
222            end
223    
224    
225      (* expandEinOp: code->  code list      (* expandEinOp: code->  code list
226      *Looks to see if the expression has a probe. If so, replaces it.      *Looks to see if the expression has a probe. If so, replaces it.
227      * Note how we keeps eps expressions so only generate pieces that are used      * Note how we keeps eps expressions so only generate pieces that are used
228      *)      *)
229      fun expandEinOp( e as (y, DstIL.EINAPP(ein as Ein.EIN{params, index, body}, args))) = let      fun expandEinOp( e as (y, DstIL.EINAPP(ein as Ein.EIN{params, index, body}, args))) = let
230          fun rewriteBody b=(case b          fun rewriteBody b=(case b
231              of E.Probe(E.Field _,_)=> raise Fail"Poorly formed EIN operator. Argument needs to be applied in High-IL"              of E.Probe(E.Field _,_)=> raise Fail"Poorly formed EIN operator."
232              | E.Probe e =>let              | E.Probe(E.Conv(_,_,_,[]),_) =>let
233                    val (body',params',args',newbies)=replaceProbe(b,params,args, index, [])
                 val (body',params',args',newbies)=replaceProbe(E.Probe e,params,args, index, [])  
234                  val einapp=(y,DstIL.EINAPP(Ein.EIN{params=params', index=index, body=body'},args'))                  val einapp=(y,DstIL.EINAPP(Ein.EIN{params=params', index=index, body=body'},args'))
235                  val code=newbies@[einapp]                  val code=newbies@[einapp]
   
236                  in                  in
237                      code                      code
238                  end                  end
239                | E.Probe(E.Conv _,_) =>liftProbe(y,b,params,args, index, [])
240              | E.Sum(sx,E.Probe e)  =>let              | E.Sum(sx,E.Probe e)  =>let
241    
242                  val (body',params',args',newbies)=replaceProbe(E.Probe e,params,args, index, sx)                  val (body',params',args',newbies)=replaceProbe(E.Probe e,params,args, index, sx)

Legend:
Removed from v.2923  
changed lines
  Added in v.2976

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