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

SCM Repository

[diderot] View of /branches/charisee/src/compiler/high-to-mid/Transform.sml
ViewVC logotype

View of /branches/charisee/src/compiler/high-to-mid/Transform.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2611 - (download) (annotate)
Mon May 5 21:21:12 2014 UTC (5 years, 2 months ago) by cchiw
File size: 3308 byte(s)
InnerProduct, DoubleDot:
(* Currently under construction 
 *
 * COPYRIGHT (c) 2012 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * All rights reserved.
 *)


(*
A couple of different approaches.
One approach is to find all the Probe(Conv). Gerenerate exp for it
Then use Subst function to sub in. That takes care for index matching and

*)

(*This approach creates probe expanded terms, and adds params to the end. *)


structure TransformEin = struct

    local
   
    structure E = Ein
    structure P=Printer
structure SrcIL = HighIL
structure SrcTy = HighILTypes
structure SrcOp = HighOps
structure SrcSV = SrcIL.StateVar
structure VTbl = SrcIL.Var.Tbl
structure DstIL = MidIL
structure DstTy = MidILTypes
structure DstOp = MidOps
structure DstV = DstIL.Var
structure SrcV = SrcIL.Var
structure P=Printer
structure shift=ShiftEin
structure split=SplitEin

in
val testing=1

fun assignEin (x, rator, args) = ((x, DstIL.EINAPP(rator, args)))

(*Transform differentiation index to world-space*)
(*Returns new deltas, summations, and List of Tensor Products*)
fun ImgtoWorldSpace(dels, outerShape,dim,Pid,ns)= let
    val _=print "\n In ImgtoWorld space"
    val dim'=dim-1
    fun setMatrix(imgix,wrdix) = E.Tensor(Pid,[ E.V imgix, E.V wrdix])

    fun changeDel([],n,newdels,sx,rest)=(newdels,sx,rest)
     | changeDel((E.C _)::es,_,_,_,_)= raise Fail "unsure what to do with constant differentiation"
     | changeDel((E.V v)::es,n,newdels,sx,rest)= let
        val P=setMatrix(v, n)
        val n'=E.V n
        in
            changeDel(es,n+1,newdels@[n'],sx@[(n',0,dim')],rest@[P])
        end


    val (newdels,sx,rest)=changeDel(dels,ns,[],[],[])
    in
        (newdels,sx,rest)
    end


(*Transformation is Lifted*)
fun ImgtoWorldSpaceLift(dels, outerShape,alpha,dim,oldArg,newArg,PArg,Pid,ns)= let
    val (newdels,sx,rest)=ImgtoWorldSpace(dels, outerShape,dim,Pid,ns)
    val tshape=List.tabulate((length(alpha)),fn v=> E.V v)

    val newbie'=Ein.EIN{
            params=[E.TEN(1,outerShape), E.TEN(1,[dim,dim])],
            index=outerShape,
            body=E.Sum(sx,E.Prod([E.Tensor(0,tshape@newdels)]@rest))
        }

    val _ = print(String.concat["\n Super Lift Transform \n ",(split.printA (newArg,newbie',[oldArg,PArg])) ,"\n"])
    val data=assignEin (newArg, newbie', [oldArg,PArg])
    val ix=List.tabulate((length(dels)),fn _=> dim)
    in
        (newdels,ix,[data])
    end


(*returns final argumentVar, new dels, and assignments*)
fun Transform(dels,outerShape,alpha,dim,PArg,ns,lift,Pid)=let
    val oldArg = DstV.new ("ProbeResult", DstTy.tensorTy outerShape)
    in (case (dels,lift)
        of ([],_) => (oldArg,oldArg,dels,[],[],[],[],[])
        | (_,0)=> let
            (*Lift the transformation of Probed Fields*)
            val newArg = DstV.new ("TransformedProbed", DstTy.tensorTy outerShape)
            val (newdels,ix,data)=ImgtoWorldSpaceLift(dels, outerShape,alpha,dim,oldArg,newArg,PArg,1,ns)
            in
                (oldArg,newArg,newdels,[],[],[],ix,data)
            end

        | _  =>  let
            val (newdels,sx,rest)=ImgtoWorldSpace(dels, outerShape,dim,Pid,ns)
            val params=[E.TEN(Pid,[dim,dim])]
            in
                (oldArg, oldArg,newdels,params,sx,rest,[],[])
            end
        (*end case*))
    end 


end
end 

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