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

SCM Repository

[diderot] Diff of /branches/charisee/src/compiler/mid-to-low/step3.sml
ViewVC logotype

Diff of /branches/charisee/src/compiler/mid-to-low/step3.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 9  Line 9 
9      structure SrcIL = MidIL      structure SrcIL = MidIL
10      structure SrcOp = MidOps      structure SrcOp = MidOps
11      structure E = Ein      structure E = Ein
12      structure tS= toS      structure LowToS= LowToString
   
13    
14      in      in
15    
16  val testing=1      val testing=0
17  val bV= ref 0  val bV= ref 0
18  fun err str=raise Fail(str)  fun err str=raise Fail(str)
19  val iTy=DstTy.IntTy  val iTy=DstTy.IntTy
20  val Sca=DstTy.TensorTy []  val Sca=DstTy.TensorTy []
21  val addR=DstOp.addSca  val addR=DstOp.addSca
   
22  fun lookup k d = d k  fun lookup k d = d k
23  fun q e1=Int.toString e1  fun q e1=Int.toString e1
24    
# Line 33  Line 31 
31      if s = key then (testp[Int.toString(key),"=>",Int.toString(value)];SOME value)      if s = key then (testp[Int.toString(key),"=>",Int.toString(value)];SOME value)
32      else d s      else d s
33    
   
34  (*Get kernel and Image bindings*)  (*Get kernel and Image bindings*)
35  fun getKernel x  = (case SrcIL.Var.binding x  fun getKernel x  = (case SrcIL.Var.binding x
36      of SrcIL.VB_RHS(SrcIL.OP(SrcOp.Kernel(h, _ ) ,_ ))=> h      of SrcIL.VB_RHS(SrcIL.OP(SrcOp.Kernel(h, _ ) ,_ ))=> h
37      | vb => (err (String.concat["\n -- Not a kernel, ", SrcIL.Var.toString x," found ", SrcIL.vbToString vb,"\n"]))      | vb => (err (String.concat["\n -- Not a kernel, ", SrcIL.Var.toString x," found ", SrcIL.vbToString vb,"\n"]))
38          (* end case *))          (* end case *))
39    
   
40  fun getImageSrc x  = (case SrcIL.Var.binding x  fun getImageSrc x  = (case SrcIL.Var.binding x
41      of SrcIL.VB_RHS(SrcIL.OP(SrcOp.LoadImage img, _ )) => img      of SrcIL.VB_RHS(SrcIL.OP(SrcOp.LoadImage img, _ )) => img
42      | vb => (err (String.concat["\n -- Not an image, ", SrcIL.Var.toString x," found ", SrcIL.vbToString vb,"\n"]))      | vb => (err (String.concat["\n -- Not an image, ", SrcIL.Var.toString x," found ", SrcIL.vbToString vb,"\n"]))
# Line 50  Line 46 
46  fun aaV(opss,args,pre,ty)=let  fun aaV(opss,args,pre,ty)=let
47      val a=DstIL.Var.new(pre ,ty)      val a=DstIL.Var.new(pre ,ty)
48      val code=DstIL.ASSGN (a,DstIL.OP(opss,args))      val code=DstIL.ASSGN (a,DstIL.OP(opss,args))
49      val _ =testp[tS.toStringAll(ty,code)]          val _ =testp[LowToS.toStringAll(ty,code)]
50      in      in
51          (a,[code])          (a,[code])
52      end      end
# Line 58  Line 54 
54  fun mkReal n=let  fun mkReal n=let
55      val a=DstIL.Var.new("Real" ,Sca)      val a=DstIL.Var.new("Real" ,Sca)
56      val code=DstIL.ASSGN (a,DstIL.LIT(Literal.Int(IntInf.fromInt n)))      val code=DstIL.ASSGN (a,DstIL.LIT(Literal.Int(IntInf.fromInt n)))
57      val _ =testp[tS.toStringAll(Sca,code)]          val _ =testp[LowToS.toStringAll(Sca,code)]
58      in      in
59          (a,[code])          (a,[code])
60      end      end
# Line 66  Line 62 
62  fun mkInt n=let  fun mkInt n=let
63      val a=DstIL.Var.new("Int" ,iTy)      val a=DstIL.Var.new("Int" ,iTy)
64      val code=DstIL.ASSGN (a,DstIL.LIT(Literal.Int(IntInf.fromInt n)))      val code=DstIL.ASSGN (a,DstIL.LIT(Literal.Int(IntInf.fromInt n)))
65      val _ =testp[tS.toStringAll(iTy,code)]          val _ =testp[LowToS.toStringAll(iTy,code)]
66      in      in
67          (a,[code])          (a,[code])
68      end      end
69    
   
   
70  (*mk Multiple, Add Ids on list1*)  (*mk Multiple, Add Ids on list1*)
71  fun mkMultiple((lhs,_,_,_),list1,rator,ty)=let  fun mkMultiple((lhs,_,_,_),list1,rator,ty)=let
72      fun add([],_,_)           = err"no element in mkMultiple"      fun add([],_,_)           = err"no element in mkMultiple"
# Line 88  Line 82 
82          add(list1,[],List.length list1)          add(list1,[],List.length list1)
83      end      end
84    
   
85  fun mapIndex(e1,mapp)=(case e1  fun mapIndex(e1,mapp)=(case e1
86      of E.V e => (case (lookup e mapp)      of E.V e => (case (lookup e mapp)
87          of NONE=> err("Outside Bound:"^Int.toString(e))          of NONE=> err("Outside Bound:"^Int.toString(e))
# Line 96  Line 89 
89      | E.C c=> c      | E.C c=> c
90      (*end case*))      (*end case*))
91    
   
92  (*Integer, or Generic Tensor*)  (*Integer, or Generic Tensor*)
93  fun getTensorTy(params, id)=(case List.nth(params,id)  fun getTensorTy(params, id)=(case List.nth(params,id)
94      of E.TEN(3,[shape])=> DstTy.iVecTy(shape) (*FIX HERE*)      of E.TEN(3,[shape])=> DstTy.iVecTy(shape) (*FIX HERE*)
# Line 105  Line 97 
97    
98  fun q e=Int.toString(e)  fun q e=Int.toString(e)
99    
   
100  fun mkSca(mapp,(id, [],(lhs,params,_,args))) = (List.nth(args,id),[])  fun mkSca(mapp,(id, [],(lhs,params,_,args))) = (List.nth(args,id),[])
101    | mkSca(mapp,(id,ix,(lhs,params,_,args)))= let    | mkSca(mapp,(id,ix,(lhs,params,_,args)))= let
102      val nU=List.nth(args,id)      val nU=List.nth(args,id)
# Line 114  Line 105 
105      val argTy=getTensorTy(params,id)      val argTy=getTensorTy(params,id)
106      val opp=DstOp.IndexTensor(id,ix',argTy)      val opp=DstOp.IndexTensor(id,ix',argTy)
107      in      in
108      aaV(opp,[nU],lhs^"S"^Int.toString(id),Sca)          aaV(opp,[nU],lhs^"R"^Int.toString(id),Sca)
109      end      end
110    
111  fun mkIntAsn(_,(id, [],(_,_,_,args))) = (List.nth(args,id),[])  fun mkIntAsn(_,(id, [],(_,_,_,args))) = (List.nth(args,id),[])
# Line 128  Line 119 
119          aaV(opp,[nU],lhs^"I"^Int.toString(id),iTy)          aaV(opp,[nU],lhs^"I"^Int.toString(id),iTy)
120      end      end
121    
   
   
122  (*eval Epsilon*)  (*eval Epsilon*)
123  fun evalEps(mapp,a,b,c)=let  fun evalEps(mapp,a,b,c)=let
124      val i=mapIndex(E.V a,mapp)      val i=mapIndex(E.V a,mapp)
# Line 155  Line 144 
144              else mkReal ~1              else mkReal ~1
145      end      end
146    
   
147  (*eval Delta*)  (*eval Delta*)
148  fun evalDelta2(mapp,a,b)= let  fun evalDelta2(mapp,a,b)= let
149      val i=mapIndex(a,mapp)      val i=mapIndex(a,mapp)
# Line 164  Line 152 
152          if(i=j) then mkReal 1  else mkReal 0          if(i=j) then mkReal 1  else mkReal 0
153      end      end
154    
   
155  fun evalDels(mapp,dels)=let  fun evalDels(mapp,dels)=let
156      fun m(a,b)=if(a=b) then 1 else 0      fun m(a,b)=if(a=b) then 1 else 0
157      fun ij(i,j)=(case (i,j)      fun ij(i,j)=(case (i,j)
# Line 178  Line 165 
165          List.foldl(fn(x,y)=>x+y) 0 dels'          List.foldl(fn(x,y)=>x+y) 0 dels'
166      end      end
167    
   
168  (*--------------------Vectorization Helper Functions--------------------*)  (*--------------------Vectorization Helper Functions--------------------*)
169  (*val nextfnArgs=(body,params,args,origargs)*)  (*val nextfnArgs=(body,params,args,origargs)*)
   
170  fun mkVec(mapp,(id,[],vecIX,(lhs,params,_,args)))= let  fun mkVec(mapp,(id,[],vecIX,(lhs,params,_,args)))= let
171      val nU=List.nth(args,id)      val nU=List.nth(args,id)
172      in (nU,[]) end      in (nU,[]) end
# Line 195  Line 180 
180          aaV(opp,[nU],lhs^"V"^Int.toString(id),vecTy)          aaV(opp,[nU],lhs^"V"^Int.toString(id),vecTy)
181      end      end
182    
   
   
   
183  (*product of -1 and 1 projection*)  (*product of -1 and 1 projection*)
184  fun mkNegV(mapp,((vA,id,ix),vecIX,info as (lhs,_,_,_)))=let  fun mkNegV(mapp,((vA,id,ix),vecIX,info as (lhs,_,_,_)))=let
185      val (vB, B)= mkVec(mapp,(id,ix,vecIX,info))      val (vB, B)= mkVec(mapp,(id,ix,vecIX,info))
# Line 247  Line 229 
229      end      end
230    
231  (*Sum of Vector Product*)  (*Sum of Vector Product*)
   
   
232  fun mkprodSumVec(mapp,(id1,ix1,id2,ix2,vecIX, info as (lhs,_,_,_)))=let  fun mkprodSumVec(mapp,(id1,ix1,id2,ix2,vecIX, info as (lhs,_,_,_)))=let
233      val (vD,D)=mkprodVec(mapp,(id1,ix1,id2,ix2,vecIX, info))      val (vD,D)=mkprodVec(mapp,(id1,ix1,id2,ix2,vecIX, info))
234      val (vE, E)=aaV(DstOp.sumVec vecIX,[vD], lhs^"sumVec",DstTy.realTy)      val (vE, E)=aaV(DstOp.sumVec vecIX,[vD], lhs^"sumVec",DstTy.realTy)
# Line 256  Line 236 
236          (vE, D @E)          (vE, D @E)
237      end      end
238    
   
239  (*Dot Product like summation *)  (*Dot Product like summation *)
240  fun sumDot(mapp, ((E.V v,lb,ub),t as (_,_,_,_,_,info) ))=let  fun sumDot(mapp, ((E.V v,lb,ub),t as (_,_,_,_,_,info) ))=let
241    

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