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

SCM Repository

[diderot] Annotation of /branches/charisee/src/compiler/translate/translate-basis.sml
ViewVC logotype

Annotation of /branches/charisee/src/compiler/translate/translate-basis.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 197 - (view) (download)
Original Path: trunk/src/compiler/translate/translate-basis.sml

1 : jhr 180 (* translate-basis.sml
2 :     *
3 :     * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)
4 :     * All rights reserved.
5 :     *
6 :     * Translation for basis operations in Simple AST to HighIL code
7 :     *)
8 :    
9 :     structure TranslateBasis : sig
10 :    
11 : jhr 189 (* translate(lhs, f, mvs, args) translates the application of f (specialized
12 :     * to the instantiated meta variables mvs) to a list of SSA assignments in
13 :     * reverse order.
14 :     *)
15 : jhr 180 val translate : (HighIL.var * Var.var * Types.meta_var list * HighIL.var list)
16 : jhr 188 -> HighIL.assign list
17 : jhr 180
18 :     end = struct
19 :    
20 : jhr 194 structure BV = BasisVars
21 : jhr 180 structure IL = HighIL
22 :     structure Op = HighOps
23 : jhr 183 structure Ty = Types
24 :     structure TU = TypeUtil
25 :     structure MV = MetaVar
26 : jhr 194 structure VTbl = Var.Tbl
27 : jhr 180
28 : jhr 188 fun assign (y, rator, xs) = [(y, IL.OP(rator, xs))]
29 : jhr 180
30 : jhr 194 fun simpleOp rator (y, [], xs) = assign (y, rator, xs)
31 : jhr 183
32 : jhr 197 fun pruneDim d = (case TU.pruneDim d
33 :     of (Ty.DimConst n) => n
34 :     | d => raise Fail("unresolved dimension " ^ TU.dimToString d)
35 :     (* end case *))
36 :    
37 : jhr 194 fun tensorOp rator (y, [sv], xs) = (case TU.pruneShape(MV.toShape sv)
38 : jhr 197 of Ty.Shape dd =>
39 :     assign (y, rator(Op.TensorTy(List.map pruneDim dd)), xs)
40 : jhr 183 | shp => raise Fail("unresolved shape " ^ TU.shapeToString shp)
41 :     (* end case *))
42 :    
43 : jhr 197 fun vectorOp rator (y, [dv], xs) =
44 :     assign (y, rator(Op.TensorTy[pruneDim(MV.toDim dv)]), xs)
45 :    
46 :     fun kernel h (y, [], []) = assign(y, Op.Kernel h, [])
47 :    
48 : jhr 184 (* build a table that maps Basis variables to their translation functions *)
49 : jhr 197 val tbl : ((IL.var * Ty.meta_var list * IL.var list) -> IL.assign list) VTbl.hash_table = let
50 : jhr 194 val tbl = VTbl.mkTable (128, Fail "Translate table")
51 : jhr 180 in
52 : jhr 194 List.app (VTbl.insert tbl) [
53 :     (BV.add_ii, simpleOp(Op.Add Op.IntTy)),
54 :     (BV.add_tt, tensorOp Op.Add),
55 :     (BV.sub_ii, simpleOp(Op.Sub Op.IntTy)),
56 :     (BV.sub_tt, tensorOp Op.Sub),
57 :     (BV.mul_ii, simpleOp(Op.Mul Op.IntTy)),
58 :     (BV.mul_rr, simpleOp(Op.Mul(Op.TensorTy[]))),
59 :     (BV.mul_rt, tensorOp Op.Scale),
60 :     (BV.mul_tr, fn (y, sv, [t, r]) => tensorOp Op.Scale (y, sv, [r, t])),
61 :     (BV.div_ii, simpleOp(Op.Div Op.IntTy)),
62 :     (BV.div_rr, simpleOp(Op.Div(Op.TensorTy[]))),
63 :     (BV.div_tr, tensorOp Op.InvScale),
64 :     (BV.lt_ii, simpleOp(Op.LT Op.IntTy)),
65 :     (BV.lt_rr, simpleOp(Op.LT(Op.TensorTy[]))),
66 :     (BV.lte_ii, simpleOp(Op.LTE Op.IntTy)),
67 :     (BV.lte_rr, simpleOp(Op.LTE(Op.TensorTy[]))),
68 :     (BV.gte_ii, simpleOp(Op.GTE Op.IntTy)),
69 :     (BV.gte_rr, simpleOp(Op.GTE(Op.TensorTy[]))),
70 :     (BV.gt_ii, simpleOp(Op.GT Op.IntTy)),
71 :     (BV.gt_rr, simpleOp(Op.GT(Op.TensorTy[]))),
72 :     (BV.equ_bb, simpleOp(Op.EQ Op.BoolTy)),
73 :     (BV.equ_ii, simpleOp(Op.EQ Op.IntTy)),
74 :     (BV.equ_ss, simpleOp(Op.EQ Op.StringTy)),
75 :     (BV.equ_rr, simpleOp(Op.EQ(Op.TensorTy[]))),
76 :     (BV.neq_bb, simpleOp(Op.NEQ Op.BoolTy)),
77 :     (BV.neq_ii, simpleOp(Op.NEQ Op.IntTy)),
78 :     (BV.neq_ss, simpleOp(Op.NEQ Op.StringTy)),
79 :     (BV.neq_rr, simpleOp(Op.NEQ(Op.TensorTy[]))),
80 :     (BV.neg_i, simpleOp(Op.Neg Op.IntTy)),
81 :     (BV.neg_t, tensorOp Op.Neg),
82 : jhr 197 (BV.neg_f, fn (y, _, xs) => assign(y, Op.NegField, xs)),
83 :     (BV.op_at, fn (y, _, xs) => assign(y, Op.Probe, xs)),
84 :     (BV.op_D, fn (y, _, xs) => assign(y, Op.DiffField, xs)),
85 : jhr 194 (BV.op_norm, tensorOp Op.Norm),
86 :     (BV.op_not, simpleOp Op.Not),
87 : jhr 197 (*
88 : jhr 194 (BV.op_subscript, fn (y, [SK, NK], xs) => ??), (*FIXME*)
89 : jhr 197 *)
90 :     (BV.fn_CL, fn (y, _, xs) => assign(y, Op.CL, xs)),
91 :     (BV.fn_convolve, fn (y, _, xs) => assign(y, Op.Convolve, xs)),
92 : jhr 194 (BV.fn_cos, simpleOp Op.Cos),
93 : jhr 197 (BV.fn_dot, vectorOp Op.Dot),
94 :     (BV.fn_inside, fn (y, _, xs) => assign(y, Op.Inside, xs)),
95 :     (*
96 : jhr 194 (BV.fn_load, fn (y, [NK, SK], xs) => ??), (*FIXME*)
97 : jhr 197 *)
98 : jhr 194 (BV.fn_max, simpleOp Op.Min),
99 :     (BV.fn_min, simpleOp Op.Max),
100 : jhr 197 (BV.fn_modulate, vectorOp Op.Mul),
101 : jhr 194 (BV.fn_pow, simpleOp Op.Pow),
102 : jhr 197 (BV.fn_principleEvec, vectorOp Op.PrincipleEvec),
103 : jhr 194 (BV.fn_sin, simpleOp Op.Sin),
104 : jhr 197 (BV.kn_bspln3, kernel Kernel.bspln3),
105 :     (BV.kn_bspln5, kernel Kernel.bspln5),
106 :     (BV.kn_ctmr, kernel Kernel.ctmr),
107 :     (BV.kn_tent, kernel Kernel.tent),
108 :     (BV.i2r, simpleOp Op.IntToReal)(*,
109 :     (BV.input, fn (y, [TK], xs) => ??), (*FIXME*)
110 :     (BV.optInput, fn (y, [TK], xs) => ??) (*FIXME*)
111 :     *)
112 : jhr 180 ];
113 :     tbl
114 :     end
115 :    
116 : jhr 194 fun translate (y, f, mvs, xs) = (case VTbl.find tbl f
117 : jhr 197 of SOME transFn => transFn(y, mvs, xs)
118 : jhr 194 | NONE => raise Fail("TranslateBasis.translate: unknown function " ^ Var.nameOf f)
119 : jhr 180 (* end case *))
120 :    
121 :     end

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