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/split.sml
ViewVC logotype

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

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

branches/charisee/src/compiler/high-to-mid/split.sml revision 3229, Thu Jul 30 16:10:54 2015 UTC branches/charisee_dev/src/compiler/high-to-mid/split.sml revision 3395, Tue Nov 10 18:23:07 2015 UTC
# Line 1  Line 1 
1  (* Currently under construction  (* Currently under construction
2   *   *
3   * COPYRIGHT (c) 2012 The Diderot Project (http://diderot-language.cs.uchicago.edu)   * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
4     *
5     * COPYRIGHT (c) 2015 The University of Chicago
6   * All rights reserved.   * All rights reserved.
7   *)   *)
8    
# Line 34  Line 36 
36    
37      val numFlag=1   (*remove common subexpression*)      val numFlag=1   (*remove common subexpression*)
38      val testing=0      val testing=0
39      fun setEin(params,index,body)=Ein.EIN{params=params, index=index, body=body}      val splitlimit=100
40      fun assignEinApp(y,params,index,body,args)= (y,DstIL.EINAPP(setEin(params,index,body),args))      fun mkEin e = E.mkEin e
41      val einappzero=DstIL.EINAPP(setEin([],[],E.Const 0),[])      val einappzero= DstIL.EINAPP(mkEin([],[],E.Const 0),[])
42      fun setEinZero y=  (y,einappzero)      fun setEinZero y=  (y,einappzero)
43      fun cleanParams e =cleanP.cleanParams e      fun cleanParams e =cleanP.cleanParams e
44      fun cleanIndex e =cleanI.cleanIndex e      fun cleanIndex e =cleanI.cleanIndex e
45      fun printEINAPP e=MidToString.printEINAPP e      fun toStringBind e= MidToString.toStringBind e
46      fun itos i =Int.toString i      fun itos i =Int.toString i
     fun filterSca e=Filter.filterSca e  
47      fun err str=raise Fail str      fun err str=raise Fail str
48      val cnt = ref 0      val cnt = ref 0
49      fun incUse (DstIL.V{useCnt, ...}) = (useCnt := !useCnt + 1)      fun incUse (DstIL.V{useCnt, ...}) = (useCnt := !useCnt + 1)
# Line 113  Line 114 
114          | E.Krn _     => err("Krn used before expand")          | E.Krn _     => err("Krn used before expand")
115          | E.Value _   => err("Value used before expand")          | E.Value _   => err("Value used before expand")
116          | E.Img _     => err("Probe used before expand")          | E.Img _     => err("Probe used before expand")
117    |  Ein.PowEmb(e1,sx1,n1) =>1
118          | _           => 2          | _           => 2
119      (*end case*))      (*end case*))
120    
   
   
121      fun rewriteOp3(name,sx,e1,x)=let      fun rewriteOp3(name,sx,e1,x)=let
122          val ((y, DstIL.EINAPP(ein,args)),fieldset,flag)=x          val ((y, DstIL.EINAPP(ein,args)),fieldset,flag)=x
123          val params=Ein.params ein          val params=Ein.params ein
# Line 138  Line 138 
138          | 2     => (e1,params,args,[],fieldset)             (*not lifted*)          | 2     => (e1,params,args,[],fieldset)             (*not lifted*)
139          (*end*))          (*end*))
140    
   
   
   
141      fun rewriteOps(name,list1,params,index,sx,args,fieldset0,flag)=let      fun rewriteOps(name,list1,params,index,sx,args,fieldset0,flag)=let
142          fun m([],rest,params,args,code,fieldset)=(rest,params,args,code,fieldset)          fun m([],rest,params,args,code,fieldset)=(rest,params,args,code,fieldset)
143          | m(e1::es,rest,params,args,code,fieldset)=let          | m(e1::es,rest,params,args,code,fieldset)=let
# Line 305  Line 302 
302              (einapp,code,fieldset)              (einapp,code,fieldset)
303          end          end
304    
305    fun handlePowEmb(y,e1,sx1,n1,params,index,args,fieldset,flag)=let
306    val (e1',params',args',code,fieldset)=  rewriteOp("mag",e1,params,index,sx1,args,fieldset,flag)
307    val body= E.Sum(sx1,E.Prod[e1',e1'])
308    val einapp= rewriteOrig(y,body,params',index,sx1,args')
309    val _=print(String.concat["\nhandlePowEmb:",P.printbody(E.PowEmb(e1,sx1,n1)),"\n=>",
310    P.printbody(body)])
311    in
312    (einapp,code,fieldset)
313    end
314    
315    
316      (* split:var*ein_app-> (var*einap)*code      (* split:var*ein_app-> (var*einap)*code
317      * split ein expression into smaller pieces      * split ein expression into smaller pieces
318        note we leave summation around probe exp        note we leave summation around probe exp
# Line 350  Line 358 
358              | E.Sum(sx,E.Tensor _)    => default              | E.Sum(sx,E.Tensor _)    => default
359              | E.Sum(sx,_)             => err(" summation not distributed:"^str)              | E.Sum(sx,_)             => err(" summation not distributed:"^str)
360              | E.Add e1                => handleAdd(y,e1,params,index,args,fieldset,flag)              | E.Add e1                => handleAdd(y,e1,params,index,args,fieldset,flag)
361                | E.Prod[E.Tensor(id0,[]),E.Tensor(id1,[i]),E.Tensor(id2,[])]=>
362                        rewrite (E.Prod[E.Prod[E.Tensor(id0,[]),E.Tensor(id2,[])],E.Tensor(id1,[i])])
363              | E.Prod e1               => handleProd(y,e1,params,index,args,fieldset,flag)              | E.Prod e1               => handleProd(y,e1,params,index,args,fieldset,flag)
364              | E.Partial _             => err(" Partial used after normalize")              | E.Partial _             => err(" Partial used after normalize")
365              | E.Krn _                 => err("Krn used before expand")              | E.Krn _                 => err("Krn used before expand")
366              | E.Value _               => err("Value used before expand")              | E.Value _               => err("Value used before expand")
367              | E.Img _                 => err("Probe used before expand")              | E.Img _                 => err("Probe used before expand")
368    | Ein.PowEmb(e1,sx1,n1) =>handlePowEmb(y,e1,sx1,n1,params,index,args,fieldset,flag)
369    
370              (*end case *))              (*end case *))
371          val (einapp2,newbies,fieldset) =rewrite body          val (einapp2,newbies,fieldset) =rewrite body
372          in          in
# Line 363  Line 375 
375          |split((y,app),fieldset,_) =(((y,app),[]),fieldset)          |split((y,app),fieldset,_) =(((y,app),[]),fieldset)
376    
377    
378      fun iterMultiple(einapp2,newbies2,fieldset)=let      fun iterAll2(einapp2,fields2)=let
379          fun itercode([],rest,code,_)=(rest,code)          val fieldset= einSet.EinSet.empty
380            val _ =print ("\nSPLit with limit"^(Int.toString(splitlimit)))
381            fun itercode([],rest,code,cnt)=(("\n Empty-SplitCount: "^Int.toString(cnt));(rest,code))
382            | itercode(e1::newbies,rest,code,cnt)=let            | itercode(e1::newbies,rest,code,cnt)=let
383                  val ((einapp3,code3),_) = split(e1,fieldset,numFlag)                  val ((einapp3,code3),_) = split(e1,fieldset,numFlag)
384                      val (rest4,code4)=itercode(code3,[],[],cnt+1)                      val (rest4,code4)=itercode(code3,[],[],cnt+1)
385                val _ =testp [toStringBind(e1),"\n\t===>\n",toStringBind(einapp3),"\nand\n",(String.concatWith",\n\t"(List.map toStringBind (code4@rest4)))]
386          in          in
387              itercode(newbies,rest@[einapp3],code4@( rest4)@code,cnt+2)                  if (length(rest@newbies@code) > splitlimit) then let
388                            val _ =("\n SplitCount: "^Int.toString(cnt))
389                            val code5=code4@rest4@code
390                            val rest5=rest@[einapp3]
391                            in
392                                (rest5,code5@newbies)(*tab4*)
393                            end
394                    else  itercode(newbies,rest@[einapp3],code4@rest4@code,cnt+2)
395          end          end
396              val(rest,code)= itercode(newbies2,[],[],1)          val(rest,code)= itercode([einapp2],[],[],0)
397          in          in
398              ((code)@rest@[einapp2])  
399                  fields2@code@rest (*B*)
400          end          end
401    
402    
403    
404    
405      fun iterAll(einapp2,fieldset)=let      fun iterAll(einapp2,fieldset)=let
406    
407          fun itercode([],rest,code,_)=(rest,code)          fun itercode([],rest,code,_)=(rest,code)
408          | itercode(e1::newbies,rest,code,cnt)=let          | itercode(e1::newbies,rest,code,cnt)=let
409              val ((einapp3,code3),_) = split(e1,fieldset,numFlag)              val ((einapp3,code3),_) = split(e1,fieldset,numFlag)
410              val (rest4,code4)=itercode(code3,[],[],cnt+1)              val (rest4,code4)=itercode(code3,[],[],cnt+1)
411                  val _ =testp [printEINAPP(e1),"\n\t===>\n",printEINAPP(einapp3),"\nand\n",(String.concatWith",\n\t"(List.map printEINAPP (code4@rest4)))]                  val _ =testp [toStringBind(e1),"\n\t===>\n",toStringBind(einapp3),"\nand\n",(String.concatWith",\n\t"(List.map toStringBind (code4@rest4)))]
412              in              in
413                  itercode(newbies,rest@[einapp3],code4@( rest4)@code,cnt+2)                  itercode(newbies,rest@[einapp3],code4@( rest4)@code,cnt+2)
414              end              end
# Line 391  Line 417 
417              (code@rest)              (code@rest)
418          end          end
419    
     fun splitEinApp einapp3= let  
         val fieldset= einSet.EinSet.empty  
420    
         (* **** split in parts **** *)  
         (*  
         val ((einapp4,newbies4),fieldset)=split(einapp3,fieldset,0)  
         val _ =testp["\n\t===>\n",printEINAPP(einapp4),"\nand\n",(String.concatWith",\n\t"(List.map printEINAPP newbies4))]  
         val (newbies5)= iterMultiple(einapp4,newbies4,fieldset)  
         *)  
   
         (* **** split all at once **** *)  
         val (newbies5)= iterAll([einapp3],fieldset)  
421    
422        fun splitEinApp (einapp3,splitflag)= let
423            val fieldset= einSet.EinSet.empty
424            val (newbies5)=(case splitflag
425                of 1 =>let
426                    (* **** split single **** *)
427                    val ((einapp4,newbies4),fieldset)=split(einapp3,fieldset,0)
428                    in newbies4@[einapp4] end
429                | _=>   (* **** split all at once **** *)
430                    iterAll([einapp3],fieldset)
431            (* end case *))
432          in          in
433              newbies5              newbies5
434          end          end

Legend:
Removed from v.3229  
changed lines
  Added in v.3395

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