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 2844, Tue Dec 9 18:05:29 2014 UTC revision 2845, Fri Dec 12 06:46:23 2014 UTC
# Line 1  Line 1 
1  (* Currently under construction  (* Expands probe ein
2   *   *
3   * COPYRIGHT (c) 2012 The Diderot Project (http://diderot-language.cs.uchicago.edu)   * COPYRIGHT (c) 2012 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4   * All rights reserved.   * All rights reserved.
# Line 9  Line 9 
9      local      local
10    
11      structure E = Ein      structure E = Ein
     structure mk= mkOperators  
     structure SrcIL = HighIL  
     structure SrcTy = HighILTypes  
     structure SrcOp = HighOps  
     structure SrcSV = SrcIL.StateVar  
     structure VTbl = SrcIL.Var.Tbl  
12      structure DstIL = MidIL      structure DstIL = MidIL
     structure DstTy = MidILTypes  
13      structure DstOp = MidOps      structure DstOp = MidOps
     structure DstV = DstIL.Var  
     structure SrcV = SrcIL.Var  
14      structure P=Printer      structure P=Printer
15      structure T=TransformEin      structure T=TransformEin
16      structure split=Split      structure MidToS=MidToString
     structure cleanI=cleanIndex  
   
   
     val testing=1  
   
   
17      in      in
18    
   
19  (* This file expands probed fields  (* This file expands probed fields
20    * Take a look at ProbeEin tex file for examples
21  *Note that the original field is an EIN operator in the form <V_alpha * H^(deltas)>(midIL.var list )  *Note that the original field is an EIN operator in the form <V_alpha * H^(deltas)>(midIL.var list )
22  * Param_ids are used to note the placement of the argument in the midIL.var list  * Param_ids are used to note the placement of the argument in the midIL.var list
23  * Index_ids  keep track of the shape of an Image or differentiation.  * Index_ids  keep track of the shape of an Image or differentiation.
# Line 49  Line 34 
34  *img-imginfo about V  *img-imginfo about V
35  *)  *)
36    
37        val testing=0
38  val cnt = ref 0  val cnt = ref 0
 fun genName prefix = let  
 val n = !cnt  
 in  
 cnt := n+1;  
 String.concat[prefix, "_", Int.toString n]  
 end  
   
39    
40  fun transformToIndexSpace e=T.transformToIndexSpace e  fun transformToIndexSpace e=T.transformToIndexSpace e
41  fun transformToImgSpace  e=T.transformToImgSpace  e  fun transformToImgSpace  e=T.transformToImgSpace  e
 fun assign (x, rator, args) = (x, DstIL.OP(rator, args))  
 fun assignEin (x, rator, args) = ((x, DstIL.EINAPP(rator, args)))  
42  fun testp n=(case testing  fun testp n=(case testing
43      of 0=> 1      of 0=> 1
44      | _ =>(print(String.concat n);1)      | _ =>(print(String.concat n);1)
# Line 75  Line 51 
51    
52    
53  (* getArgsDst:MidIL.Var* MidIL.Var->int, ImageInfo, int  (* getArgsDst:MidIL.Var* MidIL.Var->int, ImageInfo, int
54      uses the Param_ids for the image, kernel, and position tensor to get the Mid-IL arguments          uses the Param_ids for the image, kernel,
55            and position tensor to get the Mid-IL arguments
56    returns the support of ther kernel, and image    returns the support of ther kernel, and image
57  *)  *)
58   fun getArgsDst(hArg,imgArg,args)=(case (getRHSDst hArg,getRHSDst imgArg)   fun getArgsDst(hArg,imgArg,args)=(case (getRHSDst hArg,getRHSDst imgArg)
# Line 87  Line 64 
64   (*end case*))   (*end case*))
65    
66    
67  (*handleArgs():int*int*int*Mid IL.Var list ->int*Mid.ILVars list* code*int* low-il-var      (*handleArgs():int*int*int*Mid IL.Var list
68  * uses the Param_ids for the image, kernel, and tensor and gets the mid-IL vars for each          ->int*Mid.ILVars list* code*int* low-il-var
69            * uses the Param_ids for the image, kernel, and tensor
70            * and gets the mid-IL vars for each.
71  *Transforms the position to index space  *Transforms the position to index space
72  *P-mid-il var for the (transformation matrix)transpose          *P is the mid-il var for the (transformation matrix)transpose
73  *)  *)
74  fun handleArgs(Vid,hid,tid,args)=let  fun handleArgs(Vid,hid,tid,args)=let
75      val imgArg=List.nth(args,Vid)      val imgArg=List.nth(args,Vid)
# Line 98  Line 77 
77      val newposArg=List.nth(args,tid)      val newposArg=List.nth(args,tid)
78      val (s,img,dim) =getArgsDst(hArg,imgArg,args)      val (s,img,dim) =getArgsDst(hArg,imgArg,args)
79      val (argsT,P,code)=transformToImgSpace(dim,img,newposArg,imgArg)      val (argsT,P,code)=transformToImgSpace(dim,img,newposArg,imgArg)
80      in (dim,args@argsT,code, s,P)          in
81                (dim,args@argsT,code, s,P)
82      end      end
83    
   
84  (*createBody:int*int*int,mu list, param_id, param_id, param_id, param_id  (*createBody:int*int*int,mu list, param_id, param_id, param_id, param_id
85  * expands the body for the probed field  * expands the body for the probed field
86  *)  *)
87  fun createBody(dim, s,sx,alpha,deltas,Vid, hid, nid, fid)=let  fun createBody(dim, s,sx,alpha,deltas,Vid, hid, nid, fid)=let
   
88      (*1-d fields*)      (*1-d fields*)
89      fun createKRND1 ()=let      fun createKRND1 ()=let
90          val sum=sx          val sum=sx
# Line 115  Line 93 
93          val rest= E.Krn(hid,dels,E.Sub(E.Tensor(nid,[]),E.Value(sum)))          val rest= E.Krn(hid,dels,E.Sub(E.Tensor(nid,[]),E.Value(sum)))
94          in          in
95              E.Prod [E.Img(Vid,alpha,pos),rest]              E.Prod [E.Img(Vid,alpha,pos),rest]
   
96          end          end
97      (*createKRN Image field and kernels *)      (*createKRN Image field and kernels *)
98      fun createKRN(0,imgpos,rest)=E.Prod ([E.Img(Vid,alpha,imgpos)] @rest)      fun createKRN(0,imgpos,rest)=E.Prod ([E.Img(Vid,alpha,imgpos)] @rest)
# Line 132  Line 109 
109          of 1 => createKRND1()          of 1 => createKRND1()
110          | _=> createKRN(dim, [],[])          | _=> createKRN(dim, [],[])
111          (*end case*))          (*end case*))
   
112      (*sumIndex creating summaiton Index for body*)      (*sumIndex creating summaiton Index for body*)
113      val slb=1-s      val slb=1-s
114      val esum=List.tabulate(dim, (fn dim=>(E.V (dim+sx),slb,s)))      val esum=List.tabulate(dim, (fn dim=>(E.V (dim+sx),slb,s)))
# Line 152  Line 128 
128              end              end
129          (* end case *))          (* end case *))
130      val aa=List.map (fn (E.V v,_,_)=>Int.toString v) sx      val aa=List.map (fn (E.V v,_,_)=>Int.toString v) sx
131      val _ =testp["\n", "SumIndex" ,(String.concatWith"," aa),"\nThink nshift is ", Int.toString nsumshift]          val _ =testp["\n", "SumIndex" ,(String.concatWith"," aa),
132                "\nThink nshift is ", Int.toString nsumshift]
133      in      in
134          nsumshift          nsumshift
135      end      end
# Line 165  Line 142 
142  | formBody(E.Prod [e])=e  | formBody(E.Prod [e])=e
143  | formBody e=e  | formBody e=e
144    
145        (* replaceProbe:ein_exp* params *midIL.var list * int list* sum_id list
146  (* replaceProbe:ein_exp* params *midIL.var list * int list* sum_id list :ein_exp* *code              -> ein_exp* *code
147  * Transforms position to world space  * Transforms position to world space
148  * transforms result back to index_space  * transforms result back to index_space
149  * rewrites body  * rewrites body
150  * replace probe with expanded version  * replace probe with expanded version
151  *)  *)
152   fun replaceProbe(b,params,args,index, sx)=let   fun replaceProbe(b,params,args,index, sx)=let
   
153      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
154      val fid=length(params)      val fid=length(params)
155      val nid=fid+1      val nid=fid+1
# Line 190  Line 166 
166          (body',params',args' ,code)          (body',params',args' ,code)
167      end      end
168    
   
169  (* expandEinOp: code->  code list  (* expandEinOp: code->  code list
170  *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.
171  * Note how we keeps eps type expressions so we have less time in mid-to-low-il stage      * Note how we keeps eps expressions so only generate pieces that are used
172  *)  *)
173  fun expandEinOp( e as (y, DstIL.EINAPP(Ein.EIN{params, index, body}, args))) = let  fun expandEinOp( e as (y, DstIL.EINAPP(Ein.EIN{params, index, body}, args))) = let
174      fun printResult code=testp["\nINSIDE PROBEEIN","\nbody",split.printEINAPP e, "\n=>\n",          fun printResult code=testp["\nINSIDE PROBEEIN","\nbody",
175      (String.concatWith",\t"(List.map split.printEINAPP code))]                  MidToS.printEINAPP e, "\n=>\n",
176                    (String.concatWith",\t"(List.map MidToS.printEINAPP code))]
177      fun rewriteBody b=(case b      fun rewriteBody b=(case b
178          of  E.Probe e =>let          of  E.Probe e =>let
179              val (body',params',args',newbies)=replaceProbe(E.Probe e,params,args, index, [])              val (body',params',args',newbies)=replaceProbe(E.Probe e,params,args, index, [])
# Line 229  Line 204 
204          rewriteBody body          rewriteBody body
205      end      end
206    
   
   
207    end; (* local *)    end; (* local *)
208    
209  end (* local *)  end (* local *)

Legend:
Removed from v.2844  
changed lines
  Added in v.2845

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