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

SCM Repository

[diderot] Annotation of /branches/cuda/src/compiler/c-util/runtime-names.sml
ViewVC logotype

Annotation of /branches/cuda/src/compiler/c-util/runtime-names.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1372 - (view) (download)
Original Path: trunk/src/compiler/c-util/runtime-names.sml

1 : jhr 1115 (* runtime-names.sml
2 :     *
3 :     * COPYRIGHT (c) 2011 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4 :     * All rights reserved.
5 :     *)
6 :    
7 :     structure RuntimeNames =
8 :     struct
9 :    
10 :     local
11 :     structure Ty = TreeIL.Ty
12 :     structure F = Format
13 :     in
14 :    
15 :     (* globals that specify the target characteristics. These should be initialized
16 :     * when the program object is created.
17 :     *)
18 : jhr 1232 val doublePrecision = ref false
19 : jhr 1115 val gVectorWid = ref 4
20 :     val gIntTy = ref CLang.int32
21 :     val gRealTy = ref CLang.float
22 :     val gRealSuffix = ref "?"
23 :     val gIntSuffix = ref "?"
24 :     val gIntFormat = ref "?"
25 :    
26 :     (* initialize globals based on target precision *)
27 : jhr 1232 fun initTargetSpec double = (
28 :     doublePrecision := double;
29 :     if double
30 :     then (
31 :     gVectorWid := 2;
32 :     gIntTy := CLang.int64;
33 :     gRealTy := CLang.double;
34 :     gRealSuffix := "d";
35 :     gIntSuffix := "l";
36 :     gIntFormat := "%ld")
37 :     else (
38 :     gVectorWid := 4;
39 :     gIntTy := CLang.int32;
40 :     gRealTy := CLang.float;
41 :     gRealSuffix := "f";
42 :     gIntSuffix := "i";
43 :     gIntFormat := "%d"))
44 : jhr 1115
45 :     fun addRealSuffix stem = stem ^ !gRealSuffix
46 :     fun addVecSuffix stem n = concat[stem, Int.toString n, !gRealSuffix]
47 :     fun addIVecSuffix stem n = concat[stem, Int.toString n, !gIntSuffix]
48 :    
49 :     fun addTySuffix (stem, 1) = stem ^ !gRealSuffix
50 :     | addTySuffix (stem, n) = addVecSuffix stem n
51 :    
52 :     fun vecTy n = concat["vec", Int.toString n, !gRealSuffix, "_t"]
53 :     fun ivecTy n = concat["vec", Int.toString n, !gIntSuffix, "_t"]
54 :     fun imageTy n = concat["Diderot_image", Int.toString n, "D_t"]
55 :     fun matTy (n, m) = concat["Diderot_Mat", Int.toString n, "x", Int.toString m, "_t"]
56 :    
57 :     (* names of generated tyes, functions, and globals *)
58 :     val initGlobals = "Diderot_InitGlobals" (* function for initializing program globals *)
59 : jhr 1301 val registerOpts = "Diderot_RegisterGlobalOpts" (* function for registering command-line options *)
60 : jhr 1232 val shutdown = "Diderot_Shutdown" (* function that gets called at the end *)
61 : jhr 1115 val initially = "Diderot_Initially" (* function for creating initial strands *)
62 :     fun strandInit strand = strand ^ "_InitState"
63 :     fun strandTy strand = concat["Strand_", strand, "_t"]
64 :     fun strandDesc strand = concat["Strand_", strand]
65 :     val numStrands = "Diderot_NumStrands"
66 :     val strands = "Diderot_Strands"
67 :    
68 :     (* scalar math functions *)
69 :     fun max () = addRealSuffix "max"
70 :     fun min () = addRealSuffix "min"
71 :     fun fabs () = addRealSuffix "fabs"
72 :    
73 : jhr 1295 (* clamp and lerp *)
74 :     fun clamp n = addTySuffix("clamp", n)
75 : jhr 1115 fun lerp n = addTySuffix("lerp", n)
76 :    
77 :     (* vector math functions *)
78 :     val mkVec = addVecSuffix "vec"
79 :     val scale = addVecSuffix "scale"
80 :     val truncToInt = addVecSuffix "truncToInt"
81 :     val dot = addVecSuffix "dot"
82 :     fun cross () = addVecSuffix "cross" 3
83 :     val length = addVecSuffix "length"
84 :     val normalize = addVecSuffix "normalize"
85 :     fun vecitof n = concat["vec", Int.toString n, "ito", !gRealSuffix]
86 :     fun vecftoi n = concat["vec", Int.toString n, !gRealSuffix, "toi"]
87 :    
88 :     (* matrix operations *)
89 :     fun zeroMat (n, m) = concat["zero", Int.toString n, "x", Int.toString m, !gRealSuffix]
90 :     fun identityMat n = concat["identity", Int.toString n, "x", Int.toString n, !gRealSuffix]
91 :     fun trace n = concat["trace", Int.toString n, "x", Int.toString n, !gRealSuffix]
92 :     fun norm (n, m) = concat["norm", Int.toString n, "x", Int.toString m, !gRealSuffix]
93 :     fun copyMat (n, m) = concat["copy", Int.toString n, "x", Int.toString m, !gRealSuffix]
94 :     fun scaleMat (n, m) = concat["scale", Int.toString n, "x", Int.toString m, !gRealSuffix]
95 :     fun addMat (n, m) = concat["add", Int.toString n, "x", Int.toString m, !gRealSuffix]
96 :     fun subMat (n, m) = concat["sub", Int.toString n, "x", Int.toString m, !gRealSuffix]
97 :     fun mulVecMat (m, n) = F.format "mulVec%dMat%dx%d%s"
98 :     [F.INT m, F.INT m, F.INT n, F.STR(!gRealSuffix)]
99 :     fun mulMatVec (m, n) = F.format "mulMat%dx%dVec%d%s"
100 :     [F.INT n, F.INT m, F.INT n, F.STR(!gRealSuffix)]
101 :     fun mulMatMat (m, n, p) = F.format "mulMat%dx%dMat%dx%d%s"
102 :     [F.INT m, F.INT n, F.INT n, F.INT p, F.STR(!gRealSuffix)]
103 :    
104 :     (* Status_t symbols *)
105 :     val kActive = "DIDEROT_ACTIVE"
106 :     val kDie = "DIDEROT_DIE"
107 :     val kStabilize = "DIDEROT_STABILIZE"
108 :    
109 :     (* Diderot runtime system hooks *)
110 :     val statusTy = "Status_t"
111 :     val toImageSpace = addVecSuffix "ToImageSpace"
112 :     fun toWorldSpace ty = let
113 :     val suffix = (case ty
114 :     of Ty.TensorTy[d] => [Int.toString d, !gRealSuffix]
115 :     | Ty.TensorTy[m,n] => [Int.toString n, "x", Int.toString n, !gRealSuffix]
116 :     (* end case *))
117 :     in
118 :     concat("ToWorldSpace" :: suffix)
119 :     end
120 :     val inside = addVecSuffix "Inside"
121 :     fun loadImage dim = concat["Diderot_LoadImage", Int.toString dim, "D"]
122 :     val strandDescTy = "Strand_t"
123 :     val worldTy = "Diderot_World_t"
124 : jhr 1301 val optionsTy = "Diderot_Options_t"
125 : jhr 1115 val allocInitially = "Diderot_AllocInitially"
126 :     val inState = "Diderot_InState"
127 :    
128 :     fun input ty = (case ty
129 :     of Ty.StringTy => "Diderot_InputString"
130 : jhr 1232 | Ty.TensorTy[] => "Diderot_InputReal"
131 :     | Ty.TensorTy[2] => "Diderot_InputVec2"
132 :     | Ty.TensorTy[3] => "Diderot_InputVec3"
133 : jhr 1115 | ty => raise Fail("unsupported input type " ^ Ty.toString ty)
134 :     (* end case *))
135 :    
136 :     end (* local *)
137 :     end

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