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 3754 - (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 3734 avail : AvailRHS.t,
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 3734 avail : AvailRHS.t,
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 : jhr 3754
48 : cchiw 3735 fun incUse (IR.V{useCnt, ...}) = (useCnt := !useCnt + 1)
49 : jhr 3754
50 : jhr 3577 (*getTys:int->ty*int list *int list
51 :     *Returns types based on field dimension
52 :     * Really, just done literally so that 1-d fields pass the type-checker
53 :     *)
54 :     fun getTys 1 = (Ty.intTy, [], [])
55 :     | getTys dim = (Ty.iVecTy dim, [dim], [dim, dim])
56 :    
57 :     (* WorldToImagespace:dim* imageinfo* mid-il var* mid-il var
58 :     ->mid-il var * mid-il var *code
59 :     *transform image-space position x to world space position
60 :     *)
61 : jhr 3732 fun worldToImage {avail, info, img, pos} = let
62 : jhr 3577 val dim = ImageInfo.dim info
63 :     val (_, fty, pty) = getTys dim
64 :     val mty = Ty.TensorTy pty
65 :     val rty = Ty.TensorTy fty
66 : cchiw 3735 val M = AvailRHS.addAssign (avail, "Mtransform", mty, IR.OP(Op.Transform info, [img]))
67 : jhr 3754 val (mulOp, addOp) = if (dim = 1)
68 : jhr 3577 then (Mk.mulRR, Mk.addRR)
69 :     else (Mk.innerTT([dim, dim], [dim]), Mk.addTT[dim])
70 : cchiw 3735 val x0 = AvailRHS.addAssign (avail, "imagespaceM", rty, IR.EINAPP(mulOp, [M, pos])) (*Image-Space position*)
71 : jhr 3754 (* val x0 = AvailRHS.addAssign (avail, "x0M", rty, IR.OP((Op.Translate info, [M]))) (*Image-Space position*)*)
72 : cchiw 3735 val T = AvailRHS.addAssign (avail, "Ttranslate", rty, IR.OP(Op.Translate info, [img]))
73 : jhr 3754 val x = AvailRHS.addAssign (avail, "imagespaceT", rty, IR.EINAPP(addOp, [x0, T]))
74 :     (* val x = AvailRHS.addAssign (avail, "aaa", rty, IR.OP(Op.Floor dim, [x0, T]))*)
75 : jhr 3577 in
76 : jhr 3754 incUse M; incUse x0; incUse T;
77 : jhr 3732 (M, x)
78 : jhr 3577 end
79 :    
80 :     (*transformToImgSpae:int*imginfo*mid-ilvar*mid-ilvar
81 :     -> mid_il var list * mid-il var* code
82 :     *Create fractional, and integer position vectors
83 :     *)
84 : jhr 3732 fun worldToIndex (arg as {avail, info, img, pos}) = let
85 : jhr 3577 val dim = ImageInfo.dim info
86 :     val (ity, fty, pty) = getTys dim
87 :     val mty = Ty.TensorTy pty
88 :     val rty = Ty.TensorTy fty
89 : jhr 3732 val (M, x) = worldToImage arg
90 : jhr 3734 val nd = AvailRHS.addAssign (avail, "nd", rty, IR.OP(Op.Floor dim, [x])) (* real position *)
91 :     val f = AvailRHS.addAssign (avail, "f", rty, IR.EINAPP(Mk.subTT fty, [x, nd])) (* fractional *)
92 :     val n = AvailRHS.addAssign (avail, "n", ity, IR.OP(Op.RealToInt dim, [nd])) (* integer position *)
93 : jhr 3732 val P = if (dim = 1)
94 :     then M
95 : jhr 3734 else AvailRHS.addAssign (avail, "P", mty, IR.EINAPP(Mk.transposeT pty, [M]))
96 : jhr 3577 in
97 : jhr 3732 (n, f, P)
98 : jhr 3577 end
99 :    
100 :     (*transformToIndexSpace:int*int*mu list * param_id
101 :     *Make Transform Matrices, and returns new indices as mu and sum_indexids
102 :     *)
103 :     (* nextIdx -- next available variable ID
104 :     * dim -- dimension of world space
105 :     * dx -- list of indices from the differentiation of the field that was probed
106 :     * Pid -- variable ID of the transformation-matrix parameter
107 :     *)
108 :     fun imageToWorld (nextIdx, dim, dx, Pid) = let
109 :     fun iter ([], _, newdx, newsx, ps) = (rev newdx, rev newsx, rev ps)
110 :     | iter (i::es, n, newdx, newsx, ps) = let
111 :     val j = E.V n
112 :     val sx = (j, 0, dim-1)
113 :     val p = E.Tensor(Pid, [i, j])
114 :     in
115 :     iter (es, n+1, j::newdx, sx::newsx, p::ps)
116 :     end
117 :     in
118 :     iter (dx, nextIdx, [], [], [])
119 :     end
120 :    
121 :     end

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