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

SCM Repository

[diderot] Annotation of /branches/vis15/src/compiler/high-to-mid/coord-space-transform.sml
ViewVC logotype

Annotation of /branches/vis15/src/compiler/high-to-mid/coord-space-transform.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3732 - (view) (download)

1 : jhr 3577 (*
2 :     *This file does world to image space Transformations
3 :     * Take a look at tex file for examples
4 :     * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
5 :     *
6 :     * COPYRIGHT (c) 2015 The University of Chicago
7 :     * All rights reserved.
8 :     *)
9 :    
10 :    
11 :    
12 :     structure CoordSpaceTransform : sig
13 :    
14 :     (* `worldToImage {info, img, pos}` returns (M, x, stms), where M is a variable
15 :     * bound to the world-space to image-space linear transformation matrix, x is
16 :     * a variable bound to the transformed position (pos), and stms is a list of
17 :     * assignments that computes the world-space to -image-space transformation.
18 :     *)
19 :     val worldToImage : {
20 : jhr 3732 avail : AvailRHS.avail,
21 : jhr 3577 info : ImageInfo.info, (* the image info for the image *)
22 :     img : MidIR.var, (* the variable bound to the image *)
23 :     pos : MidIR.var (* the variable bound to the world-space position *)
24 : jhr 3732 } -> MidIR.var * MidIR.var
25 : jhr 3577
26 :     val worldToIndex : {
27 : jhr 3732 avail : AvailRHS.avail,
28 : jhr 3577 info : ImageInfo.info, (* the image info for the image *)
29 :     img : MidIR.var, (* the variable bound to the image *)
30 :     pos : MidIR.var (* the variable bound to the world-space position *)
31 : jhr 3732 } -> MidIR.var * MidIR.var * MidIR.var
32 : jhr 3577
33 :     val imageToWorld : Ein.tensor_id * int * Ein.mu list * Ein.tensor_id
34 :     -> (Ein.mu list * Ein.sumrange list * Ein.ein_exp list)
35 :    
36 :     end = struct
37 :    
38 :     structure E = Ein
39 :     structure IR = MidIR
40 :     structure Ty = MidTypes
41 :     structure Op = MidOps
42 :     structure V = IR.Var
43 :     structure Mk = MkOperators
44 :    
45 :     fun assign (x, rator, args) = (x, IR.OP(rator, args))
46 :     fun assignEin (x, rator, args) = ((x, IR.EINAPP(rator, args)))
47 :    
48 :     (*getTys:int->ty*int list *int list
49 :     *Returns types based on field dimension
50 :     * Really, just done literally so that 1-d fields pass the type-checker
51 :     *)
52 :     fun getTys 1 = (Ty.intTy, [], [])
53 :     | getTys dim = (Ty.iVecTy dim, [dim], [dim, dim])
54 :    
55 :     (* WorldToImagespace:dim* imageinfo* mid-il var* mid-il var
56 :     ->mid-il var * mid-il var *code
57 :     *transform image-space position x to world space position
58 :     *)
59 : jhr 3732 fun worldToImage {avail, info, img, pos} = let
60 : jhr 3577 val dim = ImageInfo.dim info
61 :     val (_, fty, pty) = getTys dim
62 :     val mty = Ty.TensorTy pty
63 :     val rty = Ty.TensorTy fty
64 : jhr 3732 val M = Avail.addAssign (avail, "M", mty, IR.OP(Op.Transform info, [img]))
65 :     val T = Avail.addAssign (avail, "T", rty, IR.OP(Op.Translate info, [img]))
66 : jhr 3577 val (mulOp, addOp) = if (dim = 1)
67 :     then (Mk.mulRR, Mk.addRR)
68 :     else (Mk.innerTT([dim, dim], [dim]), Mk.addTT[dim])
69 : jhr 3732 val x0 = Avail.addAssign (avail, "x0", rty, IR.OP(mulOp, [M, pos])) (*Image-Space position*)
70 :     val x = Avail.addAssign (avail, "x", rty, IR.OP(addOp, [x0, T]))
71 : jhr 3577 in
72 : jhr 3732 (M, x)
73 : jhr 3577 end
74 :    
75 :     (*transformToImgSpae:int*imginfo*mid-ilvar*mid-ilvar
76 :     -> mid_il var list * mid-il var* code
77 :     *Create fractional, and integer position vectors
78 :     *)
79 : jhr 3732 fun worldToIndex (arg as {avail, info, img, pos}) = let
80 : jhr 3577 val dim = ImageInfo.dim info
81 :     val (ity, fty, pty) = getTys dim
82 :     val mty = Ty.TensorTy pty
83 :     val rty = Ty.TensorTy fty
84 : jhr 3732 val (M, x) = worldToImage arg
85 :     val nd = Avail.addAssign (avail, "nd", rty, IR.OP(Op.Floor dim, [x])) (* real position *)
86 :     val f = Avail.addAssign (avail, "f", rty, IR.OP(Mk.subTT fty, [x, nd])) (* fractional *)
87 :     val n = Avail.addAssign (avail, "n", ity, IR.OP(Op.RealToInt dim, [nd])) (* integer position *)
88 :     val P = if (dim = 1)
89 :     then M
90 :     else Avail.addAssign (avail, "P", mty, IR.OP(Mk.transposeT pty, [M]))
91 : jhr 3577 in
92 : jhr 3732 (n, f, P)
93 : jhr 3577 end
94 :    
95 :     (*transformToIndexSpace:int*int*mu list * param_id
96 :     *Make Transform Matrices, and returns new indices as mu and sum_indexids
97 :     *)
98 :     (* nextIdx -- next available variable ID
99 :     * dim -- dimension of world space
100 :     * dx -- list of indices from the differentiation of the field that was probed
101 :     * Pid -- variable ID of the transformation-matrix parameter
102 :     *)
103 :     fun imageToWorld (nextIdx, dim, dx, Pid) = let
104 :     fun iter ([], _, newdx, newsx, ps) = (rev newdx, rev newsx, rev ps)
105 :     | iter (i::es, n, newdx, newsx, ps) = let
106 :     val j = E.V n
107 :     val sx = (j, 0, dim-1)
108 :     val p = E.Tensor(Pid, [i, j])
109 :     in
110 :     iter (es, n+1, j::newdx, sx::newsx, p::ps)
111 :     end
112 :     in
113 :     iter (dx, nextIdx, [], [], [])
114 :     end
115 :    
116 :     end

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